/*
  MatheMinute. Warm paper and a dark ink with four neon colours (after Breadboarder's palette, pushed to full neon),
  thin borders and no drop shadows. The logo is a clock ringed by a minute in four neon quarters; the same
  clock is the test timer, and the quarter colours run through the app. In dark mode the neon glows.
*/

:root {
  --yellow: #efff2e;
  --pink: #ff5cc6;
  --blue: #2be4ff;
  --green: #5dff7a;
  --wrong: #ff2d6f;
  --pink-text: #e5139a;

  --ink: #24251f;
  --on-neon: #24251f;
  --muted: #6f7064;
  --paper: #fffef9;
  --paper-alt: #f3f2e9;
  --line: var(--ink);
  --glow-strength: 0%;

  --radius: 10px;
  --radius-big: 16px;
  --quarters: linear-gradient(90deg, var(--yellow) 0 25%, var(--green) 25% 50%, var(--blue) 50% 75%, var(--pink) 75%);
  --font: "Nunito", ui-rounded, "SF Pro Rounded", ui-sans-serif, system-ui, sans-serif;

  color-scheme: light dark;
}

/* Dark colours, used when chosen in settings, or when following a device set to dark */
:root[data-theme="dark"] {
  --ink: #f4f4ea;
  --muted: #a3a496;
  --paper: #121310;
  --paper-alt: #1c1d18;
  --line: #4a4c40;
  --glow-strength: 55%;
  --pink-text: var(--pink);
  color-scheme: dark;
}


:root[data-theme="light"] { color-scheme: light; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f4f4ea;
    --muted: #a3a496;
    --paper: #121310;
    --paper-alt: #1c1d18;
    --line: #4a4c40;
    --glow-strength: 55%;
    --pink-text: var(--pink);
  }
}

/* ── Base ───────────────────────────────────────── */

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-synthesis: none;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  font-weight: 600;
  text-decoration-color: var(--pink);
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
}

/* Text links (and the sign out button, styled as one): green underline and a faint wash on hover.
   The wash is a touch of ink mixed into the paper, so it's slightly darker in light mode and lighter in dark */
a:not(.button, .logo, .greeting__avatar), .link-button {
  margin: 0 -0.2em;
  padding: 0.05em 0.2em;
  border-radius: 4px;
  transition: background-color 120ms, text-decoration-color 120ms;
}

a:not(.button, .logo, .greeting__avatar):hover, .link-button:hover {
  background-color: color-mix(in srgb, var(--ink) 5%, var(--paper));
  text-decoration-color: var(--green);
}

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

[hidden] { display: none !important; }

.site-header {
  display: flex;
  justify-content: center;
  padding: calc(1.5rem + env(safe-area-inset-top)) 1rem 0;
}

.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  max-width: 30rem;
  margin: 0 auto;
  padding: 1.5rem 1rem calc(2rem + env(safe-area-inset-bottom));
  text-align: center;
}

.page--narrow { max-width: 24rem; }

/* ── Clock: the logo and the test timer ───────── */

/* A clock face ringed by a minute in four neon quarters */
.clock { display: block; color: var(--ink); overflow: visible; }
.clock__track { opacity: 0.15; }
/* Each hand turns about its bottom end, the centre of the clock */
.clock__hand { transform-box: fill-box; transform-origin: 50% 100%; }

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink);
  text-decoration: none;
}

.logo__mark {
  width: 3.2rem;
  height: 3.2rem;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--blue) var(--glow-strength), transparent));
}

/* The wordmark is an SVG of Bree Serif: Mathe in ink, Minute in pink */
.logo__word { display: block; height: 1.9rem; width: auto; }
.logo__minute { fill: var(--pink-text); }

/* ── Type ───────────────────────────────────────── */

