/* ============================================================================
   The AI Sprint - base layer
   Reset, accessibility primitives and the small set of primitives every screen
   shares. Anything specific to one surface belongs in arena.css or console.css.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--surface-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Booth and question text is authored by admins; a long unbroken token would
     otherwise force the whole page to scroll sideways on a small phone. */
  overflow-wrap: break-word;
}

h1, h2, h3, h4 { margin: 0; line-height: var(--leading-tight); letter-spacing: var(--tracking-tight); font-weight: var(--weight-bold); }
p { margin: 0; }
img, svg { display: block; max-width: 100%; }

/* Never below 16px on a control: iOS zooms the viewport on focus otherwise. */
input, select, textarea, button {
  font: inherit;
  font-size: max(var(--text-md), 16px);
  color: inherit;
}

/* --- focus -----------------------------------------------------------------
   The previous build had no focus styling at all, which made every screen
   unusable by keyboard. Visible for keyboard users, quiet for pointer users. */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-control);
}

/* --- screen reader --------------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: 100;
  padding: var(--space-3) var(--space-4);
  background: var(--brand-solid);
  color: var(--text-on-brand);
  border-radius: var(--radius-control);
  font-weight: var(--weight-semibold);
  transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus-visible { top: var(--space-4); }

/* --- numerals --------------------------------------------------------------
   Scores, ranks and countdowns update in place; proportional figures make them
   jitter as the digits change. */
.tabular {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: var(--tracking-tight);
}

/* --- safe areas ------------------------------------------------------------
   Phones with a notch or home indicator clip fixed content without these. */
.safe-x { padding-left: max(var(--space-4), env(safe-area-inset-left)); padding-right: max(var(--space-4), env(safe-area-inset-right)); }
.safe-top { padding-top: max(var(--space-4), env(safe-area-inset-top)); }
.safe-bottom { padding-bottom: max(var(--space-4), env(safe-area-inset-bottom)); }

/* --- buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: var(--brand-solid);
  color: var(--text-on-brand);
  font-weight: var(--weight-semibold);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
.btn:hover:not(:disabled) { background: var(--brand-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--secondary { background: transparent; border-color: var(--border-strong); color: var(--text-primary); }
.btn--secondary:hover:not(:disabled) { background: var(--surface-sunken); }
.btn--danger { background: var(--danger-500); }
.btn--danger:hover:not(:disabled) { background: var(--danger-600); }
.btn--block { width: 100%; }

/* --- fields ---------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field__label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-secondary); }
.field__hint { font-size: var(--text-sm); color: var(--text-muted); }
.field__error { font-size: var(--text-sm); color: var(--danger-text); }

.input {
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  transition: border-color var(--dur-fast) var(--ease-out);
}
.input:hover { border-color: var(--text-muted); }
.input[aria-invalid="true"] { border-color: var(--danger-500); }

/* --- badges ---------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  background: var(--surface-sunken);
  color: var(--text-secondary);
}
.badge--success { background: var(--success-bg); color: var(--success-text); }
.badge--danger { background: var(--danger-bg); color: var(--danger-text); }

/* --- toast + live region ---------------------------------------------------
   Single shared element. Announced to assistive tech, which the old toast was
   not - it was a bare div appended to the body. */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(var(--space-6), env(safe-area-inset-bottom));
  transform: translate(-50%, var(--space-4));
  z-index: 90;
  max-width: min(92vw, 30rem);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-control);
  background: var(--success-500);
  color: #fff;
  font-weight: var(--weight-semibold);
  text-align: center;
  box-shadow: var(--shadow-lift);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-mid) var(--ease-out), transform var(--dur-mid) var(--ease-out);
}
.toast[data-visible="true"] { opacity: 1; transform: translate(-50%, 0); }
.toast[data-tone="error"] { background: var(--danger-500); }

/* --- skeleton -------------------------------------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--surface-overlay) 37%, var(--surface-sunken) 63%);
  background-size: 400% 100%;
  animation: skeleton-shift 1.4s ease-in-out infinite;
  border-radius: var(--radius-control);
}
@keyframes skeleton-shift { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

/* --- reduced motion --------------------------------------------------------
   Confetti and the countdown pulse are vestibular triggers; honour the setting. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  :root { --border-subtle: var(--border-strong); }
}
