:root {
  --bg: #f5f6f8;
  --card: #fff;
  --fg: #14161a;
  --muted: #5b6270;
  --accent: #3358ff;
  --accent-fg: #fff;
  --border: #d8dce3;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  color-scheme: light;
  background: var(--bg);
  color: var(--fg);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  -webkit-text-size-adjust: 100%;
}

.muted {
  color: var(--muted);
}

/* ---- Survey ---- */
.survey {
  max-width: 640px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px 40px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.progress {
  margin: 8px 0 28px;
}
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}
.progress-text {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
}

.step {
  border: 0;
  margin: 0;
  padding: 0;
}
.q-text {
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 650;
  line-height: 1.25;
  padding: 0;
  margin-bottom: 22px;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 18px;
  background: var(--card);
  transition:
    border-color 0.12s ease,
    background 0.12s ease,
    transform 0.05s ease;
}
.option:active {
  transform: scale(0.99);
}
.option:hover {
  border-color: #b8bec9;
}
.option input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex: none;
}
.option:has(input:checked) {
  border-color: var(--accent);
  background: #e8ecff;
}
.option.pna {
  color: var(--muted);
  font-size: 16px;
}

textarea {
  width: 100%;
  background: var(--card);
  color: var(--fg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font: inherit;
  font-size: 17px;
  resize: vertical;
}
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.controls {
  margin-top: auto;
  padding-top: 28px;
  display: flex;
  gap: 12px;
}
.btn {
  flex: 1;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
}
.btn.primary,
.btn:not(.ghost):not(.primary) {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn.ghost {
  background: transparent;
  flex: 0 0 auto;
  padding-inline: 22px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---- Result ---- */
.result {
  justify-content: center;
  text-align: center;
}
.card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 40px 28px;
}
.big-check {
  font-size: 64px;
  line-height: 1;
  color: var(--accent);
  margin-bottom: 12px;
}
.result h1 {
  font-size: 26px;
  margin: 0 0 10px;
}

/* ---- Counter ---- */
body.counter {
  color-scheme: dark;
  --fg: #f4f5f7;
  --muted: #9aa0ab;
  --accent: #6c8cff;
  --border: #2a2e38;
  background: #000;
  color: var(--fg);
}
.counter-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 24px;
}
#count-wrap {
  display: flex;
  align-items: baseline;
  gap: 2vw;
  line-height: 1;
}
.count {
  font-size: min(46vw, 60vh);
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.denom {
  font-size: min(14vw, 18vh);
  font-weight: 700;
  color: var(--muted);
}
.count.bump {
  animation: bump 0.3s ease;
}
@keyframes bump {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.08);
    color: var(--accent);
  }
  100% {
    transform: scale(1);
  }
}

.setup form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.setup label {
  color: var(--muted);
  font-size: 18px;
}
.setup input {
  font-size: 22px;
  padding: 10px 14px;
  width: 140px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #111;
  color: var(--fg);
}
/* Pinned to a corner rather than stacked: the count owns the vertical space
   on a projector, and a fixed block leaves it perfectly centred. */
.qr-block {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  top: max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
/* White quiet zone around the code: it has to scan off a projector. */
.qr {
  background: #fff;
  padding: 12px;
  border-radius: 12px;
  line-height: 0;
}
.qr svg {
  display: block;
  width: min(24vw, 32vh);
  height: auto;
  shape-rendering: crispEdges;
}
.qr-url {
  font-size: min(2.4vw, 3.2vh);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Too narrow to pin a corner without covering the count: back into the flow. */
@media (max-width: 700px), (max-height: 520px) {
  .qr-block {
    position: static;
    margin-top: 8px;
  }
  .qr svg {
    width: min(38vw, 30vh);
  }
  .qr-url {
    font-size: min(5vw, 4vh);
  }
}

.counter-footer {
  color: var(--muted);
  font-size: 20px;
  display: flex;
  gap: 16px;
  align-items: center;
}
.linkish {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}
.hidden {
  display: none !important;
}

/* ---- Graphs ---- */
/* Dark like the counter: this is the other surface that goes on the projector.
   Series hues are the validated dark-surface categorical order. */
body.graphs {
  color-scheme: dark;
  --fg: #fff;
  --muted: #c3c2b7;
  --accent: #6c8cff;
  --border: #2a2e38;
  --track: #24242b;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #008300;
  --s7: #9085e9;
  --s8: #e66767;
  background: #1a1a19;
  color: var(--fg);
}
.graphs-view {
  height: 100dvh;
  overflow: hidden;
  max-width: 1100px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.graphs-head {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.view-toggle {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.view-btn {
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.view-btn.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0d14;
}
.view-n {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.slide {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.q-index {
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.q-title {
  font-size: clamp(22px, 3.4vw, 34px);
  font-weight: 650;
  margin: 6px 0 4px;
}
.q-note {
  font-size: 14px;
  margin: 0 0 4px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 14px 0 18px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

/* The nav stays put; a tall grouped question scrolls inside the chart.
   `safe center` centres a short chart without clipping the top of a tall one. */
.chart {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  gap: 18px;
  margin-top: 18px;
}
.chart.grouped {
  gap: 14px;
}
.row {
  display: grid;
  grid-template-columns: minmax(120px, 22%) 1fr;
  gap: 16px;
  align-items: center;
}
.row-label {
  font-size: 16px;
  color: var(--muted);
  line-height: 1.3;
}
/* 2px of surface between adjacent bars so fills never touch. */
.row-bars {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bar {
  display: flex;
  align-items: center;
  gap: 12px;
}
.track {
  flex: 1;
  height: 14px;
  background: var(--track);
  border-radius: 4px;
  overflow: hidden;
}
.chart.grouped .track {
  height: 9px;
  border-radius: 3px;
}
/* Grouped rows stack up to 6 bars: the value text, not the track, sets the
   row height, so it tightens too. */
.chart.grouped .bar {
  line-height: 1.2;
}
.chart.grouped .val {
  font-size: 13px;
  min-width: 78px;
}
.fill {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
  transition: width 0.2s ease;
}
.val {
  flex: 0 0 auto;
  min-width: 86px;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.val .cnt {
  color: var(--muted);
  font-weight: 500;
  margin-left: 6px;
}
.val .cnt::before {
  content: "(";
}
.val .cnt::after {
  content: ")";
}
.empty {
  font-size: 18px;
}

.graph-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}
.graph-nav .btn {
  flex: 0 0 auto;
  padding: 12px 22px;
  font-size: 16px;
}
.dots {
  flex: 1;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.dot {
  width: 10px;
  height: 10px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: transparent;
  cursor: pointer;
}
.dot.on {
  background: var(--accent);
  border-color: var(--accent);
}

@media (max-width: 640px) {
  .row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .val {
    min-width: 74px;
    font-size: 14px;
  }
}
