/* Book Summary. Two colour jobs matter more than the rest of the sheet:
 *
 *   - a confirmed fact and an unverified fact must be distinguishable at a
 *     glance and WITHOUT colour, because the difference between them is the
 *     whole point of the app. Both carry a word, not just a hue.
 *   - a false citation must not read as a slightly worse version of unverified.
 *     It gets the alert treatment, a border and a full sentence, because it is
 *     the failure this app was built to surface. */

:root {
  --bg: #10141b;
  --panel: #171d26;
  --panel2: #1d2531;
  --line: #2b3542;
  --ink: #e7edf5;
  --dim: #9aa8ba;
  --faint: #6f7d90;
  --accent: #7fb0e8;
  --accent2: #d9a441;
  --ok: #63c08a;
  --okbg: #16301f;
  --warn: #e0a34a;
  --warnbg: #33260f;
  --bad: #e8736a;
  --badbg: #38191a;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --panel2: #f1eee7;
  --line: #ddd7ca;
  --ink: #1d2229;
  --dim: #5c6675;
  --faint: #7b8494;
  --accent: #2a5f9e;
  --accent2: #9a6b12;
  --ok: #1f7a48;
  --okbg: #e2f3e8;
  --warn: #8a5f11;
  --warnbg: #faefd8;
  --bad: #a83027;
  --badbg: #fbe6e3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  font: 16px/1.6 ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, legend, .factk, .pill, .tab, button, input, select, textarea, .mono {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.9rem; line-height: 1.25; margin: 0 0 .6rem; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; margin: 0 0 .5rem; }
h3 { font-size: 1.02rem; margin: 0 0 .45rem; }
h4 { font-size: .92rem; margin: 0 0 .35rem; color: var(--dim); text-transform: uppercase;
     letter-spacing: .06em; }

a { color: var(--accent); }
a:hover { text-decoration: none; }

.muted { color: var(--dim); }
.small { font-size: .87rem; }
.mono { font-family: var(--mono); font-size: .85rem; }
.hidden { display: none !important; }

/* --- header ------------------------------------------------------------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: center;
  justify-content: space-between;
  padding: .7rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: .5rem; font-size: .95rem; }
.brand strong { font-family: ui-sans-serif, system-ui, sans-serif; }
.backlink { text-decoration: none; color: var(--dim); }
.backlink:hover { color: var(--accent); }
.sep { color: var(--faint); }

.topactions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.credits { font-size: .85rem; color: var(--dim); font-family: var(--mono); }
.topup {
  font-size: .82rem;
  padding: .28rem .6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-decoration: none;
}

/* --- controls ----------------------------------------------------------- */

button {
  font-size: .9rem;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--ink);
  padding: .42rem .8rem;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }

.ghost { background: transparent; }
.ghost.small, .mini { font-size: .8rem; padding: .26rem .55rem; }

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0c1119;
  font-weight: 600;
}
:root[data-theme="light"] .primary { color: #fff; }

.secondary { border-color: var(--accent); color: var(--accent); background: transparent; }
.big { padding: .6rem 1.1rem; font-size: .98rem; }

input[type="text"], input[type="search"], select, textarea {
  width: 100%;
  font-size: .93rem;
  padding: .48rem .6rem;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { font-family: inherit; resize: vertical; }
label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: .25rem;
        font-family: ui-sans-serif, system-ui, sans-serif; }

/* --- layout ------------------------------------------------------------- */

main { max-width: 960px; margin: 0 auto; padding: 1.4rem 1.1rem 3rem; }

.hero { margin-bottom: 1.4rem; }
.lede { font-size: 1.04rem; color: var(--dim); max-width: 60ch; }
.lede.small { font-size: .93rem; }
.herobtns { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0 .5rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1.2rem;
}

.fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .9rem;
            margin: 0 0 1rem; }
legend { font-size: .82rem; text-transform: uppercase; letter-spacing: .07em;
         color: var(--dim); padding: 0 .4rem; }

.field { margin-bottom: .8rem; }
.field .muted { margin: .25rem 0 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem; }

@media (max-width: 720px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  h1 { font-size: 1.5rem; }
  main { padding: 1rem .8rem 2.4rem; }
}

.runrow { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; margin-top: .6rem; }
.meter { font-size: .85rem; color: var(--dim); font-family: var(--mono); }

.labelrow { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }

.warn {
  background: var(--warnbg);
  border-left: 3px solid var(--warn);
  padding: .5rem .7rem;
  border-radius: 5px;
  font-size: .88rem;
  margin: .6rem 0 0;
}
.gate {
  background: var(--badbg);
  border-left: 3px solid var(--bad);
  padding: .5rem .7rem;
  border-radius: 5px;
  font-size: .88rem;
  margin: .6rem 0 0;
}
.note {
  background: var(--panel2);
  border-left: 3px solid var(--accent);
  padding: .5rem .7rem;
  border-radius: 5px;
  font-size: .9rem;
  margin: .6rem 0 0;
}

.revisebox { background: var(--panel2); border: 1px dashed var(--line);
             border-radius: 8px; padding: .8rem; margin-bottom: 1rem; }

