:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #1d1f1e;
  --muted: #6b6f6c;
  --line: #e2e0d9;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0eb;
  --danger: #b4352c;
  --danger-soft: #fbe9e7;
  --focus: #2f8f76;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 8px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141615;
    --surface: #1c1f1e;
    --ink: #e8eae8;
    --muted: #9aa09d;
    --line: #2d3230;
    --accent: #4fb596;
    --accent-ink: #0d1412;
    --accent-soft: #1d332c;
    --danger: #ef7d73;
    --danger-soft: #3a2220;
    --focus: #6fd0b2;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--muted); }

input, textarea, select, button { font: inherit; color: inherit; }

input[type="text"], input[type="email"], input[type="number"], input[type="date"],
input[type="password"], input:not([type]), textarea, select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-soft); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { padding: 0.3rem 0.7rem; font-size: 0.875rem; }
.btn:disabled { opacity: 0.6; cursor: default; }

button.link {
  background: none;
  border: 0;
  padding: 0.25rem 0;
  color: var(--accent);
  cursor: pointer;
  font-weight: 500;
}

button.icon {
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
}
button.icon:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
button.icon.danger:hover { background: var(--danger-soft); color: var(--danger); }
button.icon:disabled { opacity: 0.3; cursor: default; }

.error { color: var(--danger); font-size: 0.9rem; margin: 0.35rem 0 0; }
.error:empty { display: none; }

