/* Quick Maths — Homegrown design language.
   Cream dot-grid ground, ink borders, hard offset shadows, square corners.
   Archivo Black for display, Space Grotesk for body, Fraunces for the wordmark —
   the exact faces and palette from Homegrown's styles.css. Blue is the identity
   colour on purpose: Maths cards in Homegrown are blue (--cat-math), and this
   app IS the Maths quest. All fonts self-hosted; zero third-party requests. */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --font-body: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Archivo Black', var(--font-body);
  --font-wordmark: 'Fraunces', Georgia, serif;

  --bg: #f3efe6;
  --card: #ffffff;
  --ink: #14120e;
  --muted: #6b655a;
  --faintline: #d9d3c4;

  --yellow: #ffd43b;
  --blue: #55ccf2;
  --green: #9ff26b;
  --orange: #ff8a3d;
  --red: #ff5c5c;
  --pink: #ff90e8;

  --bw: 3px;
  --shadow: 6px 6px 0 var(--ink);
  --shadow-sm: 4px 4px 0 var(--ink);
  --shadow-xs: 3px 3px 0 var(--ink);

  --c: var(--blue); /* identity colour: Homegrown's maths blue */
}

html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  background-image: radial-gradient(var(--ink) 1px, transparent 1.4px);
  background-size: 26px 26px;
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--yellow); }

button {
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
input { font-family: inherit; color: inherit; }

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

/* viewport-fit=cover lets the cream ground run under the iOS status bar and home
   indicator; the safe-area insets keep the content itself clear of both. Without
   this the kicker sat under the status bar blur in the home-screen app. */
.wrap {
  max-width: 560px; margin: 0 auto;
  padding: calc(26px + env(safe-area-inset-top, 0px)) calc(18px + env(safe-area-inset-right, 0px))
           calc(56px + env(safe-area-inset-bottom, 0px)) calc(18px + env(safe-area-inset-left, 0px));
}

/* ---------- brand ---------- */
.brand { margin-bottom: 24px; }
.kicker {
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 4px;
}
.wordmark {
  font-family: var(--font-wordmark);
  font-weight: 800;
  font-size: clamp(2.3rem, 9vw, 3.1rem);
  letter-spacing: -0.05em;
  line-height: 0.98;
  margin: 0;
}
.tagline { margin: 8px 0 0; font-weight: 500; color: var(--muted); }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 22px;
}
.card h2 {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

/* ---------- players ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 0.95rem; font-weight: 700;
  background: var(--card);
  border: var(--bw) solid var(--ink);
  padding: 9px 14px;
  transition: transform 0.06s ease;
}
.chip.active { background: var(--c); box-shadow: var(--shadow-xs); }
.chip:active { transform: translate(2px, 2px); }
.chip-del { font-weight: 400; opacity: 0.45; padding: 0 2px; }

.add-row { display: flex; gap: 10px; }
.add-row input {
  flex: 1; min-width: 0;
  font-size: 1rem; font-weight: 500;
  padding: 11px 12px;
  border: var(--bw) solid var(--ink);
  background: var(--card);
}
.add-row input::placeholder { color: var(--muted); }
.add-row button {
  font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  background: var(--yellow);
  border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow-xs);
  padding: 10px 18px;
}
.add-row button:active { transform: translate(3px, 3px); box-shadow: none; }

/* ---------- levels ---------- */
.levels { display: grid; gap: 12px; }
.level-btn {
  display: flex; align-items: center; gap: 14px;
  text-align: left;
  border: var(--bw) solid var(--ink);
  background: var(--card);
  padding: 12px 14px;
  transition: transform 0.06s ease;
}
.level-num {
  flex: 0 0 auto;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  border: var(--bw) solid var(--ink);
  background: var(--bg);
}
.level-info { display: flex; flex-direction: column; gap: 2px; }
.level-info strong { font-size: 1rem; letter-spacing: 0.2px; }
.level-info span { font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.level-btn.active { background: var(--c); box-shadow: var(--shadow-sm); }
.level-btn.active .level-num { background: var(--card); }
.level-btn.active .level-info span { color: var(--ink); }
.level-btn:active { transform: translate(2px, 2px); }
.level-btn:disabled { opacity: 0.45; cursor: default; }
.level-btn:disabled:active { transform: none; }

.pb-line { font-weight: 700; min-height: 1.3em; margin: 18px 0 14px; }

/* ---------- progress card (start screen) ---------- */
.progress-head { display: flex; justify-content: space-between; align-items: baseline; }
.progress-level {
  font-family: var(--font-display);
  font-size: 0.7rem; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted);
}
.progress-chart {
  display: flex; align-items: flex-end; gap: 4px;
  height: 96px; padding: 22px 2px 0; /* headroom for the labels above full bars */
  border-bottom: 3px solid var(--ink);
}
.progress-chart .bar {
  position: relative; flex: 1 1 0; min-width: 0;
  background: var(--c);
  border: 2px solid var(--ink); border-bottom: none;
}
.progress-chart .bar.pb { background: var(--yellow); }
.bar-label {
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-display); font-size: 0.6rem; white-space: nowrap;
}
.progress-line { margin: 10px 0 0; font-size: 0.9rem; font-weight: 500; color: var(--muted); }

