:root {
  --bg: #0b0c10;
  --bg-elev: #12141a;
  --bg-soft: #181b24;
  --line: rgba(255, 255, 255, 0.07);
  --text: #eceef4;
  --muted: #8d93a6;
  --gold: #f4c38b;
  --mint: #7ee0c7;
  --rose: #f07178;
  --blue: #8ab4ff;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --panel: 320px;
  --sans: "Söhne", "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(244, 195, 139, 0.08), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, rgba(126, 224, 199, 0.06), transparent 45%),
    var(--bg);
  color: var(--text);
  letter-spacing: 0.01em;
}

.app {
  display: grid;
  grid-template-columns: var(--panel) 1fr;
  min-height: 100dvh;
}

.panel {
  border-right: 1px solid var(--line);
  background: rgba(12, 14, 18, 0.88);
  backdrop-filter: blur(16px);
  padding: 22px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.brand { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 42px; height: 42px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #2a2118, #12151c);
  color: var(--gold);
  font-weight: 650;
  font-size: 0.82rem;
  letter-spacing: -0.03em;
  box-shadow: inset 0 0 0 1px rgba(244, 195, 139, 0.25), 0 8px 24px rgba(0,0,0,.35);
}
.brand-name { font-size: 1.15rem; font-weight: 650; }
.brand-tag { color: var(--muted); font-size: 0.78rem; }
.bio { color: var(--muted); font-size: 0.9rem; line-height: 1.45; margin: 0; }
.bio p { margin: 0 0 8px; }
.bio p:last-child { margin-bottom: 0; }
.identity {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-soft);
}
.identity-email {
  font-size: 0.82rem;
  color: var(--text);
  word-break: break-all;
  line-height: 1.4;
}
.panel.gated .identity-email { color: var(--muted); }
.panel.gated .scores,
.panel.gated .history { opacity: 0.45; pointer-events: none; }

