/* ============================================================
   Medieval Solutions — the TV stage (tv.html, and a host device used as
   the shared screen). A 16:9 party screen: banner across the top, the
   council down the left, the stage in the middle, the chronicle of the
   town down the right, a ticker along the bottom. Everything scales with
   the viewport so it reads from the sofa on a laptop or a living-room TV.
   ============================================================ */

body.on-stage { margin: 0; overflow: hidden; background: var(--paper); }
.st {
    --u: min(1vw, 1.78vh);   /* one "unit": 1% of a 16:9 screen's width */
    /* Text read from the sofa (the council's names, the town line, the chronicle): --u, enlarged.
       It grows with the screen like everything else; later, the type scale's TV multiplier (BRAND.md). */
    --tv-text: calc(1.2 * var(--u));
    position: fixed; inset: 0;
    display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
    font-family: var(--font-ui); color: var(--ink);
    background:
        radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, .6), rgba(255, 255, 255, 0) 60%),
        var(--paper);
}
.st.shake { animation: screenShake .4s ease; }

/* ── Banner ── */
.st-banner {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: calc(2 * var(--u));
    padding: calc(1.1 * var(--u)) calc(2 * var(--u));
    background: var(--parch); border-bottom: calc(.3 * var(--u)) solid var(--parch-brd);
    box-shadow: 0 calc(.4 * var(--u)) 0 var(--tan);
}
.st-town { display: flex; align-items: center; gap: calc(1 * var(--u)); min-width: 0; }
.st-town .icon { width: calc(3.2 * var(--u)); height: calc(3.2 * var(--u)); }
.st-town b { display: block; font-family: var(--font-pixel); font-weight: normal; color: var(--red); font-size: calc(2.2 * var(--u)); line-height: 1.1; }
.st-town span { display: block; font-size: calc(1.15 * var(--tv-text)); color: var(--ink2); }
.st-town.unroll { animation: unroll .8s cubic-bezier(.3, 1.4, .5, 1) both; transform-origin: left; }
.st-round { text-align: center; font-family: var(--font-pixel); color: var(--red); font-size: calc(2.6 * var(--u)); line-height: 1; }
.st-round small { display: block; font-family: var(--font-ui); color: var(--ink2); font-size: calc(1.1 * var(--u)); margin-top: calc(.4 * var(--u)); }
.st-join { justify-self: end; display: flex; align-items: center; gap: calc(1 * var(--u)); font-size: calc(1.1 * var(--u)); color: var(--ink2); text-align: right; }
.st-join b { display: block; font-size: calc(2.2 * var(--u)); letter-spacing: calc(.4 * var(--u)); color: var(--red); }
.st-join img { width: calc(5.2 * var(--u)); height: calc(5.2 * var(--u)); border-radius: calc(.5 * var(--u)); background: #fff; padding: calc(.3 * var(--u)); border: 2px solid var(--tan); }

/* ── Main: council | stage | chronicle ── */
.st-main { display: grid; grid-template-columns: calc(20 * var(--u)) 1fr calc(21 * var(--u)); min-height: 0; }

.st-council { padding: calc(1.6 * var(--u)) calc(1.2 * var(--u)); display: flex; flex-direction: column; gap: calc(1.1 * var(--u)); overflow-y: auto; min-height: 0; }
.st-council h3, .st-chron h3 {
    margin: 0 0 calc(.4 * var(--u)); font-family: var(--font-pixel); font-weight: normal;
    color: var(--ink2); font-size: calc(1.4 * var(--u)); text-align: center;
}
.st-seat { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: calc(.4 * var(--u)) calc(1.8 * var(--u)); position: relative; }
.st-seat .av { --av: calc(4.6 * var(--u)); grid-row: span 2; }
.st-seat .nm { font-size: calc(1.35 * var(--tv-text)); font-weight: bold; color: var(--acc); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-seat .ms-pips { gap: calc(.35 * var(--u)); }
.st-seat .ms-pip { width: calc(1 * var(--u)); height: calc(1 * var(--u)); border-width: calc(.2 * var(--u)); }
.st-seat .badge { position: absolute; left: calc(3.4 * var(--u)); top: calc(-.6 * var(--u)); width: calc(2 * var(--u)); height: calc(2 * var(--u)); image-rendering: pixelated; animation: stamp .45s cubic-bezier(.3, 1.6, .5, 1) both; }
.st-seat.troubler .av { box-shadow: 0 0 0 calc(.3 * var(--u)) var(--paper), 0 0 0 calc(.6 * var(--u)) var(--red); }
.st-seat.dim .av { opacity: .5; }
.st-seat.speaking .av { box-shadow: 0 0 0 calc(.3 * var(--u)) var(--paper), 0 0 0 calc(.6 * var(--u)) var(--gold), 0 0 calc(2 * var(--u)) calc(.6 * var(--u)) var(--glow); translate: calc(.6 * var(--u)) 0; }
.st-seat.pop .av { animation: pop .8s ease; }

.st-stage { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: safe center; text-align: center; padding: calc(1.5 * var(--u)); min-height: 0; overflow-y: auto; }

/* Drift (stage.js): parts that outgrow the screen scroll themselves; no scrollbars on a TV.
   With reduced motion nothing drifts, so the scrollbars stay. A resting panel is cut short to
   end on whole items (stage.js sets its max-height, padding included). */
.st-stage, .st-council, .st-chron { box-sizing: border-box; }
@media (prefers-reduced-motion: no-preference) {
    .st-stage, .st-council, .st-chron { scrollbar-width: none; }
    .st-stage::-webkit-scrollbar, .st-council::-webkit-scrollbar, .st-chron::-webkit-scrollbar { display: none; }
}
.overflowing { -webkit-mask-image: linear-gradient(transparent, #000 5%, #000 95%, transparent); mask-image: linear-gradient(transparent, #000 5%, #000 95%, transparent); }
.st-stage.enter > * { animation: rise .55s ease both; }
.st-stage h1 { margin: 0 0 calc(.8 * var(--u)); font-family: var(--font-pixel); font-weight: normal; color: var(--red); font-size: calc(4 * var(--u)); line-height: 1.05; }
.st-stage h1 .who { font-family: var(--font-pixel); color: var(--acc); }
.st-stage h2 { margin: calc(.6 * var(--u)) 0; font-family: var(--font-pixel); font-weight: normal; color: var(--red); font-size: calc(2.2 * var(--u)); }
.st-stage .say { font-size: calc(1.8 * var(--u)); color: var(--ink2); margin: calc(.8 * var(--u)) 0; }
.st-stage .say b { color: var(--acc, var(--ink)); }

.st-card { width: calc(17 * var(--u)); }
.st-card.huge { width: calc(21 * var(--u)); }
.st-card.small { width: calc(11 * var(--u)); }
.st-pair { display: flex; gap: calc(2 * var(--u)); justify-content: center; }
.st-pair .flip-card { width: calc(17 * var(--u)); }
.st-pair .flip-card.flipped .flip-inner { box-shadow: none; }
.st-row { display: flex; gap: calc(1.6 * var(--u)); justify-content: center; align-items: flex-end; flex-wrap: wrap; }
.st-row:has(.st-trouble) { flex-wrap: nowrap; align-items: center; margin-bottom: calc(1.6 * var(--u)); }
.st-row:has(.st-trouble) > div:not(.st-trouble) { min-width: 0; text-align: left; }

.st-actor { display: flex; align-items: center; gap: calc(1.2 * var(--u)); }
.st-actor .av { --av: calc(7 * var(--u)); }
.st-actor .typing span { width: calc(.8 * var(--u)); height: calc(.8 * var(--u)); }

/* Solving: each councillor's face-down pair drops onto the table as they seal it. */
.st-sealed { display: flex; gap: calc(2 * var(--u)); justify-content: center; flex-wrap: wrap; margin-top: calc(1.5 * var(--u)); }
.st-sealed .who { display: flex; flex-direction: column; align-items: center; gap: calc(.5 * var(--u)); }
.st-sealed .who .av { --av: calc(3.6 * var(--u)); }
.st-sealed .backs { display: flex; height: calc(9 * var(--u)); align-items: flex-end; }
.st-sealed .backs img { width: calc(5.4 * var(--u)); border-radius: calc(.5 * var(--u)); image-rendering: pixelated; }
.st-sealed .backs img + img { margin-left: calc(-2.4 * var(--u)); transform: rotate(8deg); }
.st-sealed .backs.empty { opacity: .25; filter: grayscale(1); }
.st-sealed .backs.drop img { animation: slam .5s cubic-bezier(.5, 0, .75, 0) both; }
.st-sealed .backs.drop img + img { animation-delay: .1s; }

/* Judging: every pair laid out with its councillor. */
.st-pairs { display: grid; grid-template-columns: repeat(auto-fit, minmax(calc(15 * var(--u)), 1fr)); gap: calc(1.6 * var(--u)); width: 100%; max-width: calc(64 * var(--u)); }
.st-pairs .pr { display: flex; flex-direction: column; align-items: center; gap: calc(.6 * var(--u)); padding: calc(1 * var(--u)); border-radius: calc(1.2 * var(--u)); background: var(--bub); border: calc(.25 * var(--u)) solid var(--acc); }
.st-pairs .pr .av { --av: calc(3.6 * var(--u)); }
.st-pairs .pr .cards { display: flex; gap: calc(.6 * var(--u)); }
.st-pairs .pr .card { width: calc(6.6 * var(--u)); }
.st-pairs .pr.win { box-shadow: 0 0 0 calc(.4 * var(--u)) #ecbc34, 0 0 calc(3 * var(--u)) rgba(236, 188, 52, .9); }

/* Result */
/* The winner's goblin is drawn bigger than its circle: room above it, so it is never cut at the top. */
.st-crown { display: flex; align-items: center; gap: calc(2.4 * var(--u)); margin-top: calc(1 * var(--u)); }
.st-crown .av { --av: calc(12 * var(--u)); animation: pop .9s 1s ease both; }
.st-crown .fly-in { width: calc(12 * var(--u)); }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -4%; width: calc(1 * var(--u)); height: calc(1.4 * var(--u)); animation: fall linear forwards; }

/* Lobby: the council assembles */
.st-lobby { display: grid; grid-template-columns: auto 1fr; gap: calc(4 * var(--u)); align-items: center; width: 100%; max-width: calc(90 * var(--u)); }
.st-lobby .joinbox { text-align: center; background: #fff; border: calc(.3 * var(--u)) solid var(--tan); border-radius: calc(1.6 * var(--u)); padding: calc(2 * var(--u)); box-shadow: 0 calc(.6 * var(--u)) 0 var(--tan); }
.st-lobby .joinbox img { width: calc(22 * var(--u)); height: calc(22 * var(--u)); }
.st-lobby .joinbox .code { font-weight: bold; letter-spacing: calc(1 * var(--u)); font-size: calc(6 * var(--u)); color: var(--red); line-height: 1.1; }
.st-lobby .joinbox .url { font-size: calc(1.2 * var(--u)); color: var(--ink2); word-break: break-all; max-width: calc(24 * var(--u)); }
.st-lobby .gathered { display: flex; flex-wrap: wrap; gap: calc(2 * var(--u)) calc(2.6 * var(--u)); justify-content: center; }
.st-lobby .gathered .g { display: flex; flex-direction: column; align-items: center; gap: calc(.6 * var(--u)); font-size: calc(1.5 * var(--u)); font-weight: bold; color: var(--acc); animation: bob 2.8s ease-in-out infinite; }
.st-lobby .gathered .g .av { --av: calc(8 * var(--u)); }
.st-lobby .gathered .g.arrive { animation: slam .55s cubic-bezier(.5, 0, .75, 0) both; }
.st-lobby .empty { font-size: calc(1.8 * var(--u)); color: var(--ink3); }
.st-host-btn { margin-top: calc(2 * var(--u)); font-size: calc(1.8 * var(--u)); padding: calc(1 * var(--u)) calc(3 * var(--u)); }

/* End: the coronation */
.st-end { display: flex; flex-direction: column; align-items: center; }
.st-end .throne { position: relative; margin-top: calc(5 * var(--u)); }   /* room for the crown and the goblin's head */
.st-end .throne .av { --av: calc(16 * var(--u)); }
.st-end .throne .icon { position: absolute; left: 50%; top: calc(-6 * var(--u)); transform: translateX(-50%); width: calc(8 * var(--u)); height: calc(8 * var(--u)); animation: crownDrop .9s .5s cubic-bezier(.3, 1.4, .5, 1) both; }
.st-end .trophies { display: flex; gap: calc(.8 * var(--u)); flex-wrap: wrap; justify-content: center; margin-top: calc(1 * var(--u)); }
.st-end .trophies .card { width: calc(7 * var(--u)); }

/* ── Chronicle ── */
.st-chron { padding: calc(1.6 * var(--u)) calc(1.4 * var(--u)); border-left: calc(.25 * var(--u)) dotted var(--tan); overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: calc(1 * var(--u)); }
.st-chron .entry { display: grid; grid-template-columns: auto 1fr; gap: calc(.8 * var(--u)); align-items: center; padding: calc(.8 * var(--u)); background: #fff; border: calc(.2 * var(--u)) solid var(--tan); border-radius: calc(1 * var(--u)); }
.st-chron .entry.new { animation: rise .6s ease both; }
.st-chron .entry .card { width: calc(5.4 * var(--u)); }
.st-chron .entry .rd { font-size: calc(1 * var(--tv-text)); color: var(--ink3); }
.st-chron .entry .won { display: flex; align-items: center; gap: calc(.6 * var(--u)); font-size: calc(1.2 * var(--tv-text)); color: var(--acc); font-weight: bold; overflow-wrap: anywhere; }
.st-chron .entry .won .av { --av: calc(2.6 * var(--u)); }
.st-chron .entry .mini { display: flex; gap: calc(.3 * var(--u)); margin-top: calc(.4 * var(--u)); }
.st-chron .entry .mini .card { width: calc(3 * var(--u)); }
.st-chron .none { font-size: calc(1.2 * var(--tv-text)); color: var(--ink3); text-align: center; }

/* ── Ticker ── */
.st-ticker {
    display: flex; align-items: center; gap: calc(1.2 * var(--u));
    padding: calc(.8 * var(--u)) calc(2 * var(--u)); border-top: calc(.25 * var(--u)) solid var(--tan);
    font-size: calc(1.6 * var(--u)); color: var(--ink2); background: rgba(255, 255, 255, .5);
}
/* The Town Crier reads each line, as he narrates the example and the demo (example.css). A stand-in (#70):
   a dressed Mav replaces him later (#78); naked Mav is never shown in play. */
.st-ticker .crier { --av: calc(3.6 * var(--u)); --bub: var(--parch); --acc: var(--ink3); flex: none; }
.st-ticker .crier .toot { position: absolute; right: calc(-.8 * var(--u)); top: calc(-.5 * var(--u)); font-style: normal; font-size: calc(1.1 * var(--u)); color: var(--red); line-height: 1; opacity: 0; pointer-events: none; }
/* The notes are drawn by CSS, so the status line's text stays the line alone. */
.st-ticker .crier .toot::before { content: '♪'; }
.st-ticker .crier .toot::after { content: '♫'; position: absolute; left: calc(.8 * var(--u)); top: calc(-.6 * var(--u)); }
.st-ticker .crier.tooting .toot { animation: st-toot 1.1s .1s ease-out both; }
@keyframes st-toot { 0% { opacity: 0; translate: 0 calc(.3 * var(--u)); } 25% { opacity: 1; } 100% { opacity: 0; translate: calc(.5 * var(--u)) calc(-1 * var(--u)); } }
@media (prefers-reduced-motion: reduce) { .st-ticker .crier .toot { display: none; } }
.st-ticker .t { animation: rise .5s ease both; }
/* The line going out (stage.js renderTicker): it eases away before the next one rises. */
.st-ticker .t.out { animation: tick-out .3s ease both; }
@keyframes tick-out { to { opacity: 0; translate: 0 calc(-.6 * var(--u)); } }
.st-ticker .t b { color: var(--purple); }

@keyframes screenShake { 0%, 100% { transform: none; } 20% { transform: translate(-.4%, .3%); } 40% { transform: translate(.4%, -.2%); } 60% { transform: translate(-.2%, .2%); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@keyframes crownDrop { from { opacity: 0; transform: translate(-50%, -120%) rotate(-25deg); } }

/* Away councillors fade out of the council until they rejoin or the host removes them. */
.st-seat.away .av { opacity: .35; filter: grayscale(1); }
.st-seat.away .nm::after { content: ' · away'; color: var(--ink3); font-weight: normal; }
.st-seat .kick {
    grid-column: 2; justify-self: start; margin: 0; padding: calc(.2 * var(--u)) calc(.8 * var(--u));
    font: bold calc(1 * var(--u)) var(--font-ui); color: #fff; background: var(--red); border: 0; border-radius: 999px; cursor: pointer;
}

/* A big council (seven or more): everything in the side column and the judging grid packs tighter. */
.st.crowd .st-council { gap: calc(.45 * var(--u)); padding-top: calc(1 * var(--u)); }
.st.crowd .st-seat { gap: calc(.15 * var(--u)) calc(.9 * var(--u)); }
.st.crowd .st-seat .av { --av: calc(3.2 * var(--u)); }
.st.crowd .st-seat .nm { font-size: calc(1.1 * var(--tv-text)); }
.st.crowd .st-seat .ms-pip { width: calc(.8 * var(--u)); height: calc(.8 * var(--u)); }
.st.crowd .st-seat .badge { left: calc(2.4 * var(--u)); width: calc(1.6 * var(--u)); height: calc(1.6 * var(--u)); }
.st.crowd .st-pairs { grid-template-columns: repeat(auto-fit, minmax(calc(12 * var(--u)), 1fr)); gap: calc(1 * var(--u)); max-width: none; }
.st.crowd .st-pairs .pr { padding: calc(.6 * var(--u)); gap: calc(.4 * var(--u)); }
.st.crowd .st-pairs .pr .av { --av: calc(2.6 * var(--u)); }
.st.crowd .st-pairs .pr .card { width: calc(4.6 * var(--u)); }
.st-council > *, .st-chron > *, .st-stage > * { flex-shrink: 0; }

/* The trouble card, kept on the table beside the council's answers. */
.st-trouble { display: flex; flex-direction: column; align-items: center; gap: calc(.4 * var(--u)); flex-shrink: 0; }
.st-trouble span { font-family: var(--font-pixel); color: var(--red); font-size: calc(1.4 * var(--u)); }
.st-trouble .st-card { width: calc(10 * var(--u)); rotate: -3deg; }
.st-pair .st-trouble { align-self: center; margin-right: calc(2 * var(--u)); }
.st-pair .st-trouble .st-card { width: calc(12 * var(--u)); }
.st.crowd .st-row .st-trouble .st-card { width: calc(7.5 * var(--u)); }

.st-real-deck { margin-top: 2.4vh; font-size: calc(1.6 * var(--u)); color: var(--ink2); }
.st-real-deck b { color: var(--red); }

/* "Spoken as": the names the Troubler or a presenter says, when the cards show other languages */
.st-stage .spoken-as { max-width: none; margin: calc(.6 * var(--u)) auto 0; font-size: calc(1.7 * var(--u)); color: var(--ink2); text-align: center; line-height: 1.25; }
.st-stage .spoken-as b { color: var(--red); font-family: var(--font-pixel); font-weight: normal; font-size: calc(2.1 * var(--u)); }
.st-trouble .spoken-as { max-width: calc(16 * var(--u)); margin-top: calc(.3 * var(--u)); font-size: calc(1.3 * var(--u)); }
.st-trouble .spoken-as b { font-size: calc(1.6 * var(--u)); }

/* Reduced motion. components.css already stops every animation; here the moments that
   carry news (the trouble landing, solutions sealed, a new chronicle entry, the winner
   and the champion) fade in quickly instead, and the confetti stays home. */
@media (prefers-reduced-motion: reduce) {
    .confetti { display: none; }
    .st-card.slam, .st-sealed .backs.drop img, .st-lobby .gathered .g.arrive, .st-stage.enter > *,
    .st-chron .entry.new, .st-crown .fly-in, .st-end .throne .icon { animation: fade-in .25s ease both !important; }
}

/* The pitch timer, beside the name of whoever has the floor, and the debrief that ends a session's game */
.st-timer { font-family: var(--font-pixel); font-size: calc(3.6 * var(--u)); color: var(--ink); }
.st-timer.low { color: var(--red); }
.st-timer.up { color: var(--red); font-size: calc(2 * var(--u)); animation: timerNudge 1s ease-in-out infinite; }
@keyframes timerNudge { 50% { opacity: .55; } }
.st-debrief { max-width: calc(70 * var(--u)); margin-top: calc(1.4 * var(--u)); text-align: left; }
.st-debrief h2 { font-family: var(--font-pixel); font-size: calc(2.2 * var(--u)); margin: 0 0 calc(.4 * var(--u)); }
.st-debrief ol { margin: 0; padding-left: calc(3 * var(--u)); font-size: calc(1.8 * var(--u)); line-height: 1.3; }
@media (prefers-reduced-motion: reduce) { .st-timer.up { animation: none; } }
