/* Saliedēsimies design system. System fonts only. Themes: default "app" (light/dark by OS) and body.theme-stage (always dark).
   Organisation branding: set --brand-primary / --brand-accent (and their -text partners) on <html>
   (document.documentElement.style.setProperty). Every derived colour (links, tints, focus rings, button
   edges, field focus) is computed from them there or below. Set on <body> or a wrapper they would miss
   the tokens derived on :root (--link, --tint), so only part of the page would change colour. */
:root {
  --brand-primary: #6d4aff;
  --brand-accent: #ffc53d;
  --brand-primary-text: #fff;
  --brand-accent-text: #231a00;

  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-2: #efedf8;
  --text: #1a1630;
  --text-muted: #5f5a7a;
  --border: #e4e1f0;
  --danger: #e5484d;
  --success: #30a46c;
  --warning: #f5a524;
  /* The semantic hues as small text on a surface (4.5:1 or better); the plain ones are for fills and borders. */
  --danger-text: color-mix(in srgb, var(--danger) 75%, #000);
  --success-text: color-mix(in srgb, var(--success) 62%, #000);
  --warning-text: color-mix(in srgb, var(--warning) 50%, #000);
  --link: color-mix(in srgb, var(--brand-primary) 85%, #000);
  --tint: color-mix(in srgb, var(--brand-primary) 10%, var(--surface));

  --r-sm: 8px; --r-md: 14px; --r-lg: 22px; --r-pill: 999px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;

  --shadow-sm: 0 1px 2px rgba(26, 22, 48, .08), 0 1px 1px rgba(26, 22, 48, .04);
  --shadow-md: 0 6px 18px rgba(26, 22, 48, .10), 0 2px 4px rgba(26, 22, 48, .06);
  --shadow-lg: 0 24px 60px rgba(26, 22, 48, .28);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14121f; --surface: #1e1b2e; --surface-2: #2a2640; --text: #f2f0fa; --text-muted: #a9a4c4; --border: #332f4d;
    --danger-text: color-mix(in srgb, var(--danger) 70%, #fff); --success-text: color-mix(in srgb, var(--success) 75%, #fff); --warning-text: color-mix(in srgb, var(--warning) 60%, #fff);
    --link: color-mix(in srgb, var(--brand-primary) 55%, #fff);
    --tint: color-mix(in srgb, var(--brand-primary) 22%, var(--surface));
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14121f; --surface: #1e1b2e; --surface-2: #2a2640; --text: #f2f0fa; --text-muted: #a9a4c4; --border: #332f4d;
  --danger-text: color-mix(in srgb, var(--danger) 70%, #fff); --success-text: color-mix(in srgb, var(--success) 75%, #fff); --warning-text: color-mix(in srgb, var(--warning) 60%, #fff);
  --link: color-mix(in srgb, var(--brand-primary) 55%, #fff);
  --tint: color-mix(in srgb, var(--brand-primary) 22%, var(--surface));
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

/* Stage theme: big screen and phones. Always dark, translucent surfaces. */
body.theme-stage {
  --bg: #0d0a24; --surface: rgba(255, 255, 255, .08); --surface-2: rgba(255, 255, 255, .14);
  --text: #ffffff; --text-muted: rgba(255, 255, 255, .72); --border: rgba(255, 255, 255, .18);
  --danger-text: color-mix(in srgb, var(--danger) 55%, #fff); --success-text: color-mix(in srgb, var(--success) 60%, #fff); --warning-text: color-mix(in srgb, var(--warning) 60%, #fff);
  --link: color-mix(in srgb, var(--brand-accent) 90%, #fff);
  --tint: rgba(255, 255, 255, .12);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, .35);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, .4);
  --focus-color: var(--brand-accent);
  color-scheme: dark;
  background: radial-gradient(120% 80% at 50% -10%, #2b1a6e 0%, #1d1147 38%, #0d0a24 100%) fixed;
  background-color: #0d0a24;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* dom.js: the page behind an open dialog does not scroll; the padding stands in for its scrollbar. */
html.modal-open { overflow: hidden; padding-right: var(--scrollbar-gap, 0px); }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
img, svg, video, canvas { max-width: 100%; }
a { color: var(--link); text-underline-offset: 3px; }
[hidden] { display: none !important; }

h1, h2, h3, h4 { font-weight: 800; letter-spacing: -0.02em; line-height: 1.12; margin: 0 0 var(--s-3); }
h1 { font-size: clamp(2rem, 5vw, 3.25rem); letter-spacing: -0.035em; }
h2 { font-size: clamp(1.5rem, 3.4vw, 2.1rem); }
h3 { font-size: 1.25rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 var(--s-3); }
.muted { color: var(--text-muted); }
.small { font-size: .875rem; }
.num, .score, .timer { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--link); }
code, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }

/* Focus ring: an outline, so component shadows cannot hide it and forced-colours mode keeps it. */
:focus-visible { outline: 3px solid var(--focus-color, var(--brand-primary)); outline-offset: 3px; }

/* Layout */
.container { width: 100%; max-width: 1120px; margin-inline: auto; padding-inline: var(--s-4); }
.container-narrow { max-width: 560px; }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack-sm { gap: var(--s-2); }
.stack-lg { gap: var(--s-6); }
.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.grow { flex: 1 1 0; min-width: 0; }
.grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons */
.btn {
  --btn-bg: var(--surface-2); --btn-fg: var(--text); --btn-bd: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: 0 var(--s-5); border-radius: var(--r-md);
  border: 2px solid var(--btn-bd); background: var(--btn-bg); color: var(--btn-fg);
  font: inherit; font-weight: 700; letter-spacing: -0.005em; line-height: 1.1; text-decoration: none;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease, background-color .12s ease;
}
.btn:hover { filter: brightness(1.06); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(.985); box-shadow: none; filter: brightness(.96); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; filter: none; }
.btn-primary { --btn-bg: var(--brand-primary); --btn-fg: var(--brand-primary-text); box-shadow: 0 4px 0 color-mix(in srgb, var(--brand-primary) 60%, #000); }
.btn-primary:hover { box-shadow: 0 5px 0 color-mix(in srgb, var(--brand-primary) 60%, #000), var(--shadow-md); }
.btn-primary:active { box-shadow: 0 1px 0 color-mix(in srgb, var(--brand-primary) 60%, #000); transform: translateY(3px); }
.btn-primary[disabled], .btn-primary[aria-disabled="true"] { box-shadow: none; }
.btn-secondary { --btn-bg: transparent; --btn-fg: var(--text); --btn-bd: var(--border); }
.btn-secondary:hover { --btn-bg: var(--surface-2); }
.btn-danger { --btn-bg: color-mix(in srgb, var(--danger) 88%, #000); --btn-fg: #fff; } /* white label at 4.5:1 or better */
.btn-ghost { --btn-bg: transparent; --btn-fg: var(--link); padding-inline: var(--s-3); }
.btn-ghost:hover { --btn-bg: var(--tint); box-shadow: none; }
.btn-accent { --btn-bg: var(--brand-accent); --btn-fg: var(--brand-accent-text); }
.btn-lg { min-height: 56px; padding: 0 var(--s-6); font-size: 1.125rem; border-radius: var(--r-lg); }
.btn-sm { min-height: 34px; padding: 0 var(--s-3); font-size: .875rem; border-radius: var(--r-sm); }
.btn-block { display: flex; width: 100%; }
body.theme-stage .btn { min-height: 56px; font-size: 1.0625rem; }
body.theme-stage .btn-sm { min-height: 56px; }
body.theme-stage .btn-secondary { --btn-bg: var(--surface); --btn-bd: var(--border); }
body.theme-stage .btn-ghost { --btn-fg: #fff; }
body.theme-stage .btn-primary { --btn-bg: var(--brand-accent); --btn-fg: var(--brand-accent-text); box-shadow: 0 4px 0 color-mix(in srgb, var(--brand-accent) 55%, #000); }
body.theme-stage .btn-primary:hover { box-shadow: 0 5px 0 color-mix(in srgb, var(--brand-accent) 55%, #000), var(--shadow-md); }
body.theme-stage .btn-primary:active { box-shadow: 0 1px 0 color-mix(in srgb, var(--brand-accent) 55%, #000); }
body.theme-stage .btn-primary[disabled], body.theme-stage .btn-primary[aria-disabled="true"] { box-shadow: none; }

/* Forms */
.field { display: flex; flex-direction: column; gap: var(--s-1); }
.field > label, .label { font-size: .875rem; font-weight: 700; color: var(--text); }
.field-hint { font-size: .8125rem; color: var(--text-muted); }
.field-error { font-size: .8125rem; font-weight: 600; color: var(--danger-text); min-height: 0; }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 10px var(--s-3); font: inherit; color: var(--text);
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--r-md);
  transition: border-color .12s ease, box-shadow .12s ease;
}
body.theme-stage .input, body.theme-stage .select, body.theme-stage .textarea { min-height: 56px; font-size: 1.125rem; background-color: rgba(255, 255, 255, .1); }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: color-mix(in srgb, var(--brand-primary) 40%, var(--border)); }
/* Fields show focus with border + glow; the transparent outline only becomes visible in forced-colours mode. */
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline-color: transparent; border-color: var(--brand-primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-primary) 28%, transparent); border-radius: var(--r-md); }
body.theme-stage .input:focus-visible, body.theme-stage .select:focus-visible, body.theme-stage .textarea:focus-visible { border-color: var(--brand-accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-accent) 30%, transparent); }
.field.has-error .input, .input[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 96px; resize: vertical; }
.select { appearance: none; padding-right: 40px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
.select option { color: #1a1630; background: #fff; }
.check { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; font-weight: 600; min-height: 32px; }
.check input { width: 22px; height: 22px; accent-color: var(--brand-primary); margin: 0; flex: none; }
body.theme-stage .check { min-width: 56px; min-height: 56px; }
body.theme-stage .check input { width: 28px; height: 28px; accent-color: var(--brand-accent); }

/* Cards, badges */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-sm); }
.card-hover { transition: transform .15s ease, box-shadow .15s ease; }
.card-hover:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
body.theme-stage .card { backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.card > :last-child { margin-bottom: 0; }
.badge { display: inline-flex; align-items: center; gap: var(--s-1); padding: 3px 10px; border-radius: var(--r-pill); font-size: .75rem; font-weight: 800; letter-spacing: .02em; background: var(--tint); color: var(--link); }
.badge-success { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success-text); }
.badge-warning { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--warning-text); }
.badge-danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger-text); }
.badge-solid { background: var(--brand-primary); color: var(--brand-primary-text); }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--s-5) 0; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: var(--s-4); background: rgba(13, 10, 36, .6); backdrop-filter: blur(4px); animation: sv-fade .15s ease; }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--shadow-lg); animation: sv-pop .2s cubic-bezier(.2, 1.2, .4, 1); }
body.theme-stage .modal { background: #231b52; }
.modal-title { font-size: 1.375rem; }
.modal-body { margin-bottom: var(--s-5); }
.modal-actions { display: flex; gap: var(--s-3); justify-content: flex-end; flex-wrap: wrap; }
.modal:focus-visible { outline: none; }

/* Toast */
.toast-host { position: fixed; z-index: 1100; left: var(--s-4); right: var(--s-4); bottom: var(--s-4); display: flex; flex-direction: column; align-items: center; gap: var(--s-2); pointer-events: none; }
.toast { pointer-events: auto; max-width: 480px; padding: var(--s-3) var(--s-5); border-radius: var(--r-pill); background: #1a1630; color: #fff; font-weight: 700; box-shadow: var(--shadow-md); border-left: 6px solid var(--brand-accent); animation: sv-rise .25s ease; }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-out { opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }

/* Connection banner (rt.js): a strip along the bottom edge of the window, laid over the page; no room is made
   for it. Answers are accepted again in the moment it goes, so a tap aimed while it was shown must land on the
   same control afterwards: no control may move when it comes or goes (never offset one by --conn-banner-h),
   and what lies under it cannot send while the link is down anyway. It covers no page header. Dialogs and
   toasts lie above it; only the toasts step aside, by its height (--conn-banner-h on <html>, set together
   with the class conn-offline). */
.conn-banner { position: fixed; z-index: 900; left: 0; right: 0; bottom: 0; padding: var(--s-2) var(--s-4); padding-bottom: max(var(--s-2), env(safe-area-inset-bottom)); text-align: center; font-weight: 700; background: var(--warning); color: #2b1d00; box-shadow: var(--shadow-md); }
html.conn-offline .toast-host { bottom: calc(var(--s-4) + var(--conn-banner-h, 0px)); }

/* Language switcher */
.lang-switcher .select { min-height: 38px; width: auto; padding-block: 6px; font-weight: 700; }

/* Answer buttons (colour + shape always match). The label is WCAG large text (19 px bold): white reaches 3:1 on all six colours. */
.ans-0 { --ans: #e5484d; } .ans-1 { --ans: #3e82f7; } .ans-2 { --ans: #f5b700; }
.ans-3 { --ans: #30a46c; } .ans-4 { --ans: #8e4ec6; } .ans-5 { --ans: #f76808; }
/* A question has at most six options; a game may have eight teams, and the seventh and eighth take these (the wheel's colours 7 and 8). */
.ans-6 { --ans: #12a594; } .ans-7 { --ans: #d6409f; }
.ans-0, .ans-1, .ans-2, .ans-3, .ans-4, .ans-5, .ans-6, .ans-7 { background: var(--ans); color: #fff; }
.ans-2 { color: #2a2000; }
.ans-btn { display: flex; align-items: center; gap: var(--s-3); min-height: 72px; padding: var(--s-3) var(--s-4); border: 0; border-radius: var(--r-lg); font: inherit; font-size: 1.1875rem; font-weight: 800; text-align: left; cursor: pointer; box-shadow: 0 5px 0 color-mix(in srgb, var(--ans) 55%, #000); transition: transform .1s ease, box-shadow .1s ease, opacity .2s; }
.ans-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 color-mix(in srgb, var(--ans) 55%, #000); }
.ans-btn[disabled] { opacity: .4; cursor: not-allowed; }
.ans-btn .ans-shape { flex: none; width: 32px; height: 32px; }
.ans-btn .ans-label { min-width: 0; overflow-wrap: anywhere; }

/* Animations */
@keyframes sv-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sv-pop { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes sv-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes sv-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.pulse { animation: sv-pulse 1.2s ease-in-out infinite; }

@media (max-width: 480px) {
  .card { padding: var(--s-4); }
  .modal { padding: var(--s-4); }
  .btn-lg { padding: 0 var(--s-5); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
.stack > .badge { align-self: flex-start; }
