/* TMC High Cut — design system v2
   Goal: disappear during study; surface only what drives high-cut results */

:root {
  /* Surfaces */
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --bg-card: #1c1c1e;
  --bg-input: #2c2c2e;
  --bg-press: #3a3a3c;
  --bg-header: rgba(0, 0, 0, 0.78);

  /* Borders */
  --border: #38383a;
  --border-subtle: #2c2c2e;
  --separator: rgba(84, 84, 88, 0.65);

  /* Text */
  --text: #ffffff;
  --text-body: #e5e5ea;
  --text-secondary: #8e8e93;
  --text-tertiary: #636366;

  /* Semantic (iOS dark-friendly) */
  --blue: #0a84ff;
  --blue-press: #0070e0;
  --green: #30d158;
  --green-soft: rgba(48, 209, 88, 0.14);
  --orange: #ff9f0a;
  --orange-soft: rgba(255, 159, 10, 0.14);
  --red: #ff453a;
  --red-soft: rgba(255, 69, 58, 0.14);
  --purple: #bf5af2;
  --cyan: #64d2ff;
  --yellow: #ffd60a;

  --focus-ring: 0 0 0 3px rgba(10, 132, 255, 0.45);

  /* Radii */
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius: 16px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --radius-full: 999px;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --text-xs: 11px;
  --text-sm: 13px;
  --text-md: 15px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 28px;
  --text-3xl: 40px;
  --text-4xl: 56px;
  --leading-tight: 1.15;
  --leading-snug: 1.35;
  --leading-body: 1.45;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --weight-heavy: 800;

  /* Elevation — hairlines over shadows on OLED */
  --shadow-card: none;
  --shadow-toast: 0 8px 28px rgba(0, 0, 0, 0.55);
  --shadow-sheet: 0 -8px 40px rgba(0, 0, 0, 0.45);

  /* Layout */
  --max-w: 428px;
  --nav-h: 56px;
  --header-h: 48px;
  --tap-min: 44px;
  --content-pad-x: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 100ms;
  --dur-med: 180ms;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #050505;
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
}

button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }

a { color: var(--blue); text-decoration: none; }

:focus { outline: none; }
:focus-visible {
  box-shadow: var(--focus-ring);
  border-radius: inherit;
}

/* ─── Shell ─── */
#app {
  max-width: var(--max-w);
  margin: 0 auto;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 0 1px var(--border-subtle);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: calc(8px + var(--safe-top)) var(--content-pad-x) 8px;
  min-height: calc(var(--header-h) + var(--safe-top));
  background: var(--bg-header);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--separator);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0a84ff, #64d2ff);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 14px;
}

.brand h1 {
  font-size: 16px;
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand p { display: none; } /* quieter chrome */

.header-stats {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  border: 1px solid var(--border-subtle);
  font-variant-numeric: tabular-nums;
}

.pill.fire { color: var(--orange); }

/* ─── Main ─── */
#main {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--content-pad-x) calc(var(--nav-h) + 18px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.screen {
  animation: fadeIn var(--dur-med) var(--ease-out);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .screen, .flashcard-inner, .toast, .modal-sheet { animation: none !important; transition: none !important; }
  .flashcard.flipped .flashcard-inner { transition: none; }
}

/* ─── Bottom nav ─── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-w);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(28, 28, 30, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--separator);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 50;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: var(--weight-medium);
  min-height: var(--tap-min);
  padding: 4px 2px;
  position: relative;
  border-radius: var(--radius-sm);
}

.nav-item .icon { font-size: 20px; line-height: 1; }
.nav-item.active { color: var(--blue); font-weight: var(--weight-semibold); }

.nav-badge {
  position: absolute;
  top: 2px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-full);
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  display: grid;
  place-items: center;
  line-height: 1;
}

/* Focus mode — study only */
body.focus-mode .bottom-nav,
body.focus-mode .app-header { display: none; }
body.focus-mode #main {
  padding: 12px var(--content-pad-x) calc(16px + var(--safe-bottom));
  max-width: var(--max-w);
  margin: 0 auto;
}

/* ─── Typography helpers ─── */
.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-heavy);
  letter-spacing: -0.03em;
  line-height: var(--leading-tight);
  margin-bottom: 4px;
}

