/* VolleySigns — dark "night court" theme: navy like the sign photos,
   yellow/blue accents of a match volleyball, orange court. */

:root {
  --bg: #08122b;
  --bg-2: #0b1838;
  --surface: #11224b;
  --surface-2: #172c5d;
  --surface-3: #213a74;
  --line: rgba(160, 185, 255, 0.13);
  --line-2: rgba(160, 185, 255, 0.24);
  --text: #f2f5ff;
  --text-2: #c6d0ec;
  --muted: #8f9ec8;
  --yellow: #ffc928;
  --yellow-2: #ffd75a;
  --blue: #2f6fe0;
  --blue-2: #5b93ff;
  --orange: #e98a3c;
  --good: #34d17f;
  --good-bg: rgba(52, 209, 127, 0.13);
  --bad: #ff5d6c;
  --bad-bg: rgba(255, 93, 108, 0.13);
  --mid: #ffb547;
  --ink: #0b1a3f;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  --font: 'Rubik', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Russo One', 'Rubik', system-ui, sans-serif;
  --topbar-h: 64px;
  --tabbar-h: 0px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1100px 600px at 90% -10%, rgba(47, 111, 224, 0.32), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(255, 201, 40, 0.10), transparent 60%),
    var(--bg);
}
/* volleyball net mesh fading downwards */
.backdrop::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 24px);
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent 55%);
  mask-image: linear-gradient(to bottom, #000, transparent 55%);
}

h1, h2, h3 { margin: 0; line-height: 1.15; }
h1 { font-family: var(--display); font-weight: 400; font-size: clamp(26px, 4vw, 34px); letter-spacing: 0.01em; }
h2 { font-size: 20px; font-weight: 600; }
p { margin: 0; }
a { color: var(--blue-2); text-decoration: none; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; color: var(--text-2); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.icon { width: 20px; height: 20px; flex: none; }

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 max(16px, calc((100vw - 1140px) / 2));
  background: rgba(8, 18, 43, 0.78);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 21px;
  color: var(--text);
  letter-spacing: 0.02em;
}
.brand b, .auth-card h1 b { color: var(--yellow); font-weight: 400; }
.brand .ball { width: 32px; height: 32px; transition: transform 0.6s ease; }
.brand:hover .ball { transform: rotate(240deg); }

.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 15px;
}
.nav a .icon { width: 18px; height: 18px; }
.nav a:hover { color: var(--text); background: var(--surface); }
.nav a.active { color: var(--ink); background: var(--yellow); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 500;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
}
.user-chip:hover { background: var(--surface); }
.uc-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--yellow-2), var(--yellow) 60%, #e0a800);
  color: var(--ink);
  font-family: var(--display);
  font-size: 24px;
  flex: none;
}
.avatar.sm { width: 30px; height: 30px; font-size: 14px; }

/* bottom tab bar — phones only */
.tabbar { display: none; }

/* ------------------------------------------------------------------ layout */

.main {
  max-width: 1140px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}

.loading { display: grid; place-items: center; min-height: 40vh; }
.spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 4px solid var(--surface-3);
  border-top-color: var(--yellow);
  border-right-color: var(--blue-2);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page { display: grid; gap: 18px; }
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.page-head p { margin-top: 6px; max-width: 620px; }
.eyebrow {
  color: var(--yellow);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 40%), var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}
