:root {
  --bg: #fbfbf9;
  --surface: #ffffff;
  --text: #1b1b19;
  --muted: #6f6f68;
  --faint: #93938b;
  --border: #e5e4de;
  --accent: #3d5afe;
  --accent-soft: #eef1ff;
  --danger: #b3261e;
  --danger-soft: #fdf0ef;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 15, .04), 0 8px 24px -16px rgba(20, 20, 15, .18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101010;
    --surface: #181817;
    --text: #ecebe7;
    --muted: #a1a099;
    --faint: #75746d;
    --border: #292926;
    --accent: #8fa2ff;
    --accent-soft: #1b1e33;
    --danger: #ef9a93;
    --danger-soft: #2a1a18;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -16px rgba(0, 0, 0, .8);
  }
}

* { box-sizing: border-box; }

/* Author-set `display` (e.g. .status is flex) outranks the UA rule for [hidden],
   so state this explicitly or hidden panels render anyway. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 780px;
  margin: 0 auto;
  padding: 56px 24px 96px;
}

/* ---------- masthead ---------- */

.masthead { margin-bottom: 28px; }

.masthead h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 620;
  letter-spacing: -.02em;
}

.masthead p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- panels ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---------- form ---------- */

.field { margin-bottom: 16px; }

label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 560;
  letter-spacing: -.01em;
}

.opt {
  color: var(--faint);
  font-weight: 400;
}

textarea, input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  resize: vertical;
  transition: border-color .12s, box-shadow .12s;
}

textarea::placeholder, input::placeholder { color: var(--faint); }

textarea:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button[type="submit"] {
  width: 100%;
  padding: 11px 16px;
  background: var(--text);
  color: var(--surface);
  border: none;
  border-radius: 8px;
  font: inherit;
  font-weight: 560;
  cursor: pointer;
  transition: opacity .12s;
}

button[type="submit"]:hover:not(:disabled) { opacity: .86; }
button[type="submit"]:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- status ---------- */

.status {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}

.status-text {
  display: flex;
  flex: 1;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.status-text strong { font-size: 14px; font-weight: 520; }
#timer { color: var(--faint); font-size: 13px; font-variant-numeric: tabular-nums; }

.spinner {
  width: 17px;
  height: 17px;
  flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

/* ---------- error ---------- */

.error {
  margin-top: 16px;
  border-color: var(--danger);
  background: var(--danger-soft);
}

.error strong { display: block; margin-bottom: 8px; color: var(--danger); font-size: 14px; }

.error pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- results ---------- */

#results { margin-top: 40px; }

.report-head { margin-bottom: 8px; }

.report-head h2 {
  margin: 0 0 12px;
  font-size: 21px;
  font-weight: 620;
  letter-spacing: -.02em;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }

.chip {
  padding: 3px 9px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 520;
}

.questions {
  margin: 0 0 8px;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
}

.questions li { margin-bottom: 3px; }

/* section headers */

.section { margin-top: 36px; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.section-head h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 620;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
}

.count {
  color: var(--faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* cards */

.card {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.card:last-child { border-bottom: none; }

.card h4 {
  margin: 0 0 5px;
  font-size: 15px;
  font-weight: 580;
  line-height: 1.4;
  letter-spacing: -.01em;
}

.card h4 a { color: inherit; text-decoration: none; border-bottom: 1px solid var(--border); }
.card h4 a:hover { color: var(--accent); border-bottom-color: var(--accent); }

.meta {
  margin: 0 0 8px;
  color: var(--faint);
  font-size: 12.5px;
}

.meta span + span::before { content: " · "; }

.body {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.refs { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }

.ref {
  max-width: 100%;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--faint);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* formulas */

.formula {
  margin: 8px 0 10px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

.formula .katex { font-size: 1.05em; }

.formula code {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

/* empty state */

.empty {
  padding: 14px 0;
  color: var(--faint);
  font-size: 14px;
  font-style: italic;
}

/* footer actions */

.actions { margin-top: 36px; }

.actions button {
  padding: 8px 14px;
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.actions button:hover { color: var(--text); border-color: var(--muted); }
