:root {
  color-scheme: dark;
  --bg: #02040a;
  --cyan: #19e6ff;
  --orange: #ff7a1a;
  --pink: #ff2bd6;
  --lime: #b6ff3b;
  --text: #eaf6ff;
  --muted: rgba(234, 246, 255, 0.55);
  --faint: rgba(234, 246, 255, 0.08);
  --panel: rgba(4, 14, 26, 0.62);
  --line: rgba(25, 230, 255, 0.2);
  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 10px;
  --display: "Michroma", "Oxanium", sans-serif;
  --ui: "Oxanium", "Segoe UI", sans-serif;
  --mono: "Share Tech Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 500 15px/1.4 var(--ui);
  letter-spacing: 0.06em;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
button, input { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 4px; border-radius: var(--r-sm); }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

#backdrop, #arena { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#arena { outline: none; touch-action: none; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; }

/* ---- Title ---------------------------------------------------------------- */
.title-screen { justify-content: center; gap: 7vh; padding: 24px; animation: fade-in 1.2s ease both; }
.logo { text-align: center; position: relative; }
.logo h1 { margin: 0; display: flex; flex-direction: column; align-items: center; font-family: var(--display); font-weight: 400; line-height: 0.95; }
.logo-bits { display: block; font-family: var(--mono); color: rgba(25, 230, 255, 0.55); letter-spacing: 0.6em; font-size: clamp(10px, 1.4vw, 14px); margin-bottom: 2.4vh; animation: flicker 4s steps(1) infinite; }
.logo-neon, .logo-rally { position: relative; display: block; padding-left: 0.32em; letter-spacing: 0.32em; }
.logo-neon {
  font-size: clamp(42px, 10vw, 140px);
  color: transparent;
  -webkit-text-stroke: 1.5px var(--cyan);
  text-shadow: 0 0 18px rgba(25, 230, 255, 0.55), 0 0 60px rgba(25, 230, 255, 0.3);
}
.logo-rally {
  font-size: clamp(42px, 10vw, 140px);
  background: linear-gradient(180deg, #ffffff 10%, #bff8ff 45%, var(--cyan) 52%, #0a6d8a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 16px rgba(25, 230, 255, 0.6)) drop-shadow(0 0 40px rgba(255, 122, 26, 0.25));
}
.logo-neon::after, .logo-rally::after {
  content: attr(data-text); position: absolute; inset: 0; padding-left: 0.32em;
  color: var(--pink); -webkit-text-stroke: 0; background: none; opacity: 0;
  clip-path: inset(40% 0 45% 0); animation: glitch 5s infinite;
}
.logo-rally::after { animation-delay: 2.3s; color: var(--orange); }
.press { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 34px; border-radius: 999px; font-family: var(--ui); font-weight: 600; font-size: 14px; letter-spacing: 0.5em; padding-left: calc(34px + 0.5em); color: var(--text); border: 1px solid var(--line); background: rgba(2, 8, 16, 0.4); backdrop-filter: blur(6px); animation: pulse 1.8s ease-in-out infinite; }
.press-tap { display: none; }
@media (hover: none) and (pointer: coarse) { .press-key { display: none; } .press-tap { display: block; } }

/* ---- Menu ----------------------------------------------------------------- */
.menu-screen { justify-content: flex-start; gap: clamp(14px, 2.6vh, 28px); padding: clamp(14px, 3vh, 34px) clamp(14px, 4vw, 56px) clamp(14px, 3vh, 28px); overflow-y: auto; animation: rise 0.5s cubic-bezier(.2, .9, .3, 1) both; }
.menu-top { width: 100%; max-width: 1180px; display: flex; align-items: center; justify-content: space-between; }
.mini-logo { font-family: var(--display); font-size: 15px; letter-spacing: 0.42em; color: var(--cyan); text-shadow: 0 0 14px rgba(25, 230, 255, 0.6); }
.mini-logo b { font-weight: 400; color: var(--text); }
.toggles { display: flex; gap: 10px; }
.round-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(10px); color: var(--text); transition: border-color .2s, color .2s, box-shadow .2s; }
.round-btn svg { width: 19px; height: 19px; }
.round-btn:hover { border-color: var(--cyan); box-shadow: 0 0 18px rgba(25, 230, 255, 0.3); }
.round-btn[aria-pressed="false"] { color: rgba(234, 246, 255, 0.3); }
.round-btn[aria-pressed="false"] svg { stroke-dasharray: 3 3; }

.modes { width: 100%; max-width: 1180px; display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(10px, 1.6vw, 20px); }
.mode {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: clamp(14px, 2vw, 22px); border-radius: var(--r-lg);
  border: 1px solid var(--faint); background: var(--panel); backdrop-filter: blur(12px);
  text-align: left; overflow: hidden;
  transition: transform .25s cubic-bezier(.2, .9, .3, 1), border-color .25s, box-shadow .25s, background .25s;
}
.mode::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(120% 80% at 50% 0%, rgba(25, 230, 255, 0.16), transparent 60%); opacity: 0; transition: opacity .25s; }
.mode svg { width: 100%; height: auto; max-height: 92px; margin-bottom: 8px; stroke-width: 1.5; }
.mode svg .p1 { fill: var(--cyan); stroke: none; filter: drop-shadow(0 0 4px var(--cyan)); }
.mode svg .p2 { fill: var(--orange); stroke: none; filter: drop-shadow(0 0 4px var(--orange)); }
.mode svg .p3 { fill: var(--pink); stroke: none; }
.mode svg .p4 { fill: var(--lime); stroke: none; }
.mode svg .cpu { fill: var(--orange); stroke: none; }
.mode svg .chip { stroke: var(--orange); stroke-width: 1.2; }
.mode svg .ball { fill: #fff; stroke: none; filter: drop-shadow(0 0 5px #fff); }
.mode svg .mid { stroke: rgba(25, 230, 255, 0.25); stroke-dasharray: 2 5; }
.mode svg .wall { stroke: var(--cyan); stroke-width: 3; }
.mode svg .path { stroke: rgba(255, 255, 255, 0.35); stroke-dasharray: 3 4; }
.mode svg .frame { stroke: rgba(255, 43, 74, 0.6); }
.mode b { font-family: var(--display); font-weight: 400; font-size: clamp(14px, 1.6vw, 20px); letter-spacing: 0.24em; text-transform: uppercase; }
.mode small { color: var(--muted); font-size: 12px; letter-spacing: 0.28em; text-transform: uppercase; }
.mode:hover { transform: translateY(-3px); border-color: var(--line); }
.mode[aria-checked="true"] { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan), 0 0 36px rgba(25, 230, 255, 0.25), inset 0 0 30px rgba(25, 230, 255, 0.08); }
.mode[aria-checked="true"]::before { opacity: 1; }
.mode-arena[aria-checked="true"] { border-color: #ff2b4a; box-shadow: 0 0 0 1px #ff2b4a, 0 0 36px rgba(255, 43, 74, 0.3), inset 0 0 30px rgba(255, 43, 74, 0.08); }
.mode-arena::before { background: radial-gradient(120% 80% at 50% 0%, rgba(255, 43, 74, 0.2), transparent 60%); }

.options { width: 100%; max-width: 1180px; display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.opt { display: flex; align-items: center; gap: 14px; padding: 8px 8px 8px 20px; border-radius: 999px; border: 1px solid var(--faint); background: var(--panel); backdrop-filter: blur(12px); }
.opt-row { padding-left: 8px; gap: 8px; }
.opt-label { font-size: 12px; font-weight: 600; letter-spacing: 0.32em; text-transform: uppercase; color: var(--muted); }
.seg { display: flex; gap: 4px; }
.seg button, .slot { padding: 9px 16px; border-radius: 999px; font-size: 13px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); transition: background .2s, color .2s, box-shadow .2s; }
.seg button:hover, .slot:hover { color: var(--text); background: var(--faint); }
.seg button[aria-checked="true"] { color: #02131a; background: var(--cyan); box-shadow: 0 0 18px rgba(25, 230, 255, 0.5); }
.slots { display: flex; gap: 6px; }
.slot { display: flex; align-items: center; gap: 8px; border: 1px solid currentColor; color: var(--c); padding: 7px 14px; }
.slot i { font-style: normal; font-size: 11px; opacity: .7; letter-spacing: .12em; }
.slot[data-bot="true"] { border-style: dashed; opacity: .75; }
.switch { display: flex; align-items: center; gap: 12px; padding: 4px 8px 4px 12px; border-radius: 999px; }
.track { position: relative; width: 46px; height: 26px; border-radius: 999px; background: var(--faint); border: 1px solid var(--line); transition: background .2s; }
.track i { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform .25s cubic-bezier(.2, .9, .3, 1), background .2s; }
.switch[aria-checked="true"] .track { background: rgba(25, 230, 255, 0.25); }
.switch[aria-checked="true"] .track i { transform: translateX(20px); background: var(--cyan); box-shadow: 0 0 12px var(--cyan); }
.pill-btn { padding: 10px 20px; border-radius: 999px; border: 1px solid var(--line); background: rgba(2, 8, 16, 0.5); font-size: 13px; font-weight: 600; letter-spacing: 0.26em; text-transform: uppercase; transition: border-color .2s, box-shadow .2s; }
.pill-btn:hover { border-color: var(--cyan); box-shadow: 0 0 16px rgba(25, 230, 255, 0.25); }

.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; max-width: 900px; transition: opacity .3s; }
.legend.off { opacity: .25; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--muted); }
.legend-item canvas { width: 28px; height: 28px; border-radius: 9px; border: 1px solid var(--c); background: rgba(2, 6, 12, 0.8); box-shadow: 0 0 10px color-mix(in srgb, var(--c) 40%, transparent); }
.legend-item b { color: var(--c); font-weight: 600; }
.legend.compact .legend-item { flex: 1 1 40%; justify-content: flex-start; }
.legend.compact .legend-item span { color: var(--muted); letter-spacing: 0.08em; text-transform: none; font-size: 13px; }

