:root {
  color-scheme: light dark;
  --fg: #191b20;
  --muted: #565d6b;
  --bg: #f6f6f4;
  --card: #ffffff;
  --card-soft: #fafaf8;
  --line: #e2e3e7;
  --line-strong: #cfd2d9;
  --accent: #2b57c8;
  --accent-soft: #eef2fd;
  --accent-fg: #ffffff;
  --ok: #1c6b3a;
  --ok-soft: #e8f5ec;
  --warn: #7a4b00;
  --warn-soft: #fdf1da;
  --error: #9d1c1c;
  --error-soft: #fdeaea;
  --shadow: 0 1px 2px rgba(15, 20, 30, 0.06), 0 8px 24px rgba(15, 20, 30, 0.06);
  --radius: 14px;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e9eaee;
    --muted: #a6acb9;
    --bg: #121419;
    --card: #1a1d24;
    --card-soft: #161920;
    --line: #2a2e37;
    --line-strong: #3a3f4b;
    --accent: #8ba7ff;
    --accent-soft: #1c2540;
    --accent-fg: #0f1115;
    --ok: #8fd6a8;
    --ok-soft: #16281c;
    --warn: #f0c479;
    --warn-soft: #2c2415;
    --error: #f3a1a1;
    --error-soft: #2e1a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  -webkit-text-size-adjust: 100%;
}
body.dialog-open { overflow: hidden; }
.page { max-width: 760px; margin: 0 auto; padding: 40px 20px 64px; }
h1 { font-size: 2.15rem; line-height: 1.15; letter-spacing: -0.025em; margin: 6px 0 10px; }
h2 { font-size: 1.02rem; line-height: 1.3; margin: 0; letter-spacing: -0.005em; }
h3 { font-size: 0.95rem; line-height: 1.35; margin: 0 0 6px; font-weight: 650; }
p { margin: 0 0 10px; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
code { font-family: var(--mono); font-size: 0.9em; }
.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.hero { margin-bottom: 24px; }
.lede { color: var(--muted); font-size: 1.05rem; max-width: 62ch; margin-bottom: 16px; }
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
}
.status::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}
body[data-state="ready"] .status, body[data-state="decided"] .status { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
body[data-state="ready"] .status::before, body[data-state="decided"] .status::before { background: var(--ok); }
body[data-state="needs-download"] .status, body[data-state="downloading"] .status, body[data-state="deciding"] .status { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
body[data-state="needs-download"] .status::before, body[data-state="downloading"] .status::before, body[data-state="deciding"] .status::before { background: var(--warn); }
body[data-state="error"] .status, body[data-state="unavailable"] .status { color: var(--error); border-color: var(--error); background: var(--error-soft); }
body[data-state="error"] .status::before, body[data-state="unavailable"] .status::before { background: var(--error); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.field { margin-bottom: 18px; }
label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
select, input[type="text"], textarea {
  width: 100%;
  min-height: 44px;
  font: inherit;
  color: inherit;
  background: var(--card-soft);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 12px;
}
textarea { resize: vertical; min-height: 108px; }
select:focus-visible, input:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.field-hint { margin: 6px 0 0; font-size: 0.82rem; color: var(--muted); }

.questions { border-top: 1px solid var(--line); padding-top: 18px; margin-bottom: 4px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.count { font-size: 0.8rem; color: var(--muted); }
.question {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px 10px;
  margin: 0 0 10px;
  background: var(--card-soft);
}
.question legend { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.01em; color: var(--muted); padding: 0 5px; }
.question small { display: block; color: var(--muted); margin-top: 5px; font-size: 0.79rem; }
.question input[type="text"] { background: var(--card); }
.question textarea { min-height: 64px; background: var(--card); }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}
.chip:hover { border-style: solid; color: var(--fg); border-color: var(--accent); }
.chip:disabled { opacity: 0.5; cursor: default; }

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.action-copy { flex: 1 1 260px; min-width: 0; }
.hint { margin: 0 0 2px; font-size: 0.86rem; color: var(--muted); }
.model-note { margin: 0; font-size: 0.78rem; color: var(--muted); }
.button {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  white-space: nowrap;
}
.button:hover:not(:disabled) { filter: brightness(1.06); }
.button.secondary { background: transparent; color: var(--accent); }
.button:disabled { opacity: 0.55; cursor: default; }
button.link {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  padding: 6px 0;
  min-height: 32px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.link:hover { color: var(--fg); }
.question button.link { min-height: 40px; }

.about { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 4px; }
.about summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}
.about summary:hover { color: var(--fg); }
.about-body { padding: 4px 2px 0; color: var(--muted); font-size: 0.92rem; }
.about-body h2 { font-size: 0.92rem; color: var(--fg); margin: 16px 0 6px; }
.about-body p { margin-bottom: 8px; }
.footer { margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.82rem; }
.footer p { margin: 0; }

.dialog {
  width: min(660px, calc(100vw - 32px));
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--fg);
  box-shadow: 0 24px 80px rgba(10, 15, 25, 0.35);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.dialog::backdrop { background: rgba(12, 16, 24, 0.55); backdrop-filter: blur(2px); }
.dialog[open] { animation: dialog-in 140ms ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px) scale(0.99); } to { opacity: 1; transform: none; } }
.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 6px;
}
.dialog-head h2 { font-size: 1.22rem; letter-spacing: -0.015em; margin-top: 3px; }
.icon-button {
  flex: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.icon-button:hover:not(:disabled) { color: var(--fg); border-color: var(--line-strong); }
.icon-button:disabled { opacity: 0.4; cursor: default; }
.stage { margin: 0; padding: 0 22px; color: var(--muted); font-size: 0.9rem; min-height: 1.4em; }
.progress { display: block; width: calc(100% - 44px); margin: 10px 22px 0; height: 8px; accent-color: var(--accent); }
.results {
  display: grid;
  gap: 10px;
  padding: 14px 22px 0;
  margin: 0;
}
.results:empty { display: none; }
.answer {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  background: var(--card-soft);
}
.pick { margin: 0 0 10px; font-weight: 650; }
.bars { display: grid; gap: 5px; }
.bar { display: grid; grid-template-columns: minmax(56px, 108px) 1fr 52px; align-items: center; gap: 8px; font-size: 0.85rem; }
.bar meter {
  width: 100%;
  height: 9px;
  accent-color: var(--accent);
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.bar meter::-webkit-meter-bar {
  height: 100%;
  border: 0;
  border-radius: 999px;
  background: var(--line);
}
.bar meter::-webkit-meter-optimum-value,
.bar meter::-webkit-meter-suboptimum-value,
.bar meter::-webkit-meter-even-less-good-value {
  border-radius: 999px;
  background: var(--accent);
}
.bar span:last-child { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.notice { margin: 4px 0 0; padding: 12px 14px; border-radius: 12px; font-size: 0.92rem; border: 1px solid var(--line-strong); }
.notice.warning { color: var(--warn); background: var(--warn-soft); border-color: var(--warn); }
.notice.error { color: var(--error); background: var(--error-soft); border-color: var(--error); }
.timing { margin: 0; padding: 6px 22px 0; min-height: 1.2em; color: var(--muted); font-size: 0.85rem; }
.results-note {
  margin: 10px 22px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  background: var(--card-soft);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px 20px;
  margin-top: 8px;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 560px) {
  .page { padding: 26px 14px 48px; }
  h1 { font-size: 1.72rem; }
  .card { padding: 16px; }
  .actions { align-items: stretch; }
  .action-copy { flex-basis: 100%; }
  .actions .button { flex: 1 1 100%; }
  .dialog { width: calc(100vw - 20px); max-height: 90vh; }
  .dialog-head { padding: 16px 16px 4px; }
  .stage { padding: 0 16px; }
  .progress { width: calc(100% - 32px); margin: 10px 16px 0; }
  .results { padding: 12px 16px 0; }
  .dialog { max-height: 92vh; }
  .timing { padding-left: 16px; padding-right: 16px; }
  .results-note { margin-left: 16px; margin-right: 16px; }
  .dialog-actions { padding: 14px 16px 16px; }
  .dialog-actions .button { flex: 1 1 auto; }
  .bar { grid-template-columns: minmax(48px, 88px) 1fr 46px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .dialog[open] { animation: none; }
}
