/* edge — dark, phone-first */

:root {
  --bg: #0b0e14;
  --panel: #141922;
  --panel-2: #1b2230;
  --border: #263041;
  --text: #e6edf3;
  --muted: #8b98a9;
  --green: #3fb950;
  --green-dim: #238636;
  --red: #f85149;
  --amber: #d29922;
  --blue: #58a6ff;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* manipulation: kills iOS double-tap-to-zoom and the 300ms tap delay —
   rapid consecutive keypad taps must never zoom */
html { touch-action: manipulation; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; }
.hidden { display: none !important; }
button {
  font: inherit; color: inherit; border: none; background: none; cursor: pointer;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

/* ---------- shared ---------- */

.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-weight: 600;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--green-dim); border-color: transparent; }
.btn.big { padding: 16px 22px; font-size: 17px; width: 100%; }
.btn.huge { padding: 22px; font-size: 24px; width: 100%; letter-spacing: 1px; }
.btn.small { padding: 8px 14px; font-size: 14px; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
.topbar-btn { font-size: 20px; padding: 6px 10px; color: var(--muted); }
.chip {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
}
.scroll-body { padding: 8px 16px 32px; overflow-y: auto; }
.muted { color: var(--muted); }

.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 100;
}

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px 20px 0 0; padding: 24px; width: 100%; max-width: 520px;
  display: flex; flex-direction: column; gap: 16px;
}
.setting-col { display: flex; flex-direction: column; gap: 8px; }
.setting-col small { color: var(--muted); display: block; margin-top: 2px; }
.setting-col input {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); padding: 12px; font-size: 16px;
}

/* ---------- home ---------- */

.home-wrap {
  display: flex; flex-direction: column; gap: 14px;
  padding: 48px 20px 32px; margin: auto 0; width: 100%;
}
.logo { font-size: 40px; margin: 0; text-align: center; }
.tagline { text-align: center; color: var(--muted); margin: 0 0 10px; }

.level-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.level-row { display: flex; justify-content: space-between; align-items: baseline; }
.level-title { font-weight: 700; font-size: 17px; }
.level-pnl { font-variant-numeric: tabular-nums; font-weight: 600; }
.level-pnl.pos { color: var(--green); }
.level-pnl.neg { color: var(--red); }
.xp-bar {
  height: 6px; background: var(--panel-2); border-radius: 999px;
  overflow: hidden; margin-top: 10px;
}
.xp-fill { height: 100%; background: var(--blue); width: 0%; transition: width .6s ease; }
.xp-label { color: var(--muted); font-size: 12px; margin-top: 6px; }

.daily-card {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; text-align: left;
}
.daily-card:active { transform: scale(0.98); }
.daily-card.done { opacity: 0.65; }
.daily-title { font-weight: 700; }
.daily-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.daily-streak { font-size: 20px; font-weight: 800; color: var(--amber); white-space: nowrap; }

.tip-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
}
.tip-label { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: .5px; }
.tip-text { font-size: 14px; margin-top: 6px; line-height: 1.45; }

.coach-banner {
  background: rgba(88,166,255,0.12); border: 1px solid rgba(88,166,255,0.4);
  color: var(--blue); border-radius: var(--radius); padding: 12px; font-weight: 600;
}
.home-links { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }

/* ---------- play ---------- */

.playbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.play-pnl { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 18px; }
.play-pnl.pos { color: var(--green); }
.play-pnl.neg { color: var(--red); }
.play-heat { font-size: 15px; font-weight: 700; color: var(--amber); }
.play-qnum { margin-left: auto; color: var(--muted); font-size: 14px; }

.timer-track { height: 5px; background: var(--panel-2); }
.timer-fill {
  height: 100%; background: var(--green); width: 100%;
  transition: width .1s linear;
}
.timer-fill.warn { background: var(--amber); }
.timer-fill.danger { background: var(--red); }

