/* =====================================================================
   NerdBro Games website stylesheet.

   Visual target: the approved NerdBro Games prototype (light "paper plate"
   system derived from docs/design-language: Deep Ink outlines, role
   colours, no UI gradients, no drop shadows, one hard shade edge on
   tactile buttons). Light theme only, deliberately: the prototype is
   light-themed and this file defines no dark scheme.

   Palette reconciliation (docs/architecture/games-website.md#tokens):
   brand/secondary/accent/paper come from the app's AppPalette
   (frontend/lib/app/shared/theme/app_palette.dart), which is the colour
   authority. The prototype's #0E7465 teal and #F9FAFB paper are within a
   step of AppPalette's brandPrimary #0C7465 and neutral50 #F7F8F9 and are
   reconciled to them. Ink #16263F is the prototype's outline navy.
   Functional state colours (pink/amber/violet) are the design-language
   reference's, not part of the app palette.
   Pages never use a hexadecimal colour; they use these semantic tokens.
   ===================================================================== */
:root {
  --ink: #16263F; --paper: #F7F8F9; --white: #FFFFFF; --card: #FFFFFF;
  --muted: #4F5D75; --body2: #2E3B55; --line: #DDE3EC; --well: #EEF2F6;
  --link: #1E4388;
  --brand: #0C7465; --brand-strong: #005144;
  --orange: var(--brand);
  --blue: #1E4388;
  --cyan: #5494CF;
  --green: #83CDB7;
  --navy: #16263F;
  --navy-line: #5D6B86; --navy-text: #C8D6EA;
  --pink: #EF4F87; --amber: #FFB300; --yellow: #FFC33D; --violet: #8B70EF; --slate: #68809F;
  --ok: #0B5F53; --fault: #B4235A; --fault-bg: #FFF1F6; --goal-text: #7A5200;
  --blue-tint: #E6ECF7; --green-tint: #E6F5F0; --pink-tint: #FFE9F1; --amber-tint: #FFF4D6;
  --orange-tint: #E1F3EF; --cyan-tint: #E8F1FA; --violet-tint: #EFEBFF;
  --scrim: rgba(22, 38, 63, .55); --veil: rgba(245, 248, 252, .95);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Bengali", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-body: 15px; --lh: 1.55;
  --r-xs: 6px; --r-sm: 10px; --r-md: 14px; --r-lg: 18px; --r-pill: 999px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;
  --side: 280px; --rail: 76px; --head: 60px;
  --shade: inset 0 -3px 0 rgba(22, 38, 63, .22);
  --focus: 0 0 0 3px var(--white), 0 0 0 5px var(--blue);
  /* subject chip roles, assigned by subject position (never colour alone: chips also carry an icon and text) */
  --subj-0: #0C7465; --subj-1: #1E4388; --subj-2: #B4235A; --subj-3: #7A5200; --subj-4: #5B3FC4; --subj-5: #2D7B44;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--head) + 12px); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: var(--fs-body)/var(--lh) var(--font); }
body.text-large { --fs-body: 17px; }
body.text-large .mcq-stem { font-size: 22px; }
img { max-width: 100%; display: block; }
a { color: var(--link); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 200; background: var(--white); padding: 8px 12px; border-radius: var(--r-sm); border: 2px solid var(--ink); }
.skip:focus { left: 12px; }
h1, h2, h3, h4 { text-wrap: balance; margin: 0; line-height: 1.15; }
h1 { font-size: 32px; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 22px; font-weight: 800; }
h3 { font-size: 17px; font-weight: 800; }
p { margin: 0; }
.ico { width: 20px; height: 20px; flex: none; }
.ico.subj, .ico.chap { width: 24px; height: 24px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.eyebrow { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); } /* [O] group labels */
.bn, [lang="bn"] { font-family: "Noto Sans Bengali", var(--font); }
.stack { display: grid; gap: var(--s4); }
.row { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.tabnum { font-variant-numeric: tabular-nums; }

/* ---------- Buttons [D] ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 9px 16px;
  border-radius: var(--r-sm); border: 1.5px solid var(--line); background: var(--white); color: var(--ink);
  font-weight: 700; font-size: 15px; text-decoration: none; line-height: 1.2; text-align: center; }
.btn:hover { border-color: var(--ink); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn.primary { background: var(--brand); color: var(--white); border: 2px solid var(--ink); box-shadow: var(--shade); }
.btn.primary:hover { background: var(--brand-strong); }
.btn.ink { background: var(--ink); color: var(--white); border-color: var(--ink); box-shadow: inset 0 -3px 0 rgba(0,0,0,.35); }
.btn.ink:hover { background: var(--body2); }
.btn.danger { background: var(--white); color: var(--fault); border: 2px solid var(--fault); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--well); border-color: transparent; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.lg { min-height: 52px; padding: 12px 22px; font-size: 17px; }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn .ico { width: 18px; height: 18px; }
.iconbtn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r-sm); border: 1.5px solid transparent; background: transparent; color: var(--ink); }
.iconbtn:hover { background: var(--well); }
.iconbtn:focus-visible { outline: none; box-shadow: var(--focus); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--link); text-decoration: underline; font-weight: 600; cursor: pointer; }

/* ---------- Chips, tags, badges ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px 6px 10px; border-radius: var(--r-pill);
  border: 1.5px solid var(--line); background: var(--white); font-weight: 700; font-size: 14px; color: var(--ink); }
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"], .chip.on { background: var(--ink); color: var(--white); border-color: var(--ink); }
.chip[aria-pressed="true"] .ck { display: inline-block; }
.chip .ck { display: none; width: 16px; height: 16px; }
.chip .ico.subj { width: 22px; height: 22px; }
.chip.sm { min-height: 32px; padding: 3px 10px; font-size: 13px; }
.chip[disabled] { opacity: .5; cursor: not-allowed; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 1px 9px; color: var(--muted); background: var(--paper); white-space: nowrap; } /* [O] .tag */
.tag .ico { width: 14px; height: 14px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase;
  border-radius: var(--r-xs); padding: 2px 7px; } /* [O] .badge */
.badge .ico { width: 13px; height: 13px; }
.b-ok { background: var(--green-tint); color: var(--ok); }
.b-fault { background: var(--fault-bg); color: var(--fault); }
.b-goal { background: var(--amber-tint); color: var(--goal-text); }
.b-info { background: var(--blue-tint); color: var(--blue); }
.b-ink { background: var(--ink); color: var(--white); }
.b-muted { background: var(--well); color: var(--body2); }
.b-battle { background: var(--ink); color: var(--white); }
.b-authored { background: var(--orange-tint); color: var(--ok); }

/* ---------- Shell ---------- */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 60; background: var(--white); }
.hdr { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 50; height: var(--head); background: var(--white); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s3); padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
.brand { display: flex; align-items: baseline; gap: 6px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 20px; line-height: 1; white-space: nowrap; } /* [O] .brand */
.brand small { font-weight: 600; font-size: 14px; color: var(--muted); }
.brand .mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; border: 2px solid var(--ink); background: var(--orange); align-self: center; box-shadow: var(--shade); }
.brand .mark img { width: 22px; height: 22px; }
.hdr .menubtn { display: none; }
.hsearch { flex: 1; max-width: 520px; position: relative; margin-left: var(--s4); }
.hsearch input { width: 100%; height: 42px; padding: 0 12px 0 38px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--paper); } /* [O] search input */
.hsearch input:focus { outline: 2px solid var(--blue); border-color: transparent; }
.hsearch > .ico { position: absolute; left: 11px; top: 11px; color: var(--muted); }
.hclass { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 4px 10px 4px 12px; border-radius: var(--r-pill); border: 1.5px solid var(--ink); background: var(--cyan-tint); font-weight: 800; font-size: 14px; white-space: nowrap; }
.hclass .ico { width: 16px; height: 16px; }
.hlang { min-height: 40px; padding: 4px 10px; border-radius: var(--r-pill); border: 1.5px solid var(--line); background: var(--white); font-weight: 700; font-size: 14px; }
.havatar { width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper); overflow: hidden; padding: 0; display: grid; place-items: center; }
.havatar img { width: 40px; height: 40px; object-fit: cover; object-position: 50% 8%; transform: scale(1.7) translateY(22%); }
.hdr-right { display: flex; align-items: center; gap: var(--s2); margin-left: auto; }

