/* Bytey's Helpdesk – design system and styles shared by player, game master and projector screens.
   Order: fonts → tokens → base → components → player screens → game → responsive. */

/* ============ Fonts (local, no CDN: the stand runs offline) ============ */
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 200 1000; font-display: swap; src: url("../fonts/nunito-latin-wght-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Nunito"; font-style: normal; font-weight: 200 1000; font-display: swap; src: url("../fonts/nunito-latin-ext-wght-normal.woff2") format("woff2"); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

/* ============ Tokens ============ */
:root {
  /* colour: ink and paper */
  --ink: #14213D;
  --ink-2: #2B3756;
  --muted: #4A5878;
  --paper: #F4F6FB;
  --card: #FCFDFF;
  --line: #CBD3E6;
  --edge: #14213D;          /* comic outline for "sticker" elements */
  --soft: #F0F3FA;
  --soft-2: #E6ECFA;
  --accent-soft: #DCE5FF;
  --field: #FFFFFF;
  --dots: rgba(20, 33, 61, .07);
  /* colour: brand and status */
  --cobalt: #2F5BFF;
  --cobalt-2: #1E44D6;
  --link: #2243D1;
  --green: #1F9D55;
  --green-soft: #DDF5E7;
  --green-ink: #13663A;
  --red: #D9344A;
  --red-2: #B92539;
  --red-soft: #FBE3E7;
  --red-ink: #9B1C2E;
  --amber: #F2A33A;
  --amber-2: #E08F20;
  --amber-soft: #FFF1DB;
  --amber-ink: #8A5300;
  --good-bg: #F2FBF6;
  --bad-bg: #FFF6F7;
  --hint-bg: #FFFAF0;
  /* HUD (always dark) */
  --hud: #14213D;
  --hud-line: #44557E;
  --hud-hover: #22325A;
  --hud-muted: #AFC0E4;
  /* scene */
  --stage-bg: #DCE4F0;
  --wall-1: #EEF3FA;
  --wall-2: #CDD8E8;
  --desk-1: #D7AA7A;
  --desk-2: #C08B57;
  --floor: #AEB8CC;
  /* type scale */
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --fs-xs: .78rem;
  --fs-sm: .9rem;
  --fs-md: 1rem;
  --fs-lg: 1.2rem;
  --fs-xl: 1.6rem;
  --fs-2xl: clamp(1.9rem, 4.5vw, 2.6rem);
  /* spacing scale (4px base) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
  /* shape and depth */
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-pill: 999px;
  --radius: var(--r-lg);
  --shadow: 0 2px 10px rgba(20, 33, 61, .08);
  --shadow-pop: 0 14px 40px rgba(20, 33, 61, .25);
  --sticker: 0 4px 0 var(--edge);          /* hard comic shadow */
  --focus: #1E44D6;
  --tap: 44px;                             /* minimum click target */
  color-scheme: light;
}
:root[data-theme="dark"] {
  --ink: #E8EEFF;
  --ink-2: #C5D1F0;
  --muted: #A3B2D4;
  --paper: #0D1324;
  --card: #161F38;
  --line: #2C3A5E;
  --edge: #050914;
  --soft: #1E2947;
  --soft-2: #26345C;
  --accent-soft: #2B3F7C;
  --field: #0F172D;
  --dots: rgba(143, 170, 255, .07);
  --cobalt: #3D66F5;
  --cobalt-2: #2F55DC;
  --link: #8FAAFF;
  --green: #3CCB7B;
  --green-soft: #153A2A;
  --green-ink: #7DE3A9;
  --red: #D9344A;
  --red-soft: #46202A;
  --red-ink: #FF9AA8;
  --amber: #F5B14F;
  --amber-soft: #43331A;
  --amber-ink: #FFCF8A;
  --good-bg: #123024;
  --bad-bg: #3A1B24;
  --hint-bg: #3A2E16;
  --hud: #09101F;
  --hud-line: #34456F;
  --hud-hover: #1B2848;
  --hud-muted: #9FB0D6;
  --stage-bg: #121A30;
  --wall-1: #1B2745;
  --wall-2: #121B33;
  --desk-1: #8E6A48;
  --desk-2: #6F4F32;
  --floor: #1A2440;
  --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  --shadow-pop: 0 14px 40px rgba(0, 0, 0, .55);
  --focus: #8FAAFF;
  color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); font-size: var(--fs-md); font-weight: 500; line-height: 1.45; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: var(--link); text-underline-offset: 2px; }