/* ---------- big buttons ---------- */
.big-btn {
  display: block; width: 100%;
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--c);
  border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow);
  padding: 17px;
  transition: transform 0.06s ease;
}
.big-btn:disabled { background: var(--card); color: var(--muted); box-shadow: none; cursor: default; }
.big-btn:not(:disabled):active { transform: translate(4px, 4px); box-shadow: none; }

.learn-link {
  display: block; margin: 16px auto 0;
  background: none; border: none;
  font-size: 0.95rem; font-weight: 700;
  text-decoration: underline; text-underline-offset: 3px;
  color: var(--muted);
}

/* ---------- game ---------- */
.hud { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 10px; }
.hud > div { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.hud-score span {
  font-family: var(--font-display);
  font-size: 1.5rem;
  background: var(--yellow);
  border: 2px solid var(--ink);
  box-shadow: var(--shadow-xs);
  padding: 2px 14px;
  min-width: 54px;
  text-align: center;
}
.hud-time span { font-family: var(--font-display); font-size: 1.5rem; padding: 2px 0; }
.hud small {
  font-family: var(--font-display);
  text-transform: uppercase; letter-spacing: 1.5px;
  font-size: 0.6rem; color: var(--muted);
}

.time-bar {
  height: 14px;
  border: var(--bw) solid var(--ink);
  background: var(--card);
  overflow: hidden;
  margin-bottom: 26px;
}
#time-bar-fill { height: 100%; width: 100%; background: var(--c); transition: width 0.1s linear, background 0.3s ease; }
#time-bar-fill.low { background: var(--red); }

.question {
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 9vw, 3.1rem);
  min-height: 1.2em;
  margin: 12px 0 10px;
}
.entry {
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.9rem;
  min-height: 1.3em;
  border-bottom: 4px solid var(--ink);
  max-width: 240px;
  margin: 0 auto 8px;
  padding-bottom: 2px;
}
.entry.empty { opacity: 0.3; }

.feedback { text-align: center; min-height: 1.7em; margin-bottom: 10px; }
.feedback.good, .feedback.bad {
  display: table; margin: 0 auto 10px;
  font-weight: 700; font-size: 1.05rem;
  border: 2px solid var(--ink);
  padding: 2px 14px;
}
.feedback.good { background: var(--green); }
.feedback.bad { background: var(--red); color: #fff; animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.pad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  max-width: 320px; margin: 0 auto 14px;
}
.pad button {
  font-family: var(--font-display);
  font-size: 1.35rem;
  border: var(--bw) solid var(--ink);
  background: var(--card);
  box-shadow: var(--shadow-xs);
  min-height: 58px;
  transition: transform 0.05s ease;
}
.pad button:active { background: var(--yellow); transform: translate(3px, 3px); box-shadow: none; }

.game-actions { display: flex; gap: 10px; max-width: 320px; margin: 0 auto; }
.game-actions button {
  font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  border: var(--bw) solid var(--ink);
  padding: 13px 16px;
}
#btn-skip { flex: 1; background: var(--card); box-shadow: var(--shadow-xs); }
#btn-skip:active { transform: translate(3px, 3px); box-shadow: none; }
#btn-check { flex: 2; background: var(--c); box-shadow: var(--shadow-sm); }
#btn-check:active { transform: translate(4px, 4px); box-shadow: none; }

.tier-tag {
  text-align: center; margin: -14px 0 0;
  font-family: var(--font-display);
  font-size: 0.6rem; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--muted);
}
.retry-tag {
  max-width: 340px; margin: 8px auto 0; text-align: center;
  background: var(--yellow);
  border: 2px solid var(--ink);
  padding: 6px 10px;
  font-weight: 700; font-size: 0.9rem;
}

/* ---------- teaching layer ---------- */
.explain {
  max-width: 340px; margin: 4px auto 14px; text-align: center;
  background: var(--card);
  border: var(--bw) solid var(--ink);
  border-top: 8px solid var(--c);
  box-shadow: var(--shadow);
  padding: 16px;
}
.explain-answer { font-family: var(--font-display); font-size: 1.15rem; margin: 0 0 8px; }
.explain-rule {
  font-family: var(--font-display);
  font-size: 1.1rem;
  background: var(--c);
  border: 2px solid var(--ink);
  padding: 8px 12px;
  margin: 0 0 12px;
}
.explain-rule::before {
  content: 'The trick';
  display: block;
  font-size: 0.6rem; letter-spacing: 1.5px; text-transform: uppercase;
  margin-bottom: 2px;
}
.explain-rule:empty { display: none; }
.explain-steps { display: grid; gap: 8px; margin: 0 0 14px; text-align: left; }
.explain-steps div {
  background: var(--bg);
  border: 2px solid var(--ink);
  padding: 9px 12px;
  font-weight: 700;
  font-size: 1.02rem;
}
.explain-steps div:last-child { background: var(--yellow); }
#btn-gotit { font-size: 0.95rem; padding: 13px; box-shadow: var(--shadow-sm); }
#btn-gotit:not(:disabled):active { transform: translate(3px, 3px); box-shadow: none; }

