/* ===================================================================
   Fluency Compass — design tokens
   =================================================================== */

:root {
  --bg: #ECEEEA;
  --surface: #FFFFFF;
  --surface-2: #F5F6F1;
  --surface-3: #E9EBE4;
  --text: #172029;
  --text-muted: #57626C;
  --text-faint: #8A9399;
  --brass: #8C6A1F;
  --brass-strong: #6E5417;
  --brass-tint: #F3E7C9;
  --teal: #246E64;
  --teal-tint: #DCEEEA;
  --line: rgba(23, 32, 41, 0.14);
  --line-soft: rgba(23, 32, 41, 0.08);
  --success: #3C8A52;
  --success-tint: #DFF0E1;
  --warning: #A8701A;
  --warning-tint: #F5E8D2;
  --critical: #AC3A2C;
  --critical-tint: #F6DFDB;
  --shadow: rgba(23, 32, 41, 0.12);

  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --rail-w: 232px;
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D131B;
    --surface: #151F2A;
    --surface-2: #1A2531;
    --surface-3: #202C39;
    --text: #E9E6DA;
    --text-muted: #97A3AD;
    --text-faint: #647079;
    --brass: #D9B15C;
    --brass-strong: #EFCB7A;
    --brass-tint: rgba(217, 177, 92, 0.14);
    --teal: #5FB3A6;
    --teal-tint: rgba(95, 179, 166, 0.14);
    --line: rgba(233, 230, 218, 0.14);
    --line-soft: rgba(233, 230, 218, 0.08);
    --success: #7BC98C;
    --success-tint: rgba(123, 201, 140, 0.14);
    --warning: #E0AE55;
    --warning-tint: rgba(224, 174, 85, 0.14);
    --critical: #E37862;
    --critical-tint: rgba(227, 120, 98, 0.14);
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --bg: #0D131B;
  --surface: #151F2A;
  --surface-2: #1A2531;
  --surface-3: #202C39;
  --text: #E9E6DA;
  --text-muted: #97A3AD;
  --text-faint: #647079;
  --brass: #D9B15C;
  --brass-strong: #EFCB7A;
  --brass-tint: rgba(217, 177, 92, 0.14);
  --teal: #5FB3A6;
  --teal-tint: rgba(95, 179, 166, 0.14);
  --line: rgba(233, 230, 218, 0.14);
  --line-soft: rgba(233, 230, 218, 0.08);
  --success: #7BC98C;
  --success-tint: rgba(123, 201, 140, 0.14);
  --warning: #E0AE55;
  --warning-tint: rgba(224, 174, 85, 0.14);
  --critical: #E37862;
  --critical-tint: rgba(227, 120, 98, 0.14);
  --shadow: rgba(0, 0, 0, 0.4);
}

/* ===================================================================
   Reset / base
   =================================================================== */

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; text-wrap: balance; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--teal); }
::selection { background: var(--brass-tint); color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: 4px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0 0 6px;
}

code {
  font-family: var(--font-mono);
  background: var(--surface-3);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

/* ===================================================================
   Shell / rail
   =================================================================== */

.app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 22px 16px 16px;
  gap: 20px;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}
.brand-mark { width: 30px; height: 30px; color: var(--brass); flex-shrink: 0; }
.brand-needle { animation: needle-settle 900ms cubic-bezier(.2,1.4,.4,1) both; transform-origin: 50px 50px; }
@keyframes needle-settle { from { transform: rotate(-35deg); } to { transform: rotate(0deg); } }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 16.5px; }
.brand-sub { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.03em; }

.rail-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; text-align: left;
  padding: 10px 12px; border-radius: var(--radius-s);
  color: var(--text-muted); font-weight: 500; font-size: 14px;
  transition: background 120ms ease, color 120ms ease;
}
.nav-icon { color: var(--brass); font-size: 13px; width: 16px; text-align: center; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--brass-tint); color: var(--text); font-weight: 600; }

