:root {
    color-scheme: dark;
    --ink: #f4f4e8;
    --ink-muted: rgba(240, 247, 239, 0.7);
    --panel: rgba(8, 45, 57, 0.84);
    --panel-border: rgba(224, 246, 236, 0.32);
    --focus: #fffbe8;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
}

body {
    overflow: hidden;
    background: #16637a;
    color: var(--ink);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

.pool-loader {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background-color: #075d78;
    background-image:
        linear-gradient(rgba(250, 243, 224, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(250, 243, 224, 0.07) 1px, transparent 1px);
    background-size: 30px 30px;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition:
        opacity 650ms cubic-bezier(0.22, 0.7, 0.24, 1),
        visibility 0s linear 0s;
}

.scene-ready .pool-loader,
.scene-failed .pool-loader {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 650ms cubic-bezier(0.22, 0.7, 0.24, 1),
        visibility 0s linear 650ms;
}

.loading-hourglass {
    width: clamp(3.5rem, 8vw, 4.75rem);
    height: auto;
    overflow: visible;
    filter: drop-shadow(0 10px 18px rgba(0, 31, 45, 0.3));
    animation: hourglass-flip 2.7s cubic-bezier(0.7, 0, 0.3, 1) infinite;
}

.hourglass-frame {
    fill: none;
    stroke: rgba(250, 243, 224, 0.9);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hourglass-sand {
    fill: rgba(250, 243, 224, 0.86);
    transform-box: fill-box;
    transform-origin: center bottom;
}

.hourglass-sand-top {
    animation: hourglass-empty 2.7s ease-in infinite;
}

.hourglass-sand-bottom {
    animation: hourglass-fill 2.7s ease-out infinite;
}

.hourglass-stream {
    fill: none;
    stroke: rgba(250, 243, 224, 0.86);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-dasharray: 2 3;
    animation: hourglass-stream 2.7s linear infinite;
}

@keyframes hourglass-empty {
    0%, 8% { transform: scaleY(1); }
    62%, 100% { transform: scaleY(0.06); }
}

@keyframes hourglass-fill {
    0%, 8% { transform: scaleY(0.06); }
    62%, 100% { transform: scaleY(1); }
}

@keyframes hourglass-stream {
    0%, 7%, 64%, 100% { opacity: 0; }
    12%, 57% { opacity: 1; }
}

@keyframes hourglass-flip {
    0%, 67% { transform: rotate(0deg); }
    88%, 100% { transform: rotate(180deg); }
}

.pool-fallback,
.pool-scene {
    position: fixed;
    inset: auto 0;
    top: 50%;
    width: 100%;
    height: 100lvh;
    transform: translateY(-50%);
}

.pool-fallback {
    z-index: 0;
    background-color: #1d859f;
    background-image:
        linear-gradient(rgba(10, 82, 102, 0.3) 2px, transparent 2px),
        linear-gradient(90deg, rgba(10, 82, 102, 0.3) 2px, transparent 2px),
        radial-gradient(circle at 48% 38%, rgba(154, 234, 221, 0.66), transparent 46%),
        linear-gradient(145deg, #2498af, #0d5874);
    background-size: 88px 88px, 88px 88px, auto, auto;
    box-shadow: inset 0 0 72px rgba(0, 36, 54, 0.64);
    opacity: 1;
    transition: opacity 450ms ease;
}

.pool-scene {
    z-index: 1;
    display: block;
    opacity: 1;
    pointer-events: none;
}

.scene-ready .pool-fallback {
    opacity: 0;
}

.duck-target {
    position: fixed;
    top: var(--duck-y);
    left: var(--duck-x);
    z-index: 3;
    width: var(--duck-width);
    height: var(--duck-height);
    padding: 0;
    transform: translate(-50%, -50%);
    border: 0;
    border-radius: 50%;
    outline: none;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.duck-target:disabled {
    pointer-events: none;
    cursor: default;
}

.duck-target:focus-visible {
    box-shadow: 0 0 0 3px rgba(255, 251, 232, 0.95), 0 0 0 7px rgba(3, 64, 79, 0.55);
}

.pool-interface {
    position: relative;
    z-index: 2;
    width: 100vw;
    height: 100svh;
    pointer-events: none;
}

.pool-letters {
    position: fixed;
    inset: 16vh 7vw 14vh;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: center;
    pointer-events: none;
}

.pool-letter {
    position: relative;
    display: grid;
    place-items: center;
    min-width: 0;
    height: min(52vh, 500px);
    border-radius: 12px;
    color: inherit;
    outline: none;
    pointer-events: auto;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.layout-ready .pool-letters {
    inset: 0;
    display: block;
}

.layout-ready .pool-letter {
    position: fixed;
    top: var(--letter-y);
    left: var(--letter-x);
    width: var(--letter-width);
    height: var(--letter-height);
    transform: translate(-50%, -50%);
}

.pool-letter::after {
    content: "";
    position: absolute;
    inset: 5%;
    border: 2px solid transparent;
    border-radius: 12px;
    transition: border-color 180ms ease, box-shadow 180ms ease;
}

.pool-letter:focus-visible::after {
    border-color: var(--focus);
    box-shadow: 0 0 0 4px rgba(2, 55, 70, 0.5);
}

.fallback-letter {
    color: rgba(247, 245, 225, 0.94);
    font-family: "Arial Black", Impact, sans-serif;
    font-size: clamp(4.5rem, 15vw, 13.5rem);
    font-weight: 900;
    line-height: 0.8;
    text-shadow:
        0 4px 0 #d9ddcf,
        0 10px 20px rgba(0, 48, 68, 0.42);
    transform: perspective(800px) rotateX(-8deg);
    transition: opacity 280ms ease, transform 420ms cubic-bezier(0.2, 0.9, 0.2, 1);
}

.scene-ready .fallback-letter {
    opacity: 0;
}

.pool-letter:is(:hover, :focus-visible, .active, .engaged) .fallback-letter {
    opacity: 0.36;
    transform: perspective(800px) translateY(18px) rotateX(10deg) scale(0.95);
}

.scene-ready .pool-letter:is(:hover, :focus-visible, .active, .engaged) .fallback-letter {
    opacity: 0;
}

.destination-panel {
    position: absolute;
    top: calc(100% + 0.45rem);
    left: 50%;
    z-index: 8;
    display: grid;
    gap: 0.32rem;
    width: clamp(180px, 17vw, 232px);
    padding: 1rem 1.08rem 0.9rem;
    transform: translate(-50%, -20px) scale(0.92);
    transform-origin: top center;
    border: 1px solid var(--panel-border);
    border-radius: 5px;
    background: var(--panel);
    box-shadow:
        0 20px 52px rgba(0, 31, 45, 0.3),
        inset 0 1px rgba(255, 255, 255, 0.12);
    color: var(--ink-muted);
    opacity: 0;
    visibility: hidden;
    text-align: center;
    pointer-events: none;
    transition:
        opacity 240ms ease,
        transform 420ms cubic-bezier(0.2, 0.9, 0.2, 1.05),
        visibility 0s 420ms;
}

.destination-panel strong,
.mobile-destination strong {
    color: var(--ink);
    font-size: clamp(0.94rem, 1.3vw, 1.2rem);
    line-height: 1.1;
}

.destination-panel span,
.mobile-destination span {
    min-height: 2.2em;
    font-size: clamp(0.8rem, 1vw, 0.94rem);
    font-weight: 600;
    line-height: 1.42;
}

/* The blur only exists while a panel is on screen. Left on permanently it keeps a
   composited layer over the animating canvas, and the compositor re-samples and
   blurs that region every frame for a panel nobody can see. */
.pool-letter:is(:hover, :focus-visible, .active, .engaged) .destination-panel {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0) scale(1);
    transition-delay: 80ms, 0ms, 0ms;
    backdrop-filter: blur(13px) saturate(115%);
}

.mobile-destination {
    position: fixed;
    top: var(--mobile-destination-y, 50%);
    right: max(0.8rem, env(safe-area-inset-right));
    bottom: auto;
    left: auto;
    z-index: 30;
    display: none;
    width: clamp(180px, 17vw, 232px);
    align-content: center;
    gap: 0.32rem;
    padding: 1rem 1.08rem 0.9rem;
    transform: translate(1.5rem, -50%) scale(0.96);
    transform-origin: right center;
    border: 1px solid var(--panel-border);
    border-radius: 5px;
    background: var(--panel);
    box-shadow:
        0 20px 52px rgba(0, 31, 45, 0.3),
        inset 0 1px rgba(255, 255, 255, 0.12);
    color: var(--ink-muted);
    opacity: 0;
    pointer-events: none;
    text-align: center;
    text-decoration: none;
    transition:
        opacity 220ms ease,
        transform 360ms cubic-bezier(0.2, 0.84, 0.24, 1);
}

.mobile-destination .tap-indicator {
    display: flex;
    min-height: 0;
    align-items: center;
    justify-content: center;
    gap: 0.38rem;
    margin-top: 0.12rem;
    color: rgba(250, 243, 224, 0.62);
    font-size: clamp(0.64rem, 2.45vw, 0.75rem);
    font-weight: 600;
    letter-spacing: 0.07em;
    line-height: 1;
    text-transform: uppercase;
}

.mobile-destination .tap-indicator > span {
    min-height: 0;
}

.mobile-destination .tap-indicator > span:last-child {
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
}

.mobile-destination .tap-icon {
    color: var(--ink);
    font-size: 1.08rem;
    line-height: 1;
}

@media (orientation: portrait) {
    .pool-letters {
        inset: 11vh 12vw 12vh;
        grid-template-rows: repeat(5, minmax(0, 1fr));
        grid-template-columns: 1fr;
    }

    .pool-letter {
        width: 100%;
        height: 100%;
    }

    .fallback-letter {
        font-size: clamp(4rem, 23vw, 7.4rem);
    }
}

@media (max-width: 768px), (pointer: coarse), (orientation: portrait) {
    .destination-panel {
        display: none;
    }

    .mobile-destination {
        position: fixed;
        top: var(--mobile-destination-y, 50%);
        right: max(0.8rem, env(safe-area-inset-right));
        bottom: auto;
        left: auto;
        display: grid;
        box-sizing: border-box;
        width: clamp(180px, 17vw, 232px);
        height: auto;
        transform: translate(1.5rem, -50%) scale(0.96);
        transform-origin: right center;
    }

    .mobile-destination.visible {
        transform: translate(0, -50%) scale(1);
        opacity: 1;
        pointer-events: auto;
        backdrop-filter: blur(13px) saturate(115%);
    }

    .pool-letter::after {
        inset: 7%;
    }

}

@media (max-width: 420px) {
    .mobile-destination {
        right: max(0.72rem, env(safe-area-inset-right));
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
