/* The game stage, the host console and everything inside the two games. */

/* ---------- Stage ---------- */

.stage {
    position: relative;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    flex: 1;
    /* Nav above, footer below: a game page never needs to scroll. */
    min-height: calc(100dvh - var(--nav-h) - var(--footer-h));
}

.app.is-presenting .stage {
    min-height: 100dvh;
}

.stage-focus {
    display: grid;
    align-content: center;
    justify-items: center;
    gap: clamp(.75rem, 2.2vh, 1.75rem);
    min-width: 0;
    padding: clamp(.75rem, 2vh, 2rem) var(--gutter);
    text-align: center;
}

/* Entrances that are a plain rise are done in CSS; --i staggers them. */
[data-enter] {
    animation: enter-rise var(--dur-slow) var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 80ms);
}

@keyframes enter-rise {
    from {
        opacity: 0;
        transform: translateY(1.5rem);
    }
}

.stage-lead {
    color: var(--mist);
    font-family: var(--font-display);
    font-size: clamp(1.25rem, 2.6vw, 2.25rem);
    font-weight: 600;
    line-height: 1.1;
}

.stage-instruction {
    max-width: 28ch;
    min-height: 2.5em;
    font-family: var(--font-display);
    font-size: clamp(1.35rem, 3.1vw, 3rem);
    font-weight: 600;
    line-height: 1.2;
    text-wrap: balance;
}

.stage-instruction.is-quiet {
    color: var(--mist);
    font-weight: 500;
}

.stage-progress {
    color: var(--mist);
    font-size: .9375rem;
    font-variant-numeric: tabular-nums;
}

/* ---------- Host console ---------- */

.deck {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-5) var(--gutter) calc(var(--space-4) + env(safe-area-inset-bottom));
    background: linear-gradient(rgb(8 11 20 / 0), rgb(8 11 20 / .92) 45%);
}

.deck-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
}

.deck-side {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    transition: opacity var(--dur-slow) var(--ease-out);
}

.deck-utilities {
    justify-self: start;
}

.deck-tools {
    justify-self: end;
}

.btn[aria-disabled="true"] {
    opacity: .6;
    cursor: progress;
}

/* While presenting, the housekeeping controls step back until the host reaches for them. */
@media (hover: hover) {
    .app.is-presenting .deck-side {
        opacity: .3;
    }

    .app.is-presenting .deck:hover .deck-side,
    .app.is-presenting .deck:focus-within .deck-side {
        opacity: 1;
    }
}

/* Below a wide desktop the game actions take a row of their own above the housekeeping. */
@media (max-width: 1180px) {
    .deck {
        grid-template-columns: 1fr 1fr;
        row-gap: var(--space-3);
        padding-top: var(--space-4);
    }

    .deck-main {
        grid-column: 1 / -1;
        grid-row: 1;
    }
}

@media (max-width: 760px) {
    .deck-main .btn {
        flex: 1 1 100%;
    }

    .deck-main .btn:not(.btn-primary) {
        flex: 1 1 40%;
        padding: 0 .75rem;
        font-size: .9375rem;
    }

    .deck-main .btn[data-action="tie-breaker"] {
        flex-basis: 100%;
    }
}

/* ---------- Big result type ---------- */

.result-word {
    --glow: .35;
    min-height: 1em;
    color: var(--gold);
    font-family: var(--font-display);
    font-size: clamp(3rem, min(13vw, 16vh), 15rem);
    font-stretch: 75%;
    font-weight: 800;
    line-height: .9;
    text-shadow: 0 0 calc(var(--glow) * .55em) rgb(251 191 36 / calc(var(--glow) * .95));
    text-transform: uppercase;
}

.result-hint {
    color: var(--mist);
    font-family: var(--font-display);
    font-size: clamp(1.25rem, 2.6vw, 2.25rem);
    font-weight: 500;
}

/* ---------- 3D coin ---------- */

.coin3d {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Absolutely placed, so the canvas never feeds its own pixel size back into the layout. */
.coin3d-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity var(--dur-slow) var(--ease-out);
}

.coin3d.is-ready .coin3d-canvas {
    opacity: 1;
}

.coin3d-fallback {
    --coin-size: min(44vh, 62vw);
    position: absolute;
    inset: 0;
    display: none;
    place-items: center;
}

.coin3d-fallback .css-coin {
    --coin-size: inherit;
    width: min(44vh, 62vw);
}

.coin3d.is-fallback .coin3d-canvas {
    display: none;
}

.coin3d.is-fallback .coin3d-fallback {
    display: grid;
}

/* ---------- Coin Flip page ---------- */

.stage-coin .stage-focus {
    grid-template-rows: minmax(0, 1fr) auto auto;
    align-content: stretch;
    gap: 0;
    padding-top: 0;
}