.rail-rank {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 12px 14px;
}
.rank-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.rank-title { font-family: var(--font-display); font-weight: 700; font-size: 14.5px; }
.rank-xp { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.xp-track { height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.xp-fill { height: 100%; background: linear-gradient(90deg, var(--teal), var(--brass)); border-radius: 4px; transition: width 500ms cubic-bezier(.2,.8,.2,1); }

.theme-toggle {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-s); padding: 8px; align-self: flex-start;
  color: var(--text-muted); display: flex;
}
.theme-toggle:hover { color: var(--brass); }

.rail-toggle { display: none; }
.rail-scrim { display: none; }

/* ===================================================================
   Stage / views
   =================================================================== */

.stage { padding: 40px 44px 80px; min-width: 0; }
.view { display: none; max-width: 980px; margin: 0 auto; animation: view-in 320ms ease both; }
.view.is-active { display: block; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head { margin-bottom: 28px; }
.view-head h1 { font-size: clamp(26px, 3vw, 34px); margin-bottom: 8px; }
.lede { color: var(--text-muted); max-width: 62ch; font-size: 15px; }

/* ===================================================================
   Panels / cards
   =================================================================== */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-head h2 { font-size: 17px; }
.panel-note { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); letter-spacing: 0.02em; }

.btn {
  border-radius: 999px; border: 1px solid transparent; padding: 10px 20px;
  font-weight: 600; font-size: 13.5px; display: inline-flex; align-items: center; gap: 8px;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--text); color: var(--surface); }
.btn-primary:hover { box-shadow: 0 4px 14px var(--shadow); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--brass); color: var(--brass); }
.btn-small { padding: 6px 14px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ===================================================================
   Bearing view
   =================================================================== */

.bearing-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 20px;
}
.compass-panel, .gauges-panel { grid-column: span 1; }
.next-panel, .badges-panel, .streak-panel, .course-panel { grid-column: 1 / -1; }

@media (min-width: 880px) {
  .bearing-grid { grid-template-columns: 1.05fr 0.6fr 0.6fr; }
  .compass-panel { grid-row: 1 / 3; }
  .gauges-panel { grid-column: 2 / 4; }
  .next-panel { grid-column: 2 / 3; }
  .streak-panel { grid-column: 3 / 4; }
  .course-panel { grid-column: 1 / -1; }
  .badges-panel { grid-column: 1 / -1; }
}

.course-panel .xp-track { height: 8px; margin-bottom: 14px; }
.module-pips { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.module-pip {
  border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface-2);
  padding: 8px 10px; display: flex; flex-direction: column; gap: 2px;
}
.module-pip.is-partial { border-color: var(--brass); background: var(--brass-tint); }
.module-pip.is-complete { border-color: var(--success); background: var(--success-tint); }
.mp-name { font-size: 11.5px; font-weight: 600; }
.mp-count { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.compass-panel { display: flex; flex-direction: column; align-items: center; text-align: center; }
#compass-canvas { max-width: 100%; height: auto; margin: 6px 0 10px; }
.compass-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; font-size: 12.5px; }
.compass-legend li { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.compass-legend .swatch { width: 9px; height: 9px; border-radius: 2px; }

.gauges { display: flex; flex-direction: column; gap: 14px; }
.gauge-row { display: grid; grid-template-columns: 100px 1fr 30px; align-items: center; gap: 12px; }
.gauge-label { font-weight: 600; font-size: 13px; }
.gauge-track { height: 10px; border-radius: 6px; background: var(--surface-3); position: relative; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 6px; transition: width 500ms ease; }
.gauge-value { font-family: var(--font-mono); font-size: 12px; text-align: right; color: var(--text-muted); }
.gauge-hint { color: var(--text-faint); font-size: 12.5px; margin-top: 6px; }

.next-panel p { color: var(--text-muted); margin-bottom: 14px; font-size: 14px; }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.badge {
  border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px 10px;
  text-align: center; background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.badge-icon { font-size: 18px; color: var(--text-faint); }
.badge-name { font-size: 11.5px; font-weight: 600; line-height: 1.25; }
.badge.is-unlocked { background: var(--brass-tint); border-color: color-mix(in srgb, var(--brass) 40%, transparent); }
.badge.is-unlocked .badge-icon { color: var(--brass); }

.streak-readout { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 8px; }
.streak-number { font-family: var(--font-display); font-size: 42px; font-weight: 700; color: var(--brass); }
.streak-label { color: var(--text-muted); font-size: 13px; }

/* ===================================================================
   Assessment view
   =================================================================== */

.d-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 20px; }

.d-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.d-card-head { display: flex; align-items: center; gap: 10px; }
.d-glyph { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; flex-shrink: 0; }
.d-card h3 { font-size: 16px; }
.d-def { color: var(--text-muted); font-size: 13.5px; }

.level-toggle { display: flex; gap: 6px; }
.level-btn {
  flex: 1; padding: 8px 6px; border-radius: var(--radius-s); border: 1px solid var(--line);
  background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-align: center; transition: all 120ms ease;
}
.level-btn.is-selected { background: var(--text); color: var(--surface); border-color: var(--text); }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  font-weight: 400; font-size: 13.5px; color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface-2);
  padding: 8px 10px; resize: vertical;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brass); outline: none; background: var(--surface); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.ways-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 16px; }
