:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1d2430;
  --muted: #5b6575;
  --line: #dde2e9;
  --primary: #2f5d8a;
  --primary-ink: #ffffff;
  --accent: #c2581f;
  --good: #2e7d4f;
  --bad: #b3261e;
  --slot: #e8ecf1;
  --target: #1d2430;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --card: #1b2129;
    --text: #e6eaf0;
    --muted: #9aa5b5;
    --line: #2c3540;
    --primary: #6aa3d8;
    --primary-ink: #0d1218;
    --accent: #f0955c;
    --good: #6cc792;
    --bad: #f2827a;
    --slot: #262e38;
    --target: #e6eaf0;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --card: #1b2129; --text: #e6eaf0; --muted: #9aa5b5; --line: #2c3540;
  --primary: #6aa3d8; --primary-ink: #0d1218; --accent: #f0955c; --good: #6cc792; --bad: #f2827a;
  --slot: #262e38; --target: #e6eaf0;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.7rem; line-height: 1.2; margin: 0.5rem 0 0.75rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.5rem; }
p { margin: 0.5rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

.appbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--card);
  border-bottom: 1px solid var(--line);
}
.appbar[hidden] { display: none; }
.appbar-title { font-weight: 700; flex: 1; }
.back { border: 0; background: transparent; color: var(--primary); font-size: 1.8rem; line-height: 1; padding: 0 8px 4px 0; cursor: pointer; min-height: 40px; }
.back[hidden] { display: none; }
.proto-tag { font-size: 0.7rem; color: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: 1px 6px; }
body.running main { padding-top: calc(8px + env(safe-area-inset-top)); }

