/* =====================================================================
   spleach.org games: shared chrome + the celebration layers that
   /js/games.js builds. Rides on site.css tokens (ink, teal, fonts).
   Layers: card scrim 9000 < fireworks 9010 < card 9020 < toasts 9030.
   ===================================================================== */

/* ---- Page frame on phones -------------------------------------------- */
/* Every /games page (hub, Mancala, Sudoku) loads this file. On a phone the
   site's floating nav would cover a big slice of the screen (the owner's
   has two or three rows of tabs), so here it scrolls away with the page
   instead of sticking, and the side gutter drops to 16px. A game's own
   stylesheet loads after this one and can fine-tune it. */
@media (max-width: 640px) {
    header {
        position: relative;
        top: 0;
        padding: 12px 16px 0;
    }

    main {
        padding: 18px 16px 36px;
    }
}

/* Sideways: 24px at the sides, so Mancala's stone canvas (it hangs 22px
   past the board so lifted stones aren't clipped) never widens the page. */
@media (max-height: 520px) and (orientation: landscape) {
    header {
        position: relative;
        top: 0;
        padding: 12px 24px 0;
    }

    main {
        padding: 14px 24px 28px;
    }
}

/* ---- "<- Games" back link ------------------------------------------- */
.g-back {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 14px 6px 10px;
    border-radius: var(--r-pill);
    font: 600 var(--text-sm)/1.25 var(--font-ui);
    color: var(--fg-1);
    background: rgba(255,255,255,.04);
    border: 1px solid var(--line-2);
    text-decoration: none;
    white-space: nowrap;
    transition: color .12s ease, background .12s ease, border-color .12s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

    .g-back:visited {
        color: var(--fg-1);
    }

    .g-back::before {
        content: "";
        flex: none;
        width: 16px;
        height: 16px;
        background: var(--teal);
        -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5'/%3E%3Cpath d='M11 18l-6-6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
        mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5'/%3E%3Cpath d='M11 18l-6-6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
        transition: transform .15s ease;
    }

/* Hover only where there's a real pointer: a tap leaves :hover stuck on. */
@media (hover: hover) {
    .g-back:hover {
        color: var(--fg-0);
        background: rgba(255,255,255,.08);
        border-color: rgba(16,202,188,.35);
    }

        .g-back:hover::before {
            transform: translateX(-2px);
        }
}

    .g-back:active {
        color: var(--fg-0);
    }

    .g-back:focus-visible {
        outline: 2px solid var(--teal);
        outline-offset: 2px;
    }

    .g-back.g-back--own-icon::before {
        display: none;
    }

/* ---- Toolbar --------------------------------------------------------- */
.g-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

    .g-toolbar .ds-btn {
        padding: 9px 18px;
        font-size: var(--text-sm);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .g-toolbar .g-toolbar-end {
        margin-left: auto;
    }

/* ---- Segmented control (difficulty etc.) ----------------------------- */
.g-seg {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 4px;
    gap: 4px;
    border-radius: var(--r-pill);
    background: rgba(255,255,255,.04);
    border: 1px solid var(--line-2);
}

.g-seg-btn {
    font: 600 var(--text-sm)/1.2 var(--font-ui);
    color: var(--fg-1);
    background: none;
    border: 0;
    padding: 8px 14px;
    border-radius: var(--r-pill);
    cursor: pointer;
    white-space: nowrap;
    transition: color .12s ease, background .12s ease, box-shadow .12s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
    .g-seg-btn:hover {
        color: var(--fg-0);
        background: rgba(255,255,255,.05);
    }
}

    .g-seg-btn.is-on {
        color: var(--fg-on-teal);
        background: var(--grad-teal);
        box-shadow: 0 4px 14px rgba(16,202,188,.25);
    }

    .g-seg-btn:focus-visible {
        outline: 2px solid var(--teal-bright);
        outline-offset: 1px;
    }

    .g-seg-btn:disabled {
        opacity: .45;
        cursor: default;
    }

@media (max-width: 560px) {
    .g-seg-btn {
        padding: 7px 10px;
    }
}

/* ---- Round icon button ----------------------------------------------- */
.g-icon-btn {
    --g-size: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: var(--g-size);
    height: var(--g-size);
    padding: 0;
    border-radius: 50%;
    color: var(--fg-1);
    background: rgba(255,255,255,.04);
    border: 1px solid var(--line-2);
    cursor: pointer;
    transition: color .12s ease, background .12s ease, border-color .12s ease, transform .12s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

    .g-icon-btn svg {
        display: block;
        width: 20px;
        height: 20px;
        overflow: visible;
    }

@media (hover: hover) {
    .g-icon-btn:hover {
        color: var(--fg-0);
        background: rgba(255,255,255,.08);
    }
}

    .g-icon-btn:active {
        transform: scale(.93);
    }

    .g-icon-btn:focus-visible {
        outline: 2px solid var(--teal);
        outline-offset: 2px;
    }

    .g-icon-btn.is-on,
    .g-icon-btn[aria-pressed="true"] {
        color: var(--teal-bright);
        background: rgba(16,202,188,.10);
        border-color: rgba(16,202,188,.45);
    }

    .g-icon-btn:disabled {
        opacity: .4;
        cursor: default;
        transform: none;
    }

    .g-icon-btn[hidden] {
        display: none;
    }

/* the vibration toggle: waves when on, slashed when off */
.g-haptics .g-hap-waves {
    transition: opacity .15s ease;
}

.g-haptics .g-hap-cut,
.g-haptics .g-hap-slash {
    opacity: 0;
    transition: opacity .15s ease;
}

.g-haptics .g-hap-cut {
    stroke: var(--ink-1);
    stroke-width: 5;
}

.g-haptics.is-off .g-hap-waves {
    opacity: 0;
}

.g-haptics.is-off .g-hap-cut,
.g-haptics.is-off .g-hap-slash {
    opacity: 1;
}

.g-haptics.is-buzz svg {
    animation: g-buzz .36s linear;
}

@keyframes g-buzz {
    20% { transform: translateX(-1px) rotate(-5deg); }
    40% { transform: translateX(1px) rotate(5deg); }
    60% { transform: translateX(-1px) rotate(-3deg); }
    80% { transform: translateX(1px) rotate(2deg); }
}

/* ---- Fireworks overlay ----------------------------------------------- */
.g-fx {
    position: fixed;
    inset: 0;
    z-index: 9010;
    pointer-events: none;
    contain: strict;
    transition: opacity .24s ease;
}

    .g-fx canvas {
        display: block;
        width: 100%;
        height: 100%;
    }

    .g-fx.is-out {
        opacity: 0;
    }

/* ---- Toasts ---------------------------------------------------------- */
.g-toasts {
    position: fixed;
    left: 50%;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 9030;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: max-content;
    max-width: calc(100vw - 32px);
    pointer-events: none;
}

.g-toast {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    padding: 11px 18px 11px 14px;
    border-radius: var(--r-pill);
    font: 500 var(--text-sm)/1.35 var(--font-ui);
    color: var(--fg-0);
    background: rgba(20,26,26,.92);
    border: 1px solid var(--line-2);
    box-shadow: var(--shadow-pop);
    -webkit-backdrop-filter: blur(14px) saturate(1.1);
    backdrop-filter: blur(14px) saturate(1.1);
    animation: g-toast-in .34s cubic-bezier(.2,1.25,.4,1) both;
}

    .g-toast::before {
        content: "";
        flex: none;
        width: 7px;
        height: 7px;
        border-radius: 9px;
        background: var(--teal);
        box-shadow: 0 0 10px var(--teal);
    }

    .g-toast.is-out {
        animation: g-toast-out .2s ease forwards;
    }

@keyframes g-toast-in {
    from { opacity: 0; transform: translateY(14px) scale(.96); }
}

@keyframes g-toast-out {
    to { opacity: 0; transform: translateY(6px) scale(.98); }
}

/* ---- Celebration card ------------------------------------------------ */
.g-cel-scrim {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: radial-gradient(120% 90% at 50% 38%, rgba(8,10,10,.52), rgba(4,6,6,.8));
    -webkit-backdrop-filter: blur(7px) saturate(.9);
    backdrop-filter: blur(7px) saturate(.9);
    touch-action: none;
    overscroll-behavior: contain;
    animation: g-fade-in .28s ease both;
}

    .g-cel-scrim[data-tone="win"] {
        background: radial-gradient(90% 70% at 50% 42%, rgba(10,142,133,.16), transparent 70%), radial-gradient(120% 90% at 50% 38%, rgba(8,10,10,.5), rgba(4,6,6,.8));
    }

    /* Still catches taps while it fades (and a beat after; games.js
       detaches it late): the second tap of a double tap on the card's
       button must not land on the game underneath. */
    .g-cel-scrim.is-closing {
        animation: g-fade-out .22s ease forwards;
    }

.g-cel {
    position: fixed;
    inset: 0;
    z-index: 9020;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    pointer-events: none;
}

.g-cel-card {
    position: relative;
    isolation: isolate;
    width: 100%;
    max-width: 420px;
    max-height: 100%;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 30px 24px 22px;
    border-radius: var(--r-xl);
    text-align: center;
    color: var(--fg-1);
    background: linear-gradient(180deg, #1c2424, #0e1212);
    border: 1px solid var(--line-2);
    box-shadow: var(--shadow-pop), inset 0 1px 0 rgba(255,255,255,.07);
    outline: none;
    pointer-events: auto;
    animation: g-cel-in .62s cubic-bezier(.2,.9,.25,1) both;
}

    /* halo + bright lattice at the top, fading down */
    .g-cel-card::before {
        content: "";
        position: absolute;
        inset: 0;
        z-index: -1;
        border-radius: inherit;
        pointer-events: none;
        background: radial-gradient(75% 46% at 50% 0%, rgba(16,202,188,.26), transparent 72%), repeating-linear-gradient(45deg, transparent 0 20px, rgba(70,230,215,.07) 20px 21px), repeating-linear-gradient(-45deg, transparent 0 20px, rgba(70,230,215,.07) 20px 21px);
        -webkit-mask-image: linear-gradient(180deg, #000 10%, transparent 62%);
        mask-image: linear-gradient(180deg, #000 10%, transparent 62%);
    }

.g-cel[data-tone="lose"] .g-cel-card::before {
    background: radial-gradient(75% 46% at 50% 0%, rgba(255,255,255,.06), transparent 72%), repeating-linear-gradient(45deg, transparent 0 20px, rgba(255,255,255,.035) 20px 21px), repeating-linear-gradient(-45deg, transparent 0 20px, rgba(255,255,255,.035) 20px 21px);
}

.g-cel[data-tone="tie"] .g-cel-card::before {
    background: radial-gradient(75% 46% at 50% 0%, rgba(16,202,188,.13), transparent 72%), repeating-linear-gradient(45deg, transparent 0 20px, rgba(70,230,215,.045) 20px 21px), repeating-linear-gradient(-45deg, transparent 0 20px, rgba(70,230,215,.045) 20px 21px);
}

.g-cel.is-closing .g-cel-card {
    pointer-events: none;
    animation: g-cel-out .2s ease forwards;
}

.g-cel-badge {
    position: relative;
    display: grid;
    place-items: center;
    width: 68px;
    height: 68px;
    margin: 0 auto 16px;
    border-radius: 50%;
    color: var(--fg-on-teal);
    background: var(--grad-teal);
    box-shadow: 0 0 0 6px rgba(16,202,188,.12), 0 10px 34px rgba(16,202,188,.45);
    animation: g-badge-in .7s cubic-bezier(.25,1.6,.4,1) .08s both;
}

    .g-cel-badge svg {
        width: 34px;
        height: 34px;
    }

.g-cel[data-tone="lose"] .g-cel-badge {
    color: var(--fg-1);
    background: var(--ink-3);
    border: 1px solid var(--line-2);
    box-shadow: 0 0 0 6px rgba(255,255,255,.035), inset 0 1px 0 rgba(255,255,255,.08);
}

.g-cel[data-tone="tie"] .g-cel-badge {
    color: var(--teal-bright);
    background: rgba(16,202,188,.12);
    border: 1px solid rgba(16,202,188,.42);
    box-shadow: 0 0 0 6px rgba(16,202,188,.06);
}

/* the hat-draw spark ring, bursting off the trophy */
.g-cel-sparks {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0;
    height: 0;
}

.g-cel-spark {
    position: absolute;
    left: 0;
    top: 0;
    width: 7px;
    height: 7px;
    margin: -3.5px;
    border-radius: 50%;
    opacity: 0;
    color: var(--teal-bright);
    background: currentColor;
    box-shadow: 0 0 10px currentColor;
    animation: g-spark .9s ease-out .42s forwards;
}

    .g-cel-spark:nth-child(3n+1) {
        color: #ffd76a;
    }

    .g-cel-spark:nth-child(3n+2) {
        color: var(--fg-0);
    }

.g-cel-title {
    margin: 0;
    font: 800 clamp(30px, 8.4vw, 40px)/1.05 var(--font-display);
    letter-spacing: -.035em;
    color: var(--fg-0);
}

.g-cel[data-tone="win"] .g-cel-title {
    background: linear-gradient(120deg, #f3f7f6 0%, #46e6d7 58%, #10cabc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.g-cel-sub {
    max-width: 34ch;
    margin: 8px auto 0;
    font: 400 var(--text-body)/1.5 var(--font-ui);
    color: var(--fg-1);
}

.g-cel-stats {
    display: grid;
    grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
    gap: 8px;
    margin: 20px 0 0;
    padding: 0;
}

.g-cel-stat {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 4px;
    min-width: 0;
    padding: 11px 6px 10px;
    border-radius: var(--r-md);
    background: rgba(255,255,255,.035);
    border: 1px solid var(--line);
}

    .g-cel-stat dt {
        max-width: 100%;
        font: 600 10.5px/1.2 var(--font-meta);
        letter-spacing: .08em;
        text-transform: uppercase;
        color: #8a9a98; /* quieter than the value, but 5.6:1 on the cell (--fg-2 is 4:1) */
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .g-cel-stat dd {
        max-width: 100%;
        margin: 0;
        font: 600 22px/1.1 var(--font-mono);
        font-variant-numeric: tabular-nums;
        color: var(--fg-0);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

.g-cel-actions {
    display: flex;
    flex-wrap: wrap-reverse; /* when the two buttons stack, the primary goes on top */
    gap: 10px;
    margin-top: 22px;
}

    .g-cel-actions .ds-btn {
        flex: 1 1 140px;
        justify-content: center;
        padding: 12px 18px;
        font-size: 15px;
        touch-action: manipulation;
    }

    .g-cel-actions .ds-btn:focus-visible {
        outline: 2px solid var(--teal-bright);
        outline-offset: 2px;
    }

.g-cel-x {
    --g-size: 34px;
    position: absolute;
    top: 12px;
    right: 12px;
    color: var(--fg-2);
    background: transparent;
    border-color: transparent;
}

    .g-cel-x svg {
        width: 16px;
        height: 16px;
    }

/* the card's contents rise in just behind it */
.g-cel-title,
.g-cel-sub,
.g-cel-stat,
.g-cel-actions {
    animation: g-rise .5s cubic-bezier(.2,.9,.3,1) both;
}

.g-cel-title { animation-delay: .12s; }
.g-cel-sub { animation-delay: .18s; }
.g-cel-stat { animation-delay: .24s; }
.g-cel-stat:nth-child(2) { animation-delay: .29s; }
.g-cel-stat:nth-child(3) { animation-delay: .34s; }
.g-cel-stat:nth-child(n+4) { animation-delay: .39s; }
.g-cel-actions { animation-delay: .32s; }

@keyframes g-cel-in {
    0% { opacity: 0; transform: translateY(28px) scale(.86); }
    45% { opacity: 1; }
    62% { transform: translateY(-5px) scale(1.025); }
    80% { transform: translateY(1px) scale(.995); }
    100% { opacity: 1; transform: none; }
}

@keyframes g-cel-out {
    to { opacity: 0; transform: translateY(10px) scale(.96); }
}

@keyframes g-badge-in {
    0% { opacity: 0; transform: scale(.3) rotate(-25deg); }
    70% { opacity: 1; transform: scale(1.08) rotate(4deg); }
    100% { opacity: 1; transform: none; }
}

@keyframes g-spark {
    0% { opacity: 1; transform: rotate(var(--a)) translateX(30px) scale(1.3); }
    100% { opacity: 0; transform: rotate(var(--a)) translateX(66px) scale(0); }
}

@keyframes g-rise {
    from { opacity: 0; transform: translateY(10px); }
}

@keyframes g-fade-in {
    from { opacity: 0; }
}

@keyframes g-fade-out {
    to { opacity: 0; }
}

/* landscape phones: a shorter card */
@media (max-height: 520px) {
    .g-cel-card {
        max-width: 460px;
        padding: 18px 22px 16px;
    }

    .g-cel-badge {
        width: 46px;
        height: 46px;
        margin-bottom: 10px;
        box-shadow: 0 0 0 5px rgba(16,202,188,.12), 0 8px 24px rgba(16,202,188,.4);
    }

        .g-cel-badge svg {
            width: 24px;
            height: 24px;
        }

    .g-cel-title {
        font-size: 28px;
    }

    .g-cel-sub {
        margin-top: 4px;
        font-size: var(--text-sm);
    }

    .g-cel-stats {
        grid-template-columns: repeat(var(--cols-wide, var(--cols, 3)), minmax(0, 1fr));
        margin-top: 12px;
    }

    .g-cel-stat {
        padding: 7px 6px 6px;
    }

        .g-cel-stat dd {
            font-size: 18px;
        }

    .g-cel-actions {
        margin-top: 14px;
    }

        .g-cel-actions .ds-btn {
            padding: 10px 16px;
        }

    @keyframes g-spark {
        0% { opacity: 1; transform: rotate(var(--a)) translateX(22px) scale(1.1); }
        100% { opacity: 0; transform: rotate(var(--a)) translateX(48px) scale(0); }
    }
}

/* ---- Touch: bigger tap targets, same layout ---------------------------- */
/* An invisible ::after stretches each control's hit area to about 40px or
   more (into the pill track's padding, or the gap to its neighbor) without
   moving anything. The card's close button has room to grow for real. */
@media (pointer: coarse) {
    .g-back,
    .g-seg-btn,
    .g-toolbar .ds-btn,
    :where(.g-icon-btn) {
        position: relative;
    }

        .g-back::after,
        .g-seg-btn::after,
        .g-toolbar .ds-btn::after,
        .g-icon-btn::after {
            content: "";
            position: absolute;
            inset: -3px;
        }

        .g-back::after,
        .g-seg-btn::after {
            inset: -5px -2px;
        }

    .g-cel-x {
        --g-size: 40px;
        top: 8px;
        right: 8px;
    }

        .g-cel-x::after {
            inset: -4px;
        }
}

/* ---- Reduced motion: fades only, no travel ---------------------------- */
@media (prefers-reduced-motion: reduce) {
    .g-cel-card {
        animation: g-fade-in .2s ease both;
    }

    .g-cel.is-closing .g-cel-card {
        animation: g-fade-out .16s ease forwards;
    }

    .g-cel-badge,
    .g-cel-title,
    .g-cel-sub,
    .g-cel-stat,
    .g-cel-actions {
        animation: none;
    }

    .g-cel-sparks {
        display: none;
    }

    .g-toast {
        animation-name: g-fade-in;
    }

        .g-toast.is-out {
            animation-name: g-fade-out;
        }

    .g-haptics.is-buzz svg {
        animation: none;
    }

    .g-back::before,
    .g-icon-btn {
        transition: none;
    }

    .g-icon-btn:active {
        transform: none;
    }
}