.way-card { border: 1px solid var(--line); border-radius: var(--radius-m); padding: 14px; background: var(--surface-2); }
.way-card h4 { font-size: 14px; margin-bottom: 4px; }
.way-card p { color: var(--text-muted); font-size: 12.5px; margin-bottom: 10px; }
.way-slider { width: 100%; accent-color: var(--brass); }
.way-slider-labels { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-faint); font-family: var(--font-mono); margin-top: 2px; }

.ways-reflection { display: flex; gap: 16px; flex-wrap: wrap; }
.ways-reflection .field { flex: 1; min-width: 220px; }

.save-bar { display: flex; align-items: center; gap: 14px; margin: 24px 0; }
.save-note { color: var(--success); font-size: 13px; font-weight: 600; opacity: 0; transition: opacity 200ms ease; }
.save-note.is-visible { opacity: 1; }

/* ===================================================================
   Plan view
   =================================================================== */

.priority-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.priority-option {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px; border-radius: var(--radius-m);
  border: 1px solid var(--line); cursor: pointer; background: var(--surface-2);
}
.priority-option.is-selected { background: var(--teal-tint); border-color: var(--teal); }
.priority-option input { margin-top: 3px; accent-color: var(--teal); }
.priority-option .po-title { font-weight: 600; font-size: 13.5px; }
.priority-option .po-level { font-size: 11.5px; color: var(--text-muted); font-family: var(--font-mono); }

.quest-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; margin-bottom: 20px; }
.field-wide { grid-column: span 2; }
.field-full { grid-column: 1 / -1; }
.quest-form .btn { grid-column: 1 / -1; justify-self: start; }

.quest-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.quest-item { display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px 14px; background: var(--surface-2); }
.quest-item.is-done { opacity: 0.6; }
.quest-check { flex-shrink: 0; margin-top: 3px; width: 18px; height: 18px; accent-color: var(--success); }
.quest-body { flex: 1; min-width: 0; }
.quest-activity { font-weight: 600; font-size: 13.5px; }
.quest-item.is-done .quest-activity { text-decoration: line-through; }
.quest-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.quest-tag { font-family: var(--font-mono); background: var(--surface-3); padding: 1px 7px; border-radius: 5px; }
.quest-del { background: none; border: none; color: var(--text-faint); font-size: 16px; flex-shrink: 0; line-height: 1; padding: 4px; }
.quest-del:hover { color: var(--critical); }
.quest-empty { color: var(--text-faint); font-size: 13px; padding: 10px 0; }

/* ===================================================================
   Logbook view
   =================================================================== */