.page-sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
  line-height: var(--leading-snug);
}

.section-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: var(--space-5) 0 var(--space-2);
}

.section-title:first-child { margin-top: 0; }

.muted { color: var(--text-secondary); }
.small { font-size: var(--text-sm); }
.tiny { font-size: var(--text-xs); }
.mono {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

.stem {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  color: var(--text);
  margin-bottom: var(--space-4);
}

/* ─── Layout ─── */
.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.gap-sm { gap: var(--space-2); }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }

/* ─── Cards ─── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  text-align: left;
  width: 100%;
}

.card.interactive,
button.card {
  cursor: pointer;
  transition: background var(--dur-fast), transform var(--dur-fast);
  color: inherit;
  font: inherit;
  display: block;
}
.card.interactive:active,
button.card:active {
  background: var(--bg-press);
  transform: scale(0.99);
}

.card.featured {
  border-radius: var(--radius-lg);
  border-color: rgba(10, 132, 255, 0.35);
  background: linear-gradient(180deg, rgba(10, 132, 255, 0.1) 0%, var(--bg-elevated) 48%);
  padding: var(--space-5) var(--space-4);
}

.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 14px 16px;
  width: 100%;
  text-align: left;
  min-height: var(--tap-min);
}
.list-row:has(.topic-accent) {
  align-items: stretch;
}
.list-row:has(.topic-accent) .meta,
.list-row:has(.topic-accent) .mono,
.list-row:has(.topic-accent) .chevron {
  align-self: center;
}
.list-row .meta { flex: 1; min-width: 0; }
.list-row .title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-md);
  line-height: 1.25;
}
.list-row .sub {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.3;
}
.chevron {
  color: var(--text-tertiary);
  font-size: 18px;
  font-weight: 300;
  flex-shrink: 0;
}

.topic-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
  background: rgba(10, 132, 255, 0.12);
}

.topic-accent {
  width: 3px;
  align-self: stretch;
  border-radius: 2px;
  flex-shrink: 0;
  margin: 2px 0;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: var(--weight-semibold);
  font-size: var(--text-md);
  transition: transform var(--dur-fast), opacity var(--dur-fast), background var(--dur-fast);
  border: 1px solid transparent;
  text-align: center;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:active:not(:disabled) { background: var(--blue-press); }
.btn-danger {
  background: transparent;
  border-color: rgba(255, 69, 58, 0.45);
  color: var(--red);
}
.btn-success { background: var(--green); color: #000; }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-block { width: 100%; }
.btn-sm {
  min-height: 36px;
  padding: 8px 12px;
  font-size: var(--text-sm);
  border-radius: 10px;
}
.btn-icon {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 18px;
  flex-shrink: 0;
}

/* Sticky session action */
.session-actions {
  position: sticky;
  bottom: 0;
  padding: 12px 0 calc(8px + var(--safe-bottom));
  margin-top: var(--space-4);
  background: linear-gradient(180deg, transparent 0%, var(--bg) 28%);
}

/* ─── Badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: rgba(10, 132, 255, 0.16); color: var(--blue); }
.badge-purple { background: rgba(191, 90, 242, 0.16); color: var(--purple); }
.badge-gray { background: rgba(142, 142, 147, 0.16); color: var(--text-secondary); }

/* ─── Progress ─── */
.progress-track {
  height: 6px;
  background: var(--border-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--blue);
  transition: width var(--dur-med) var(--ease-out);
}
.progress-fill.green { background: var(--green); }
.progress-fill.orange { background: var(--orange); }
.progress-fill.red { background: var(--red); }

