:root {
  --primary: #6C4CE0;
  --soft: #A78BFA;
  --light: #EDE7FF;
  --navy: #2B2350;
  --slate: #5B5575;
  --grayblue: #9990B5;
  --bg: #F6F4FF;
  --surface: #ffffff;
  --text: #241E40;
  --muted: #6B6486;
  --border: #e7e2f5;
  --success: #1F9D55;
  --success-bg: #e3f7ec;
  --danger: #E5484D;
  --danger-bg: #fdeaea;
  --c1: #6C4CE0; --c2: #FF7A59; --c3: #14B8A6; --c4: #FFB020;
  --c5: #FF5DA2; --c6: #3B82F6; --c7: #22C55E; --c8: #A855F7;
  --radius: 16px;
  --radius-sm: 11px;
}
[data-theme="dark"] {
  --bg: #17132b;
  --surface: #221c3d;
  --text: #efeaff;
  --muted: #a99fce;
  --border: #352c5a;
  --navy: #0f0c1f;
  --light: #2c2350;
  --success-bg: #16321f;
  --danger-bg: #3a1f22;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

#topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 12px;
}
[data-theme="dark"] #topbar { background: #11151f; }
#topbar-title { font-weight: 600; font-size: 16px; }
.icon-btn {
  background: transparent; border: none; color: #fff;
  font-size: 24px; width: 36px; height: 36px; cursor: pointer; border-radius: 8px;
}
.icon-btn:active { background: rgba(255,255,255,0.12); }
#back-home { visibility: hidden; }

#app { max-width: 760px; margin: 0 auto; padding: 1rem 1rem 4rem; }
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

h1 { font-size: 22px; line-height: 1.25; margin: 0 0 1rem; font-weight: 700; }
h2 { font-size: 19px; margin: 0 0 1rem; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 10px; font-weight: 600; color: var(--slate); }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--primary); font-weight: 600; margin: 0 0 4px; }
.muted { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; text-align: center; margin: -6px 0 12px; }
.error-text { color: var(--danger); font-size: 14px; }

/* Home */
.home-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 1.25rem; }
.mini-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 8px; text-align: center; }
.mini-stat .n { font-size: 19px; font-weight: 700; color: var(--navy); }
.mini-stat .l { font-size: 11px; color: var(--muted); }

.nav-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.nav-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 3px;
  min-height: 74px; color: var(--text); transition: transform 0.06s;
}
.nav-card:active { transform: scale(0.98); }
.nav-card .nc-title { font-weight: 700; font-size: 15px; }
.nav-card .nc-sub { font-size: 12px; color: var(--muted); }
.nav-card { border-left: 5px solid var(--c1); }
.nav-card:nth-of-type(2) { border-left-color: var(--c2); }
.nav-card:nth-of-type(3) { border-left-color: var(--c3); }
.nav-card:nth-of-type(4) { border-left-color: var(--c4); }
.nav-card:nth-of-type(5) { border-left-color: var(--c5); }
.nav-card:nth-of-type(6) { border-left-color: var(--c6); }
.nav-card:nth-of-type(7) { border-left-color: var(--c7); }
.nav-card:nth-of-type(8) { border-left-color: var(--c8); }
.nav-card:nth-of-type(9) { border-left-color: var(--c2); }
.nav-card:nth-of-type(10) { border-left-color: var(--c3); }
.primary-card {
  grid-column: 1 / -1; border-left: none; color: #fff;
  background: linear-gradient(120deg, var(--c1), var(--c8) 60%, var(--c5));
  border-color: transparent;
}
.primary-card .nc-title { font-size: 17px; }
.primary-card .nc-sub { color: rgba(255,255,255,0.9); }
.mini-stat { border-bottom: 3px solid var(--c1); }
.home-stats .mini-stat:nth-child(2) { border-bottom-color: var(--c3); }
.home-stats .mini-stat:nth-child(3) { border-bottom-color: var(--c4); }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
  width: 100%; border-radius: var(--radius-sm); padding: 14px; font-size: 15px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent; margin-top: 8px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--soft); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: 0.55; }