.template-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; }
.template-form .btn { grid-column: 1 / -1; justify-self: start; margin-top: 4px; }

.library-toolbar { display: flex; gap: 10px; align-items: center; margin: 22px 0 14px; flex-wrap: wrap; }
#library-search { flex: 1; min-width: 200px; border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px; background: var(--surface); }
.tag-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 12px; color: var(--text-muted); }
.tag-chip.is-active { background: var(--teal); border-color: var(--teal); color: white; }

.library-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.tpl-card { border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); padding: 18px 20px; }
.tpl-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.tpl-task { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.tpl-tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tpl-tag { font-family: var(--font-mono); font-size: 10.5px; background: var(--brass-tint); color: var(--brass-strong); padding: 2px 8px; border-radius: 5px; }
.tpl-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 6px 10px; font-size: 12px; color: var(--text-muted); }
.icon-btn:hover { color: var(--brass); border-color: var(--brass); }
.tpl-template { font-family: var(--font-mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--radius-s); padding: 10px 12px; white-space: pre-wrap; margin-bottom: 8px; }
.tpl-template .ph { color: var(--teal); font-weight: 600; }
.tpl-notes { font-size: 13px; color: var(--text-muted); }
.tpl-test { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 12px; }
.tpl-test-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin-bottom: 10px; }
.tpl-test-fields input { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 7px 9px; background: var(--surface-2); font-size: 12.5px; }
.tpl-test-out { margin-top: 10px; background: var(--surface-2); border-radius: var(--radius-s); padding: 10px 12px; font-size: 13px; white-space: pre-wrap; border: 1px solid var(--line-soft); }

/* ===================================================================
   Arcade
   =================================================================== */

.arcade-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.arcade-card {
  text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: 20px; display: flex; flex-direction: column; gap: 8px; transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
}
.arcade-card:hover { transform: translateY(-3px); box-shadow: 0 10px 24px var(--shadow); border-color: var(--brass); }
.arcade-card-icon { font-size: 20px; color: var(--brass); }
.arcade-card h3 { font-size: 16.5px; }
.arcade-card p { color: var(--text-muted); font-size: 13px; }
.arcade-card-tag { font-family: var(--font-mono); font-size: 10.5px; color: var(--teal); letter-spacing: 0.03em; margin-top: auto; padding-top: 6px; }

.game-stage { max-width: 100%; }
.back-to-arcade { margin-bottom: 16px; }
.game-head { margin-bottom: 16px; }
.game-head h2 { font-size: 20px; margin-bottom: 6px; }
.game-head p { color: var(--text-muted); font-size: 13.5px; }

.mode-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.mode-tab { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 16px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.mode-tab.is-active { background: var(--text); color: var(--surface); border-color: var(--text); }

.privacy-note { display: flex; gap: 8px; align-items: flex-start; background: var(--teal-tint); border: 1px solid color-mix(in srgb, var(--teal) 35%, transparent); border-radius: var(--radius-m); padding: 10px 14px; font-size: 12.5px; color: var(--text); margin-bottom: 16px; }

/* Chat component */
.chat-panel { border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface-2); display: flex; flex-direction: column; height: 420px; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 82%; padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; }
.chat-msg.role-assistant { background: var(--surface); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg.role-user { background: var(--text); color: var(--surface); align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg.role-system { align-self: center; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); background: none; text-transform: uppercase; letter-spacing: 0.05em; }
.chat-msg.role-error { background: var(--critical-tint); color: var(--critical); align-self: center; border-radius: var(--radius-s); }
.chat-typing { align-self: flex-start; display: flex; gap: 4px; padding: 10px 13px; }
.chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); animation: chat-bounce 1.1s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }
.chat-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-input-row input { flex: 1; border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px; background: var(--surface); }
.chat-input-row button { flex-shrink: 0; }
.chat-toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

