:root {
  --bg: #11131f;
  --panel: #1b1f33;
  --line: #2c3252;
  --ink: #f3f4fa;
  --muted: #9097b5;
  --left: #ff9a4d;
  --right: #55c8ff;
  --ok: #37d67a;
  --bad: #ff5470;
  --gold: #ffd84a;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  word-break: keep-all;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
small { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 500; }
p { margin: 0; }

#app {
  max-width: 720px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- shared pieces ---------- */
.btn {
  padding: 14px 22px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 1.05rem;
}
.btn.cta { background: var(--gold); border-color: var(--gold); color: #1a1500; }
.link { color: var(--muted); padding: 8px 12px; text-decoration: underline; text-underline-offset: 3px; }
.label { color: var(--muted); font-size: 0.85rem; letter-spacing: 0.04em; }
.best { color: var(--muted); }
.best b { color: var(--gold); }
.stat b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }

/* ---------- home / game over ---------- */
.home, .over {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}
.home .link { align-self: flex-end; }
.logo {
  margin: 0;
  font-size: clamp(5.5rem, 30vw, 11rem);
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: -0.05em;
  color: var(--gold);
}
.tag { font-size: 1.35rem; font-weight: 700; }
.tag2 { color: var(--muted); max-width: 30ch; margin-bottom: 14px; }
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; max-width: 440px; }
.chip { padding: 12px 4px; border-radius: 12px; background: var(--panel); border: 2px solid var(--line); font-weight: 700; }
.chip.on { border-color: var(--gold); color: var(--gold); }
.home .cta, .over .cta { width: 100%; max-width: 440px; font-size: 1.25rem; padding: 18px; margin-top: 8px; }
.final { font-size: clamp(3rem, 16vw, 6rem); font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; max-width: 440px; margin: 10px 0; }
.stats .stat { background: var(--panel); border-radius: 12px; padding: 12px 4px; }

/* ---------- play ---------- */
.play { display: flex; flex-direction: column; gap: 12px; }
.hud { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.lives { color: var(--bad); font-size: 1.5rem; letter-spacing: 0.1em; }
.timer { height: 6px; border-radius: 3px; background: var(--panel); overflow: hidden; }
.timer i { display: block; height: 100%; background: var(--gold); transform-origin: left; }
.prompt { text-align: center; font-size: 1.1rem; font-weight: 700; min-height: 2.6em; display: grid; place-items: center; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card {
  min-width: 0;
  height: clamp(190px, 36dvh, 340px);
  padding: 12px 8px;
  border-radius: 18px;
  background: var(--panel);
  border: 3px solid var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s;
}
.card.left { --accent: var(--left); }
.card.right { --accent: var(--right); }
.card:active { transform: scale(0.98); }
.cards.done .card { pointer-events: none; opacity: 0.55; }
.cards.done .card.ok { opacity: 1; border-color: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 35%, transparent); }
.cards.done .card.bad { opacity: 1; border-color: var(--bad); }

.content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3em;
  text-align: center;
  font-size: clamp(1.2rem, 5.2vw, 2.1rem);
  font-weight: 700;
  line-height: 1.25;
}
.content .big { display: block; }
.content .sub { display: block; font-size: 0.68em; font-weight: 600; color: var(--muted); }
.content .txt { display: block; font-size: 0.72em; line-height: 1.35; }
.reveal { font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.reveal:empty { display: none; }

.fig { display: block; width: min(100%, 24dvh); aspect-ratio: 1; fill: currentColor; color: var(--accent); }
.fig .mark { stroke: var(--bg); stroke-width: 1.4; }

/* ---------- math notation ---------- */
.math { font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif; font-size: 1.3em; font-weight: 500; }
.why .math { font-size: 1em; }
.rt { white-space: nowrap; font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif; }
.rad { border-top: 0.07em solid currentColor; padding: 0 0.12em 0 0.06em; }
.ri { font-size: 0.55em; vertical-align: 0.9em; margin-right: -0.35em; }
.fr { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1.15; margin: 0 0.1em; }
.fr > span:first-child { border-bottom: 0.07em solid currentColor; padding: 0 0.25em; }
sup, sub { font-size: 0.62em; line-height: 0; }

/* ---------- feedback ---------- */
.feedback { display: flex; flex-direction: column; gap: 12px; }
.verdict { text-align: center; font-size: 1.3rem; font-weight: 800; }
.verdict.ok { color: var(--ok); }
.verdict.ok b { color: var(--gold); margin-left: 6px; }
.verdict.bad { color: var(--bad); }
.verdict .up { margin-left: 10px; padding: 2px 10px; border-radius: 99px; background: var(--gold); color: #1a1500; font-size: 0.8rem; vertical-align: middle; }
.formula { display: flex; align-items: flex-start; justify-content: center; gap: 6px; flex-wrap: wrap; }
.formula i { color: var(--muted); font-style: normal; padding-top: 2px; }
.formula .f { text-align: center; min-width: 2.6em; }
.formula .f b { font-variant-numeric: tabular-nums; }
.why { background: var(--panel); border-left: 4px solid var(--gold); border-radius: 10px; padding: 12px 14px; line-height: 1.7; }
.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; }
.actions .cta { flex: 2; }
