:root {
  --ink: #14213d;
  --ink-2: #3b4a6b;
  --bg: #eef1f5;
  --paper: #ffffff;
  --orange: #f26522;
  --orange-deep: #c9501a;
  --orange-soft: #fff1ea;
  --silver: #d7dce4;
  --ok: #1f8a4c;
  --ok-soft: #e6f4ec;
  --bad: #c8322b;
  --bad-soft: #fbe9e7;
  --muted: #6b7280;
  --line: #dde2ea;
  --radius: 10px;
  --rail: 232px;
  --maxw: 880px;
  font-size: 17px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Assistant', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  line-height: 1.55; -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--orange-deep); }
button { font: inherit; cursor: pointer; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 0.8em; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- vest stripe (identity element) ---------- */
.stripe {
  height: 10px; width: 100%;
  background:
    linear-gradient(90deg, transparent 0 2px, var(--silver) 2px 4px, transparent 4px 6px, var(--silver) 6px 8px, transparent 8px) 0 0/ 0 0 no-repeat,
    linear-gradient(180deg, var(--orange) 0 2px, var(--silver) 2px 4px, var(--orange) 4px 6px, var(--silver) 6px 8px, var(--orange) 8px 10px);
}
.stripe.thin { height: 6px; background: linear-gradient(180deg, var(--orange) 0 2px, var(--silver) 2px 4px, var(--orange) 4px 6px); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }
.rail {
  background: var(--ink); color: #fff; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 0 0 20px;
}
.brand { padding: 22px 22px 18px; }
.brand .name { font-size: 1.45rem; font-weight: 800; display: block; color: #fff; text-decoration: none; }
.brand .sub { color: #aeb8cc; font-size: 0.9rem; }
.nav { display: flex; flex-direction: column; padding: 8px 12px; gap: 2px; }
.nav a {
  color: #d5dbe8; text-decoration: none; padding: 11px 12px; border-radius: 8px;
  display: flex; align-items: center; gap: 10px; font-weight: 600; border-right: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,0.1); color: #fff; border-right-color: var(--orange); }
.nav svg { width: 20px; height: 20px; flex: none; }
.nav .short { display: none; }
.rail .foot { margin-top: auto; padding: 14px 22px 0; color: #8b96ad; font-size: 0.82rem; line-height: 1.4; }

main { padding: 32px 36px 60px; }
.page { max-width: var(--maxw); margin: 0 auto; }
.page-head { margin-bottom: 22px; }
.page-head p { color: var(--muted); margin: 6px 0 0; max-width: 60ch; }

/* account box in rail */
.account { padding: 12px 18px 0; }
.account .who { display: flex; align-items: center; gap: 10px; color: #d5dbe8; font-size: 0.9rem; }
.account .who img { width: 32px; height: 32px; border-radius: 50%; flex: none; }
.account .who .n { font-weight: 700; color: #fff; display: block; line-height: 1.2; }
.account .who .e { font-size: 0.78rem; color: #8b96ad; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.account .lnk { background: none; border: 0; color: #8b96ad; font-size: 0.8rem; padding: 4px 0; text-decoration: underline; }
.account .lnk:hover { color: #fff; }
.account .gbtn { min-height: 40px; }
.account .hint { color: #8b96ad; font-size: 0.8rem; margin-top: 6px; line-height: 1.35; }
#accountMobile img { width: 30px; height: 30px; border-radius: 50%; vertical-align: middle; }
#accountMobile .lnk { background: none; border: 0; color: var(--ink-2); font-size: 0.85rem; text-decoration: underline; }

/* focused summary */
.focus-form { display: flex; gap: 8px; margin-bottom: 14px; }
.focus-form input { flex: 1; font-size: 1.05rem; }
.focus-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 0.88rem; margin-bottom: 10px; }
.recent-topics { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 18px; }

/* ---------- simulation ---------- */
.case-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.case { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.case .t { font-weight: 800; font-size: 1.1rem; }
.case .m { color: var(--muted); font-size: 0.88rem; }
.case .best { color: var(--ok); font-weight: 700; }
.sim-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.sim-head .t { font-weight: 800; font-size: 1.15rem; }
.sim-head .clock { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; }
.steps { display: flex; gap: 4px; margin: 6px 0 16px; }
.steps span { flex: 1; text-align: center; padding: 7px 0; font-weight: 800; font-size: 0.95rem; border-radius: 6px; background: var(--silver); color: var(--ink-2); }
.steps span.done { background: var(--ink); color: #fff; }
.steps span.cur { background: repeating-linear-gradient(135deg, var(--orange) 0 10px, var(--orange-deep) 10px 13px); color: #fff; }
.sim-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.transcript { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; padding: 4px; }
.line { padding: 9px 13px; border-radius: 10px; max-width: 95%; font-size: 0.97rem; }
.line.me { align-self: flex-start; background: var(--ink); color: #fff; border-bottom-right-radius: 3px; }
.line.them { align-self: flex-end; background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.line.sys { align-self: center; color: var(--muted); font-size: 0.85rem; text-align: center; }
.line.nudge { align-self: flex-end; background: var(--orange-soft); border: 1px solid #f0c9b6; color: var(--orange-deep); font-weight: 700; }
.line .who { display: block; font-size: 0.75rem; opacity: 0.7; margin-bottom: 2px; }
.line.reveal { align-self: stretch; max-width: 100%; border-right: 4px solid; border-radius: 6px; }
.line.reveal .who { opacity: 1; font-weight: 800; }
.line.reveal.check { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.line.reveal.treat { background: var(--bad); border-color: #8f1f1a; color: #fff; font-weight: 700; }
.line.reveal.harm { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.line.reveal.extra { background: #fff8e1; border-color: #e0a800; color: #7a5a00; }
.sim-grid.exam { grid-template-columns: 1fr; }
.sim-grid.exam .transcript { max-height: 50vh; }
.actions h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--ink-2); }
.act-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.act { text-align: right; padding: 10px 12px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--paper); font-weight: 600; color: var(--ink); display: flex; gap: 8px; align-items: flex-start; }
.act .ic { flex: none; width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 0.75rem; font-weight: 800; }
.act.check .ic { background: #e8eef8; color: var(--ink-2); }
.act.treat .ic { background: var(--orange-soft); color: var(--orange-deep); }
.act:hover:not(:disabled) { border-color: var(--ink-2); }
.act.done { opacity: 0.55; text-decoration: line-through; }
.act:disabled { cursor: default; }
.free { display: flex; gap: 6px; }
.free input { flex: 1; min-width: 0; }
.free .btn { white-space: nowrap; }
.sim-next { margin-top: 10px; }
.assess .opt { margin-bottom: 8px; }
.result-stage { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.result-stage .k { font-weight: 800; }
.ri { display: flex; gap: 8px; align-items: flex-start; font-size: 0.95rem; }
.ri .s { flex: none; width: 20px; text-align: center; font-weight: 800; }
.ri.ok .s { color: var(--ok); } .ri.miss .s { color: var(--bad); } .ri.extra .s { color: var(--muted); } .ri.harm .s { color: var(--bad); }
.ri.miss { color: var(--bad); }
.ri.harm { color: var(--bad); }
@media (max-width: 860px) { .sim-grid { grid-template-columns: 1fr; } .transcript { max-height: 38vh; } .steps span { font-size: 0.8rem; padding: 5px 0; } }

/* ---------- common ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.btn {
  border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 8px;
  padding: 10px 16px; font-weight: 700; transition: background 0.12s, border-color 0.12s;
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.primary:hover { background: var(--orange-deep); border-color: var(--orange-deep); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 6px 14px;
  font-weight: 600; font-size: 0.92rem; color: var(--ink-2);
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--paper); }
.seg button { border: 0; background: transparent; padding: 8px 16px; font-weight: 700; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.err { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 14px; font-weight: 600; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--orange); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
select, textarea, input[type=text], input[type=password] {
  font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px;
}
textarea { resize: vertical; }

/* markdown content */
.md h1, .md h2, .md h3 { margin: 1.1em 0 0.4em; }
.md h2 { font-size: 1.15rem; padding-bottom: 4px; border-bottom: 2px solid var(--orange-soft); }
.md h3 { font-size: 1rem; }
.md ul, .md ol { padding-right: 1.3em; margin: 0.3em 0 0.8em; }
.md li { margin: 0.2em 0; }
.md table { border-collapse: collapse; margin: 0.6em 0 1em; width: 100%; font-size: 0.95rem; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: right; vertical-align: top; }
.md th { background: var(--bg); }
.md strong { color: var(--ink); }
.md p:last-child { margin-bottom: 0; }
.md code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

/* citation chip */
.cite {
  display: inline-flex; align-items: center; gap: 4px; vertical-align: baseline;
  border: 0; border-right: 3px solid var(--orange); background: var(--orange-soft); color: var(--orange-deep);
  font-size: 0.78em; font-weight: 700; padding: 1px 7px 1px 8px; border-radius: 4px; margin: 0 2px; line-height: 1.4;
}
.cite:hover { background: #ffe3d4; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-height: calc(100vh - 200px); }
.chat-top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.chat-top label { font-weight: 600; color: var(--ink-2); }
.messages { flex: 1; display: flex; flex-direction: column; gap: 14px; padding-bottom: 20px; }
.msg { max-width: 92%; }
.msg.user { align-self: flex-start; }
.msg.bot { align-self: flex-end; width: 100%; max-width: 100%; }
.msg .bubble { padding: 12px 16px; border-radius: 14px; }
.msg.user .bubble { background: var(--ink); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: var(--paper); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot.notfound .bubble { border-color: #f0c9b6; background: #fffaf7; }
.sources { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 0.85rem; color: var(--muted); }
.sources .cite { font-size: 0.85rem; }
.starters { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin: 30px 0; }
.starters button { text-align: right; padding: 12px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; font-weight: 600; color: var(--ink-2); }
.starters button:hover { border-color: var(--orange); color: var(--ink); }
.composer { position: sticky; bottom: 0; background: linear-gradient(180deg, transparent, var(--bg) 30%); padding-top: 14px; }
.composer .box { display: flex; gap: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.composer textarea { flex: 1; border: 0; padding: 8px 10px; min-height: 44px; max-height: 160px; }
.composer textarea:focus-visible { outline: none; }
.composer .btn { align-self: flex-end; }

/* ---------- quiz ---------- */
.setup .block { margin-bottom: 22px; }
.setup .block > h3 { margin-bottom: 10px; }
.progress { position: relative; height: 10px; background: var(--silver); border-radius: 999px; overflow: hidden; margin: 6px 0 18px; }
.progress > i { position: absolute; inset: 0 auto 0 0; right: 0; width: 0; background: repeating-linear-gradient(135deg, var(--orange) 0 14px, var(--orange-deep) 14px 18px); transition: width 0.25s; border-radius: 999px; }
.qmeta { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.question { font-size: 1.25rem; font-weight: 700; margin: 8px 0 18px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  text-align: right; padding: 13px 16px; border-radius: 10px; border: 2px solid var(--line); background: var(--paper);
  display: flex; gap: 12px; align-items: flex-start; font-weight: 600; color: var(--ink);
}
.opt .k { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 0.85rem; color: var(--muted); }
.opt:hover:not(:disabled) { border-color: var(--ink-2); }
.opt.picked { border-color: var(--ink); }
.opt.picked .k { background: var(--ink); border-color: var(--ink); color: #fff; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .k { background: var(--ok); border-color: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .k { background: var(--bad); border-color: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 10px; border-right: 4px solid; }
.feedback.ok { background: var(--ok-soft); border-color: var(--ok); }
.feedback.bad { background: var(--bad-soft); border-color: var(--bad); }
.feedback b.v { display: block; margin-bottom: 4px; }
.qnav { display: flex; justify-content: space-between; margin-top: 20px; gap: 10px; }

.score { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.score .big { font-size: 3.6rem; font-weight: 800; line-height: 1; }
.score .big small { font-size: 1.2rem; color: var(--muted); font-weight: 600; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar { display: grid; grid-template-columns: 1fr 140px 52px; gap: 12px; align-items: center; }
.bar .track { height: 10px; background: var(--silver); border-radius: 999px; overflow: hidden; }
.bar .track i { display: block; height: 100%; background: var(--ok); }
.bar.low .track i { background: var(--bad); }
.bar.mid .track i { background: var(--orange); }
.bar .pct { font-weight: 700; text-align: left; }
.review { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.review .item { border-right: 4px solid var(--bad); }
.review .item.ok { border-right-color: var(--ok); }
.review .ans { margin: 6px 0; }
.review .ans.bad { color: var(--bad); }
.review .ans.good { color: var(--ok); }

/* ---------- progress ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 0.9rem; }
.topic-list { display: flex; flex-direction: column; gap: 8px; }
.topic { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
.topic .t { font-weight: 700; }
.topic .d { color: var(--muted); font-size: 0.85rem; }
.spark { display: flex; gap: 4px; align-items: flex-end; height: 60px; }
.spark i { flex: 1; background: var(--ink-2); border-radius: 3px 3px 0 0; min-height: 4px; }
.spark i.good { background: var(--ok); }
.spark i.low { background: var(--bad); }
.section { margin-top: 26px; }
.section > h2 { margin-bottom: 12px; }

/* ---------- chapters ---------- */
.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 14px 18px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; }
.doc:hover { border-color: var(--ink-2); }
.doc .t { font-weight: 700; font-size: 1.05rem; }
.doc .m { color: var(--muted); font-size: 0.88rem; }
.doc .go { color: var(--orange-deep); font-weight: 700; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---------- drawer (slide source) ---------- */
.drawer-bg { position: fixed; inset: 0; background: rgba(20,33,61,0.45); display: none; z-index: 40; }
.drawer-bg.open { display: block; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(520px, 100%); background: var(--paper); z-index: 41; transform: translateX(-100%); transition: transform 0.2s; display: flex; flex-direction: column; box-shadow: 0 0 40px rgba(0,0,0,0.2); }
.drawer.open { transform: none; }
.drawer .dh { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.drawer .dh .k { color: var(--orange-deep); font-weight: 700; font-size: 0.9rem; }
.drawer .db { padding: 20px; overflow: auto; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  :root { font-size: 16px; }
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; padding: 0; z-index: 30; border-top: 1px solid #2a3654; }
  .brand, .rail .foot, .rail .stripe, .account { display: none; }
  .nav { flex-direction: row; width: 100%; padding: 4px; gap: 0; }
  .nav a { flex: 1; flex-direction: column; gap: 3px; font-size: 0.75rem; padding: 8px 4px; border-right: 0; border-top: 3px solid transparent; border-radius: 6px; }
  .nav a.active { border-top-color: var(--orange); }
  .nav .long { display: none; } .nav .short { display: inline; }
  main { padding: 18px 16px 90px; }
  .mobile-brand { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
  .bar { grid-template-columns: 1fr 90px 46px; }
  .chat { min-height: calc(100vh - 220px); }
  .composer { bottom: 70px; }
  .drawer { width: 100%; }
}
@media (min-width: 861px) { .mobile-brand { display: none; } }
