/* صدى على نظام تصميم أدوات الجزيرة (AJ Tool Design System):
   أسطح دافئة فاتحة، تحكّمات على شكل كبسولة، لون إبراز برتقالي واحد،
   وخط الجزيرة للعربية مع Helvetica للأرقام والرموز. سمتان: فاتحة وداكنة. */

/* ---------- fonts (self-hosted: CSP allows only 'self') */
@font-face { font-family: "Al Jazeera"; src: url("/fonts/AlJazeera-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Al Jazeera"; src: url("/fonts/AlJazeera-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Al Jazeera"; src: url("/fonts/AlJazeera-Heavy.woff2") format("woff2"); font-weight: 800 900; font-display: swap; }
@font-face { font-family: "AJ Helvetica"; src: url("/fonts/Helvetica.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "AJ Helvetica"; src: url("/fonts/Helvetica-Bold.woff2") format("woff2"); font-weight: 700 900; font-display: swap; }

/* ---------- tokens: light-dark(light, dark), switched by color-scheme */
:root {
  color-scheme: light dark;

  --accent-gold: #FC7E34;
  --accent-gold-soft: light-dark(#FFCD6C, #6B4F16);
  --accent-sky: light-dark(#0090FC, #3AA8FF);

  --surface-base: light-dark(#FBFAF9, #121212);
  --surface-raised: light-dark(#F6F4EE, #242423);
  --surface-cream: light-dark(#F3EBDF, #2C2721);
  --surface-sand: light-dark(#E5D5C3, #4A4035);
  --surface-card: light-dark(#FFFFFF, #1C1C1B);
  --surface-track: light-dark(#F2EEE6, #2C2B29);
  --surface-inverse: light-dark(#121212, #FBFAF9);

  --border-hairline: light-dark(#E4E4E4, #3A3937);
  --border-card: light-dark(#ECE7DF, #2E2C29);
  --border-control: light-dark(#CFC9BF, #6E6A64);
  --divider: light-dark(rgba(153,153,153,0.3), rgba(255,255,255,0.12));
  --topbar-glass: light-dark(rgba(251,250,249,0.82), rgba(18,18,18,0.82));

  --text-ink: light-dark(#121212, #FBFAF9);
  --text-body: light-dark(#343433, #E4E2DE);
  --text-secondary: light-dark(#474645, #C9C6C0);
  --text-muted: light-dark(#747485, #A3A3B2);
  --text-faint: light-dark(#999999, #8F8D88);
  --text-disabled: light-dark(#B0ABA3, #6B6862);
  --text-tag: light-dark(#5C5347, #E5D5C3);

  --success: #00C978;
  --success-tint: light-dark(#E7F9F0, #0E2A1E);
  --success-ink: light-dark(#00824E, #3BE38C);
  --warning-tint: light-dark(#FFF3DB, #33240F);
  --warning-ink: light-dark(#B07700, #FFB066);
  --danger: light-dark(#215E61, #5FB3B6);
  --danger-tint: light-dark(#E4EFEF, #12292A);
  --danger-ink: light-dark(#173E40, #8FD3D5);
  --selected-tint: light-dark(#FFF3EB, #33200F);

  --chart-1: #FC7E34;
  --chart-2: light-dark(#FD9A5E, #D46A2D);
  --chart-3: light-dark(#FEB585, #A45527);
  --chart-4: light-dark(#FFD0AE, #76401F);
  --chart-track: light-dark(#EFE9DF, #2C2B29);

  --shadow-sm: 0 1px 2px light-dark(rgba(18,18,18,0.06), rgba(0,0,0,0.4));
  --shadow-segment: 0 2px 8px -2px light-dark(rgba(18,18,18,0.18), rgba(0,0,0,0.5));
  --focus-ring: 0 0 0 4px light-dark(rgba(252,126,52,0.16), rgba(252,126,52,0.28));

  --radius-check: 7px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-option: 20px;
  --radius-panel: 24px;
  --radius-lg: 28px;
  --radius-pill: 999px;

  --space-4: 4px; --space-8: 8px; --space-16: 16px; --space-24: 24px; --space-32: 32px; --space-48: 48px;

  --font-arabic: "Al Jazeera", "SF Arabic", "Geeza Pro", sans-serif;
  --font-latin: "AJ Helvetica", "Al Jazeera", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --ease: ease;

  --logo: url("/assets/aj-logo-ink.svg");

  /* Legacy names still set inline by js/results.js (word-cloud tones). */
  --chalk: var(--text-ink);
  --chalk-2: var(--text-muted);
  --sage: var(--text-secondary);
  --sage-deep: var(--text-tag);
  --ochre: var(--accent-gold);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --logo: url("/assets/aj-logo-original.svg"); }
}
:root[data-theme="dark"] { --logo: url("/assets/aj-logo-original.svg"); }

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

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font-arabic);
  font-size: 17px;
  background: var(--surface-base);
  color: var(--text-body);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { color: var(--text-ink); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-sky); text-decoration: none; font-weight: 700; }
a:hover { color: var(--text-ink); }
::selection { background: var(--accent-gold-soft); color: var(--text-ink); }

:focus-visible { outline: 2px solid var(--accent-gold); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Latin, numbers and codes: Helvetica, isolated LTR inside Arabic. */
.mono, bdi, .code, .join-hint b, .deck-meta bdi { font-family: var(--font-latin); }

/* ---------- brand: the AJ mark, then the product name «صدى» */
.brand {
  display: inline-flex; align-items: center; gap: 12px;
  color: var(--text-ink); font-weight: 900; font-size: 18px; line-height: 1;
}
.brand:hover { color: var(--text-ink); }
.brand::before {
  content: ""; flex: none; width: 20px; height: 34px;
  background: var(--logo) center / contain no-repeat;
}
.brand > svg.tally { display: none; }
.editor .brand::after, .vote .brand::after { content: "صدى"; }

/* The Sada tally glyph, kept for the "vote counted" moment. */
.tally path { stroke: var(--text-ink); stroke-width: 2.4; stroke-linecap: round; fill: none; }
.tally path.slash { stroke: var(--accent-gold); }

/* ---------- buttons: pills, 15px bold */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 12px 24px;
  border: 0; border-radius: var(--radius-pill);
  background: var(--surface-inverse); color: var(--surface-base);
  font-size: 15px; font-weight: 700; line-height: 1.2; cursor: pointer;
  transition: background-color 0.18s var(--ease), opacity 0.18s var(--ease);
}
.btn:hover { opacity: 0.86; }
.btn:disabled { background: var(--surface-track); color: var(--text-disabled); cursor: not-allowed; opacity: 1; }
.btn svg { width: 18px; height: 18px; transition: transform 0.2s var(--ease); }
.btn:hover svg.arrow { transform: translate(-3px, -3px); }
/* Send/commit step: the system's green, ink label for contrast. */
.btn.submit { background: var(--success); color: #121212; }
.btn.submit:disabled { background: var(--surface-track); color: var(--text-disabled); }

.quiet {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 8px 14px;
  border: 0; border-radius: var(--radius-pill);
  background: transparent; color: var(--text-body); cursor: pointer;
  font-size: 15px; font-weight: 700;
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease);
}
.quiet:hover { background: var(--surface-track); color: var(--text-ink); }
.quiet[aria-pressed="true"] { background: var(--selected-tint); color: var(--text-ink); }
.quiet[aria-pressed="true"] svg { color: var(--accent-gold); }
.quiet svg { width: 20px; height: 20px; }

/* ---------- fields: raised fill, 1.5px hairline, gold focus */
.field {
  width: 100%; min-height: 44px; padding: 10px 18px;
  border: 1.5px solid var(--border-hairline); border-radius: var(--radius-pill);
  background: var(--surface-raised); color: var(--text-ink); font-size: 15px;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
textarea.field { border-radius: var(--radius-md); padding: 12px 18px; }
.field:hover { border-color: var(--border-control); }
.field:focus { outline: none; border-color: var(--accent-gold); box-shadow: var(--focus-ring); }
.field::placeholder { color: var(--text-faint); }
select.field { cursor: pointer; }

.error-line { min-height: 1.6em; margin: 8px 0 0; color: var(--danger-ink); font-size: 14px; font-weight: 700; }

/* ---------- icons: 1.8 stroke outline set in currentColor; accent stroke in gold */
.ico { width: 24px; height: 24px; flex: none; }
.ico * { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ico .acc { stroke: var(--accent-gold); }
.ico .dot { fill: var(--accent-gold); stroke: none; }

/* ======================================================== HOME (join) */
.home { min-height: 100svh; display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); overflow-x: hidden; }

/* Sada's signature: tally strokes drifting behind the join card. */
.tally-field { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.tally-field svg { position: absolute; inset: -10% -20%; width: 140%; height: 120%; }
.tally-field path { stroke: var(--surface-sand); stroke-width: 2; stroke-linecap: round; fill: none; opacity: 0.45; }
.tally-field .drift { animation: drift 60s ease-in-out infinite alternate; }
.tally-field .drift.slow { animation-duration: 85s; animation-direction: alternate-reverse; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(12%); } }

.home-top {
  display: flex; justify-content: center; padding: 14px 32px;
  background: var(--topbar-glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-card);
}

.join {
  align-self: center; justify-self: center;
  width: min(600px, 100% - 32px); margin: 32px 0;
  padding: clamp(24px, 5vw, 44px) clamp(20px, 5vw, 40px);
  background: var(--surface-card); border: 1px solid var(--border-card); border-radius: var(--radius-lg);
  text-align: center;
}
.join h1 { margin: 0 0 8px; font-size: clamp(28px, 5vw, 40px); line-height: 1.3; font-weight: 900; }
.join p.lead { margin: 0 0 28px; color: var(--text-secondary); font-size: 18px; }

.code-form { display: flex; gap: 10px; align-items: stretch; }
.code-input {
  flex: 1; min-width: 0;
  padding: 12px 24px;
  border: 1.5px solid var(--border-hairline); border-radius: var(--radius-pill);
  background: var(--surface-raised); color: var(--text-ink);
  font-family: var(--font-latin); font-size: clamp(26px, 6vw, 36px); font-weight: 700;
  line-height: 1.2; letter-spacing: 0.1em; text-align: center; direction: ltr;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.code-input:focus { outline: none; border-color: var(--accent-gold); box-shadow: var(--focus-ring); }
/* Browser autofill paints its own (blue) fill; keep the raised surface and ink text. */
.code-input:-webkit-autofill, .field:-webkit-autofill {
  -webkit-text-fill-color: var(--text-ink);
  box-shadow: inset 0 0 0 100px var(--surface-raised);
  caret-color: var(--text-ink);
}
.code-input:-webkit-autofill:focus, .field:-webkit-autofill:focus {
  box-shadow: inset 0 0 0 100px var(--surface-raised), var(--focus-ring);
}
.code-input::placeholder { color: var(--text-faint); opacity: 0.6; }
.code-form .btn { min-width: 120px; padding-inline: 32px; font-size: 17px; }

.home-foot {
  display: grid; justify-items: center; gap: 12px;
  padding: 8px 16px 36px; text-align: center; color: var(--text-secondary); font-size: 15px;
}
.home-foot .host-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; }
.mine { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; margin: 0; padding: 0; list-style: none; font-size: 15px; }

/* ---------- /me: presenter sign-in and deck list */
.code-input.email { font-family: var(--font-arabic); font-size: 18px; font-weight: 700; letter-spacing: 0; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.admin-head h1 { margin: 0; }
.admin .lead bdi { color: var(--text-ink); }
.deck-list { display: grid; gap: 8px; margin: 8px 0 0; padding: 0; list-style: none; text-align: start; }
.deck-list a {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 14px 18px; border-radius: var(--radius-option);
  background: var(--surface-card); border: 1.5px solid var(--border-hairline);
  color: var(--text-ink); text-decoration: none;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.deck-list a:hover, .deck-list a:focus-visible { border-color: var(--accent-gold); background: var(--selected-tint); outline: none; }
.deck-title { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-meta { flex: none; color: var(--text-muted); font-size: 14px; font-weight: 400; }
.deck-meta bdi { direction: ltr; letter-spacing: 0.06em; }
@media (max-width: 520px) {
  .deck-list a { flex-direction: column; align-items: flex-start; gap: 2px; }
  .deck-title { max-width: 100%; }
}

/* ======================================================== EDITOR */
.editor { min-height: 100svh; display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 24px;
  padding: 12px 32px;
  background: var(--topbar-glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-card);
}
.title-input { max-width: 460px; font-size: 18px; font-weight: 700; background: transparent; border-color: transparent; }
.title-input:hover { border-color: var(--border-hairline); }
.topbar .actions { display: flex; align-items: center; gap: 8px; }
.join-hint { margin: 0; color: var(--text-muted); font-size: 14px; font-weight: 700; white-space: nowrap; text-align: center; }
.join-hint b { color: var(--text-ink); letter-spacing: 0.06em; direction: ltr; unicode-bidi: isolate; }
.save-state { color: var(--text-faint); font-size: 13px; min-width: 5em; }

.workspace { display: grid; grid-template-columns: 300px 1fr; min-height: 0; }

.slides-rail {
  padding: 20px 16px; border-inline-end: 1px solid var(--border-card);
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto; max-height: calc(100svh - 69px); position: sticky; top: 69px;
}
.slide-item {
  display: grid; grid-template-columns: 22px 24px 1fr; align-items: center; gap: 10px;
  width: 100%; min-height: 44px; padding: 8px 14px; text-align: start;
  border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--text-body);
  font-size: 15px; cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.slide-item:hover { background: var(--surface-track); color: var(--text-ink); }
.slide-item[aria-current="true"] { background: var(--surface-inverse); color: var(--surface-base); font-weight: 700; }
.slide-item[aria-current="true"] .num { color: var(--surface-base); opacity: 0.7; }
.slide-item .num { font-family: var(--font-latin); color: var(--text-faint); font-size: 13px; text-align: center; }
.slide-item .q { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-add { margin-top: 8px; justify-content: center; border: 1.5px dashed var(--border-control); }

.slide-form { padding: 32px clamp(16px, 4vw, 56px) 80px; max-width: 920px; width: 100%; }
.slide-form h2 { margin: 0 0 8px; font-size: 14px; line-height: 1.4; color: var(--text-muted); font-weight: 700; }
.section { margin-top: 32px; }

.type-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.type-option {
  display: grid; justify-items: center; gap: 6px; padding: 14px 6px;
  border: 1.5px solid var(--border-hairline); border-radius: var(--radius-option);
  background: var(--surface-card); color: var(--text-body); cursor: pointer; font-size: 14px; font-weight: 700;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.type-option:hover { border-color: var(--border-control); color: var(--text-ink); }
.type-option[aria-checked="true"] { background: var(--selected-tint); color: var(--text-ink); border-color: var(--accent-gold); }

.question-input { font-size: clamp(22px, 2.4vw, 28px); font-weight: 700; line-height: 1.4; resize: vertical; min-height: 2.6em; }

.option-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; margin-bottom: 8px; }
.option-row .mark { width: 28px; text-align: center; color: var(--text-faint); font-family: var(--font-latin); font-weight: 700; }
.correct-toggle { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: var(--radius-pill); background: none; cursor: pointer; color: var(--text-faint); transition: background-color 0.15s var(--ease); }
.correct-toggle:hover { background: var(--surface-track); }
.correct-toggle[aria-pressed="true"] { color: var(--success-ink); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.settings-grid label { display: grid; gap: 8px; color: var(--text-body); font-size: 14px; font-weight: 700; }
.check { display: flex !important; align-items: center; gap: 12px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--success); }
.slide-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--divider); }
.danger:hover { color: var(--danger-ink); background: var(--danger-tint); }

/* ======================================================== STAGE (present mode) */
.stage {
  position: fixed; inset: 0; z-index: 20;
  display: grid; grid-template-rows: auto 1fr auto;
  background: var(--surface-base);
  overflow: hidden;
}
.stage[hidden] { display: none; }

.stage-head {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 24px;
  padding: 22px clamp(20px, 4vw, 56px) 0;
}
.stage-join { margin: 0; font-size: clamp(16px, 1.6vw, 22px); color: var(--text-muted); font-weight: 700; }
.stage-join b { color: var(--text-ink); }
.stage-join .code {
  display: inline-block; margin-inline-start: 0.45em; padding: 0.15em 0.7em;
  border-radius: var(--radius-pill); background: var(--surface-inverse); color: var(--surface-base);
  font-size: 1.3em; letter-spacing: 0.08em; direction: ltr; unicode-bidi: isolate; font-weight: 700;
}
.qr { width: 112px; height: 112px; padding: 10px; background: #FFFFFF; border: 1px solid var(--border-card); border-radius: var(--radius-md); }
.qr svg { display: block; width: 100%; height: 100%; }
.qr-fallback { font-size: 11px; color: #121212; word-break: break-all; }

.stage-main { display: grid; grid-template-rows: auto 1fr; gap: clamp(16px, 3vh, 40px); padding: clamp(12px, 3vh, 32px) clamp(20px, 6vw, 96px); min-height: 0; }
.stage-question { margin: 0; font-size: clamp(30px, 4.2vw, 60px); line-height: 1.25; font-weight: 900; max-width: 26ch; }
.stage-results { min-height: 0; overflow: auto; }

.stage-foot {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px clamp(12px, 3vw, 40px) 16px;
  border-top: 1px solid var(--border-card);
}
.stage-foot .count { display: inline-flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 16px; font-weight: 700; }
.stage-foot .count b { font-family: var(--font-latin); color: var(--text-ink); font-size: 24px; }
.stage-foot .controls { display: flex; gap: 4px; justify-content: center; }
.stage-foot .meta { justify-self: end; color: var(--text-faint); font-size: 14px; }

.reaction-layer { position: absolute; inset-inline-end: 3vw; bottom: 80px; width: 120px; height: 60vh; pointer-events: none; }
.reaction-pop { position: absolute; bottom: 0; font-size: 2.4rem; animation: rise 2.6s var(--ease) forwards; }
@keyframes rise {
  0% { transform: translate(0, 0) scale(0.8); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx, 0), -55vh) scale(1.15); opacity: 0; }
}

/* ---------- results: ranked pill bars, chart-1 leads, the correct answer turns green */
.bars { display: grid; gap: clamp(14px, 2.6vh, 24px); align-content: start; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: end; }
.bar-label { font-size: clamp(17px, 1.8vw, 24px); font-weight: 700; color: var(--text-ink); }
.bar-value { font-family: var(--font-latin); font-size: clamp(17px, 1.8vw, 24px); font-weight: 700; color: var(--text-ink); text-align: end; }
.bar-track { grid-column: 1 / -1; height: clamp(14px, 3vh, 28px); background: var(--chart-track); border-radius: var(--radius-pill); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--chart-3); border-radius: var(--radius-pill); transition: width 0.7s var(--ease); }
.bar-row.lead .bar-fill { background: var(--chart-1); }
.bar-row.correct .bar-fill { background: var(--success); }
.bar-row.correct .bar-label::after { content: " ✓"; color: var(--success-ink); }

.ranking { display: grid; gap: 16px; align-content: start; }
.ranking .bar-row { grid-template-columns: 3ch 1fr auto; }
.ranking .rank { grid-row: span 2; align-self: center; font-family: var(--font-latin); font-size: clamp(22px, 2.6vw, 36px); font-weight: 700; color: var(--text-faint); }
.ranking .bar-track { grid-column: 2 / -1; }
.ranking .bar-row:nth-child(1) .bar-fill { background: var(--chart-1); }
.ranking .bar-row:nth-child(2) .bar-fill { background: var(--chart-2); }
.ranking .bar-row:nth-child(3) .bar-fill { background: var(--chart-3); }
.ranking .bar-row:nth-child(n+4) .bar-fill { background: var(--chart-4); }

.cloud {
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center; align-items: baseline;
  gap: 0.15em 0.6em; min-height: 100%; padding: 2vh 0; line-height: 1.2;
}
.cloud span { font-weight: 900; color: var(--text-ink); transition: font-size 0.5s var(--ease); }

.open-list { columns: 3 280px; column-gap: 16px; }
.open-list p {
  break-inside: avoid; margin: 0 0 16px; padding: 18px 22px;
  background: var(--surface-card); border: 1px solid var(--border-card); border-radius: var(--radius-md);
  color: var(--text-ink); font-size: clamp(17px, 1.5vw, 21px);
}

.scales { display: grid; gap: clamp(16px, 3vh, 28px); align-content: start; }
.scale-ends { display: grid; grid-template-columns: 1fr 1fr; color: var(--text-muted); font-size: 14px; font-weight: 700; }
.scale-ends span:last-child { text-align: end; }
.scale-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) 3.5ch; gap: 16px; align-items: center; }
.scale-row .label { font-size: clamp(17px, 1.7vw, 23px); font-weight: 700; color: var(--text-ink); }
.scale-line { position: relative; height: 24px; }
.scale-line::before { content: ""; position: absolute; inset-inline: 0; top: 9px; height: 6px; border-radius: var(--radius-pill); background: var(--chart-track); }
.scale-line i { position: absolute; top: 6px; width: 2px; height: 12px; border-radius: 2px; background: var(--border-control); transform: translateX(50%); }
.scale-mark {
  position: absolute; top: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-gold); border: 3px solid var(--surface-card); transform: translateX(50%);
  transition: inset-inline-start 0.7s var(--ease);
}
.scale-row .avg { font-family: var(--font-latin); font-size: 21px; font-weight: 700; color: var(--text-ink); text-align: end; }

.qna-board { display: grid; gap: 10px; align-content: start; }
.qna-item {
  display: grid; grid-template-columns: 4ch 1fr auto; align-items: center; gap: 16px;
  padding: 14px 20px; background: var(--surface-card); border: 1px solid var(--border-card); border-radius: var(--radius-md);
}
.qna-item .votes { font-family: var(--font-latin); font-size: 24px; font-weight: 700; text-align: center; color: var(--text-ink); }
.qna-item .text { font-size: clamp(17px, 1.6vw, 22px); color: var(--text-ink); }
.qna-item.answered { background: transparent; border-style: dashed; }
.qna-item.answered .text, .qna-item.answered .votes { color: var(--text-faint); }

.leaderboard { display: grid; gap: 10px; max-width: 900px; align-content: start; }
.leader-row {
  display: grid; grid-template-columns: 3ch 1fr auto; gap: 16px; align-items: center;
  padding: 12px 22px; background: var(--surface-card); border: 1px solid var(--border-card); border-radius: var(--radius-pill);
  font-size: clamp(18px, 1.8vw, 24px); color: var(--text-ink);
}
.leader-row:first-child { background: var(--selected-tint); border-color: var(--accent-gold); }
.leader-row .rank { font-family: var(--font-latin); font-weight: 700; color: var(--text-muted); }
.leader-row:first-child .rank { color: var(--text-ink); }
.leader-row .score { font-family: var(--font-latin); font-weight: 700; }

.countdown { font-family: var(--font-latin); font-size: clamp(64px, 14vw, 160px); font-weight: 700; line-height: 1; color: var(--text-ink); text-align: center; }
.stage-note { color: var(--text-secondary); font-size: clamp(18px, 2vw, 26px); text-align: center; margin: 4vh 0 0; }
.quiz-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 3vh; }
.quiz-options div {
  padding: 18px 24px; background: var(--surface-card); border: 1.5px solid var(--border-hairline); border-radius: var(--radius-option);
  font-size: clamp(18px, 2vw, 26px); font-weight: 700; color: var(--text-ink);
}

/* ======================================================== VOTE (audience) */
.vote { min-height: 100svh; display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); }
.vote-head {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  background: var(--topbar-glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-card);
}
.vote-head .title { color: var(--text-muted); font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vote-body { width: min(560px, 100%); margin: 0 auto; padding: 28px 20px 40px; }
.vote-body h1 { margin: 0 0 24px; font-size: clamp(24px, 6vw, 32px); line-height: 1.35; font-weight: 900; }
.vote-step { color: var(--text-muted); font-size: 14px; font-weight: 700; margin-bottom: 8px; }

/* Options follow the RadioCard: ring, label, gold border when selected. */
.choice-list { display: grid; gap: 10px; margin-bottom: 20px; }
.choice {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 56px; padding: 14px 16px; text-align: start;
  border: 1.5px solid var(--border-hairline); border-radius: var(--radius-option);
  background: var(--surface-card); color: var(--text-ink); cursor: pointer; font-size: 16px; font-weight: 700;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.choice:hover { border-color: var(--border-control); }
.choice[aria-checked="true"], .choice[aria-pressed="true"] { background: var(--selected-tint); border-color: var(--accent-gold); }
.choice .box {
  width: 20px; height: 20px; flex: none; border: 2px solid var(--border-control); border-radius: 50%;
  background: var(--surface-card); transition: border 0.15s var(--ease);
}
.choice.multi .box { border-radius: var(--radius-check); width: 22px; height: 22px; }
.choice[aria-checked="true"] .box { border: 6px solid var(--accent-gold); }
.choice.multi[aria-checked="true"] .box { border: 0; background: var(--success); }
.choice.correct { border-color: var(--success); background: var(--success-tint); }
.choice.wrong { opacity: 0.55; }

.stack { display: grid; gap: 12px; margin-bottom: 20px; }
.counter { font-family: var(--font-latin); color: var(--text-faint); font-size: 13px; text-align: end; }
.submit { width: 100%; min-height: 52px; font-size: 17px; }

.scale-q { padding: 16px 0; border-bottom: 1px solid var(--divider); }
.scale-q .label { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; color: var(--text-ink); margin-bottom: 6px; }
.scale-q .label output { font-family: var(--font-latin); color: var(--text-ink); font-weight: 700; }
.scale-q input[type="range"] { width: 100%; accent-color: var(--accent-gold); }
.scale-q .ends { display: flex; justify-content: space-between; color: var(--text-muted); font-size: 13px; }

.rank-item, .point-item {
  display: grid; grid-template-columns: 2ch 1fr auto; align-items: center; gap: 10px;
  padding: 8px 8px 8px 8px; padding-inline-start: 16px;
  background: var(--surface-card); border: 1.5px solid var(--border-hairline); border-radius: var(--radius-pill);
  color: var(--text-ink); font-weight: 700;
}
.rank-item .pos { font-family: var(--font-latin); color: var(--text-muted); font-weight: 700; }
.rank-item .moves, .point-item .moves { display: flex; align-items: center; gap: 4px; }
.rank-item button, .point-item button {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: var(--radius-pill); background: var(--surface-track); color: var(--text-ink);
  cursor: pointer; font-size: 18px; font-weight: 700; transition: background-color 0.15s var(--ease);
}
.rank-item button:hover, .point-item button:hover { background: var(--surface-sand); }
.rank-item button:disabled, .point-item button:disabled { opacity: 0.35; cursor: default; }
.point-item { grid-template-columns: 1fr auto; }
.point-item .val { font-family: var(--font-latin); min-width: 3ch; text-align: center; font-weight: 700; font-size: 17px; }
.budget { display: flex; justify-content: space-between; color: var(--text-muted); font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.budget b { font-family: var(--font-latin); color: var(--text-ink); }

.done {
  padding: 28px 24px; text-align: center;
  background: var(--surface-card); border: 1px solid var(--border-card); border-radius: var(--radius-lg); color: var(--text-secondary);
}
.done .big { font-size: 24px; font-weight: 900; margin: 8px 0; color: var(--text-ink); }
.done svg.tally { width: 56px; height: 56px; }
.wait { text-align: center; color: var(--text-secondary); padding: 40px 0; }
.wait .countdown { font-size: 80px; }

.qna-ask { display: grid; gap: 10px; margin-bottom: 24px; }
.qna-list { display: grid; gap: 8px; }
.qna-row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 12px 16px; background: var(--surface-card); border: 1px solid var(--border-card); border-radius: var(--radius-md);
  color: var(--text-ink);
}
.qna-row.answered { opacity: 0.6; }
.upvote {
  display: inline-flex; align-items: center; gap: 6px; min-width: 64px; min-height: 40px; justify-content: center;
  border: 1.5px solid var(--border-hairline); border-radius: var(--radius-pill); background: var(--surface-card);
  font-family: var(--font-latin); font-weight: 700; color: var(--text-body); cursor: pointer;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.upvote:hover { border-color: var(--border-control); }
.upvote[aria-pressed="true"] { border-color: var(--accent-gold); background: var(--selected-tint); color: var(--text-ink); }

.reactions {
  position: sticky; bottom: 0; display: flex; justify-content: center; gap: 4px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--topbar-glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-card);
}
.reactions button { width: 52px; height: 48px; border: 0; border-radius: var(--radius-pill); background: transparent; font-size: 1.6rem; cursor: pointer; transition: background-color 0.15s var(--ease); }
.reactions button:hover { background: var(--surface-track); }
.reactions button:active { background: var(--surface-sand); }

.name-gate { display: grid; gap: 12px; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .slides-rail { position: static; max-height: none; flex-direction: row; overflow-x: auto; border-inline-end: 0; border-bottom: 1px solid var(--border-card); padding: 12px 16px; }
  .slide-item { min-width: 200px; }
  .rail-add { min-width: 140px; margin-top: 0; }
  .type-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { grid-template-columns: 1fr; gap: 8px; padding: 12px 16px; }
  .join-hint { white-space: normal; text-align: start; }
  .topbar .actions { flex-wrap: wrap; }
  .stage-head { grid-template-columns: 1fr; }
  .qr { display: none; }
  .quiz-options { grid-template-columns: 1fr; }
  .scale-row { grid-template-columns: 1fr 3.5ch; }
  .scale-row .scale-line { grid-column: 1 / -1; grid-row: 2; }
  .stage-foot { grid-template-columns: 1fr auto; }
  .stage-foot .meta { display: none; }
}

@media (max-width: 520px) {
  .code-form { flex-direction: column; }
  .home-top { padding: 12px 16px; }
}

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

.topbar-start { display: flex; align-items: center; gap: 16px; min-width: 0; }

/* Icon wrappers: flex so glyphs centre on the text's middle, not its baseline. */
.btn > span, .quiet > span, .upvote > span, .type-option > span, .slide-item > span:nth-child(2), .count > span { display: inline-flex; align-items: center; justify-content: center; }
.upvote svg { width: 18px; height: 18px; }
.vote-body .done { margin-bottom: 16px; }
ol.stack { list-style: none; padding: 0; margin: 0 0 20px; }
