/* ==========================================================
   DUK Tutor — monochrome UI
   Every colour is a token. Light = white paper, dark = pure black.
   ========================================================== */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f6;
  --bg-hover: #efefef;
  --fg: #0a0a0a;
  --fg-soft: #3a3a3a;
  --muted: #737373;
  --line: #e7e7e7;
  --line-strong: #cfcfcf;
  --user-bg: #0a0a0a;
  --user-fg: #ffffff;
  --code-bg: #f4f4f4;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --focus: 0 0 0 3px rgba(0,0,0,.12);

  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Space Grotesk", var(--font);
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --radius: 14px;
  --sidebar-w: 272px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --bg-soft: #0c0c0c; --bg-hover: #161616;
    --fg: #f5f5f5; --fg-soft: #cfcfcf; --muted: #8a8a8a;
    --line: #1c1c1c; --line-strong: #2e2e2e;
    --user-bg: #f5f5f5; --user-fg: #000000;
    --code-bg: #111111;
    --shadow: 0 1px 2px rgba(0,0,0,.6), 0 8px 24px rgba(0,0,0,.5);
    --focus: 0 0 0 3px rgba(255,255,255,.18);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --bg-soft: #0c0c0c; --bg-hover: #161616;
  --fg: #f5f5f5; --fg-soft: #cfcfcf; --muted: #8a8a8a;
  --line: #1c1c1c; --line-strong: #2e2e2e;
  --user-bg: #f5f5f5; --user-fg: #000000;
  --code-bg: #111111;
  --shadow: 0 1px 2px rgba(0,0,0,.6), 0 8px 24px rgba(0,0,0,.5);
  --focus: 0 0 0 3px rgba(255,255,255,.18);
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased;
}
button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { flex-shrink: 0; }
kbd {
  font: 500 11px var(--font-mono); padding: 1px 5px; border-radius: 5px;
  border: 1px solid var(--line-strong); color: var(--muted); background: var(--bg);
}
::selection { background: var(--fg); color: var(--bg); }

/* logo symbol colours follow the theme */
.logo { width: 34px; height: 34px; }
.logo-tile { fill: var(--fg); }
.logo-d { stroke: var(--bg); }
.logo-spark { fill: var(--bg); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100dvh; }
.scrim { display: none; }   /* mobile-only overlay behind the drawer */