.card.narrow { max-width: 480px; }
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
}
.card-title .muted { font-weight: 400; }
.card-title-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title-row .card-title { margin: 0; }
.cards-2 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.tile-label { color: var(--muted); font-size: 13px; }
.tile-value { font-size: 28px; font-weight: 600; margin-top: 2px; }
.tile-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.row-end { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.row-center { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--text);
  font: 600 15px var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn .icon { width: 18px; height: 18px; }
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--yellow); border-color: var(--yellow); color: var(--ink); }
.btn.primary:hover { background: var(--yellow-2); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface); }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.big { height: 50px; width: 100%; font-size: 16px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

.link { background: none; border: 0; padding: 0; color: var(--blue-2); font: inherit; font-weight: 600; cursor: pointer; }
.link:hover { text-decoration: underline; }

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  padding: 4px;
  gap: 4px;
  border-radius: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  font: 500 14px var(--font);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.segmented button:hover { color: var(--text); background: var(--surface); }
.segmented button[aria-pressed='true'],
.segmented button[aria-selected='true'] { background: var(--yellow); color: var(--ink); font-weight: 600; }
.segmented.wide { display: flex; }
.segmented.wide button { flex: 1; }

.form { display: grid; gap: 14px; text-align: left; }
.form label { display: grid; gap: 6px; font-size: 14px; color: var(--text-2); font-weight: 500; }
.form input, .search {
  height: 46px;
  width: 100%;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: var(--text);
  font: 16px var(--font);
}
.form input:focus, .search:focus { outline: none; border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 201, 40, 0.25); }
.form input[aria-invalid='true'] { border-color: var(--bad); box-shadow: 0 0 0 3px rgba(255, 93, 108, 0.22); }
.search { height: 38px; width: min(260px, 100%); font-size: 14px; }
.input-row { display: flex; gap: 8px; }
.input-row .btn { height: 46px; }
.form-error { color: var(--bad); font-size: 14px; min-height: 1em; }
.form-error:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip[class*='lv-']::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.lv-good::before { background: var(--good); }
.chip.lv-mid::before { background: var(--mid); }
.chip.lv-bad::before { background: var(--bad); }
.chip.admin { background: rgba(255, 201, 40, 0.14); color: var(--yellow-2); border-color: rgba(255, 201, 40, 0.3); }
.chip.mode-all { color: #bcd2ff; }
.chip.mode-errors { color: #ffc2c8; }
.chip.mode-blitz { color: var(--yellow-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tabs a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  color: var(--text-2);
  font-weight: 500;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.tabs a .icon { width: 18px; height: 18px; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--yellow); }
[data-tab] { display: grid; gap: 18px; }

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding: 8px;
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}
.table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table.compact td, .table.compact th { padding: 6px 8px; }
.actions-cell { text-align: right; }

/* ------------------------------------------------------------------ charts */

.cchart { padding-bottom: 4px; }
.cc-plot { position: relative; margin: 6px 0 26px; }
.cc-grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.cc-grid span {
  position: absolute;
  left: 0;
  top: -8px;
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  background: var(--surface);
  padding-right: 4px;
  font-variant-numeric: tabular-nums;
}
.cc-cols { position: absolute; inset: 0 0 0 30px; display: flex; align-items: stretch; gap: 2px; }
.cc-col {
  position: relative;
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-radius: 4px;
  outline-offset: 0;
}
.cc-bar {
  width: min(100%, 18px);
  background: var(--yellow);
  border-radius: 4px 4px 0 0;
  transition: filter 0.15s ease;
}
.cc-col:hover, .cc-col:focus-visible { background: rgba(255, 255, 255, 0.05); }
.cc-col:hover .cc-bar { filter: brightness(1.12); }
.cc-x {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.cc-table summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.cc-table[open] summary { margin-bottom: 8px; }

.chart-tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 300;
  max-width: 260px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #f4f7ff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.chart-tip.show { opacity: 1; }

.barlist { display: grid; }
.bl-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.bl-row:last-child { border-bottom: 0; }
.bl-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 8px; display: block; }
.bl-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.bl-name { font-weight: 500; }
.bl-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.bl-track { height: 8px; border-radius: 999px; background: var(--surface-3); margin: 6px 0; overflow: hidden; }
.bl-fill { height: 100%; border-radius: 999px; background: var(--muted); transition: width 0.6s ease; }
.bl-fill.lv-good { background: var(--good); }
.bl-fill.lv-mid { background: var(--mid); }
.bl-fill.lv-bad { background: var(--bad); }
.bl-sub { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; }

/* ------------------------------------------------------------------ auth */

.auth {
  min-height: calc(100dvh - var(--topbar-h) - 80px);
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 460px);
  justify-content: center;
  align-items: center;
  gap: 48px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}
.auth-logo .ball { width: 76px; height: 76px; animation: float 4s ease-in-out infinite; filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.4)); }
@keyframes float { 50% { transform: translateY(-6px) rotate(20deg); } }
.auth-card h1 { font-size: 32px; }
.auth-art .court { width: 100%; transform: rotate(-6deg); filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.45)); }
body.guest .topbar { justify-content: center; }