.layout { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: calc(100vh - var(--head)); }
body.side-collapsed .layout { grid-template-columns: var(--rail) minmax(0, 1fr); }
.side { position: sticky; top: calc(var(--head) + env(safe-area-inset-top, 0px)); height: calc(100vh - var(--head) - env(safe-area-inset-top, 0px)); overflow-y: auto; overscroll-behavior: contain;
  background: var(--white); border-right: 1px solid var(--line); padding: 14px 12px 40px; } /* [O] #side */
.main { min-width: 0; padding-block: 24px 80px; padding-left: max(16px, min(40px, 3vw)); padding-right: max(16px, min(40px, 3vw), env(safe-area-inset-right, 0px)); max-width: 1320px; width: 100%; }
.side-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.side-nav { display: grid; gap: 2px; margin-bottom: 14px; }
.navlink { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 8px 10px; border-radius: var(--r-sm); color: var(--ink); text-decoration: none; font-weight: 700; font-size: 14.5px; border: 1.5px solid transparent; background: none; width: 100%; text-align: left; }
.navlink:hover { background: var(--well); }
.navlink[aria-current="page"] { background: var(--ink); color: var(--white); }
.navlink .lbl { min-width: 0; }
.side-class { border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; background: var(--paper); margin-bottom: 12px; }
.side-class .row { justify-content: space-between; }
.side-class b { font-size: 16px; }
.side-filter { width: 100%; height: 38px; padding: 0 10px 0 34px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--paper); }
.side-filter-wrap { position: relative; margin-bottom: 8px; }
.side-filter-wrap .ico { position: absolute; left: 9px; top: 9px; color: var(--muted); width: 18px; height: 18px; }
.subjgroup { margin-top: 6px; }
.subjhead { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 6px 8px; background: none; border: 0; border-radius: var(--r-sm); font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink); text-align: left; }
.subjhead:hover { background: var(--well); }
.subjhead .chev { margin-left: auto; width: 16px; height: 16px; transition: transform .15s; }
.subjhead[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.chaplist { list-style: none; margin: 2px 0 6px 18px; padding: 0 0 0 6px; border-left: 2px solid var(--line); } /* [O] toc nested list */
.chaplink { display: flex; align-items: flex-start; gap: 9px; padding: 7px 8px; border-radius: var(--r-sm); text-decoration: none; color: var(--body2); font-size: 14px; line-height: 1.3; position: relative; }
.chaplink .ico.chap { width: 22px; height: 22px; margin-top: -1px; }
.chaplink:hover { background: var(--well); color: var(--ink); }
.chaplink[aria-current="page"] { background: var(--blue-tint); color: var(--ink); font-weight: 800; }
.chaplink[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 6px; bottom: 6px; width: 4px; border-radius: 3px; background: var(--ink); }
.chaplink .cnt { margin-left: auto; font-size: 12px; color: var(--muted); padding-left: 6px; font-variant-numeric: tabular-nums; }
.side-empty { font-size: 13px; color: var(--muted); padding: 8px; border: 1px dashed var(--line); border-radius: var(--r-sm); }
.side-foot { margin-top: 18px; font-size: 12px; color: var(--muted); }

/* collapsed rail */
body.side-collapsed .side { padding: 12px 10px; overflow: visible; }
body.side-collapsed .side .lbl, body.side-collapsed .side .side-class, body.side-collapsed .side .side-filter-wrap,
body.side-collapsed .side .chaplist, body.side-collapsed .side .side-foot, body.side-collapsed .side .subjhead .chev, body.side-collapsed .side .subjhead .lbl { display: none; }
body.side-collapsed .navlink, body.side-collapsed .subjhead { justify-content: center; padding: 8px; }
body.side-collapsed .side-top { justify-content: center; }
.railclass { display: none; }
body.side-collapsed .railclass { display: grid; place-items: center; width: 52px; min-height: 44px; margin: 0 auto 8px; border-radius: var(--r-sm); border: 1.5px solid var(--ink); background: var(--cyan-tint); font-weight: 800; font-size: 12px; line-height: 1.1; text-align: center; padding: 4px; }
.flyout { position: fixed; z-index: 70; width: 300px; max-height: 70vh; overflow-y: auto; background: var(--white); border: 1.5px solid var(--ink); border-radius: var(--r-md); padding: 12px; }
.flyout h3 { font-size: 15px; margin-bottom: 2px; }
.flyout .chaplist { margin-left: 0; border-left: 0; padding-left: 0; }

/* ---------- Page scaffolding ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13.5px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.crumbs .sep { opacity: .6; }
.pagehead { display: flex; gap: var(--s4); align-items: flex-start; flex-wrap: wrap; margin-bottom: var(--s5); }
.pagehead .ttl { min-width: 0; flex: 1 1 320px; }
.pagehead h1 { overflow-wrap: anywhere; }
.pagehead .lead { color: var(--body2); max-width: 70ch; margin-top: 6px; }
.chapbadge { width: 64px; height: 64px; border-radius: var(--r-md); border: 2px solid var(--ink); background: var(--white); display: grid; place-items: center; flex: none; }
.chapbadge .ico { width: 40px; height: 40px; }
.section { margin-top: 36px; }
.sechead { display: flex; align-items: flex-end; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s3); }
.sechead .ttl { flex: 1 1 280px; min-width: 0; }
.sechead h2 { padding-top: 10px; border-top: 3px solid var(--ink); display: inline-block; } /* [O] .part > h2 rule */
.sechead p { color: var(--body2); margin-top: 4px; max-width: 70ch; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px 22px; } /* [O] .entry */
.panel.tight { padding: 14px 16px; border-radius: var(--r-md); }
.statusbox { background: var(--white); border: 1px solid var(--line); border-left: 5px solid var(--fault); border-radius: var(--r-sm); padding: 10px 14px; font-size: 14px; } /* [O] */
.note { display: flex; gap: 10px; align-items: flex-start; background: var(--white); border: 1px solid var(--line); border-left: 5px solid var(--blue); border-radius: var(--r-sm); padding: 10px 14px; font-size: 14px; }
.note.warn { border-left-color: var(--amber); }
.note.fault { border-left-color: var(--fault); background: var(--fault-bg); }
.note.ok { border-left-color: var(--green); }
.note .ico { margin-top: 1px; }
.note > div { min-width: 0; flex: 1; }
.banner { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 10px 14px; border-radius: var(--r-md); border: 1.5px solid var(--ink); background: var(--amber-tint); margin-bottom: var(--s4); }
.banner .txt { flex: 1 1 260px; min-width: 0; }
.banner.offline { background: var(--fault-bg); border-color: var(--fault); }

/* ---------- Empty / error / skeleton (K32) ---------- */
.empty { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: var(--s5); align-items: center; padding: 22px; border: 2px dashed var(--line); border-radius: var(--r-lg); background: var(--white); }
.empty img { width: 120px; height: 140px; object-fit: contain; }
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--body2); max-width: 62ch; }
.empty .row { margin-top: 12px; }
.skel { background: linear-gradient(90deg, var(--well) 0 40%, var(--paper) 50%, var(--well) 60% 100%); background-size: 300% 100%; animation: shimmer 1.4s linear infinite; border-radius: var(--r-md); }
@keyframes shimmer { from { background-position: 100% 0 } to { background-position: 0 0 } }

