/* =========================================================================
   base.css — reset + layout + komponendid. Kasutab AINULT tokens.css muutujaid.
   Mobile-first. Suured puutenupud.
   ========================================================================= */

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

html, body { margin: 0; padding: 0; }

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  font-size: 17px;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  color: var(--ink);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin: 0 0 0.4em;
}
h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); }
h2 { font-size: clamp(1.35rem, 4.5vw, 1.8rem); }
h3 { font-size: 1.15rem; }

p { margin: 0 0 1rem; }
a { color: var(--accent-strong); }

.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---- Layout ------------------------------------------------------------- */

.wrap {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}
.wrap-narrow { max-width: 460px; }

.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.grow { flex: 1 1 auto; }
.wrap-flex { flex-wrap: wrap; }

/* ---- Topbar ------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--page);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.brand small {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.55em;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-left: 6px;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ---- Cards -------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 14px; }
.card-flush { padding: 0; overflow: hidden; }

/* Aura-hero (Hearthi allkiri-gradient) */
.hero {
  border-radius: var(--radius);
  background: var(--aura);
  color: #fff;
  padding: 26px 22px;
  box-shadow: var(--shadow-2);
}
.hero h1, .hero h2 { color: #fff; }
.hero .muted { color: rgba(255,255,255,0.85); }
.hero-soft { background: var(--aura-soft); color: var(--ink); box-shadow: var(--shadow-1); }
.hero-soft h1, .hero-soft h2 { color: var(--ink); }

/* ---- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  padding: 14px 20px;
  min-height: 52px;
  border-radius: var(--radius-pill);
  border: 1.5px solid transparent;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.05s ease, box-shadow 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); }
.btn-ink { background: var(--ink); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-bad { background: var(--bad); color: #fff; }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 60px; font-size: 1.1rem; padding: 16px 24px; }
.btn-sm { min-height: 40px; font-size: 0.9rem; padding: 8px 14px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.85rem;
  color: var(--ink);
  text-decoration: none;
}

/* ---- Forms -------------------------------------------------------------- */

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; color: var(--ink-soft); }

input[type="text"], input[type="password"], input[type="number"],
textarea, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  min-height: 50px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field + .field { margin-top: 14px; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.check label { margin: 0; font-weight: 500; color: var(--ink); }

.segmented { display: inline-flex; border: 1.5px solid var(--border); border-radius: var(--radius-pill); overflow: hidden; background: var(--surface); }
.segmented button {
  border: 0; background: transparent; font: inherit; font-weight: 600;
  padding: 10px 18px; cursor: pointer; color: var(--ink-soft); min-height: 44px;
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* ---- Badges / status ---------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--ink-soft);
}
.badge-draft { background: var(--surface-2); color: var(--ink-soft); }
.badge-running { background: var(--ok-bg); color: var(--ok); }
.badge-finished { background: var(--border); color: var(--muted); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }

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

.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.list-item:last-child { border-bottom: 0; }
.list-item .title { font-weight: 600; }

/* ---- Choice buttons (osaleja / run) ------------------------------------ */

.choices { display: grid; gap: 12px; }
.choice {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 18px 18px; min-height: 66px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  color: #fff; font-size: 1.05rem; font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: transform 0.05s ease, filter 0.15s ease, outline 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}
.choice:active { transform: translateY(1px); }
.choice[data-c="0"] { background: var(--choice-1); }
.choice[data-c="1"] { background: var(--choice-2); }
.choice[data-c="2"] { background: var(--choice-3); }
.choice[data-c="3"] { background: var(--choice-4); }
.choice[data-c="4"] { background: var(--choice-5); }
.choice[data-c="5"] { background: var(--choice-6); }
.choice[aria-pressed="true"] { outline: 4px solid var(--ink); outline-offset: 2px; filter: saturate(1.1); }
.choice.dim { opacity: 0.45; }
.choice .glyph {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px;
  background: rgba(255,255,255,0.25); display: grid; place-items: center; font-weight: 800;
}
.choice.correct { box-shadow: 0 0 0 3px var(--ok), var(--shadow-1); }
.choice.wrong { box-shadow: 0 0 0 3px var(--bad), var(--shadow-1); }

/* Jaotus-riba (run) */
.dist-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.dist-bar-track { flex: 1 1 auto; height: 14px; background: var(--surface-2); border-radius: var(--radius-pill); overflow: hidden; }
.dist-bar { height: 100%; background: var(--accent); border-radius: var(--radius-pill); }

/* ---- Leaderboard -------------------------------------------------------- */

.lb { list-style: none; margin: 0; padding: 0; }
.lb-row {
  display: grid; grid-template-columns: 44px 1fr auto auto; gap: 12px; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.lb-row:last-child { border-bottom: 0; }
.lb-rank { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; color: var(--muted); text-align: center; }
.lb-row.me { background: var(--surface-2); }
.lb-row.top .lb-rank { color: var(--accent); }
.lb-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-points { font-variant-numeric: tabular-nums; font-weight: 700; }
.lb-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; }

/* ---- QR / join ---------------------------------------------------------- */

.qr-box { background: #fff; padding: 16px; border-radius: var(--radius); display: inline-block; box-shadow: var(--shadow-1); }
.qr-box svg, .qr-box img { display: block; width: 240px; height: 240px; max-width: 60vw; max-height: 60vw; }
.joincode {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2.2rem, 12vw, 4rem); letter-spacing: 0.12em;
  color: var(--ink);
}

/* ---- Countdown ---------------------------------------------------------- */

.countdown {
  font-variant-numeric: tabular-nums; font-weight: 800;
  font-size: clamp(2rem, 10vw, 3.4rem); color: var(--accent);
}
.countdown.warn { color: var(--warn); }
.countdown.danger { color: var(--bad); }

/* ---- Question image ----------------------------------------------------- */

.q-image { width: 100%; max-height: 42vh; object-fit: contain; border-radius: var(--radius); background: var(--surface-2); }
.q-text { font-family: var(--font-display); font-size: clamp(1.4rem, 5.5vw, 2rem); line-height: 1.15; margin: 8px 0 4px; }

/* ---- Toast / notice ----------------------------------------------------- */

.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink); font-weight: 500; }
.notice-ok { background: var(--ok-bg); color: var(--ok); }
.notice-bad { background: var(--bad-bg); color: var(--bad); }
.notice-warn { background: var(--warn-bg); color: var(--warn); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius-pill);
  box-shadow: var(--shadow-2); z-index: 60; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

/* ---- Utilities ---------------------------------------------------------- */

.hidden { display: none !important; }
.spread { margin-top: auto; }
.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }
.big-num { font-family: var(--font-display); font-size: clamp(2.4rem, 11vw, 4rem); font-weight: 700; line-height: 1; }

/* Osaleja mängu-vaade: täisekraan, tegevusnupp alla */
.play-screen { min-height: 100dvh; display: flex; flex-direction: column; }
.play-screen .wrap { flex: 1 1 auto; display: flex; flex-direction: column; }
.sticky-action { position: sticky; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 70%, transparent); }

@media (min-width: 640px) {
  .choices.two { grid-template-columns: 1fr 1fr; }
}