/* ---------- sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column; gap: 14px; min-height: 0;
  padding: 18px 14px; background: var(--bg-soft); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 6px 6px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font: 700 17px var(--font-display); letter-spacing: -.02em; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.btn-new {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line-strong);
  background: var(--bg); font-weight: 500; transition: border-color .15s, transform .1s;
}
.btn-new:hover { border-color: var(--fg); }
.btn-new:active { transform: scale(.985); }
.btn-new svg { width: 17px; height: 17px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
.btn-new kbd { margin-left: auto; }

.side-label { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 4px 8px 0; }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.chat-item {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 9px;
  border: 0; background: none; text-align: left; color: var(--fg-soft); font-size: 14px;
}
.chat-item:hover { background: var(--bg-hover); color: var(--fg); }
.chat-item.active { background: var(--fg); color: var(--bg); }
.chat-item .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-item .del {
  opacity: 0; border: 0; background: none; color: inherit; padding: 2px; border-radius: 5px; line-height: 0;
}
.chat-item:hover .del, .chat-item.active .del { opacity: .65; }
.chat-item .del:hover { opacity: 1; }
.chat-item .del svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }
.chat-empty { font-size: 13px; color: var(--muted); padding: 6px 10px; }

.side-foot { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.field select {
  appearance: none; padding: 8px 32px 8px 11px; border-radius: 9px; border: 1px solid var(--line-strong);
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 9px center / 15px;
  color: var(--fg); font-size: 14px;
}
.field select:focus { outline: none; box-shadow: var(--focus); border-color: var(--fg); }

.status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 0 2px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--muted); }
.status.ok .dot { background: var(--fg); border-color: var(--fg); box-shadow: 0 0 0 3px var(--bg-hover); }
.status.warn .dot { border-style: dashed; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 18px;
  border-bottom: 1px solid var(--line);
}
.chat-title {
  flex: 1; margin: 0; font: 600 15px var(--font); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid transparent; background: none;
}
.icon-btn:hover { background: var(--bg-hover); }
.icon-btn svg { width: 19px; height: 19px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}
.only-mobile { display: none; }

.scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread { max-width: 780px; margin: 0 auto; padding: 28px 20px 12px; }

/* ---------- welcome ---------- */
.welcome {
  max-width: 720px; margin: 0 auto; padding: 9vh 20px 24px; text-align: center;
  animation: rise .5s cubic-bezier(.2,.8,.2,1);
}
.welcome.hidden { display: none; }
.logo-xl { width: 64px; height: 64px; margin-bottom: 20px; }
.welcome h2 { font: 700 clamp(26px, 4.2vw, 36px)/1.15 var(--font-display); letter-spacing: -.03em; margin: 0 0 10px; }
.welcome p { color: var(--muted); margin: 0 0 32px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.suggestions button {
  display: flex; flex-direction: column; gap: 3px; padding: 14px 16px; border-radius: var(--radius); text-align: left;
  border: 1px solid var(--line); background: var(--bg); transition: border-color .15s, transform .15s, box-shadow .15s;
}
.suggestions button:hover { border-color: var(--fg); transform: translateY(-1px); box-shadow: var(--shadow); }
.suggestions b { font-size: 13.5px; font-weight: 600; }
.suggestions span { font-size: 13.5px; color: var(--muted); }

/* ---------- messages ---------- */
.msg { display: flex; gap: 14px; margin-bottom: 28px; animation: rise .35s cubic-bezier(.2,.8,.2,1); }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: 78%; padding: 10px 16px; border-radius: 18px 18px 5px 18px;
  background: var(--user-bg); color: var(--user-fg); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg .avatar { width: 30px; height: 30px; margin-top: 1px; }
.msg.assistant .body { flex: 1; min-width: 0; }

.interpreted { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.interpreted q { color: var(--fg-soft); font-style: italic; }

.answer { overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer h1, .answer h2, .answer h3 { font-family: var(--font-display); letter-spacing: -.015em; line-height: 1.25; margin: 1.3em 0 .5em; }
.answer h1 { font-size: 1.35em; } .answer h2 { font-size: 1.2em; } .answer h3 { font-size: 1.05em; }
.answer p { margin: 0 0 .85em; }
.answer ul, .answer ol { padding-left: 1.4em; margin: 0 0 .85em; }
.answer li { margin: .25em 0; }
.answer li::marker { color: var(--muted); }
.answer strong { font-weight: 600; }
.answer a { color: var(--fg); text-underline-offset: 3px; }
.answer blockquote { margin: 0 0 .85em; padding: 2px 14px; border-left: 3px solid var(--fg); color: var(--fg-soft); }
.answer hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.answer code { font: 13px var(--font-mono); background: var(--code-bg); padding: 1.5px 5px; border-radius: 5px; border: 1px solid var(--line); }
.answer pre { position: relative; background: var(--code-bg); border: 1px solid var(--line); border-radius: 11px; padding: 14px 16px; overflow-x: auto; margin: 0 0 1em; }
.answer pre code { background: none; border: 0; padding: 0; font-size: 13px; line-height: 1.55; }
.answer table { border-collapse: collapse; display: block; overflow-x: auto; margin: 0 0 1em; font-size: 14px; }
.answer th, .answer td { border: 1px solid var(--line-strong); padding: 6px 10px; text-align: left; }
.answer th { background: var(--bg-soft); font-weight: 600; }

.copy-code {
  position: absolute; top: 8px; right: 8px; font: 500 11px var(--font); padding: 3px 8px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--bg); color: var(--muted); opacity: 0; transition: opacity .15s;
}
.answer pre:hover .copy-code { opacity: 1; }

/* citation chips [S1] */
.cite {
  display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin: 0 1px;
  border-radius: 6px; border: 1px solid var(--line-strong); background: var(--bg-soft);
  font: 600 10.5px var(--font-mono); color: var(--fg); vertical-align: 2px; transition: all .12s;
}
.cite:hover { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* thinking indicator */
.thinking { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.thinking .dots { display: inline-flex; gap: 4px; }
.thinking .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg); animation: blink 1.2s infinite both; }
.thinking .dots i:nth-child(2) { animation-delay: .15s; }
.thinking .dots i:nth-child(3) { animation-delay: .3s; }
.caret::after { content: ""; display: inline-block; width: 7px; height: 1.05em; margin-left: 2px; background: var(--fg); vertical-align: -2px; animation: caret 1s steps(2) infinite; }

/* warning */
.notice {
  display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  border: 1px dashed var(--line-strong); font-size: 13px; color: var(--fg-soft);
}
.notice svg { width: 17px; height: 17px; margin-top: 1px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }

/* action row */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 12px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); font-size: 12.5px; color: var(--fg-soft);
}
.chip-btn:hover { border-color: var(--fg); color: var(--fg); }
.chip-btn[aria-expanded="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chip-btn svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.timing { margin-left: auto; font: 11.5px var(--font-mono); color: var(--muted); }

/* sources */
.sources { display: none; margin-top: 10px; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.sources.open { display: grid; animation: rise .25s ease; }
.sources .q { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }
.src {
  display: flex; flex-direction: column; gap: 6px; padding: 12px 13px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-soft); font-size: 13px; transition: border-color .2s, box-shadow .2s;
}
.src.flash { border-color: var(--fg); box-shadow: var(--focus); }
.src-head { display: flex; align-items: flex-start; gap: 8px; }
.src-id { font: 600 11px var(--font-mono); padding: 2px 6px; border-radius: 5px; background: var(--fg); color: var(--bg); }
.src-title { font-weight: 600; line-height: 1.35; }
.src-meta { font-size: 12px; color: var(--muted); }
.src-preview { font-size: 12.5px; color: var(--fg-soft); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.src-preview.full { -webkit-line-clamp: unset; }
.src-bar { height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.src-bar i { display: block; height: 100%; background: var(--fg); }

/* ---------- composer ---------- */
.composer-wrap { padding: 8px 20px 14px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer {
  max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 8px 8px 16px; border-radius: 20px; border: 1px solid var(--line-strong);
  background: var(--bg); box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--fg); }
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: none; padding: 8px 0;
  max-height: 200px; line-height: 1.5; font-size: 15px;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; border: 0;
  background: var(--fg); color: var(--bg); transition: opacity .15s, transform .1s;
}
.send:active { transform: scale(.94); }
.send:disabled { opacity: .25; cursor: default; }
.send svg { width: 19px; height: 19px; stroke: currentColor; stroke-width: 2.2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send.busy .i-send { display: none; }
.send.busy .i-stop { display: block; }
.hint { max-width: 780px; margin: 8px auto 0; text-align: center; font-size: 11.5px; color: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
  padding: 8px 14px; border-radius: 10px; background: var(--fg); color: var(--bg); font-size: 13px; transition: all .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- animations ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: .2; transform: scale(.8); } 40% { opacity: 1; transform: none; } }
@keyframes caret { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 300px); z-index: 20;
    transform: translateX(-100%); transition: transform .25s cubic-bezier(.2,.8,.2,1);
  }
  .app.menu-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.4); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .app.menu-open .scrim { opacity: 1; pointer-events: auto; }
  .only-mobile { display: grid; }
  .topbar { padding: 0 10px; }
  .thread { padding: 20px 16px 8px; }
  .welcome { padding: 6vh 16px 16px; }
  .suggestions { grid-template-columns: 1fr; }
  .composer-wrap { padding: 6px 12px max(10px, env(safe-area-inset-bottom)); }
  .msg.user .bubble { max-width: 88%; }
  .msg { gap: 10px; }
  .msg .avatar { width: 26px; height: 26px; }
  .hint { display: none; }
  .btn-new kbd { display: none; }
}
