/* Word search. Starts as a copy of ../screen-test/styles.css (the shared paper-and-ink look of
   ../cps-test, plus the verdict, toolbar and chips of ../mouse-test), and is extended at the bottom
   with the puzzle grid, the word list, the maker form and the print layout. Keep the shared part in
   step by hand. */
: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; } }

/* ---------- from the mouse test: pad text, chips, verdict, toolbar, log ---------- */
.pad { align-content: center; gap: 18px; cursor: crosshair; }
.pad.is-active { border-color: var(--teal); }
.pad-sub { position: relative; pointer-events: none; color: var(--muted); font-size: 16px; padding: 0 24px; text-align: center; max-width: 48ch; }
.pad-big { position: relative; pointer-events: none; font-family: var(--display); font-weight: 800; font-variant-numeric: tabular-nums; font-size: clamp(44px, 9vw, 92px); line-height: 1; letter-spacing: -0.03em; }
.pad-big small { font-size: 0.32em; font-weight: 700; color: var(--muted); letter-spacing: 0; margin-left: 6px; }

/* the mouse drawing: parts light while held and stay marked once they have registered */
.mouse { position: relative; pointer-events: none; width: clamp(150px, 26vw, 210px); height: auto; }
.mouse .part { fill: var(--pad); stroke: var(--ink); stroke-width: 3; transition: fill 60ms; }
.mouse .part.is-ok { fill: color-mix(in srgb, var(--teal) 22%, var(--pad)); }
.mouse .part.is-down { fill: var(--accent); }
.mouse .body { fill: var(--pad); stroke: var(--ink); stroke-width: 3; }
.mouse .arrow { fill: none; stroke: var(--line); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.mouse .arrow.is-ok { stroke: var(--teal); }
.mouse .arrow.is-down { stroke: var(--accent); }

.checks { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.checks li { padding: 6px 14px; border: 1.5px solid var(--line); border-radius: 999px; font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.checks li.is-ok { border-color: var(--teal); color: var(--ink); }
.checks li.is-ok::before { content: "\2713  "; color: var(--teal); font-weight: 800; }
.checks li.is-bad { border-color: var(--accent); color: var(--accent); font-weight: 700; }

.verdict { margin: 18px 0 0; padding: 12px 16px; border-left: 4px solid var(--line); background: var(--pad); font-weight: 600; max-width: 70ch; }
.verdict.is-good { border-left-color: var(--teal); }
.verdict.is-bad { border-left-color: var(--accent); color: var(--accent); }
.verdict a { color: inherit; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 18px 0 0; }
.toolbar .label { color: var(--muted); font-size: 15px; }
.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 7px 14px; cursor: pointer; font-weight: 600; font-variant-numeric: tabular-nums; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

.log { margin: 18px 0 0; padding: 0; list-style: none; max-width: 70ch; font-variant-numeric: tabular-nums; border-top: 2px solid var(--ink); }
.log li { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.log li.is-bad { color: var(--accent); font-weight: 700; }
.log li span:last-child { color: var(--muted); }
.log li.is-bad span:last-child { color: inherit; }
.log-empty { color: var(--muted); }
.touch-warning { margin: 0 0 18px; padding: 12px 16px; border-left: 4px solid var(--accent); background: var(--pad); font-weight: 600; }
@media (max-width: 760px) { .pad { gap: 12px; } .checks li { font-size: 14px; padding: 5px 11px; } }

.bench.solo { grid-template-columns: minmax(0, 1fr); }
.bench.solo .pad { grid-column: 1; min-height: 460px; }
.cell.is-bad dd { color: var(--accent); }
.cell .small { font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1.35; letter-spacing: 0; }
@media (max-width: 760px) { .bench.solo .pad { min-height: 360px; } }


/* ---------- word search ---------- */
.btn[disabled] { opacity: .55; cursor: default; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
a.btn { color: var(--ink); text-decoration: none; }
.stick-note { margin: 12px 0 0; color: var(--muted); font-size: 15px; }
.chips { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 6px 14px; border: 1.5px solid var(--line); border-radius: 999px; background: transparent; cursor: pointer; font-size: 15px; }
.chips button:hover { border-color: var(--ink); }
.chips button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); font-weight: 600; }
.toolbar select, .ws-maker input, .ws-maker textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--pad);
  border: 1.5px solid var(--ink); border-radius: 12px; padding: 8px 12px;
}
.toolbar select { border-radius: 999px; padding: 7px 14px; }
.ws-maker { display: grid; gap: 6px; max-width: 640px; margin: 0 0 8px; }
.ws-maker textarea { resize: vertical; min-height: 150px; line-height: 1.5; }
.ws-maker .toolbar { margin-top: 10px; }

.ws-board { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 24px; align-items: start; margin-top: 18px; }
.ws-grid-wrap {
  position: relative; container-type: inline-size; padding: 10px; max-width: 680px;
  border: 2px solid var(--ink); border-radius: 18px; background: var(--pad);
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer;
}
.ws-grid { --n: 10; display: grid; grid-template-columns: repeat(var(--n), 1fr); font-family: var(--display); font-weight: 800; font-size: calc(100cqw / var(--n) * .52); line-height: 1; }
.ws-grid span { aspect-ratio: 1; display: grid; place-items: center; }
.ws-grid span.is-start { color: var(--accent); }
.ws-marks { position: absolute; left: 10px; top: 10px; width: calc(100% - 20px); height: calc(100% - 20px); pointer-events: none; overflow: visible; }
.ws-marks line { stroke-linecap: round; }
.ws-marks .sel { stroke: var(--accent); opacity: .28; }
.ws-status { margin: 0 0 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ws-status span { color: var(--ink); font-weight: 700; }
.ws-title { margin: 0 0 8px; font-family: var(--display); font-size: 22px; }
.ws-words { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 14px; font-weight: 600; letter-spacing: .03em; }
.ws-words.is-long { columns: 1; }
.ws-words li { padding: 3px 0; break-inside: avoid; overflow-wrap: anywhere; } /* last resort: never wider than the list */
.ws-words li.is-found { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 2px; font-weight: 400; }
.ws-words li i { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; background: var(--line); vertical-align: 1px; }

.print-area { display: none; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff !important; }
  body > :not(.print-area) { display: none !important; }
  .print-area { display: block; color: #000; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
  .print-page { break-after: page; page-break-after: always; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page h1 { margin: 0; font-size: 22pt; }
  .print-page .sub { margin: 2mm 0 5mm; font-size: 11pt; color: #444; }
  .print-page svg { display: block; width: 100%; max-height: 165mm; }
  .print-words { columns: 3; margin: 6mm 0 0; padding: 0; list-style: none; font-size: 12.5pt; font-weight: 600; letter-spacing: .04em; }
  .print-page.is-large .print-words { columns: 2; font-size: 17pt; }
  .print-words li { padding: 1mm 0; }
  .print-foot { margin-top: 6mm; font-size: 9pt; color: #666; }
}

@media (max-width: 760px) {
  .ws-board { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .ws-grid-wrap { padding: 6px; border-radius: 14px; }
  .ws-marks { left: 6px; top: 6px; width: calc(100% - 12px); height: calc(100% - 12px); }
  .ws-words, .ws-words.is-long { columns: auto 7.2em; font-size: 15px; } /* as many columns as fit, so long words never squeeze */
}