/* Description Dojo */
.dojo-brief { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 14px 16px; margin-bottom: 14px; font-size: 13.5px; }
.dojo-brief strong { color: var(--brass-strong); }
.dojo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .dojo-grid { grid-template-columns: 1fr; } }
.dojo-col textarea { width: 100%; min-height: 130px; border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px; background: var(--surface-2); font-size: 13.5px; }
.dojo-out { min-height: 130px; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--radius-s); padding: 10px 12px; font-size: 13.5px; white-space: pre-wrap; }
.dojo-actions { display: flex; gap: 10px; margin-top: 10px; }

/* Gauntlet */
.gauntlet-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 18px; margin-bottom: 14px; }
.gauntlet-task { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.gauntlet-passage { font-size: 14px; margin-bottom: 14px; }
.category-picker { display: flex; gap: 8px; margin-bottom: 12px; }
.category-btn { flex: 1; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-s); padding: 10px; font-size: 12.5px; font-weight: 600; text-align: center; }
.category-btn.is-selected { border-color: var(--teal); background: var(--teal-tint); }
.category-btn.is-correct { border-color: var(--success); background: var(--success-tint); }
.category-btn.is-wrong { border-color: var(--critical); background: var(--critical-tint); }
.gauntlet-reveal { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 13px; }
.gauntlet-reveal .flaw { color: var(--critical); font-weight: 600; margin-bottom: 6px; }
.gauntlet-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
.pip-row { display: flex; gap: 5px; }
.pip { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.pip.is-current { background: var(--brass); }
.pip.is-done { background: var(--teal); }

/* Word theme sort */
.themesort-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
@media (max-width: 560px) { .themesort-grid { grid-template-columns: repeat(2, 1fr); } }
.ts-word { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-s); padding: 14px 6px; text-align: center; font-weight: 600; font-size: 12px; letter-spacing: 0.02em; }
.ts-word.is-selected { border-color: var(--brass); background: var(--brass-tint); }
.ts-word.is-solved-0 { background: var(--teal-tint); border-color: var(--teal); }
.ts-word.is-solved-1 { background: var(--brass-tint); border-color: var(--brass); }
.ts-word.is-solved-2 { background: var(--success-tint); border-color: var(--success); }
.ts-word.is-solved-3 { background: var(--critical-tint); border-color: var(--critical); }
.ts-solved-row { display: flex; justify-content: space-between; align-items: center; border-radius: var(--radius-s); padding: 10px 14px; margin-bottom: 6px; font-size: 12.5px; font-weight: 600; }
.ts-mistakes { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); margin-left: 12px; }

/* Twenty Q quick buttons */
.qbtn-row { display: flex; gap: 8px; margin-top: 4px; }