.heading {
  margin: 0;
  font-size: clamp(2rem, 9vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.1;
}

.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.aside, .hint { margin: 0; color: var(--muted); }
.hint { margin-top: -0.4rem; font-size: 0.85rem; text-align: left; }

/* ── Buttons ────────────────────────────────────── */

.button {
  --fill: var(--paper);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3.25rem;
  padding: 0.6rem 1.4rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--fill);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-decoration: none;
  text-transform: uppercase;
  touch-action: manipulation;
  transition: transform 100ms;
  -webkit-tap-highlight-color: transparent;
}

/* With no shadow to press into, a tap shrinks the button slightly */
.button:active { transform: scale(0.97); }

/* Neon buttons: dark text in both themes, and a glow in the dark */
.button--go, .button--share, .button--start, .button--cta {
  border-color: var(--on-neon);
  color: var(--on-neon);
  box-shadow: 0 0 22px color-mix(in srgb, var(--fill) var(--glow-strength), transparent);
}

.button--go { --fill: var(--green); }
.button--share { --fill: var(--pink); }
.button--cta { --fill: var(--blue); min-height: 4rem; font-size: 1.5rem; }

.button--start {
  --fill: var(--blue);
  width: 100%;
  min-height: 5.5rem;
  border-radius: var(--radius-big);
  font-size: clamp(2.25rem, 11vw, 3rem);
  letter-spacing: 0.04em;
}

.button--wide { width: 100%; }

.link-button {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  text-decoration: underline var(--pink) 3px;
  text-underline-offset: 4px;
}

.inline { display: inline; }

/* ── Forms ──────────────────────────────────────── */

.form {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
}

.form label, .choice legend { font-size: 0.9rem; font-weight: 700; }

.form input[type="text"],
.form input[type="password"] {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1.5px solid var(--muted);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 600;
}

.form input:focus-visible { border-color: var(--ink); outline: 3px solid var(--blue); outline-offset: 2px; }
.form .button { margin-top: 0.75rem; }

.choice {
  display: grid;
  gap: 0.5rem;
  margin: 0.75rem 0 0;
  padding: 0;
  border: 0;
}

.choice legend { margin-bottom: 0.5rem; padding: 0; }

.choice__option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
}

.choice__option:has(:checked) { border-color: var(--on-neon); background: var(--yellow); color: var(--on-neon); }
.choice__option input { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--on-neon); }

.flash {
  width: 100%;
  margin: 0;
  padding: 0.7rem 1rem;
  border: 2px solid var(--on-neon);
  border-radius: var(--radius);
  background: var(--green);
  color: var(--on-neon);
  font-weight: 600;
  list-style: none;
}

.flash--alert { background: var(--pink); }

/* ── Home ───────────────────────────────────────── */

