/* MathRush — mobile-first. Portrait, one thumb, never scrolls while playing. */

:root {
  --bg: #0e1116;
  --bg-2: #151a22;
  --card: #1a212b;
  --card-2: #212a36;
  --line: #2a3441;
  --ink: #eef3f8;
  --ink-dim: #8d9bad;
  --ok: #3ddc84;
  --bad: #ff5d5d;
  --hot: #ffb020;
  --accent: #5b8cff;
  --r: 16px;
  --pad: max(14px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  position: relative;
  height: 100dvh;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: radial-gradient(120% 60% at 50% 0%, #17202b 0%, var(--bg) 60%);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 14px var(--pad);
}
.screen.active { display: flex; }
.screen.scrollable { overflow-y: auto; -webkit-overflow-scrolling: touch; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

/* ── Home ─────────────────────────────────────────── */
.brand { margin: 8vh 0 0; text-align: center; }
.brand h1 {
  margin: 0;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1.2px;
}
.brand h1 span { color: var(--ok); }
.tagline { margin: 6px 0 0; color: var(--ink-dim); font-size: 14px; }

.statusline {
  margin: 18px auto 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 13px;
}

.modes { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }

.mode-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 16px;
  border-radius: var(--r);
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line);
  text-align: left;
  transition: transform .08s ease, border-color .15s ease;
}
.mode-card:active { transform: scale(.98); border-color: var(--ok); }
.mode-icon {
  width: 44px; height: 44px;
  flex: 0 0 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: #0f151d;
  font-size: 20px;
  color: var(--ok);
}
.mode-text { display: flex; flex-direction: column; flex: 1; }
.mode-text b { font-size: 19px; font-weight: 700; }
.mode-text em { font-style: normal; font-size: 13px; color: var(--ink-dim); margin-top: 2px; }
.mode-best { font-size: 12px; color: var(--ink-dim); text-align: right; white-space: nowrap; }

.home-nav { margin-top: 18px; display: flex; gap: 10px; }
.home-nav .ghost { flex: 1; }

.ghost {
  padding: 14px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  background: var(--card);
}
.ghost:active { background: var(--card-2); }

.primary {
  padding: 17px;
  border-radius: var(--r);
  background: var(--ok);
  color: #06210f;
  font-weight: 800;
  font-size: 17px;
}
.primary:active { filter: brightness(.9); }

.danger {
  padding: 14px;
  border-radius: var(--r);
  border: 1px solid #532;
  color: var(--bad);
  background: #1c1416;
}

/* ── Play ─────────────────────────────────────────── */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 40px;
}
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 12px;
  color: var(--ink-dim);
  font-size: 20px;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--card); }
.hud-mid { font-size: 17px; font-weight: 700; letter-spacing: .5px; }
.hud-mid .heart { color: var(--bad); letter-spacing: 2px; }
.hud-mid .heart.gone { color: #333c48; }
.hud-score { font-size: 17px; font-weight: 700; min-width: 56px; text-align: right; }
.hud-score i { font-style: normal; color: var(--hot); font-size: 13px; margin-left: 5px; }

.timerbar {
  height: 5px;
  border-radius: 99px;
  background: var(--card);
  overflow: hidden;
  margin-top: 8px;
}
#timerfill {
  height: 100%;
  width: 100%;
  background: var(--ok);
  transform-origin: left;
}
#timerfill.low { background: var(--bad); }

.qarea {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
}
.qwrap { text-align: center; }
.question {
  font-size: clamp(34px, 11vw, 52px);
  font-weight: 700;
  letter-spacing: 1px;
}
.answer {
  margin-top: 18px;
  min-height: 56px;
  font-size: clamp(38px, 13vw, 60px);
  font-weight: 800;
  color: var(--ok);
  letter-spacing: 2px;
}
.answer.wrong { color: var(--bad); }
.answer .caret {
  display: inline-block;
  width: 3px; height: .78em;
  background: var(--ink-dim);
  vertical-align: -.06em;
  animation: blink 1.1s steps(1) infinite;
}
.answer.filled .caret { display: none; }
@keyframes blink { 50% { opacity: 0; } }

.qarea.flash-ok .question { color: var(--ok); }
.qarea.flash-bad .question { color: var(--bad); }

/* Tier up / easing off — flashes over the question without pausing anything.
   Sits above .trick: a demotion is usually triggered by a miss, which opens the
   trick overlay in the same instant. */
