/* Theory Path. One stylesheet, no build step. */

:root {
  --paper: #f6f2ea;
  --card: #ffffff;
  --ink: #1f2530;
  --ink-soft: #5a6272;
  --line: #e3ddd1;
  --accent: #3949c6;
  --accent-soft: #e8eafc;
  --accent-ink: #ffffff;
  --right: #1f8a55;
  --right-soft: #e2f4ea;
  --wrong: #c9463d;
  --wrong-soft: #fbe6e3;
  --gold: #dc9a00;
  --radius: 16px;
  --tap: 52px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 19px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  max-width: 920px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  min-height: 100vh;
}

h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 4px; }
h2 { font-size: 1.25rem; line-height: 1.25; margin: 0 0 8px; }
h3 { font-size: 1.05rem; margin: 0 0 6px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
.soft { color: var(--ink-soft); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
.loading { color: var(--ink-soft); padding: 40px 0; text-align: center; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; min-height: var(--tap); }
.topbar .title { flex: 1; min-width: 0; }
.topbar .title h1 { font-size: 1.3rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title .soft { font-size: 0.86rem; }
.back {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--tap); height: var(--tap); border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-size: 1.3rem; text-decoration: none; cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 22px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--accent); }
.btn.danger { color: var(--wrong); }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn:focus-visible, .choice:focus-visible, .back:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.spread { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: grid; gap: 12px; }

/* Cards and panels */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px;
}
.panel.tint { background: var(--accent-soft); border-color: transparent; }
.banner { background: #fff6d6; border: 1px solid #ecd58a; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }

/* Home */
.streak { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; padding: 6px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); white-space: nowrap; }
.streak .flame { color: var(--gold); }
.todo { display: flex; align-items: center; gap: 14px; }
.todo .num { width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.todo .what { flex: 1; min-width: 0; }
.todo.done .num { background: var(--right-soft); color: var(--right); }
.footer { margin-top: 28px; text-align: center; font-size: 0.78rem; color: var(--ink-soft); }

/* Unit steps */
.steps { display: grid; gap: 10px; }
.step {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  min-height: 64px; padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; cursor: pointer; text-decoration: none;
}
.step .tick { width: 30px; height: 30px; flex: none; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 0.9rem; color: transparent; }
.step.done .tick { background: var(--right); border-color: var(--right); color: #fff; }
.step.next { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.step.locked { opacity: 0.5; cursor: default; }
.step .label { flex: 1; }
.step .label small { display: block; color: var(--ink-soft); }

/* Map */
.stage { margin-bottom: 22px; }
.stage > h2 { margin-bottom: 10px; }
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.unit {
  display: flex; align-items: center; gap: 12px; min-height: 68px; padding: 10px 14px;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--card);
  color: var(--ink); text-decoration: none; font: inherit; text-align: left; cursor: pointer;
}
.unit .n { width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--paper); color: var(--ink-soft); }
.unit .t { flex: 1; min-width: 0; line-height: 1.25; }
.unit.done .n { background: var(--right-soft); color: var(--right); }
.unit.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.unit.current .n { background: var(--accent); color: #fff; }
.unit.locked { opacity: 0.5; cursor: default; }
.unit.soon { border-style: dashed; opacity: 0.6; cursor: default; }
.stars { letter-spacing: 1px; white-space: nowrap; }
.star { color: var(--line); }
.star.on { color: var(--gold); }

/* Progress dots and bar */
.dots { display: flex; gap: 6px; justify-content: center; margin: 4px 0 14px; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--accent); }
.dot.right { background: var(--right); }
.dot.wrong { background: var(--wrong); }

/* Lesson */
.lesson { font-size: 1.12rem; }
.lesson .panel { padding: 22px; }
.fingers { display: flex; gap: 10px; align-items: flex-start; background: #fff6d6; border-radius: 12px; padding: 12px 14px; margin-top: 12px; font-size: 1rem; }
.fingers .tag { font-weight: 700; white-space: nowrap; color: #8a6200; }

/* Music */
.staff { display: flex; justify-content: center; align-items: center; min-height: 110px; margin: 6px 0 10px; overflow-x: auto; }
.staff svg { display: block; }
.snapshot { white-space: pre-wrap; font: 0.78rem/1.4 ui-monospace, Menlo, monospace; color: var(--ink-soft); margin: 6px 0 0; }
.music-row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.play {
  display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 8px 18px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--accent);
  font: inherit; font-weight: 600; cursor: pointer;
}
.play.playing { background: var(--accent-soft); }
.glyph { font-family: Bravura, serif; font-size: 3.2rem; line-height: 1.6; text-align: center; min-height: 100px; display: grid; place-items: center; }
.bigword { font-size: 2rem; font-weight: 700; text-align: center; padding: 18px 0; font-style: italic; }

/* Question card */
.question { max-width: 880px; margin: 0 auto; }
.prompt { font-size: 1.2rem; font-weight: 600; text-align: center; margin-bottom: 10px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choices.wide { grid-template-columns: 1fr; }
.choice {
  min-height: 64px; padding: 10px 14px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; display: grid; place-items: center; text-align: center;
}
.choice .staff { min-height: 90px; margin: 0; pointer-events: none; }
.choice.right { border-color: var(--right); background: var(--right-soft); }
.choice.wrong { border-color: var(--wrong); background: var(--wrong-soft); }
.choice[disabled] { cursor: default; color: var(--ink); opacity: 1; }
.choice.dim { opacity: 0.55; }
.feedback { margin-top: 14px; border-radius: var(--radius); padding: 14px 16px; }
.feedback.right { background: var(--right-soft); }
.feedback.wrong { background: var(--wrong-soft); }
.feedback h3 { margin: 0 0 4px; }
.feedback p { margin: 0; }
.flag { background: none; border: none; color: var(--ink-soft); font: inherit; font-size: 0.82rem; text-decoration: underline; cursor: pointer; padding: 10px; min-height: 48px; }

/* Build it */
.builder { user-select: none; -webkit-user-select: none; }
.builder .pad { position: relative; display: flex; justify-content: center; touch-action: manipulation; cursor: pointer; overflow-x: auto; }
.builder .tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0; }
.tool {
  min-width: var(--tap); min-height: var(--tap); padding: 6px 12px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 1.7rem; line-height: 1; cursor: pointer;
}
.tool.text { font-size: 0.95rem; font-weight: 600; }
.tool.on { border-color: var(--accent); background: var(--accent-soft); }
.tool[disabled] { opacity: 0.4; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.compare > div { background: var(--card); border-radius: 12px; padding: 8px; text-align: center; }
.compare .staff { min-height: 80px; }

/* Results */
.result { text-align: center; padding: 26px 18px; }
.result .score { font-size: 3rem; font-weight: 800; line-height: 1.1; }
.result .stars { font-size: 2.4rem; display: block; margin: 6px 0 10px; }

/* Grown-ups */
.hold { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.hold .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent-soft); z-index: 0; }
.hold span { position: relative; z-index: 1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 1.8rem; line-height: 1.1; }
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.list li { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table.plain { width: 100%; border-collapse: collapse; }
table.plain td, table.plain th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }

@media (max-width: 560px) {
  body { font-size: 17px; }
  .choices { grid-template-columns: 1fr; }
  .compare { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: no-preference) {
  .choice, .btn, .step, .unit { transition: background-color 0.15s, border-color 0.15s, transform 0.08s; }
  .choice:active:not([disabled]), .btn:active:not([disabled]) { transform: scale(0.98); }
}
