/* Agent Memory — study studio · lockin academic mode · style: claude */

:root {
  --bg: #f0eee6;         --surface: #faf9f5;    --surface-2: #e8e6dc;
  --ink: #141413;        --muted: #6e6d66;
  --accent: #d97757;     --on-accent: #ffffff;
  --border: rgba(20, 20, 19, 0.10);
  --radius: 12px;        --radius-lg: 18px;
  --shadow: 0 1px 3px rgba(20, 20, 19, 0.07);
  --font-display: ui-serif, Georgia, 'Times New Roman', serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, monospace;
  --ok: #7d9a6f;  --warn: #c58c33;  --err: #b0552f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1e1b; --surface: #262521; --surface-2: #302e29;
    --ink: #f0eee6; --muted: #a3a094; --border: rgba(240, 238, 230, 0.12);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 16px; line-height: 1.65;
  display: flex; flex-direction: column;
}
a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Topbar ─────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 1rem; flex: none;
  padding: 0.65rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 0.5rem; text-decoration: none; color: var(--ink); }
.brand-mark { color: var(--accent); font-size: 1.1rem; }
.brand-title { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; }
.brand-sub { color: var(--muted); font-size: 0.85rem; font-style: italic; }
.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }

.searchbox { position: relative; }
.searchbox input {
  width: min(34vw, 340px); padding: 0.45rem 0.9rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg); color: var(--ink); font-size: 0.9rem;
}
.searchbox input::placeholder { color: var(--muted); }
.search-results {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 60;
  width: min(80vw, 420px); max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(20, 20, 19, 0.18);
  padding: 0.35rem;
}
.search-hit { display: block; width: 100%; text-align: left; padding: 0.5rem 0.65rem; border-radius: 8px; }
.search-hit:hover, .search-hit.active { background: var(--surface-2); }
.search-hit .hit-kind { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; }
.search-hit .hit-title { display: block; font-weight: 600; font-size: 0.92rem; }
.search-hit .hit-sub { color: var(--muted); font-size: 0.83rem; }
.search-empty { padding: 0.75rem; color: var(--muted); font-size: 0.9rem; }

/* ── Tab bar (mobile) ───────────────────────────────── */
.tabbar { display: none; flex: none; background: var(--surface); border-bottom: 1px solid var(--border); }
.tabbar button {
  flex: 1; padding: 0.6rem 0; font-size: 0.9rem; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabbar button[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Three-panel layout ─────────────────────────────── */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 250px minmax(0, 1fr) 280px;
}
.rail {
  overflow-y: auto; padding: 1.1rem 0.9rem 4rem;
  background: var(--surface);
}
.rail-sources { border-right: 1px solid var(--border); }
.rail-studio { border-left: 1px solid var(--border); }
.rail-title {
  font-family: var(--font-display); font-size: 0.95rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em;
  margin: 0.5rem 0.35rem 0.6rem; font-variant: small-caps;
}
.rail-title + .rail-title, .topics-list + .rail-title { margin-top: 1.4rem; }

.sources-list { list-style: none; margin: 0; padding: 0; }
.sources-list a {
  display: flex; gap: 0.5rem; align-items: baseline;
  padding: 0.42rem 0.5rem; border-radius: 8px;
  color: var(--ink); text-decoration: none; font-size: 0.88rem; line-height: 1.35;
}
.sources-list a:hover { background: var(--surface-2); }
.sources-list a.active { background: var(--surface-2); box-shadow: inset 2px 0 0 var(--accent); }
.sources-list .src-icon { flex: none; }
.sources-list .src-meta { display: block; color: var(--muted); font-size: 0.76rem; }

.studio-list { display: flex; flex-direction: column; gap: 2px; }
.studio-list a, .topics-list a {
  display: flex; align-items: baseline; gap: 0.45rem;
  padding: 0.4rem 0.5rem; border-radius: 8px;
  color: var(--ink); text-decoration: none; font-size: 0.9rem;
}
.studio-list a:hover, .topics-list a:hover { background: var(--surface-2); }
.studio-list a.active, .topics-list a.active { background: var(--surface-2); box-shadow: inset 2px 0 0 var(--accent); }
.studio-list .art-icon { flex: none; width: 1.2em; text-align: center; }

.topics-list .theme-label {
  margin: 0.9rem 0.35rem 0.25rem; font-size: 0.76rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em;
}
.topics-list .read-check { margin-left: auto; font-size: 0.75rem; color: var(--ok); }

/* ── Reader ─────────────────────────────────────────── */
.reader { overflow-y: auto; min-width: 0; }
.doc {
  max-width: 72ch; margin: 0 auto; padding: 2.2rem 2rem 7rem;
}
.doc h1 {
  font-family: var(--font-display); font-size: 1.9rem; line-height: 1.25;
  margin: 0 0 0.4rem; font-weight: 650;
}
.doc h2 {
  font-family: var(--font-display); font-size: 1.35rem; margin: 2rem 0 0.6rem;
  font-weight: 600;
}
.doc h3 { font-size: 1.05rem; margin: 1.4rem 0 0.4rem; }
.doc .thesis {
  font-size: 1.06rem; color: var(--muted); font-style: italic;
  margin: 0 0 1.2rem; line-height: 1.55;
}
.doc .doc-kicker {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--accent); font-weight: 600; margin-bottom: 0.5rem;
}
.doc p { margin: 0.75rem 0; }
.doc ul, .doc ol { margin: 0.6rem 0; padding-left: 1.4rem; }
.doc li { margin: 0.3rem 0; }
.doc code {
  font-family: var(--font-mono); font-size: 0.86em;
  background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px;
}
.doc hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

