:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #fcfcfb;
  --ink: #1a1917;
  --ink-2: #52514e;
  --ink-3: #8a8883;
  --rule: #e2dfd8;
  --grid: #ebe8e1;
  --fear-2: #b8352a;   /* extreme fear */
  --fear-1: #e8907f;   /* fear */
  --neutral: #d9d7d1;
  --glee-1: #7fb0eb;   /* glee */
  --glee-2: #2466c2;   /* extreme glee */
  --accent: #1a1917;
  --accent-ink: #fcfcfb;
  --sel: #1a1917;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #8f8e86;
    --rule: #2e2e2b;
    --grid: #262624;
    --fear-2: #e0574a;
    --fear-1: #8f4238;
    --neutral: #43423e;
    --glee-1: #36598a;
    --glee-2: #4b8fe8;
    --accent: #f0efec;
    --accent-ink: #1a1a19;
    --sel: #f0efec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --ink-3: #8f8e86;
  --rule: #2e2e2b; --grid: #262624; --fear-2: #e0574a; --fear-1: #8f4238; --neutral: #43423e;
  --glee-1: #36598a; --glee-2: #4b8fe8; --accent: #f0efec; --accent-ink: #1a1a19; --sel: #f0efec;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 Inter, system-ui, -apple-system, sans-serif;
}
main { max-width: 760px; margin: 0 auto; padding: 40px 16px 64px; }
h1, h2, .value, .voted-big { font-family: Fraunces, Georgia, serif; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.masthead { text-align: center; margin-bottom: 28px; }
.kicker { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; color: var(--ink-3); margin: 0 0 6px; font-weight: 600; }
h1 { font-size: clamp(44px, 10vw, 76px); line-height: 1; margin: 0; font-weight: 800; letter-spacing: -.02em; }
.slash { color: var(--ink-3); font-weight: 400; }
.dek { max-width: 560px; margin: 16px auto 0; color: var(--ink-2); }

.card, .gauge-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 24px;
  margin-top: 20px;
}
.card h2 { font-size: 24px; margin: 0; font-weight: 600; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.sub { color: var(--ink-2); margin: 4px 0 18px; }
.note, .fine { color: var(--ink-3); font-size: 13px; margin: 8px 0 0; }

/* Gauge */
.gauge-card { text-align: center; padding-top: 28px; }
#gauge { width: 100%; max-width: 420px; display: block; margin: 0 auto; overflow: visible; }
#gauge .tick { font: 500 10px Inter, sans-serif; fill: var(--ink-3); }
#gauge .needle { transition: transform 1.1s cubic-bezier(.2, .8, .2, 1); transform-origin: 160px 160px; }
.readout { margin-top: -6px; }
.value { font-size: 64px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.label { font-size: 18px; font-weight: 600; margin-top: 4px; color: var(--ink-2); }
.meta { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 24px 0 0; padding-top: 18px; border-top: 1px solid var(--rule); }
.meta div { min-width: 0; }
.meta dt { font-size: 12px; color: var(--ink-3); }
.meta dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .meta { grid-template-columns: repeat(2, 1fr); } }

/* History chart */
.chart-wrap { position: relative; }
#chart { width: 100%; height: 240px; display: block; }
#chart .axis { font: 11px Inter, sans-serif; fill: var(--ink-3); }
#chart .grid { stroke: var(--grid); stroke-width: 1; }
#chart .line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
#chart .cross { stroke: var(--ink-3); stroke-width: 1; }
#chart .dot { fill: var(--ink); stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 8px;
  padding: 6px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.12); white-space: nowrap;
}
.tooltip b { font-variant-numeric: tabular-nums; }
.tooltip .t { color: var(--ink-3); font-size: 12px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--ink-2); text-decoration: underline; cursor: pointer; font: inherit; font-size: 14px; }
#table-view { max-height: 280px; overflow: auto; margin-top: 12px; }
#table-view table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
#table-view th, #table-view td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--rule); }
#table-view th { color: var(--ink-3); font-weight: 500; position: sticky; top: 0; background: var(--surface); }