/* ---------- Battlefield module + cards (K07) ---------- */
.bf { background: var(--navy); color: var(--white); border-radius: var(--r-lg); padding: 18px 18px 20px; } /* [D] dark band frames the four battles as one module; the stage art inside stays light per foundation */
.bf-head { display: flex; gap: var(--s3); align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.bf-head .ttl { flex: 1 1 300px; min-width: 0; }
.bf-head h2 { color: var(--white); font-size: 24px; }
.bf-head p { color: var(--navy-text); margin-top: 4px; }
.bf-head .btn { background: transparent; color: var(--white); border-color: var(--navy-line); }
.bf-head .btn:hover { border-color: var(--white); }
.bfgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.bcard { position: relative; display: flex; flex-direction: column; text-align: left; padding: 0; background: var(--white); color: var(--ink); border: 3px solid var(--white); border-radius: var(--r-md); overflow: hidden; text-decoration: none; }
.bcard:hover { border-color: var(--green); }
.bcard:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
.bcard .art { aspect-ratio: 16 / 10; }
.bcard .body { padding: 10px 12px 12px; display: grid; gap: 4px; }
.bcard h3 { font-size: 17px; }
.bcard p { font-size: 13.5px; color: var(--body2); }
.bcard .modes { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.bcard .modes span { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--body2); }
.bcard .modes .ico { width: 15px; height: 15px; }
.bcard .badge { position: absolute; top: 8px; left: 8px; }
.bcard.sel { border-color: var(--orange); }
.bf-unavail { margin-top: 12px; color: var(--pink-tint); font-size: 14px; display: flex; gap: 8px; align-items: center; }

/* ---------- Art compositions (owner vectors, composed) ---------- */
.art { position: relative; overflow: hidden; background: var(--well); }
.art > img { position: absolute; }
.art .bg { inset: 0; width: 100%; height: 100%; object-fit: cover; }
.art .plate { position: absolute; inset: 0; background: var(--paper); }
.art .ph { position: absolute; right: 6px; bottom: 6px; font-size: 10px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; background: rgba(255,255,255,.92); color: var(--muted); border-radius: 4px; padding: 1px 5px; }
.art .track { position: absolute; left: 0; right: 0; }

/* ---------- Authored game cards (K06) ---------- */
.ggrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.gcard { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; position: relative; } /* [O] .pillar */
.gcard:hover { border-color: var(--ink); }
.gcard .art { aspect-ratio: 16 / 10; }
.gcard .body { padding: 10px 12px 12px; display: grid; gap: 6px; flex: 1; align-content: start; }
.gcard .gt { font-weight: 800; font-size: 16px; line-height: 1.25; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.gcard .gt::after { content: ""; position: absolute; inset: 0; }
.gcard .gt:focus-visible { outline: none; }
.gcard:focus-within { box-shadow: var(--focus); }
.gcard .chapline { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.gcard .chapline .ico { width: 16px; height: 16px; }
.gcard .caps { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.gcard .fav { position: absolute; top: 8px; right: 8px; z-index: 2; width: 40px; height: 40px; border-radius: 50%; background: var(--white); border: 1.5px solid var(--line); display: grid; place-items: center; }
.gcard .fav:hover { border-color: var(--ink); }
.gcard .kind { position: absolute; top: 8px; left: 8px; z-index: 1; }
.gcard .prog { font-size: 12.5px; font-weight: 700; color: var(--ok); }
.shelf { margin-top: 26px; }
.shelfhead { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.shelfhead h3 { font-size: 19px; display: flex; gap: 8px; align-items: center; }
.shelfhead .chips { margin-left: 4px; }
.shelfhead .spacer { min-width: 8px; }

/* ---------- Filters (K09) ---------- */
.filterbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; padding: 12px 14px; background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 12px; }
.fgroup { display: grid; gap: 4px; min-width: 0; }
.fgroup > .flabel { font-size: 12px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.select { height: 40px; padding: 0 34px 0 12px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%2316263F' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 8px center / 18px; appearance: none; max-width: 100%; font-weight: 600; }
.select:focus { outline: 2px solid var(--blue); border-color: transparent; }
.input { height: 44px; padding: 0 12px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--paper); width: 100%; }
.input:focus { outline: 2px solid var(--blue); border-color: transparent; background: var(--white); }
.input.err { border-color: var(--fault); }
.field { display: grid; gap: 6px; }
.field label { font-weight: 700; font-size: 14px; }
.field .hint { font-size: 13px; color: var(--muted); }
.field .errmsg { font-size: 13.5px; color: var(--fault); font-weight: 700; display: flex; gap: 6px; align-items: center; }
.resultline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 4px 0 12px; font-size: 14px; color: var(--body2); }
.activechip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px 2px 10px; border-radius: var(--r-pill); background: var(--ink); color: var(--white); font-size: 13px; font-weight: 700; border: 0; min-height: 30px; }
.activechip .ico { width: 15px; height: 15px; }
.filterbtn-m { display: none; }

/* ---------- Search panel (K10/D07) ---------- */
.spanel { position: absolute; left: 0; right: 0; top: 48px; background: var(--white); border: 1.5px solid var(--ink); border-radius: var(--r-md); padding: 8px; z-index: 80; max-height: 70vh; overflow-y: auto; }
.sgroup { padding: 4px 0 6px; }
.sgroup + .sgroup { border-top: 1px solid var(--line); }
.sgroup .eyebrow { padding: 6px 8px 4px; display: flex; gap: 6px; align-items: center; }
.sopt { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: var(--r-sm); text-decoration: none; color: var(--ink); cursor: pointer; }
.sopt[aria-selected="true"], .sopt:hover { background: var(--blue-tint); }
.sopt .ico { width: 22px; height: 22px; }
.sopt .s2 { font-size: 12.5px; color: var(--muted); }
.sopt.bfopt { background: var(--paper); border: 1px dashed var(--slate); }
.sscope { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 6px 8px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); }

/* ---------- Modal / sheet foundation (K30) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(22, 38, 63, .55); z-index: 120; display: grid; place-items: center; padding: 16px; }
.dialog { min-width: 0; max-width: 100%; background: var(--white); border: 2px solid var(--ink); border-radius: var(--r-lg); width: min(560px, 100%); max-height: min(88vh, 900px); display: flex; flex-direction: column; }
.dialog.sm { width: min(440px, 100%); }
.dialog.lg { width: min(920px, 100%); height: min(86vh, 860px); }
.dlg-head { display: flex; align-items: flex-start; gap: 10px; padding: 16px 16px 10px 20px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 20px; flex: 1; padding-top: 8px; }
.dlg-head .sub { font-size: 13.5px; color: var(--muted); margin-top: 4px; font-weight: 400; }
.dlg-body > * { min-width: 0; }
.field .select { width: 100%; }
.dlg-body { padding: 16px 20px; overflow-y: auto; display: grid; gap: 14px; align-content: start; flex: 1; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.drawer-scrim { place-items: stretch start; padding: 0; }
.drawer { background: var(--white); width: min(360px, 92vw); height: 100%; overflow-y: auto; padding: 14px 14px 40px; padding-left: max(14px, env(safe-area-inset-left, 0px)); border-right: 2px solid var(--ink); }
.popover { position: fixed; z-index: 130; width: min(320px, calc(100vw - 32px)); background: var(--white); border: 1.5px solid var(--ink); border-radius: var(--r-md); padding: 12px 14px; font-size: 14px; }
@media (max-width: 640px) {
  .scrim:not(.drawer-scrim) { place-items: end stretch; padding: 0; }
  .dialog, .dialog.sm, .dialog.lg { width: 100%; max-height: 92vh; border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .dialog.lg, .dialog.full { height: 100%; max-height: 100%; border-radius: 0; }
}

/* ---------- Toasts (K31) ---------- */
.toasts { position: fixed; z-index: 150; left: 50%; transform: translateX(-50%); bottom: max(20px, env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; width: min(460px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: center; background: var(--ink); color: var(--white); border-radius: var(--r-md); padding: 10px 14px; font-weight: 600; font-size: 14px; }
.toast.fault { background: var(--fault); }
.toast .ico { width: 18px; height: 18px; }

/* ---------- Choice cards (class chooser, mode cards, avatar picks) ---------- */
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.choice { position: relative; display: grid; gap: 4px; text-align: left; padding: 12px 14px; border-radius: var(--r-md); border: 1.5px solid var(--line); background: var(--white); min-height: 64px; }
.choice:hover { border-color: var(--ink); }
.choice[aria-checked="true"], .choice[aria-pressed="true"] { border: 2.5px solid var(--ink); background: var(--blue-tint); padding: 11px 13px; }
.choice[aria-checked="true"]::after, .choice[aria-pressed="true"]::after { content: ""; position: absolute; top: 10px; right: 10px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4L18 8' fill='none' stroke='white' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") center / 16px no-repeat; }
.choice b { font-size: 16px; padding-right: 24px; }
.choice span { font-size: 13px; color: var(--muted); }
.choice[disabled] { opacity: .6; cursor: not-allowed; background: var(--well); }

/* ---------- Authored game page (P03) ---------- */
.gpage { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.gside { display: grid; gap: 14px; }
.player { background: var(--white); border: 2px solid var(--ink); border-radius: var(--r-lg); overflow: hidden; display: flex; flex-direction: column; }
.pbar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--white); flex-wrap: wrap; }
.pbar .ptitle { font-weight: 800; padding: 0 6px; min-width: 0; flex: 1 1 140px; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.25; }
.pbar .iconbtn { width: 42px; height: 42px; }
.pbar .sep { width: 1px; height: 24px; background: var(--line); margin: 0 2px; }
.pstage { position: relative; aspect-ratio: 16 / 9; background: var(--paper); min-height: 300px; }
.pstage .gameph { position: absolute; inset: 0; }
.pfoot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); }
.preview-cover { position: absolute; inset: 0; display: grid; place-items: center; }
.preview-cover .art { position: absolute; inset: 0; }
.preview-cover .cta { position: relative; z-index: 2; display: grid; gap: 10px; justify-items: center; background: rgba(255,255,255,.94); border: 2px solid var(--ink); border-radius: var(--r-lg); padding: 16px 22px; max-width: 90%; text-align: center; }
.statepanel { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; background: var(--paper); z-index: 5; }
.statepanel .inner { max-width: 460px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.statepanel img { width: 110px; height: 120px; object-fit: contain; }
.loader { width: 160px; height: 10px; border-radius: 6px; border: 2px solid var(--ink); background: var(--white); overflow: hidden; }
.loader i { display: block; height: 100%; width: 40%; background: var(--blue); animation: load 1.2s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-100%) } to { transform: translateX(260%) } }
.howto ol { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 4px; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; font-size: 14px; } /* [O] dl.kv */
.kv dt { font-weight: 700; } .kv dd { margin: 0; }

/* theater / fullscreen — same DOM node, just restyled (session preserved) */
body.theater .hdr, body.theater .side, body.theater .hide-in-theater { display: none !important; }
body.theater .layout { display: block; }
body.theater .main { max-width: none; padding: 0; }
.player.is-theater, .bshell.is-theater { position: fixed; inset: 0; z-index: 90; border-radius: 0; border: 0; padding-top: env(safe-area-inset-top, 0px); }
.player.is-theater .pstage { aspect-ratio: auto; flex: 1; }
.player:fullscreen { border: 0; border-radius: 0; }
.player:fullscreen .pstage { aspect-ratio: auto; flex: 1; }

/* ---------- Completion (K25) ---------- */
.complete { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; padding: 16px; background: rgba(245, 248, 252, .96); }
.complete .card { background: var(--white); border: 2px solid var(--ink); border-radius: var(--r-lg); padding: 20px 22px; max-width: 520px; width: 100%; display: grid; gap: 12px; }
.stars { display: flex; gap: 4px; }
.stars .ico { width: 34px; height: 34px; }

/* ---------- Battle setup (P04) ---------- */
.setup { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
.simpanel { position: sticky; top: calc(var(--head) + 16px); display: grid; gap: 12px; }
.simpanel .art { aspect-ratio: 16 / 10; border-radius: var(--r-md); border: 2px solid var(--ink); }
.simtabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.simtab { border: 1.5px solid var(--line); background: var(--white); border-radius: var(--r-sm); padding: 6px 4px; font-size: 12px; font-weight: 700; line-height: 1.2; min-height: 44px; }
.simtab[aria-pressed="true"] { border: 2px solid var(--ink); background: var(--orange-tint); }
a.simtab { display: grid; place-items: center; text-align: center; color: var(--ink); text-decoration: none; }
.step { display: grid; gap: 12px; }
.step + .step { margin-top: 22px; }
.stephead { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stepnum { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); display: grid; place-items: center; font-weight: 800; background: var(--white); flex: none; }
.stepnum.done { background: var(--green); }
.stephead h2 { font-size: 20px; flex: 1; min-width: 0; }
.segs { display: inline-flex; border: 1.5px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: var(--white); flex-wrap: wrap; }
.seg { border: 0; background: none; padding: 8px 14px; min-height: 40px; font-weight: 700; font-size: 14px; }
.seg + .seg { border-left: 1.5px solid var(--line); }
.seg[aria-selected="true"], .seg[aria-pressed="true"] { background: var(--ink); color: var(--white); }
.chapgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.chapcard { position: relative; display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 10px; align-items: start; text-align: left; padding: 12px; border-radius: var(--r-md); border: 1.5px solid var(--line); background: var(--white); } /* K08 */
.chapcard:hover { border-color: var(--ink); }
.chapcard[aria-checked="true"] { border: 2.5px solid var(--ink); background: var(--blue-tint); padding: 11px; }
.chapcard .ico.chap { width: 36px; height: 36px; }
.chapcard b { display: block; font-size: 15px; line-height: 1.3; overflow-wrap: anywhere; }
.chapcard .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.chapcard .why { font-size: 12.5px; color: var(--body2); margin-top: 4px; }
.chapcard .pool { margin-top: 6px; }
.chapcard.unavail { background: var(--well); }
.summary { display: grid; gap: 8px; padding: 14px 16px; border-radius: var(--r-md); border: 1.5px solid var(--ink); background: var(--white); }
.summary .kv { font-size: 14px; }
.modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.modecard { display: grid; gap: 4px; justify-items: start; text-align: left; padding: 14px; border-radius: var(--r-md); border: 1.5px solid var(--line); background: var(--white); position: relative; }
.modecard .ico { width: 28px; height: 28px; }
.modecard b { font-size: 17px; }
.modecard span { font-size: 13px; color: var(--muted); }
.modecard:hover { border-color: var(--ink); }
.modecard[aria-checked="true"] { border: 2.5px solid var(--ink); background: var(--orange-tint); padding: 13px; }
.modecard[disabled] { background: var(--well); cursor: not-allowed; }
.levels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.level { padding: 10px 12px; border-radius: var(--r-sm); border: 1.5px solid var(--line); background: var(--white); text-align: left; display: grid; gap: 2px; }
.level b { font-size: 16px; }
.level span { font-size: 12.5px; color: var(--muted); }
.level[aria-checked="true"] { border: 2.5px solid var(--ink); background: var(--amber-tint); padding: 9px 11px; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--white); }
.dots i.on { background: var(--ink); }
.startbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-radius: var(--r-md); background: var(--white); border: 1px solid var(--line); margin-top: 18px; }
.startbar .txt { flex: 1 1 260px; min-width: 0; font-size: 14px; color: var(--body2); }