/* --- the ask guard ------------------------------------------------------ */

.guard {
  border: 1px solid var(--warn);
  background: var(--warnbg);
  border-radius: 8px;
  padding: .8rem;
  margin-top: .6rem;
}
.guard.blocked { border-color: var(--bad); background: var(--badbg); }
.guardhead { display: flex; justify-content: space-between; align-items: center;
             gap: .6rem; margin-bottom: .4rem; }
.guard p { margin: .3rem 0; font-size: .9rem; }
.guardacts { display: flex; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }

/* --- pills -------------------------------------------------------------- */

.pill {
  display: inline-block;
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .03em;
  padding: .12rem .45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.ok { background: var(--okbg); border-color: var(--ok); color: var(--ok); }
.pill.warn { background: var(--warnbg); border-color: var(--warn); color: var(--warn);
             border-left-width: 1px; padding: .12rem .45rem; margin: 0; }
.pill.bad { background: var(--badbg); border-color: var(--bad); color: var(--bad); }
.pill.info { background: var(--panel2); color: var(--dim); }

/* --- progress ----------------------------------------------------------- */

.progress .prow { display: flex; justify-content: space-between; align-items: center; }
.steps { list-style: none; margin: .7rem 0 0; padding: 0; }
.step { display: flex; gap: .55rem; align-items: baseline; padding: .16rem 0;
        font-size: .89rem; color: var(--faint); }
.step.now { color: var(--ink); font-weight: 600; }
.step.done { color: var(--dim); }
.step-ic { width: 1rem; color: var(--accent); }

/* --- result ------------------------------------------------------------- */

.resulthead { display: flex; flex-wrap: wrap; gap: .7rem; justify-content: space-between;
              align-items: flex-start; margin-bottom: .8rem; }
.resulthead h2 { margin: 0; }

.section { margin: 1.3rem 0; }
.section:first-child { margin-top: 0; }
.listhead { display: flex; justify-content: space-between; align-items: center;
            gap: .6rem; flex-wrap: wrap; }

.factrow {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .5rem;
  margin-bottom: 1rem;
}
@media (max-width: 720px) { .factrow { grid-template-columns: repeat(2, 1fr); } }
.fact {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .5rem .6rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.factk { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.factv { font-size: 1.05rem; font-weight: 600; font-family: ui-sans-serif, system-ui, sans-serif; }
.factv.bad { color: var(--bad); }
.factv.ok { color: var(--ok); }

.audit {
  border: 1px solid var(--bad);
  background: var(--badbg);
  border-radius: 8px;
  padding: .8rem;
  margin-bottom: 1rem;
}
.audit.warnonly { border-color: var(--warn); background: var(--warnbg); }
.audit.infoonly { border-color: var(--line); background: var(--panel2); }
.audit h3 { margin-top: 0; }
.audit ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.audit li { margin-bottom: .35rem; font-size: .89rem; }
.audit .where { font-family: var(--mono); font-size: .8rem; color: var(--dim); }

/* --- the claim ledger --------------------------------------------------- */

.claims { display: flex; flex-direction: column; gap: .45rem; margin-top: .6rem; }
.claim {
  display: grid;
  grid-template-columns: 10rem 1fr auto;
  gap: .6rem;
  align-items: baseline;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .5rem .65rem;
  background: var(--panel2);
}
@media (max-width: 720px) { .claim { grid-template-columns: 1fr; } }
.claim.unsupported { border-color: var(--bad); background: var(--badbg); }
.claim.bad-ref { border-color: var(--bad); background: var(--badbg); }
.claim.supported { border-color: var(--ok); }
.claimk { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em;
          color: var(--faint); font-family: ui-sans-serif, system-ui, sans-serif; }
.claimv { font-weight: 600; }
.claimwhy { grid-column: 1 / -1; font-size: .86rem; color: var(--dim); margin: .2rem 0 0; }
.claim.unsupported .claimwhy, .claim.bad-ref .claimwhy { color: var(--ink); }

/* --- retrieved sources -------------------------------------------------- */

.sources { display: flex; flex-direction: column; gap: .6rem; margin-top: .6rem; }
.source {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .6rem .7rem;
  background: var(--panel2);
}
.source.chosen { border-color: var(--accent); }
.sourcehead { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.sourcehead a { font-weight: 600; }
.srcid { font-family: var(--mono); font-size: .76rem; color: var(--faint);
         border: 1px solid var(--line); border-radius: 4px; padding: 0 .3rem; }
.abstract { font-size: .89rem; margin: .35rem 0; }
.states { font-size: .8rem; color: var(--dim); font-family: var(--mono); }

/* --- search hits (before the run) --------------------------------------- */

.hits { display: flex; flex-direction: column; gap: .5rem; margin-top: .7rem; }
.hit {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .55rem .7rem;
  background: var(--panel2);
  display: flex;
  gap: .6rem;
  align-items: flex-start;
}
.hit.picked { border-color: var(--accent); background: var(--panel); }
.hit input[type="checkbox"] { width: auto; margin-top: .35rem; flex: none; }
.hitbody { flex: 1; min-width: 0; }
.hitscore { font-family: var(--mono); font-size: .76rem; color: var(--faint); }

/* --- prose sections ----------------------------------------------------- */

.rows { display: flex; flex-direction: column; gap: .5rem; }
.row {
  border-left: 3px solid var(--line);
  padding: .1rem 0 .1rem .7rem;
}
.row strong { display: block; font-family: ui-sans-serif, system-ui, sans-serif;
              font-size: .9rem; }
.row .rownote { color: var(--dim); font-size: .87rem; }

.cards { display: flex; flex-direction: column; gap: .6rem; }
.themecard {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .65rem .75rem;
  background: var(--panel2);
}
.themecard.flagged { border-color: var(--bad); }
.themecard h4 { color: var(--ink); text-transform: none; letter-spacing: 0;
                font-size: 1rem; margin-bottom: .3rem; }
.themecard .where { font-size: .86rem; color: var(--dim); margin: .35rem 0 0; }

.deflist { margin: 0; }
.deflist dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em;
              color: var(--faint); font-family: ui-sans-serif, system-ui, sans-serif;
              margin-top: .55rem; }
.deflist dd { margin: .15rem 0 0; font-size: .92rem; }

.plainlist { margin: .3rem 0 0; padding-left: 1.1rem; }
.plainlist li { margin-bottom: .3rem; }

.nextlist { list-style: none; margin: .4rem 0 0; padding: 0; }
.nextlist li { border-bottom: 1px solid var(--line); padding: .45rem 0; }
.nextlist li:last-child { border-bottom: none; }
.nextlist strong { font-family: ui-sans-serif, system-ui, sans-serif; }
.nextlist .rel { color: var(--dim); font-size: .88rem; display: block; }

.quotes { display: flex; flex-direction: column; gap: .6rem; }
.quote {
  border-left: 3px solid var(--accent2);
  padding: .3rem 0 .3rem .8rem;
}
.quote.flagged { border-color: var(--bad); background: var(--badbg); padding: .5rem .7rem;
                 border-radius: 0 6px 6px 0; }
.quote blockquote { margin: 0; font-style: italic; }
.quote .attrib { font-size: .85rem; color: var(--dim); margin: .3rem 0 0; }

.notfound {
  border: 1px solid var(--warn);
  background: var(--warnbg);
  border-radius: 8px;
  padding: 1rem;
}
.notfound h3 { margin-top: 0; }

.raw { white-space: pre-wrap; word-break: break-word; font-family: var(--mono);
       font-size: .82rem; background: var(--panel2); border: 1px solid var(--line);
       border-radius: 7px; padding: .7rem; max-height: 30rem; overflow: auto; }

/* --- history ------------------------------------------------------------ */

.history { list-style: none; margin: 0; padding: 0; }
.history li { border-bottom: 1px solid var(--line); padding: .6rem 0; }
.history li:last-child { border-bottom: none; }

/* --- docs pages --------------------------------------------------------- */

.doc { max-width: 900px; }
.doc h1 { margin-top: .5rem; }
.doc h2 { margin-top: 1.8rem; }
.doc pre { background: var(--panel2); border: 1px solid var(--line); border-radius: 7px;
           padding: .7rem; overflow-x: auto; font-family: var(--mono); font-size: .82rem; }
.doc code { font-family: var(--mono); font-size: .86em; }
.doc table { border-collapse: collapse; width: 100%; font-size: .89rem; display: block;
             overflow-x: auto; }
.doc th, .doc td { border: 1px solid var(--line); padding: .4rem .55rem; text-align: left; }
.codegroup { margin: .6rem 0 1rem; }
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .3rem; }
.tab { font-size: .78rem; padding: .22rem .5rem; border: 1px solid var(--line);
       border-radius: 5px; background: transparent; color: var(--dim); cursor: pointer; }
.tab.active { border-color: var(--accent); color: var(--accent); }

.statebox { border: 1px solid var(--line); border-radius: 8px; padding: .8rem;
            background: var(--panel2); margin: .8rem 0; }
.tokenrow { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0; }
.tokenbox { flex: 1; min-width: 14rem; font-family: var(--mono); font-size: .82rem;
            background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
            padding: .5rem .6rem; word-break: break-all; }

/* --- footer and toasts -------------------------------------------------- */

.foot { border-top: 1px solid var(--line); padding: 1.2rem 1.1rem 2rem;
        max-width: 960px; margin: 0 auto; }
.foot p { margin: .3rem 0; font-size: .88rem; }

.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column;
          gap: .4rem; z-index: 50; max-width: 26rem; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left-width: 3px;
         border-radius: 7px; padding: .55rem .7rem; font-size: .88rem;
         box-shadow: 0 6px 18px rgba(0,0,0,.28); transition: opacity .5s; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--bad); }
.toast.gone { opacity: 0; }
.toast a { margin-left: .4rem; }

@media print {
  .topbar, .foot, .toasts, form, #historyZone, #how, #progressPanel,
  .topactions, .herobtns, .hero { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: none; padding: 0; }
}
