/* Number Crunch: all styles. No remote fonts, no images beyond inline data URIs. */

:root {
  color-scheme: light dark;
  --bg: #f6f2ea;
  --surface: #ffffff;
  --surface-2: #efe9dd;
  --text: #1d1b26;
  --muted: #58546a;
  --line: #ddd5c4;
  --line-strong: #857e96;
  --accent: #4b32b8;
  --on-accent: #ffffff;
  --accent-soft: #e7e2fa;
  --big: #fff0c2;
  --ok: #0b6444;
  --ok-soft: #dcf2e7;
  --err: #a3262a;
  --err-soft: #fde5e3;
  --badge-bg: #1d1b26;
  --badge-text: #ffd666;
  --shadow: 0 1px 0 rgba(29, 27, 38, .08), 0 6px 18px rgba(29, 27, 38, .08);
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14131a;
    --surface: #1e1c27;
    --surface-2: #28263a;
    --text: #f2f0f8;
    --muted: #b8b4c8;
    --line: #36334a;
    --line-strong: #8a85a3;
    --accent: #bcaaff;
    --on-accent: #14131a;
    --accent-soft: #2f2a52;
    --big: #3d3420;
    --ok: #74dfb2;
    --ok-soft: #17352a;
    --err: #ff9f98;
    --err-soft: #3d1f22;
    --badge-bg: #ffd666;
    --badge-text: #1d1b26;
    --shadow: 0 1px 0 rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

h1, h2, h3, p, ol, ul, dl, dd, pre { margin: 0; }

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 8px;
}

[hidden] { display: none !important; }

.skip {
  position: absolute;
  left: 12px;
  top: -80px;
  background: var(--accent);
  color: var(--on-accent);
  padding: 10px 14px;
  border-radius: 10px;
  z-index: 10;
}
.skip:focus { top: 12px; }

/* ---------- header ---------- */