/* ---------- Lobby (K19/K20) ---------- */
.lobby { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ptile { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; align-items: center; padding: 12px; border-radius: var(--r-md); border: 1.5px solid var(--line); background: var(--white); }
.ptile .av { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper); overflow: hidden; display: grid; place-items: center; }
.ptile .av img { width: 64px; height: 64px; object-fit: cover; object-position: 50% 6%; transform: scale(1.75) translateY(22%); }
.ptile b { display: block; font-size: 16px; overflow-wrap: anywhere; }
.ptile .st { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.ptile.empty-slot { border-style: dashed; background: var(--paper); }
.ptile.ready { border: 2.5px solid var(--ok); padding: 11px; }
.codebox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border: 2px solid var(--ink); border-radius: var(--r-md); background: var(--white); }
.codebox .code { font-family: var(--mono); font-size: 24px; font-weight: 800; letter-spacing: .08em; flex: 1 1 100%; min-width: 0; user-select: all; white-space: nowrap; }

/* ---------- Battle player shell (K15) ---------- */
.bshell { display: grid; gap: 0; background: var(--white); border: 2px solid var(--ink); border-radius: var(--r-lg); overflow: hidden; }
.bstatus { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.who { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: var(--r-pill); border: 1.5px solid var(--line); background: var(--paper); font-weight: 800; font-size: 14px; }
.who .mini { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--ink); overflow: hidden; background: var(--white); display: grid; place-items: center; }
.who .mini img { width: 30px; height: 30px; object-fit: cover; object-position: 50% 6%; transform: scale(1.75) translateY(22%); }
.who.you { border-color: var(--orange); background: var(--orange-tint); }
.who .sc { font-variant-numeric: tabular-nums; }
.who .tagcpu { font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; background: var(--ink); color: var(--white); border-radius: 4px; padding: 1px 5px; }
.who .conn { width: 9px; height: 9px; border-radius: 50%; background: var(--green); border: 1.5px solid var(--ink); }
.who .conn.off { background: var(--white); border-style: dashed; }
.roundinfo { margin-left: auto; display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 14px; }
.timer { display: inline-flex; align-items: center; gap: 6px; min-width: 76px; padding: 4px 10px; border-radius: var(--r-pill); border: 2px solid var(--ink); background: var(--amber-tint); font-variant-numeric: tabular-nums; }
.timer.low { background: var(--pink-tint); border-color: var(--fault); color: var(--fault); }
.timer .ico { width: 16px; height: 16px; }
.bbody { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr); min-height: 0; }
.scene { position: relative; background: var(--paper); border-right: 1px solid var(--line); min-height: 320px; overflow: hidden; }
.scene .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scene .sprite { position: absolute; transition: left .8s cubic-bezier(.3,.7,.3,1), bottom .8s, transform .8s, opacity .5s; }
.scene .evt { position: absolute; left: 10px; bottom: 10px; right: 10px; z-index: 4; display: flex; flex-wrap: wrap; gap: 6px; }
.scene .lane-label { position: absolute; z-index: 3; }
.scenebar { position: absolute; z-index: 3; left: 10px; right: 10px; top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.mcq { padding: 14px 16px 16px; display: grid; gap: 12px; align-content: start; background: var(--white); min-width: 0; }
.mcq-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12.5px; color: var(--muted); }
.mcq-stem { font-size: 19px; line-height: 1.5; font-weight: 600; overflow-wrap: anywhere; } /* calm, readable surface */
.mcq-stem[lang="bn"] { line-height: 1.75; }
.mathexpr { display: inline-flex; align-items: center; gap: 10px; font-size: 26px; font-weight: 700; padding: 6px 14px; border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--paper); font-family: "Cambria Math", "STIX Two Math", Georgia, serif; }
.frac { display: inline-grid; text-align: center; line-height: 1.05; }
.frac span:first-child { border-bottom: 2px solid var(--ink); padding: 0 4px; }
.diagram { border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--paper); padding: 12px; display: grid; gap: 6px; }
.diagram .bar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 2.5px solid var(--ink); border-radius: 6px; overflow: hidden; height: 46px; }
.diagram .bar i { border-right: 2px solid var(--ink); background: var(--white); }
.diagram .bar i:last-child { border-right: 0; }
.diagram .bar i.on { background: var(--blue); background-image: repeating-linear-gradient(45deg, transparent 0 6px, rgba(255,255,255,.35) 6px 9px); }
.diagram figcaption { font-size: 12.5px; color: var(--muted); }
.diagram.broken { border: 2px dashed var(--fault); background: var(--fault-bg); }
.opts { display: grid; gap: 8px; }
.opt { display: grid; grid-template-columns: 34px minmax(0, 1fr) 24px; gap: 10px; align-items: center; text-align: left; min-height: 52px; padding: 8px 12px 8px 8px; border-radius: var(--r-md); border: 2px solid var(--line); background: var(--white); font-size: 16.5px; line-height: 1.4; overflow-wrap: anywhere; } /* K17 */
.opt[lang="bn"] { line-height: 1.6; }
.opt .key { width: 34px; height: 34px; border-radius: 9px; border: 2px solid var(--ink); display: grid; place-items: center; font-weight: 800; font-size: 14px; background: var(--paper); }
.opt .mark { width: 24px; height: 24px; }
.opt:hover:not([disabled]) { border-color: var(--ink); }
.opt[aria-checked="true"] { border: 3px solid var(--blue); background: var(--blue-tint); padding: 7px 11px 7px 7px; }
.opt[aria-checked="true"] .key { background: var(--blue); color: var(--white); }
.opt[disabled] { cursor: default; }
.opt.locked[aria-checked="true"] { border-style: solid; }
.opt.dim { opacity: .6; }
.opt.correct { border: 3px solid var(--ok); background: var(--green-tint); padding: 7px 11px 7px 7px; }
.opt.correct .key { background: var(--green); color: var(--ink); }
.opt.wrong { border: 3px dashed var(--fault); background: var(--pink-tint); padding: 7px 11px 7px 7px; }
.opt.wrong .key { background: var(--pink); color: var(--white); }
.answerbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.answerbar .state { flex: 1 1 200px; min-width: 0; font-size: 14px; font-weight: 700; display: flex; gap: 8px; align-items: center; }
.feedback { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-md); border: 2px solid var(--ink); font-size: 14.5px; }
.feedback.correct { border-color: var(--ok); background: var(--green-tint); }
.feedback.wrong { border-color: var(--fault); border-style: dashed; background: var(--pink-tint); }
.feedback.timeout { border-color: var(--slate); border-style: dotted; background: var(--well); }
.feedback .ico { width: 24px; height: 24px; flex: none; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg) } }
.bctrl { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; padding: 6px 8px; border-top: 1px solid var(--line); background: var(--white); }
.bctrl .note-inline { font-size: 12.5px; color: var(--muted); margin-left: 6px; flex: 1 1 200px; }
.bshell.is-theater { display: flex; flex-direction: column; }
.bshell.is-theater .bbody { flex: 1; min-height: 0; }
.bshell.is-theater .mcq { overflow-y: auto; }
.bshell:fullscreen { display: flex; flex-direction: column; border: 0; border-radius: 0; }
.bshell:fullscreen .bbody { flex: 1; min-height: 0; }
.bshell:fullscreen .mcq { overflow-y: auto; }
.overlay { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(245, 248, 252, .95); }
.overlay .card { background: var(--white); border: 2px solid var(--ink); border-radius: var(--r-lg); padding: 18px 20px; max-width: 460px; width: 100%; display: grid; gap: 10px; }
.bshell { position: relative; }
.progress-track { height: 12px; border-radius: 7px; border: 2px solid var(--ink); background: var(--white); position: relative; overflow: hidden; }
.progress-track i { position: absolute; top: 0; bottom: 0; left: 0; background: var(--orange); transition: width .6s; }
.progress-track i.opp { background: var(--slate); }

