/* Tres Tap. System fonts only (P1). Behavior colors are from the Okabe-Ito
   palette, chosen to stay distinct with common color-vision deficiencies;
   buttons are also told apart by number and name (N5). */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #14181f;
  --muted: #4d5663;
  --line: #d5dae1;
  --accent: #0b5cad;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --danger-text: #ffffff;
  --warn-bg: #fff4d6;
  --warn-text: #5c4000;
  --info-bg: #e3effc;
  --info-text: #0b3a6b;
  --focus: #0b5cad;
  --b1: #0072b2; --b1-text: #ffffff;
  --b2: #e69f00; --b2-text: #111111;
  --b3: #009e73; --b3-text: #111111;
  --radius: 14px;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a24;
    --surface: #182633;
    --text: #eef2f6;
    --muted: #a9b5c2;
    --line: #2d3e4f;
    --accent: #6cb4ff;
    --accent-text: #08131d;
    --danger: #ff8a80;
    --danger-text: #2a0705;
    --warn-bg: #3d2f00;
    --warn-text: #ffe08a;
    --info-bg: #0d2c4a;
    --info-text: #cfe5ff;
    --focus: #6cb4ff;
  }
}

/* Makes iOS Safari follow the Dynamic Type text size. */
html { font: -apple-system-body; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

h1, h2 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
h1:focus, h2:focus { outline: none; }
p { margin: 0.5rem 0; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.wrap { max-width: 44rem; margin: 0 auto; padding: 0 var(--gutter) 3rem; padding-left: max(var(--gutter), env(safe-area-inset-left)); padding-right: max(var(--gutter), env(safe-area-inset-right)); }
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  max-width: 44rem; margin: 0 auto; padding: 1rem var(--gutter) 0.5rem;
  padding-top: max(1rem, env(safe-area-inset-top));
}
.lede { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.hint { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); font-weight: 600; }
.block { margin-top: 1.5rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0; }
.row.end { justify-content: flex-end; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600;
  min-height: 44px; min-width: 44px; padding: 0.55rem 1rem;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  cursor: pointer; touch-action: manipulation;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: currentColor; background: var(--surface); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.big { display: block; width: 100%; font-size: 1.25rem; min-height: 64px; margin: 1rem 0 0.25rem; }
.btn.small { min-height: 36px; padding: 0.2rem 0.7rem; font-size: 0.9rem; }
.linkish { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
kbd { font: inherit; font-size: 0.8em; border: 1px solid currentColor; border-radius: 6px; padding: 0 0.4em; margin-left: 0.4em; opacity: 0.85; }

.banner { border-radius: 10px; padding: 0.75rem 1rem; margin: 0.75rem 0; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.info { background: var(--info-bg); color: var(--info-text); }
#storage-warning { margin: 0.75rem var(--gutter); }
.note { margin-top: 2rem; padding: 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }

/* Forms */
label { display: block; font-weight: 600; margin-top: 0.75rem; }
input[type="text"], input[type="number"] {
  font: inherit; width: 100%; box-sizing: border-box; min-height: 44px;
  padding: 0.5rem 0.75rem; border-radius: 10px; border: 1px solid var(--muted);
  background: var(--surface); color: var(--text);
}
input[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.field { margin-bottom: 0.5rem; }
.name-field { display: grid; grid-template-columns: auto 1fr; gap: 0 0.75rem; align-items: center; }
.name-field label { grid-column: 1 / -1; }
.name-field .error { grid-column: 1 / -1; }
.swatch { display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: 10px; font-weight: 800; }
.check { display: flex; align-items: center; gap: 0.75rem; margin: 0.75rem 0; }
.check input { width: 1.5rem; height: 1.5rem; margin: 0; flex: none; }
.check label { margin: 0; font-weight: 400; }
ul.plain { padding-left: 1.2rem; }
ul.plain li { margin: 0.4rem 0; }

/* Past sessions */
.past { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.past-item {
  display: grid; gap: 0.15rem; width: 100%; text-align: left;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 1rem; cursor: pointer;
}
.past-title { font-weight: 700; }
.past-detail { color: var(--muted); font-size: 0.9rem; }
.tag { display: inline-block; font-size: 0.8rem; font-weight: 700; padding: 0 0.5em; border-radius: 999px; background: var(--warn-bg); color: var(--warn-text); margin-left: 0.4em; }

.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.95em; word-break: break-all; }
.code b { font-weight: 800; background: var(--info-bg); color: var(--info-text); border-radius: 4px; padding: 0 0.15em; }

/* Session screen: fills the viewport; the three buttons take most of it (F5). */
.session {
  position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr;
  background: var(--bg); overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.session-bar {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.25rem 0.75rem;
  padding: 0.5rem 0.75rem 0;
}
.timer { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.2rem; font-variant-numeric: tabular-nums; min-width: 0; }
.countdown { font-size: 2.5rem; font-weight: 800; line-height: 1; }
.unit { font-size: 1.25rem; color: var(--muted); }
.key-hint { margin-left: 0.6rem; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.key-hint kbd { margin-left: 0.25em; padding: 0 0.35em; }
.session-actions { display: flex; gap: 0.5rem; }
.session-actions .btn { white-space: nowrap; }
.progress { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; width: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); }

.pads { display: grid; grid-template-rows: repeat(3, 1fr); gap: 0.5rem; padding: 0.5rem 0.75rem 0.75rem; min-height: 0; }
.pad {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.75rem;
  min-width: 64px; min-height: 64px; padding: 0.75rem 1.25rem;
  font: inherit; text-align: left; border: 0; border-radius: 18px; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.pad-1 { background: var(--b1); color: var(--b1-text); }
.pad-2 { background: var(--b2); color: var(--b2-text); }
.pad-3 { background: var(--b3); color: var(--b3-text); }
.pad-num {
  display: grid; place-items: center; width: 3rem; height: 3rem; border-radius: 50%;
  border: 3px solid currentColor; font-size: 1.6rem; font-weight: 800;
}
.pad-name { font-size: clamp(1.5rem, 6vmin, 3rem); font-weight: 800; overflow-wrap: anywhere; }
.pad-count { font-size: clamp(1.75rem, 8vmin, 3.5rem); font-weight: 800; font-variant-numeric: tabular-nums; }
/* Wide screens: three columns, each button's number, name and count stacked and centered. */
@media (orientation: landscape) and (min-aspect-ratio: 5/4) {
  .pads { grid-template-rows: none; grid-template-columns: repeat(3, 1fr); }
  .pad { grid-template-columns: 1fr; grid-template-rows: none; align-content: center; justify-items: center; text-align: center; gap: 1rem; }
}
.pad:disabled { cursor: default; filter: saturate(0.35); opacity: 0.55; }
.pad::after { content: ""; position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.pad.hit::after { animation: hit 220ms ease-out; }
.pad.hit { animation: press 160ms ease-out; }
@keyframes hit { from { opacity: 0.55; } to { opacity: 0; } }
@keyframes press { from { transform: scale(0.97); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .pad.hit { animation: none; } }

.ready-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(28rem, calc(100% - 2 * var(--gutter))); max-height: calc(100% - 2rem); overflow: auto; box-sizing: border-box;
  background: var(--surface); color: var(--text); border-radius: var(--radius);
  padding: 1.25rem; box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
}
.ready-card h2 { margin-top: 0; }
.code-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.5rem; }

/* While a session runs: no selection, long-press menus, zoom or pull-to-refresh (N3). */
html.running, html.running body { overscroll-behavior: none; overflow: hidden; }
html.running .session, html.running .pad { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* Review */
.meta { font-size: 1rem; }
.counts { list-style: none; padding: 0; margin: 1rem 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
.count-card { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; overflow-wrap: anywhere; padding: 0.75rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.count-card .swatch { flex: none; }
.count-num { font-size: 1.75rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }

.timeline { margin: 1rem 0; }
.timeline-rows { display: grid; gap: 4px; }
.tl-row { display: grid; grid-template-columns: 5.5rem 1fr; align-items: center; gap: 0.5rem; }
.tl-name { font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-track { position: relative; height: 28px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.tl-mark { position: absolute; top: 3px; bottom: 3px; width: 3px; margin-left: -1px; border-radius: 2px; }
.tl-row-1 .tl-mark { background: var(--b1); }
.tl-row-2 .tl-mark { background: var(--b2); }
.tl-row-3 .tl-mark { background: var(--b3); }
.tl-after { position: absolute; top: 0; bottom: 0; right: 0; background: repeating-linear-gradient(135deg, transparent 0 4px, var(--line) 4px 6px); }
.timeline-axis { position: relative; height: 1.4rem; margin-left: 6rem; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-tick { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.tl-tick:first-child { transform: none; }
.tl-tick:last-child { transform: translateX(-100%); }
.timeline figcaption { margin-top: 0.25rem; }

.table-wrap { overflow-x: auto; }
.events { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.events th, .events td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); }
.events .num { text-align: right; }
.dot { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; margin-right: 0.4em; vertical-align: -0.05em; }
.dot-1, .swatch-1 { background: var(--b1); color: var(--b1-text); }
.dot-2, .swatch-2 { background: var(--b2); color: var(--b2-text); }
.dot-3, .swatch-3 { background: var(--b3); color: var(--b3-text); }

/* Toast and dialogs */
.toast {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 2 * var(--gutter)); box-sizing: border-box;
  background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: 10px;
  font-weight: 600; opacity: 0; transition: opacity 150ms; pointer-events: none; z-index: 10;
}
.toast.show { opacity: 1; }

dialog {
  border: 0; border-radius: var(--radius); padding: 1.25rem; max-width: min(30rem, calc(100% - 2 * var(--gutter)));
  background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog h2 { margin-top: 0; }
.export-grid { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.5rem 1rem; margin: 1rem 0; }
