:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1c1f2b;
  --muted: #6b7080;
  --border: #dfe2ea;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --ok: #2b8a3e;
  --warn: #b7791f;
  --danger: #c92a2a;
  --chip: #eef0f7;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --card: #1b1e29;
    --text: #e8eaf2;
    --muted: #9aa0b4;
    --border: #2c3040;
    --accent: #6f8cff;
    --accent-text: #0d1020;
    --ok: #69db7c;
    --warn: #ffd43b;
    --danger: #ff6b6b;
    --chip: #262a38;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar nav { display: flex; gap: 4px; }
.topbar button {
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.topbar nav button.active { background: var(--chip); }
.brand { font-weight: 700; font-size: 1.05rem; }

.banner, .notice {
  margin: 12px 16px 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--chip);
  border-left: 4px solid var(--warn);
  font-size: 0.95rem;
}
.notice { margin: 0 0 12px; }
.banner.error { border-left-color: var(--danger); }

.button {
  display: inline-block;
  font: inherit;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}
.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.button.danger { color: var(--danger); }
.button.block { display: block; width: 100%; padding: 14px; font-size: 1.05rem; }
.button:disabled { opacity: 0.6; cursor: default; }
.small-btn { padding: 8px 12px; }
button.link { background: none; border: none; color: var(--accent); font: inherit; padding: 0; text-decoration: underline; cursor: pointer; }

.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.row input[type="text"], .row input[type="password"] { flex: 1; min-width: 0; }

input, select {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.form fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 16px; }
.form legend { padding: 0 6px; font-weight: 600; }
.form label { display: block; margin: 10px 0 4px; font-size: 0.9rem; color: var(--muted); }

.history { list-style: none; padding: 0; margin: 0; }
.history li + li { margin-top: 8px; }
.history-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title badge" "sub badge";
  gap: 2px 10px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
}
.history-title { grid-area: title; font-weight: 600; }
.history-sub { grid-area: sub; color: var(--muted); font-size: 0.85rem; }
.history-item .badge { grid-area: badge; align-self: center; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--chip);
}
.badge.muted { color: var(--muted); font-weight: 500; }
.verdict-ok { background: var(--ok); color: #fff; }
.verdict-borderline { background: var(--warn); color: #1c1f2b; }
.verdict-not_yet { background: var(--danger); color: #fff; }

.book-card {
  display: flex;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 8px 0 12px;
  min-height: 60px;
}
.cover { width: 84px; height: auto; align-self: flex-start; border-radius: 6px; flex-shrink: 0; }
.book-text { min-width: 0; flex: 1; }
.book-title { margin: 0 0 2px; font-size: 1.15rem; }
.book-authors { margin: 0 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { background: var(--chip); border-radius: 999px; padding: 2px 10px; font-size: 0.8rem; }
.description summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.description p { font-size: 0.9rem; }

.log {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.85rem;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 12px;
}
.log-line { padding: 2px 0; color: var(--muted); }
.log-line.ok { color: var(--ok); }
.log-line.warn { color: var(--warn); }
.log-line.muted { opacity: 0.7; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 560px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

/* ---------- research / report ---------- */
.status { color: var(--muted); font-size: 0.9rem; margin: 4px 0 10px; }
.status::before { content: "⏳ "; }

.verdict-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 6px solid var(--muted);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 8px 0 12px;
}
.verdict-card.v-ok { border-left-color: var(--ok); }
.verdict-card.v-borderline { border-left-color: var(--warn); }
.verdict-card.v-not_yet { border-left-color: var(--danger); }
.verdict-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.verdict-word { font-size: 1.5rem; font-weight: 800; }
.v-ok .verdict-word { color: var(--ok); }
.v-borderline .verdict-word { color: var(--warn); }
.v-not_yet .verdict-word { color: var(--danger); }
.verdict-for { color: var(--muted); font-size: 0.9rem; }
.verdict-line { margin: 6px 0 10px; }
.meters { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 12px; align-items: center; font-size: 0.9rem; }
.meter-label { color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--chip); border: 1px solid var(--border); }
.dot.on { background: var(--accent); border-color: var(--accent); }
.meter-spice .dot.on { background: var(--danger); border-color: var(--danger); }
.meter-note { font-size: 0.85rem; }
.verdict-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.report { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 16px 10px; margin-bottom: 12px; }
.report h3 { font-size: 1.05rem; margin: 16px 0 6px; }
.report h4 { font-size: 0.95rem; margin: 12px 0 4px; }
.report ul, .report ol { padding-left: 20px; margin: 6px 0; }
.report li { margin: 3px 0; }
.report pre { overflow-x: auto; background: var(--chip); padding: 8px; border-radius: 8px; font-size: 0.85rem; }
.report a { color: var(--accent); }
.report.streaming::after { content: "▍"; color: var(--accent); animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

.sources { margin-bottom: 12px; }
.sources h3 { font-size: 1rem; margin: 8px 0; }
.sources ul { list-style: none; padding: 0; margin: 0; }
.sources li { padding: 6px 0; border-top: 1px solid var(--border); font-size: 0.9rem; }
.sources a { color: var(--accent); word-break: break-all; }
.sources .note { color: var(--muted); display: block; font-size: 0.85rem; }