.play-body {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start; padding: 18px 16px 24px; gap: 12px;
}
.q-badges { display: flex; gap: 8px; min-height: 24px; }
.badge {
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.stretch { background: rgba(210,153,34,0.15); color: var(--amber); border-color: rgba(210,153,34,0.5); }
.q-prompt {
  font-size: 26px; font-weight: 700; text-align: center; line-height: 1.35;
  min-height: 70px; display: flex; align-items: center; white-space: pre-wrap;
}
.q-prompt.small { font-size: 19px; font-weight: 600; }

.answer-area { width: 100%; max-width: 380px; margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.answer-display {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  min-height: 54px; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; gap: 6px;
}
.answer-text:empty::before { content: "·"; color: var(--border); }
.answer-unit { color: var(--muted); font-size: 16px; font-weight: 600; }
.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.key {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  font-size: 22px; font-weight: 600; padding: 13px 0;
}
.key:active { background: var(--border); }
.key-dim { color: var(--muted); font-size: 18px; }
.submit-btn { font-size: 19px; letter-spacing: 1px; }

.mc-option {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 15px 16px; font-size: 16px; font-weight: 600; text-align: left; width: 100%;
}
.mc-option:active { background: var(--panel-2); }
#answer-mc { gap: 10px; }

/* feedback overlay */
.feedback {
  position: fixed; inset: 0; background: rgba(4,6,10,0.82);
  display: flex; align-items: center; justify-content: center; z-index: 40; padding: 20px;
}
.feedback-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 24px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px;
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.fb-result { font-size: 26px; font-weight: 800; text-align: center; }
.fb-result.pos { color: var(--green); }
.fb-result.neg { color: var(--red); }
.fb-result.baited { color: var(--amber); }
.fb-answer { text-align: center; font-size: 17px; }
.fb-answer b { font-variant-numeric: tabular-nums; }
.fb-expl {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-size: 14px; line-height: 1.5; color: var(--muted);
}
.fb-actions { display: flex; gap: 10px; align-items: center; }
.fb-btn {
  font-size: 20px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 14px;
}
.fb-btn.selected { border-color: var(--blue); background: rgba(88,166,255,0.15); }
.fb-actions .btn { flex: 1; }

/* ---------- recap ---------- */

.recap-wrap {
  display: flex; flex-direction: column; gap: 14px;
  padding: 48px 20px 32px; margin: auto 0;
}
.recap-headline { text-align: center; margin: 0; font-size: 22px; }
.recap-pnl {
  text-align: center; font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.recap-pnl.pos { color: var(--green); }
.recap-pnl.neg { color: var(--red); }
.recap-spark {
  width: 100%; height: 80px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.recap-stats { display: flex; justify-content: space-around; }
.recap-stat { text-align: center; }
.recap-stat .v { font-size: 20px; font-weight: 700; }
.recap-stat .l { font-size: 12px; color: var(--muted); }
.recap-note {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; font-size: 13px; line-height: 1.5;
}
.recap-note b { color: var(--green); }
.recap-note.bad b { color: var(--red); }
.recap-note .expl { color: var(--muted); display: block; margin-top: 4px; }

/* ---------- stats ---------- */

.stat-group {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
}
.stat-group-head { display: flex; justify-content: space-between; font-weight: 700; }
.mastery-track { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.mastery-fill { height: 100%; background: var(--blue); }
.skill-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 0;
  border-top: 1px solid var(--border); font-size: 13px;
}
.skill-row:first-of-type { border-top: none; margin-top: 8px; }
.skill-name { flex: 1; color: var(--muted); }
.skill-rating { font-weight: 700; font-variant-numeric: tabular-nums; }
.skill-spark { width: 70px; height: 20px; }
.pnl-chart { display: flex; align-items: flex-end; gap: 3px; height: 90px; padding: 12px 0; }
.pnl-bar { flex: 1; max-width: 22px; border-radius: 3px 3px 0 0; min-height: 2px; }
.pnl-bar.pos { background: var(--green-dim); }
.pnl-bar.neg { background: var(--red); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding-top: 8px; }
.cal-cell {
  aspect-ratio: 1; border-radius: 4px; background: var(--panel-2);
  font-size: 9px; color: var(--muted); display: flex; align-items: center; justify-content: center;
}
.cal-cell.done { background: var(--green-dim); color: white; }
.section-label { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: .5px; margin: 16px 0 6px; }

/* ---------- lesson / coach ---------- */

.lesson-body { line-height: 1.6; font-size: 15px; }
.lesson-body h1, .lesson-body h2, .lesson-body h3 { line-height: 1.3; }
.lesson-body code {
  background: var(--panel-2); padding: 2px 6px; border-radius: 6px; font-size: 13px;
}
.lesson-body pre {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; overflow-x: auto;
}
.lesson-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.changes-list { color: var(--muted); font-size: 13px; }