/* ---------- public form ---------- */
.public .sheet { max-width: 680px; margin: 0 auto; padding: 2.5rem 1rem 4rem; }
.form-head {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 6px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.5rem 1.5rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.form-head h1 { font-size: 1.75rem; }
.lede { margin: 0.6rem 0 0; color: var(--muted); }
.hint { margin: 0.9rem 0 0; font-size: 0.85rem; color: var(--muted); }
.req { color: var(--danger); }

.question {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin: 0 0 0.75rem;
  box-shadow: var(--shadow);
  min-width: 0;
}
fieldset.question { display: block; }
.question > label, .question legend { display: block; font-weight: 600; margin-bottom: 0.5rem; padding: 0; }
.question legend { float: left; width: 100%; }
.question legend + * { clear: both; }
.question .help { margin: -0.25rem 0 0.75rem; font-size: 0.9rem; color: var(--muted); clear: both; }
.question.has-error { border-color: var(--danger); }
.question.has-error input, .question.has-error textarea, .question.has-error select { border-color: var(--danger); }

.options { display: grid; gap: 0.25rem; clear: both; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
}
.option:hover { background: var(--bg); }
.option input { width: 1.1rem; height: 1.1rem; margin: 0.2rem 0 0; accent-color: var(--accent); flex: none; }
.option.other { align-items: center; }
.option.other input[type="text"] { width: auto; height: auto; flex: 1; margin: 0; padding: 0.35rem 0.6rem; }

@media print {
  :root { --bg: #fff; --surface: #fff; --ink: #000; --muted: #555; --line: #bbb; --accent: #1f6f5c; }
  body { background: #fff; color: #000; }
  .public .sheet { padding: 0; }
  .form-head, .question { box-shadow: none; break-inside: avoid; }
  .actions, .banner { display: none; }
}

.scale { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; clear: both; }
.scale-end { font-size: 0.85rem; color: var(--muted); }
.scale-points { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.scale-point { position: relative; cursor: pointer; }
.scale-point input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.scale-point span {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-weight: 500;
}
.scale-point:hover span { border-color: var(--accent); }
.scale-point input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.scale-point input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

.actions { margin-top: 1.25rem; }
.actions .btn { padding: 0.7rem 1.75rem; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.banner { padding: 0.75rem 1rem; border-radius: 8px; margin: 0 0 0.75rem; }
.error-banner { background: var(--danger-soft); color: var(--danger); }
.message {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.message.done { border-left: 4px solid var(--accent); }
.again { margin: 1rem 0 0 0.25rem; }

/* ---------- admin ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.brand::before {
  content: "";
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-right: 0.5rem;
  border-radius: 3px;
  background: var(--accent);
}
#topnav { display: flex; align-items: center; gap: 1.25rem; font-size: 0.95rem; }
#topnav a { text-decoration: none; font-weight: 500; }
#topnav button.link { color: var(--muted); }

.wrap { max-width: 820px; margin: 0 auto; padding: 1.75rem 1rem 5rem; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-head.sticky {
  position: sticky;
  top: 0;
  z-index: 5;
  align-items: center;
  padding: 0.75rem 0;
  margin: -0.75rem 0 0.75rem;
  background: var(--bg);
}
.page-head p { margin: 0.25rem 0 0; }
.back { display: inline-block; text-decoration: none; font-size: 0.9rem; margin-bottom: 0.35rem; }
.head-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.save-state { font-size: 0.875rem; color: var(--muted); }
.save-state.dirty { color: var(--ink); font-weight: 500; }

.login { max-width: 360px; margin: 4rem auto; padding: 2rem; display: grid; gap: 0.6rem; }
.login h1 { margin-bottom: 0.5rem; }
.login label { font-weight: 500; }
.login .btn { margin-top: 0.5rem; }

.form-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.form-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.form-main { min-width: 0; }
.form-title {
  display: block;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.form-title:hover { color: var(--accent); }
.meta { font-size: 0.85rem; color: var(--muted); margin-top: 0.2rem; }
.pill { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; }
.pill.on { background: var(--accent-soft); color: var(--accent); }
.pill.off { background: var(--bg); color: var(--muted); }
.count { text-decoration: none; color: var(--muted); font-size: 0.9rem; text-align: right; }
.count strong { color: var(--ink); font-size: 1.1rem; }
.row-actions { display: flex; gap: 0.4rem; }

.empty { text-align: center; padding: 3rem 1.5rem; }
.empty p { color: var(--muted); margin: 0.5rem 0 1.25rem; }

.form-meta { padding: 1.25rem 1.5rem; border-top: 6px solid var(--accent); display: grid; gap: 0.6rem; }
.title-input { font-size: 1.5rem !important; font-weight: 650; border-color: transparent !important; padding-left: 0.4rem !important; }
.title-input:hover { border-color: var(--line) !important; }

.questions { list-style: none; margin: 0.75rem 0 0; padding: 0; display: grid; gap: 0.75rem; }
.q-card { padding: 1.1rem 1.25rem 0.6rem; display: grid; gap: 0.6rem; }
.q-top { display: grid; grid-template-columns: 1fr 12rem; gap: 0.6rem; }
.q-label { font-weight: 600; }
.q-help { font-size: 0.9rem; }
.opts { display: grid; gap: 0.35rem; padding-left: 0.25rem; }
.opt { display: flex; align-items: center; gap: 0.5rem; }
.opt .mark { width: 1.4rem; color: var(--muted); text-align: center; flex: none; font-size: 0.9rem; }
.opt input { padding: 0.4rem 0.6rem; }
.opt-links { display: flex; gap: 1.25rem; margin-left: 1.9rem; }
.other-preview { flex: 1; padding: 0.4rem 0.6rem; color: var(--muted); font-style: italic; font-size: 0.925rem; }
.scale-cfg { display: flex; gap: 0.75rem; flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); }
.scale-cfg label { display: grid; gap: 0.2rem; flex: 1 1 9rem; }
.q-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 0.4rem;
}
.q-tools { display: flex; gap: 0.15rem; }
.switch { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 0.9rem; }
.switch input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); margin: 0; }

.add-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin: 1rem 0 1.5rem;
  padding: 0.9rem 1rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.add-row .muted { font-size: 0.9rem; margin-right: 0.25rem; }

.settings { padding: 1.25rem 1.5rem; display: grid; gap: 0.6rem; }
.settings > label:not(.switch) { font-weight: 500; font-size: 0.9rem; margin-top: 0.4rem; }
.share { display: flex; gap: 0.5rem; }
.share input { font-family: ui-monospace, Consolas, monospace; font-size: 0.875rem; }
.danger-zone { border-top: 1px solid var(--line); margin-top: 0.75rem; padding-top: 1rem; }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs button {
  border: 0;
  background: none;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.sum { padding: 1.1rem 1.25rem; margin-bottom: 0.75rem; }
.sum-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 0.75rem; }
.sum-head .muted { font-size: 0.85rem; white-space: nowrap; }
.avg { margin: -0.25rem 0 0.75rem; color: var(--muted); }
.avg strong { color: var(--ink); font-size: 1.2rem; }
.bars { display: grid; gap: 0.45rem; }
.bar-row { display: grid; grid-template-columns: minmax(5rem, 30%) 1fr 4.5rem; gap: 0.75rem; align-items: center; font-size: 0.9rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 0.7rem; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar-n { text-align: right; font-variant-numeric: tabular-nums; }
.others { margin-top: 0.9rem; font-size: 0.9rem; }
.others summary { cursor: pointer; color: var(--accent); font-weight: 500; margin-bottom: 0.5rem; }
.text-answers { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.text-answers li { padding: 0.5rem 0.75rem; background: var(--bg); border-radius: 6px; font-size: 0.925rem; white-space: pre-wrap; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; background: var(--bg); position: sticky; top: 0; min-width: 8rem; }
td { max-width: 22rem; overflow-wrap: anywhere; white-space: pre-wrap; }
tr:last-child td { border-bottom: 0; }
.nowrap { white-space: nowrap; }

.sum-head h3 { flex: 1; }
.sum-head .btn.small { padding: 0.2rem 0.6rem; font-size: 0.8rem; }

.tab-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tab-row .tabs { border-bottom: 0; margin-bottom: 0; }
.chart-style { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--muted); padding-bottom: 0.4rem; }
select.compact { width: auto; padding: 0.25rem 0.5rem; font-size: 0.85rem; }

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 20;
  min-width: 15rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
  display: grid;
}
.menu-item {
  display: grid;
  gap: 0.05rem;
  text-align: left;
  padding: 0.5rem 0.7rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
}
.menu-item small { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.menu-item:hover, .menu-item:focus-visible { background: var(--bg); }

@media print {
  .admin .topbar, .admin .no-print, .admin .back, .toast { display: none !important; }
  .admin .wrap { max-width: none; padding: 0; }
  .admin .sum { break-inside: avoid; border-color: #bbb; }
  .bar, .bar-track { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 1rem);
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr auto; }
  .row-actions { grid-column: 1 / -1; }
  .q-top { grid-template-columns: 1fr; }
  .question, .form-head { padding-left: 1.1rem; padding-right: 1.1rem; }
  .bar-row { grid-template-columns: 6rem 1fr 3.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