h1, h2, h3, h4 { line-height: 1.15; margin: 0 0 .5em; font-weight: 800; letter-spacing: -.01em; }
p { margin: 0 0 var(--sp-3); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

/* icons: one set (assets/icons.svg), inherits colour and scales with text */
.icon { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }
.icon.fill { fill: currentColor; stroke-width: 1.5; }

/* ============ Components ============ */
/* buttons: sticker look, pressed state moves the button into its shadow */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5em; min-height: var(--tap); padding: .55em 1.2em; border-radius: var(--r-md); border: 2px solid var(--edge); background: var(--cobalt); color: #fff; font-weight: 800; cursor: pointer; text-decoration: none; box-shadow: 0 3px 0 var(--edge); transition: transform .08s, box-shadow .08s, background .15s; }
.btn:hover { background: var(--cobalt-2); }
.btn:active:not([disabled]) { transform: translateY(3px); box-shadow: 0 0 0 var(--edge); }
.btn[disabled] { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }
.btn-ghost { background: var(--card); color: var(--ink); }
.btn-ghost:hover { background: var(--soft-2); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: var(--red-2); }
.btn-big { font-size: var(--fs-lg); min-height: 58px; padding: .7em 1.6em; border-radius: var(--r-lg); box-shadow: 0 4px 0 var(--edge); }
.btn-big:active:not([disabled]) { transform: translateY(4px); }
.btn-small { min-height: 36px; padding: .25em .9em; font-size: var(--fs-sm); border-radius: var(--r-sm); box-shadow: 0 2px 0 var(--edge); }
.btn-small:active:not([disabled]) { transform: translateY(2px); }
.icon-btn { width: var(--tap); padding: 0; }
.link-btn { display: inline-flex; align-items: center; gap: .35em; background: none; border: 0; padding: var(--sp-1) var(--sp-2); min-height: 32px; font: inherit; font-weight: 700; color: var(--link); text-decoration: underline; cursor: pointer; }

/* cards: calm panels by default; .menu-card, .level-card, .results are stickers */
.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: var(--sp-4) var(--sp-5); box-shadow: var(--shadow); }
.menu-card, .results, .report-dialog { border: 2px solid var(--edge); box-shadow: var(--sticker); }

/* forms */
.field { display: grid; gap: 6px; margin: 0 0 var(--sp-4); }
.field label { font-weight: 800; font-size: var(--fs-sm); }
.field input, .field select, .field textarea, .report-dialog select, .report-dialog textarea, .feedback-card input[type="text"] { width: 100%; min-height: 48px; padding: .5em .85em; border: 2px solid var(--line); border-radius: var(--r-md); background: var(--field); font-size: var(--fs-lg); font-weight: 600; transition: border-color .15s; }
.field input:hover, .field select:hover { border-color: var(--muted); }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .report-dialog select:focus-visible, .report-dialog textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.field input::placeholder { color: var(--muted); font-weight: 500; opacity: .75; }
.field small { font-weight: 500; }
.field input[aria-invalid="true"] { border-color: var(--red); }
.error-text { color: var(--red-ink); font-weight: 700; min-height: 1.4em; }
:root[data-theme="dark"] .error-text { color: var(--red-ink); }
.msg { min-height: 1.3em; }
.msg.ok { color: var(--green-ink); font-weight: 700; }

