:root {
  color-scheme: dark;
  --bg: #181a20;
  --text: #f1f2f5;
  --muted: #a6abb8;
  --accent: #ffb443;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

main {
  width: min(100%, 560px);
  padding: max(16px, env(safe-area-inset-top)) 16px calc(56px + env(safe-area-inset-bottom));
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

h1 { margin: 0; font-size: 1.5rem; letter-spacing: 0.01em; }

.header-side { display: flex; align-items: center; gap: 12px; }
#help { width: 36px; height: 36px; padding: 0; border-radius: 50%; }

#lives { font-size: 1.4rem; display: flex; gap: 6px; }
#lives .spent { filter: grayscale(1); opacity: 0.3; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0 0 12px;
}
.stats div:nth-child(2) { text-align: center; }
.stats div:nth-child(3) { text-align: right; }
.stats dt { color: var(--muted); font-size: 0.78rem; }
.stats dd { margin: 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }

#board {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  border: 3px solid #0b0c0f;
  border-radius: 8px;
  overflow: hidden;
  touch-action: manipulation;
}

.tile {
  appearance: none;
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0 solid #0b0c0f;
  border-radius: 0;
  font-size: var(--tile-font);
  line-height: 1;
  color: #1c1e26;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile:focus-visible { outline: 3px solid #fff; outline-offset: -3px; }
.tile.marked { color: rgb(20 22 28 / 0.65); font-weight: 700; }
.tile.running, .tile.mouse { background: #3b3f4a !important; }
.tile.missed { filter: saturate(0.5); }

.runner {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
}

.rules {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
  margin: 12px 0 0;
}
.rules strong { color: var(--text); }

.controls {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

button {
  font: inherit;
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
}

button { background: var(--accent); color: #231703; font-weight: 600; cursor: pointer; }
button.secondary { background: #2a2d36; color: var(--text); }
button:disabled { opacity: 0.5; cursor: default; }

dialog {
  border: 0;
  border-radius: 14px;
  background: #23262e;
  color: var(--text);
  padding: 24px;
  text-align: center;
  width: min(86vw, 320px);
}
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
dialog h2 { margin: 0 0 18px; font-size: 1.3rem; }
#privacy-policy { text-align: left; padding: 20px; width: min(92vw, 460px); max-height: 86dvh; user-select: text; -webkit-user-select: text; }
#privacy-policy h2 { margin-bottom: 10px; }
#privacy-policy h3 { margin: 16px 0 4px; font-size: 1rem; }
#privacy-policy p { margin: 0 0 8px; color: var(--muted); font-size: 0.92rem; line-height: 1.45; }
#privacy-policy p strong, #privacy-policy .lead { color: var(--text); }
#privacy-policy ul { margin: 0 0 8px; padding-left: 18px; color: var(--muted); font-size: 0.92rem; line-height: 1.45; }
#privacy-policy li { margin-bottom: 6px; }
#privacy-policy li strong { color: var(--text); }
#privacy-policy .lead { font-weight: 700; }
#visitor-line { margin-top: 10px; }
#visitor-line[hidden] { display: none; }
#delete-status { min-height: 1.2em; color: var(--accent) !important; }
#privacy-policy a { color: var(--accent); overflow-wrap: anywhere; }
#how-to-play { text-align: left; padding: 20px; }
#how-to-play h2 { text-align: center; margin-bottom: 12px; }
#how-to-play p { margin: 0 0 12px; color: var(--muted); font-size: 0.92rem; line-height: 1.4; }
#how-to-play ul { list-style: none; margin: 0 0 12px; padding: 0; }
#how-to-play li { display: flex; gap: 10px; margin-bottom: 9px; font-size: 0.95rem; line-height: 1.35; }
#how-to-play li span { flex: 0 0 1.5em; text-align: center; }
#result-score { margin-bottom: 14px; }
#result-score p {
  display: flex;
  justify-content: space-between;
  margin: 4px 0;
  color: var(--muted);
}
#result-score p:last-child {
  margin-top: 10px;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 700;
}
#result-score p.total {
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 700;
}
#result-score p.heading { margin-top: 14px; font-size: 0.85rem; }
#result-score p.you, #result-score p.you:last-child {
  margin-top: 4px;
  color: var(--accent);
  font-size: inherit;
  font-weight: 700;
}
dialog button { display: block; width: 100%; margin-top: 8px; }
#auth-dialog { user-select: text; -webkit-user-select: text; }
dialog button[hidden] { display: none; }
#challenge-status { margin: 0 0 12px; color: var(--muted); font-size: 0.92rem; line-height: 1.4; }
#challenge-text {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: #2a2d36;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
  resize: none;
  user-select: text;
  -webkit-user-select: text;
}
dialog h2:focus { outline: none; }
#auth-help { margin: 0 0 10px; color: var(--muted); font-size: 0.92rem; }
#auth-error { margin: 8px 0 0; color: #ff9c8f; font-size: 0.88rem; min-height: 1.2em; }
dialog input {
  width: 100%;
  font: inherit;
  padding: 11px 12px;
  border: 0;
  border-radius: 8px;
  background: #2a2d36;
  color: var(--text);
}

#privacy {
  position: fixed;
  right: 8px;
  bottom: max(8px, env(safe-area-inset-bottom));
  padding: 8px;
  background: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}

@media (max-width: 380px) {
  h1 { font-size: 1.25rem; }
  #lives { font-size: 1.15rem; gap: 4px; }
  .header-side { gap: 8px; }
}

.odometer { display: inline-flex; gap: 3px; padding: 5px; border-radius: 6px; background: #000; }
.odometer span {
  width: 1.5em;
  padding: 4px 0;
  border-radius: 3px;
  background: linear-gradient(#25262b, #0a0a0c 50%, #1d1e23 50%, #0a0a0c);
  color: #7dff7a;
  font-family: "Courier New", monospace;
  font-size: clamp(1.05rem, 5vw, 1.5rem);
  font-weight: 700;
  text-align: center;
}