.keyideas { margin: 1.1rem 0 1.6rem; padding: 1rem 1.2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.keyideas h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.keyideas ul { margin: 0; }

/* Typed blocks */
.blk-def {
  margin: 1.1rem 0; padding: 0.9rem 1.1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--radius);
}
.blk-def .def-term { font-weight: 700; font-family: var(--font-display); font-size: 1.02rem; }
.blk-def .def-plain { color: var(--muted); font-size: 0.9rem; margin-top: 0.35rem; }
.blk-def .def-plain::before { content: "In plain words — "; font-style: italic; }

.blk-formula {
  margin: 1.2rem 0; padding: 1rem 1.2rem; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto;
}
.blk-formula .formula-tex { font-family: var(--font-mono); font-size: 1.02rem; }
.blk-formula img { max-width: 100%; }
.blk-formula .formula-plain, .blk-formula .formula-note { color: var(--muted); font-size: 0.86rem; margin-top: 0.5rem; text-align: center; }

.blk-callout {
  margin: 1.1rem 0; padding: 0.85rem 1.1rem;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface);
}
.blk-callout .co-label {
  font-size: 0.76rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
  display: block; margin-bottom: 0.25rem;
}
.blk-callout.co-intuition { border-left: 3px solid var(--ok); }
.blk-callout.co-intuition .co-label { color: var(--ok); }
.blk-callout.co-warning { border-left: 3px solid var(--warn); }
.blk-callout.co-warning .co-label { color: var(--warn); }
.blk-callout.co-example { border-left: 3px solid var(--muted); }
.blk-callout.co-example .co-label { color: var(--muted); }

.blk-quote {
  margin: 1.2rem 0; padding: 0.4rem 0 0.4rem 1.1rem;
  border-left: 3px solid var(--accent); color: var(--muted); font-style: italic;
}
.blk-quote .quote-ref { display: block; font-style: normal; font-size: 0.82rem; margin-top: 0.3rem; }

.blk-table { margin: 1.2rem 0; overflow-x: auto; }
.blk-table table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.blk-table th {
  text-align: left; font-family: var(--font-display);
  border-bottom: 2px solid var(--border); padding: 0.45rem 0.7rem;
}
.blk-table td { border-bottom: 1px solid var(--border); padding: 0.45rem 0.7rem; vertical-align: top; }
.blk-table tr:nth-child(even) td { background: var(--surface); }