/* Toasts */
.toast-rack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 999; }
.toast {
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: var(--radius-m);
  font-size: 13px; font-weight: 500; box-shadow: 0 8px 24px var(--shadow);
  animation: toast-in 220ms cubic-bezier(.2,.8,.2,1) both;
  display: flex; align-items: center; gap: 8px;
}
.toast .toast-xp { font-family: var(--font-mono); color: var(--brass-strong); background: var(--brass-tint); padding: 1px 7px; border-radius: 5px; font-size: 11.5px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast.is-leaving { animation: toast-out 200ms ease both; }
@keyframes toast-out { to { opacity: 0; transform: translateX(8px); } }

/* ===================================================================
   Course — index
   =================================================================== */

.course-hero { padding: 20px 24px; }
.course-hero-top { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.course-hero-top h2 { font-size: 18px; margin-bottom: 2px; }
.course-hero-track { height: 8px; }
.course-done-chip {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--success);
  background: var(--success-tint); padding: 6px 14px; border-radius: 999px;
}

.module-list { display: flex; flex-direction: column; gap: 16px; }
.module-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); overflow: hidden; }
.module-card.is-complete { border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.module-head { display: flex; align-items: center; gap: 14px; padding: 18px 22px; border-bottom: 1px solid var(--line-soft); }
.module-num {
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--brass-tint); color: var(--brass-strong);
}
.module-card.is-complete .module-num { background: var(--success-tint); color: var(--success); }
.module-title { flex: 1; min-width: 0; }
.module-title h3 { font-size: 16.5px; }
.module-title p { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.module-count {
  font-family: var(--font-mono); font-size: 12px; color: var(--text-muted);
  font-variant-numeric: tabular-nums; flex-shrink: 0;
}
.module-count.is-complete { color: var(--success); font-weight: 600; }

.lesson-list { list-style: none; margin: 0; padding: 6px; }
.lesson-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px;
  border-radius: var(--radius-s); cursor: pointer; transition: background 120ms ease;
}
.lesson-row:hover { background: var(--surface-2); }
.lesson-check {
  width: 20px; height: 20px; flex-shrink: 0; border-radius: 50%;
  border: 1.5px solid var(--line); display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--surface);
}
.lesson-row.is-done .lesson-check { background: var(--success); border-color: var(--success); }
.lesson-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lesson-title { font-weight: 600; font-size: 13.5px; }
.lesson-row.is-done .lesson-title { color: var(--text-muted); }
.lesson-sub { font-size: 12px; color: var(--text-faint); }
.lesson-type {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--teal); background: var(--teal-tint); padding: 2px 8px; border-radius: 5px; flex-shrink: 0;
}

/* ===================================================================
   Course — lesson detail
   =================================================================== */

.lesson-view { margin-top: 16px; }
.lesson-head { margin-bottom: 20px; }
.lesson-head h2 { font-size: clamp(22px, 2.6vw, 28px); margin-bottom: 4px; }
.lesson-subtitle { color: var(--text-muted); font-size: 14.5px; }

.lesson-body { max-width: 68ch; display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; }
.lesson-body p { font-size: 15px; line-height: 1.65; }
.lesson-body strong { color: var(--brass-strong); font-weight: 600; }

.key-points {
  background: var(--surface-2); border-left: 3px solid var(--brass);
  border-radius: 0 var(--radius-m) var(--radius-m) 0; padding: 16px 20px; margin-bottom: 26px;
}
.key-points h4 {
  font-family: var(--font-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--brass-strong); font-weight: 600; margin-bottom: 8px;
}
.key-points ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; }
.key-points li { font-size: 13.5px; color: var(--text); }