/* ------------------------------------------------------------------ home */

.home { display: grid; gap: 22px; }
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 28px;
  align-items: center;
  padding: 28px;
  border-radius: 24px;
  background:
    radial-gradient(500px 300px at 100% 0%, rgba(255, 201, 40, 0.16), transparent 70%),
    linear-gradient(135deg, #1a3b86, #10224f 70%);
  border: 1px solid var(--line-2);
  overflow: hidden;
}
.hero-text p { margin-top: 10px; max-width: 520px; color: var(--text-2); }
.hero-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 22px; }
.hero-stats div {
  display: grid;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(8, 18, 43, 0.45);
  border: 1px solid var(--line);
}
.hero-stats b { font-size: 22px; font-weight: 600; color: var(--yellow); }
.hero-stats span { font-size: 12px; color: var(--muted); }
.hero-art .court { width: 100%; transform: rotate(-5deg); filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.45)); }

.modes { display: grid; gap: 14px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mode-card {
  --accent: var(--blue-2);
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas: 'icon' 'title' 'desc' 'meta';
  column-gap: 16px;
  row-gap: 6px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.mode-card::after {
  content: '';
  position: absolute;
  right: -40px;
  top: -40px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%);
  pointer-events: none;
}
.mode-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: var(--surface-2); }
.m-errors { --accent: var(--bad); }
.m-blitz { --accent: var(--yellow); }
.mc-icon {
  margin-bottom: 6px;
  grid-area: icon;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.mc-icon .icon { width: 26px; height: 26px; }
.mc-title { grid-area: title; font-family: var(--display); font-size: 22px; }
.mc-desc { grid-area: desc; color: var(--text-2); font-size: 14px; }
.mc-meta { grid-area: meta; margin-top: 8px; font-size: 13px; font-weight: 600; color: var(--accent); }

/* ------------------------------------------------------------------ quiz */
/* The quiz always fits one screen. Header rows have fixed heights, the
   question card takes what is left, and inside it the media area (a size
   container) packs its images with cqw/cqh so they shrink to fit. */

body.playing .tabbar { display: none; }
body.playing .main {
  height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-bottom, 0px));
  padding-top: 16px;
  padding-bottom: 16px;
  display: flex;
  flex-direction: column;
}
body.playing .view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.play {
  --g: 10px;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 640px;
  max-height: 840px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.play-head { flex: none; display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px; }
.play-title { font-family: var(--display); font-size: 20px; }
.play-meta { color: var(--text-2); font-weight: 500; font-variant-numeric: tabular-nums; }
.progress { flex: none; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--blue-2), var(--yellow)); transition: width 0.4s ease; }

.play-body {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: 'card' 'fb';
}
.play-body.with-hud { grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: 'hud' 'card' 'fb'; }

.hud { grid-area: hud; display: flex; align-items: center; gap: 8px; }
.hud-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.hud-item .icon { width: 16px; height: 16px; color: var(--yellow); }
.hud .btn { margin-left: auto; }

