:root {
  color-scheme: dark;
  --bg: #15171a;
  --panel: #1c1f23;
  --raised: #2a2e34;
  --line: #2c3036;
  --text: #d9dce0;
  --muted: #8a9099;
  --accent: #86b3d9;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

/* ---- header ---- */

.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-height: 46px;
}
.bar .name { font-weight: 600; letter-spacing: 0.04em; }
.bar .spacer { flex: 1; }
.bar label { display: flex; align-items: center; gap: 8px; min-width: 0; }

select, input[type="text"] {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 0;
  max-width: 100%;
}

/* ---- buttons ---- */

button { font: inherit; color: inherit; }
.btn, .seg button {
  background: transparent;
  border: 1px solid var(--line);
  padding: 6px 11px;
  min-height: 32px;
  cursor: pointer;
  white-space: nowrap;
}
.btn { border-radius: 6px; }
.btn:hover:not(:disabled), .seg button:hover:not(:disabled) { background: var(--raised); }
.btn[aria-pressed="true"], .seg button[aria-pressed="true"] {
  background: var(--raised);
  border-color: var(--accent);
  color: #fff;
}
.btn:disabled, .seg button:disabled { opacity: 0.35; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0f1a24; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #9cc3e4; }
.linkish { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; text-decoration: underline; }
.linkish:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; }
.seg button { margin-left: -1px; }
.seg button:first-child { margin-left: 0; border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button[aria-pressed="true"] { position: relative; z-index: 1; }

/* ---- stage ---- */

.stage {
  position: relative;
  flex: 1;
  min-height: 240px;
  overflow: hidden;
  background: #1a1c20;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.label {
  position: absolute;
  transform: translateX(-50%);
  text-align: center;
  font-size: 12px;
  line-height: 1.25;
  color: var(--text);
  text-shadow: 0 1px 2px #000a;
}
.label small { display: block; color: var(--accent); font-size: 11px; }
.label.letter { font-size: 16px; font-weight: 600; }
.notice {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  max-width: min(90%, 460px);
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}
.notice code { color: var(--accent); }

/* ---- comparison page ---- */

.transport, .controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.transport input[type="range"] { flex: 1; min-width: 80px; accent-color: var(--accent); }
.transport #play { min-width: 68px; }
.transport #time { min-width: 150px; text-align: right; color: var(--muted); }
.check { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.check input { accent-color: var(--accent); }

.controls { flex-wrap: wrap; gap: 10px 22px; }
.group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cap { color: var(--muted); font-size: 12px; margin-right: 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---- rating page ---- */

.progress { display: flex; align-items: center; gap: 10px; color: var(--muted); white-space: nowrap; }
.progress .track { width: 140px; height: 4px; border-radius: 2px; background: var(--raised); overflow: hidden; }
.progress .fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

.card {
  margin: auto;
  width: min(100% - 28px, 520px);
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.card h1 { margin: 0 0 10px; font-size: 18px; font-weight: 600; }
.card p { margin: 0 0 12px; }
.card label { display: block; margin-bottom: 6px; }
.card input[type="text"] { width: 100%; margin-bottom: 6px; }
.card .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; }

.trial { flex: 1; display: flex; min-height: 0; }
.trial .stage { flex: 1; }
.trial form {
  width: 400px;
  padding: 16px 18px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}
.q { border: 0; margin: 0 0 18px; padding: 0; min-width: 0; }
.q legend { padding: 0; margin-bottom: 8px; }
.scale { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.scale.three { grid-template-columns: repeat(3, 1fr); }
.scale label { position: relative; }
.scale input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.scale span {
  display: grid;
  place-items: center;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.scale input:hover + span { background: var(--raised); }
.scale input:checked + span { background: var(--raised); border-color: var(--accent); color: #fff; }
.scale input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.ends { display: flex; justify-content: space-between; margin-top: 5px; color: var(--muted); font-size: 12px; }
.trial .actions { display: flex; align-items: center; gap: 12px; }
.trial .actions .btn { min-width: 110px; min-height: 38px; }

/* ---- narrow screens ---- */

@media (max-width: 700px) {
  body { height: auto; min-height: 100%; }
  .bar { flex-wrap: wrap; gap: 8px 12px; }
  .bar label { flex: 1 1 100%; order: 3; }
  .bar select { flex: 1; }
  .compare .stage { flex: none; height: 56vh; }
  .transport { flex-wrap: wrap; gap: 10px; }
  .transport input[type="range"] { flex: 1 1 60%; }
  .transport .seg button { padding: 6px 8px; }
  .transport #time { flex: 1; min-width: 0; order: 5; font-size: 12px; white-space: nowrap; }
  .controls { display: grid; gap: 10px; }
  .group { display: grid; grid-template-columns: 104px 1fr; justify-items: start; }
  .group select { width: 100%; }

  .rate .bar { flex-wrap: nowrap; }
  .progress .track { display: none; }
  .trial { flex-direction: column; }
  .trial .stage { flex: none; height: 42vh; position: sticky; top: 0; z-index: 2; }
  .trial form { width: auto; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .card { margin: 14px auto; }
}

/* ---- sandbox ---- */

.sandbox .stage canvas { cursor: grab; }
.sandbox .stage canvas:active { cursor: grabbing; }
.hud {
  position: absolute;
  margin: 0;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  background: #15171acc;
  border: 1px solid var(--line);
  border-radius: 6px;
  pointer-events: none;
}
.hud.help { left: 12px; bottom: 12px; }
.hud.help b { color: var(--text); font-weight: 600; }
.hud.stats { right: 12px; top: 12px; text-align: right; font-family: inherit; white-space: pre; }
.vote label { display: inline-flex; align-items: center; gap: 6px; margin-right: 10px; }
.vote input[type="text"] { width: 7em; padding: 4px 8px; }
.vote #vote-form, .vote #vote-result { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
@media (max-width: 700px) {
  .hud.help { display: none; }
}

/* ---- the study page (blind.html): nothing technical on screen ---- */

.card-over {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  width: min(92%, 460px);
  padding: 22px 24px;
  background: #1c1f23f2;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.5;
}
.card-over h1 { margin: 0 0 10px; font-size: 20px; font-weight: 600; }
.card-over p { margin: 0 0 12px; }
.card-over label { display: block; margin: 4px 0 14px; }
.card-over input[type="text"] { display: block; width: 100%; margin-top: 6px; }
.card-over .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.card-over .actions .btn { min-height: 40px; min-width: 120px; }
.small { font-size: 12px; }
.study-panel { padding: 10px 14px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.study-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.study-row:first-child { margin-top: 0; }
.study-row .spacer { flex: 1; }
.study-row .cap { font-size: 13px; }
.study-row .cap.gap { margin-left: 14px; }
.study-row .seg button { min-width: 44px; min-height: 36px; font-weight: 600; }
.study-row .seg.big button { min-width: 72px; min-height: 46px; font-size: 17px; }
.study-row #next { min-height: 40px; min-width: 120px; }

/* ---- about ---- */

.about { display: block; overflow: auto; }
.prose { max-width: 680px; margin: 0 auto; padding: 28px 20px 60px; font-size: 15px; line-height: 1.6; }
.prose h1 { font-size: 22px; margin: 0 0 12px; }
.prose h2 { font-size: 16px; margin: 26px 0 8px; }
.prose li { margin-bottom: 8px; }
