/* ==========================================================================
   Dory — animated guide chat
   --------------------------------------------------------------------------
   Pure CSS/SVG animation, no libraries. Every motion rule is disabled under
   prefers-reduced-motion.
   ========================================================================== */

/* --------------------------------------------------------------------------
   The fish
   -------------------------------------------------------------------------- */

.dory-fish {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.dory-fish .swim {
    animation: dory-bob 2.2s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: center;
}

.dory-fish .body {
    fill: #3a7bd5;
    stroke: #1c4fa1;
    stroke-width: 1.5;
}

/* Blue-tang "palette" marking around the eye */

.dory-fish .mark {
    fill: #101c33;
}

.dory-fish .tail {
    fill: #ffd43b;
    stroke: #dfa20e;
    stroke-width: 1.5;
    transform-origin: 17px 24px;
    animation: dory-wag .55s ease-in-out infinite alternate;
}

.dory-fish .fin {
    fill: #ffd43b;
    stroke: #dfa20e;
    stroke-width: 1;
    transform-origin: center 60%;
    animation: dory-flutter .8s ease-in-out infinite alternate;
}

.dory-fish .eye-white {
    fill: #fff;
}

.dory-fish .eye-dot {
    fill: #1f2937;
}

@keyframes dory-bob {

    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }

    50% {
        transform: translateY(-3.5px) rotate(-3deg);
    }
}

@keyframes dory-wag {

    from {
        transform: rotate(-14deg);
    }

    to {
        transform: rotate(14deg);
    }
}

@keyframes dory-flutter {

    from {
        transform: rotate(-10deg);
    }

    to {
        transform: rotate(16deg);
    }
}

/* Inside the bowl she wanders lazily back and forth, turning at each side.
   Everywhere else (chat avatar) she keeps the gentle bob. */

@keyframes dory-swim {

    /* Cruise right toward the glass */
    0% {
        transform: translate(-7px, -2px) scaleX(1) rotate(-3deg);
    }

    20% {
        transform: translate(0, 0) scaleX(1) rotate(2deg);
    }

    /* Nose pressed against the right wall — squash! */
    38%,
    41% {
        transform: translate(9px, 1px) scaleX(.82) rotate(4deg);
    }

    /* Recoil off the glass and turn around */
    45% {
        transform: translate(6px, 0) scaleX(1) rotate(8deg);
    }

    48% {
        transform: translate(3px, 0) scaleX(-1) rotate(-6deg);
    }

    /* Cruise left, diving toward the bowl's bottom curve */
    70% {
        transform: translate(-4px, 5px) scaleX(-1) rotate(-2deg);
    }

    /* Belly-bump on the lower glass arc */
    80%,
    83% {
        transform: translate(-7px, 8px) scaleY(.82) rotate(-5deg);
    }

    /* Pop back up and face right again */
    87% {
        transform: translate(-5px, 4px) scaleY(1) rotate(6deg);
    }

    91% {
        transform: translate(-4px, 2px) scaleX(1) rotate(-4deg);
    }

    100% {
        transform: translate(-7px, -2px) scaleX(1) rotate(-3deg);
    }
}

/* The glass flashes faintly at the exact moments Dory thumps it */

@keyframes dory-glass {

    0%,
    35%,
    49%,
    76%,
    90%,
    100% {
        box-shadow: inset 0 0 12px rgba(191, 219, 254, 0);
    }

    39%,
    81% {
        box-shadow: inset 0 0 14px 3px rgba(191, 219, 254, .38);
    }
}

.dory-launcher .swim {
    animation: dory-swim 11s ease-in-out infinite;
}

.dory-launcher::before {
    animation: dory-glass 11s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Floating launcher
   -------------------------------------------------------------------------- */

.dory-launcher {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 150;
    display: grid;
    place-items: center;
    width: 74px;
    height: 74px;
    padding: 13px;
    overflow: hidden;
    border: 2px solid rgba(147, 197, 253, .4);
    border-radius: 50%;
    background:
        radial-gradient(circle at 32% 26%, rgba(255, 255, 255, .18), rgba(96, 165, 250, .10) 55%, rgba(23, 52, 105, .38));
    box-shadow: 0 14px 36px rgba(59, 130, 246, .35);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    animation: dory-glow 3s ease-in-out infinite;
}

/* Water filling the lower two-thirds of the bowl */

.dory-launcher::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: linear-gradient(180deg,
        rgba(125, 180, 255, .08) 0%,
        rgba(59, 130, 246, .30) 48%,
        rgba(29, 78, 160, .48) 100%);
    pointer-events: none;
}

/* Glass shine on the upper-left curve */