.challenge {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: 22px 24px; margin-bottom: 20px;
}
.challenge-head { margin-bottom: 18px; }
.challenge-tag {
  display: inline-block; font-family: var(--font-mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--surface); background: var(--text);
  padding: 3px 9px; border-radius: 5px; margin-bottom: 8px;
}
.challenge-head p { color: var(--text-muted); font-size: 13.5px; }
.challenge-actions { display: flex; align-items: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.challenge-status { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

.lesson-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* quiz */
.quiz-q { padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--line-soft); }
.quiz-q:last-of-type { border-bottom: none; margin-bottom: 0; }
.quiz-prompt { font-weight: 600; font-size: 14px; margin-bottom: 10px; display: flex; gap: 10px; }
.quiz-num {
  font-family: var(--font-mono); font-size: 11px; color: var(--brass); flex-shrink: 0;
  border: 1px solid var(--brass); border-radius: 50%; width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center; margin-top: 1px;
}
.quiz-options { display: flex; flex-direction: column; gap: 7px; }
.quiz-option {
  text-align: left; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: var(--radius-s); padding: 10px 14px; font-size: 13.5px;
  transition: border-color 120ms ease, background 120ms ease;
}
.quiz-option:not(:disabled):hover { border-color: var(--brass); }
.quiz-option.is-picked { border-color: var(--teal); background: var(--teal-tint); font-weight: 600; }
.quiz-option.is-correct { border-color: var(--success); background: var(--success-tint); font-weight: 600; }
.quiz-option.is-wrong { border-color: var(--critical); background: var(--critical-tint); }
.quiz-option:disabled { cursor: default; }
.quiz-why { font-size: 13px; margin-top: 10px; padding: 10px 14px; border-radius: var(--radius-s); line-height: 1.5; }
.quiz-why.is-right { background: var(--success-tint); color: var(--text); }
.quiz-why.is-wrong { background: var(--warning-tint); color: var(--text); }

/* sort */
.sort-list { display: flex; flex-direction: column; gap: 14px; }
.sort-item { border: 1px solid var(--line); border-radius: var(--radius-m); padding: 14px 16px; background: var(--surface-2); }
.sort-item.is-right { border-color: color-mix(in srgb, var(--success) 50%, transparent); }
.sort-item.is-wrong { border-color: color-mix(in srgb, var(--critical) 50%, transparent); }
.sort-text { font-size: 13.5px; margin-bottom: 10px; }
.sort-buckets { display: flex; gap: 7px; flex-wrap: wrap; }
.sort-bucket {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; font-size: 12.5px; font-weight: 600; color: var(--text-muted);
}
.sort-bucket:not(:disabled):hover { border-color: var(--brass); color: var(--brass); }
.sort-bucket.is-picked { background: var(--teal); border-color: var(--teal); color: #fff; }
.sort-bucket.is-correct { background: var(--success-tint); border-color: var(--success); color: var(--success); }
.sort-bucket.is-wrong { background: var(--critical-tint); border-color: var(--critical); color: var(--critical); }
.sort-why { font-size: 12.5px; color: var(--text-muted); margin-top: 10px; line-height: 1.5; }

/* prompt grading */
.grade-card { margin-top: 18px; border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px 20px; background: var(--surface-2); }
.grade-score { display: flex; align-items: baseline; gap: 8px; margin-bottom: 14px; }
.grade-num { font-family: var(--font-display); font-size: 32px; font-weight: 700; color: var(--brass); }
.grade-of { font-size: 13px; color: var(--text-muted); }
.grade-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.grade-item { display: flex; gap: 10px; font-size: 13px; align-items: flex-start; }
.grade-mark {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 12px; font-weight: 700;
}
.verdict-met .grade-mark { background: var(--success-tint); color: var(--success); }
.verdict-partial .grade-mark { background: var(--warning-tint); color: var(--warning); }
.verdict-missed .grade-mark { background: var(--critical-tint); color: var(--critical); }
.grade-note { color: var(--text-muted); font-size: 12.5px; }
.grade-feedback {
  margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line);
  font-size: 13.5px; line-height: 1.55;
}

/* drill */
.drill-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 18px; }
.drill-instruction { font-size: 13.5px; line-height: 1.6; }

/* reflect */
.reflect-field { margin-bottom: 14px; }
.reflect-field span { line-height: 1.45; }

/* ===================================================================
   Suggested quests
   =================================================================== */

.suggested-quests { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.sq-card {
  text-align: left; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-m); padding: 14px; display: flex; flex-direction: column; gap: 7px;
  transition: border-color 120ms ease, transform 120ms ease;
}
.sq-card:not(:disabled):hover { border-color: var(--brass); transform: translateY(-2px); }
.sq-card.is-priority { border-left: 3px solid var(--teal); }
.sq-card.is-added { opacity: 0.55; }
.sq-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sq-comp { font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--brass-strong); }
.sq-freq { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); }
.sq-activity { font-size: 13px; font-weight: 600; line-height: 1.4; }
.sq-success { font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
.sq-add { font-size: 11.5px; font-weight: 600; color: var(--teal); margin-top: auto; padding-top: 4px; }
.sq-card.is-added .sq-add { color: var(--text-faint); }

.custom-quest { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line); }
.custom-quest summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.custom-quest summary:hover { color: var(--brass); }
.custom-quest .quest-form { margin-top: 16px; }

/* ===================================================================
   Leaderboard
   =================================================================== */

