:root {
  --ink: #1c2b33;
  --muted: #56666e;
  --canvas: #eef2f1;
  --surface: #ffffff;
  --line: #cfd8d6;
  --accent: #74205c;
  --accent-hover: #5c1849;
  --accent-wash: #f6eaf2;
  --logic: #a15c00;
  --logic-wash: #fff4e0;
  --danger: #b42318;
  --danger-wash: #fdecea;
  --ok: #1e6b45;
  --ok-wash: #e6f4ec;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--canvas); line-height: 1.5; font-size: 1rem; }
h1 { font-size: 1.75rem; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 0.25rem; }
h2 { font-size: 1.25rem; line-height: 1.3; font-weight: 650; margin: 2rem 0 0.75rem; }
p { margin: 0 0 1rem; }
a { color: var(--accent); text-underline-offset: 0.15em; }
a:hover { color: var(--accent-hover); }
code { font-family: var(--mono); font-size: 0.875em; background: var(--canvas); padding: 0.1em 0.3em; border-radius: var(--radius-s); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------ chrome */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.75rem 1.5rem; background: var(--ink); color: #fff; }
.wordmark { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.0625rem; }
.wordmark:hover { color: #fff; }
.topnav { display: flex; align-items: center; gap: 1.25rem; }
.topnav a, .topnav .linklike { color: #dfe7e5; text-decoration: none; font: inherit; }
.topnav a:hover, .topnav .linklike:hover { color: #fff; text-decoration: underline; }
.topnav form { margin: 0; }
.topbar :focus-visible { outline-color: #fff; }
.linklike { background: none; border: 0; padding: 0; cursor: pointer; }

.page { max-width: 72rem; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.page.narrow { max-width: 40rem; }
.page.wide { max-width: none; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head p { margin: 0; }
.head-actions, .inline-create { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.inline-create input { width: min(22rem, 70vw); }
.lede { color: var(--muted); font-size: 1.0625rem; }

.flash p { padding: 0.75rem 1rem; border-radius: var(--radius-m); background: var(--surface); border: 1px solid var(--line); }
.flash .flash-success { background: var(--ok-wash); border-color: var(--ok); }
.flash .flash-error { background: var(--danger-wash); border-color: var(--danger); }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius-m); padding: 2.5rem; text-align: center; color: var(--muted); }
.empty p { margin: 0; }

/* ------------------------------------------------ controls */
input, textarea, select { font: inherit; color: inherit; background: var(--surface); border: 1px solid #9fb0ad; border-radius: var(--radius-s);
  padding: 0.5rem 0.625rem; min-height: 2.5rem; width: 100%; }
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 1.125rem; height: 1.125rem; min-height: 0; margin: 0; accent-color: var(--accent); flex: none; }
.stack { display: grid; gap: 0.5rem; }
.stack label { font-weight: 600; margin-top: 0.5rem; }
.stack .btn { margin-top: 1rem; justify-self: start; }

.btn { display: inline-flex; align-items: center; gap: 0.4rem; font: inherit; font-weight: 600; font-size: 0.9375rem; line-height: 1;
  padding: 0.6rem 0.9rem; min-height: 2.5rem; border-radius: var(--radius-s); border: 1px solid #9fb0ad; background: var(--surface);
  color: var(--ink); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { font-size: 0.8125rem; padding: 0.35rem 0.6rem; min-height: 2rem; font-weight: 500; }
.btn.quiet { border-color: transparent; background: transparent; }
.btn.quiet:hover { border-color: var(--line); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.pill { display: inline-block; font-size: 0.8125rem; font-weight: 600; padding: 0.1rem 0.55rem; border-radius: 999px; background: var(--canvas); color: var(--muted); }
.pill.live { background: var(--ok-wash); color: var(--ok); }

.error { color: var(--danger); font-weight: 600; margin: 0.25rem 0; }
.error-box { background: var(--danger-wash); border-left: 4px solid var(--danger); padding: 1rem 1.25rem; border-radius: var(--radius-s); margin-bottom: 1.5rem; }
.error-box ul { margin: 0; padding-left: 1.25rem; }
.error-box p:last-child { margin: 0; }

/* ------------------------------------------------ tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
table.data { border-collapse: collapse; width: 100%; font-size: 0.9375rem; }
.data th, .data td { text-align: left; padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.data th { font-weight: 600; color: var(--muted); background: #f7f9f8; white-space: nowrap; }
.data tbody tr:last-child td { border-bottom: 0; }
.data tbody tr:hover { background: #f7f9f8; }
.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.data .actions { text-align: right; white-space: nowrap; }
.responses td { max-width: 22rem; }
.pager { display: flex; gap: 1.5rem; justify-content: center; margin-top: 1.25rem; }

/* ------------------------------------------------ response detail */
.answers { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 0.25rem 1.25rem; margin: 1.5rem 0; }
.answers > div { padding: 0.9rem 0; border-bottom: 1px solid var(--line); }
.answers > div:last-child { border-bottom: 0; }
.answers dt { font-weight: 600; margin-bottom: 0.2rem; }
.answers dd { margin: 0; }
.answers .archived { opacity: 0.75; }
.danger-zone { margin-top: 2rem; }
.danger-zone summary { cursor: pointer; color: var(--danger); font-weight: 600; }
.danger-zone form { margin-top: 0.75rem; padding: 1rem; background: var(--danger-wash); border-radius: var(--radius-s); }

/* ------------------------------------------------ builder */
.sticky-head { position: sticky; top: 0; z-index: 5; background: var(--canvas); padding: 1rem 0; margin: -1rem 0 1rem; border-bottom: 1px solid var(--line); }
.builder-grid { display: grid; grid-template-columns: minmax(0, 1fr) 20rem; gap: 2rem; align-items: start; }
@media (max-width: 60rem) { .builder-grid { grid-template-columns: 1fr; } .settings { order: -1; } }
.settings { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.25rem; position: sticky; top: 6.5rem; }
.settings h2 { margin-top: 0; font-size: 1.0625rem; }
.settings label { display: block; font-weight: 600; font-size: 0.875rem; margin: 0.9rem 0 0.25rem; }
.settings .check { display: flex; gap: 0.5rem; align-items: center; font-weight: 600; }
.settings .hint { font-size: 0.8125rem; color: var(--muted); margin: 0.25rem 0 0; word-break: break-all; }

.fields { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }
.fcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
/* The signature: conditional questions hang off an amber rail. */
.fcard.conditional { margin-left: 1.5rem; border-left: 4px solid var(--logic); position: relative; }
.fcard.conditional::before { content: ""; position: absolute; left: -1.6rem; top: -0.8rem; width: 1.2rem; height: 2.3rem;
  border-left: 2px solid var(--logic); border-bottom: 2px solid var(--logic); border-bottom-left-radius: 6px; }
.fcard > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1rem; padding: 0.85rem 1rem; }
.fcard > summary::-webkit-details-marker { display: none; }
.fcard-title { font-weight: 600; }
.fcard-title.untitled { color: var(--muted); font-style: italic; font-weight: 500; }
.fcard-meta { font-size: 0.8125rem; color: var(--muted); display: flex; gap: 0.75rem; align-items: center; }
.fcard-logic { grid-column: 1 / -1; font-size: 0.875rem; color: var(--logic); font-weight: 600; }
.fcard-body { padding: 0 1rem 1rem; border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0.75rem 1rem; }
.fcard-body label { display: block; font-weight: 600; font-size: 0.875rem; margin: 0.9rem 0 0.25rem; }
.fcard-body .check { display: flex; gap: 0.5rem; align-items: center; margin-top: 2.1rem; }
.fcard-body .hint { font-size: 0.8125rem; color: var(--muted); margin: 0.25rem 0 0; }
.fcard-tools { display: flex; gap: 0.25rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.key-input { font-family: var(--mono); font-size: 0.875rem; }

.logic-box { margin-top: 1rem; padding: 0.9rem 1rem; background: var(--logic-wash); border-radius: var(--radius-s); border: 1px solid #efd3a3; }
.logic-box > label:first-child { margin-top: 0; }
.logic-head { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.logic-head select { width: auto; }
.rule { display: grid; grid-template-columns: minmax(8rem, 1.3fr) minmax(7rem, 1fr) minmax(7rem, 1fr) auto; gap: 0.5rem; margin-top: 0.5rem; align-items: center; }
@media (max-width: 40rem) { .rule { grid-template-columns: 1fr 1fr; } }
.rule.broken select:first-child { border-color: var(--danger); }
.logic-box .empty-note { font-size: 0.875rem; color: var(--muted); margin: 0.5rem 0 0; }

.add-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 1.25rem; padding: 1rem; border: 1px dashed #9fb0ad; border-radius: var(--radius-m); }
.add-bar select { width: auto; }

/* ------------------------------------------------ respondent form */
body.public { background: var(--surface); }
.respondent { max-width: 38rem; margin: 0 auto; padding: 2.5rem 1.25rem 5rem; font-size: 1.0625rem; }
.respondent h1 { font-size: 2rem; margin-bottom: 0.75rem; }
.intro { color: var(--muted); margin-bottom: 2rem; }
.preview-note { background: var(--logic-wash); border-left: 4px solid var(--logic); padding: 0.75rem 1rem; font-size: 0.9375rem; }
.respondent form { display: grid; gap: 1.75rem; }
.q fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.q-label { display: block; font-weight: 650; margin-bottom: 0.35rem; padding: 0; }
.q .help { color: var(--muted); font-size: 0.9375rem; margin: 0 0 0.5rem; }
.q .req { font-weight: 400; color: var(--muted); font-size: 0.9375rem; }
.q input:not([type="checkbox"]):not([type="radio"]), .q select, .q textarea { min-height: 3rem; font-size: 1.0625rem; }
.q.has-error input, .q.has-error select, .q.has-error textarea { border-color: var(--danger); border-width: 2px; }
.q.conditional { animation: reveal 180ms ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.choices { display: grid; gap: 0.5rem; }
.choice { display: flex; gap: 0.75rem; align-items: center; padding: 0.7rem 0.9rem; border: 1px solid var(--line); border-radius: var(--radius-s); cursor: pointer; }
.choice:hover { border-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-wash); }
.choice input { width: 1.25rem; height: 1.25rem; }
.choice.single { font-weight: 650; }
.btn.big { font-size: 1.0625rem; min-height: 3.25rem; padding: 0 1.75rem; justify-self: start; }
.hp { position: absolute; left: -9999px; }
.confirmation { font-size: 1.1875rem; padding: 1.25rem 1.5rem; background: var(--ok-wash); border-left: 4px solid var(--ok); border-radius: var(--radius-s); margin: 1.5rem 0; }
.confirmation p:last-child { margin: 0; }

@media (prefers-reduced-motion: reduce) { .q.conditional { animation: none; } }
@media (max-width: 40rem) { .page { padding: 1.25rem 1rem 3rem; } .fcard.conditional { margin-left: 1rem; } .fcard.conditional::before { left: -1.1rem; width: 0.8rem; } }
