:root {
  --bg: #1b1240;
  --panel: rgba(24, 14, 60, 0.86);
  --ink: #f4f0ff;
  --muted: #b7acd9;
  --accent: #8f6cf0;
  --accent-ink: #ffffff;
  --good: #7ef0b5;
  --warn: #ffd27a;
  --bad: #ff9a9a;
  --hud-h: 64px;
  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: 16px/1.4 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 10px;
  gap: 8px;
}
#hud[hidden] { display: none; }
.hud-center { text-align: center; min-width: 0; }
#score { font-size: 30px; font-weight: 800; letter-spacing: 0.5px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.hud-sub { font-size: 13px; color: var(--muted); display: flex; gap: 10px; justify-content: center; }
#combo { color: var(--warn); font-weight: 700; }

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

.icon-btn {
  width: 52px;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  flex: none;
}
.icon-btn img { width: 100%; height: 100%; display: block; pointer-events: none; }
.icon-btn.muted { position: relative; }
.icon-btn.muted.no-off-icon::after {
  content: "";
  position: absolute;
  left: 8px; right: 8px; top: 50%;
  height: 5px;
  margin-top: -2px;
  background: #ff6b6b;
  border-radius: 3px;
  transform: rotate(-45deg);
}

.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)) 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--panel);
  text-align: center;
  overflow-y: auto;
}
.screen[hidden] { display: none; }
.screen h2 { margin: 0; font-size: 28px; }
.title { margin: 0; font-size: 52px; font-weight: 900; letter-spacing: 1px; color: #fff; text-shadow: 0 4px 0 #5b3cc4, 0 0 24px rgba(143, 108, 240, 0.6); }
.tagline { margin: 0; color: var(--muted); }
.row { display: flex; gap: 14px; justify-content: center; }

.big-btn {
  min-width: 220px;
  min-height: 64px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 22px 8px 8px;
  border: 0;
  border-radius: 40px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 0 #5b3cc4;
}
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #5b3cc4; }
.big-btn img { width: 48px; height: 48px; }
.big-btn span:only-child { padding-left: 14px; }
.small-btn { border: 0; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: #fff; font: inherit; }

.final-score { font-size: 54px; font-weight: 900; font-variant-numeric: tabular-nums; }
.best { margin: 0; color: var(--muted); }
.best.new { color: var(--good); font-weight: 700; }
.note { margin: 0; color: var(--warn); }
.status { margin: 0; max-width: 340px; color: var(--muted); }
.status.ok { color: var(--good); }
.status.warn { color: var(--warn); }
.status.bad { color: var(--bad); }
.fineprint { margin: 0; font-size: 13px; color: var(--muted); max-width: 340px; }
.fineprint a { color: var(--muted); }
.bonus { list-style: none; margin: 0; padding: 0; width: min(300px, 100%); display: grid; gap: 6px; font-size: 18px; }
.bonus li { display: flex; justify-content: space-between; gap: 12px; }
.bonus li span:last-child { color: var(--good); font-weight: 800; font-variant-numeric: tabular-nums; }
#rows.urgent { color: var(--warn); font-weight: 700; }
#rows.danger { color: var(--bad); font-weight: 800; }
.link-btn { border: 0; background: none; color: inherit; font: inherit; text-decoration: underline; padding: 4px; cursor: pointer; }
.board { width: min(320px, 100%); }
.board h3 { margin: 0 0 6px; font-size: 16px; color: var(--muted); font-weight: 700; }
.board-list { list-style: none; margin: 0; padding: 0; width: min(320px, 100%); display: grid; gap: 2px; }
.board-row { display: grid; grid-template-columns: 52px 1fr auto; gap: 8px; padding: 6px 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); font-variant-numeric: tabular-nums; }
.board-row.mine { background: rgba(126, 240, 181, 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); }
.initials-row { display: flex; gap: 14px; }
.initials-col { display: grid; justify-items: center; gap: 4px; }
.initials-arrow { width: 64px; height: 48px; border: 0; border-radius: 12px; background: rgba(143, 108, 240, 0.85); color: #fff; font-size: 22px; cursor: pointer; }
.initials-arrow:active { transform: translateY(1px); }
.initials-char { width: 64px; height: 72px; display: grid; place-items: center; border-radius: 12px; background: #120b2c; border: 2px solid #3c2d77; 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; }
#turnstile-box[hidden] { display: none; }
.help { text-align: left; max-width: 360px; margin: 0; padding-left: 20px; display: grid; gap: 8px; }

#toast {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.55);
  font-weight: 800;
  pointer-events: none;
  white-space: nowrap;
}
#toast[hidden] { display: none; }
#toast.big { top: 30%; padding: 12px 26px; font-size: 30px; background: rgba(91, 60, 196, 0.85); box-shadow: 0 0 30px rgba(143, 108, 240, 0.7); }
#toast.show { animation: toast-in 260ms ease-out; }
@keyframes toast-in { from { transform: translateX(-50%) scale(0.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
#level.flash { animation: level-flash 1.6s ease-out; }
@keyframes level-flash { 0%, 40% { color: #ffe27a; font-weight: 800; transform: scale(1.35); } 100% { color: inherit; transform: scale(1); } }
#level { display: inline-block; }

#debug-record { width: min(340px, 100%); text-align: left; color: var(--muted); }
#debug-record textarea { width: 100%; font: 11px/1.3 ui-monospace, monospace; background: #120b2c; color: var(--ink); border: 1px solid #3c2d77; }

#fps {
  position: absolute;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 10;
  font: 12px ui-monospace, monospace;
  background: rgba(0, 0, 0, 0.5);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}
#fps[hidden] { display: none; }