/* pills and status dots */
.pill { display: inline-flex; align-items: center; gap: .35em; padding: .15em .75em; border-radius: var(--r-pill); background: var(--soft-2); color: var(--ink-2); font-size: var(--fs-sm); font-weight: 750; }
.pill.green { background: var(--green-soft); color: var(--green-ink); }
.pill.red { background: var(--red-soft); color: var(--red-ink); }
.pill.amber { background: var(--amber-soft); color: var(--amber-ink); }
.dot { width: .65em; height: .65em; border-radius: 50%; background: var(--muted); opacity: .6; display: inline-block; flex: none; }
.dot.on { background: var(--green); opacity: 1; }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: var(--sp-5); transform: translateX(-50%); display: grid; gap: var(--sp-2); z-index: 80; width: min(520px, calc(100% - 32px)); pointer-events: none; }
.toast { background: var(--hud); color: #fff; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); border: 2px solid var(--edge); box-shadow: var(--shadow-pop); font-weight: 650; animation: toast-in .2s ease-out; }
.toast.ok { background: var(--green-ink); }
.toast.error { background: var(--red); }
:root[data-theme="dark"] .toast { background: #2B3A63; }
:root[data-theme="dark"] .toast.ok { background: #1E6B45; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { display: inline-flex; align-items: center; justify-content: center; gap: .45em; min-height: var(--tap); padding: .45em 1.1em; border-radius: var(--r-md) var(--r-md) 0 0; border: 2px solid var(--line); border-bottom: 0; background: var(--soft); color: var(--muted); font-weight: 800; cursor: pointer; transition: background .15s, color .15s; }
.tab:hover:not([disabled]):not([aria-selected="true"]) { background: var(--soft-2); color: var(--ink); }
.tab[aria-selected="true"] { background: var(--cobalt); border-color: var(--edge); color: #fff; }
.tab[disabled] { opacity: .5; cursor: not-allowed; }

/* tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: var(--sp-2) var(--sp-3); text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { color: var(--muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; }

/* lists with ranks and logs (player, game master, projector share them) */
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rank-list li { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); background: var(--soft); }
.rank-list li.me { background: var(--accent-soft); font-weight: 800; border-left: 5px solid var(--cobalt); }
.rank-list .r { font-weight: 900; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-list .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .s { font-variant-numeric: tabular-nums; font-weight: 800; }
.rank-list .sub { grid-column: 2 / 4; font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 360px; overflow: auto; font-size: var(--fs-sm); }
.log li { padding: 6px var(--sp-2); border-left: 4px solid var(--line); background: var(--soft); border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.log li.fixed, .log li.ticket { border-color: var(--green); }
.log li.nochange, .log li.blocked { border-color: var(--red); }
.log li.hint { border-color: var(--amber); }
.log .what { font-weight: 750; }
.log .delta { float: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.log .delta.plus { color: var(--green-ink); }
.log .delta.minus { color: var(--red-ink); }
/* empty state shared by every list */
ul li.empty, ol li.empty { display: block; grid-column: 1 / -1; background: none; border: 2px dashed var(--line); border-left-width: 2px; border-radius: var(--r-md); color: var(--muted); text-align: center; padding: var(--sp-4) var(--sp-3); font-weight: 650; }
.panel h3 { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: var(--sp-3); font-weight: 800; }

/* ============ Player screens ============ */
body { background-image: radial-gradient(var(--dots) 1.5px, transparent 1.6px); background-size: 22px 22px; }
.app { min-height: 100%; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; }
.center-view { align-items: center; justify-content: center; padding: var(--sp-6) var(--sp-4); text-align: center; }
.menu-card { width: min(520px, 100%); display: grid; gap: var(--sp-4); padding: var(--sp-6); }
.logo { display: flex; align-items: center; justify-content: center; gap: var(--sp-4); margin-bottom: var(--sp-1); }
.logo img { width: 76px; height: 76px; }
.logo h1 { font-size: var(--fs-2xl); margin: 0; font-weight: 900; line-height: 1; text-align: left; }
.logo h1 span { color: var(--link); display: block; }
.tagline { margin: 0; color: var(--muted); font-size: var(--fs-lg); font-weight: 650; }
.menu-buttons { display: grid; gap: var(--sp-3); margin-top: var(--sp-1); }
.menu-card h2 { margin: 0; font-size: var(--fs-xl); }
.footer { text-align: center; color: var(--muted); font-size: var(--fs-sm); padding: var(--sp-3); }
.footer-links { vertical-align: middle; display: inline-flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-1) var(--sp-3); margin-left: var(--sp-3); }
.page-head { text-align: center; margin-bottom: var(--sp-2); }
.page-head h2 { font-size: var(--fs-2xl); margin-bottom: var(--sp-1); }
.page-head p { margin: 0; }

.account-bar { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); align-items: center; justify-content: center; padding: var(--sp-2) var(--sp-3); background: var(--soft); border-radius: var(--r-md); }
.account-bar .who { display: inline-flex; align-items: center; gap: .4em; font-weight: 700; }
.auth-tabs { justify-content: center; }
.auth-tabs .tab { border-radius: var(--r-md); border-bottom: 2px solid var(--line); }
.auth-tabs .tab[aria-selected="true"] { border-bottom-color: var(--edge); }
#v-auth form, #join-form { text-align: left; }
#v-auth form .btn, #join-form .btn { width: 100%; }
#v-auth .tabs { margin-bottom: var(--sp-2); }
.profile { width: min(900px, 100%); display: grid; gap: var(--sp-4); text-align: left; }
.profile h2, .profile h3 { margin-top: 0; }
.inline-form { max-width: 420px; box-shadow: none; }

/* level selection */
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--sp-4); width: min(1040px, 100%); margin: var(--sp-4) auto; text-align: left; }
.level-card { display: grid; gap: var(--sp-3); align-content: start; cursor: pointer; border: 2px solid var(--edge); box-shadow: var(--sticker); transition: transform .12s, box-shadow .12s, background .15s; }
.level-card:hover:not(.locked) { transform: translateY(-2px); box-shadow: 0 6px 0 var(--edge); background: var(--accent-soft); }
.level-card:active:not(.locked) { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.level-card.locked { cursor: not-allowed; background: var(--soft); border-color: var(--line); box-shadow: none; }
.level-top { display: flex; align-items: center; gap: var(--sp-3); }
.level-top h3 { margin: 0; font-size: var(--fs-lg); }
.level-no { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--cobalt); color: #fff; font-weight: 900; border: 2px solid var(--edge); }
.level-card.locked .level-no { background: var(--soft-2); color: var(--muted); border-color: var(--line); }
.level-card .meta { display: flex; flex-wrap: wrap; gap: 6px; }
.level-desc { margin: 0; color: var(--muted); }
.level-card.locked .level-desc { color: var(--ink-2); }

/* lobby */
.lobby-list { list-style: none; padding: 0; margin: var(--sp-3) 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-2); text-align: left; }
.lobby-list li { display: flex; align-items: center; gap: 10px; padding: 10px var(--sp-3); border-radius: var(--r-md); background: var(--soft-2); font-weight: 700; }
.lobby-list li.me { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--cobalt); }
.bytey-wait { width: 96px; margin-inline: auto; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* results */
.results { width: min(760px, 100%); display: grid; gap: var(--sp-4); text-align: left; padding: var(--sp-5); background: var(--card); border-radius: var(--radius); }
.results .big { display: flex; align-items: center; gap: var(--sp-5); }
.results .big h2 { font-size: var(--fs-xl); }
.results .place { font-size: 4rem; font-weight: 900; color: var(--link); line-height: 1; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stats-grid div { background: var(--soft); border-radius: var(--r-md); padding: 10px var(--sp-3); }
.stats-grid small { display: block; color: var(--muted); font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.stats-grid b { font-size: var(--fs-xl); font-variant-numeric: tabular-nums; font-weight: 900; }
.fixed-list { margin: 0; padding-left: 1.2em; columns: 2; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* theme toggle and floating bug button */
.theme-fixed { position: fixed; top: var(--sp-3); right: var(--sp-3); z-index: 30; }
body:has(#v-game:not([hidden])) .theme-fixed { display: none; }
.fab-report { position: fixed; right: var(--sp-3); bottom: var(--sp-3); z-index: 20; width: var(--tap); height: var(--tap); border-radius: 50%; border: 2px solid var(--edge); background: var(--card); color: var(--ink); display: grid; place-items: center; cursor: pointer; box-shadow: 0 2px 0 var(--edge); }
.fab-report:hover { background: var(--soft-2); }
body:has(#v-game:not([hidden])) .fab-report { display: none; }
.report-dialog { padding: var(--sp-5); max-width: min(480px, calc(100vw - 32px)); width: 100%; background: var(--card); color: var(--ink); border-radius: var(--r-lg); }
.report-dialog::backdrop { background: rgba(10, 16, 32, .6); }
.report-dialog h2 { margin-top: 0; }
.report-dialog select, .report-dialog textarea { margin: 6px 0; font-size: var(--fs-md); }
.report-dialog .row-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-3); }

/* end-of-level feedback */
.feedback-card { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); padding: 10px var(--sp-4); border-radius: var(--r-md); background: var(--soft); }
.feedback-card input[type="text"] { flex: 1 1 200px; min-width: 0; min-height: 40px; font-size: var(--fs-md); }
.stars { display: flex; gap: 2px; }
.star { display: grid; place-items: center; width: 40px; height: 40px; background: none; border: 0; padding: 0; font-size: 1.6rem; cursor: pointer; color: var(--line); border-radius: var(--r-sm); }
.star .icon { stroke-width: 1.8; }
.star.on { color: var(--amber); }
.star.on .icon { fill: currentColor; }
.star:hover, .star:focus-visible { color: var(--amber); transform: scale(1.12); }

/* ============ Game ============ */
.hud { display: flex; flex-wrap: wrap; align-items: center; gap: 10px var(--sp-4); padding: 10px var(--sp-4); background: var(--hud); color: #fff; border-bottom: 3px solid var(--edge); }
.hud .brand { font-weight: 900; letter-spacing: -.01em; margin-right: auto; display: flex; align-items: center; gap: var(--sp-2); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud .brand img { width: 30px; height: 30px; flex: none; }
.hud .brand span { font-weight: 600; color: var(--hud-muted); overflow: hidden; text-overflow: ellipsis; }
.hud .stat { display: grid; line-height: 1.1; text-align: center; min-width: 70px; }
.hud .stat small { color: var(--hud-muted); font-size: var(--fs-xs); font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.hud .stat b { font-size: 1.5rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.hud .timer.low b { color: #FF8A98; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.hud .btn-ghost { background: transparent; color: #fff; border-color: var(--hud-line); box-shadow: none; }
.hud .btn-ghost:hover { background: var(--hud-hover); }
.hud .btn-ghost:active { transform: none; }
.hint-btn { background: var(--amber); color: #14213D; }
.hint-btn:hover { background: var(--amber-2); }

.game { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--sp-4); padding: var(--sp-4); max-width: 1500px; width: 100%; margin: 0 auto; }
.game-main { position: relative; display: flex; flex-direction: column; gap: var(--sp-3); align-content: start; min-width: 0; }
.game-side { display: grid; gap: var(--sp-3); align-content: start; }
.top-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: var(--sp-3); }

.ticket { padding: 0; overflow: hidden; }
.ticket-bar { display: flex; align-items: center; gap: var(--sp-2); padding: 6px var(--sp-4); background: var(--soft-2); border-bottom: 2px solid var(--line); font-weight: 800; font-size: var(--fs-sm); }
.ticket-bar .x { margin-left: auto; display: flex; gap: 6px; }
.ticket-bar .x i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); transition: background .3s, transform .3s; }
.ticket-bar .x i.done { background: var(--green); }
.ticket-bar .x i.now { background: var(--cobalt); transform: scale(1.25); }
.ticket-body { padding: var(--sp-3) var(--sp-4); }
.ticket-body .from { color: var(--muted); font-size: var(--fs-sm); font-weight: 650; }
.ticket-body .text { font-size: var(--fs-lg); font-weight: 800; margin: 2px 0 var(--sp-2); }
.ticket-body .note { font-size: var(--fs-sm); color: var(--ink-2); font-style: italic; margin: 0 0 var(--sp-2); padding-left: var(--sp-2); border-left: 3px solid var(--line); }
.progress { height: 10px; background: var(--soft-2); border-radius: var(--r-pill); overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--cobalt), #6C8CFF); border-radius: var(--r-pill); transition: width .4s; }
.ticket-steps { display: flex; justify-content: space-between; gap: var(--sp-2); color: var(--muted); font-size: var(--fs-sm); margin-top: 6px; }
.ticket.flash { animation: ticket-flash 1.4s ease-out; }
@keyframes ticket-flash { 0% { box-shadow: 0 0 0 0 var(--cobalt); transform: scale(1.03); } 40% { box-shadow: 0 0 0 8px rgba(47, 91, 255, .35); } 100% { box-shadow: var(--shadow); transform: none; } }

.bytey { display: flex; gap: var(--sp-3); align-items: flex-start; }
.bytey img { width: 64px; height: 64px; flex: none; }
.bubble { position: relative; flex: 1; background: var(--card); border: 2px solid var(--edge); border-radius: var(--r-lg); padding: var(--sp-3) var(--sp-4); min-height: 64px; box-shadow: 0 3px 0 var(--edge); }
.bubble::before { content: ''; position: absolute; left: -11px; top: 20px; border: 8px solid transparent; border-right-color: var(--edge); border-left: 0; }
.bubble::after { content: ''; position: absolute; left: -7px; top: 22px; border: 6px solid transparent; border-right-color: var(--card); border-left: 0; }
.bubble.good { background: var(--good-bg); }
.bubble.good::after { border-right-color: var(--good-bg); }
.bubble.bad { background: var(--bad-bg); }
.bubble.bad::after { border-right-color: var(--bad-bg); }
.bubble.hint { background: var(--hint-bg); }
.bubble.hint::after { border-right-color: var(--hint-bg); }
.bubble.good, .bubble.bad, .bubble.hint { border-width: 2px; }
.bubble.good { border-color: var(--green); } .bubble.good::before { border-right-color: var(--green); }
.bubble.bad { border-color: var(--red); } .bubble.bad::before { border-right-color: var(--red); }
.bubble.hint { border-color: var(--amber); } .bubble.hint::before { border-right-color: var(--amber); }
.bubble .who { display: block; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 800; }
.bubble.pop { animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.97); } }

.tip-pill { display: flex; align-items: center; gap: .6em; background: var(--cobalt); color: #fff; padding: .5em 1em; border-radius: var(--r-pill); font-weight: 700; box-shadow: var(--shadow); width: fit-content; max-width: 100%; transition: opacity .3s, max-height .3s; max-height: 80px; }
.tip-pill.gone { opacity: 0; max-height: 0; padding: 0; overflow: hidden; margin: -7px 0; }

.stage { position: relative; border-radius: var(--radius); overflow: hidden; border: 2px solid var(--edge); box-shadow: var(--sticker); background: var(--stage-bg); }
.tabs + .stage, .tabs + .stage + .win-view { border-top-left-radius: 0; }
.stage svg { display: block; width: 100%; height: auto; touch-action: manipulation; }

/* action menu: popover on desktop, bottom sheet on phones */
.menu-pop { position: fixed; z-index: 40; min-width: 250px; max-width: min(330px, calc(100vw - 24px)); background: var(--card); border: 2px solid var(--edge); border-radius: var(--r-lg); box-shadow: var(--shadow-pop), 0 4px 0 var(--edge); padding: 0 0 var(--sp-2); overflow: hidden; animation: toast-in .12s ease-out; }
.menu-head { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px var(--sp-3); background: var(--accent-soft); margin-bottom: var(--sp-1); }
.menu-head b { display: block; font-size: var(--fs-md); font-weight: 800; }
.menu-head small { display: block; color: var(--muted); font-size: var(--fs-sm); line-height: 1.25; font-weight: 600; }
.menu-head .menu-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: var(--r-md); background: var(--card); border: 2px solid var(--edge); font-size: 1.15rem; }
.menu-head .menu-close { width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: none; cursor: pointer; color: var(--muted); border-radius: var(--r-sm); align-self: start; margin: -4px -6px 0 0; }
.menu-head .menu-close:hover { background: var(--soft-2); color: var(--ink); }
.menu-pop .grp { margin: var(--sp-2) var(--sp-3) 2px; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; }
.menu-pop .act { display: flex; width: calc(100% - 12px); margin: 2px 6px; align-items: center; gap: 10px; min-height: var(--tap); text-align: left; border: 2px solid transparent; background: transparent; border-radius: var(--r-md); padding: var(--sp-2) 10px; cursor: pointer; font-weight: 700; }
.menu-pop .act:hover, .menu-pop .act:focus-visible { background: var(--soft-2); border-color: var(--cobalt); outline: none; }
.menu-pop .act .ico { width: 28px; height: 28px; flex: none; border-radius: var(--r-sm); display: grid; place-items: center; font-size: .95rem; }
.menu-pop .act.inspect .ico { background: var(--soft-2); }
.menu-pop .act.change .ico { background: var(--amber-soft); color: var(--amber-ink); }
.menu-pop .act small { display: block; color: var(--muted); font-weight: 500; font-size: var(--fs-xs); }
.menu-pop .act.switch { background: var(--cobalt); color: #fff; margin-top: 6px; }
.menu-pop .act.switch:hover { background: var(--cobalt-2); }
.menu-pop .act.switch .ico { background: rgba(255, 255, 255, .2); }
.menu-pop.sheet { left: 0; right: 0; bottom: 0; top: auto; max-width: none; min-width: 0; max-height: 65vh; overflow: auto; border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

/* Windows view (monitor close-up) */
.win-view { display: grid; gap: var(--sp-3); max-width: 760px; margin-inline: auto; width: 100%; }
.win-frame { aspect-ratio: 310 / 222; overflow: hidden; border-radius: 10px; margin: 10px; box-shadow: 0 0 0 10px #1E2A44, 0 0 0 12px #14213D, var(--shadow); background: #000; }
.win-view.zoom .win-frame { animation: win-zoom .55s cubic-bezier(.2, .8, .2, 1); }
@keyframes win-zoom { from { transform: scale(.42) translateY(8%); opacity: .35; } }
.win-fit { width: 310px; height: 222px; transform: scale(var(--s, 1)); transform-origin: top left; }
.win-view .screen { width: 310px; height: 222px; overflow: hidden; font-family: var(--font); font-size: 13px; line-height: 1.3; }
.win-tools { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: stretch; }
.win-note { flex: 1 0 100%; font-weight: 700; }
.win-tools .win-act { width: auto; flex: 1 1 220px; margin: 0; background: var(--card); border: 2px solid var(--line); box-shadow: var(--shadow); }
.win-tools .win-act:hover:not([disabled]) { border-color: var(--cobalt); background: var(--soft-2); }
.win-tools .win-act[disabled] { opacity: .5; cursor: not-allowed; }
.win-tools .win-act .ico { background: var(--soft-2); }
.stage.swap, .win-view.swap { animation: stage-swap .7s ease-out; }
@keyframes stage-swap { 0% { opacity: 0; transform: translateY(14px) scale(.98); } 100% { opacity: 1; transform: none; } }

/* next-ticket banner */
.ticket-banner { position: absolute; z-index: 25; left: 50%; top: 52%; width: min(560px, calc(100% - 24px)); transform: translate(-50%, -50%); background: var(--card); border: 2px solid var(--edge); border-radius: var(--r-lg); padding: var(--sp-4) var(--sp-5); box-shadow: var(--shadow-pop), 0 5px 0 var(--edge); display: grid; gap: 6px; text-align: left; }
.ticket-banner[hidden] { display: none; }
.ticket-banner.show { animation: banner-in .45s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes banner-in { from { opacity: 0; transform: translate(-50%, -70%) scale(.92); } }
.tb-done { display: inline-flex; align-items: center; gap: .4em; color: var(--green-ink); background: var(--green-soft); border-radius: var(--r-md); padding: 4px 10px; font-weight: 800; width: fit-content; }
.tb-next { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.tb-count { background: var(--cobalt); color: #fff; border-radius: var(--r-pill); padding: 2px 10px; font-weight: 800; font-size: var(--fs-sm); }
.tb-next b { font-size: var(--fs-lg); }
.tb-text { font-size: var(--fs-md); }
.ticket-banner .btn { justify-self: end; }

/* side panels */
.rank-list.compact li { padding: 5px var(--sp-2); }
.float-score { position: fixed; z-index: 60; font-weight: 900; font-size: 1.7rem; pointer-events: none; animation: float-up 1.2s ease-out forwards; text-shadow: 0 2px 0 var(--card), 0 -2px 0 var(--card), 2px 0 0 var(--card), -2px 0 0 var(--card); }
.float-score.plus { color: var(--green-ink); }
.float-score.minus { color: var(--red); }
@keyframes float-up { to { transform: translateY(-70px); opacity: 0; } }

.overlay { position: fixed; inset: 0; z-index: 70; background: rgba(10, 16, 32, .8); display: grid; place-items: center; color: #fff; text-align: center; padding: var(--sp-4); }
.overlay .count { font-size: clamp(6rem, 22vw, 14rem); font-weight: 900; line-height: 1; animation: pop .4s ease-out; text-shadow: 0 6px 0 var(--edge); }
.overlay .banner { background: var(--card); color: var(--ink); border: 2px solid var(--edge); border-radius: var(--r-lg); padding: var(--sp-5) var(--sp-6); box-shadow: var(--sticker); max-width: 520px; animation: pop .25s ease-out; }
.overlay .banner h2 { font-size: 2rem; }

/* The running game is always exactly one screen high and never scrolls */
body:has(#v-game:not([hidden])) { overflow: hidden; background-image: none; }
#v-game:not([hidden]) { flex: none; height: 100dvh; min-height: 0; overflow: hidden; }
#v-game .hud { flex: none; padding: 6px var(--sp-4); gap: 6px var(--sp-4); flex-wrap: nowrap; }
#v-game .hud .stat b, #v-game .hud .timer b { font-size: 1.4rem; }
#v-game .game { flex: 1; min-height: 0; padding: 10px var(--sp-4); gap: var(--sp-3); grid-template-columns: minmax(0, 1fr) 270px; grid-template-rows: minmax(0, 1fr); }
#v-game .game-main { gap: var(--sp-2); min-height: 0; }
#v-game .game-main > .tabs { flex: none; }
#v-game .top-row { flex: none; gap: 10px; }
#v-game .ticket-bar { padding: 4px var(--sp-3); font-size: var(--fs-xs); }
#v-game .ticket-body { padding: var(--sp-2) 14px 10px; }
#v-game .ticket-body .text { font-size: var(--fs-md); margin: 2px 0 var(--sp-2); }
#v-game .ticket-body .from, #v-game .ticket-steps { font-size: var(--fs-xs); }
#v-game .ticket-body .note { font-size: var(--fs-xs); margin-bottom: 6px; }
#v-game .bytey img { width: 48px; height: 48px; }
#v-game .bubble { min-height: 0; padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); line-height: 1.3; }
#v-game .tip-pill { flex: none; font-size: var(--fs-sm); padding: .35em .9em; }
#v-game .tab { min-height: 38px; padding: .3em 1em; }
#v-game .stage { flex: 1; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
#v-game .stage svg { width: 100%; height: 100%; min-height: 0; }
#v-game .win-view { flex: 1; min-height: 0; max-width: none; grid-template-rows: minmax(0, 1fr) auto; gap: var(--sp-2); }
#v-game .win-frame { height: calc(100% - 24px); max-width: calc(100% - 24px); aspect-ratio: 310 / 222; justify-self: center; align-self: center; margin: 12px; }
#v-game .win-tools .win-act { flex: 1 1 180px; min-height: 40px; }
#v-game .game-side { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
#v-game .game-side .panel { padding: 10px var(--sp-3); min-height: 0; overflow: hidden; }
#v-game .game-side #rank-panel { flex: none; max-height: 45%; }
#v-game .game-side .panel:last-child { flex: 1; display: flex; flex-direction: column; }
#v-game .panel h3 { margin-bottom: 6px; flex: none; }
#v-game .rank-list { gap: 4px; }
#v-game .rank-list li { padding: 5px var(--sp-2); }
#v-game .log { align-content: start; flex: 1; min-height: 0; max-height: none; overflow: hidden; gap: 4px; }
#v-game .log li { padding: 4px var(--sp-2); font-size: var(--fs-xs); }
#v-game .log li.empty { padding: var(--sp-3); font-size: var(--fs-sm); }

/* ============ Responsive ============ */
@media (max-width: 1100px) {
  .game { grid-template-columns: 1fr; }
  .game-side { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-height: 820px) {
  #v-game .tip-pill { display: none; }
  .center-view { padding: var(--sp-3) var(--sp-4); }
  .menu-card { padding: var(--sp-5); gap: var(--sp-3); }
  .logo img { width: 60px; height: 60px; }
  .level-grid { gap: 10px; margin: var(--sp-2) auto; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); }
  .level-card { padding: 10px 14px; gap: 6px; }
  .level-card.locked .level-desc { display: none; }
  .bytey-wait { width: 64px; }
  .lobby-list { margin: var(--sp-2) 0; gap: 6px; }
  .lobby-list li { padding: 6px var(--sp-3); }
}
@media (max-width: 900px) {
  #v-game .game { grid-template-columns: minmax(0, 1fr); padding: var(--sp-2); }
  #v-game .game-side { display: none; }
}
@media (max-width: 720px) {
  .top-row { grid-template-columns: 1fr; }
  .fixed-list { columns: 1; }
  .menu-card { padding: var(--sp-4); }
  .results .big { flex-direction: column; text-align: center; }
  .results { padding: var(--sp-4); }
  /* phone HUD: row 1 = brand + tools, row 2 = three stats + hint */
  #v-game .hud { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto auto auto; gap: 6px var(--sp-2); padding: 6px var(--sp-2); align-items: center; }
  #v-game .hud .brand { grid-column: 1 / 4; grid-row: 1; margin: 0; }
  #v-game .hud .theme-toggle { grid-column: 4; grid-row: 1; }
  #v-game .hud #g-mute { grid-column: 5; grid-row: 1; }
  #v-game .hud #g-leave { grid-column: 6; grid-row: 1; }
  #v-game .hud .timer { grid-column: 1; grid-row: 2; }
  #v-game .hud .stat:nth-of-type(3) { grid-column: 2; grid-row: 2; }
  #v-game .hud .stat:nth-of-type(4) { grid-column: 3; grid-row: 2; }
  #v-game .hud .hint-btn { grid-column: 4 / 7; grid-row: 2; padding-inline: .6em; font-size: var(--fs-sm); min-height: 40px; }
  #v-game .hud .stat { min-width: 0; }
  #v-game .hud .stat b, #v-game .hud .timer b { font-size: 1.2rem; }
  #v-game .hud .icon-btn { width: 40px; min-height: 40px; }
  #v-game .top-row { grid-template-columns: 1fr; }
  #v-game .bytey { display: none; }
  #v-game .tabs { flex-wrap: nowrap; }
  #v-game .tab { flex: 1 1 0; min-width: 0; padding: .3em .4em; font-size: var(--fs-sm); gap: .3em; }
  #v-game .tab .icon { width: 1.1em; height: 1.1em; }
  #v-game .ticket-steps #t-cat { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .ticket.flash, .stage.swap, .win-view.swap, .ticket-banner.show { animation: none; }
}

/* online lobbies */
.hub { max-width: 560px; }
.hub-block { text-align: left; margin: var(--sp-4) 0; padding-top: var(--sp-3); border-top: 2px dashed var(--line); }
.hub-block h3 { margin: 0 0 var(--sp-2); }
.hub .check, .host-box .check { display: flex; align-items: center; gap: 10px; font-weight: 700; margin: 0 0 var(--sp-3); }
.hub .check input, .host-box .check input { width: 22px; height: 22px; accent-color: var(--cobalt); }
.hub-code-row { display: flex; gap: var(--sp-2); }
.code-input, .field input.code-input { flex: 1; min-width: 0; min-height: 48px; padding: .5em .85em; border: 2px solid var(--line); border-radius: var(--r-md); background: var(--field); font-size: var(--fs-lg); font-weight: 800; letter-spacing: .25em; text-transform: uppercase; text-align: center; }
.code-input:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.lobby-browse { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.lobby-browse li { display: flex; align-items: center; gap: var(--sp-3); padding: 10px var(--sp-3); border-radius: var(--r-md); background: var(--soft-2); }
.lobby-browse .info { flex: 1; min-width: 0; display: grid; text-align: left; }
.lobby-browse .info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobby-browse .info small { color: var(--muted); }
.lobby-browse .empty { display: block; background: none; color: var(--muted); text-align: center; }
.lobby-code { margin: var(--sp-3) 0; padding: var(--sp-3); border-radius: var(--r-md); background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--cobalt); }
.lobby-code small { display: block; font-weight: 700; }
.lobby-code b { display: block; font-size: 2.4rem; letter-spacing: .3em; padding-left: .3em; line-height: 1.2; }
.qr { width: 150px; margin: var(--sp-2) auto 0; border-radius: var(--r-sm, 8px); overflow: hidden; border: 3px solid #fff; background: #fff; }
.qr svg { display: block; width: 100%; height: auto; }
.lobby-code .row-buttons { margin-top: var(--sp-2); }
.host-box { text-align: left; margin: var(--sp-3) 0; }
.lobby-list .crown { margin-left: auto; font-size: var(--fs-sm); color: var(--muted); }
.lobby-list .kick { margin-left: auto; }

.conn-banner { position: fixed; left: 50%; top: 10px; transform: translateX(-50%); z-index: 50; padding: 8px 16px; border-radius: 999px; background: var(--amber-soft, #FFF1D6); color: var(--amber-ink, #6B4A00); border: 2px solid var(--amber, #F5B14F); font-weight: 800; box-shadow: var(--shadow); }
.conn-banner[hidden] { display: none; }
.demo-banner { margin: 6px 0 0; padding: 8px 14px; border-radius: 12px; background: var(--amber-soft, #FFF1D6); border: 2px solid var(--amber, #F5B14F); font-weight: 700; }
.demo-banner[hidden] { display: none; }