.coin-area {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: min(46vh, 86vw);
}

/* The coin is drawn on a canvas taller than its slot, so a toss can rise over the navigation
   and the coin itself can be large. It ignores the pointer, so nothing underneath is blocked. */
.coin-area .coin3d,
.tie-coin .coin3d {
    position: absolute;
    inset: -22% 0 -8%;
    width: auto;
    height: auto;
    pointer-events: none;
}

.coin-result {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    min-height: clamp(3.4rem, min(13vw, 16vh), 15rem);
    margin-top: calc(-1 * clamp(.5rem, 3vh, 2.5rem));
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, auto) auto;
    align-items: center;
    gap: var(--space-5);
    margin-top: var(--space-4);
    padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5);
    border-radius: var(--radius-l);
    background: rgb(17 24 39 / .82);
    box-shadow: inset 0 0 0 1px var(--line);
    text-align: left;
    animation: enter-rise var(--dur-slow) var(--ease-out) both;
}

.stats dl {
    display: contents;
}

.stat {
    display: grid;
    gap: .1rem;
}

.stat dt {
    color: var(--mist);
    font-size: .8125rem;
}

.stat dd {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    line-height: 1.1;
}

.stat dd small {
    margin-left: .35em;
    color: var(--mist);
    font-family: var(--font-ui);
    font-size: .8125rem;
    font-weight: 500;
}

.stats-bar {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    height: .375rem;
    overflow: hidden;
    border-radius: var(--radius-pill);
    background: var(--slate-3);
}

.stats-bar span {
    background: var(--gold);
    transition: width var(--dur-slow) var(--ease-out);
}

.stats-bar span + span {
    background: var(--mist);
    margin-left: 2px;
}

/* On a wide screen the panel sits in the corner above its button, leaving the height to the coin. */
@media (min-width: 1100px) {
    .stage-coin .stage-focus {
        position: relative;
    }

    .stats {
        position: absolute;
        left: var(--gutter);
        bottom: 0;
        z-index: 2;
        margin: 0;
    }
}

@media (max-width: 560px) {
    .stats {
        gap: var(--space-4);
        padding-left: var(--space-4);
    }

    .stats .btn {
        grid-column: 1 / -1;
        grid-row: 3;
    }

    .stats-bar {
        grid-column: 1 / 4;
    }
}

/* ---------- Reel ---------- */

.reel {
    --glow: .35;
    position: relative;
    width: 100%;
    height: 1.16em;
    color: var(--gold);
    font-family: var(--font-display);
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
    white-space: nowrap;
}

.reel-month {
    font-size: clamp(3rem, min(15.5vw, 28vh), 24rem);
    font-stretch: 75%;
    letter-spacing: -.012em;
}

.reel-day {
    font-size: clamp(7rem, min(38vw, 44vh), 36rem);
    font-stretch: 82%;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.03em;
}

.reel-value {
    display: grid;
    place-items: center;
    height: 100%;
    text-shadow: 0 0 calc(var(--glow) * .5em) rgb(251 191 36 / calc(var(--glow) * .95));
}

/* Nothing drawn yet: an outlined question mark, breathing. */
.reel-value.is-idle {
    color: transparent;
    text-shadow: none;
    -webkit-text-stroke: .018em rgb(251 191 36 / .55);
    animation: idle-breathe 2.2s ease-in-out infinite alternate;
}

@keyframes idle-breathe {
    to {
        opacity: .45;
        transform: scale(.96);
    }
}

/* While spinning, the window clips to one line and fades its top and bottom edges. */
.reel[data-state] {
    overflow: hidden;
    -webkit-mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
    mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
}

.reel[data-state] .reel-value {
    visibility: hidden;
}

.reel-strip {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    will-change: transform;
}

.reel-item {
    display: grid;
    place-items: center;
}

/* ---------- Birthday Game: welcome ---------- */

.welcome {
    display: grid;
    justify-items: center;
    gap: clamp(.75rem, 2.2vh, 2rem);
    max-width: 70rem;
}

.welcome-title {
    font-size: clamp(3.2rem, min(13vw, 14vh), 15rem);
    font-stretch: 75%;
    font-weight: 800;
    line-height: .86;
    letter-spacing: -.012em;
    text-transform: uppercase;
}

.welcome-title span {
    display: block;
}

.welcome-title .is-gold {
    color: var(--gold);
    text-shadow: var(--glow-gold);
}

.welcome-sub {
    max-width: 26ch;
    color: var(--mist);
    font-family: var(--font-display);
    font-size: clamp(1.25rem, min(2.6vw, 3.6vh), 2.25rem);
    font-weight: 500;
    line-height: 1.2;
    text-wrap: balance;
}

.btn-xl {
    min-height: 4.5rem;
    margin-top: var(--space-3);
    padding: 0 3.25rem;
    font-size: 1.5rem;
}

