:root {
  --paper: #F3F5F8;
  --surface: #FFFFFF;
  --ink: #16233A;
  --ink-2: #4A5568;
  --rule: #D8DEE8;
  --seal: #B42318;
  --seal-wash: #FBEDEB;
  --ok: #1F7A4D;
  --ok-wash: #E7F4EC;
  --wait: #9A5B06;
  --wait-wash: #FDF1DD;
  --focus: #2457C5;
  --on-seal: #FFFFFF;

  --sans: "Be Vietnam Pro", system-ui, sans-serif;
  --serif: "Literata", Georgia, serif;
  --measure: 68ch;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0E1522;
    --surface: #162033;
    --ink: #E7ECF4;
    --ink-2: #A7B1C2;
    --rule: #2A3650;
    --seal: #F07563;
    --seal-wash: #3A1F22;
    --ok: #5CC28C;
    --ok-wash: #16302A;
    --wait: #E8AE55;
    --wait-wash: #3A2C14;
    --focus: #8FB0FF;
    --on-seal: #2A0F0B;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  display: flex;
  flex-direction: column;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-name { font: 600 17px/1 var(--sans); letter-spacing: -0.01em; }
.brand-seal, .seal {
  display: inline-grid; place-items: center;
  border: 2px solid var(--seal); border-radius: 50%;
  color: var(--seal); font-family: var(--serif); font-weight: 600;
}
.brand-seal { width: 30px; height: 30px; font-size: 16px; transform: rotate(-8deg); }
.topbar-note { margin: 0; font-size: 13px; color: var(--ink-2); text-align: right; }

main { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px); }

/* ---------- empty state ---------- */
.intro { max-width: 760px; padding: clamp(40px, 9vh, 96px) 0 32px; }
.intro-title {
  margin: 0 0 18px;
  font: 500 clamp(30px, 4.6vw, 48px)/1.15 var(--serif);
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.intro-lead { margin: 0 0 32px; max-width: 58ch; font-size: 17px; color: var(--ink-2); }
.examples { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.example {
  text-align: left; background: none; border: 0; padding: 6px 0;
  font-family: var(--serif); font-size: 17px; color: var(--ink);
  border-bottom: 1px dashed var(--rule);
}
.example:hover { border-bottom-color: var(--seal); color: var(--seal); }
body.has-thread .intro { display: none; }

/* ---------- thread ---------- */
.thread { list-style: none; margin: 0; padding: 0; }
.turn {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); gap: 40px;
  padding: 40px 0; border-bottom: 1px solid var(--rule);
}
.turn:first-child { padding-top: 48px; }
.question {
  margin: 0 0 24px; max-width: var(--measure);
  font: 500 clamp(21px, 2.4vw, 26px)/1.35 var(--serif); letter-spacing: -0.01em;
}

.progress { color: var(--ink-2); }
.steps { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 15px; }
.steps li { display: inline-flex; align-items: center; gap: 8px; opacity: .45; transition: opacity .3s; }
.steps li::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%; border: 2px solid currentColor; flex: none;
}
.steps li.active { opacity: 1; color: var(--ink); }
.steps li.active::before { border-color: var(--seal); animation: pulse 1.1s ease-in-out infinite; }
.steps li.done { opacity: .8; }
.steps li.done::before { background: currentColor; }
.progress-hint { margin: 0; font-size: 13px; }
@keyframes pulse { 50% { transform: scale(1.5); } }

.answer { max-width: var(--measure); font-size: 17px; line-height: 1.7; }
.answer p { margin: 0 0 14px; }
.answer ul { margin: 0 0 14px; padding-left: 22px; }
.answer li { margin-bottom: 6px; }
.answer .caveat { font-size: 14px; color: var(--ink-2); border-top: 1px solid var(--rule); padding-top: 12px; margin-top: 20px; }