.blk-figure { margin: 1.4rem 0; text-align: center; }
.blk-figure img { max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); }
.blk-figure figcaption { color: var(--muted); font-size: 0.85rem; margin-top: 0.45rem; }

/* Citation chips */
.cite-chip {
  display: inline-block; vertical-align: super; font-size: 0.68em; line-height: 1;
  background: var(--surface-2); color: var(--accent);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 0.15em 0.5em; margin: 0 0.12em; cursor: pointer; font-weight: 600;
  transition: background 160ms ease;
}
.cite-chip:hover { background: var(--accent); color: var(--on-accent); }

.cite-popover {
  position: fixed; z-index: 90; width: min(88vw, 380px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 10px 36px rgba(20, 20, 19, 0.22);
  padding: 0.9rem 1rem; font-size: 0.88rem;
}
.cite-popover .cp-source { font-weight: 700; font-family: var(--font-display); }
.cite-popover .cp-loc { color: var(--muted); font-size: 0.8rem; margin-top: 0.1rem; }
.cite-popover .cp-quote {
  margin: 0.55rem 0; padding-left: 0.75rem; border-left: 2px solid var(--accent);
  font-style: italic; color: var(--muted);
}
.cite-popover a { font-size: 0.85rem; }

/* Sources & citations list at page foot */
.cite-foot { margin-top: 2.4rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.cite-foot h2 { font-size: 1.05rem; margin-top: 0; }
.cite-foot ol { font-size: 0.88rem; color: var(--muted); }
.cite-foot .cite-n { color: var(--accent); font-weight: 600; }

/* Related topics */
.related-list { list-style: none; padding: 0; margin: 0.6rem 0; }
.related-list li { margin: 0.55rem 0; }
.related-list .rel-kind {
  display: inline-block; font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--accent); margin-right: 0.4rem;
}
.related-list .rel-why { display: block; color: var(--muted); font-size: 0.85rem; }

/* Overview page */
.stats-row { display: flex; gap: 0.9rem; flex-wrap: wrap; margin: 1.2rem 0; }
.stat-card {
  flex: 1 1 8rem; padding: 0.85rem 1rem; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.stat-card .stat-n { font-family: var(--font-display); font-size: 1.6rem; font-weight: 650; display: block; }
.stat-card .stat-label { color: var(--muted); font-size: 0.82rem; }
.start-here { margin: 1rem 0; }
.start-here a { font-weight: 600; }
.start-here .why { color: var(--muted); font-size: 0.88rem; }
.theme-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0.8rem; margin: 1.2rem 0; }
.theme-card {
  padding: 0.9rem 1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.theme-card h3 { margin: 0 0 0.35rem; font-family: var(--font-display); font-size: 1rem; }
.theme-card a { display: block; font-size: 0.87rem; margin: 0.2rem 0; }

/* Source guide */
.src-facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; font-size: 0.9rem; margin: 1rem 0; }
.src-facts dt { color: var(--muted); }
.src-facts dd { margin: 0; overflow-wrap: anywhere; }
.fetch-badge {
  display: inline-block; font-size: 0.76rem; font-weight: 600;
  padding: 0.1em 0.6em; border-radius: 999px; border: 1px solid var(--border);
}
.fetch-badge.ok { color: var(--ok); }
.fetch-badge.no { color: var(--warn); }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.6rem 0; }
.chip-row a {
  font-size: 0.83rem; text-decoration: none; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 0.18em 0.7em; border-radius: 999px;
}
.chip-row a:hover { border-color: var(--accent); color: var(--accent); }

/* Study guide reveal */
.reveal-item { margin: 0.9rem 0; }
.reveal-item summary { cursor: pointer; font-weight: 600; }
.reveal-item[open] summary { color: var(--accent); }
.reveal-item .answer { margin: 0.5rem 0 0.2rem 1rem; }

