/* =====================================================================
   SurveyAll — foundation.
   Every colour and face comes from a theme token (see app/themes.js).
   The values here are the fallbacks used before JS applies a theme, so
   nothing ever flashes unstyled.
   ===================================================================== */

/* ---------------------------------------------------------------------
   The `hidden` attribute must actually hide.

   Every page here switches views by toggling `el.hidden` (the lobby vs a
   live question, sign-in vs setup, the phone's waiting state). That
   relies on the browser's `[hidden] { display: none }` rule, which lives
   in the UA stylesheet, and ANY author rule that sets `display` on the
   same element beats it, regardless of specificity. Several do:
   `.lobby`, `.stage-head`, `.join-corner`, `.join-state`, `.pulse-wait`
   and `.bg-controls` are all `display: flex`.

   Without this rule those elements stay visible, so the projector drew
   the lobby QR, the live question, the corner QR and the Q&A drawer all
   at once, stacked, pushing the question off the bottom of the screen.
   `!important` is deliberate: `hidden` is a statement of fact about the
   document, and no layout rule should be able to argue with it.
   --------------------------------------------------------------------- */
[hidden] { display: none !important; }

:root {
  --ink: #1c2434;
  --ink-soft: #4a5568;
  --ground: #f7f4ee;
  --surface: #fffdf8;
  --edge: #e2dbcd;
  --accent: #1d4ed8;
  --accent-soft: #dbe4fb;
  --accent-2: #b45309;
  --good: #15803d;
  --bad: #b91c1c;
  --display: 'Fraunces', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --body: 'Inter', 'Inter var', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --bar-radius: 6px;

  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 8px 24px rgba(0, 0, 0, .07);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);

  /* Motion scale.
     Durations and curves follow the same values the incumbent tools and
     the major design systems converged on — `--ease-snap` is Material 3's
     "emphasized" curve, `--ease-in-out` its legacy standard. Entrances
     decelerate, exits accelerate, and anything above ~400ms starts to
     feel like waiting rather than moving.
     Most result animation is NOT here: bars, positions and counters are
     spring-driven in app/motion.js, because a fixed duration makes a bar
     travelling 2% take as long as one travelling 60%. */
  --duration-instant: .1s;
  --duration-fast: .15s;
  --duration-moderate: .25s;
  --duration-slow: .4s;
  --ease-in-out: cubic-bezier(.4, 0, .2, 1);
  --ease-in: cubic-bezier(.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, .2, 1);
  --ease-snap: cubic-bezier(.2, 0, 0, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 {
  font-family: var(--display);
  line-height: 1.15;
  text-wrap: balance;
  margin: 0;
  font-weight: 600;
}

p { margin: 0; }

a { color: var(--accent); }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: 6px;
}

.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;
}

/* ---------------------------------------------------------------- type */

.eyebrow {
  font-family: var(--body);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.muted { color: var(--ink-soft); }
.tabular { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: .6rem 1rem;
  border: 1px solid var(--edge);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: .92rem;
  font-weight: 550;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .08s ease;
}

.btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 45%, var(--edge)); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--edge)); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.btn-sm { padding: .35rem .6rem; font-size: .82rem; }
.btn-lg { padding: .85rem 1.4rem; font-size: 1.05rem; }

/* -------------------------------------------------------------- footer */

.page-foot {
  padding: var(--sp-4) var(--sp-3) calc(var(--sp-4) + env(safe-area-inset-bottom));
  text-align: center;
  font-size: .78rem;
}

.page-foot a { color: var(--ink-soft); text-decoration: none; }
.page-foot a:hover { color: var(--ink); text-decoration: underline; }

/* -------------------------------------------------------------- fields */

.field { display: flex; flex-direction: column; gap: var(--sp-2); }

.field > label, .label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

/* Guidance under an input — what a valid value looks like, or a
   consequence worth knowing before submitting (the sign-up form uses it
   to say that a forgotten password cannot be self-reset). */
.field-hint {
  margin: 0;
  font-size: .74rem;
  line-height: 1.45;
  color: var(--ink-soft);
  opacity: .85;
  text-align: left;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], select, textarea {
  width: 100%;
  padding: .58rem .7rem;
  border: 1px solid var(--edge);
  border-radius: 9px;
  background: var(--surface);
  transition: border-color .15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 5rem; }

.checkline {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: .9rem;
}
.checkline input { width: auto; }

/* --------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: var(--sp-5);
}

.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* --------------------------------------------------------------- chips */

.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .18rem .55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: color-mix(in srgb, var(--accent) 80%, var(--ink));
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.chip-live { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.chip-ended { background: color-mix(in srgb, var(--ink) 10%, transparent); color: var(--ink-soft); }

.dot-live {
  width: .5rem; height: .5rem; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  70% { box-shadow: 0 0 0 .5rem transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* -------------------------------------------------------------- alerts */

.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: 10px;
  border: 1px solid;
  font-size: .9rem;
}
.alert-error {
  border-color: color-mix(in srgb, var(--bad) 40%, transparent);
  background: color-mix(in srgb, var(--bad) 8%, transparent);
  color: var(--bad);
}
.alert-info {
  border-color: var(--edge);
  background: var(--accent-soft);
  color: color-mix(in srgb, var(--accent) 75%, var(--ink));
}
.alert-warn {
  border-color: color-mix(in srgb, var(--accent-2) 40%, transparent);
  background: color-mix(in srgb, var(--accent-2) 10%, transparent);
  color: color-mix(in srgb, var(--accent-2) 80%, var(--ink));
}

/* ------------------------------------------------------- privacy badge */

/* The padlock hangs in the margin rather than being a flex sibling.
   Flex here would make every inline child its own column — a link inside
   the note gets torn onto its own narrow line and trailing punctuation
   becomes a third column. Text must flow normally in this one. */
.privacy-note {
  position: relative;
  padding-left: 1.6rem;
  font-size: .8rem;
  color: var(--ink-soft);
  line-height: 1.45;
}
.privacy-note::before {
  content: '🔒';
  position: absolute;
  left: 0;
  top: 0;
  font-size: .9rem;
  line-height: 1.45;
}

/* --------------------------------------------------------------- shell */

.appbar {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--edge);
  background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}

.appbar .brand {
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.01em;
  text-decoration: none;
  color: var(--ink);
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-7);
  display: flex; flex-direction: column; gap: var(--sp-5);
}
.page-narrow { max-width: 620px; }

.toast {
  position: fixed;
  bottom: var(--sp-5); left: 50%;
  transform: translateX(-50%) translateY(1rem);
  padding: .6rem 1rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--ground);
  font-size: .88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 100;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

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