/* ---------- learn page ---------- */
.back-link {
  background: var(--card); border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow-xs);
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 8px 14px; margin-bottom: 14px;
}
.back-link:active { transform: translate(2px, 2px); box-shadow: none; }
.learn-title {
  font-family: var(--font-wordmark);
  font-weight: 800; letter-spacing: -0.04em;
  font-size: 2rem; margin: 0 0 18px;
}
.method { border-top: 8px solid var(--muted); }
.method-add { border-top-color: var(--green); }
.method-sub { border-top-color: var(--orange); }
.method-mul { border-top-color: var(--pink); }
.method-div { border-top-color: var(--blue); }
.method-pct { border-top-color: var(--yellow); }
.method h3 { margin: 0 0 8px; font-family: var(--font-display); font-size: 1rem; }
.method p { margin: 8px 0; line-height: 1.55; font-weight: 500; }
.method .eg {
  background: var(--bg);
  border: 2px solid var(--ink);
  padding: 9px 12px;
  font-weight: 700;
}
.pct-list { margin: 8px 0; padding-left: 20px; line-height: 1.8; font-weight: 500; }

/* ---------- end screen ---------- */
.end-card { text-align: center; margin-top: 44px; border-top: 8px solid var(--c); }
.pb-banner {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 1rem;
  background: var(--yellow);
  border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow-xs);
  padding: 8px 16px;
  margin: 0 0 8px;
  transform: rotate(-2deg);
  animation: pb-pop 0.45s ease-out;
}
@keyframes pb-pop {
  0% { transform: rotate(-2deg) scale(0.5); }
  65% { transform: rotate(-2deg) scale(1.1); }
  100% { transform: rotate(-2deg) scale(1); }
}
.end-score span { font-family: var(--font-display); font-size: 4.2rem; display: block; line-height: 1.05; }
.end-score small {
  font-family: var(--font-display);
  text-transform: uppercase; letter-spacing: 2px; font-size: 0.65rem; color: var(--muted);
}
#end-stats { font-weight: 500; color: var(--muted); }
.end-actions { display: grid; gap: 12px; margin-top: 18px; }
#btn-home {
  background: var(--card); border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow-xs);
  font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 12px 16px;
}
#btn-home:active { transform: translate(2px, 2px); box-shadow: none; }
.made-by { text-align: center; margin: 18px 0 0; font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.made-by a { color: var(--ink); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- hover states (pointer devices only — the Homegrown touch lesson) ---------- */
@media (hover: hover) {
  .chip:not(.active):hover { background: var(--bg); }
  .chip-del:hover { opacity: 1; }
  .level-btn:not(.active):not(:disabled):hover { background: var(--bg); }
  .big-btn:not(:disabled):hover { background: var(--green); }
  .add-row button:hover { background: var(--green); }
  .pad button:hover { background: var(--bg); }
  #btn-skip:hover { background: var(--bg); }
  #btn-check:hover { background: var(--green); }
  .learn-link:hover { color: var(--ink); }
  .back-link:hover, #btn-home:hover { background: var(--bg); }
}

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

/* version stamp under the start screen (filled in by update.js) */
.version {
  text-align: center; margin: 14px 0 0;
  font-family: var(--font-display);
  font-size: 0.55rem; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--muted); opacity: 0.6;
}

/* Home-screen app only. iOS draws the status bar as frosted glass whose blur
   bleeds a little way below the bar, and env(safe-area-inset-top) reports 0 in
   this mode with the "default" status bar style (checked on Tom's phone,
   2026-09-04: the inset padding above moved nothing). A fixed floor keeps the
   first line clear of the glass. 2026-09-29: the 64px floor was too big. With the
   "default" status bar style the page already starts BELOW the bar, so 64px was
   stacked on top of the bar (Tom + Leo saw a ~100pt gap; changing the inset term
   moved nothing, proving the floor was the active value). 26px blurred, 64px was
   clean, 40px still blurred (2026-09-29), so 54px. Browser tabs never match this query. */
@media (display-mode: standalone) {
  .wrap { padding-top: max(calc(8px + env(safe-area-inset-top, 0px)), 54px); }
}
