/* was? — design tokens */
:root, [data-theme="light"] {
  --bg: #f6f4ef; --surface: #fffdf9; --surface-2: #f1eee7; --ink: #24211c; --muted: #6b655b; --line: #e3ded3;
  --accent: #3d5a80; --accent-ink: #fff; --accent-soft: #e4eaf2; --mark: #fbe7a1; --danger: #a33a2c; --ok: #3d7a4f;
  --concept: rgba(61, 90, 128, .45); --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
  --t-def: #6a4c93; --t-premise: #3d5a80; --t-evidence: #3d7a4f; --t-assumption: #8a7a5c; --t-intermediate: #b0702a;
  --t-conclusion: #a33a2c; --t-objection: #9b3d6b; --t-response: #2f7f86; --t-qualification: #777;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #16171a; --surface: #1e1f23; --surface-2: #26282d; --ink: #e7e4dd; --muted: #9b968c; --line: #30323a;
  --accent: #93b2dc; --accent-ink: #10141a; --accent-soft: #263346; --mark: #5b4d1f; --danger: #e08a7c; --ok: #8cc79c;
  --concept: rgba(147, 178, 220, .5); --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --t-def: #b79be0; --t-premise: #93b2dc; --t-evidence: #8cc79c; --t-assumption: #c2b38f; --t-intermediate: #e0a15c;
  --t-conclusion: #e08a7c; --t-objection: #db8fb6; --t-response: #7cc8cf; --t-qualification: #aaa;
  color-scheme: dark;
}
[data-theme="sepia"] {
  --bg: #f1e7cf; --surface: #f8efd9; --surface-2: #ede0c2; --ink: #3a2e1f; --muted: #7a6a52; --line: #dfcfac;
  --accent: #8a5a2b; --accent-ink: #fff; --accent-soft: #ecdcbc; --mark: #efd38a; --danger: #9a3b26; --ok: #4f6f2f;
  --concept: rgba(138, 90, 43, .5);
}
:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Noto Serif", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Noto Sans Mono", monospace;
  --radius: 10px; --reader-size: 19px; --reader-width: 40em;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.boot { font: 600 28px var(--serif); text-align: center; margin-top: 30vh; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* controls */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 12px; cursor: pointer;
  transition: background .15s, border-color .15s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 3px 9px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { resize: vertical; min-height: 90px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 999px;
  padding: 1px 9px; font-size: 12.5px; background: var(--surface); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.badge { display: inline-block; font-size: 11px; letter-spacing: .02em; text-transform: uppercase; padding: 1px 6px;
  border-radius: 4px; background: var(--surface-2); color: var(--muted); vertical-align: 1px; }
.badge.k-text { color: var(--t-premise); } .badge.k-fact { color: var(--t-evidence); }
.badge.k-interpretation { color: var(--t-def); } .badge.k-synthesis { color: var(--t-intermediate); }
.badge.s-excerpt { color: var(--ok); } .badge.s-link { color: var(--muted); } .badge.s-unavailable { color: var(--danger); }

/* brand */
.brand { display: flex; align-items: center; gap: 8px; font: 700 20px var(--serif); letter-spacing: -.01em; text-decoration: none; color: var(--ink); }
.brand img { width: 28px; height: 28px; }
.tagline { font: italic 17px var(--serif); color: var(--muted); }
.mascot { width: 22px; height: 22px; vertical-align: middle; }
.mascot.pop { animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(.6) rotate(-8deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* top bar */
.top { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20; height: 52px; }
.top .title { font: 600 15px var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* auth */
.auth { max-width: 380px; margin: 12vh auto; padding: 32px; text-align: center; }
.auth img { width: 72px; }
.auth h1 { font: 700 40px var(--serif); margin: 6px 0 0; }
.auth form { text-align: left; margin-top: 18px; }
.err { color: var(--danger); font-size: 13.5px; min-height: 1.2em; }

/* library */
.lib { max-width: 980px; margin: 0 auto; padding: 24px 16px 60px; }
.hero { display: flex; align-items: center; gap: 16px; margin: 6px 0 22px; }
.hero img { width: 54px; }
.hero h1 { margin: 0; font: 700 30px var(--serif); }
.drop { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); background: var(--surface); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; margin-top: 16px; }
.doc { padding: 14px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; transition: border-color .15s; }
.doc:hover { border-color: var(--accent); }
.doc h3 { margin: 0; font: 600 17px/1.3 var(--serif); }
.bar { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.empty img { width: 64px; opacity: .9; }

/* reader layout */
.reader { display: grid; grid-template-columns: 270px minmax(0, 1fr) 380px; height: calc(100vh - 52px); }
.reader.no-left { grid-template-columns: 0 minmax(0, 1fr) 380px; }
.reader.no-right { grid-template-columns: 270px minmax(0, 1fr) 0; }
.reader.no-left.no-right { grid-template-columns: 0 minmax(0, 1fr) 0; }
.pane { overflow: auto; min-width: 0; }
.left { border-right: 1px solid var(--line); background: var(--surface); }
.right { border-left: 1px solid var(--line); background: var(--surface); }
.no-left .left, .no-right .right { visibility: hidden; border: 0; }
.tabs { display: flex; gap: 2px; padding: 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.tabs button { flex: 1; border: 0; background: none; padding: 5px 4px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--ink); }
.navlist { list-style: none; margin: 0; padding: 6px 8px 30px; }
.navlist li { padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px; line-height: 1.35; }
.navlist li:hover { background: var(--surface-2); }
.navlist li.l2 { padding-left: 20px; } .navlist li.l3 { padding-left: 32px; font-size: 13px; }
.navlist .meta { color: var(--muted); font-size: 12px; }
.navpad { padding: 10px 12px; }

.center { position: relative; background: var(--bg); }
.text { max-width: var(--reader-width); margin: 0 auto; padding: 36px 28px 40vh; font: var(--reader-size)/1.7 var(--serif); hyphens: auto; }
.text p { margin: 0 0 1em; text-align: left; }
.text .h { font-weight: 700; font-size: 1.15em; margin: 1.8em 0 .7em; line-height: 1.3; }
.text .fn { font-size: .8em; color: var(--muted); }
.text .pg { font: 11px var(--sans); color: var(--muted); text-align: center; margin: 1.4em 0; letter-spacing: .08em; }
.text [data-pid] { position: relative; border-radius: 4px; transition: background .6s; scroll-margin-top: 30vh; }
.text [data-pid].flash { background: var(--accent-soft); }
.text .has-note::after { content: "✎"; position: absolute; left: -1.6em; top: .1em; font-size: .7em; color: var(--accent); }
.concept { text-decoration: underline dotted var(--concept); text-decoration-thickness: 1.5px; text-underline-offset: 3px; cursor: help; }
.hide-markers .concept { text-decoration: none; cursor: auto; }
mark.hl { background: var(--mark); color: inherit; border-radius: 2px; }
.pageimg { display: block; margin: 20px auto; max-width: 100%; box-shadow: var(--shadow); background: #fff; }
.pagebar { position: sticky; top: 0; z-index: 3; display: flex; justify-content: center; gap: 8px; padding: 8px; background: var(--bg); border-bottom: 1px solid var(--line); }

/* selection toolbar */
.selbar { position: fixed; z-index: 40; display: flex; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); align-items: center; }
.selbar button { border: 0; background: none; padding: 4px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.selbar button:hover { background: var(--surface-2); }
.selbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px; }
.menu { position: fixed; z-index: 41; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13.5px; }
.menu button:hover { background: var(--surface-2); }

/* X-Ray panel */
.xray { padding: 14px 16px 60px; }
.xhead { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.xhead h2 { margin: 0; font: 700 21px/1.25 var(--serif); }
.sect { border-top: 1px solid var(--line); padding: 10px 0 8px; }
.sect > h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sect > h4 .lvl { font-weight: 400; text-transform: none; letter-spacing: 0; }
.def { font: 17px/1.55 var(--serif); margin: 4px 0 6px; }
.claims { list-style: none; padding: 0; margin: 4px 0; }
.claims li { margin: 0 0 8px; line-height: 1.5; }
.cite { font: 11.5px var(--mono); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 3px; cursor: pointer; background: var(--surface-2); }
.cite:hover { border-color: var(--accent); }
.occ { padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px; font-family: var(--serif); }
.occ:hover { background: var(--surface-2); }
.src { padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.src:last-child { border-bottom: 0; }
.note-ed { margin-top: 8px; }
.timeline { list-style: none; padding: 0 0 0 12px; border-left: 2px solid var(--line); margin: 6px 0; }
.timeline li { margin-bottom: 6px; } .timeline b { font-family: var(--mono); font-size: 12.5px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice { font-size: 13px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); color: var(--muted); display: flex; gap: 8px; align-items: flex-start; }
.ask { display: flex; gap: 6px; margin-top: 12px; }

/* graphs */
.graphwrap { position: relative; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); overflow: hidden; height: 420px; touch-action: none; }
.graphwrap svg { width: 100%; height: 100%; cursor: grab; user-select: none; }
.graphwrap svg.drag { cursor: grabbing; }
.gctl { position: absolute; bottom: 6px; right: 6px; display: flex; gap: 4px; }
.node rect { fill: var(--surface); stroke-width: 1.5; }
.node text { fill: var(--ink); font: 12px var(--sans); }
.node .ty { font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.node.hidden-concl rect { stroke-dasharray: 4 3; }
.node:hover rect { filter: brightness(.97); stroke-width: 2.5; }
.node { cursor: pointer; }
.edge { fill: none; stroke: var(--muted); stroke-width: 1.4; }
.edge.contradicts, .edge.opposition { stroke: var(--danger); stroke-dasharray: 5 3; }
.edge.qualifies { stroke-dasharray: 2 3; } .edge.defines { stroke: var(--t-def); }
.edge.responds_to { stroke: var(--t-response); } .edge.exemplifies { stroke: var(--t-evidence); }
.edge.prerequisite { stroke: var(--t-premise); } .edge.influence { stroke: var(--t-intermediate); stroke-dasharray: 8 3; }
.edge.similarity { stroke: var(--t-def); stroke-dasharray: 1 3; stroke-linecap: round; } .edge.co-occurrence { stroke: var(--line); stroke-width: 2.5; }
.elabel { font: 10px var(--sans); fill: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin: 6px 0; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--muted); vertical-align: middle; margin-right: 4px; }
.legend i.contradicts, .legend i.opposition { border-top: 2px dashed var(--danger); } .legend i.prerequisite { border-color: var(--t-premise); }
.legend i.influence { border-top: 2px dashed var(--t-intermediate); } .legend i.similarity { border-top: 2px dotted var(--t-def); }
.legend i.co-occurrence { border-top: 3px solid var(--line); } .legend i.defines { border-color: var(--t-def); }
.legend i.responds_to { border-color: var(--t-response); } .legend i.exemplifies { border-color: var(--t-evidence); }
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; padding: 20px; }
.overlay > .card { width: min(1100px, 100%); max-height: 100%; overflow: auto; padding: 16px; box-shadow: var(--shadow); }
.overlay .graphwrap { height: min(70vh, 680px); }
.dialog { width: min(560px, 100%) !important; }

/* settings */
.settings { max-width: 720px; margin: 0 auto; padding: 24px 16px 60px; }
.settings section { padding: 16px 18px; margin-bottom: 14px; }
.settings h2 { font: 700 26px var(--serif); margin: 0 0 14px; }
.settings h3 { margin: 0 0 4px; font-size: 16px; }
table.usage { width: 100%; border-collapse: collapse; font-size: 13px; }
table.usage td, table.usage th { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast > div { background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 13.5px; box-shadow: var(--shadow); display: flex; gap: 8px; align-items: center; }

/* responsive: Chromebook ~1366px works with 3 panels; smaller screens overlay side panels */
@media (max-width: 1180px) {
  .reader { grid-template-columns: 0 minmax(0, 1fr) 360px; }
  .reader .left { visibility: hidden; }
  .reader.show-left .left { visibility: visible; position: fixed; left: 0; top: 52px; bottom: 0; width: 280px; z-index: 30; box-shadow: var(--shadow); }
}
@media (max-width: 820px) {
  .reader, .reader.no-right { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .reader .right { visibility: hidden; }
  .reader.show-right .right { visibility: visible; position: fixed; right: 0; top: 52px; bottom: 0; width: min(420px, 100%); z-index: 30; box-shadow: var(--shadow); }
  .text { padding: 24px 18px 40vh; }
  .top .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.arrowhead { fill: var(--muted); }
.row > input, .row > select { width: auto; }
.row > .grow { flex: 1; min-width: 160px; }
.docs > .empty { grid-column: 1 / -1; }
.provider { border-top: 1px solid var(--line); padding: 10px 0; }
.provider summary { cursor: pointer; display: flex; gap: 6px; align-items: center; }
.provider p { margin: 6px 0; }
