/* nextpage — "Ferrari at night": black, carbon greys, Rosso Corsa accents. */
:root {
  --bg: #000;
  --surface: #0a0a0b;
  --surface-2: #121214;
  --surface-3: #1a1a1d;
  --border: #222226;
  --border-strong: #2e2e33;
  --text: #ececee;
  --text-dim: #9a9aa3;
  --text-faint: #62626b;
  --accent: #ff2800;          /* rosso corsa */
  --accent-hover: #ff4a26;
  --accent-deep: #a81a00;
  --accent-soft: rgba(255, 40, 0, 0.12);
  --accent-glow: 0 0 0 1px rgba(255, 40, 0, 0.35), 0 0 24px rgba(255, 40, 0, 0.18);
  --ok: #3ddc84;
  --warn: #ffb020;
  --radius: 10px;
  --font-ui: "Titillium Web", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
::selection { background: var(--accent-deep); color: #fff; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--accent-deep); }

/* ---------- brand ---------- */
.brand {
  font: 700 20px/1 var(--font-ui);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  display: flex; align-items: center; gap: 10px;
}
.brand-word span { color: var(--accent); }
.brand-mark {
  width: 6px; height: 22px; border-radius: 2px;
  background: linear-gradient(var(--accent), var(--accent-deep));
  box-shadow: 0 0 14px rgba(255, 40, 0, 0.6);
}
.brand-lg { font-size: 34px; justify-content: center; }
.brand-lg .brand-mark { height: 34px; width: 8px; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--accent-glow); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 0 18px rgba(255, 40, 0, 0.35); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
input[type=text], input[type=password], textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
}
textarea { resize: vertical; }

/* ---------- login ---------- */
.login-body {
  display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse 80% 50% at 50% 110%, rgba(255, 40, 0, 0.16), transparent 60%), var(--bg);
}
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 36px 28px 28px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
}
.login-sub { text-align: center; color: var(--text-dim); margin: -4px 0 12px; font-family: var(--font-ui); letter-spacing: .08em; text-transform: uppercase; font-size: 12px; }
.login-card label { font-size: 13px; color: var(--text-dim); }
.login-card .btn { margin-top: 8px; padding: 11px; }
.login-error { margin: 0; color: var(--accent); font-size: 14px; text-align: center; }