.launch { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: auto; padding-bottom: 6px; }
.start-btn {
  position: relative; display: inline-flex; align-items: center; gap: 14px;
  padding: 18px 46px 18px calc(46px + 0.5em); border-radius: 999px;
  font-family: var(--display); font-size: 18px; letter-spacing: 0.5em; text-transform: uppercase;
  color: #02131a; background: linear-gradient(90deg, #8ff6ff, var(--cyan) 60%, #0fb8e0);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4) inset, 0 0 30px rgba(25, 230, 255, 0.55), 0 0 80px rgba(25, 230, 255, 0.25);
  transition: transform .2s, box-shadow .2s;
}
.start-btn svg { width: 18px; height: 18px; fill: currentColor; stroke: none; }
.start-btn:hover { transform: scale(1.04); box-shadow: 0 0 0 1px #fff inset, 0 0 44px rgba(25, 230, 255, 0.8), 0 0 120px rgba(25, 230, 255, 0.35); }
.start-btn.small { padding: 13px 30px 13px calc(30px + 0.4em); font-size: 14px; letter-spacing: 0.4em; }
.start-btn.danger { background: linear-gradient(90deg, #ff9db0, #ff2b4a 60%, #c4122f); color: #1a0206; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4) inset, 0 0 30px rgba(255, 43, 74, 0.55), 0 0 80px rgba(255, 43, 74, 0.25); }
.keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 22px; color: var(--muted); font-size: 12px; letter-spacing: 0.24em; text-transform: uppercase; }
.keys span { display: inline-flex; align-items: center; gap: 6px; }
kbd { display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 8px; border: 1px solid var(--c, var(--line)); color: var(--c, var(--text)); background: rgba(2, 6, 12, 0.7); font: 600 12px var(--ui); letter-spacing: 0; }

/* ---- Overlay -------------------------------------------------------------- */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 50% 50%, rgba(2, 6, 14, 0.55), rgba(2, 4, 10, 0.85)); backdrop-filter: blur(3px); animation: fade-in .25s ease both; }
.overlay-card { width: min(560px, 100%); padding: clamp(24px, 4vw, 40px); border-radius: 28px; border: 1px solid var(--line); background: rgba(4, 14, 26, 0.78); backdrop-filter: blur(18px); text-align: center; box-shadow: 0 0 60px rgba(25, 230, 255, 0.12); animation: rise .35s cubic-bezier(.2, .9, .3, 1) both; }
.kicker { margin: 0 0 10px; font-size: 12px; font-weight: 600; letter-spacing: 0.6em; text-transform: uppercase; color: var(--muted); padding-left: 0.6em; }
.overlay-card h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(28px, 6vw, 52px); letter-spacing: 0.22em; padding-left: 0.22em; text-transform: uppercase; color: var(--c, var(--text)); text-shadow: 0 0 24px var(--c, rgba(25, 230, 255, 0.6)); overflow-wrap: anywhere; }
.ov-sub { margin: 12px 0 0; color: var(--muted); letter-spacing: 0.3em; text-transform: uppercase; font-size: 13px; min-height: 1em; }
.ov-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin-top: 26px; }
#ov-legend { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--faint); text-align: left; gap: 10px 16px; }
.pause-btn { position: fixed; top: 12px; right: 12px; z-index: 5; width: 40px; height: 40px; opacity: .7; }
.pause-btn:hover { opacity: 1; }

