/* CPS test. Same paper-and-ink palette as the Pastime Arcade hub; the click pad is
   dot-grid paper and every click stamps an ink mark on it. */
:root {
  --paper: #faf8f2;
  --ink: #292d28;
  --muted: #697064;
  --line: #dfdfd3;
  --accent: #bd5f3e;
  --teal: #24878b;
  --pad: #fffdf8;
  --dot: #d5d3c4;
  --ink-mark: #bd5f3e;
  --display: ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", "Arial Rounded MT Bold", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1b1d1a; --ink: #ecebe3; --muted: #a3a898; --line: #3a3d36;
    --accent: #e27f5a; --teal: #58b9bd; --pad: #232621; --dot: #3d4138; --ink-mark: #e27f5a;
  }
}
:root[data-theme="dark"] {
  --paper: #1b1d1a; --ink: #ecebe3; --muted: #a3a898; --line: #3a3d36;
  --accent: #e27f5a; --teal: #58b9bd; --pad: #232621; --dot: #3d4138; --ink-mark: #e27f5a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid var(--teal); outline-offset: 4px; }
.wrap { width: min(1120px, calc(100% - 48px)); margin: 0 auto; }

/* ---------- header ---------- */
.site-header {
  display: flex; align-items: center; gap: 20px;
  padding: 20px 0; border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; text-decoration: none; white-space: nowrap; }
.crumbs { flex: 1; color: var(--muted); font-size: 15px; min-width: 0; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { margin: 0 8px; color: var(--line); }
.crumbs [aria-current] { color: var(--ink); }
.theme-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: transparent; display: grid; place-items: center; cursor: pointer;
}
.theme-btn:hover { border-color: var(--ink); }
.theme-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.langs { display: flex; gap: 2px; }
.langs a { padding: 5px 8px; border-radius: 999px; font-size: 13px; font-weight: 700; letter-spacing: .03em; color: var(--muted); text-decoration: none; }
.langs a:hover { color: var(--ink); }
.langs a[aria-current] { color: var(--ink); background: var(--line); }

/* ---------- intro ---------- */
.intro { padding: 34px 0 22px; }
.intro h1 {
  margin: 0; font-family: var(--display); font-weight: 800;
  font-size: clamp(40px, 6.4vw, 68px); line-height: 1.02; letter-spacing: -0.02em;
}
.lede { margin: 12px 0 0; font-size: 18px; color: var(--muted); max-width: 58ch; }

.durations { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; }
.durations a {
  padding: 7px 16px; border: 1.5px solid var(--line); border-radius: 999px;
  text-decoration: none; font-size: 15px; color: var(--muted);
}
.durations a:hover { border-color: var(--ink); color: var(--ink); }
.durations a[aria-current] { background: var(--ink); border-color: var(--ink); color: var(--paper); font-weight: 600; }

.mode-switch { display: inline-flex; margin: 0 0 18px; border: 1.5px solid var(--ink); border-radius: 999px; overflow: hidden; }
.mode-switch button { border: 0; background: transparent; padding: 8px 18px; cursor: pointer; font-weight: 600; }
.mode-switch button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.stop-row { margin: 14px 0 0; min-height: 0; }
.stop-row:has([hidden]) { margin: 0; }

.challenge {
  margin: 0 0 20px; padding: 12px 16px; border-left: 4px solid var(--accent);
  background: var(--pad); font-weight: 600;
}

/* ---------- bench: pad + readout ---------- */
.bench { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 24px; align-items: stretch; }
.pad {
  grid-column: 1; grid-row: 1;
  position: relative; overflow: hidden; display: grid; place-items: center;
  min-height: 430px; padding: 0; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 20px;
  background-color: var(--pad);
  background-image: radial-gradient(var(--dot) 1.3px, transparent 1.4px);
  background-size: 22px 22px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  /* Idle: a swipe that starts on the pad may still scroll the page, but no double-tap or pinch zoom. */
  touch-action: pan-y;
}
.pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.pad-msg {
  position: relative; font-family: var(--display); font-weight: 700;
  font-size: clamp(22px, 3vw, 30px); pointer-events: none; padding: 0 20px; text-align: center;
}
/* Running: fast two-finger tapping must never turn into a scroll or a pinch. */
.pad.is-running { border-color: var(--teal); touch-action: none; }
.pad.is-locked { cursor: default; border-style: dashed; }
.pad.is-record { border-color: var(--accent); border-style: solid; }
.pad.is-record .pad-msg { color: var(--accent); font-size: clamp(30px, 5vw, 46px); }
.pad.hit { animation: press 90ms ease-out; }
@keyframes press { from { transform: scale(.993); } to { transform: scale(1); } }

.readout { grid-column: 2; grid-row: 1; margin: 0; display: flex; flex-direction: column; gap: 0; border-top: 2px solid var(--ink); }
.cell { padding: 14px 0 12px; border-bottom: 1px solid var(--line); }
.cell dt { font-size: 14px; color: var(--muted); }
.cell dd {
  margin: 0; font-family: var(--display); font-weight: 800; font-size: 40px; line-height: 1.1;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.cell.best dd { color: var(--accent); }
.cell.best.is-new dd { animation: record 1.1s ease-out; }
@keyframes record { 0% { transform: scale(1); } 25% { transform: scale(1.22); } 100% { transform: scale(1); } }
.cell.best dd { transform-origin: left center; }

/* ---------- result ---------- */
.result {
  margin-top: 28px; padding: 26px 0 6px; border-top: 2px solid var(--ink);
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 48px;
}
.score { grid-column: 1; }
.score-num { margin: 0; line-height: 1; }
.score-num #resCps {
  font-family: var(--display); font-weight: 800; font-size: clamp(64px, 10vw, 104px);
  letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
}
.score-num .unit { font-size: 17px; color: var(--muted); }
.score-sub { margin: 8px 0 0; color: var(--muted); }
.pb-note { margin: 6px 0 0; min-height: 1.6em; }
.pb-note.is-new { color: var(--accent); font-weight: 700; }
.pb-badge {
  display: inline-block; vertical-align: middle; margin-left: 10px; padding: 4px 12px;
  background: var(--accent); color: #fff; border-radius: 999px; font-size: 15px; font-weight: 700;
}
.touch-note { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.rank { grid-column: 1; margin-top: 10px; }
.rank-name { margin: 0; font-family: var(--display); font-weight: 800; font-size: 30px; }
.rank-line { margin: 2px 0 0; max-width: 46ch; }
.fade { margin: 12px 0 0; font-weight: 600; }
.series { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.series p { margin: 0 0 8px; font-weight: 600; }
.series ol { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.series li {
  font-family: var(--display); font-weight: 800; font-variant-numeric: tabular-nums;
  padding: 4px 12px; border: 1.5px solid var(--line); border-radius: 8px;
}
.series li.is-best { border-color: var(--accent); color: var(--accent); }
.pace { grid-column: 2; grid-row: 1 / span 2; margin: 0; align-self: end; }
.pace figcaption { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.bars { display: flex; align-items: flex-end; gap: 8px; }
.bar { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-val { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-track { width: 100%; height: 120px; display: flex; align-items: flex-end; border-bottom: 2px solid var(--ink); }
.bar-fill { width: 100%; background: var(--accent); border-radius: 6px 6px 0 0; }
.bar-lab { font-size: 13px; color: var(--muted); }
.actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 22px; }
.btn {
  padding: 11px 22px; border-radius: 999px; border: 1.5px solid var(--ink);
  background: transparent; cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.copied { font-size: 14px; color: var(--muted); word-break: break-all; }

/* ---------- article ---------- */
.prose { max-width: 70ch; margin: 56px 0 0; font-size: 17px; line-height: 1.7; }
.prose h2 { font-family: var(--display); font-weight: 800; font-size: 28px; line-height: 1.2; margin: 44px 0 10px; letter-spacing: -0.01em; }
.prose h3 { font-size: 19px; margin: 26px 0 6px; }
.prose p { margin: 0 0 14px; }
.prose ul, .prose ol { padding-left: 22px; margin: 0 0 14px; }
.prose li { margin-bottom: 6px; }
.prose a { color: var(--accent); }
.prose table { width: 100%; border-collapse: collapse; font-size: 16px; margin: 0 0 16px; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 9px 12px 9px 0; text-align: left; vertical-align: top; }
.prose th { border-bottom: 2px solid var(--ink); font-weight: 700; }
.prose td:first-child { font-weight: 700; white-space: nowrap; }
.faq details { border-bottom: 1px solid var(--line); padding: 12px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq-answer { padding: 8px 0 0; color: var(--muted); }

/* ---------- footer ---------- */
.site-footer { margin-top: 64px; padding: 22px 0 40px; border-top: 1px solid var(--line); color: var(--muted); font-size: 15px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 6px 22px; }
.site-footer a { text-decoration: none; color: var(--ink); }
.site-footer a:hover { color: var(--accent); }
.site-footer a[aria-current] { color: var(--muted); }
.site-footer .footer-site { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.site-footer p { margin: 10px 0 0; }

/* ---------- small screens: readout moves above the pad so it stays visible while tapping ---------- */
@media (max-width: 760px) {
  .wrap { width: calc(100% - 32px); }
  .site-header { gap: 12px; padding: 14px 0; }
  .crumbs { display: none; }
  .brand { flex: 1; }
  .intro { padding: 24px 0 16px; }
  .lede { font-size: 16px; }
  .durations { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 14px; padding: 2px 16px 6px; scrollbar-width: none; }
  .durations::-webkit-scrollbar { display: none; }
  .durations a { white-space: nowrap; flex: none; }
  .bench { grid-template-columns: 1fr; gap: 12px; }
  .readout { grid-column: 1; grid-row: 1; flex-direction: row; flex-wrap: wrap; border-top: 0; }
  .cell { flex: 1 1 50%; padding: 8px 0; }
  .cell dd { font-size: 28px; }
  .pad { grid-column: 1; grid-row: 2; min-height: 320px; border-radius: 16px; }
  .result { grid-template-columns: 1fr; }
  .pace { grid-column: 1; grid-row: auto; margin-top: 20px; }
  .bar-track { height: 96px; }
  .prose { font-size: 16px; margin-top: 40px; }
  .prose h2 { font-size: 23px; }
  .prose table { display: block; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) { .pad.hit, .cell.best.is-new dd { animation: none; } }

/* ---------- rank dialog ---------- */
.rank-dialog {
  width: min(460px, calc(100vw - 28px)); padding: 26px 22px 20px; text-align: center;
  border: 2px solid var(--ink); border-radius: 26px; background: var(--paper); color: var(--ink);
}
.rank-dialog::backdrop { background: rgba(24, 26, 23, .62); }
.rank-dialog[open] { animation: rank-pop .24s ease-out; }
.rank-dialog:focus { outline: none; }
@keyframes rank-pop { from { transform: translateY(12px) scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }
.emoji { font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; font-style: normal; }
.rank-close {
  position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: transparent; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer;
}
.rank-close:hover { color: var(--ink); background: var(--pad); }
.ladder { list-style: none; display: flex; justify-content: center; align-items: center; gap: 4px; margin: 0 0 16px; padding: 0; }
.ladder li { font-size: 22px; line-height: 1; padding: 7px; border-radius: 50%; opacity: .3; filter: grayscale(1); }
.ladder li.is-passed { opacity: .8; filter: none; }
.ladder li.is-here { opacity: 1; filter: none; font-size: 30px; background: var(--pad); box-shadow: 0 0 0 2px var(--accent); }
.rank-hero {
  width: 136px; height: 136px; margin: 0 auto 12px; display: grid; place-items: center; font-size: 78px; line-height: 1;
  border: 2px solid var(--ink); border-radius: 50%; background-color: var(--pad);
  background-image: radial-gradient(var(--dot) 1.3px, transparent 1.4px); background-size: 22px 22px;
}
.rank-dialog[open] .rank-hero { animation: rank-hero .5s cubic-bezier(.2, 1.4, .4, 1) .08s both; }
@keyframes rank-hero { from { transform: scale(.6) rotate(-8deg); } to { transform: none; } }
.rank-dialog h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 36px; line-height: 1.1; letter-spacing: -0.01em; }
.rank-score { margin: 6px 0 0; font-family: var(--display); font-weight: 800; font-size: 28px; font-variant-numeric: tabular-nums; }
.rank-score .unit { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 400; font-size: 15px; color: var(--muted); }
.rank-detail { margin: 2px 0 0; color: var(--muted); font-size: 15px; }
.rank-best { margin: 10px 0 0; font-weight: 700; color: var(--accent); }
.rank-text { margin: 12px auto 0; max-width: 36ch; }
.rank-next { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 15px; color: var(--muted); }
.rank-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 18px; transition: opacity .2s; }
.rank-dialog.is-guarded .rank-actions { pointer-events: none; opacity: .5; }
.rank-copied { margin: 10px 0 0; min-height: 1.4em; font-size: 14px; color: var(--muted); word-break: break-all; }
@media (max-width: 760px) { .rank-hero { width: 116px; height: 116px; font-size: 66px; } .rank-dialog h2 { font-size: 30px; } .rank-actions .btn { padding: 10px 16px; } }
@media (prefers-reduced-motion: reduce) { .rank-dialog[open], .rank-dialog[open] .rank-hero { animation: none; } }

/* ---------- share sheet (desktop fallback inside the rank dialog) ---------- */
.share-sheet { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.share-sheet img { display: block; width: 100%; height: auto; border: 1.5px solid var(--line); border-radius: 12px; }
.share-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.share-actions .btn { padding: 8px 16px; font-size: 15px; text-decoration: none; }

/* Illustrated rank mascots, including compact mobile ladders. */
.ladder li { width: 42px; height: 42px; padding: 2px; flex: 0 1 42px; min-width: 0; }
.rank-hero { overflow: hidden; background: #faf8f2; }