/* Mind map — collapsible LTR tree */
.mindmap { margin: 1.2rem 0; }
.mindmap ul { list-style: none; margin: 0; padding-left: 1.6rem; border-left: 1px solid var(--border); }
.mindmap > ul { padding-left: 0; border-left: none; }
.mindmap li { position: relative; margin: 0.35rem 0; }
.mindmap .mm-row { display: flex; align-items: center; gap: 0.4rem; }
.mindmap .mm-toggle {
  flex: none; width: 1.35rem; height: 1.35rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 0.7rem; line-height: 1; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.mindmap .mm-toggle[aria-expanded="true"] { color: var(--accent); }
.mindmap .mm-label { padding: 0.15rem 0.5rem; border-radius: 8px; font-size: 0.93rem; }
.mindmap .mm-root > .mm-row .mm-label { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.mindmap .mm-theme-label { font-weight: 600; }
.mindmap a.mm-label { text-decoration: none; color: var(--ink); border: 1px solid var(--border); background: var(--surface); }
.mindmap a.mm-label:hover { border-color: var(--accent); color: var(--accent); }
.mindmap .mm-leaf { color: var(--muted); font-size: 0.86rem; }

/* Flashcards */
.flash-wrap { max-width: 34rem; margin: 1.4rem auto; text-align: center; }
.flash-card {
  width: 100%; min-height: 11rem; padding: 1.4rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  font-size: 1.08rem; cursor: pointer;
}
.flash-card .side-label {
  position: absolute; top: 0.7rem; left: 1rem;
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
}
.flash-card { position: relative; }
.flash-card.back { border-left: 3px solid var(--accent); }
.flash-meta { color: var(--muted); font-size: 0.85rem; margin: 0.7rem 0; }
.flash-controls { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

.btn {
  padding: 0.45rem 1.1rem; border-radius: 999px; font-size: 0.9rem;
  border: 1px solid var(--border); background: var(--surface);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.06); color: var(--on-accent); }

/* Quiz */
.quiz-q { margin: 1.5rem 0; padding: 1.1rem 1.2rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.quiz-q .q-text { font-weight: 600; margin: 0 0 0.7rem; }
.quiz-q .q-topic { float: right; font-size: 0.74rem; color: var(--muted); }
.quiz-opt {
  display: block; width: 100%; text-align: left;
  margin: 0.35rem 0; padding: 0.55rem 0.8rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); font-size: 0.93rem;
}
.quiz-opt:hover:not([disabled]) { border-color: var(--accent); }
.quiz-opt.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--bg)); }
.quiz-opt.wrong { border-color: var(--err); background: color-mix(in srgb, var(--err) 12%, var(--bg)); }
.quiz-why { margin-top: 0.6rem; font-size: 0.88rem; color: var(--muted); border-left: 2px solid var(--accent); padding-left: 0.7rem; }
.quiz-score { text-align: center; font-size: 1.02rem; margin: 1.4rem 0; }

/* Misc */
.doc .muted { color: var(--muted); }
.notfound { text-align: center; color: var(--muted); margin-top: 4rem; }
.skeleton { color: var(--muted); text-align: center; margin-top: 4rem; }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 1000px) {
  .tabbar { display: flex; }
  .layout { display: block; overflow-y: auto; }
  .rail, .reader { display: none; }
  .layout[data-tab="sources"] .rail-sources { display: block; border: none; }
  .layout[data-tab="reader"] .reader { display: block; }
  .layout[data-tab="studio"] .rail-studio { display: block; border: none; }
  .doc { padding: 1.4rem 1.1rem 7rem; }
  .searchbox input { width: 38vw; }
}
@media print {
  .topbar, .tabbar, .rail, .cite-popover { display: none !important; }
  .layout { display: block; }
  .reader { overflow: visible; }
  body { background: #fff; color: #000; }
}