/* ---- Dialog --------------------------------------------------------------- */
dialog { width: min(640px, calc(100% - 24px)); max-height: calc(100% - 24px); padding: clamp(20px, 3vw, 32px); border-radius: 28px; border: 1px solid var(--line); background: rgba(4, 14, 26, 0.94); color: var(--text); box-shadow: 0 0 80px rgba(25, 230, 255, 0.18); user-select: text; }
dialog::backdrop { background: rgba(1, 3, 8, 0.7); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 20px; font-family: var(--display); font-weight: 400; font-size: 20px; letter-spacing: 0.4em; text-transform: uppercase; }
.player-row { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; align-items: center; padding: 14px 0; border-top: 1px solid var(--faint); }
.player-row .seat { font-size: 11px; letter-spacing: 0.3em; color: var(--c); text-transform: uppercase; }
.player-row input[type="text"] { width: 100%; padding: 10px 16px; border-radius: 999px; border: 1px solid var(--faint); background: rgba(2, 6, 12, 0.7); color: var(--c); font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; outline: none; }
.player-row input[type="text"]:focus { border-color: var(--c); box-shadow: 0 0 12px color-mix(in srgb, var(--c) 40%, transparent); }
.swatches { grid-column: 2; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch { width: 26px; height: 26px; border-radius: 50%; background: var(--s); border: 2px solid transparent; box-shadow: 0 0 8px var(--s); transition: transform .15s; }
.swatch:hover { transform: scale(1.15); }
.swatch[aria-checked="true"] { border-color: #fff; transform: scale(1.15); }
.size { grid-column: 2; display: flex; align-items: center; gap: 12px; font-size: 11px; letter-spacing: 0.24em; color: var(--muted); text-transform: uppercase; }
.size input { flex: 1; accent-color: var(--c); }
.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding-top: 16px; border-top: 1px solid var(--faint); font-size: 13px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted); }
.check input { width: 18px; height: 18px; accent-color: var(--cyan); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---- Motion --------------------------------------------------------------- */
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } }
@keyframes pulse { 50% { opacity: .45; box-shadow: 0 0 30px rgba(25, 230, 255, 0.25); } }
@keyframes flicker { 0%, 100% { opacity: 1; } 42% { opacity: .3; } 44% { opacity: 1; } 71% { opacity: .5; } 72% { opacity: 1; } }
@keyframes glitch {
  0%, 88%, 100% { opacity: 0; transform: none; }
  89% { opacity: .9; transform: translate(-6px, 0); clip-path: inset(20% 0 60% 0); }
  91% { opacity: .9; transform: translate(5px, 0); clip-path: inset(62% 0 12% 0); }
  93% { opacity: .9; transform: translate(-3px, 0); clip-path: inset(40% 0 40% 0); }
  94% { opacity: 0; }
}
.calm *, .calm *::before, .calm *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; } }

/* ---- Small screens -------------------------------------------------------- */
@media (max-width: 860px) {
  .modes { grid-template-columns: repeat(2, 1fr); }
  .mode svg { max-height: 60px; }
}
@media (max-width: 520px) {
  .mode { padding: 12px; border-radius: var(--r-md); }
  .mode small { font-size: 10px; letter-spacing: 0.16em; }
  .opt { padding-left: 14px; gap: 8px; }
  .seg button { padding: 8px 10px; font-size: 11px; letter-spacing: 0.1em; }
  .slots { flex-wrap: wrap; }
  .legend-item { font-size: 10px; }
  .start-btn { padding: 15px 34px 15px calc(34px + 0.5em); font-size: 15px; }
  .keys { display: none; }
}
@media (max-height: 640px) and (min-width: 861px) {
  .mode svg { max-height: 54px; }
  .legend { display: none; }
}
