/* KS3 Maths Challenges. Mobile first: designed at 375x812 for a phone on the bus, scales up to a laptop.
   One theme: deep indigo night, glass cards, a gold accent, mint for "right", soft sky blue for "learning". */

:root {
  --bg: #0b1020;
  --panel: #161f40;
  --panel-2: #212c58;
  --glass: rgba(255, 255, 255, 0.07);
  --glass-strong: rgba(255, 255, 255, 0.11);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f6f7ff;
  --muted: #b9c1e2;
  --accent: #ffc83d;
  --accent-2: #ff9f43;
  --accent-text: #2a1a00;
  --good: #6df0b0;
  --bad: #ff8f9d;
  --nudge: #ffe2a8;
  --calm: #bfe3ff;
  --focus: #8fd0ff;
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(520px 360px at 92% -6%, rgba(111, 92, 255, 0.45) 0%, transparent 70%),
    radial-gradient(520px 420px at -8% 104%, rgba(60, 90, 255, 0.28) 0%, transparent 68%),
    radial-gradient(380px 260px at 50% 52%, rgba(255, 200, 61, 0.05) 0%, transparent 70%),
    linear-gradient(180deg, #121a45 0%, #0b1020 55%);
  background-attachment: fixed;
  background-color: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding-top: calc(20px + env(safe-area-inset-top));
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* The game screens: one centred phone-width column that fills the screen height. */
main:not(.wide) {
  max-width: 560px;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: 0;
  padding-bottom: 0;
  display: flex;
  flex-direction: column;
}

h1 { font-size: 1.9rem; line-height: 1.15; margin: 0 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 28px 0 8px; color: var(--muted); font-weight: 600; letter-spacing: 0.02em; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1:focus { outline: none; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 1.25em; height: 1.25em; flex: none; fill: currentColor; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- Buttons ---- */
button {
  font: inherit;
  font-weight: 700;
  min-height: 48px;
  border: 0;
  border-radius: 16px;
  padding: 12px 22px;
  cursor: pointer;
  color: var(--text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  line-height: 1.25;
}

/* Glossy gold: bright top highlight, deeper bottom, a solid "lip" underneath, soft glow. */
button.primary {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 58px;
  border-radius: 18px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent-text);
  background: linear-gradient(180deg, #ffd95f 0%, #ffb52f 52%, #ff9a1c 100%);
  box-shadow:
    inset 0 1.5px 0 rgba(255, 255, 255, 0.75),
    inset 0 -3px 6px rgba(170, 80, 0, 0.22),
    0 5px 0 #b3600b,
    0 14px 28px rgba(255, 150, 30, 0.32);
  margin-bottom: 5px;
}
button.primary::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 48% 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.1));
  border-radius: 18px 18px 50% 50% / 18px 18px 22px 22px;
}
button.primary:hover { filter: brightness(1.05); }
button.primary:active {
  transform: translateY(4px);
  box-shadow:
    inset 0 1.5px 0 rgba(255, 255, 255, 0.75),
    inset 0 -3px 6px rgba(170, 80, 0, 0.22),
    0 1px 0 #b3600b,
    0 6px 14px rgba(255, 150, 30, 0.25);
}

button.secondary {
  background: var(--glass);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 6px 16px rgba(5, 8, 30, 0.35);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
button.secondary:hover { background: var(--glass-strong); }
button.secondary:active { transform: scale(0.98); }
.hintbtn .ico { color: var(--accent); }

/* "I don't know this": a quiet, friendly door to the answer. Sky blue, never red. */
button.calm {
  background: rgba(143, 208, 255, 0.09);
  border: 1px solid rgba(143, 208, 255, 0.3);
  color: var(--calm);
  font-weight: 600;
  font-size: 0.95rem;
  min-height: 50px;
}
button.calm:hover { background: rgba(143, 208, 255, 0.15); }
button.calm:active { transform: scale(0.98); }

button.link {
  background: none;
  color: var(--muted);
  text-decoration: underline;
  font-weight: 500;
  padding: 12px 12px;
}
a.link {
  display: inline-block;
  color: var(--accent);
  text-decoration: underline;
  font-weight: 600;
  padding: 12px 12px;
}
button:disabled,
button.primary:disabled {
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
  background: #29325f;
  color: #c9d0ee;
  border: 1px solid var(--border);
  margin-bottom: 0;
}
button.primary:disabled::before { display: none; }
button.secondary:disabled { opacity: 0.7; }
button:not(.primary):disabled { background: rgba(255, 255, 255, 0.05); color: #aeb7dc; }

/* ---- General text ---- */
.status { font-size: 1.1rem; color: var(--muted); margin: 0 0 16px; }
.note { color: var(--muted); font-size: 0.95rem; min-height: 1.4em; }
.view .note { text-align: center; }
.error {
  background: rgba(255, 143, 157, 0.12);
  border: 1px solid rgba(255, 143, 157, 0.45);
  color: #ffe0e4;
  padding: 12px 16px;
  border-radius: 14px;
  margin: 12px 0 0;
}

/* Top of the screen: staging banner (if any) and score + streak. It stays put while you scroll. */
.chrome {
  position: sticky;
  top: 0;
  z-index: 30;
  margin: 0 calc(-1 * max(16px, env(safe-area-inset-left)));
  padding: var(--safe-top) max(16px, env(safe-area-inset-left)) 0;
  background: rgba(11, 16, 32, 0.72);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.env-banner {
  margin: 0 calc(-1 * max(16px, env(safe-area-inset-left)));
  padding: 8px 16px;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.3;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent-text);
  background: repeating-linear-gradient(-45deg, #ffd45a 0 14px, #ffbf2e 14px 28px);
}
.hud { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; min-height: 48px; }
.brand .ico { width: 34px; height: 34px; filter: drop-shadow(0 2px 6px rgba(255, 160, 40, 0.35)); }
.chips { display: flex; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 14px 4px 10px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.chip-points .ico { color: var(--accent); filter: drop-shadow(0 0 6px rgba(255, 200, 61, 0.55)); }
.chip-streak .ico { color: #8e97c4; }
.chip-streak.lit .ico { color: #ff9a3d; filter: drop-shadow(0 0 7px rgba(255, 140, 40, 0.65)); }

/* ---- Sign in ---- */
.login-wrap { margin: auto 0; padding: 32px 0; }
.login-wrap .hero { margin-bottom: 20px; }
.login {
  display: grid;
  gap: 8px;
  padding: 22px 20px;
  border-radius: 24px;
  background: var(--glass);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 18px 40px rgba(4, 6, 24, 0.45);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.login input {
  font: inherit;
  font-size: 1.15rem;
  min-height: 54px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: rgba(8, 12, 32, 0.6);
  color: var(--text);
  width: 100%;
  margin-bottom: 6px;
}
.login input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 4px rgba(143, 208, 255, 0.2); }
.login .primary { margin-top: 10px; width: 100%; }
.login .feedback { min-height: 0; text-align: center; }
.login .feedback:empty { padding: 0; border: 0; margin: 0; }

/* ---- Hero blocks (home and result) ---- */
.hero { position: relative; text-align: center; padding: 26px 0 18px; }
.hero h1 { font-size: 1.75rem; }
.hero .status { margin-bottom: 18px; }
.logo {
  width: 88px;
  height: 88px;
  margin: 0 auto 14px;
  border-radius: 26px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #5443d6 0%, #1a1f5e 100%);
  box-shadow:
    inset 0 1.5px 0 rgba(255, 255, 255, 0.35),
    inset 0 -8px 16px rgba(7, 10, 40, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.1),
    0 16px 36px rgba(86, 68, 220, 0.5);
}
.logo .ico { width: 56px; height: 56px; }

/* ---- Progress pills ---- */
.dots { display: flex; gap: 6px; max-width: 360px; margin: 0 auto; }
.dot {
  flex: 1 1 0;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}
.dot.done {
  background: linear-gradient(180deg, #ffe082, #ffb02e);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 0 10px rgba(255, 190, 50, 0.45);
}
.dot.current { background: rgba(255, 255, 255, 0.28); box-shadow: 0 0 0 2px rgba(255, 224, 130, 0.9), 0 0 12px rgba(255, 200, 61, 0.5); }
.dots-sm { margin: 8px 0 6px; max-width: none; gap: 4px; }
.dots-sm .dot { height: 8px; }

/* ---- Stat tiles ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 22px 0 0; }
.stats div {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.stats .ico { position: absolute; top: 12px; right: 12px; width: 20px; height: 20px; color: var(--accent); opacity: 0.9; }
.stats dt { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; line-height: 1.3; padding-right: 22px; }
.stats dd { margin: 6px 0 0; font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.signout { text-align: center; margin: 8px 0 0; }

/* ---- Views and layout ---- */
.view { flex: 1; display: flex; flex-direction: column; padding: 8px 0 calc(28px + var(--safe-bottom)); }
#view-home > .stats, #view-result > .stats { display: grid; }
.view > * { flex: none; }

/* ---- Challenge ---- */
#view-challenge { padding-bottom: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin: 10px 0 6px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 10px 26px rgba(4, 6, 24, 0.35);
}
.topbar-text { min-width: 0; flex: 1; }
.topbar h1 { font-size: 1.1rem; margin: 0; font-weight: 800; }
.maxpoints { color: var(--muted); font-size: 0.9rem; }
.maxpoints strong { color: var(--accent); font-size: 1.1rem; font-variant-numeric: tabular-nums; }

.timer-block { position: relative; width: 4.3rem; height: 4.3rem; flex: none; display: grid; place-items: center; }
.ring { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ring circle { fill: none; stroke-width: 5; }
.ring-track { stroke: rgba(255, 255, 255, 0.14); }
.ring-fill { stroke: var(--accent); stroke-linecap: round; filter: drop-shadow(0 0 5px rgba(255, 200, 61, 0.6)); }
.ring-fill.empty { stroke: transparent; }
.timer { position: relative; font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.bonuslines { margin: 0 0 2px; }
.bonusline { display: flex; align-items: flex-start; gap: 8px; color: var(--muted); font-size: 0.88rem; line-height: 1.35; }
.bonusline::before { content: ""; flex: none; width: 8px; height: 8px; margin-top: 0.45em; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px rgba(255, 200, 61, 0.7); }
#streakline { min-height: 2.7em; }
#streakline::before { background: #ff9a3d; box-shadow: 0 0 8px rgba(255, 140, 40, 0.7); }

.topic {
  align-self: flex-start;
  margin: 6px 0 0;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(255, 200, 61, 0.12);
  border: 1px solid rgba(255, 200, 61, 0.3);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
  font-weight: 800;
}
.topic:empty { display: none; }

.question {
  font-size: 1.45rem;
  line-height: 1.4;
  font-weight: 650;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05));
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: 24px;
  margin: 8px 0 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 14px 32px rgba(4, 6, 24, 0.4);
}
.glossary { color: var(--muted); font-size: 0.95rem; margin: 0 0 12px; padding: 10px 14px; border-radius: 14px; background: rgba(143, 208, 255, 0.07); border: 1px solid rgba(143, 208, 255, 0.18); }
.glossary strong { color: var(--text); font-weight: 700; }

.hints { list-style: none; counter-reset: hint; padding: 0; margin: 0 0 12px; }
.hints:empty { margin: 0; }
.hints li {
  counter-increment: hint;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: rgba(255, 200, 61, 0.08);
  border: 1px solid rgba(255, 200, 61, 0.22);
  padding: 10px 14px;
  border-radius: 14px;
  margin-bottom: 8px;
}
.hints li::before {
  content: counter(hint);
  flex: none;
  width: 1.6em;
  height: 1.6em;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--accent-text);
  background: linear-gradient(180deg, #ffd95f, #ffa72b);
}

.spacer { flex: 1 1 auto; min-height: 4px; }

/* Feedback has its own reserved space so nothing jumps when it appears. Soft amber, not alarming. */
.feedback {
  min-height: 5.4em;
  margin: 0 0 8px;
  font-size: 0.92rem;
  padding: 10px 14px;
  border-radius: 16px;
  font-weight: 600;
  border: 1px solid transparent;
  line-height: 1.45;
}
.feedback:empty { background: transparent; }
.feedback.bad { color: var(--nudge); background: rgba(255, 200, 110, 0.1); border-color: rgba(255, 200, 110, 0.3); }

.actions { display: grid; gap: 8px; margin-top: 8px; }
#dontknow-btn { scroll-margin-bottom: 200px; }
.actions-result { margin-top: 6px; }

/* The answer box lives at the bottom, in thumb reach, and stays on screen above the keyboard. */
.dock {
  position: sticky;
  bottom: 0;
  z-index: 20;
  margin: 8px calc(-1 * max(16px, env(safe-area-inset-left))) 0;
  padding: 10px max(16px, env(safe-area-inset-left)) calc(10px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(11, 16, 32, 0) 0, rgba(11, 16, 32, 0.97) 14px, #0b1020 100%);
}
label { display: block; color: var(--muted); margin: 0 0 4px 4px; font-size: 0.85rem; font-weight: 600; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; }
.dock .row { flex-wrap: wrap; }
input[type="text"] {
  flex: 1 1 9rem;
  min-width: 0;
  font: inherit;
  font-size: 1.5rem; /* 16px or more stops phones zooming in when the box is tapped */
  font-weight: 700;
  min-height: 58px;
  padding: 10px 16px;
  border-radius: 18px;
  border: 2px solid var(--border);
  background: rgba(8, 12, 32, 0.7);
  color: var(--text);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
}
input[type="text"]:focus { border-color: var(--focus); outline: none; box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3), 0 0 0 4px rgba(143, 208, 255, 0.22); }
input[type="text"]:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.dock button.primary { flex: 0 0 auto; padding: 12px 20px; margin-bottom: 5px; }
.dock .row { padding-bottom: 5px; }
.dock button.primary { margin-bottom: 0; }

/* ---- Result ---- */
.result-hero { padding-top: 22px; }
.result-hero::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 360px;
  height: 300px;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(255, 200, 61, 0.28), transparent);
  pointer-events: none;
  z-index: -1;
}
#view-result.calm .result-hero::before { background: radial-gradient(closest-side, rgba(143, 208, 255, 0.24), transparent); }
.medal {
  width: 84px;
  height: 84px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--accent-text);
  background: linear-gradient(180deg, #ffe38a, #ffa72b);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.7), inset 0 -4px 8px rgba(160, 80, 0, 0.25), 0 0 0 6px rgba(255, 200, 61, 0.18), 0 12px 32px rgba(255, 160, 40, 0.45);
}
.medal .ico { width: 44px; height: 44px; fill: none; stroke: currentColor; }
.medal .ico use { fill: none; }
#view-result.calm .medal {
  color: #0c2a44;
  background: linear-gradient(180deg, #cfeaff, #7fc0f5);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.7), inset 0 -4px 8px rgba(20, 70, 120, 0.25), 0 0 0 6px rgba(143, 208, 255, 0.16), 0 12px 32px rgba(90, 170, 240, 0.4);
}
.result-hero h1 { font-size: 1.45rem; line-height: 1.25; margin-bottom: 4px; }
.score-wrap { margin: 0; display: flex; justify-content: center; align-items: baseline; gap: 8px; }
.score { font-size: 3.6rem; line-height: 1.1; font-weight: 900; color: var(--accent); font-variant-numeric: tabular-nums; text-shadow: 0 0 24px rgba(255, 200, 61, 0.45); }
#view-result.calm .score { color: var(--calm); text-shadow: 0 0 24px rgba(143, 208, 255, 0.35); }
.score-unit { color: var(--muted); font-weight: 700; }
.badges { color: var(--good); font-weight: 700; min-height: 1.4em; margin: 4px 0 16px; }
#view-result.calm .badges { color: var(--calm); }
.breakdown { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--glass); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.breakdown th, .breakdown td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); font-weight: 500; }
.breakdown tr:last-child th, .breakdown tr:last-child td { border-bottom: 0; }
.breakdown td { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.solution { background: var(--glass); border: 1px solid var(--border); padding: 16px 20px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 12px; }
#result-note:not(:empty) {
  padding: 14px 16px;
  margin: 4px 0 8px;
  border-radius: 18px;
  color: var(--text);
  font-weight: 600;
  background: linear-gradient(160deg, rgba(255, 200, 61, 0.16), rgba(255, 200, 61, 0.06));
  border: 1px solid rgba(255, 200, 61, 0.35);
}

.flag-box { margin: 18px 0 0; color: var(--muted); }
.flag-box summary { cursor: pointer; padding: 12px 4px; min-height: 48px; display: flex; align-items: center; gap: 8px; }
.flag-box form { background: var(--glass); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-top: 8px; display: grid; gap: 8px; }
.flag-box select, .flag-box input[type="text"] {
  font: inherit; font-size: 1rem; font-weight: 500; min-height: 48px; color: var(--text);
  background: rgba(8, 12, 32, 0.7); border: 2px solid var(--border); border-radius: 12px; padding: 8px 12px; box-shadow: none;
}
.flag-box button { justify-self: stretch; }
.flag-box label { margin-left: 0; }

/* ---- Motion (all of it is switched off for people who ask for less) ---- */
@media (prefers-reduced-motion: no-preference) {
  button { transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease, background 0.15s ease; }

  .view.enter > * { animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) backwards; }
  .view.enter > *:nth-child(2) { animation-delay: 50ms; }
  .view.enter > *:nth-child(3) { animation-delay: 100ms; }
  .view.enter > *:nth-child(4) { animation-delay: 150ms; }
  .view.enter > *:nth-child(5) { animation-delay: 200ms; }
  .view.enter > *:nth-child(n+6) { animation-delay: 250ms; }
  @keyframes rise { from { opacity: 0; transform: translateY(14px); } }

  .ring-fill { transition: stroke-dashoffset 0.25s linear; }

  .dot.current { animation: glow 1.8s ease-in-out infinite; }
  @keyframes glow { 50% { box-shadow: 0 0 0 2px rgba(255, 224, 130, 0.9), 0 0 20px rgba(255, 200, 61, 0.8); } }

  .chip.bump { animation: bump 0.6s ease-out; }
  @keyframes bump { 30% { transform: scale(1.14); box-shadow: 0 0 18px rgba(255, 200, 61, 0.6); } }

  .score.pop { animation: pop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1); }
  @keyframes pop { from { transform: scale(0.8); } to { transform: scale(1); } }

  #view-result.win .medal { animation: medal 0.8s cubic-bezier(0.2, 1.5, 0.4, 1) both, halo 2.4s ease-in-out 0.8s infinite; }
  #view-result.calm .medal { animation: medal 0.7s ease-out both; }
  @keyframes medal { from { transform: scale(0.4) rotate(-12deg); opacity: 0; } }
  @keyframes halo { 50% { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.7), inset 0 -4px 8px rgba(160, 80, 0, 0.25), 0 0 0 12px rgba(255, 200, 61, 0.08), 0 12px 40px rgba(255, 160, 40, 0.6); } }

  /* A wrong answer gets a soft glow and the tiniest sway. No flashing red. */
  .feedback.flash { animation: soft 0.7s ease-out; }
  @keyframes soft { from { background: rgba(255, 200, 110, 0.3); transform: translateY(4px); } to { background: rgba(255, 200, 110, 0.1); transform: none; } }
  #view-challenge.nudge #answer { animation: sway 0.45s ease-in-out; }
  @keyframes sway { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

  .bit { animation: confetti 1.4s cubic-bezier(0.15, 0.7, 0.3, 1) var(--d) both; }
  @keyframes confetti {
    0% { transform: translate(0, 0) rotate(0) scale(0.5); opacity: 1; }
    75% { opacity: 1; }
    100% { transform: translate(var(--dx), calc(var(--dy) + 150px)) rotate(var(--rot)) scale(1); opacity: 0; }
  }
}

/* Confetti layer: nothing in it can be tapped. */
.fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 60; }
.bit { position: absolute; left: 50%; top: 34%; width: 9px; height: 14px; border-radius: 2px; background: var(--c); }
.bit.round { width: 10px; height: 10px; border-radius: 50%; }

/* ---- Phones ---- */
@media (max-width: 600px) {
  body { font-size: 16.5px; }
  .question { font-size: 1.35rem; padding: 18px; border-radius: 22px; }
  .score { font-size: 3.2rem; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats dd { font-size: 1.3rem; }
  .login { padding: 20px 16px; }
  button.primary, button.secondary { width: 100%; }
  .dock button.primary { width: auto; }
}

@media (max-width: 360px) {
  .stats { grid-template-columns: 1fr; }
  .chip { padding-right: 10px; }
}

/* Short screens (landscape phones, big text, keyboard open): let the bars scroll away so the question has room. */
@media (max-height: 560px) {
  .chrome, .dock { position: static; }
}

/* Two columns of actions when there is room (not on the narrowest phones). */
@media (min-width: 480px) {
  #view-challenge .actions { grid-template-columns: 1fr 1fr; }
}

/* ---- One-time welcome ---- */
.welcome {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  overflow-y: auto;
  padding: max(16px, var(--safe-top)) max(16px, env(safe-area-inset-left)) max(16px, var(--safe-bottom));
  background: rgba(8, 12, 32, 0.86);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.welcome-card {
  width: 100%;
  max-width: 460px;
  margin: auto;
  padding: 24px 20px 22px;
  text-align: center;
  border-radius: 28px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.05));
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 24px 56px rgba(4, 6, 24, 0.55);
}
.welcome-card .logo { width: 72px; height: 72px; border-radius: 22px; margin-bottom: 12px; }
.welcome-card .logo .ico { width: 46px; height: 46px; }
.welcome-card h1 { font-size: 1.6rem; margin-bottom: 14px; }
.welcome-list { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 10px; text-align: left; }
.welcome-list li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 16px; background: rgba(8, 12, 32, 0.4); border: 1px solid rgba(255, 255, 255, 0.08); line-height: 1.4; }
.welcome-list .ico { width: 24px; height: 24px; margin-top: 1px; color: var(--accent); }
.welcome-list li:nth-child(3) .ico { color: var(--calm); }
.welcome-card .primary { width: 100%; }

