:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #1d1b19;
  --muted: #7a746c;
  --ground: #d9d2c7;
  --rope: #e4572e;
  --jumper: #1d1b19;
  --turner: #8a837a;
  --accent: #2f6fde;
  --fail: #d6336c;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141312;
    --surface: #1e1c1a;
    --ink: #f1ece4;
    --muted: #9b948a;
    --ground: #3a3633;
    --rope: #ff7a50;
    --jumper: #f1ece4;
    --turner: #8d867c;
    --accent: #6a9bff;
    --fail: #ff6b98;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.stat { display: flex; flex-direction: column; }
.stat.right { align-items: flex-end; }
.label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.value { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }

#stage {
  position: relative;
  height: min(62vh, 560px);
  min-height: 260px;
  border-radius: 20px;
  background: var(--surface);
  overflow: hidden;
  touch-action: manipulation;
  cursor: pointer;
}

canvas { display: block; width: 100%; height: 100%; }

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  text-align: center;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(2px);
}

#overlay[hidden] { display: none; }

#title { margin: 0; font-size: clamp(1.8rem, 6vw, 2.6rem); font-weight: 800; }
#title.fail { color: var(--fail); }
#message { margin: 0 0 8px; color: var(--muted); font-size: 1rem; }

#start {
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 12px 32px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
#start:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.hint { margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); }

.leaderboard { margin-top: 28px; }
.leaderboard h2 { font-size: 1rem; font-weight: 700; margin: 0 0 12px; }
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; white-space: nowrap; }
th {
  text-align: left; font-weight: 600; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--ground);
}
td { padding: 10px 14px; border-bottom: 1px solid var(--ground); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, td.rank { font-variant-numeric: tabular-nums; }
td.rank { color: var(--muted); }
td strong { color: var(--accent); }
td .sub, td.sub { color: var(--muted); font-size: 0.8rem; }
td.empty { text-align: center; color: var(--muted); padding: 24px; }
tr.mine td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.note { margin: 12px 0 0; font-size: 0.82rem; color: var(--muted); text-align: center; }