.q-card {
  grid-area: card;
  container: card / size;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
}
.q-card.enter { animation: rise 0.28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.q-layout { height: 100%; display: flex; flex-direction: column; gap: 12px; }
.q-top { flex: none; display: grid; gap: 6px; justify-items: start; }
.q-media { flex: 1 1 0; min-height: 0; container: media / size; display: grid; place-items: center; }
.q-answers { flex: none; }

/* Wide and low card (phone in landscape): media left, answers right. */
@container card (aspect-ratio > 3 / 2) {
  .q-layout.has-answers {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: 'top top' 'media answers';
  }
  .has-answers .q-top { grid-area: top; }
  .has-answers .q-media { grid-area: media; }
  .has-answers .q-answers { grid-area: answers; align-self: center; }
}
.q-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--yellow);
  border: 1px solid rgba(255, 201, 40, 0.45);
  background: rgba(255, 201, 40, 0.08);
}
.q-badge .icon { width: 14px; height: 14px; }
.q-prompt { font-size: 17px; font-weight: 600; color: var(--text-2); }
.q-hint { font-size: 13px; color: var(--muted); }
.q-name {
  justify-self: stretch;
  font-family: var(--display);
  font-size: clamp(22px, 7cqh, 36px);
  line-height: 1.15;
  color: var(--yellow);
  text-align: center;
  padding: 4px 0;
}

.sign-img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #1a2a5c; user-select: none; -webkit-user-select: none; }

/* Media packing. Each width is the largest grid of 4:3 cells that fits the
   media area: min(available width, width implied by available height). */
.media-box { display: grid; gap: var(--g); }
.mb-photo { width: min(100cqw, 100cqh * 4 / 3); }
.mb-photo .sign-img { border-radius: 14px; }
.mb-grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); width: min(100cqw, (100cqh - var(--g)) * 4 / 3 + var(--g)); }
.mb-grid6 { grid-template-columns: repeat(3, minmax(0, 1fr)); width: min(100cqw, 200cqh); }
.mb-combo {
  grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr);
  align-items: center;
  width: min(100cqw, 100cqh * 8 / 3 + 28px + 2 * var(--g));
}
@container media (aspect-ratio > 8 / 3) {
  .mb-grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); width: min(100cqw, 100cqh * 16 / 3 + 3 * var(--g)); }
}
@container media (aspect-ratio < 4 / 3) {
  .mb-grid6 { grid-template-columns: repeat(2, minmax(0, 1fr)); width: min(100cqw, (100cqh - 2 * var(--g)) * 8 / 9 + var(--g)); }
}

.opts { display: grid; gap: var(--g); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.opts.list { grid-template-columns: 1fr; }
.opts.list .name-opt { min-height: 46px; }

.opt {
  --bc: var(--line-2);
  position: relative;
  border: 2px solid var(--bc);
  background: var(--surface-2);
  color: var(--text);
  font: 600 16px var(--font);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease, opacity 0.2s ease;
}
.opt:hover { --bc: var(--blue-2); background: var(--surface-3); }
.opt:active { transform: scale(0.98); }
.name-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 14px;
  text-align: left;
  line-height: 1.2;
}
.name-opt .sep { color: var(--yellow); }
.key {
  display: none;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line-2);
  background: rgba(8, 18, 43, 0.6);
}
@media (hover: hover) and (pointer: fine) { .key { display: grid; } }

/* Image options draw their frame on top of the photo, so the button is
   exactly one 4:3 cell and the packing maths above stays exact. */
.pic-opt { border: 0; padding: 0; overflow: hidden; border-radius: 12px; background: none; }
.pic-opt::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--bc);
  border-radius: inherit;
  pointer-events: none;
  transition: border-color 0.15s ease;
}
.pic-opt .key { position: absolute; top: 8px; left: 8px; color: var(--text-2); }

.pic-cap, .pic-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 8px 7px;
  font-size: 14px;
  line-height: 1.2;
  text-align: center;
  background: linear-gradient(transparent, rgba(5, 12, 30, 0.92) 55%);
}
.pic-cap { opacity: 0; transition: opacity 0.2s ease; }
.revealed .pic-cap:not(:empty) { opacity: 1; }
.pic-label s { text-decoration: none; }
.pic-label .real { display: none; color: var(--yellow); }
.fixed .pic-label s { text-decoration: line-through; opacity: 0.7; font-weight: 400; }
.fixed .pic-label .real { display: block; margin-top: 2px; }