/* ---------- Matchmaking ---------- */
.mm { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.searchviz { position: relative; height: 200px; border-radius: var(--r-lg); border: 2px solid var(--ink); background: var(--white); overflow: hidden; display: grid; place-items: center; }
.searchviz .ring { position: absolute; width: 90px; height: 90px; border-radius: 50%; border: 2px solid var(--blue); animation: ping 2s ease-out infinite; }
.searchviz .ring:nth-child(2) { animation-delay: .7s; }
@keyframes ping { from { transform: scale(.6); opacity: 1 } to { transform: scale(2.6); opacity: 0 } }
.searchviz img { width: 90px; height: 110px; object-fit: contain; position: relative; }

/* ---------- Results ---------- */
.results { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.outcome { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px; align-items: center; }
.outcome img { width: 120px; height: 150px; object-fit: contain; }
.outcome h1 { font-size: 34px; }
.statgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; background: var(--white); }
.stat .eyebrow { margin-bottom: 4px; }
.stat .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 13px; color: var(--muted); }
.stat.learn { border: 2px solid var(--cyan); background: var(--cyan-tint); }
.tabs { display: flex; gap: 4px; border-bottom: 1.5px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 10px 14px; min-height: 44px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1.5px; white-space: nowrap; text-decoration: none; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.rrow { display: grid; gap: 10px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--white); } /* K26 */
.rrow .ans { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.rrow .ans > div { border-radius: var(--r-sm); padding: 8px 10px; border: 1.5px solid var(--line); font-size: 14.5px; overflow-wrap: anywhere; }
.rrow .ans .yours.wrong { border: 2px dashed var(--fault); background: var(--pink-tint); }
.rrow .ans .yours.right { border: 2px solid var(--ok); background: var(--green-tint); }
.rrow .ans .key { border: 2px solid var(--ok); background: var(--green-tint); }

/* ---------- Library / profile ---------- */
.libitem { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 10px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--white); } /* K27 */
.libitem .art { width: 96px; height: 64px; border-radius: var(--r-sm); }
.libitem .t { font-weight: 800; overflow-wrap: anywhere; }
.libitem .m { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.libitem .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.liblist { display: grid; gap: 8px; }
.progrow { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.progrow:last-child { border-bottom: 0; }
.meter { height: 10px; border-radius: 6px; background: var(--well); border: 1.5px solid var(--ink); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--cyan); }
.avatars { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.avpick { border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--white); padding: 6px; aspect-ratio: 1; display: grid; place-items: center; }
.avpick img { width: 100%; height: 100%; object-fit: contain; }
.avpick[aria-checked="true"] { border: 3px solid var(--ink); background: var(--blue-tint); }
.toggle { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle:last-child { border-bottom: 0; }
.toggle .txt { min-width: 0; flex: 1; }
.toggle .txt b { display: block; }
.toggle .txt span { font-size: 13px; color: var(--muted); }
.switch { position: relative; width: 52px; height: 30px; border-radius: 16px; border: 2px solid var(--ink); background: var(--well); flex: none; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--white); border: 2px solid var(--ink); transition: left .15s; }
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"]::after { left: 25px; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .bfgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gpage { grid-template-columns: minmax(0, 1fr); }
  .gside { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
  .setup { grid-template-columns: minmax(0, 1fr); }
  .simpanel { position: static; grid-template-columns: 220px minmax(0, 1fr); align-items: start; }
  .bbody { grid-template-columns: minmax(0, 1fr); }
  .scene { border-right: 0; border-bottom: 1px solid var(--line); min-height: 240px; aspect-ratio: 16 / 6.5; }
  .bshell.is-theater .scene, .bshell:fullscreen .scene { aspect-ratio: auto; min-height: 30vh; flex: none; height: 34vh; }
  .results, .lobby, .mm { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 1281px) {
  .bshell.is-theater .bbody, .bshell:fullscreen .bbody { grid-template-columns: minmax(0, 1.4fr) minmax(420px, 1fr); }
}
/* tablet: rail by default handled in JS; drawer below 900 (reference breakpoint) */
@media (max-width: 900px) {
  .layout, body.side-collapsed .layout { display: block; }
  .side { display: none; }
  .hdr .menubtn { display: inline-grid; }
  .hsearch { margin-left: 4px; }
  .hlang .full { display: none; }
  .main { padding-block: 16px 90px; }
  h1 { font-size: 26px; }
  .filterbar.collapsible { display: none; }
  .filterbtn-m { display: inline-flex; }
  .simpanel { grid-template-columns: minmax(0, 1fr); }
  .modes { grid-template-columns: minmax(0, 1fr); }
  .empty { grid-template-columns: minmax(0, 1fr); }
  .empty img { width: 90px; height: 100px; }
  .libitem { grid-template-columns: 72px minmax(0, 1fr); }
  .libitem .art { width: 72px; height: 52px; }
  .libitem .acts { grid-column: 1 / -1; justify-content: flex-start; }
  .progrow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .hsearch { display: none; }
  .hdr .searchbtn { display: inline-grid !important; }
  .brand small { display: none; }
  .bf { padding: 14px 12px 14px; border-radius: var(--r-md); }
  .bfgrid { gap: 8px; }
  .bcard .body { padding: 8px 9px 10px; }
  .bcard h3 { font-size: 15px; }
  .bcard p { font-size: 12.5px; }
  .bcard .modes { display: none; }
  .ggrid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .gcard .gt { font-size: 15px; }
  .slots, .statgrid, .rrow .ans { grid-template-columns: minmax(0, 1fr); }
  .levels { grid-template-columns: minmax(0, 1fr); }
  .outcome { grid-template-columns: 80px minmax(0, 1fr); }
  .outcome img { width: 80px; height: 100px; }
  .outcome h1 { font-size: 26px; }
  .mcq { padding: 12px; }
  .mcq-stem { font-size: 17.5px; }
  .opt { font-size: 16px; }
  .scene { aspect-ratio: 16 / 8; min-height: 170px; }
  .avatars { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pstage { aspect-ratio: 4 / 5; }
  .simtabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .roundinfo { margin-left: 0; width: 100%; justify-content: space-between; }
  .codebox .code { font-size: 20px; }
}
@media (max-width: 640px) { .toasts { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + 10px); } .hdr { gap: 6px; } .brand { font-size: 18px; } .brand .mark { width: 26px; height: 26px; } .hdr-right { gap: 4px; } .hlang { padding: 4px 8px; } .havatar { width: 38px; height: 38px; } .hdr .iconbtn { width: 40px; height: 40px; } }
@media (max-width: 380px) {
  .hclass { padding: 4px 8px; font-size: 13px; }
  .brand .bt { display: none; }
  .ggrid { grid-template-columns: minmax(0, 1fr); }
  .bfgrid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
body.reduce-motion * { animation: none !important; transition: none !important; }
@media print { .side, .hdr { display: none; } }

h1[tabindex="-1"]:focus { outline: none; }

/* ---------- Icon sprite roles ---------- */
.ico .s, .ico.s { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico .f { fill: currentColor; }
.ico .o { stroke: var(--ink); stroke-width: 1.6; stroke-linejoin: round; }
.ico .w { fill: none; stroke: var(--white); stroke-width: 1.8; stroke-linecap: round; }
.ico .f-blue { fill: var(--blue); } .ico .f-cyan { fill: var(--cyan); } .ico .f-green { fill: var(--green); }
.ico .f-brand { fill: var(--brand); } .ico .f-amber { fill: var(--amber); } .ico .f-yellow { fill: var(--yellow); }
.ico .f-pink { fill: var(--pink); } .ico .f-violet { fill: var(--violet); } .ico .f-slate { fill: var(--slate); }
.ico .f-white { fill: var(--white); }
.ico.xl { width: 40px; height: 40px; }

/* ---------- Subject roles (chip edge + icon, never colour alone) ---------- */
.subj-0 { --subj: var(--subj-0); } .subj-1 { --subj: var(--subj-1); } .subj-2 { --subj: var(--subj-2); }
.subj-3 { --subj: var(--subj-3); } .subj-4 { --subj: var(--subj-4); } .subj-5 { --subj: var(--subj-5); }
.chip[class*="subj-"] { border-left: 5px solid var(--subj); }
.chapnum { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 6px; border: 1.5px solid var(--ink); background: var(--white); font-size: 11.5px; font-weight: 800; font-variant-numeric: tabular-nums; flex: none; }
.chaplink[aria-current="page"] .chapnum { background: var(--ink); color: var(--white); }
.groupname { font-size: 11.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 10px 8px 2px; }

/* ---------- Embedded player host ---------- */
.pstage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--paper); }
.player.is-theater, .player:fullscreen { height: 100%; }
.player.is-theater .pstage, .player:fullscreen .pstage { min-height: 0; }
.cover-fallback { position: absolute; inset: 0; display: grid; place-items: center; background: var(--well); color: var(--muted); }
.cover-fallback .ico { width: 56px; height: 56px; }
.gcard .art img, .bcard .art img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Battle scene host ---------- */
.scene iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.standings { position: absolute; inset: 0; display: grid; align-content: center; gap: 14px; padding: 18px; }
.standings .lane { display: grid; grid-template-columns: minmax(80px, 140px) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-weight: 800; font-size: 14px; }
.standings .lane .nm { overflow-wrap: anywhere; }
.tugbar { position: relative; height: 18px; border-radius: 10px; border: 2px solid var(--ink); background: linear-gradient(90deg, var(--orange-tint) 0 50%, var(--well) 50% 100%); }
.tugbar i { position: absolute; top: -7px; width: 6px; height: 28px; border-radius: 3px; background: var(--ink); transform: translateX(-50%); transition: left .6s; }
.pips { display: flex; gap: 4px; flex-wrap: wrap; }
.pips i { width: 14px; height: 14px; border-radius: 4px; border: 1.5px solid var(--ink); background: var(--white); }
.pips i.on { background: var(--green); }
.pips i.lost { background: var(--pink-tint); border-style: dashed; }
.mcq-visual { border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--white); padding: 8px; display: grid; place-items: center; }
.mcq-visual img { max-width: 100%; max-height: 260px; }
.opt .otext { min-width: 0; display: grid; gap: 6px; }
.opt .otext img { max-height: 120px; }
.katex { font-size: 1.05em; }
.mcq-stem .katex-display { margin: .4em 0; overflow-x: auto; overflow-y: hidden; }
.visual-missing { border: 2px dashed var(--fault); background: var(--fault-bg); border-radius: var(--r-sm); padding: 10px 12px; font-size: 14px; }
.lang-note { font-size: 12.5px; color: var(--muted); }
.seq-dots { display: inline-flex; gap: 4px; }
.seq-dots i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--white); }
.seq-dots i.done { background: var(--ink); } .seq-dots i.now { background: var(--amber); }
.scopebar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; border-radius: var(--r-md); border: 1.5px dashed var(--ink); background: var(--cyan-tint); margin-bottom: var(--s4); }
.scopebar .txt { flex: 1 1 240px; min-width: 0; font-size: 14px; }
.leaderboard-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.leaderboard-table th, .leaderboard-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.leaderboard-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.leaderboard-table tr.hl td { background: var(--amber-tint); font-weight: 800; }
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.sim-art .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.sim-art .hero { position: absolute; left: 50%; bottom: 6%; height: 62%; width: auto; max-width: 80%; object-fit: contain; transform: translateX(-50%); }
.sim-tug-of-knowledge { background: var(--orange-tint); }
.sim-tug-of-knowledge .bg, .sim-tug-of-knowledge .hero { inset: auto; bottom: 4%; width: 46%; height: 88%; object-fit: contain; transform: none; }
.sim-tug-of-knowledge .bg { left: 2%; }
.sim-tug-of-knowledge .hero { left: auto; right: 2%; }
.sim-quiz-grand-prix { background: var(--green-tint); }
.sim-quiz-grand-prix .bg { object-fit: contain; }
@media (max-width: 440px) {
  .brand .bt { display: none; }
  .hclass { max-width: 112px; overflow: hidden; }
  .hclass [data-class-label] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hlang { padding: 4px 8px; font-size: 13px; }
}

