/* Design system ported from kintale (public/index.html tokens, 2026-09-01):
   same palette, buttons, cards, chips, cmd-palette, snackbar, focus rules. */
:root { color-scheme: light dark;
  --bg: #faf7f2; --fg: #1f1a14; --muted: #6b6156; --card: #ffffff;
  --accent: #7a5c3e; --accent-soft: #ede4d8; --line: #e5dccf;
  --ready: #4c8a4f; --ready-soft: #e7f0e4; --stale: #b8862e; --stale-soft: #f6ead2;
  --confuse: #a05a9e; }
:root[data-theme="dark"] {
  --bg: #171310; --fg: #ece5da; --muted: #a3988a; --card: #211c17;
  --accent: #d9b054; --accent-soft: #302a18; --line: #332c24;
  --ready: #7fb183; --ready-soft: #1e2a1e; --stale: #d9a854; --stale-soft: #2e2618; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #171310; --fg: #ece5da; --muted: #a3988a; --card: #211c17;
    --accent: #d9b054; --accent-soft: #302a18; --line: #332c24;
    --ready: #7fb183; --ready-soft: #1e2a1e; --stale: #d9a854; --stale-soft: #2e2618; } }

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif;
  background: var(--bg); color: var(--fg); font-size: 16px; line-height: 1.5; }

button, .btn { border: 1px solid var(--line); background: var(--card); color: var(--fg);
  border-radius: 9px; padding: 6px 12px; cursor: pointer; font: inherit; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px; }
button.primary, .btn.primary { background: var(--accent-soft); border-color: var(--accent); }
button.on, .btn.active { border-color: var(--accent); color: var(--accent); font-weight: 700; }
button:disabled { opacity: 0.5; cursor: default; }
button:focus { outline: none; }
button:focus-visible, a:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }
button, a, .card, svg, svg * { -webkit-tap-highlight-color: transparent; }
svg g:focus, svg *:focus { outline: none; }
svg g:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); cursor: pointer; }
a.btn { text-decoration: none; color: var(--fg); }
.muted { color: var(--muted); }

input, textarea, select { width: 100%; padding: 9px 11px; margin: 4px 0;
  border: 1px solid var(--line); border-radius: 9px; font: inherit;
  background: var(--card); color: var(--fg); }
textarea { min-height: 70px; resize: vertical; }