.howto {
    width: min(100%, 38rem);
    margin-top: var(--space-2);
    border-radius: var(--radius-l);
    text-align: left;
}

.howto summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 2.75rem;
    color: var(--mist);
    font-weight: 500;
    cursor: pointer;
    list-style: none;
    text-decoration: underline;
    text-decoration-color: var(--line-strong);
    text-underline-offset: .3em;
}

.howto summary::-webkit-details-marker {
    display: none;
}

.howto summary:hover {
    color: var(--paper);
}

.howto[open] {
    padding: 0 var(--space-5) var(--space-5);
    background: rgb(17 24 39 / .82);
    box-shadow: inset 0 0 0 1px var(--line);
}

.howto ol {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding-left: 1.4em;
    color: var(--paper);
    font-size: 1.0625rem;
}

.howto ol li::marker {
    color: var(--gold);
    font-weight: 700;
}

.notice {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    max-width: 44rem;
    padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5);
    border-radius: var(--radius-m);
    background: var(--slate);
    box-shadow: inset 0 0 0 1px rgb(56 189 248 / .45);
    text-align: left;
}

/* ---------- Birthday Game: months ---------- */

.month-stage {
    display: grid;
    justify-items: center;
    gap: clamp(.5rem, 1.6vh, 1.25rem);
    width: 100%;
}

.month-board,
.day-grid {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

.month-board {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: .4rem;
    width: min(100%, 62rem);
    margin-top: var(--space-2);
}

/* Board tiles show their state three ways: fill, text treatment and a marker. */
.chip {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 2.5rem;
    border-radius: .6rem;
    background: var(--slate-2);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--paper);
    font-size: .9375rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    line-height: 1;
}

.chip.is-drawn {
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--line);
    color: rgb(148 163 184 / .6);
    font-weight: 500;
    text-decoration: line-through;
    text-decoration-thickness: .1em;
}

.chip.is-latest,
.chip.is-final {
    background: var(--gold);
    box-shadow: 0 0 0 .1875rem rgb(251 191 36 / .28), 0 .5rem 1.5rem rgb(251 191 36 / .25);
    color: var(--on-gold);
    font-weight: 800;
    text-decoration: none;
}

.chip.is-latest::after,
.chip.is-final::after {
    content: "";
    position: absolute;
    left: 50%;
    top: -.5rem;
    width: .5rem;
    height: .5rem;
    border-radius: 50%;
    background: var(--gold);
    transform: translateX(-50%);
}

@media (max-width: 760px) {
    .month-board {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        row-gap: .7rem;
    }
}

/* ---------- Birthday Game: month picker ---------- */

dialog.modal-picker {
    width: min(44rem, calc(100vw - 2rem));
}

.picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
    gap: var(--space-2);
    margin-top: var(--space-5);
}

.picker-month {
    appearance: none;
    min-height: 3.5rem;
    border: 0;
    border-radius: var(--radius-m);
    background: var(--slate-2);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--paper);
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--dur) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.picker-month:hover {
    background: var(--slate-3);
}

.picker-month[aria-pressed="true"] {
    background: var(--gold);
    box-shadow: 0 0 0 .1875rem rgb(251 191 36 / .28);
    color: var(--on-gold);
    font-weight: 800;
}

/* ---------- Birthday Game: months-to-days transition ---------- */

.transition {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 50vh;
    font-family: var(--font-display);
    font-weight: 800;
    line-height: .9;
    text-transform: uppercase;
}

.transition > * {
    grid-area: 1 / 1;
    opacity: 0;
}

.transition-round {
    font-size: clamp(3.2rem, min(15vw, 26vh), 20rem);
    font-stretch: 75%;
}

.transition-stack {
    display: grid;
    justify-items: center;
    gap: clamp(.5rem, 2vh, 1.5rem);
    opacity: 1;
}

.transition-line {
    color: var(--mist);
    font-size: clamp(1.5rem, min(5vw, 7vh), 5rem);
    font-stretch: 75%;
    opacity: 0;
}

.transition-month {
    color: var(--gold);
    font-size: clamp(3.2rem, min(15.5vw, 28vh), 24rem);
    font-stretch: 75%;
    text-shadow: var(--glow-gold);
    opacity: 0;
}

/* ---------- Birthday Game: days ---------- */

.day-stage {
    position: relative;
    display: grid;
    justify-items: center;
    gap: var(--space-4);
    width: 100%;
    max-width: 104rem;
}

.day-main {
    display: grid;
    justify-items: center;
    gap: clamp(.25rem, 1vh, .75rem);
    min-width: 0;
}

.day-side {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
    border-radius: var(--radius-l);
    background: rgb(17 24 39 / .7);
    box-shadow: inset 0 0 0 1px var(--line);
}