.dory-launcher::after {
    content: "";
    position: absolute;
    top: 8px;
    left: 9px;
    width: 18px;
    height: 11px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .4);
    filter: blur(1px);
    transform: rotate(-28deg);
    pointer-events: none;
}

.dory-launcher:hover {
    transform: translateY(-4px) scale(1.06);
    box-shadow: 0 18px 44px rgba(59, 130, 246, .5);
    animation-play-state: paused;
}

@keyframes dory-glow {

    0%,
    100% {
        box-shadow: 0 14px 36px rgba(59, 130, 246, .3);
    }

    50% {
        box-shadow: 0 14px 44px rgba(59, 130, 246, .55);
    }
}

.dory-bubbles {
    position: absolute;
    bottom: 18px;
    left: 15px;
    pointer-events: none;
}

/* Fizz born in the water, escaping past the rim */

.dory-bubbles i {
    position: absolute;
    bottom: 0;
    width: 6px;
    height: 6px;
    border: 1.5px solid rgba(219, 234, 254, .9);
    background: rgba(191, 219, 254, .22);
    border-radius: 50%;
    opacity: 0;
    animation: dory-rise 3s linear infinite;
}

.dory-bubbles i:nth-child(1) {
    left: 0;
    animation-delay: 0s;
}

.dory-bubbles i:nth-child(2) {
    left: 11px;
    width: 4px;
    height: 4px;
    animation-delay: 1s;
}

.dory-bubbles i:nth-child(3) {
    left: 6px;
    width: 5px;
    height: 5px;
    animation-delay: 2s;
}

@keyframes dory-rise {

    0% {
        transform: translateY(0) scale(.6);
        opacity: 0;
    }

    15% {
        opacity: .9;
    }

    70% {
        opacity: .65;
    }

    100% {
        transform: translateY(-58px) scale(1.2);
        opacity: 0;
    }
}

/* --------------------------------------------------------------------------
   Chat panel
   -------------------------------------------------------------------------- */

.dory-chat {
    position: fixed;
    right: 1.25rem;
    bottom: calc(1.25rem + 90px + env(safe-area-inset-bottom));
    left: auto;
    display: none;
    flex-direction: column;
    width: min(380px, calc(100vw - 2rem));
    height: min(540px, calc(100dvh - 8.5rem));
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    box-shadow: 0 24px 64px rgba(0, 0, 0, .5);
}

.dory-chat[open] {
    display: flex;
    animation: dory-pop .22s ease-out;
}

.dory-chat::backdrop {
    background: transparent;
}

@keyframes dory-pop {

    from {
        opacity: 0;
        transform: translateY(12px) scale(.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Slow dissolve out of the whole chat panel after a farewell reply */
.dory-chat.fading {
    opacity: 0;
    transform: translateY(12px) scale(.97);
    pointer-events: none;
    transition: opacity .9s ease, transform .9s ease;
}

.dory-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--border);
    background: rgba(59, 130, 246, .08);
}

.dory-avatar {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 7px;
    border-radius: 50%;
    overflow: hidden;
    background: radial-gradient(circle at 30% 25%, rgba(96, 165, 250, .25), transparent 75%);
    flex-shrink: 0;
}

.dory-title {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.dory-title strong {
    color: var(--text);
    font-size: var(--step-0);
}

.dory-title span {
    color: var(--text-muted);
    font-size: .78rem;
}

.dory-close {
    margin-left: auto;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 1.15rem;
    line-height: 1;
    transition: background var(--transition), color var(--transition);
}

.dory-close:hover {
    background: rgba(255, 255, 255, .08);
    color: var(--text);
}

.dory-note-btn {
    margin-left: auto;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: .95rem;
    line-height: 1;
    transition: background var(--transition), color var(--transition);
}

.dory-note-btn:hover {
    background: rgba(255, 255, 255, .1);
    color: var(--text);
}

.dory-log {
    display: flex;
    flex-direction: column;
    gap: .6rem;
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.msg {
    max-width: 86%;
    padding: .6rem .85rem;
    border-radius: 14px;
    font-size: var(--step--1);
    line-height: 1.55;
    word-break: break-word;
}

.msg.dory {
    align-self: flex-start;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    background: rgba(255, 255, 255, .055);
    color: var(--text);
}

.msg.user {
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    color: #04121f;
    font-weight: 500;
}

.msg b {
    color: inherit;
}

/* Typing indicator */

.msg.typing {
    padding: .75rem 1rem;
}

.dots {
    display: inline-flex;
    gap: 5px;
}

.dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-light);
    animation: dory-dots 1s ease-in-out infinite;
}

.dots i:nth-child(2) {
    animation-delay: .15s;
}

.dots i:nth-child(3) {
    animation-delay: .3s;
}

@keyframes dory-dots {

    0%,
    100% {
        transform: translateY(0);
        opacity: .4;
    }

    50% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* While Dory thinks, his avatar jiggles eagerly */

.dory-chat.is-thinking .dory-avatar .swim {
    animation-duration: .5s;
}

.dory-chat.is-thinking .dory-avatar .tail {
    animation-duration: .25s;
}

/* Guestbook note card */

.dory-note {
    display: none;
    flex-direction: column;
    gap: .55rem;
    margin: 0 .75rem .75rem;
    padding: .8rem .9rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(2, 6, 23, .55);
}

.dory-note:not([hidden]) {
    display: flex;
}

.dory-note-title {
    color: var(--text);
    font-size: var(--step--1);
    font-weight: 600;
}

.dory-note label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
}

.dory-note label span {
    color: var(--text-secondary);
    font-size: .72rem;
}

.dory-note label em {
    color: var(--text-muted);
    font-style: normal;
}

.dory-note input,
.dory-note textarea {
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, .05);
    color: var(--text);
    font-size: var(--step--1);
    font-family: inherit;
}