header { display: flex; align-items: center; gap: 12px; padding: 10px 18px;
  background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header h1 { font-size: 19px; margin: 0; letter-spacing: .4px; cursor: pointer; }
.ns { color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.tracker { margin-left: auto; color: var(--muted); font-size: 13px;
  font-variant-numeric: tabular-nums; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.kbd { font-family: ui-monospace, Menlo, monospace; font-size: 11px;
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
  color: var(--muted); }

.error { background: #b3402e; color: #fff; padding: 8px 18px; display: flex;
  justify-content: space-between; align-items: center; }
.error button { background: transparent; border: none; color: #fff; }
.hint { padding: 8px 18px; color: var(--muted); font-style: italic; font-size: 14px; }

/* map — physics graph, kintale visual language */
.map-wrap { overflow: hidden; }
svg.graph { display: block; background: var(--bg); touch-action: none; }
.node { cursor: pointer; }
.node .node-body { fill: var(--muted); stroke: var(--card); stroke-width: 2;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.15)); }
.node:hover .node-body { stroke: var(--accent); }
.node-empty .node-body { fill: color-mix(in srgb, var(--muted) 45%, var(--bg)); }
.tile-ready .node-body { fill: var(--ready); }
.tile-stale .node-body { fill: var(--stale); }
.tile-accepted .node-body { fill: var(--accent); }
/* course focus: targets ringed, prerequisite closure dashed, the rest dimmed */
.node.dim { opacity: .28; }
.node.in-target .node-body { stroke: var(--accent); stroke-width: 3.5; }
.node.in-closure .node-body { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 4 3; }
/* course panel rows */
.crow { display: flex; align-items: center; gap: 8px; padding: 5px 0;
  border-bottom: 1px solid var(--line); }
.crow input[type="checkbox"] { width: auto; margin: 0; }
.crow-title { flex: 1; cursor: pointer; }
.crow select { width: auto; margin: 0; padding: 4px 8px; font-size: 12px; }
input.short { width: 80px; margin: 0; }
.course-summary { margin-top: 12px; }
/* source viewer: page-marked extraction, the anchored page highlighted */
.srcpage { white-space: pre-wrap; font: inherit; font-size: 13px; margin: 0 0 8px;
  padding: 8px 10px; border-left: 3px solid var(--line); background: var(--bg); }
.srcpage.hit { border-left-color: var(--accent); }
a.srclink { color: var(--accent); }
a.chip { text-decoration: none; color: inherit; }
.course-intake { margin: 10px 0 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.course-intake .msgs { min-width: 0; }
.panel .row select { width: auto; margin: 0; }
.course-intake .composer { margin-top: 0; padding-top: 0; }
.tile-deprecated .node-body { fill: var(--line); }
.node-label { font-size: 12.5px; font-weight: 600; fill: var(--fg);
  text-anchor: middle; paint-order: stroke; stroke: var(--bg);
  stroke-width: 3px; stroke-linejoin: round; }
.node-sub { font-size: 10.5px; fill: var(--muted); text-anchor: middle;
  paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }
.node-ghost { cursor: pointer; }
.edge { stroke: var(--line); stroke-width: 1.4; fill: none; }
.edge-requires { stroke: var(--accent); stroke-width: 1.7; }
.edge-is-confused-with { stroke: var(--confuse); stroke-dasharray: 4 3; }
.edge-generalizes, .edge-part-of, .edge-see-also { stroke-dasharray: 2 4; }
#arrow path { fill: var(--accent); }
.empty { min-height: 60vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; color: var(--muted); }
.empty .empty-ico { width: 48px; height: 48px; stroke-width: 1.2; }
.btnrow { display: flex; gap: 8px; }

.split { display: grid; grid-template-columns: 1fr minmax(340px, 480px); }
.panel, .chat { background: var(--card); border-left: 1px solid var(--line);
  padding: 16px 20px; max-height: calc(100vh - 55px); overflow-y: auto; }
.panel-head { display: flex; align-items: center; gap: 10px; }
.panel-head h2 { font-size: 18px; flex: 1; margin: 0; }
.close { text-decoration: none; color: var(--muted); font-size: 17px; }
.badge { font-size: 11px; padding: 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--fg); white-space: nowrap; }
.badge.tile-ready { background: var(--ready); color: var(--card); }
.badge.tile-stale { background: var(--stale); color: var(--card); }
.badge.tile-empty { background: var(--line); }
.def { margin: 10px 0; }
.links { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { font-size: 12px; background: var(--bg); border: 1px solid var(--line);
  padding: 3px 11px; border-radius: 999px; cursor: pointer; }
.chip:hover { background: var(--accent-soft); }
.panel h3 { font-size: 14px; margin: 18px 0 6px; color: var(--muted); }
.lo, .item { border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin: 6px 0; background: var(--card); }
.lo-kind { font-size: 11px; color: var(--muted); }
.lo p, .item p { margin: 4px 0 0; }

.form { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.form .row { display: flex; gap: 8px; }
.form .row > * { flex: 1; }
.addbtn { color: var(--muted); border-style: dashed; width: 100%; justify-content: center; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 210;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal .form { background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px 20px; min-width: 320px; max-width: 500px;
  width: 100%; box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.modal h3 { margin: 0 0 6px; font-size: 15px; }
.edge-btn { text-align: left; }

/* command palette (kintale .cmd-*) */
.cmd-scrim { position: fixed; inset: 0; z-index: 220; background: rgba(0,0,0,.35); }
.cmd-palette { position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); width: min(460px, calc(100vw - 24px));
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.cmd-title { font-size: 11px; color: var(--muted); padding: 0 4px 6px; }
.cmd-input { width: 100%; font: inherit; font-size: 14px; background: var(--bg);
  color: var(--fg); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; margin: 0; }
.cmd-list { list-style: none; margin: 6px 0 0; padding: 0;
  max-height: 46vh; overflow-y: auto; }
.cmd-list li { padding: 6px 8px; border-radius: 8px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-list li.sel, .cmd-list li:hover { background: var(--accent-soft); }
.cmd-list .muted { font-size: 12px; margin-left: 6px; }
.cmd-list li { display: flex; align-items: center; gap: 8px; }
.cmd-ico { width: 15px; height: 15px; }
.cmd-empty { color: var(--muted); font-size: 12px; padding: 6px 8px; margin: 0; }

/* snackbar (kintale .kt-snack) */
.snack { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px;
  z-index: 200; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  font-size: 13.5px; padding: 10px 16px; border-radius: 10px;
  max-width: min(340px, 80vw); box-shadow: 0 6px 24px rgba(0,0,0,.25);
  animation: snack-in .2s ease-out; }
@keyframes snack-in { from { transform: translate(-50%, 8px); opacity: 0; }
  to { transform: translate(-50%, 0); } }

/* chat */
.chat { display: flex; flex-direction: column; gap: 10px; }
.chat-head { display: flex; align-items: center; gap: 10px; }
.chat-head h2 { font-size: 17px; flex: 1; margin: 0; }
.msgs { display: flex; flex-direction: column; gap: 6px; }
.msg { padding: 8px 12px; border-radius: 12px; max-width: 92%; white-space: pre-wrap;
  min-width: 0; overflow-wrap: anywhere; }
.msg-user { background: var(--accent-soft); align-self: flex-end; }
.msg-llm { background: var(--bg); border: 1px solid var(--line); }
.msg-sys { background: var(--stale-soft); font-style: italic; }
.cards h3 { font-size: 14px; color: var(--muted); margin: 4px 0 6px; }
.card { border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 10px 12px; margin: 6px 0; background: var(--card); }
.card-q { border-left-color: var(--confuse); }
.card-tag { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.card .row { margin-top: 8px; display: flex; gap: 6px; }
.card p { margin: 4px 0 0; }
.doc-chip { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.doc-chip .card-tag { display: inline; margin: 0; }
/* kintale composer: the border lives on .chat-field, the textarea inside
   is bare, attach and send are flex children on its last line */
.composer { margin-top: auto; padding-top: 8px; }
.chat-field { display: flex; align-items: flex-end; gap: 4px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 22px; padding: 6px; }
.chat-field textarea { flex: 1; min-width: 0; min-height: 0; resize: none; font: inherit;
  font-size: 13px; background: transparent; color: var(--fg);
  border: 0; border-radius: 0; margin: 0; padding: 8px 2px 8px 12px;
  overflow-y: auto; max-height: 200px; line-height: 1.4; }
.chat-field textarea:focus, .chat-field textarea:focus-visible { outline: none; }
.chat-field .chat-attach, .chat-field .chat-sendbtn { flex: none;
  width: 30px; height: 30px; margin: 0 0 3px; padding: 0;
  border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; }
.chat-field .chat-attach { background: transparent; border: 0;
  color: var(--muted); cursor: pointer; }
.chat-field .chat-attach:hover { background: var(--accent-soft); color: var(--fg); }
.chat-field .chat-attach .ico,
.chat-field .chat-sendbtn .ico { width: 16px; height: 16px; }
/* send: filled, the shape every messenger trained the hand to find */
button.primary.chat-sendbtn { background: var(--accent);
  border-color: var(--accent); color: var(--bg); }
button.primary.chat-sendbtn:hover:not(:disabled) { filter: brightness(1.08); }

@media (max-width: 700px) {
  .split { grid-template-columns: 1fr; }
  .panel, .chat { border-left: none; border-top: 1px solid var(--line); max-height: none; }
  .tracker { display: none; }
  .map-wrap { min-height: 0; }
}

/* stroke icons (kintale .ico) */
.ico { width: 18px; height: 18px; display: block; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
button .ico, .btn .ico { width: 16px; height: 16px; }
.panel h3 .ico { width: 15px; height: 15px; display: inline-block; vertical-align: -2px; }
.close .ico { width: 17px; height: 17px; }