/* ---------- Battlefield v2: live scene HUD and the phone layout ----------
   The scene is visual only: the frame never takes a touch, so a swipe that
   starts on the world still scrolls the page. The live HUD (power, its time
   left, the objective) sits over the world and never intercepts taps. On a
   phone the world stays pinned under the header while the question scrolls,
   and Confirm stays reachable at the bottom of the screen. */
/* The world on top at 16:9, the HUD strip under it: the HUD never covers
   the cars, fighters, rovers or boats it describes. */
.scene { display: flex; flex-direction: column; }
.scene iframe { pointer-events: none; position: relative; inset: auto; flex: none; width: 100%; height: auto; aspect-ratio: 16 / 9; }
.scene[data-mode="loading"] iframe { background: var(--well); }
.scenehud { position: static; z-index: 2; display: grid; gap: 3px; padding: 5px 6px 6px; pointer-events: none; }
.hudlane { display: grid; grid-template-columns: minmax(44px, 96px) minmax(40px, 1fr) auto auto; gap: 6px; align-items: center; padding: 2px 8px; border-radius: var(--r-pill); background: rgba(255, 255, 255, .86); border: 1.5px solid var(--line); font-size: 12px; font-weight: 800; line-height: 1.3; font-variant-numeric: tabular-nums; }
.hudlane.you { border-color: var(--orange); }
.hudlane .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hudlane .pmeter { position: relative; height: 8px; border-radius: 5px; border: 1.5px solid var(--ink); background: var(--white); overflow: hidden; }
.hudlane .pmeter i { position: absolute; inset: 0 auto 0 0; background: var(--amber); }
.hudlane.you .pmeter i { background: var(--orange); }
.hudlane .pleft { display: inline-flex; align-items: center; gap: 2px; min-width: 0; }
.hudlane .pleft .ico { width: 12px; height: 12px; }
.hudlane .tugbar { grid-column: 1 / 3; height: 12px; }
.hudlane .tugbar i { top: -5px; height: 18px; transition: none; }
.scene[data-mode="board"] .scenehud { padding: 52px 10px 12px; gap: 8px; }
.scene[data-mode="board"] .hudlane { font-size: 14px; padding: 6px 10px; }
.scene[data-mode="board"] { min-height: 0; aspect-ratio: auto; }
.scenebar { pointer-events: auto; align-items: center; }
.scenebar .btn { pointer-events: auto; }

