@font-face { font-family: 'Orbitron'; font-weight: 700; font-display: swap; src: url('fonts/orbitron-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Orbitron'; font-weight: 900; font-display: swap; src: url('fonts/orbitron-latin-900-normal.woff2') format('woff2'); }

:root {
  --bg: #06081a; --panel: #10142e; --panel2: #171d40; --line: #2c3570; --text: #eef1ff; --muted: #a6aed6;
  --pink: #ff4fd8; --cyan: #55e6ff; --yellow: #ffd43b; --accent: var(--pink);
  --display: 'Orbitron', system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; color: var(--text); font: 16px/1.35 system-ui, -apple-system, 'Segoe UI', sans-serif;
  background:
    radial-gradient(1200px 600px at 50% -10%, #2a1150 0%, transparent 60%),
    radial-gradient(900px 500px at 50% 120%, #0d2d55 0%, transparent 60%), var(--bg);
  display: grid; place-items: center;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
main { width: min(1080px, 100%); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
h2, h3 { font-family: var(--display); letter-spacing: .04em; }
h2 { margin: 0; font-size: clamp(18px, 4vw, 26px); }
h3 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; }

/* Buttons & inputs */
button, input, summary, .ghost-btn {
  min-height: 46px; padding: 10px 16px; border: 1px solid var(--line); border-radius: 14px; font: inherit; font-weight: 700; color: var(--text);
  background: linear-gradient(180deg, #1d2452, #141a3c); cursor: pointer; touch-action: manipulation;
  transition: transform .08s ease, border-color .15s ease, box-shadow .15s ease, opacity .15s;
}
button:hover { border-color: #5b67b8; }
button:active { transform: scale(.97); }
button:disabled { opacity: .45; cursor: default; transform: none; }
button.primary { background: linear-gradient(180deg, #ff5fdc, #c22fa8); border-color: #ff9ef0; box-shadow: 0 0 24px #ff4fd855; }
button.ghost, .ghost-btn { background: transparent; }
button.active, button[aria-pressed=true] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent), 0 0 14px color-mix(in srgb, var(--accent) 35%, transparent); }
input[type=text] { cursor: text; background: #0b0f26; font-size: 16px; -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
input[type=text]::placeholder { color: #6c74a3; }
.row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; min-height: 1em; }
.status { min-height: 22px; text-align: center; color: var(--yellow); margin: 10px 0 0; }

/* Screens */
.screen { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } }
.logo { text-align: center; margin: 4px 0 14px; }
.logo h1 {
  font-family: var(--display); font-weight: 900; margin: 0; font-size: clamp(54px, 13vw, 104px); letter-spacing: .06em; line-height: 1.2; padding-top: .06em;
  background: linear-gradient(90deg, var(--cyan), #a879ff 45%, var(--pink)); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px #ff4fd866);
}
.logo p { margin: 6px 0 0; color: var(--muted); letter-spacing: .25em; text-transform: uppercase; font-size: 12px; }
.profile { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.profile input { width: 180px; text-align: center; }
.swatches { display: flex; gap: 6px; }
.swatch { width: 34px; height: 34px; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid #0008; }
.swatch.active { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px #fff; }
.menu-grid { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.big { display: grid; justify-items: center; gap: 4px; padding: 18px 12px; border-radius: 18px; text-align: center; }
.big b { font-family: var(--display); font-size: clamp(14px, 2.4vw, 18px); letter-spacing: .05em; }
.big small { color: #d7dcff; font-weight: 500; font-size: 12px; opacity: .85; }
.big .ico { font-size: 28px; line-height: 1; }
.small-row { margin-top: 10px; }
.small-row button { flex: 1 1 140px; }
.foot { margin-top: 14px; }
.bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-bottom: 12px; }
.bar .back { justify-self: start; }
.card { background: linear-gradient(180deg, #121738ee, #0d112bee); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 12px; text-align: center; }
.join-row { margin-top: 14px; }
.join-row input { width: 160px; text-transform: uppercase; text-align: center; letter-spacing: .2em; font-family: var(--display); }
.seg button { flex: 1 1 0; }
.diff { flex: 1 1 0; }
.chaos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; text-align: left; }
.chaos-grid label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 10px; background: #0b0f26; font-size: 13px; cursor: pointer; }
.chaos-grid input { width: 18px; height: 18px; min-height: 0; accent-color: var(--pink); }
.server { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: #0b0f26; padding: 8px 10px; margin: 6px 0; border-radius: 12px; overflow-wrap: anywhere; text-align: left; }

/* Campaign */
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.level { display: grid; gap: 4px; padding: 14px 10px; border-radius: 16px; text-align: center; position: relative; }
.level .lv { font-size: 11px; color: var(--muted); font-family: var(--display); }
.level .lname { font-family: var(--display); font-size: 15px; }
.level .lico { font-size: 34px; }
.level .ldesc { font-size: 12px; color: var(--muted); font-weight: 500; }
.level.done::after { content: '✓'; position: absolute; top: 8px; right: 12px; color: #7dff72; }
.level.boss { border-color: #ffb13b; box-shadow: 0 0 20px #ff7b3244; }

/* Leaderboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat { background: #0b0f26; border-radius: 12px; padding: 10px; }
.stat b { display: block; font-family: var(--display); font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }
table { width: 100%; border-collapse: collapse; }
td, th { padding: 7px 8px; text-align: left; border-bottom: 1px solid #ffffff10; }
th { color: var(--muted); font-size: 12px; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { color: var(--yellow); }

/* Waiting */
.waiting-card { display: grid; gap: 14px; justify-items: center; padding: 30px 16px; }
.wait-text { margin: 0; font-size: 18px; }
.code-box { font-family: var(--display); font-weight: 900; font-size: clamp(34px, 9vw, 54px); letter-spacing: .25em; color: var(--yellow); text-shadow: 0 0 18px #ffd43b66; -webkit-user-select: text; user-select: text; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #ffffff22; border-top-color: var(--pink); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Game */
.scorebar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 6px; }
.side { display: flex; align-items: center; gap: 6px; min-width: 0; }
.side.right { justify-content: flex-end; }
.pname { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 10px; font-family: var(--display); padding: 2px 6px; border-radius: 6px; background: #ffffff1a; }
.tag:empty { display: none; }
.score { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; font-variant-numeric: tabular-nums; font-weight: 900; font-size: clamp(28px, 7vw, 46px); color: var(--accent); text-shadow: 0 0 16px color-mix(in srgb, var(--accent) 60%, transparent); display: flex; gap: 10px; }
.score i { font-style: normal; opacity: .5; }
.score span { display: inline-block; min-width: 1.1em; text-align: center; }
.score span.pulse { animation: pulse .6s ease; }
@keyframes pulse { 0% { transform: scale(1); } 30% { transform: scale(1.6); color: #fff; } 100% { transform: scale(1); } }
.arena { position: relative; touch-action: none; }
canvas { display: block; width: 100%; aspect-ratio: 12 / 7; border-radius: 16px; border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: 0 0 30px color-mix(in srgb, var(--accent) 22%, transparent); background: #050713; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; background: #050713d9; border-radius: 16px; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.overlay h2 { font-size: clamp(28px, 7vw, 54px); margin-bottom: 6px; }
.overlay .spinner { margin: 10px auto 0; }
#result.win { color: #7dff72; text-shadow: 0 0 22px #7dff7288; }
#result.lose { color: #ff6b7d; }
.tip { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); width: min(92%, 560px); display: flex; gap: 10px; align-items: center; background: #ffffffee; color: #13163a; padding: 10px 12px; border-radius: 14px; font-weight: 700; box-shadow: 0 6px 30px #0008; animation: fadeIn .3s ease; }
.tip span { flex: 1; }
.tip button { color: #13163a; border-color: #13163a33; min-height: 36px; padding: 6px 10px; }
.abilities { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 8px 0; touch-action: none; }
.abilities button, .chaos { position: relative; overflow: hidden; }
.abilities button { background: linear-gradient(180deg, #5a3a9a, #3c2670); border-color: #8d6ad8; display: flex; gap: 6px; align-items: center; justify-content: center; font-size: clamp(11px, 2.4vw, 14px); padding: 6px; touch-action: none; }
.abilities .aico { font-size: 18px; }
.abilities .key { font-size: 10px; opacity: .6; border: 1px solid #ffffff55; border-radius: 4px; padding: 0 4px; }
.ring { position: absolute; inset: 0; background: conic-gradient(#000a calc(var(--cd, 0) * 1turn), transparent 0); pointer-events: none; }
.abilities button .ring { border-radius: inherit; }
.controls { display: flex; gap: 8px; }
.controls button { height: 84px; min-width: 0; font-size: 26px; touch-action: none; }
.controls .move { flex: 3; }
.controls .chaos { flex: 4; font-family: var(--display); font-size: clamp(16px, 4.5vw, 24px); background: linear-gradient(180deg, #ff7b32, #c2410c); border-color: #ffb07a; box-shadow: 0 0 22px #ff7b3244; }
.controls .chaos.alien { background: linear-gradient(180deg, #5fd23a, #2f7a19); border-color: #c8ff9a; }
.controls .chaos:disabled { opacity: 1; filter: saturate(.4) brightness(.7); }
.emotes button { font-size: 20px; min-width: 56px; }
.game-foot { justify-content: space-between; }
.picker { position: relative; }
.picker summary { list-style: none; display: flex; align-items: center; gap: 6px; }
.picker summary::-webkit-details-marker { display: none; }
.dropdown { position: absolute; bottom: calc(100% + 6px); right: 0; z-index: 5; width: min(290px, 88vw); max-height: 65vh; overflow: auto; display: grid; gap: 6px; background: #0e1330; border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.theme-buttons { display: grid; gap: 5px; }
.theme-buttons button { text-align: left; }
#track { width: 100%; font-size: 13px; }
#arenaTools { margin-top: 6px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #fff; color: #111; padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 20; animation: fadeIn .2s ease; }

@media (max-width: 720px) {
  .menu-grid { grid-template-columns: 1fr; }
  .big { grid-template-columns: auto 1fr; justify-items: start; text-align: left; column-gap: 12px; }
  .big .ico { grid-row: span 2; align-self: center; }
}
/* Phones held sideways: give the arena the space. */
@media (max-height: 500px) and (orientation: landscape) {
  .logo h1 { font-size: 44px; }
  .logo { margin-bottom: 6px; }
  .big { padding: 10px; }
  #hint { display: none; }
  #game {
    display: grid; grid-template-columns: 76px minmax(0, 1fr) 160px; grid-template-rows: auto 1fr 1fr auto; gap: 6px;
    height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .scorebar { grid-column: 1 / -1; margin: 0; }
  .score { font-size: 26px; }
  .arena { grid-column: 2; grid-row: 2 / 4; min-height: 0; display: flex; align-items: center; justify-content: center; }
  .arena canvas { height: 100%; width: auto; max-width: 100%; }
  .controls { display: contents; }
  .controls button { height: auto; min-height: 0; }
  #up { grid-column: 1; grid-row: 2; }
  #down { grid-column: 1; grid-row: 3; }
  #chaos { grid-column: 3; grid-row: 3; font-size: 16px; }
  .abilities { grid-column: 3; grid-row: 2; grid-template-columns: 1fr; margin: 0; }
  .abilities button { min-height: 0; padding: 2px 6px; font-size: 11px; }
  #arenaTools, #emotes { grid-column: 1 / -1; margin: 0; }
  .game-foot { grid-column: 1 / -1; margin: 0; }
  .game-foot button, .game-foot summary { min-height: 34px; padding: 4px 10px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
