:root {
  --bg: #03110f;
  --glass: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.09);
  --border-soft: rgba(255, 255, 255, 0.16);
  --text: #ecfdf9;
  --text-muted: #8fb5ae;
  --accent: #2dd4bf;
  --accent-2: #38bdf8;
  --ok: #4ade80;
  --partial: #fbbf24;
  --error: #ff6b81;
  --radius: 20px;
  --radius-sm: 13px;
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overscroll-behavior-y: none;
}

/* ---- red atmosphere: aurora + a faint graph of y' = y with its tangent ---- */
.aurora-bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: var(--bg); }
.aurora-blob { position: absolute; border-radius: 50%; filter: blur(85px); opacity: 0.34; will-change: transform; }
.blob-1 {
  width: 60vh; height: 60vh; top: -20%; left: -14%;
  background: radial-gradient(circle, #2dd4bf 0%, transparent 70%);
  animation: drift1 32s ease-in-out infinite alternate;
}
.blob-2 {
  width: 52vh; height: 52vh; top: 34%; right: -24%;
  background: radial-gradient(circle, #b3123c 0%, transparent 70%);
  opacity: 0.4;
  animation: drift2 38s ease-in-out infinite alternate;
}
.blob-3 {
  width: 46vh; height: 46vh; bottom: -22%; left: 6%;
  background: radial-gradient(circle, #38bdf8 0%, transparent 70%);
  opacity: 0.16;
  animation: drift3 44s ease-in-out infinite alternate;
}
@keyframes drift1 { from { transform: translate(0,0); } to { transform: translate(8%,10%); } }
@keyframes drift2 { from { transform: translate(0,0); } to { transform: translate(-10%,8%); } }
@keyframes drift3 { from { transform: translate(0,0); } to { transform: translate(6%,-8%); } }

.graph-bg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  color: rgba(255, 255, 255, 0.055);
  opacity: 0.45;
}

.grain {
  position: absolute; inset: -10%; opacity: 0.035; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

#app {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  height: 100dvh; height: 100vh;
  max-width: 560px; margin: 0 auto;
}

.view-container {
  flex: 1; overflow-y: auto;
  padding: 30px 18px calc(116px + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

.view-header { margin-bottom: 22px; }
.view-title { font-family: var(--font-display); font-size: 25px; font-weight: 700; letter-spacing: -0.01em; }
.title-math {
  font-size: 40px; font-style: italic; letter-spacing: 0.01em; line-height: 1.05;
  background: linear-gradient(135deg, #fff 0%, #ccfbf1 40%, var(--accent-2) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.title-math .prime { color: var(--accent); -webkit-text-fill-color: var(--accent); padding: 0 1px; }
.view-subtitle { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.4; }

.section-title {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-muted); margin: 30px 0 14px; opacity: 0.85;
}

.glass, .packet-card, .flash-card, .summary-card, .global-stat-card, .stat-packet-row {
  background: var(--glass);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 12px 30px -18px rgba(0,0,0,0.7);
}

@keyframes riseIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.packet-card, .flash-card, .summary-card { animation: riseIn 0.4s cubic-bezier(.2,.7,.3,1) both; }

.sub-chip, .btn-packet-all, .btn-packet-errors, .btn-packet-partial, .btn-packet-review, .tier-chip, .nav-btn, .assess-btn, .btn-primary, .packet-card, .quick-start-btn {
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.sub-chip:active, .btn-packet-all:active, .btn-packet-errors:active, .btn-packet-partial:active, .btn-packet-review:active, .tier-chip:active, .nav-btn:active, .assess-btn:active, .btn-primary:active, .quick-start-btn:active {
  transform: scale(0.96);
}

/* ---- quick start ---- */
.quick-start-card {
  display: flex; align-items: center; gap: 14px;
  border-radius: 24px;
  padding: 18px 18px 18px 20px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, rgba(45,212,191,0.2), rgba(56,189,248,0.1));
  border: 1px solid rgba(255,255,255,0.15);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.09), 0 16px 36px -18px rgba(45,212,191,0.55);
  animation: riseIn 0.4s cubic-bezier(.2,.7,.3,1) both;
}
.quick-start-icon { font-size: 28px; }
.quick-start-info { flex: 1; min-width: 0; }
.quick-start-label { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.quick-start-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.quick-start-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #032420; border: none; border-radius: var(--radius-sm);
  padding: 12px 18px; font-size: 13px; font-weight: 700; font-family: var(--font-body);
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  box-shadow: 0 8px 20px -8px rgba(45,212,191,0.7);
}

/* ---- error summary ---- */
.error-summary {
  font-size: 12.5px; color: var(--error); font-weight: 600;
  padding: 4px 4px 14px;
}
.error-summary.ok { color: var(--ok); }

/* ---- packets ---- */
.packet-list { display: flex; flex-direction: column; gap: 12px; }
.packet-card { border-radius: var(--radius); padding: 16px; }
.packet-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 10px; }
.packet-title { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.packet-count { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.packet-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 8px; vertical-align: 1px;
  box-shadow: 0 0 10px currentColor;
}
.packet-title sup, .stat-packet-label sup { font-size: 0.7em; }

.mini-bar { display: flex; height: 7px; border-radius: 99px; overflow: hidden; background: rgba(255,255,255,0.07); }
.mini-bar-seg { height: 100%; }
.seg-ok { background: var(--ok); }
.seg-partial { background: var(--partial); }
.seg-error { background: var(--error); }
.seg-new { background: transparent; }

.packet-actions { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.btn-packet-all {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #032420; border: none; border-radius: var(--radius-sm);
  padding: 11px; font-size: 13px; font-weight: 700; font-family: var(--font-body); cursor: pointer;
  box-shadow: 0 8px 20px -10px rgba(45,212,191,0.7);
}
.sub-chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.sub-chip {
  flex: 1; min-width: 40px; background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: var(--radius-sm); padding: 9px 4px;
  font-size: 12px; font-weight: 700; cursor: pointer; font-family: var(--font-display);
}
.btn-packet-errors {
  background: rgba(255,107,129,0.14); border: 1px solid rgba(255,107,129,0.42);
  color: var(--error); border-radius: var(--radius-sm); padding: 10px;
  font-size: 12.5px; font-weight: 700; font-family: var(--font-body); cursor: pointer;
}
.btn-packet-partial {
  background: color-mix(in srgb, var(--partial) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--partial) 45%, transparent);
  color: var(--partial); border-radius: var(--radius-sm); padding: 10px;
  font-size: 12.5px; font-weight: 700; font-family: var(--font-body); cursor: pointer;
}
.btn-packet-review {
  background: rgba(255,255,255,0.05); border: 1px solid var(--border-soft);
  color: var(--text); border-radius: var(--radius-sm); padding: 10px;
  font-size: 12.5px; font-weight: 700; font-family: var(--font-body); cursor: pointer;
}
.tier-chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tier-chip {
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent);
  color: var(--ok); border-radius: var(--radius-sm); padding: 8px 11px;
  font-size: 12px; font-weight: 700; font-family: var(--font-body); cursor: pointer;
}

/* ---- session ---- */
.bottom-nav.hidden { display: none; }
.session-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 8px;
}
.session-exit {
  background: var(--glass); border: 1px solid var(--border); color: var(--text);
  border-radius: 99px; padding: 8px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: var(--font-body); white-space: nowrap;
}
.session-progress-label {
  font-size: 12px; color: var(--text-muted); font-weight: 600;
  min-width: 0; flex: 1; display: flex; justify-content: center; gap: 6px;
}
.spl-scope { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spl-count { flex-shrink: 0; white-space: nowrap; color: var(--text); }
.spl-count::before { content: "· "; color: var(--text-muted); }
.type-tag {
  font-size: 10.5px; font-weight: 700; padding: 5px 11px; border-radius: 99px;
  background: color-mix(in srgb, var(--tag-color) 20%, transparent);
  border: 1px solid color-mix(in srgb, var(--tag-color) 50%, transparent);
  color: var(--tag-color); white-space: nowrap;
}

.progress-bar-track { height: 5px; background: rgba(255,255,255,0.07); border-radius: 99px; margin-bottom: 22px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.3s ease; box-shadow: 0 0 12px rgba(45,212,191,0.7); }

.flash-card {
  position: relative;
  border-radius: 26px;
  padding: 34px 22px 26px;
  text-align: center;
  min-height: 320px;
  display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start;
  border-top: 1px solid rgba(45,212,191,0.35);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 18px 44px -22px rgba(45,212,191,0.45);
}
.flash-card.tappable { cursor: pointer; }
.q-text {
  font-family: var(--font-display); font-size: 21px; font-weight: 700; line-height: 1.38;
  overflow-wrap: anywhere;
}
.q-text sup, .a-text sup { font-size: 0.68em; line-height: 0; }
.reveal-stack { width: 100%; margin-top: 26px; display: flex; flex-direction: column; gap: 14px; }
.reveal-row {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  animation: riseIn 0.3s ease both;
}
.reveal-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent-2); margin-bottom: 8px; }
.a-text {
  text-align: left; font-size: 16px; line-height: 1.62; color: var(--text);
  overflow-wrap: anywhere;
  font-family: 'Inter', 'Cambria Math', 'STIX Two Math', system-ui, sans-serif;
}

.session-footer { margin-top: 22px; }
.session-tap-hint { text-align: center; font-size: 12.5px; color: var(--text-muted); }
.assess-row { display: flex; gap: 10px; }
.assess-btn {
  flex: 1; border: none; border-radius: var(--radius-sm); padding: 15px 8px;
  font-size: 14px; font-weight: 700; font-family: var(--font-body); cursor: pointer;
}
.assess-wrong { background: rgba(255,107,129,0.16); color: var(--error); border: 1px solid rgba(255,107,129,0.42); }
.assess-correct { background: rgba(74,222,128,0.16); color: var(--ok); border: 1px solid rgba(74,222,128,0.4); }

.summary-card { border-radius: 26px; padding: 32px 22px; text-align: center; }
.summary-pct { font-family: var(--font-display); font-size: 46px; font-weight: 700; }
.summary-sub { font-size: 13px; color: var(--text-muted); margin: 8px 0 22px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #032420; border: none; border-radius: var(--radius-sm);
  padding: 13px; font-size: 14px; font-weight: 700; font-family: var(--font-body); cursor: pointer;
}
.btn-full { width: 100%; }

/* ---- stats ---- */
.global-stat-grid { display: flex; gap: 10px; }
.global-stat-card { flex: 1; border-radius: var(--radius); padding: 16px; text-align: center; }
.global-stat-num { font-family: var(--font-display); font-size: 26px; font-weight: 700; }
.global-stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.stat-packet-list { display: flex; flex-direction: column; gap: 10px; }
.stat-packet-row { border-radius: var(--radius-sm); padding: 14px; }
.stat-packet-label { font-family: var(--font-display); font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.stat-packet-nums { font-size: 11px; color: var(--text-muted); margin-top: 8px; }

.btn-reset {
  display: block; width: 100%; margin-top: 30px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); border-radius: var(--radius-sm);
  padding: 12px; font-size: 12.5px; font-weight: 600; font-family: var(--font-body);
  cursor: pointer; transition: border-color 0.15s ease, color 0.15s ease;
}
.btn-reset:active { border-color: var(--error); color: var(--error); }

/* ---- floating bottom nav ---- */
.bottom-nav {
  position: absolute; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 16px; right: 16px;
  display: flex; background: rgba(20, 6, 11, 0.7); border: 1px solid var(--border-soft);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-radius: 22px; padding: 8px;
  box-shadow: 0 16px 40px -12px rgba(0,0,0,0.7);
}
.nav-btn {
  flex: 1; background: none; border: none; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px; cursor: pointer; border-radius: 16px; font-family: var(--font-body);
}
.nav-btn.active { color: var(--accent-2); background: linear-gradient(135deg, rgba(45,212,191,0.22), rgba(56,189,248,0.1)); }
.nav-icon { font-size: 19px; }
.nav-label { font-size: 9.5px; font-weight: 600; }

/* ---- courses (home) ---- */
.course-list { display: flex; flex-direction: column; gap: 14px; }
.course-card {
  display: flex; align-items: center; gap: 16px;
  width: 100%; text-align: left; font-family: var(--font-body); color: var(--text);
  padding: 18px; border-radius: 24px; cursor: pointer;
  background: linear-gradient(135deg, rgba(45,212,191,0.16), rgba(255,255,255,0.04));
  border: 1px solid var(--border-soft);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.07), 0 16px 36px -20px rgba(45,212,191,0.55);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  animation: riseIn 0.4s cubic-bezier(.2,.7,.3,1) both;
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.course-card:active { transform: scale(0.98); border-color: rgba(45,212,191,0.5); }
.course-num {
  flex: 0 0 56px; height: 56px; border-radius: 17px; display: grid; place-items: center;
  font-family: var(--font-display); font-size: 30px; font-weight: 700; font-style: italic;
  color: #032420; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px -10px rgba(45,212,191,0.85);
}
.course-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 9px; }
.course-title { font-family: var(--font-display); font-weight: 700; font-size: 19px; }
.course-sub { font-size: 12px; color: var(--text-muted); line-height: 1.35; margin-top: -5px; }
.course-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; font-size: 11.5px; color: var(--text-muted); }
.course-errors { color: var(--error); font-weight: 600; white-space: nowrap; }
.course-meta > span:first-child { white-space: nowrap; }
.course-arrow { font-size: 28px; color: var(--accent-2); flex-shrink: 0; line-height: 1; }
.back-btn { margin-bottom: 18px; }
.course-heading { font-size: 30px; }

/* ---- LaTeX (KaTeX) ---- */
.katex { font-size: 1.1em; }
.q-text .katex { font-size: 1.05em; }
.a-text .katex-display { margin: 0.7em 0; overflow-x: auto; overflow-y: hidden; }
.tex-fallback { font-family: ui-monospace, Consolas, monospace; font-size: 0.92em; }