@media (max-width: 900px) {
  /* clip, not hidden: a hidden overflow would make the shell the scroller
     and stop the world and the answer bar from staying in view. */
  .bshell { overflow: visible; overflow: clip; }
  /* Two short rows at most: the round and its timer first, then the players. */
  .bstatus { flex-wrap: wrap; gap: 4px 6px; padding: 6px 8px; }
  .bstatus .who { flex: 0 1 auto; min-width: 0; max-width: calc(50% - 3px); padding: 2px 8px; font-size: 13px; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bstatus .who .mini { display: none; }
  .bstatus .roundinfo { order: -1; margin-left: 0; width: 100%; justify-content: space-between; gap: 6px; font-size: 13px; }
  .timer { min-width: 64px; padding: 2px 8px; }
  .scene { position: sticky; top: calc(var(--head) + env(safe-area-inset-top, 0px)); z-index: 6; aspect-ratio: auto; min-height: 0; height: auto; }
  .answerbar { position: sticky; bottom: 0; z-index: 4; margin: 0 -12px -12px; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--white); border-top: 1px solid var(--line); }
  .answerbar .btn { min-height: 48px; }
  .bshell.is-theater { height: 100vh; height: 100dvh; padding-top: env(safe-area-inset-top, 0px); }
  .bshell.is-theater .scene, .bshell:fullscreen .scene { position: relative; top: 0; flex: none; height: auto; min-height: 0; aspect-ratio: auto; }
  .bshell.is-theater .scene iframe, .bshell:fullscreen .scene iframe { max-height: 40vh; max-height: 40dvh; }
  .bshell.is-theater .bbody, .bshell:fullscreen .bbody { display: flex; flex-direction: column; }
  .bshell.is-theater .mcq, .bshell:fullscreen .mcq { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  .bshell.is-theater .answerbar, .bshell:fullscreen .answerbar { margin-bottom: -12px; }
  .bctrl { padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px)); }
  .bctrl .note-inline { display: none; }
}
@media (max-width: 640px) {
  .scene { aspect-ratio: auto; min-height: 0; }
  .hudlane { font-size: 11px; grid-template-columns: minmax(36px, 72px) minmax(30px, 1fr) auto auto; gap: 4px; padding: 1px 6px; }
}
/* A phone on its side: world and question side by side when both fit. */
@media (max-width: 1280px) and (orientation: landscape) and (max-height: 560px) {
  .bbody { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .scene { position: sticky; top: calc(var(--head) + env(safe-area-inset-top, 0px)); align-self: start; aspect-ratio: auto; min-height: 0; border-right: 1px solid var(--line); border-bottom: 0; }
  .bshell.is-theater .bbody, .bshell:fullscreen .bbody { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); flex: 1; min-height: 0; }
  .bshell.is-theater .scene, .bshell:fullscreen .scene { position: relative; top: 0; max-height: none; align-self: center; }
  .bshell.is-theater .mcq, .bshell:fullscreen .mcq { height: 100%; overflow-y: auto; }
}