/* ---------- app shell ---------- */
.app { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(var(--surface), var(--bg));
  position: relative;
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent) 30%, var(--accent) 70%, transparent);
  opacity: .55;
}
.topbar .spacer { flex: 1; }
.model-pill {
  font: 600 12px var(--font-mono); color: var(--text-dim);
  border: 1px solid var(--border-strong); border-radius: 999px; padding: 3px 10px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.status-dot.live { background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.tabs { display: none; }
.mobile-only { display: none; }

.panes {
  min-height: 0;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 420px;
}
.pane { min-height: 0; min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.pane:last-child { border-right: 0; }
.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px;
  font: 600 12px var(--font-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.pane-body { flex: 1; min-height: 0; overflow-y: auto; }

/* ---------- sidebar ---------- */
.sidebar { background: var(--surface); }
.course { border-bottom: 1px solid var(--border); }
.course-head {
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 12px 16px; display: flex; flex-direction: column; gap: 6px;
}
.course-head:hover { background: var(--surface-2); }
.course-title { font: 600 15px var(--font-ui); display: flex; align-items: center; gap: 8px; }
.course.active .course-title::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.course-meta { font-size: 12px; color: var(--text-dim); }
.progress { height: 3px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent-deep), var(--accent)); }
.files { list-style: none; margin: 0; padding: 0 0 8px; }
.files li button {
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 6px 16px 6px 28px; color: var(--text-dim); font-size: 13px;
  border-left: 2px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.files li button:hover { color: var(--text); background: var(--surface-2); }
.files li button.open { color: var(--text); border-left-color: var(--accent); background: var(--accent-soft); }
.files .group { padding: 8px 16px 2px 28px; font: 600 11px var(--font-ui); letter-spacing: .12em; color: var(--text-faint); text-transform: uppercase; }
.empty { padding: 24px 16px; color: var(--text-faint); font-size: 14px; }

/* ---------- reader ---------- */
.reader-body { padding: 32px clamp(16px, 5vw, 64px) 80px; }
.doc { max-width: 760px; margin: 0 auto; }
.reader-empty { max-width: 520px; margin: 12vh auto 0; text-align: center; color: var(--text-dim); }
.reader-empty h2 { font: 700 30px var(--font-ui); color: var(--text); margin: 0 0 8px; }
.reader-empty .brand-mark { margin: 0 auto 18px; height: 40px; width: 8px; }

.md h1, .md h2, .md h3, .md h4 { font-family: var(--font-ui); line-height: 1.25; margin: 1.6em 0 .6em; }
.md h1 { font-size: 34px; margin-top: 0; padding-bottom: 10px; border-bottom: 2px solid var(--accent); display: inline-block; }
.md h2 { font-size: 24px; }
.md h2::before { content: ""; display: inline-block; width: 4px; height: .9em; background: var(--accent); margin-right: 10px; vertical-align: -2px; border-radius: 2px; }
.md h3 { font-size: 19px; }
.md p, .md li { color: #d9d9dd; }
.md strong { color: #fff; }
.md code { font: 13px var(--font-mono); background: var(--surface-3); padding: 2px 6px; border-radius: 5px; }
.md pre { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 1em 0; padding: 4px 16px; border-left: 3px solid var(--border-strong); color: var(--text-dim); }
.md table { border-collapse: collapse; margin: 1em 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border-strong); padding: 6px 12px; }
.md th { background: var(--surface-2); font-family: var(--font-ui); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.md img { max-width: 100%; }
.md input[type=checkbox] { accent-color: var(--accent); }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 6px 0; }
.md .wikilink { color: var(--accent); text-decoration: none; border-bottom: 1px dashed rgba(255, 40, 0, .5); cursor: pointer; }
.md .wikilink:hover { border-bottom-style: solid; }
.md .frontmatter { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.md .tag { font: 600 11px var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 10px; }
.md .mermaid { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; text-align: center; overflow-x: auto; }
.md pre.tex { white-space: pre-wrap; }

.callout { border: 1px solid var(--border); border-left: 3px solid var(--accent); background: var(--surface); border-radius: 8px; padding: 10px 16px; margin: 1.2em 0; }
.callout > .callout-title, .callout > summary { font: 600 14px var(--font-ui); letter-spacing: .04em; color: var(--accent); cursor: default; list-style: none; }
.callout > summary { cursor: pointer; }
.callout > summary::before { content: "▸ "; }
.callout[open] > summary::before { content: "▾ "; }
.callout-tip, .callout-success { border-left-color: var(--ok); }
.callout-tip > .callout-title, .callout-success > .callout-title { color: var(--ok); }
.callout-warning, .callout-caution { border-left-color: var(--warn); }
.callout-warning > .callout-title { color: var(--warn); }
.callout-abstract > .callout-title, .callout-info > .callout-title, .callout-note > .callout-title { color: #ff8a70; }

/* ---------- chat ---------- */
.chat { background: var(--surface); }
.messages { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 100%; }
.msg-user {
  align-self: flex-end; max-width: 88%;
  background: var(--accent-soft); border: 1px solid rgba(255, 40, 0, .35);
  border-radius: 14px 14px 4px 14px; padding: 8px 14px; white-space: pre-wrap;
}
.msg-assistant { font-size: 14.5px; }
.msg-assistant.md p:first-child { margin-top: 0; }
.msg-assistant.md p:last-child { margin-bottom: 0; }
.msg-assistant.md h1 { font-size: 22px; }
.msg-assistant.md h2 { font-size: 18px; }
.msg-thinking { font-size: 13px; color: var(--text-faint); }
.msg-thinking summary { cursor: pointer; font-style: italic; }
.msg-thinking div { white-space: pre-wrap; margin-top: 6px; }
.msg-notice { font-size: 13px; color: var(--text-dim); text-align: center; }
.msg-error { font-size: 13px; color: var(--accent); text-align: center; }
.tool {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 13px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: var(--bg);
}
.tool .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--warn); animation: pulse 1s infinite; }
.tool.ok .dot { background: var(--ok); animation: none; }
.tool.err .dot { background: var(--accent); animation: none; }
.tool > div { min-width: 0; }
.tool b { color: var(--text); font-family: var(--font-ui); letter-spacing: .02em; }
.tool .out { display: block; color: var(--text-faint); word-break: break-word; }
.tool.err .out { color: #ff8a70; }
.tool a { cursor: pointer; }

.card {
  border: 1px solid var(--border-strong); border-top: 2px solid var(--accent);
  border-radius: var(--radius); background: var(--bg); padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.card h4 { margin: 0; font: 600 15px var(--font-ui); }
.card pre { margin: 0; max-height: 220px; overflow: auto; font: 12px var(--font-mono); background: var(--surface); padding: 10px; border-radius: 6px; white-space: pre-wrap; }
.card .row { display: flex; flex-wrap: wrap; gap: 8px; }

.composer { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { min-height: 46px; max-height: 200px; background: var(--bg); }
.composer .row { display: flex; align-items: center; gap: 8px; }
.composer .hint { flex: 1; font-size: 12px; color: var(--text-faint); }
.working { display: none; align-items: center; gap: 8px; font: 600 12px var(--font-ui); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.working.on { display: flex; }
.rev { display: flex; gap: 3px; }
.rev i { width: 4px; height: 10px; background: var(--accent); border-radius: 1px; animation: rev 0.9s infinite ease-in-out; }
.rev i:nth-child(2) { animation-delay: .1s; } .rev i:nth-child(3) { animation-delay: .2s; } .rev i:nth-child(4) { animation-delay: .3s; } .rev i:nth-child(5) { animation-delay: .4s; }
@keyframes rev { 0%, 100% { transform: scaleY(.4); opacity: .4; } 50% { transform: scaleY(1.3); opacity: 1; } }

/* ---------- quiz ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .78); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 16px;
}
.overlay[hidden] { display: none; }
.quiz {
  width: min(760px, 100%); max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-strong); border-top: 3px solid var(--accent);
  border-radius: 14px; box-shadow: 0 40px 120px rgba(0, 0, 0, .9), 0 0 60px rgba(255, 40, 0, .08);
}
.quiz-head { padding: 22px 26px 14px; border-bottom: 1px solid var(--border); }
.quiz-kicker { font: 600 12px var(--font-ui); letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
.quiz-head h2 { font: 700 26px var(--font-ui); margin: 4px 0 0; }
.quiz-body { overflow-y: auto; padding: 8px 26px 20px; }
.q { padding: 18px 0; border-bottom: 1px solid var(--border); }
.q:last-child { border-bottom: 0; }
.q-num { font: 700 13px var(--font-ui); color: var(--accent); letter-spacing: .1em; }
.q-prompt { margin: 4px 0 12px; font-size: 16px; }
.q-prompt p { margin: 0 0 6px; }
.opt {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 10px 14px; margin: 8px 0;
  cursor: pointer; transition: border-color .12s, background .12s;
}
.opt:hover { border-color: var(--text-faint); }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt .key {
  flex: none; width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center;
  font: 700 13px var(--font-ui); background: var(--surface-3); color: var(--text-dim);
}
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt:has(input:checked) .key { background: var(--accent); color: #fff; }
.opt:has(input:focus-visible) { box-shadow: var(--accent-glow); }
.quiz-foot { padding: 16px 26px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.quiz-foot .count { flex: 1; color: var(--text-dim); font-size: 13px; }

/* ---------- settings ---------- */
.settings { width: min(620px, 100%); }
.settings .quiz-body { display: flex; flex-direction: column; gap: 14px; padding-top: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.field > span { font: 600 12px var(--font-ui); letter-spacing: .1em; text-transform: uppercase; color: var(--text-dim); }
.field em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--text-faint); }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row-end { align-items: flex-end; }
select {
  width: 100%; background: var(--surface); color: var(--text); font: inherit;
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 10px 12px;
}
select:focus-visible { outline: none; box-shadow: var(--accent-glow); }
.settings-msg { margin: 0; min-height: 1.4em; font-size: 14px; color: var(--text-dim); }
.settings-msg.err { color: var(--accent); }
.settings-msg.ok { color: var(--ok); }

/* ---------- narrow screens ---------- */
@media (max-width: 1100px) {
  .panes { grid-template-columns: 230px minmax(0, 1fr) 360px; }
}
@media (max-width: 900px) {
  body { overflow-x: hidden; }
  .topbar .btn { padding: 6px 8px; font-size: 13px; }
  .topbar .spacer { min-width: 0; }
  .topbar .signout { display: none; }
  .mobile-only { display: inline-block; }
  .panes { grid-template-columns: minmax(0, 1fr); }
  .tabs { display: flex; gap: 4px; }
  .tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 4px 8px; color: var(--text-dim); font: 600 13px var(--font-ui); letter-spacing: .06em; text-transform: uppercase; cursor: pointer; }
  .tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .topbar .tabs { order: 10; width: 100%; }
  .model-pill { display: none; }
  .panes { grid-template-columns: 1fr; }
  .pane { display: none; border-right: 0; }
  .pane.show { display: flex; }
  .reader-body { padding: 20px 16px 60px; }
  .quiz-head, .quiz-body, .quiz-foot { padding-left: 16px; padding-right: 16px; }
}