/* After "I don't know this": a quiet, honest line instead of a big score. */
.soft-points { margin: 6px auto 4px; max-width: 30em; color: var(--muted); font-size: 0.95rem; line-height: 1.4; }

@media (prefers-reduced-motion: no-preference) {
  .welcome-card { animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) backwards; }
}

/* ---- Public (signed-out) mode ---- */
.chips { align-items: center; }
.signin-link {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: underline;
  padding: 12px 8px;
  margin-right: 2px;
}
.signin-link:hover { color: var(--text); }
/* Things that only exist for signed-in people are never shown in public mode. */
body.is-public #home-stats,
body.is-public #result-stats,
body.is-public #flag-box { display: none; }

.site-foot { margin-top: auto; padding: 18px 0 calc(14px + var(--safe-bottom)); text-align: center; font-size: 0.9rem; }
.site-foot a.link { color: var(--muted); font-weight: 500; padding: 12px 14px; }

/* Summary: the ten results as coloured pills (the same shape as the progress pills). */
.squares { max-width: 400px; margin-top: 14px; }
.squares .dot { height: 26px; border-radius: 9px; }
.dot.sq-g { background: linear-gradient(180deg, #9bf6cb, #36c985); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 0 10px rgba(109, 240, 176, 0.35); }
.dot.sq-y { background: linear-gradient(180deg, #ffe082, #ffb02e); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 0 10px rgba(255, 190, 50, 0.35); }
.dot.sq-b { background: linear-gradient(180deg, #cfeaff, #6fb6f0); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 0 10px rgba(143, 208, 255, 0.35); }
#view-summary .badges { margin: 4px 0 0; }
.signin-note { margin-top: 4px; }
.tagline { margin: 0 0 12px; color: var(--accent); font-weight: 600; font-size: 1rem; }
.copy-box {
  display: block;
  width: 100%;
  margin: 8px 0;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: rgba(8, 12, 32, 0.7);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}

/* Privacy page and the small links under the sign-in form. */
.doc { padding: 20px 0 8px; }
.doc h1 { font-size: 1.7rem; margin-bottom: 6px; }
.doc .lead { color: var(--muted); margin: 0 0 18px; }
.doc section {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 18px 14px;
  margin: 0 0 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.doc h2 { margin: 14px 0 4px; color: var(--accent); font-size: 1.02rem; }
.doc p { margin: 0 0 8px; }
.doc a:not(.link) { color: var(--accent); }
.back { margin: 8px 0 0; }
.login-links { text-align: center; margin: 14px 0 0; }
.login-links a.link { color: var(--muted); font-weight: 500; }
