/* VedaScholarLens v1 (M1 + M2) */
:root, html[data-theme="dark"] {
  --bg: #14161a;
  --bg-soft: #1b1e24;
  --panel: #1e222a;
  --ink: #e8e6e1;
  --ink-dim: #a09c94;
  --border: #2e333d;
  --accent: #e8792b;
  --accent-dim: rgba(232, 121, 43, 0.65);
  --accent-soft: rgba(232, 121, 43, 0.12);
  --hover: rgba(232, 121, 43, 0.07);
  --shadow: rgba(0, 0, 0, 0.4);
  --ok: #4caf7d;
  --active: #4f9cf0;
  --active-soft: rgba(79, 156, 240, 0.14);
}
html[data-theme="light"] {
  --bg: #faf8f5;
  --bg-soft: #f1eee9;
  --panel: #ffffff;
  --ink: #23211e;
  --ink-dim: #6d675e;
  --border: #ddd7cd;
  --accent: #c9611a;
  --accent-dim: rgba(201, 97, 26, 0.6);
  --accent-soft: rgba(201, 97, 26, 0.10);
  --hover: rgba(201, 97, 26, 0.06);
  --shadow: rgba(60, 50, 30, 0.15);
  --ok: #2e8f5f;
  --active: #2b6cb0;
  --active-soft: rgba(43, 108, 176, 0.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.brand, a.brand { font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; color: var(--ink); }
a.brand:hover { text-decoration: none; color: var(--ink); }
.brand .lens { color: var(--accent); }
.topbar .paper-title {
  flex: 1; text-align: center; font-size: 0.92rem; color: var(--ink-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn {
  background: transparent; color: var(--ink);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 13px; font-size: 0.85rem; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- viewer layout ---------- */
.viewer-grid {
  display: grid;
  grid-template-columns: var(--toc-w, 175px) 8px minmax(0, 1fr) 8px var(--panel-w, 420px);
  gap: 0;
  margin: 0 auto;
  align-items: start;
}
.toc {
  position: sticky; top: 58px;
  max-height: calc(100vh - 58px); overflow-y: auto;
  padding: 26px 10px 26px 14px;
  font-size: 0.84rem;
}
.toc h5 { margin: 0 0 10px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.7rem; }
.toc a { display: block; padding: 5px 8px; border-radius: 5px; color: var(--ink); }
.toc a:hover { background: var(--hover); text-decoration: none; color: var(--accent); }
.toc a.current { color: var(--accent); background: var(--accent-soft); }
.toc .hint { margin-top: 22px; color: var(--ink-dim); font-size: 0.76rem; line-height: 1.5; border-top: 1px solid var(--border); padding-top: 14px; }

.paper {
  padding: 34px 40px 120px;
  min-height: 100vh;
  background: var(--bg);
}
.paper-inner { max-width: 860px; margin: 0 auto; font-family: Georgia, "Times New Roman", serif; font-size: 1.02rem; }
.paper-inner h1 { font-size: 1.9rem; margin: 6px 0 2px; line-height: 1.25; }
.paper-inner .meta { color: var(--ink-dim); font-size: 0.86rem; font-family: "Segoe UI", system-ui, sans-serif; margin-bottom: 6px; }
.paper-inner .source-note { color: var(--ink-dim); font-size: 0.8rem; font-style: italic; margin-bottom: 26px; }
.paper-inner h2 { font-size: 1.28rem; margin: 40px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); scroll-margin-top: 74px; }

/* ---------- blocks ---------- */
.block { position: relative; margin: 0 0 16px; border-radius: 8px; }
.block > .block-content { padding: 8px 12px; border-radius: 8px; border-left: 3px solid transparent; }
.block.explainable > .block-content {
  cursor: pointer;
  border-left-color: var(--accent-dim);
  transition: background 0.12s, border-color 0.12s;
}
.block.explainable:hover > .block-content { background: var(--hover); border-left-color: var(--accent); }
.block.explainable.active > .block-content { background: var(--active-soft); border-left-color: var(--active); }
.block.explainable::after {
  content: "\2315";
  position: absolute; top: 8px; right: 10px;
  font-size: 0.85rem; color: var(--accent); opacity: 0.35;
  transition: opacity 0.12s;
}
.block.explainable:hover::after { opacity: 0.9; }
.block.explainable.active::after { opacity: 0.9; color: var(--active); }

.block p { margin: 0; }
.block h3 { margin: 26px 0 4px; font-size: 1.12rem; }
.block h4 { margin: 20px 0 4px; font-size: 1.0rem; }
.block.eq .block-content { text-align: center; padding: 14px 12px; font-size: 1.08rem; }
.block table { border-collapse: collapse; margin: 6px auto; font-size: 0.92rem; font-family: "Segoe UI", system-ui, sans-serif; }
.block th, .block td { border: 1px solid var(--border); padding: 5px 14px; text-align: center; }
.block thead th, .block tbody tr:last-child th { background: var(--bg-soft); }
.block figure { margin: 6px 0; text-align: center; }
.block img { max-width: 100%; border-radius: 6px; background: #fff; }
.block figcaption, .block .tcaption { color: var(--ink-dim); font-size: 0.82rem; margin-top: 6px; text-align: center; font-family: "Segoe UI", system-ui, sans-serif; }

/* ---------- explanation panel ---------- */
.panel {
  position: sticky; top: 58px;
  min-height: calc(100vh - 58px);
  max-height: calc(100vh - 58px); overflow-y: auto;
  padding: 26px 26px 40px;
  background: var(--bg-soft);
}
.panel .placeholder { color: var(--ink-dim); font-size: 0.92rem; margin-top: 30px; text-align: center; padding: 0 12px; }
.panel .placeholder .big { font-size: 2rem; display: block; margin-bottom: 10px; color: var(--accent); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panel-head h5 { margin: 0; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.7rem; }
.panel-nav { display: flex; gap: 6px; }
.panel-nav .btn { padding: 3px 10px; font-size: 0.78rem; }
.gist {
  font-weight: 600; font-size: 1.02rem; line-height: 1.45;
  padding: 12px 14px; border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 8px 8px 0; margin-bottom: 14px;
}
.expl-body { font-size: 0.94rem; }
.expl-body p { margin: 0 0 12px; }
.expl-body em { color: var(--accent); font-style: normal; font-weight: 600; }
.expl-body img { max-width: 100%; border-radius: 6px; background: #fff; margin: 8px 0; }
.block-ref { color: var(--ink-dim); font-size: 0.76rem; margin-top: 16px; border-top: 1px solid var(--border); padding-top: 10px; }

/* ---------- glossary drawer ---------- */
.drawer-mask { position: fixed; inset: 0; background: var(--shadow); z-index: 60; display: none; }
.drawer-mask.open { display: block; }
.drawer {
  position: fixed; top: 0; right: -520px; width: min(500px, 92vw); height: 100vh;
  background: var(--panel); border-left: 1px solid var(--border);
  z-index: 70; transition: right 0.22s ease; overflow-y: auto; padding: 22px 26px;
}
.drawer.open { right: 0; }
.drawer h4 { margin: 0 0 6px; }
.drawer dl dt { font-weight: 600; color: var(--accent); margin-top: 12px; }
.drawer dl dd { margin: 2px 0 0 0; font-size: 0.9rem; color: var(--ink); }
.drawer .close-x { float: right; }

/* ---------- modal prompt ---------- */
.prompt-mask {
  position: fixed; inset: 0; background: var(--shadow); z-index: 80;
  display: none; align-items: center; justify-content: center;
}
.prompt-mask.open { display: flex; }
.prompt {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  max-width: 420px; width: 92vw; padding: 26px 28px; text-align: center;
}
.prompt h3 { margin: 0 0 8px; }
.prompt p { margin: 0 0 18px; color: var(--ink-dim); font-size: 0.92rem; }
.prompt .row { display: flex; gap: 10px; justify-content: center; }

/* ---------- landing ---------- */
.landing { max-width: 900px; margin: 0 auto; padding: 60px 24px 80px; }
.landing h1 { font-size: 2.2rem; margin: 0 0 6px; }
.landing .tagline { color: var(--ink-dim); font-size: 1.05rem; margin-bottom: 40px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; display: flex; flex-direction: column; gap: 10px;
}
.card h3 { margin: 0; font-size: 1.1rem; }
.card p { margin: 0; color: var(--ink-dim); font-size: 0.9rem; flex: 1; }
.card .btn { align-self: flex-start; }
.card.disabled { opacity: 0.55; }
.landing .privacy, .setup .privacy {
  margin-top: 44px; padding: 16px 20px; border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 8px;
  color: var(--ink-dim); font-size: 0.9rem;
}
.setup .privacy { margin-top: 24px; }

/* ---------- resizable divider ---------- */
.resizer {
  position: sticky; top: 58px;
  height: calc(100vh - 58px);
  cursor: col-resize;
  display: flex; align-items: stretch; justify-content: center;
  touch-action: none;
}
.resizer::after {
  content: ""; width: 2px; background: var(--border); border-radius: 2px;
}
.resizer:hover::after, .resizer.dragging::after { background: var(--accent); }

/* ---------- creator ---------- */
.creator-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 8px var(--panel-w, 480px);
  margin: 0 auto; align-items: start;
}
.creator-grid .paper { border: 0; }
.editor {
  position: sticky; top: 58px;
  min-height: calc(100vh - 58px);
  max-height: calc(100vh - 58px); overflow-y: auto;
  padding: 22px 26px 60px; background: var(--bg-soft);
}
.editor h5 { margin: 0 0 10px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.7rem; }
.editor label { display: block; font-size: 0.78rem; color: var(--ink-dim); margin: 14px 0 4px; }
.editor input[type="text"], .editor textarea {
  width: 100%; background: var(--bg); color: var(--ink);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 8px 10px; font-family: inherit; font-size: 0.9rem;
}
.editor textarea { resize: vertical; min-height: 90px; }
.editor textarea.tall { min-height: 200px; }
.editor .row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.editor .muted { color: var(--ink-dim); font-size: 0.8rem; }
.progress-wrap { margin: 8px 0 4px; }
.progress-bar { height: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); width: 0; transition: width 0.2s; }
.block .status-dot {
  position: absolute; top: 12px; left: -14px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--border);
}
.block.done .status-dot { background: var(--ok); }
.setup { max-width: 900px; margin: 40px auto; padding: 0 24px; }
.setup .card { margin-bottom: 16px; }
.editor .flagged-note {
  border: 1px solid var(--accent); border-radius: 7px; background: var(--accent-soft);
  padding: 8px 10px; font-size: 0.8rem; margin-top: 10px;
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .viewer-grid, .creator-grid { grid-template-columns: minmax(0, 1fr); }
  .toc, .resizer { display: none; }
  .paper { border: 0; padding: 24px 18px 40vh; }
  .panel, .editor {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    max-height: 46vh; border-top: 2px solid var(--accent);
    box-shadow: 0 -8px 30px var(--shadow); z-index: 50; padding: 16px 18px 30px;
  }
  .panel.hidden-mobile { display: none; }
}