.top {
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 16px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-bg { fill: var(--accent); }
.logo-mark { stroke: var(--badge-text); fill: none; stroke-width: 8; stroke-linecap: round; }
.logo { flex: none; }
h1 { font-size: 1.3rem; line-height: 1.1; letter-spacing: -0.01em; font-weight: 800; }
.sub { color: var(--muted); font-size: .85rem; }
.top-actions { display: flex; gap: 4px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 10px;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-weight: 600;
  font-size: .9rem;
  justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }
.ico-line { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */

.layout {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  display: grid;
  gap: 18px;
}
.layout:focus { outline: none; }

.noscript { background: var(--err-soft); color: var(--err); padding: 12px; border-radius: 12px; }

@media (min-width: 900px) {
  .layout {
    max-width: 980px;
    grid-template-columns: minmax(0, 520px) minmax(0, 1fr);
    align-items: start;
    gap: 32px;
    padding-top: 16px;
  }
  .side { position: sticky; top: 16px; }
}

/* ---------- target ---------- */

.play { display: grid; gap: 14px; align-content: start; }
.side { display: grid; gap: 14px; align-content: start; }

.target-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 12px 16px;
  box-shadow: var(--shadow);
}
.eyebrow {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.target-wrap { display: grid; gap: 2px; }
.target {
  font-size: clamp(2.6rem, 14vw, 3.6rem);
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--badge-bg);
  color: var(--badge-text);
  border-radius: 14px;
  padding: 6px 18px;
  min-width: 3.4ch;
  text-align: center;
}
.target-wrap { grid-auto-flow: row; justify-items: start; }
.par {
  text-align: right;
  font-weight: 700;
  line-height: 1.25;
  display: grid;
  gap: 2px;
}
.par-label { font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
#par-value { font-size: 1.15rem; }

/* ---------- message ---------- */

.message {
  min-height: 2.5em;
  margin: -4px 0;
  padding: 6px 12px;
  border-radius: 12px;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  line-height: 1.3;
}
.message:empty { visibility: hidden; }
.message.ok { background: var(--ok-soft); color: var(--ok); }
.message.err { background: var(--err-soft); color: var(--err); }

/* ---------- tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.tile {
  position: relative;
  min-height: clamp(76px, 22vw, 104px);
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: clamp(1.9rem, 9vw, 2.7rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  padding: 0;
}
.tile[data-kind="big"] { background: var(--big); }
.tile[data-kind="result"] { background: var(--accent-soft); }
.tile .badge {
  position: absolute;
  top: 5px;
  left: 9px;
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .04em;
}
.tile .badge.hit { color: var(--ok); left: auto; right: 9px; font-size: .8rem; }
.tile.is-hit { border-color: var(--ok); box-shadow: inset 0 0 0 2px var(--ok), var(--shadow); }
.tile[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.tile[aria-pressed="true"] .badge { color: var(--on-accent); }
.tile:disabled { cursor: default; }

/* ---------- operators and actions ---------- */

.controls { display: grid; gap: 12px; }

.ops { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }

.op {
  min-height: 64px;
  background: var(--surface-2);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.op[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.actions { display: grid; grid-template-columns: 1fr 1fr 1.8fr; gap: 10px; }

.btn {
  min-height: 54px;
  padding: 0 14px;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-radius: 14px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary.is-hit { background: var(--ok); border-color: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) {
  .btn-primary.is-hit { color: #07281c; }
}
.btn.small { min-height: 44px; }

.hint { color: var(--muted); font-size: .92rem; text-align: center; }

/* ---------- panels ---------- */

.panel {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}
h2 { font-size: 1.2rem; line-height: 1.2; font-weight: 800; }
h3 { font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-top: 8px; }
h2:focus { outline: none; }
.empty, .note { color: var(--muted); font-size: .95rem; }

.steps { list-style: none; padding: 0; display: grid; gap: 6px; counter-reset: step; }
.steps li {
  counter-increment: step;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 10px;
}
.steps li::before {
  content: counter(step);
  flex: none;
  min-width: 1.5em;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 700;
}

.score-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px; }
.score-row div { background: var(--surface-2); border-radius: 12px; padding: 8px 6px; text-align: center; }
.score-row dt { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.score-row dd { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.results h2 { font-size: 1.5rem; }
.results.good h2 { color: var(--ok); }

.share {
  white-space: pre-wrap;
  background: var(--surface-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 1.05rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.share-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.share-actions .btn { flex: 1 1 140px; }
.copy-status { min-height: 1.4em; color: var(--ok); font-weight: 700; font-size: .95rem; }
.copy-status.err { color: var(--err); }

.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mini-stats div { text-align: center; background: var(--surface-2); border-radius: 12px; padding: 8px 4px; }
.mini-stats dt { font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); order: 2; }
.mini-stats dd { font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; order: 1; }
.mini-stats div { display: flex; flex-direction: column; }
.mini-stats.big dd { font-size: 1.8rem; }

.next { color: var(--muted); font-size: .95rem; text-align: center; font-variant-numeric: tabular-nums; }

.dist { list-style: none; padding: 0; display: grid; gap: 8px; margin-top: 4px; }
.dist li { display: grid; grid-template-columns: 5.4em 1fr 2.2em; align-items: center; gap: 10px; font-weight: 700; }
.dist .bar { background: var(--surface-2); border-radius: 8px; height: 26px; overflow: hidden; }
.dist .fill { display: block; height: 100%; min-width: 4px; background: var(--accent); border-radius: 8px; }
.dist li.today .fill { background: var(--ok); }
.dist .count { text-align: right; font-variant-numeric: tabular-nums; }


/* ---------- dialogs ---------- */

dialog {
  border: 2px solid var(--line);
  border-radius: 20px;
  padding: 0;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  overflow: hidden;
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(10, 8, 20, .6); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 12px 6px 18px; }
.dlg-body { padding: 4px 18px 12px; overflow-y: auto; display: grid; gap: 10px; }
.dlg-foot { padding: 10px 18px 16px; display: flex; gap: 10px; }
.dlg-foot .btn { flex: 1; }
.prose p, .prose li { font-size: .98rem; }
.howto { padding-left: 1.3em; display: grid; gap: 8px; }
kbd {
  font-family: inherit;
  font-size: .85em;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 1px 6px;
}

/* ---------- small screens: keep everything thumb-reachable ---------- */

@media (max-width: 420px) {
  .top { padding-top: 10px; }
  .icon-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .layout { gap: 14px; padding-bottom: 16px; }
  .tiles, .ops, .actions { gap: 9px; }
}
@media (max-height: 700px) and (max-width: 520px) {
  .tile { min-height: 68px; }
  .op { min-height: 56px; }
  .btn { min-height: 48px; }
}

/* ---------- motion: only for people who haven't asked for less ---------- */

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
  .tile, .op, .btn, .icon-btn { transition: background-color .15s ease, color .15s ease, transform .1s ease, border-color .15s ease; }
  .tile:active, .op:active, .btn:active { transform: scale(.97); }
  .tile.pop { animation: pop .28s ease-out; }
  .dist .fill { transition: width .5s ease-out; }
}
@keyframes pop {
  0% { transform: scale(.8); }
  70% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@media (hover: hover) {
  .tile:hover:not(:disabled):not([aria-pressed="true"]), .op:hover:not([aria-pressed="true"]), .btn:hover:not(:disabled) { border-color: var(--accent); }
}

@media (forced-colors: active) {
  .tile[aria-pressed="true"], .op[aria-pressed="true"] { outline: 4px solid Highlight; }
  .tile.is-hit { outline: 3px solid LinkText; }
}

.offscreen { position: fixed; left: -9999px; top: 0; }
.dist .fill.zero { min-width: 0; }

/* ---------- mode switch (Daily / Infinite) ---------- */

.modes-wrap { max-width: 980px; margin: 0 auto; padding: 4px 16px 0; }
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 2px solid var(--line-strong);
  border-radius: 16px;
  max-width: 560px;
  margin: 0 auto;
}
.mode {
  min-height: 46px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: transparent;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.mode[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.mode[aria-pressed="true"]::before { content: "✓ "; content: "✓ " / ""; }
@media (min-width: 900px) {
  .modes { max-width: 340px; margin: 0; }
}
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.btn.ghost { background: transparent; border-style: dashed; min-height: 48px; font-weight: 600; color: var(--muted); }
.next-row { display: grid; margin-top: 4px; }
.next-row .btn { min-height: 56px; font-size: 1.1rem; }
@media (hover: hover) {
  .mode:hover:not([aria-pressed="true"]) { border-color: var(--accent); }
}
@media (prefers-reduced-motion: no-preference) {
  .mode { transition: background-color .15s ease, color .15s ease, border-color .15s ease; }
}