.greeting {
  margin: 0.5rem 0 -0.75rem;
  font-size: clamp(1.6rem, 7vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.streak {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.5rem;
}

.streak__number {
  font-size: clamp(4.5rem, 26vw, 7.5rem);
  font-weight: 700;
  letter-spacing: -0.06em;
  line-height: 1;
}


.streak__number { text-shadow: 0 0 28px color-mix(in srgb, var(--yellow) var(--glow-strength), transparent); }

.streak__label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.nudge { margin: 0; color: var(--muted); font-size: 1.05rem; font-weight: 500; }

.nudge--risk {
  padding: 0.35rem 0.9rem;
  border: 2px solid var(--on-neon);
  border-radius: 999px;
  background: var(--pink);
  color: var(--on-neon);
  box-shadow: 0 0 18px color-mix(in srgb, var(--pink) var(--glow-strength), transparent);
}

.save-nudge {
  margin: 0;
  padding: 0.75rem 1rem;
  border: 1.5px dashed var(--muted);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.95rem;
}

.install { display: flex; flex-direction: column; align-items: center; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
  width: 100%;
  margin: 0.25rem 0 0;
}

.stats div {
  --stripe: var(--yellow);
  padding: 0.85rem 0.7rem 0.7rem;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(var(--stripe) 0 6px, var(--paper-alt) 6px);
}

.stats div:nth-child(2) { --stripe: var(--green); }

.stats dt { color: var(--muted); font-size: 0.65rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.stats dd { margin: 0; font-size: 1.75rem; font-weight: 700; letter-spacing: -0.03em; }

.footer { color: var(--muted); font-size: 0.85rem; }

/* ── Avatars ─────────────────────────────────────── */

.avatar {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border: 2px solid var(--line);
  border-radius: 50%;
  object-fit: cover;
}

.avatar--medium { --avatar-size: 2.75rem; }
.avatar--large { --avatar-size: 6rem; }

/* No picture: the first letter on the player's neon colour */
.avatar--letter {
  --fill: var(--yellow);
  border-color: var(--on-neon);
  background: var(--fill);
  box-shadow: 0 0 16px color-mix(in srgb, var(--fill) var(--glow-strength), transparent);
  color: var(--on-neon);
  font-size: calc(var(--avatar-size) * 0.48);
  font-weight: 700;
  line-height: 1;
}

.avatar--green { --fill: var(--green); }
.avatar--blue { --fill: var(--blue); }
.avatar--pink { --fill: var(--pink); }

.greeting { display: flex; align-items: center; justify-content: center; gap: 0.6rem; }
.greeting__avatar { display: inline-flex; border-radius: 50%; text-decoration: none; }

.avatar-field { margin: 0 0 0.75rem; padding: 0; border: 0; }
.avatar-field legend { margin-bottom: 0.6rem; padding: 0; font-size: 0.9rem; font-weight: 700; }
.avatar-field__row { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.6rem; }
.avatar-field__controls { display: grid; gap: 0.6rem; justify-items: start; }
.avatar-field__controls .button { min-height: 2.75rem; padding: 0.4rem 1rem; font-size: 0.85rem; cursor: pointer; }
.avatar-field__controls .button:focus-within { outline: 3px solid var(--blue); outline-offset: 3px; }
.avatar-field__remove { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; font-weight: 500; }
.avatar-field .hint { margin-top: 0; }

/* ── Stats ──────────────────────────────────────── */

.stats--three { grid-template-columns: repeat(3, 1fr); }
.stats--three div:nth-child(3) { --stripe: var(--blue); }

.tables {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.tables caption { margin-bottom: 0.5rem; }

.tables th, .tables td { padding: 0.45rem 0.3rem; text-align: right; white-space: nowrap; }
.tables thead th { color: var(--muted); font-size: 0.65rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.tables tbody tr { border-top: 1px solid color-mix(in srgb, var(--ink) 12%, transparent); }
.tables tbody th { font-weight: 700; text-align: left; }
.tables__bar { width: 100%; }

/* One hue for every bar: the percentage is a magnitude, and the number beside it carries the value */
.bar {
  display: block;
  height: 0.85rem;
  overflow: hidden;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--paper-alt);
}

.bar__fill {
  display: block;
  height: 100%;
  background: var(--blue);
  box-shadow: 0 0 10px color-mix(in srgb, var(--blue) var(--glow-strength), transparent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── Test ───────────────────────────────────────── */

/* Fill the screen, no scrolling, no zooming, no text selection while tapping fast */
body.testing {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.test {
  --right: var(--green);
  --quarter: var(--yellow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 30rem;
  margin: 0 auto;
  padding: calc(0.75rem + env(safe-area-inset-top)) 1rem calc(0.75rem + env(safe-area-inset-bottom));
}

/* Score, clock, seconds: equal side columns keep the clock dead centre */
.test__bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.9rem;
}

/* The timer is the logo's clock: its quarters fill in over the minute while the hands spin */
.timer__clock {
  width: 5.5rem;
  height: 5.5rem;
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--quarter) var(--glow-strength), transparent));
}

/* Quick spins, just to show time moving */
.test--running .clock__hand--long { animation: spin 1.5s linear infinite; }
.test--running .clock__hand--short { animation: spin 12s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.test__seconds, .test__score {
  border-radius: var(--radius);
  font-weight: 700;
}

.test[data-quarter="1"] { --quarter: var(--green); }
.test[data-quarter="2"] { --quarter: var(--blue); }
.test[data-quarter="3"] { --quarter: var(--pink); }

.test__seconds { justify-self: start; font-size: 1.75rem; }

.test__score {
  justify-self: end;
  padding: 0 0.3rem;
  font-size: 2.5rem;
  line-height: 1;
}

.test__stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 0;
}

.question {
  margin: 0;
  font-size: clamp(3.75rem, 17vw, 8rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  white-space: nowrap;
}

.question--done { font-size: clamp(2.75rem, 12vw, 5rem); }

/* Fixed height so the layout never shifts as digits appear */
.answer {
  min-width: 3ch;
  height: clamp(3.25rem, 14vw, 5.5rem);
  margin: 0;
  border-bottom: 6px solid var(--blue);
  font-size: clamp(2.75rem, 13vw, 5rem);
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.answer--wrong { border-color: var(--wrong); color: var(--wrong); }

.test__status { margin: 0; color: var(--muted); font-weight: 500; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
}

.keypad__key {
  min-height: 72px;
  height: clamp(72px, 9dvh, 86px);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-alt);
  color: var(--ink);
  font: inherit;
  font-size: 2rem;
  font-weight: 500;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Instant press feedback, no transition to wait for */
.keypad__key:active {
  border-color: var(--on-neon);
  background: var(--quarter);
  box-shadow: 0 0 18px color-mix(in srgb, var(--quarter) var(--glow-strength), transparent);
  color: var(--on-neon);
  transform: scale(0.97);
}

.keypad__key--back { background: var(--paper); font-size: 1.6rem; }

/* ── Results and share ──────────────────────────── */

.banner {
  margin: 0;
  padding: 0.45rem 1.1rem;
  border: 2px solid var(--on-neon);
  border-radius: var(--radius);
  background: var(--yellow);
  box-shadow: 0 0 24px color-mix(in srgb, var(--yellow) var(--glow-strength), transparent);
  color: var(--on-neon);
  font-size: 1.25rem;
  font-weight: 700;
  transform: rotate(-2deg);
}

/* The logo's four neon quarters of a minute across the top */
.card {
  width: 100%;
  padding: 1.5rem 1rem 1.25rem;
  border: 2px solid var(--line);
  border-radius: var(--radius-big);
  background: var(--quarters) top / 100% 8px no-repeat, var(--paper);
  box-shadow: 0 0 30px color-mix(in srgb, var(--yellow) calc(var(--glow-strength) / 2), transparent);
}

.card p { margin: 0; }

.card__score { font-size: 1.25rem; font-weight: 600; }

.card__number {
  display: block;
  font-size: clamp(4.5rem, 25vw, 7rem);
  font-weight: 700;
  letter-spacing: -0.06em;
  line-height: 1.05;
}

.card__stats { margin-top: 0.5rem !important; color: var(--muted); font-size: 1rem; font-weight: 500; }

.feedback { margin: 0; font-size: 1.25rem; font-weight: 600; letter-spacing: -0.02em; }

.missed { width: 100%; }

.missed ul {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
}

.missed li {
  padding: 0.25rem 0.7rem;
  border: 2px solid var(--pink);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--pink) 14%, var(--paper));
  font-size: 1.15rem;
  font-weight: 600;
}

/* Right but slow: yellow rather than pink */
.missed li.missed__slow {
  border-color: color-mix(in srgb, var(--yellow) 70%, var(--ink));
  background: color-mix(in srgb, var(--yellow) 30%, var(--paper));
}

.hint--centre { margin-top: 0.6rem; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .banner { transform: none; }
}
