:root {
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #242422;
  --line: #383835;
  --text: #f0efec;
  --muted: #c3c2b7;
  --accent: #3987e5;
  --good: #0ca30c;
  --bad: #d03b3b;
  --neutral: #7a7974;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  /* iOS Safari ignores user-scalable=no, so this is what stops a quick double
     tap anywhere on the page (between buttons, on text, on a panel that just
     re-rendered) from zooming in. Effective touch-action intersects every
     ancestor's, so setting it here covers the whole page. */
  touch-action: manipulation;
}

body.fullscreen {
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
}

a {
  color: var(--accent);
}

button,
.button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  text-decoration: none;
  display: inline-block;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  opacity: 0.4;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.big {
  width: 100%;
  padding: 14px;
  font-size: 18px;
  margin-top: 8px;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 18px 48px;
}

h1 {
  font-size: 28px;
  margin: 8px 0 4px;
}

h2 {
  font-size: 19px;
  margin: 28px 0 6px;
}

.lede {
  font-size: 18px;
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.back {
  text-decoration: none;
  font-size: 15px;
}

.cards {
  display: grid;
  gap: 10px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  text-decoration: none;
}

.card span {
  color: var(--muted);
  font-size: 14px;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
}

.device {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 12px 0;
}

.device b {
  color: var(--text);
}

.warn {
  color: #fab219;
  margin-top: 4px;
}

.sources {
  font-size: 14px;
  color: var(--muted);
  padding-left: 18px;
}

.sources li {
  margin-bottom: 6px;
}

.ref {
  font-size: 0.7em;
}

.ref a {
  text-decoration: none;
}

.sources li.flash {
  animation: flash 1.6s ease-out;
}

@keyframes flash {
  from {
    background: rgba(57, 135, 229, 0.35);
  }
  to {
    background: transparent;
  }
}

/* Full-screen experience layout */

.run {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(8px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  gap: 8px;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}

.run-top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 28px;
}

.run-top .back {
  font-size: 26px;
  line-height: 1;
  padding: 0 6px;
}

.run-title {
  font-weight: 600;
  font-size: 15px;
}

.ab {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ab button {
  font-size: 20px;
  font-weight: 700;
  padding: 8px;
}

.ab button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ab button.pulse {
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  to {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(57, 135, 229, 0.45);
  }
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
}

.answers .hint {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 6px;
}

.answer-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.answer-row button {
  padding: 12px 6px;
  font-size: 15px;
}

.reveal {
  position: absolute;
  inset: 0;
  background: rgba(17, 17, 16, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.reveal.hidden {
  display: none;
}

.reveal-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.verdict {
  font-size: 22px;
  font-weight: 700;
}

.verdict.right {
  color: var(--good);
}

.verdict.wrong {
  color: #e86a6a;
}

.reveal-card button {
  margin-top: 8px;
}

/* Keypad. No CSS transitions or :active styles: every visual change is driven
   by the frame-delayed queue, never by the browser directly. */

.keypad {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 12px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.kp-display {
  flex: 0 0 auto;
  font-size: 44px;
  font-weight: 600;
  text-align: right;
  padding: 4px 8px;
  font-variant-numeric: tabular-nums;
}

.kp-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 10px;
}

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  background: var(--surface-2);
  border-radius: 14px;
  -webkit-tap-highlight-color: transparent;
}

.key.down {
  background: var(--accent);
  color: #fff;
}

/* Scroller */

.scroller {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.scroll-content {
  will-change: transform;
}

.sec {
  padding: 14px 16px 6px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--bg);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 68px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  flex: none;
}

.row-text {
  flex: 1;
  min-width: 0;
}

.row-title {
  font-weight: 600;
}

.row-sub {
  font-size: 13px;
  color: var(--muted);
}

.row-price {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* Playground controls */

.controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
}

.tabs button {
  padding: 7px 2px;
  font-size: 13px;
  white-space: nowrap;
}

.tabs button.active {
  border-color: var(--accent);
  color: #fff;
  background: rgba(57, 135, 229, 0.25);
}

.control.hidden {
  display: none;
}

.explain {
  font-size: 13px;
  color: var(--muted);
  min-height: 3.2em;
  margin-top: 4px;
}

.controls .device {
  margin: 2px 0 0;
}

.control-head {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.control-head output {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.control input[type='range'] {
  width: 100%;
  margin: 2px 0;
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 999px;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Results */

.headline {
  font-size: 18px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 13px;
  color: var(--muted);
  margin: 10px 0;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cell {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-style: normal;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

.legend .cell {
  width: 20px;
  height: 20px;
  font-size: 12px;
}

.cell.right {
  background: var(--good);
}

.cell.wrong {
  background: var(--bad);
}

.results {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 8px 0 16px;
}

.res-row {
  display: grid;
  grid-template-columns: 9em 1fr 2.6em;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.cells {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.res-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.history-link {
  display: inline-block;
  margin-top: 12px;
}

.run-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 10px 0;
}

.run-item summary {
  cursor: pointer;
  list-style: none;
}

.run-item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.run-item-head span,
.run-item-headline {
  color: var(--muted);
  font-size: 14px;
}

details {
  margin: 16px 0;
}

.findings {
  margin: -6px 0 16px;
  padding: 2px 14px;
  border-left: 3px solid var(--line);
}

.findings summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 15px;
}

.findings p {
  margin: 8px 0;
}

.trials {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}

.trials th,
.trials td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
}

.actions {
  display: flex;
  gap: 10px;
}

.footer {
  margin-top: 28px;
}