/* Form */
fieldset.q { border: 0; padding: 0; margin: 0 0 24px; min-width: 0; }
legend { font-weight: 600; margin-bottom: 10px; padding: 0; }
.qn {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--ink); color: var(--surface); font-size: 12px; margin-right: 8px; vertical-align: 1px;
}
.q-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
@media (max-width: 620px) { .q-row { grid-template-columns: 1fr; } }

label { cursor: pointer; }
label input { position: absolute; opacity: 0; pointer-events: none; }
label span { display: block; border: 1px solid var(--rule); border-radius: 10px; transition: background .15s, border-color .15s, color .15s; }
label:hover span { border-color: var(--ink-3); }
label input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

.feelings { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.feelings span { text-align: center; padding: 14px 2px; font-size: 13px; font-weight: 500; }
.feelings label:nth-child(1) span { border-bottom: 4px solid var(--fear-2); }
.feelings label:nth-child(2) span { border-bottom: 4px solid var(--fear-1); }
.feelings label:nth-child(3) span { border-bottom: 4px solid var(--fear-1); }
.feelings label:nth-child(4) span { border-bottom: 4px solid var(--neutral); }
.feelings label:nth-child(5) span { border-bottom: 4px solid var(--glee-1); }
.feelings label:nth-child(6) span { border-bottom: 4px solid var(--glee-1); }
.feelings label:nth-child(7) span { border-bottom: 4px solid var(--glee-2); }
.feelings input:checked + span, .stack input:checked + span, .chips input:checked + span {
  background: var(--sel); color: var(--accent-ink); border-color: var(--sel);
}
@media (max-width: 560px) {
  .feelings { grid-template-columns: repeat(4, 1fr); }
  .feelings label:nth-child(n+5) { grid-row: 2; }
}
.scale-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); margin-top: 6px; }

.stack { display: grid; gap: 6px; }
.stack span { padding: 10px 14px; font-size: 14px; color: var(--ink-2); }
.stack b { color: inherit; font-weight: 600; }
.stack input:checked + span b, .stack input:checked + span { color: var(--accent-ink); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span { padding: 7px 12px; font-size: 14px; border-radius: 999px; }

.submit-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
#submit-btn {
  font: 600 16px Inter, sans-serif; padding: 13px 24px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
#submit-btn:disabled { opacity: .5; cursor: default; }
.form-msg { margin: 0; color: var(--fear-2); font-size: 14px; }
.voted { text-align: center; padding: 12px 0; }
.voted-big { font-size: 22px; font-weight: 600; margin: 0; }

.about p, .about li { color: var(--ink-2); font-size: 15px; }
.about ul { padding-left: 20px; }
.about li { margin-bottom: 6px; }
.about b { color: var(--ink); }

footer { text-align: center; color: var(--ink-3); font-size: 13px; margin-top: 32px; }
footer a { color: inherit; }

/* CTA, modal, recent table, footer details */
.cta {
  display: block; margin: 26px auto 0; max-width: 100%;
  font: 600 18px Inter, sans-serif; padding: 18px 28px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
}
.cta:hover { opacity: .9; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: start center; overflow-y: auto; padding: 24px 12px; z-index: 10; }
.backdrop[hidden] { display: none; }
.modal { position: relative; background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; padding: 28px 24px 24px; width: 100%; max-width: 640px; margin: auto; }
.modal h2 { font-family: Fraunces, Georgia, serif; font-size: 26px; margin: 0; font-weight: 600; }
.close { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border: 0; background: none; font-size: 28px; line-height: 1; color: var(--ink-2); cursor: pointer; }
table.recent { width: 100%; border-collapse: collapse; margin-top: 12px; font-variant-numeric: tabular-nums; }
table.recent th, table.recent td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--rule); }
table.recent th { color: var(--ink-3); font-weight: 500; font-size: 13px; }
table.recent th:last-child, table.recent td:last-child { text-align: right; }
table.recent .empty { color: var(--ink-3); text-align: center !important; }
footer details { text-align: left; max-width: 620px; margin: 0 auto 16px; }
footer summary { cursor: pointer; text-align: center; }
footer details p { font-size: 13px; color: var(--ink-2); }