/* citation marker in the answer: a small stamped number */
.cite {
  display: inline-grid; place-items: center; vertical-align: 2px;
  min-width: 21px; height: 21px; padding: 0 3px; margin: 0 1px;
  border: 1.5px solid var(--seal); border-radius: 50%;
  background: transparent; color: var(--seal);
  font: 600 11.5px/1 var(--sans);
}
.cite:hover, .cite[aria-pressed="true"] { background: var(--seal); color: var(--on-seal); }

.failure { padding: 16px 18px; border-left: 3px solid var(--seal); background: var(--seal-wash); max-width: var(--measure); }
.failure-text { margin: 0 0 10px; }
.retry { background: none; border: 1px solid var(--ink); border-radius: 6px; padding: 6px 14px; font-weight: 500; }

/* ---------- source slips ---------- */
.turn-sources { align-self: start; position: sticky; top: 16px; max-height: calc(100dvh - 140px); overflow: auto; padding-right: 4px; }
.sources-title { margin: 4px 0 14px; font: 600 14px/1.3 var(--sans); color: var(--ink-2); }
.slips { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.slip {
  position: relative; background: var(--surface); border: 1px solid var(--rule); border-radius: 3px;
  padding: 14px 16px 12px 58px;
}
.slip .seal {
  position: absolute; left: 14px; top: 14px; width: 32px; height: 32px; font-size: 15px;
  transform: rotate(-8deg);
}
.slip.lit { border-color: var(--seal); box-shadow: 0 0 0 3px var(--seal-wash); }
.slip.lit .seal { animation: stamp .45s cubic-bezier(.2,.9,.3,1.3); }
@keyframes stamp { 0% { transform: rotate(-8deg) scale(1.6); opacity: .2; } 100% { transform: rotate(-8deg) scale(1); opacity: 1; } }
.slip-cite { margin: 0; font: 600 15px/1.35 var(--sans); }
.slip-title { margin: 2px 0 8px; font: 400 14.5px/1.45 var(--serif); color: var(--ink-2); }
.status { display: inline-block; font-size: 12.5px; font-weight: 500; padding: 2px 8px; border-radius: 99px; }
.status.ok { color: var(--ok); background: var(--ok-wash); }
.status.wait { color: var(--wait); background: var(--wait-wash); }
.slip details { margin-top: 8px; }
.slip summary { font-size: 13.5px; font-weight: 500; color: var(--ink-2); cursor: pointer; width: fit-content; }
.slip summary:hover { color: var(--seal); }
.slip-text {
  margin: 10px 0 2px; padding-top: 10px; border-top: 1px dashed var(--rule);
  font: 400 15px/1.75 var(--serif); white-space: pre-line;
}
.slip-text .elide { color: var(--ink-2); }
.more { margin-top: 18px; }
.more > summary { font-size: 14px; color: var(--ink-2); cursor: pointer; margin-bottom: 12px; }
.slips-more .slip { opacity: .85; }

/* ---------- composer ---------- */
.composer {
  position: sticky; bottom: 0; z-index: 2;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px;
  width: 100%; max-width: 1200px; margin: 0 auto;
  padding: 14px clamp(16px, 4vw, 40px) 12px;
  background: linear-gradient(to bottom, transparent, var(--paper) 22%);
}
.composer textarea {
  resize: none; min-height: 52px; max-height: 200px;
  padding: 14px 16px; border: 1.5px solid var(--ink); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: 400 16px/1.5 var(--sans);
}
.composer textarea::placeholder { color: var(--ink-2); opacity: .8; }
.send {
  align-self: end; height: 52px; padding: 0 26px; border: 0; border-radius: 8px;
  background: var(--seal); color: var(--on-seal); font-weight: 600; font-size: 16px;
}
.send:disabled { opacity: .5; cursor: progress; }
.composer-note { grid-column: 1 / -1; margin: 0; font-size: 12.5px; color: var(--ink-2); }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .turn { grid-template-columns: 1fr; gap: 24px; }
  .turn-sources { position: static; max-height: none; overflow: visible; }
  .topbar-note { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