select, textarea, input {
  width: 100%; padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 15px; margin-bottom: 10px; font-family: inherit;
}
textarea { resize: vertical; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-top: 1rem; text-align: center; color: var(--muted); }

/* Practice runner */
#runner-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#runner-progress { font-size: 13px; color: var(--muted); font-weight: 600; }
.timer { font-size: 14px; font-weight: 700; color: var(--primary); }
.timer.warn { color: var(--danger); }
.passage, .dataset { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; font-size: 15px; max-height: 300px; overflow-y: auto; }
.dataset { font-family: ui-monospace, monospace; font-size: 13px; white-space: pre-wrap; }
.qcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; }
.qtype-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--primary); font-weight: 600; margin-bottom: 6px; }
.qprompt { font-weight: 600; font-size: 16px; margin-bottom: 14px; }
.choice {
  display: block; width: 100%; text-align: left; padding: 13px 14px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text); font-size: 15px; cursor: pointer;
}
.choice:active { border-color: var(--primary); }
.choice.correct { background: var(--success-bg); border-color: var(--success); }
.choice.wrong { background: var(--danger-bg); border-color: var(--danger); }
.choice:disabled { cursor: default; }

.feedback { margin-top: 14px; font-size: 14px; }
.fb-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px; background: var(--light); color: var(--navy); margin-bottom: 8px; }
.fb-section { margin: 10px 0; }
.fb-section .lab { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--grayblue); margin-bottom: 2px; }
.fb-es { background: var(--bg); border-left: 3px solid var(--soft); padding: 8px 10px; border-radius: 4px; }
details.analysis { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
details.analysis summary { font-weight: 600; font-size: 14px; cursor: pointer; color: var(--primary); }
details.analysis ul { padding-left: 18px; margin: 8px 0; }

/* Summary */
#practice-summary .sum-head { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.coach-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-top: 1rem; }
.coach-box .lab { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--grayblue); font-weight: 600; margin: 10px 0 2px; }

/* Flashcards */
#flash-overview .fc-summary { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 1rem; }
.flashcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem 1.25rem; min-height: 150px; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 17px; cursor: pointer; margin-bottom: 12px; }
.fc-stats { text-align: center; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.fc-grades { display: grid; grid-template-columns: repeat(4,1fr); gap: 6px; margin-bottom: 10px; }
.fc-grades button { padding: 12px 4px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.deck-list { margin-top: 1rem; }
.deck-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 6px; font-size: 13px; }

/* Dashboard */
.dash-cards { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; margin-bottom: 1.25rem; }
.dash-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.dash-card .n { font-size: 24px; font-weight: 700; color: var(--navy); }
.dash-card .l { font-size: 12px; color: var(--muted); }
.chart-block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.chart-block canvas { max-height: 240px; }
.chart-legend { margin-top: 10px; }
.leg-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; padding: 5px 0; border-top: 1px solid var(--border); }
.leg-row:first-child { border-top: none; }
.leg-left { display: flex; align-items: center; gap: 8px; }
.leg-dot { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.leg-val { font-weight: 700; }
.freq-pill { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px; margin-left: 6px; }
.freq-3 { background: #ffe1d6; color: #c0410b; }
.freq-2 { background: #fff3cf; color: #9a6b00; }
.freq-1 { background: #e7e2f5; color: #6B6486; }
#heatmap { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; }
.hm-cell { aspect-ratio: 1; border-radius: 3px; background: var(--border); }

/* Error log */
.elog-row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 6px; font-size: 13px; }
.elog-row .top { display: flex; justify-content: space-between; font-weight: 600; }

.setting-row { margin-bottom: 1rem; }
.setting-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }

@media (min-width: 620px) {
  .nav-grid { grid-template-columns: repeat(3,1fr); }
  .primary-card { grid-column: 1 / -1; }
  .dash-cards { grid-template-columns: repeat(4,1fr); }
}