.answered .opt { pointer-events: none; }
.opt.dim { opacity: 0.42; }
.opt.right { --bc: var(--good); background: var(--good-bg); box-shadow: 0 0 0 3px rgba(52, 209, 127, 0.3); opacity: 1; }
.opt.wrong { --bc: var(--bad); background: var(--bad-bg); box-shadow: 0 0 0 3px rgba(255, 93, 108, 0.3); opacity: 1; animation: shake 0.35s ease; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* combination question */
.mb-combo figure { margin: 0; position: relative; }
.mb-combo .sign-img { border-radius: 12px; }
.mb-combo figcaption {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 700;
}
.combo-arrow { color: var(--yellow); display: grid; place-items: center; }
.combo-arrow .icon { width: 28px; height: 28px; }

/* matching question */
.match-names { display: grid; gap: var(--g); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.match-names .name-opt { min-height: 46px; }
.pair-badge:empty { display: none; }
.pair-badge {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  background: var(--pair, var(--text));
}
.pic-opt .pair-badge { position: absolute; top: 8px; right: 8px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); }
.opt.p1 { --pair: #5b93ff; }
.opt.p2 { --pair: #c084fc; }
.opt.p3 { --pair: #2ec4b6; }
.opt.p4 { --pair: #ff8c42; }
:is(.opt.p1, .opt.p2, .opt.p3, .opt.p4):not(.right):not(.wrong) { --bc: var(--pair); }
.opt.selected { --bc: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 201, 40, 0.35); }

/* Answer feedback: a fixed-height strip under the card on narrow screens,
   a side panel next to it on wide ones (see the 980px query below). */
.feedback {
  grid-area: fb;
  height: 72px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}
.feedback.idle { background: transparent; border-style: dashed; color: var(--muted); }
.feedback.good { background: var(--good-bg); border-color: rgba(52, 209, 127, 0.35); }
.feedback.bad { background: var(--bad-bg); border-color: rgba(255, 93, 108, 0.35); }
.fb-text { display: flex; align-items: flex-start; gap: 4px 8px; font-weight: 600; font-size: 15px; line-height: 1.3; }
.feedback.idle .fb-text { font-weight: 500; font-size: 14px; align-items: center; }
.fb-text > .icon { flex: none; margin-top: 1px; }
.fb-msg {
  flex: 1 1 0;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.feedback.good .fb-text > .icon { color: var(--good); }
.feedback.bad .fb-text > .icon { color: var(--bad); }
.streak-note { display: inline-flex; align-items: center; gap: 4px; color: var(--yellow); font-weight: 600; white-space: nowrap; }
.streak-note .icon { width: 16px; height: 16px; }
.fb-timer { flex: none; height: 3px; margin-top: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.fb-timer div { height: 100%; background: currentColor; opacity: 0.5; animation: drain linear forwards; }
.feedback.good .fb-timer div { color: var(--good); }
.feedback.bad .fb-timer div { color: var(--bad); }
@keyframes drain { from { width: 100%; } to { width: 0; } }

/* Low card: tighter text so the images keep some room. Kept after the base
   option rules so it wins over them. */
@container card (height < 430px) {
  .q-hint { display: none; }
  .name-opt, .opts.list .name-opt, .match-names .name-opt { min-height: 42px; padding: 5px 10px; font-size: 14px; }
  .opts.list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .q-name { padding: 0; }
}

/* Wide screens, and phones in landscape, show feedback beside the card. */
@media (min-width: 980px), (min-width: 600px) and (max-height: 560px) and (min-aspect-ratio: 3 / 2) {
  .play { max-width: 960px; }
  .play-body { grid-template-columns: minmax(0, 1fr) 280px; grid-template-rows: minmax(0, 1fr); grid-template-areas: 'card fb'; }
  .play-body.with-hud { grid-template-rows: auto minmax(0, 1fr); grid-template-areas: 'card hud' 'card fb'; }
  .hud { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-self: start; }
  .hud .btn { grid-column: 1 / -1; margin: 0; }
  .feedback { align-self: start; height: auto; min-height: 190px; padding: 20px; justify-content: flex-start; }
  .fb-text { flex-direction: column; gap: 12px; font-size: 18px; }
  .feedback.idle .fb-text { align-items: flex-start; font-size: 15px; }
  .fb-text > .icon {
    width: 48px;
    height: 48px;
    padding: 11px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
  }
  .feedback.good .fb-text > .icon { background: rgba(52, 209, 127, 0.18); }
  .feedback.bad .fb-text > .icon { background: rgba(255, 93, 108, 0.18); }
  .fb-msg { display: block; flex: none; }
  .fb-timer { margin-top: 18px; }
}

/* Low screens: every pixel goes to the question. */
@media (max-height: 560px) {
  body.playing { --topbar-h: 0px; }
  body.playing .topbar { display: none; }
  body.playing .main { padding-top: 8px; padding-bottom: 8px; }
  .play, .play-body { gap: 8px; }
  .play-head .icon-btn { width: 34px; height: 34px; }
  .play-head { grid-template-columns: 34px 1fr auto; }
}
@media (min-width: 600px) and (max-height: 560px) and (min-aspect-ratio: 3 / 2) {
  .play-body { grid-template-columns: minmax(0, 1fr) 210px; }
  .hud { gap: 6px; }
  .hud-item { padding: 4px 6px; gap: 4px; }
  .feedback { align-self: stretch; min-height: 0; padding: 12px; }
  .fb-text { gap: 8px; font-size: 15px; }
  .feedback.idle .fb-text { font-size: 14px; }
  .fb-text > .icon { width: 36px; height: 36px; padding: 8px; }
  .fb-timer { margin-top: 10px; }
}

/* summary */
.summary { max-width: 760px; margin: 0 auto; display: grid; gap: 20px; }
.sum-hero { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.sum-hero h1 { margin-bottom: 6px; }
.ring {
  --p: 0;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--yellow) calc(var(--p) * 1%), var(--surface-2) 0);
  flex: none;
}
.ring span {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--bg);
  font-size: 28px;
  font-weight: 600;
}
.section-title { margin-top: 4px; }
.mistakes { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.mistake {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.mistake .sign-img { width: 76px; border-radius: 10px; flex: none; }
.mistake div { display: grid; }
.perfect { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--yellow); }
.actions { margin-top: 6px; }

.empty-state { max-width: 520px; margin: 8vh auto; text-align: center; display: grid; gap: 14px; justify-items: center; }
.empty-icon { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--yellow); }
.empty-icon .icon { width: 36px; height: 36px; }

/* ------------------------------------------------------------------ overview */

.level-summary { display: flex; flex-wrap: wrap; gap: 8px; }
/* Flex rather than grid so an unfinished last row is centred. The column
   count follows the grid's own width (cards stay at least ~220px wide). */
.sign-grid {
  --gap: 14px;
  container-type: inline-size;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gap);
}
.sign-grid > .sign-card { --cols: 4; flex: 0 0 calc((100% - (var(--cols) - 1) * var(--gap)) / var(--cols)); min-width: 0; }
@container (max-width: 921px) { .sign-grid > .sign-card { --cols: 3; } }
@container (max-width: 687px) { .sign-grid > .sign-card { --cols: 2; } }
.sign-card {
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.sign-card:hover { transform: translateY(-2px); border-color: var(--line-2); }
.sc-body { padding: 12px 14px 14px; display: grid; gap: 4px; }
.sc-name { font-weight: 600; font-size: 16px; }
.sc-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sc-pct { font-size: 24px; font-weight: 600; }
.sc-sub { font-size: 13px; }
.sign-detail { display: grid; gap: 14px; }
.sd-img .sign-img { border-radius: 14px; }
.sd-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }

/* ------------------------------------------------------------------ account */

.profile-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.ph-text { flex: 1; min-width: 180px; display: grid; gap: 4px; }
.ph-text h1 { overflow-wrap: anywhere; }
.ph-login { color: var(--text-2); font-weight: 600; }
.ph-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sessions { display: grid; }
.session-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: 'mode when score' 'mode extra extra';
  gap: 2px 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.session-row:last-child { border-bottom: 0; }
.session-row .chip { grid-area: mode; align-self: start; margin-top: 2px; }
.sr-when { grid-area: when; }
.sr-score { grid-area: score; text-align: right; font-variant-numeric: tabular-nums; }
.sr-extra { grid-area: extra; font-size: 12px; }
.user-meta { margin-bottom: 16px; }
.modal-body > .tiles, .modal-body > .cards-2 { margin-bottom: 16px; }

/* ------------------------------------------------------------------ modal & toast */

.modal-wrap {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 8, 20, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 20px;
  box-shadow: var(--shadow);
  animation: rise 0.2s ease;
}
.modal.wide { width: min(1040px, 100%); }
.modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.modal-body { padding: 18px; }
.modal .card { background: var(--bg-2); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--tabbar-h) + env(safe-area-inset-bottom));
  z-index: 400;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 14px;
  background: #f4f7ff;
  color: var(--ink);
  font-weight: 500;
  box-shadow: var(--shadow);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  border-left: 5px solid var(--blue);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.good { border-left-color: var(--good); }
.toast.error { border-left-color: var(--bad); }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .auth { grid-template-columns: minmax(0, 440px); gap: 24px; }
  .auth-art { display: none; }
  .hero { grid-template-columns: 1fr; padding: 22px; }
  .hero-art { display: none; }
}

@media (max-width: 720px) {
  :root { --topbar-h: 56px; --tabbar-h: 64px; }
  .nav, .uc-name { display: none; }
  .user-chip { margin-left: auto; padding: 3px; border: 0; }
  .brand { font-size: 19px; }
  body.guest { --tabbar-h: 0px; }

  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: flex;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(8, 18, 43, 0.94);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line-2);
  }
  body.guest .tabbar { display: none; }
  .tabbar a {
    flex: 1;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
  }
  .tabbar a .icon { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--yellow); }

  /* full-screen quiz on phones */
  body.playing { --tabbar-h: 0px; --topbar-h: 0px; }
  body.playing .topbar { display: none; }
  body.playing .main { padding: 10px 12px; }
  .play { --g: 8px; gap: 10px; }
  .play-body { gap: 10px; }

  .main { padding: 18px 12px 32px; }
  .modes { grid-template-columns: 1fr; }
  .mode-card {
    padding: 16px;
    grid-template-columns: auto 1fr;
    grid-template-rows: none;
    grid-template-areas: 'icon title' 'icon desc' 'icon meta';
    row-gap: 4px;
  }
  .mc-icon { margin-bottom: 0; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .q-card { padding: 12px; border-radius: 16px; }
  .q-layout { gap: 10px; }
  .q-prompt { font-size: 16px; }
  .name-opt { font-size: 15px; padding: 8px 12px; }
  .pic-cap, .pic-label { font-size: 13px; }
  .feedback { padding: 8px 12px; }
  .sign-grid { --gap: 10px; }
  .sc-body { padding: 10px; }
  .sc-pct { font-size: 20px; }
  .sc-name { font-size: 14px; }
  .sum-hero { gap: 16px; }
  .ring { width: 104px; height: 104px; }
  .ring span { width: 80px; height: 80px; font-size: 22px; }
  .tile-value { font-size: 24px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ph-actions { width: 100%; }
  .ph-actions .btn { flex: 1 1 auto; }
  .page-head .segmented { width: 100%; }
  .page-head .segmented button { flex: 1; }

  /* tables become stacked cards */
  .table.stack thead { display: none; }
  .table.stack tr { display: grid; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table.stack tr:last-child { border-bottom: 0; }
  .table.stack td { display: flex; justify-content: space-between; gap: 12px; padding: 0; border: 0; text-align: right; }
  .table.stack td[data-label]::before { content: attr(data-label); color: var(--muted); text-align: left; }
  .table.stack .actions-cell { justify-content: flex-end; padding-top: 6px; }
  .modal-wrap { padding: 0; align-items: end; }
  .modal { border-radius: 20px 20px 0 0; max-height: 92dvh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .fb-timer div { animation-duration: 2s !important; }
}