.banner {
  position: absolute;
  z-index: 2;
  top: 0; left: 50%;
  transform: translate(-50%, -14px);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  background: #14251a;
  color: var(--ok);
  border: 1px solid #21402c;
}
.banner.show { opacity: 1; transform: translate(-50%, 4px); }
.banner.down { background: #2a1f0c; color: var(--hot); border-color: #4a3611; }

/* Intro */
.intro-body { margin-top: 10vh; }
.intro-lead { font-size: 22px; font-weight: 700; margin: 0 0 10px; }
.intro-body .note { font-size: 14px; }

.trick[hidden] { display: none; }   /* author display:flex would beat the UA [hidden] rule */
.trick {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  border-radius: var(--r);
  background: rgba(14, 17, 22, .97);
  border: 1px solid var(--line);
}
.trick-head { color: var(--hot); font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; }
.trick-lines div {
  font-size: clamp(17px, 5.2vw, 22px);
  padding: 5px 0;
  color: var(--ink);
}
.trick-lines div:last-child { color: var(--ok); font-weight: 700; }

/* ── Keypad ───────────────────────────────────────── */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  height: min(46vh, 360px);
  margin-top: 10px;
}
.key {
  border-radius: 14px;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line);
  font-size: 27px;
  font-weight: 600;
  display: grid;
  place-items: center;
  transition: transform .06s ease, background .06s ease;
}
.key.down { transform: scale(.94); background: var(--ok); color: #06210f; border-color: var(--ok); }
.key.util { font-size: 22px; color: var(--ink-dim); background: #12181f; }
.key.util.down { color: #06210f; }

/* ── Results ──────────────────────────────────────── */
.res-placement .bigscore,
.res-placement #res-home { display: none; }
.res-placement .res-sub { max-width: 30ch; margin: 14px auto 0; line-height: 1.5; }
.res-top { text-align: center; margin-top: 6vh; }
.res-title { color: var(--ink-dim); font-size: 15px; text-transform: uppercase; letter-spacing: 2px; }
.bigscore { font-size: 76px; font-weight: 800; line-height: 1.05; margin: 6px 0; }
.res-sub { color: var(--ink-dim); font-size: 14px; }

.badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.badge {
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: #14251a;
  color: var(--ok);
  border: 1px solid #21402c;
}
.badge.hot { background: #2a1f0c; color: var(--hot); border-color: #4a3611; }

.review { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.review h3 { margin: 0 0 2px; font-size: 13px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; }
.review-item {
  padding: 12px 14px;
  border-radius: var(--r);
  background: var(--card);
  border: 1px solid var(--line);
}
.review-q { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.review-q s { color: var(--bad); text-decoration-color: var(--bad); font-weight: 500; margin-left: 8px; font-size: 15px; }
.review-q b { color: var(--ok); }
.review-line { font-size: 14px; color: var(--ink-dim); padding: 2px 0; }

.actions { margin-top: auto; padding-top: 22px; display: flex; flex-direction: column; gap: 10px; }

/* ── Progress / Settings ──────────────────────────── */
.topbar { display: flex; align-items: center; justify-content: space-between; }
.topbar h2 { font-size: 18px; margin: 0; }
.topbar span { width: 40px; }

.section-head { font-size: 13px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; margin: 22px 0 10px; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { padding: 14px; border-radius: var(--r); background: var(--card); border: 1px solid var(--line); }
.tile b { display: block; font-size: 26px; font-weight: 800; }
.tile span { font-size: 12px; color: var(--ink-dim); }

.heat { display: grid; gap: 3px; margin-top: 4px; }
.heat-row { display: grid; gap: 3px; grid-auto-flow: column; }
.cell { aspect-ratio: 1; border-radius: 4px; background: #161c24; font-size: 9px; color: #4b5a6b; display: grid; place-items: center; }
.cell.h0 { background: #2b1a1c; }
.cell.h1 { background: #4a2f22; }
.cell.h2 { background: #5c4a1e; }
.cell.h3 { background: #2e5334; }
.cell.h4 { background: #3ddc84; }
.cell.axis { background: none; color: var(--ink-dim); font-size: 10px; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ink-dim); margin-top: 8px; }
.legend i { width: 14px; height: 10px; border-radius: 3px; display: inline-block; }

.oprow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.oprow .sym { width: 34px; height: 34px; border-radius: 10px; background: var(--card); display: grid; place-items: center; font-size: 17px; }
.oprow .name { flex: 1; font-size: 15px; }
.oprow .val { font-size: 14px; color: var(--ink-dim); text-align: right; }
.oprow .val b { color: var(--ink); }

.toggles { display: flex; flex-direction: column; gap: 8px; }
.toggles label {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border-radius: var(--r);
  background: var(--card); border: 1px solid var(--line);
}
.toggles input { width: 22px; height: 22px; accent-color: var(--ok); flex: 0 0 22px; }
.toggles span { font-size: 15px; display: flex; flex-direction: column; }
.toggles em { font-style: normal; font-size: 12px; color: var(--ink-dim); margin-top: 3px; }

.note { color: var(--ink-dim); font-size: 12px; line-height: 1.5; }
.version { text-align: center; margin-top: 26px; opacity: .5; }

.tierline { display: flex; justify-content: space-between; font-size: 14px; padding: 10px 0; }
.tierline span { color: var(--ink-dim); }
.bar { height: 6px; border-radius: 99px; background: var(--card); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); }