/* ---- Embedded player lifecycle: result and save line (player.js) ---- */
.presult { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--paper); }
.presult[hidden] { display: none; }
.presult-line { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.presult-line .small { color: var(--muted); }
.player.is-theater .presult, .player:fullscreen .presult { flex: none; }
[data-cover] .cta [data-resume-row] { justify-content: center; }
/* ---- end embedded player lifecycle ---- */
/* Wide expanded/fullscreen: the world fills the space above its HUD strip
   (the scene letterboxes itself). */
@media (min-width: 901px) {
  .bshell.is-theater .scene iframe, .bshell:fullscreen .scene iframe { flex: 1 1 auto; min-height: 0; aspect-ratio: auto; }
}
@media (min-width: 901px) and (max-width: 1280px) {
  .bshell:not(.is-theater):not(:fullscreen) .scene { aspect-ratio: auto; min-height: 0; }
}
/* The narrowest phones (320 px): the header's class chip and language pill
   give up a little width so the page never scrolls sideways. */
@media (max-width: 360px) {
  .hdr { gap: 4px; padding-inline: 8px; }
  .hdr-right { gap: 2px; }
  .hclass { max-width: 84px; padding: 4px 6px; }
  .hlang { padding: 4px 6px; }
  .hdr .iconbtn { width: 36px; height: 36px; }
  .havatar { width: 34px; height: 34px; }
}