.hero { text-align: center; padding: 16px 0 4px; }
.hero-icon { width: 72px; height: 72px; border-radius: 18px; }
.hero h1 { margin-top: 8px; }
.tiles { display: grid; gap: 12px; margin: 16px 0; }
.tile {
  display: flex; flex-direction: column; gap: 4px; text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; font: inherit; color: var(--text); cursor: pointer;
}
.tile.primary { border: 2px solid var(--primary); }
.tile:disabled { opacity: 0.55; cursor: default; }
.tile-kicker { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tile-title { font-size: 1.1rem; font-weight: 700; }
.tile-text { color: var(--muted); font-size: 0.95rem; }
.switch { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.switch input { width: 22px; height: 22px; margin-top: 3px; accent-color: var(--primary); flex: none; }
h2.flush { margin-top: 0; }
kbd.pressed { background: var(--good); color: #fff; }
.bar-labels { display: flex; justify-content: space-between; }
.bad-text { color: var(--bad); }
.pressure { color: var(--accent); font-weight: 600; }

/* stage header: perceived time pressure clock + quit */
.stage-top { display: flex; justify-content: center; align-items: center; position: relative; min-height: 44px; }
/* The clock sits directly above the task area, in the line of sight. Its space is always reserved,
   so the stimuli appear in exactly the same place with and without time pressure. */
.clock { font: 700 1.4rem ui-monospace, monospace; padding: 4px 14px; border-radius: 10px; font-variant-numeric: tabular-nums;
  min-height: 2.2rem; line-height: 1.6rem; margin-bottom: 14px; text-align: center; }
.clock.idle { visibility: hidden; }
.clock.warn { color: var(--accent); }
.clock.over { color: #fff; background: var(--bad); }
.quit { position: absolute; right: 0; top: 4px; border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; min-width: 44px; min-height: 44px; cursor: pointer; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0;
}
.btn {
  display: inline-block; border: 0; border-radius: 10px; padding: 12px 20px;
  background: var(--primary); color: var(--primary-ink); font: inherit; font-weight: 600;
  cursor: pointer; min-height: 48px;
}
.btn.secondary { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
kbd {
  display: inline-block; min-width: 1.8em; text-align: center; padding: 1px 6px;
  border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 6px;
  background: var(--card); font: 600 0.9em ui-monospace, monospace;
}
ul.plain { padding-left: 1.2em; margin: 0.5rem 0; }

/* Task stage */
.stage-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; }
.stage { display: flex; gap: 6vw; justify-content: center; align-items: center; height: 140px; }
.slot {
  width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--line); background: transparent;
}
.slot.on { background: var(--target); border-color: var(--target); }
.fix { font-size: 2rem; color: var(--muted); height: 2.5rem; text-align: center; }
.feedback { height: 2rem; font-weight: 700; text-align: center; }
.feedback.bad { color: var(--bad); }
.feedback.good { color: var(--good); }
.progress { color: var(--muted); font-size: 0.85rem; text-align: center; margin-top: 8px; }

/* Touch pads */
.pads { display: none; width: 100%; gap: 16px; margin-top: 16px; }
.touch .pads { display: flex; }
.pad { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pad h3 { grid-column: 1 / -1; margin: 0; font-size: 0.8rem; color: var(--muted); text-align: center; font-weight: 600; }
.pad button {
  min-height: 72px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: 600 0.95rem system-ui, sans-serif; touch-action: manipulation;
}
.pad button:active { background: var(--slot); }
.pad.inactive { opacity: 0.35; }

/* Results */
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.state { font-size: 0.75rem; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.headline { font-size: 1.15rem; }
.cost-bar { position: relative; height: 28px; margin: 10px 0 4px; }
.cost-bar .axis { position: absolute; top: 13px; left: 0; right: 0; height: 2px; background: var(--line); }
.cost-bar .zero { position: absolute; top: 4px; width: 2px; height: 20px; background: var(--muted); }
.cost-bar .ci { position: absolute; top: 9px; height: 10px; border-radius: 5px; background: var(--primary); opacity: 0.35; }
.cost-bar .pt { position: absolute; top: 6px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--primary); }
.tone-btns { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 480px) {
  h1 { font-size: 1.45rem; }
  .slot { width: 52px; height: 52px; }
  .stage { gap: 8vw; }
}

/* Experiment 2: colour words + digits on a fixed dark panel (same contrast in light and dark mode) */
.stroop-panel {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  width: 100%; max-width: 560px; height: 160px; padding: 0 16px;
  background: #15191f; border-radius: var(--radius);
}
.stroop-panel .fix { color: #8792a2; }
.stroop-panel .digit { justify-self: end; font: 700 3rem system-ui, sans-serif; color: #e6eaf0; min-width: 2ch; text-align: center; }
.stroop-panel .word { justify-self: start; font: 800 2.6rem system-ui, sans-serif; letter-spacing: 0.04em; }
.swatch { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; margin-right: 6px; vertical-align: -0.05em; }
.swatch.big { width: 1.6em; height: 1.6em; vertical-align: middle; margin-right: 8px; }
.ink-check { display: flex; gap: 20px; flex-wrap: wrap; margin: 8px 0 12px; align-items: center; }
@media (max-width: 480px) {
  .stroop-panel { height: 130px; }
  .stroop-panel .digit { font-size: 2.4rem; }
  .stroop-panel .word { font-size: 1.9rem; }
}
.card.update { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-color: var(--primary); }
h3.sub { font-size: 0.95rem; margin: 1rem 0 0.25rem; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 460px; }

/* Experiment 3: remember while you work */
.ospan { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 62vh; gap: 12px; }
.center { text-align: center; justify-content: center; }
.mathacc { font-weight: 700; color: var(--bad); font-size: 0.95rem; min-height: 1.4em; }
.mathacc .low { text-decoration: underline; }
.op-problem, .op-answer { font: 700 2.4rem system-ui, sans-serif; font-variant-numeric: tabular-nums; text-align: center; }
.big-letter { font: 800 5rem system-ui, sans-serif; min-height: 6rem; text-align: center; }
.btn.big { font-size: 1.1rem; padding: 16px 28px; }
.btn.tf { min-width: 130px; font-size: 1.1rem; }
.recall-seq { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 3rem; }
.recall-seq span { min-width: 2.2rem; text-align: center; font: 700 1.6rem ui-monospace, monospace; border-bottom: 3px solid var(--line); }
.recall-seq span.filled { border-color: var(--primary); }
.letter-grid { display: grid; grid-template-columns: repeat(4, 64px); gap: 8px; }
.letter-grid .lg { height: 56px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: 700 1.3rem system-ui, sans-serif; cursor: pointer; touch-action: manipulation; }
.letter-grid .lg:active { background: var(--slot); }
.set-feedback { text-align: center; font-size: 1.15rem; }
.good-text { color: var(--good); font-weight: 700; }
.hold { font-size: 1rem; }
@media (max-width: 480px) {
  .op-problem, .op-answer { font-size: 1.9rem; }
  .letter-grid { grid-template-columns: repeat(4, 56px); }
}

/* Saved results, consent, history */
.data-card { border-color: var(--primary); }
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field input, .field select { font: inherit; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); min-height: 44px; }
.switch + .switch { margin-top: 10px; }
.btn.rate { min-width: 52px; }
.btn.rate.chosen { background: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--bad); color: #fff; }
.linkish { border: 0; background: none; color: var(--bad); text-decoration: underline; cursor: pointer; font: inherit; font-size: 0.85rem; padding: 4px; }
.hist-chart { width: 100%; height: auto; margin: 8px 0; }
.hist-chart .series { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.hist-chart .pt { fill: var(--primary); stroke: var(--card); stroke-width: 2; }
.hist-chart .hit { fill: transparent; }
.hist-chart .grid { stroke: var(--line); stroke-width: 1; }
.hist-chart .zero { stroke: var(--muted); stroke-width: 1; }
.hist-chart .tick { fill: var(--muted); font-size: 11px; }

/* Top bar: person icon opens "You & your data" */
.me-btn { position: relative; border: 0; background: transparent; color: var(--primary); width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; cursor: pointer; }
.me-btn:hover, .me-btn:focus-visible { background: var(--slot); }
.me-dot { position: absolute; top: 9px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--good); border: 2px solid var(--card); }
.me-dot[hidden] { display: none; }

/* Home sections */
.test-section { margin: 24px 0 8px; }
.test-section h2 { margin: 0 0 2px; font-size: 1.15rem; }
.test-section .tiles { margin: 10px 0 0; }
@media (min-width: 640px) { .test-section .tiles { grid-template-columns: 1fr 1fr; } }
.hub-grid { display: grid; gap: 12px; margin-top: 12px; }
@media (min-width: 640px) { .hub-grid { grid-template-columns: 1fr 1fr; } }
.app-footer { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 8px; }
.home-hero { padding-top: 32px; }
.hero-icon.big { width: 96px; height: 96px; border-radius: 24px; }
.lead { font-size: 1.25rem; font-weight: 600; margin: 4px 0 8px; }
.home-hero .row { margin: 20px 0 8px; }
.status { margin-top: 8px; font-size: 0.9rem; border-radius: 8px; }
.status:empty { display: none; }
.status.ok { color: var(--good); background: color-mix(in srgb, var(--good) 10%, transparent); padding: 8px 10px; }
.status.error { color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); padding: 8px 10px; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.soon-tag { font-size: 0.7rem; font-weight: 600; color: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: 0 6px; vertical-align: middle; white-space: nowrap; }
h1 .soon-tag { font-size: 0.8rem; }
.tile.party { border-color: #c026d3; background: color-mix(in srgb, #c026d3 6%, var(--card)); }
.tile.party.primary { border-width: 2px; }
fieldset.choice { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 12px 0 0; }
fieldset.choice legend { padding: 0 4px; }
label.radio { display: flex; gap: 10px; align-items: center; padding: 8px 0; cursor: pointer; }
label.radio input { width: 20px; height: 20px; accent-color: var(--primary); }
.tile.choice-tile { border-width: 2px; }
.privacy-promise { margin: 8px 0; padding: 10px 12px; border-radius: 10px; border-left: 4px solid var(--good);
  background: color-mix(in srgb, var(--good) 8%, transparent); font-size: 0.9rem; }

/* Party events */
.card.share { display: grid; gap: 16px; align-items: center; }
@media (min-width: 560px) { .card.share { grid-template-columns: 180px 1fr; } }
.qr { width: 180px; max-width: 60vw; background: #fff; padding: 6px; border-radius: 10px; justify-self: center; }
.qr svg { width: 100%; height: auto; display: block; }
.event-link code { word-break: break-all; font-size: 0.85rem; }
tr.mine td { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.linkish { border: 0; background: none; color: var(--bad); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.card.invite { border-color: var(--primary); }