.day-grid {
    grid-template-columns: repeat(7, 2.35rem);
    gap: .3rem;
}

.day-grid .chip {
    min-height: 2.35rem;
    border-radius: .5rem;
    font-size: .875rem;
}

.day-grid .chip.is-latest::after {
    display: none;
}

/* On a wide screen the number owns the centre and the calendar stands to one side. */
@media (min-width: 1280px) {
    .day-side {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
    }
}

@media (min-width: 900px) and (max-width: 1279px) {
    .day-stage {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
    }

    .reel-day {
        font-size: clamp(7rem, min(30vw, 34vh), 30rem);
    }
}

@media (max-width: 899px) {
    .day-grid {
        grid-template-columns: repeat(7, minmax(2.1rem, 2.6rem));
    }

    .reel-day {
        font-size: clamp(6rem, min(38vw, 21vh), 30rem);
    }

    .day-stage .stage-instruction {
        min-height: 0;
    }
}

/* ---------- Birthday Game: tie-breaker ---------- */

.tie {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    justify-items: center;
    align-self: stretch;
    gap: clamp(.25rem, 1vh, .75rem);
    width: 100%;
}

.tie-title {
    font-size: clamp(2.8rem, min(11vw, 14vh), 13rem);
    font-stretch: 75%;
    font-weight: 800;
    line-height: .9;
    text-transform: uppercase;
}

.tie-title.is-result {
    --glow: .35;
    color: var(--gold);
    text-shadow: 0 0 calc(var(--glow) * .55em) rgb(251 191 36 / calc(var(--glow) * .95));
}

.tie-coin {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: min(34vh, 70vw);
}

.tie .stage-instruction {
    max-width: 34ch;
    min-height: 0;
    font-size: clamp(1.15rem, 2.1vw, 1.9rem);
}

.tie-count {
    padding: .3rem .9rem;
    border-radius: var(--radius-pill);
    background: var(--slate-2);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--paper);
    font-size: .9375rem;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* ---------- Birthday Game: winner ---------- */

.winner {
    position: relative;
    display: grid;
    justify-items: center;
    gap: clamp(.75rem, 2.5vh, 2rem);
    width: 100%;
    max-width: 96rem;
}

/* Fixed to the screen, so the rays can be larger than the page without ever making it scroll.
   The wrapper is what the entrance timeline scales; the turning happens on the pseudo-element. */
.winner-rays {
    --rays: min(150vw, 150vh);
    position: fixed;
    left: 50%;
    top: 42%;
    z-index: -1;
    width: var(--rays);
    height: var(--rays);
    margin: calc(var(--rays) / -2) 0 0 calc(var(--rays) / -2);
    -webkit-mask-image: radial-gradient(closest-side, #000 8%, transparent 72%);
    mask-image: radial-gradient(closest-side, #000 8%, transparent 72%);
    pointer-events: none;
}

.winner-rays::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: repeating-conic-gradient(from 0deg, rgb(251 191 36 / .16) 0deg 6deg, transparent 6deg 18deg);
    animation: rays-turn 60s linear infinite;
}

@keyframes rays-turn {
    to {
        transform: rotate(360deg);
    }
}

.winner-title {
    --glow: .6;
    color: var(--gold);
    font-size: clamp(4rem, min(12.5vw, 22vh), 18rem);
    font-stretch: 75%;
    font-weight: 800;
    line-height: .86;
    text-shadow: 0 0 calc(var(--glow) * .5em) rgb(251 191 36 / calc(var(--glow) * .9));
    text-transform: uppercase;
    text-wrap: balance;
    overflow-wrap: anywhere;
}

.winner-sub {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 3.6vw, 3.5rem);
    font-weight: 600;
}

.winner-name {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: center;
    gap: var(--space-3);
    margin-top: var(--space-3);
}

.winner-name label {
    display: grid;
    gap: var(--space-1);
    color: var(--mist);
    font-size: .875rem;
    text-align: left;
}

.winner-name input {
    width: min(18rem, 70vw);
    min-height: 3rem;
    padding: 0 var(--space-4);
    border: 0;
    border-radius: var(--radius-m);
    background: var(--slate);
    box-shadow: inset 0 0 0 1px var(--line-strong);
    color: var(--paper);
    font-size: 1.0625rem;
}

.winner-name input::placeholder {
    color: rgb(148 163 184 / .7);
}

/* The form is for the host; on the big screen it stays out of the picture until needed. */
@media (hover: hover) {
    .app.is-presenting .winner-name {
        opacity: .25;
        transition: opacity var(--dur-slow) var(--ease-out);
    }

    .app.is-presenting .winner-name:hover,
    .app.is-presenting .winner-name:focus-within {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .winner-rays::before,
    .reel-value.is-idle {
        animation: none;
    }
}