.session-progress {
  height: 3px;
  width: 100%;
  background: var(--border-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 10px;
}

.stat-card {
  text-align: center;
  padding: 12px 6px;
}
.stat-card .label {
  font-size: 10px;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.stat-card .value {
  font-size: 22px;
  font-weight: var(--weight-heavy);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.readiness-num {
  font-size: var(--text-3xl);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.score-huge {
  font-size: var(--text-4xl);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ─── Forms ─── */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 48px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: var(--text-md);
  outline: none;
}
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus,
.field select:focus,
.field textarea:focus { border-color: var(--blue); }

/* ─── Quiz options ─── */
.option {
  width: 100%;
  text-align: left;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-height: 48px;
  padding: 14px;
  border-radius: 14px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.option:active:not(:disabled) {
  border-color: var(--blue);
  background: rgba(10, 132, 255, 0.08);
}
.option .letter {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
  flex-shrink: 0;
  margin-top: 0;
  color: var(--text-secondary);
}
.option.correct {
  background: var(--green-soft);
  border-color: var(--green);
}
.option.correct .letter {
  border-color: var(--green);
  color: var(--green);
  background: rgba(48, 209, 88, 0.15);
}
.option.incorrect {
  background: var(--red-soft);
  border-color: var(--red);
}
.option.incorrect .letter {
  border-color: var(--red);
  color: var(--red);
}
.option:disabled { cursor: default; }

.explain {
  margin-top: var(--space-3);
  padding: 14px 14px 14px 16px;
  border-radius: 14px;
  font-size: var(--text-sm);
  line-height: var(--leading-body);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--border);
}
.explain.ok { border-left-color: var(--green); }
.explain.bad { border-left-color: var(--red); }
.explain .status {
  font-weight: var(--weight-bold);
  font-size: var(--text-md);
  margin-bottom: 4px;
}
.explain.ok .status { color: var(--green); }
.explain.bad .status { color: var(--red); }
.explain .body { color: var(--text-body); }

/* ─── Session chrome ─── */
.session-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.session-chrome .meta {
  text-align: right;
  flex: 1;
  min-width: 0;
}
.session-chrome .count {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.session-chrome .label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Flashcard ─── */
.flashcard {
  perspective: 1000px;
  height: min(52vh, 320px);
  cursor: pointer;
  user-select: none;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.45s var(--ease-out);
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.flash-face.back { transform: rotateY(180deg); }
.flash-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
  font-weight: var(--weight-bold);
}
.flash-front-text {
  font-size: 22px;
  font-weight: var(--weight-bold);
  line-height: 1.25;
}
.flash-back-text {
  font-size: 16px;
  line-height: 1.45;
  color: var(--text-body);
}
.grade-row.disabled-grades {
  opacity: 0.35;
  pointer-events: none;
}

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  width: 100%;
  max-width: var(--max-w);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  border: 1px solid var(--border);
  border-bottom: none;
  box-shadow: var(--shadow-sheet);
  animation: sheetUp var(--dur-med) var(--ease-out);
}
@keyframes sheetUp {
  from { transform: translateY(20px); opacity: 0.7; }
  to { transform: none; opacity: 1; }
}
.modal-sheet h2 {
  font-size: var(--text-xl);
  font-weight: var(--weight-heavy);
  letter-spacing: -0.02em;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 16px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  max-width: min(320px, 90vw);
  box-shadow: var(--shadow-toast);
  animation: toastIn var(--dur-med) var(--ease-out);
}
body.focus-mode .toast {
  bottom: calc(20px + var(--safe-bottom));
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ─── Misc ─── */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
}
.empty .emoji { font-size: 36px; margin-bottom: 10px; }

.loading {
  min-height: 50vh;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  gap: 12px;
  text-align: center;
}

.hidden { display: none !important; }

.text-green { color: var(--green); }
.text-orange { color: var(--orange); }
.text-red { color: var(--red); }
.text-blue { color: var(--blue); }
.text-yellow { color: var(--yellow); }

.hr {
  height: 1px;
  background: var(--border-subtle);
  margin: 16px 0;
  border: none;
}

.link-quiet {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-sm);
  color: var(--blue);
  font-weight: var(--weight-semibold);
  padding: 8px 0;
  min-height: var(--tap-min);
  background: none;
  border: none;
  cursor: pointer;
}

.formula-card .name { font-weight: 700; color: var(--cyan); margin-bottom: 4px; }
.formula-card .eq {
  font-family: var(--font-mono);
  font-size: 14px;
  margin-bottom: 4px;
}
.formula-card .note { font-size: 12px; color: var(--text-secondary); }

.mastery-row { margin-bottom: 12px; }
.mastery-row .top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 5px;
}

.next-steps {
  text-align: left;
}

.hint-keys {
  font-size: 10px;
  color: var(--text-tertiary);
  text-align: center;
  margin-top: 8px;
}
