:root {
  --bg: #1c1233;
  --panel: rgba(24, 14, 42, 0.84);
  --ink: #fff6e8;
  --muted: #e4d3b4;
  --accent: #ffd56a;
  --accent-ink: #3a2410;
  --accent-shadow: #c4872a;
  --good: #b6f3c0;
  --warn: #ffd27a;
  --bad: #ffb4b4;
  --hud-h: 72px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Anything marked hidden stays hidden, whatever display rule its class sets. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#hud {
  height: var(--hud-h);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
}

.hud-center { text-align: center; min-width: 0; }
#score {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.hud-sub {
  font-size: 16px;
  color: var(--muted);
  display: flex;
  gap: 12px;
  justify-content: center;
}
#streak { color: var(--warn); font-weight: 800; }

#stage { position: relative; flex: 1; min-height: 0; }
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}

.text-btn {
  min-width: 76px;
  min-height: 48px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 246, 232, 0.14);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
.text-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: calc(24px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
  background: var(--panel);
  text-align: center;
  overflow-y: auto;
}
.screen h2 { margin: 0; font-size: 32px; }
.title {
  margin: 0;
  font-size: 56px;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: #fff8ea;
  text-shadow: 0 3px 0 #6a3a16, 0 0 24px rgba(255, 196, 90, 0.45);
}
.tagline { margin: 0; color: var(--muted); font-size: 20px; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.big-btn {
  min-width: 240px;
  min-height: 68px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 28px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 22px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-shadow);
}
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--accent-shadow); }
.big-btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.small-btn {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 8px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.final-score { font-size: 56px; font-weight: 900; font-variant-numeric: tabular-nums; }
.best { margin: 0; color: var(--muted); font-size: 18px; }
.best.new { color: var(--good); font-weight: 800; }
.note { margin: 0; color: var(--warn); max-width: 360px; }
.status { margin: 0; max-width: 360px; color: var(--muted); }
.status.ok { color: var(--good); }
.status.warn { color: var(--warn); }
.status.bad { color: var(--bad); }
.fineprint { margin: 0; font-size: 16px; color: var(--muted); max-width: 380px; }
.fineprint a { color: var(--muted); }
.link-btn {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  padding: 4px;
  cursor: pointer;
}

.board { width: min(340px, 100%); }
.board h3 { margin: 0 0 6px; font-size: 18px; color: var(--muted); font-weight: 800; }
.board-list { list-style: none; margin: 0; padding: 0; width: min(340px, 100%); display: grid; gap: 4px; }
.board-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
}
.board-row.mine { background: rgba(182, 243, 192, 0.18); outline: 2px solid var(--good); font-weight: 800; }
.board-rank { color: var(--muted); text-align: left; }
.board-name { text-align: left; letter-spacing: 3px; font-family: ui-monospace, monospace; font-weight: 800; }
.board-score { text-align: right; }
.board-gap, .board-empty { text-align: center; color: var(--muted); list-style: none; padding: 4px; }

.initials { display: grid; justify-items: center; gap: 10px; }
.initials-title { margin: 0; font-weight: 800; color: var(--warn); font-size: 18px; }
.initials-row { display: flex; gap: 14px; }
.initials-col { display: grid; justify-items: center; gap: 4px; }
.initials-arrow {
  width: 68px;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 213, 106, 0.9);
  color: var(--accent-ink);
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
}
.initials-arrow:active { transform: translateY(1px); }
.initials-char {
  width: 68px;
  height: 76px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #140c24;
  border: 2px solid #6a5430;
  font: 900 44px/1 ui-monospace, monospace;
}
.initials-char.focus { border-color: var(--warn); }
.initials-ok { min-width: 160px; }

#turnstile-box {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
}

.help {
  text-align: left;
  max-width: 420px;
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 10px;
  font-size: 18px;
}

#toast {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(28, 16, 40, 0.72);
  font-weight: 900;
  font-size: 22px;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { animation: toast-in 260ms ease-out; }
@keyframes toast-in {
  from { transform: translateX(-50%) scale(0.8); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

#clock {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  padding: 4px 8px;
  background: #000;
  color: #fff;
  font: 16px/1.2 ui-monospace, monospace;
}
#debug-record { width: min(340px, 100%); text-align: left; color: var(--muted); }
#debug-record textarea {
  width: 100%;
  font: 12px/1.3 ui-monospace, monospace;
  background: #140c24;
  color: var(--ink);
  border: 1px solid #6a5430;
}

@media (prefers-reduced-motion: reduce) {
  #toast.show { animation: none; }
}