.dory-note textarea {
    resize: vertical;
    min-height: 70px;
}

.dory-note input::placeholder,
.dory-note textarea::placeholder {
    color: var(--text-muted);
}

.dory-note input:focus-visible,
.dory-note textarea:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 1px;
}

.dory-note-actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

.dory-note-cancel,
.dory-note-submit {
    padding: .45rem .9rem;
    border-radius: 999px;
    font-size: var(--step--1);
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
}

.dory-note-cancel {
    border: 1px solid var(--border);
    color: var(--text-secondary);
    background: transparent;
}

.dory-note-cancel:hover {
    background: rgba(255, 255, 255, .06);
    color: var(--text);
}

.dory-note-submit {
    border: none;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    color: #04121f;
    font-weight: 600;
}

.dory-note-submit:hover {
    transform: scale(1.04);
}

/* Input bar */

.dory-form {
    display: flex;
    gap: .55rem;
    padding: .75rem;
    border-top: 1px solid var(--border);
    background: rgba(2, 6, 23, .35);
}

.dory-form input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: .65rem .95rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, .05);
    color: var(--text);
    font-size: var(--step--1);
}

.dory-form input::placeholder {
    color: var(--text-muted);
}

.dory-form input:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 1px;
}

.dory-send {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    color: #04121f;
    cursor: pointer;
    transition: transform var(--transition);
}

.dory-send,
.dory-launcher,
.dory-note-btn,
.dory-close {
    touch-action: manipulation;
}

.dory-send:hover {
    transform: scale(1.08);
}

.dory-send svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

/* Mobile: full sheet */

@media (max-width: 640px) {

    .dory-chat {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        border: none;
    }

    .dory-head {
        padding-top: calc(.8rem + env(safe-area-inset-top));
    }

    .dory-form {
        padding-bottom: calc(.75rem + env(safe-area-inset-bottom));
    }
}

/* --------------------------------------------------------------------------
   Dock — launcher + one-time intro bubble
   -------------------------------------------------------------------------- */

.dory-dock {
    position: fixed;
    right: 1.25rem;
    bottom: calc(1.25rem + env(safe-area-inset-bottom));
    z-index: 150;
}

.dory-dock .dory-launcher {
    position: relative;
}

.dory-hint {
    position: absolute;
    right: 0;
    bottom: calc(100% + 14px);
    display: flex;
    flex-direction: column;
    gap: .35rem;
    max-width: 240px;
    padding: .7rem .85rem;
    border: 1px solid var(--border);
    border-radius: 14px;
    border-bottom-right-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font-size: var(--step--1);
    line-height: 1.45;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .4);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity var(--transition), transform var(--transition);
}

/* tail pointing down at Dory's launcher */
.dory-hint::after {
    content: "";
    position: absolute;
    right: 18px;
    bottom: -7px;
    width: 14px;
    height: 14px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-bottom-right-radius: 3px;
    transform: rotate(45deg);
}

.dory-hint.show {
    opacity: 1;
    transform: translateY(0);
}

.dory-hint-msg {
    max-width: 240px;
}

/* two messages, one bubble: second line gets a quiet divider */
.dory-hint-msg + .dory-hint-msg {
    padding-top: .35rem;
    border-top: 1px dashed var(--border);
}

/* Reduced motion: everything static */

@media (prefers-reduced-motion: reduce) {

    .dory-fish .swim,
    .dory-fish .tail,
    .dory-fish .fin,
    .dory-launcher,
    .dory-launcher::before,
    .dory-bubbles i,
    .dots i,
    .dory-chat[open],
    .dory-hint,
    .dory-hint-msg {
        animation: none;
        transition: none;
    }
}