.scores { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.score-card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.score-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.score-value { font-size: 1.55rem; font-weight: 650; margin-top: 4px; color: var(--gold); }
.score-card:first-child .score-value { color: var(--mint); }
.score-meta { font-size: 0.72rem; color: var(--muted); margin-top: 4px; min-height: 2.2em; }
.cert-line {
  margin: -4px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}
.page-card .note { color: var(--muted); line-height: 1.6; }

.actions { display: flex; flex-direction: column; gap: 8px; }
.btn {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  font: inherit;
  cursor: pointer;
}
.btn.primary {
  background: linear-gradient(180deg, #f6d3a4, #e2b072);
  color: #1a1208;
  border: none;
  font-weight: 650;
}
.btn.ghost:hover, .btn.primary:hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.55; cursor: wait; }
a.btn { text-decoration: none; display: inline-block; text-align: center; }

.history { flex: 1; overflow: auto; font-size: 0.8rem; color: var(--muted); }
.history h3 { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.hist-row {
  display: flex; justify-content: space-between; gap: 8px; padding: 6px 0;
  border: 0; border-bottom: 1px solid var(--line); width: 100%;
  background: transparent; color: inherit; font: inherit; cursor: pointer; text-align: left;
}
.miss-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.miss-row p { margin: 0 0 6px; color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.miss-ask { margin-top: 8px; }
.miss-inline { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 10px; }
.miss-inline .sitting-ask { width: auto; }
#misses .sitting-ask { margin: 8px 0 10px; width: 100%; }
.fine { color: var(--muted); font-size: 0.72rem; margin: 0; }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.wordmark {
  display: inline;
  color: var(--gold);
  font-weight: 650;
  font-size: 1.02rem;
  text-decoration: none;
  letter-spacing: -0.02em;
}
.top-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.nav-link {
  background: transparent;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 0.92rem;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); background: var(--bg-soft); }
.nav-link.active {
  color: var(--text);
  background: var(--bg-soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
.nav-link.external { color: var(--gold); }
.mode-pill {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--mint);
  margin-left: auto;
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  width: 36px; height: 36px;
  cursor: pointer;
}
.mobile-only { display: none; margin-left: auto; }
#open-panel { display: none; }

.chat, .exam, .page, .work {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.work { position: relative; }
.hidden { display: none !important; }

.gate {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: start center;
  padding: 7vh 20px 32px;
  background: rgba(8, 9, 12, 0.78);
  backdrop-filter: blur(12px);
}
.gate-card {
  width: min(440px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
}
.gate-card h1 {
  font-family: var(--serif);
  font-size: 1.55rem;
  margin: 0 0 10px;
  color: var(--text);
}
.gate-card .lede { color: var(--muted); font-size: 0.95rem; line-height: 1.5; margin: 0 0 16px; }
.gate-label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.gate-card input[type="email"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  outline: none;
}
.gate-card input[type="email"]:focus { border-color: var(--gold); }
.gate-error { color: var(--rose); font-size: 0.85rem; margin: 0 0 10px; }
.gate-card .btn.primary { width: 100%; margin-bottom: 10px; }
.gate-card .fine { margin-top: 4px; line-height: 1.45; }

.thread {
  flex: 1;
  overflow: auto;
  padding: 28px 8vw 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.msg { max-width: 720px; width: 100%; margin: 0 auto; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble {
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 1.02rem;
}
.msg.user .bubble {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 18px 18px 6px 18px;
  padding: 12px 16px;
  max-width: 85%;
}
.msg.assistant .who {
  font-size: 0.75rem;
  color: var(--gold);
  margin-bottom: 6px;
  font-weight: 600;
}
.msg.sitting { max-width: 720px; }
.sitting-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 8px;
}
.sitting-head p { color: var(--muted); margin: 0 0 8px; font-size: 0.92rem; line-height: 1.45; }
.sitting-items { display: flex; flex-direction: column; gap: 4px; }
.sitting-card .choice { cursor: default; }
.sitting-card .stem { font-size: 1.02rem; }
.citations { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 0.72rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  cursor: pointer;
}
.chip.thin {
  color: #f3d27a;
  border-color: rgba(243, 210, 122, 0.45);
  background: rgba(243, 210, 122, 0.08);
  cursor: default;
}
.chip.grok {
  color: var(--gold);
  border-color: rgba(244, 195, 139, 0.45);
  background: rgba(244, 195, 139, 0.08);
  cursor: default;
}
.flags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.excerpt {
  display: none;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
  white-space: pre-wrap;
}
.excerpt.open { display: block; }
.split-hint {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto 8px;
  color: var(--gold);
  font-size: 0.8rem;
}
.msg.assistant h3 {
  font-size: 1.02rem;
  margin: 1em 0 0.35em;
  color: var(--gold);
}
.drill-btn {
  margin-top: 10px;
}
.welcome { max-width: 720px; margin: 8vh auto 0; color: var(--muted); }
.welcome h1, .page-card h1, .practice-intro h1 {
  font-family: var(--serif);
  color: var(--text);
  font-size: clamp(1.7rem, 3vw, 2.15rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 12px;
}
.welcome p, .practice-intro p { line-height: 1.55; }
.welcome .lede, .page-card .lede { font-size: 1.05rem; color: var(--text); max-width: 42rem; }
.eyebrow {
  margin: 0 0 8px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}
.hero-points {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 22px 0 18px;
}
.hero-points div {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hero-points strong { color: var(--text); font-size: 0.88rem; }
.hero-points span { font-size: 0.82rem; line-height: 1.4; }
.welcome-actions, .page-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.practice-intro h1 { margin-top: 4px; }

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin: 0 auto 20px;
  width: min(720px, calc(100% - 32px));
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  background: transparent;
  border: 0;
  color: var(--text);
  font: inherit;
  outline: none;
}
.send {
  width: 40px; height: 40px; border-radius: 14px;
  border: 0; cursor: pointer;
  background: var(--gold); color: #1a1208; font-size: 1.1rem; font-weight: 700;
}

.exam, .page { padding: 24px 16px 40px; overflow: auto; }
.page-card {
  width: min(880px, 100%);
  margin: 0 auto 32px;
}
.page-card h2 {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 2rem 0 0.7rem;
  color: var(--text);
}
.page-card p { color: var(--muted); line-height: 1.6; margin: 0 0 0.9rem; }
.page-card a { color: var(--gold); }
.pillars {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 8px 0 8px;
}
.pillars article, .layers article {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 16px 8px;
}
.pillars h3, .layers h3 {
  font-size: 1rem;
  margin: 0 0 8px;
  color: var(--text);
  font-weight: 650;
}
.pillars p, .layers p { font-size: 0.9rem; }
.layers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 8px 0 16px;
  padding: 0;
}
.layer-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mint);
  margin: 0 0 6px;
}
.flow-table-wrap { overflow: auto; margin: 8px 0 16px; border: 1px solid var(--line); border-radius: 16px; }
.flow-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  line-height: 1.45;
}
.flow-table th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 14px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}
.flow-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  color: var(--muted);
}
.flow-table td:first-child {
  color: var(--text);
  font-weight: 650;
  width: 22%;
}
.flow-table tr:last-child td { border-bottom: 0; }

.exam-card {
  width: min(720px, 100%);
  margin: 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.progress { color: var(--muted); font-size: 0.82rem; margin-bottom: 12px; }
.stem { font-size: 1.12rem; line-height: 1.5; margin: 0 0 16px; }
.choice {
  display: block; width: 100%; text-align: left;
  background: var(--bg-soft); border: 1px solid var(--line);
  color: inherit; font: inherit; border-radius: 12px;
  padding: 12px 14px; margin: 8px 0; cursor: pointer;
}
.choice.selected { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.choice.correct { border-color: var(--mint); }
.choice.wrong { border-color: var(--rose); }
.exam-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.result-hero { font-size: 2.4rem; font-weight: 650; color: var(--gold); }
.review { margin-top: 18px; display: flex; flex-direction: column; gap: 14px; }
.review-item { border-top: 1px solid var(--line); padding-top: 12px; }
.explain { color: var(--muted); font-size: 0.92rem; line-height: 1.45; }

.cursor::after {
  content: "▍";
  animation: blink 1s steps(1) infinite;
  color: var(--gold);
}
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .panel {
    position: fixed; inset: 0 auto 0 0; width: min(var(--panel), 92vw);
    z-index: 20; transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .panel.open { transform: none; }
  .mobile-only, #open-panel { display: inline-grid; place-items: center; }
  .wordmark { display: inline; }
  .top-nav { flex: 1 1 100%; order: 3; }
  .mode-pill { display: none; }
  .nav-link { padding: 6px 10px; font-size: 0.86rem; }
  .thread { padding: 18px 16px 12px; }
  .welcome { margin-top: 4vh; }
  .hero-points, .pillars, .layers { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .flow-table thead { display: none; }
  .flow-table, .flow-table tbody, .flow-table tr, .flow-table td { display: block; width: 100%; }
  .flow-table tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
  }
  .flow-table td {
    padding: 4px 0;
    border: 0;
    width: auto;
  }
  .flow-table td:first-child {
    color: var(--gold);
    margin-bottom: 4px;
  }
}