.table-scroll { overflow-x: auto; }
.leaderboard-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.leaderboard-table th {
  text-align: left; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-faint); font-weight: 600;
  padding: 0 12px 10px; border-bottom: 1px solid var(--line);
}
.leaderboard-table td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); }
.leaderboard-table tbody tr:last-child td { border-bottom: none; }
.leaderboard-table .lb-pos { font-family: var(--font-mono); color: var(--text-faint); width: 28px; font-variant-numeric: tabular-nums; }
.leaderboard-table .lb-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--text-muted); }
.leaderboard-table .lb-name { font-weight: 600; }
.leaderboard-table tr.is-top .lb-pos { color: var(--brass); font-weight: 700; }
.leaderboard-table tr.is-top-0 .lb-pos::after { content: " \1F3C6"; }
.leaderboard-table tr.is-you { background: var(--teal-tint); }
.leaderboard-table tr.is-you td:first-child { border-top-left-radius: var(--radius-s); border-bottom-left-radius: var(--radius-s); }
.leaderboard-table tr.is-you td:last-child { border-top-right-radius: var(--radius-s); border-bottom-right-radius: var(--radius-s); }
.lb-you-tag {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.03em;
  background: var(--teal); color: white; padding: 1px 7px; border-radius: 999px; margin-left: 8px; vertical-align: middle;
}

/* ===================================================================
   Auth gate
   =================================================================== */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.auth-gate[hidden] { display: none; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  padding: 30px 28px;
  box-shadow: 0 20px 60px var(--shadow);
}

.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 34px; height: 34px; color: var(--brass); flex-shrink: 0; }
.auth-brand .brand-name { display: block; font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.auth-brand .brand-sub { display: block; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); }

.auth-tabs { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin-bottom: 16px; }
.auth-tab { flex: 1; border: none; background: none; padding: 8px 0; border-radius: 999px; font-weight: 600; font-size: 13px; color: var(--text-muted); }
.auth-tab.is-active { background: var(--text); color: var(--surface); }

.auth-blurb { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }

#auth-form { display: flex; flex-direction: column; gap: 14px; }
#auth-form[hidden] { display: none; }
.auth-hint { font-size: 11.5px; color: var(--text-faint); margin-top: -8px; }
.auth-error {
  background: var(--critical-tint); color: var(--critical); font-size: 12.5px; font-weight: 600;
  border-radius: var(--radius-s); padding: 8px 12px; margin: 0;
}
.auth-submit { width: 100%; justify-content: center; margin-top: 2px; }
.auth-submit[disabled] { opacity: 0.6; }

.auth-import { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--line); }
.auth-import p { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }

/* ===================================================================
   Rail account row
   =================================================================== */

.rail-account {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 4px; font-size: 12px;
}
.account-email {
  color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-mono); font-size: 11px;
}
.account-logout {
  background: none; border: none; color: var(--text-faint); font-weight: 600; font-size: 11.5px;
  flex-shrink: 0; padding: 2px 4px;
}
.account-logout:hover { color: var(--critical); }

/* ===================================================================
   Responsive
   =================================================================== */

@media (max-width: 880px) {
  .app-shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px); z-index: 40;
    transform: translateX(-100%); transition: transform 220ms ease; box-shadow: 0 0 40px var(--shadow);
  }
  .rail.is-open { transform: translateX(0); }
  .rail-toggle {
    display: flex; flex-direction: column; justify-content: center; gap: 4px;
    position: fixed; top: 16px; left: 16px; z-index: 50;
    width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--surface); box-shadow: 0 4px 14px var(--shadow);
  }
  .rail-toggle span { display: block; height: 2px; width: 18px; background: var(--text); margin: 0 auto; border-radius: 2px; }
  .rail-scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 30; }
  .rail-scrim.is-visible { display: block; }
  .stage { padding: 76px 20px 60px; }
  .quest-form, .template-form { grid-template-columns: 1fr; }
  .field-wide, .field-full { grid-column: 1; }
  .dojo-grid { grid-template-columns: 1fr; }
}
