*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #05060a;
  --surface: #0d1018;
  --surface-2: #131724;
  --border: #232a3d;
  --accent: #ff3b5c;
  --accent-2: #3be8ff;
  --gold: #ffd447;
  --text: #eef2ff;
  --muted: #8b95b3;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* ==================== MAIN MENU (2-IN-1) ==================== */
.menu-screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  touch-action: pan-y;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 3vh, 28px) clamp(14px, 3vw, 32px);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 59, 92, 0.14), transparent 55%),
    radial-gradient(ellipse at 80% 100%, rgba(59, 232, 255, 0.08), transparent 50%),
    var(--bg);
}

.menu-shell {
  width: 100%;
  max-width: 880px;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.2vh, 22px);
}

.menu-header {
  text-align: center;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--accent-2);
  padding: 4px 12px;
  border: 1px solid rgba(59, 232, 255, 0.28);
  border-radius: 999px;
  background: rgba(59, 232, 255, 0.06);
  margin-bottom: 8px;
}

.title {
  font-size: clamp(1.7rem, 4.5vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  background: linear-gradient(180deg, #ffffff 0%, #ffd447 55%, #ff3b5c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 32px rgba(255, 59, 92, 0.25);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 2vw, 18px);
}

.mode-card {
  position: relative;
  text-align: left;
  background: linear-gradient(160deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: clamp(14px, 2.4vw, 24px);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.mode-card--active {
  cursor: pointer;
  border-color: rgba(255, 59, 92, 0.55);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 0 24px rgba(255, 59, 92, 0.14);
}

.mode-card--active:hover,
.mode-card--active:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55), 0 0 32px rgba(255, 59, 92, 0.28);
  outline: none;
}

.mode-card--active:active {
  transform: translateY(0);
}

.mode-card--soon {
  opacity: 0.55;
  border-style: dashed;
}

.mode-tag {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--accent-2);
}

.mode-card--soon .mode-tag {
  color: var(--muted);
}

.mode-name {
  font-size: clamp(1.2rem, 2.6vw, 1.7rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.mode-desc {
  font-size: clamp(0.78rem, 1.4vw, 0.9rem);
  line-height: 1.45;
  color: var(--muted);
  flex: 1;
}

.mode-cta {
  margin-top: 6px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--gold);
}

.mode-cta--muted {
  color: var(--muted);
}

.menu-lower {
  display: grid;
  grid-template-columns: 1.35fr 0.95fr;
  gap: clamp(10px, 2vw, 18px);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: clamp(12px, 2vw, 20px);
}

.panel-title {
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--accent-2);
  margin-bottom: 12px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  font-size: 0.88rem;
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.setting-control input[type="range"] {
  width: clamp(95px, 16vw, 155px);
  accent-color: var(--accent);
  cursor: pointer;
}

.setting-value {
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: var(--muted);
  min-width: 36px;
  text-align: right;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: #232a3d;
  border-radius: 999px;
  transition: background 0.16s ease;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.16s ease;
}

.toggle input:checked + .toggle-track {
  background: var(--accent);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(20px);
}

.controls-legend {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 0.76rem;
  line-height: 1.55;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.controls-legend strong {
  color: var(--text);
}

.controls-legend code {
  background: rgba(255, 255, 255, 0.08);
  color: var(--gold);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.74rem;
}

.score-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: ui-monospace, 'Cascadia Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 0.86rem;
}

.score-item {
  display: grid;
  grid-template-columns: 28px 56px 1fr;
  align-items: center;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
}

.score-item:first-child {
  color: var(--gold);
  background: rgba(255, 212, 71, 0.08);
}

.score-rank {
  color: var(--muted);
  font-size: 0.76rem;
}

.score-ini {
  font-weight: 800;
  letter-spacing: 0.14em;
}

.score-pts {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.score-loading {
  color: var(--muted);
  font-size: 0.82rem;
}

/* ==================== GAME SCREEN (ZERO HUD + FRAMED CRT BEZEL) ==================== */
.game-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, #0b0d14 0%, #030407 75%, #000000 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.crt-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Subtle physical CRT monitor bezel framing the curved glass without crowding screen edges */
.crt-bezel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 1.5vh, 16px);
  border-radius: clamp(14px, 2.2vh, 24px);
  background: linear-gradient(145deg, #171a24 0%, #0c0e14 55%, #07080c 100%);
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.85),
    inset 0 2px 6px rgba(255, 255, 255, 0.06),
    inset 0 -3px 10px rgba(0, 0, 0, 0.85);
}

#crt-canvas {
  display: block;
  border-radius: clamp(10px, 1.6vh, 18px);
  background: #040406;
  cursor: none;
  touch-action: none;
}

/* ==================== MOBILE PORTRAIT ROTATE OVERLAY ==================== */
.rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(5, 6, 10, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.rotate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 320px;
}

.phone-icon {
  width: 54px;
  height: 92px;
  border: 3px solid var(--accent-2);
  border-radius: 12px;
  position: relative;
  animation: rotatePhone 2.2s ease-in-out infinite;
  box-shadow: 0 0 24px rgba(59, 232, 255, 0.25);
}

.phone-icon::after {
  content: '';
  position: absolute;
  bottom: 7px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent-2);
}

@keyframes rotatePhone {
  0%, 15% { transform: rotate(0deg); }
  45%, 75% { transform: rotate(-90deg); }
  90%, 100% { transform: rotate(0deg); }
}

.rotate-title {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--text);
}

.rotate-sub {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

/* Compact landscape mobile menu fit */
@media (max-height: 520px) {
  .menu-screen {
    align-items: flex-start;
  }
  .menu-shell {
    gap: 10px;
  }
  .badge {
    margin-bottom: 4px;
  }
  .title {
    font-size: 1.5rem;
  }
  .mode-card {
    padding: 12px 14px;
    gap: 4px;
  }
  .mode-desc {
    display: none;
  }
  .panel {
    padding: 10px 14px;
  }
  .panel-title {
    margin-bottom: 6px;
  }
  .setting-row {
    padding: 4px 0;
    font-size: 0.82rem;
  }
  .score-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px 8px;
    font-size: 0.78rem;
  }
}

@media (max-width: 640px) {
  .mode-grid,
  .menu-lower {
    grid-template-columns: 1fr;
  }
}
