:root {
  --bg: #f5f5f5;
  --fg: #2a2a2a;
  --accent: #ff5252;
  --overlay-bg: rgba(245, 245, 245, 0.92);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --stage-size: min(92vmin, 500px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: var(--stage-size);
  max-width: 100%;
  padding: 12px;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px;
  font-size: 14px;
  letter-spacing: 0.05em;
}

#hud-left, #hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-label {
  opacity: 0.6;
  font-size: 11px;
  text-transform: uppercase;
}

#score {
  font-weight: 700;
  font-size: 20px;
  min-width: 3ch;
  display: inline-block;
}

.badge {
  border: 1px solid var(--fg);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  text-transform: uppercase;
  opacity: 0.7;
}

#hud button {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--fg);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  line-height: 1;
}

#hud button:hover { background: var(--fg); color: var(--bg); }

#stage {
  position: relative;
  width: var(--stage-size);
  height: var(--stage-size);
  margin: 0 auto;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg);
  /* Phase 1 RT:F2 — prevents browser pan/zoom during swipes. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: var(--overlay-bg);
  text-align: center;
  /* Overlays accept taps; canvas does not when overlay is visible. */
  pointer-events: auto;
}

.overlay.visible { display: flex; }

.overlay h1 {
  margin: 0;
  font-size: clamp(36px, 10vmin, 72px);
  letter-spacing: 0.15em;
}

.overlay h2 {
  margin: 0;
  font-size: clamp(24px, 6vmin, 40px);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 180px;
}

.menu-buttons button {
  padding: 12px 18px;
  font: inherit;
  font-size: 16px;
  border-radius: 8px;
  border: 1px solid var(--fg);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
}

.menu-buttons button:hover { background: var(--fg); color: var(--bg); }

.menu-buttons button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.menu-buttons button.primary:hover { filter: brightness(0.92); }

.menu-buttons button.danger {
  border-color: #c0392b;
  color: #c0392b;
}

.menu-buttons button.danger:hover { background: #c0392b; color: #fff; }

.big-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.big-score span:last-child {
  font-size: clamp(36px, 10vmin, 56px);
  font-weight: 700;
}

#countdown-number {
  font-size: clamp(80px, 25vmin, 160px);
  font-weight: 700;
  line-height: 1;
}

.ready-text {
  font-size: clamp(40px, 12vmin, 80px);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.name-label { font-size: 14px; opacity: 0.8; }

#ne-input {
  font: inherit;
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  text-align: center;
  width: 6ch;
  padding: 6px 0 6px 0.4em;
  border: 2px solid var(--fg);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  outline: none;
}

#ne-input:focus { border-color: var(--accent); }

.scores-tabs {
  display: flex;
  gap: 8px;
}

.tab-btn {
  border: 1px solid var(--fg);
  background: transparent;
  color: var(--fg);
  padding: 4px 12px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.tab-btn.active { background: var(--fg); color: var(--bg); }

#scores-table {
  width: 100%;
  max-width: 320px;
  border-collapse: collapse;
  font-size: 14px;
}

#scores-table th, #scores-table td {
  padding: 4px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

#scores-table tr.new td {
  font-weight: 700;
  color: var(--accent);
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 280px;
}

.setting-row label { font-size: 14px; }

.setting-row select, .setting-row input[type="checkbox"] {
  font: inherit;
  padding: 4px 6px;
}

#debug-fps {
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.4);
  color: #0f0;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
  display: none;
}

#debug-fps.visible { display: block; }
