:root {
  --bg: #04060d;
  --accent: #3ff0ff;
  --accent2: #ff4d8d;
  --text: #dff6ff;
  --dim: #7f9bb3;
  --panel: rgba(10, 18, 32, 0.82);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  touch-action: manipulation;
  overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
}

[hidden] { display: none !important; }

#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
#safe-probe { position: fixed; top: 0; height: env(safe-area-inset-top, 0px); width: 1px; pointer-events: none; visibility: hidden; }

#game { position: fixed; inset: 0; z-index: 1; touch-action: none; }
#gl, #hud { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud { touch-action: none; }

/* ---------- screens ---------- */
.screen, .overlay {
  position: fixed; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  overflow-y: auto;
}
.overlay { z-index: 10; background: rgba(2, 4, 10, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }

.logo { text-align: center; margin-bottom: 28px; }
.logo h1 {
  margin: 0; font-weight: 900; line-height: 0.9; letter-spacing: 0.12em;
  font-size: clamp(40px, 13vw, 72px);
  display: flex; flex-direction: column;
}
.logo h1 span:first-child {
  background: linear-gradient(180deg, #ffffff 0%, var(--accent) 60%, #1a7fa0 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 14px rgba(63, 240, 255, 0.55));
}
.logo h1 span:last-child {
  font-size: 0.48em; letter-spacing: 0.42em; margin-top: 8px; padding-left: 0.42em;
  color: var(--accent2); text-shadow: 0 0 12px rgba(255, 77, 141, 0.7);
}
.logo-sub { font-size: 11px; letter-spacing: 0.5em; color: var(--dim); margin-bottom: 10px; padding-left: 0.5em; }

.panel {
  position: relative;
  width: min(92vw, 380px);
  padding: 22px 18px 18px;
  background:
    linear-gradient(180deg, rgba(63, 240, 255, 0.07), transparent 40%),
    var(--panel);
  clip-path: polygon(16px 0, 100% 0, 100% calc(100% - 16px), calc(100% - 16px) 100%, 0 100%, 0 16px);
  box-shadow: inset 0 0 0 1px rgba(63, 240, 255, 0.35), inset 0 0 40px rgba(63, 240, 255, 0.06);
  display: flex; flex-direction: column; gap: 10px;
}
.panel::before, .panel::after {
  content: ""; position: absolute; width: 22px; height: 22px; pointer-events: none;
  border: 2px solid var(--accent);
}
.panel::before { top: 0; left: 0; border-right: 0; border-bottom: 0; transform: translate(4px, 4px); }
.panel::after { bottom: 0; right: 0; border-left: 0; border-top: 0; transform: translate(-4px, -4px); }
.panel.wide { width: min(94vw, 440px); }

.panel-title {
  font-size: 11px; letter-spacing: 0.35em; color: var(--accent);
  border-bottom: 1px solid rgba(63, 240, 255, 0.25); padding-bottom: 8px; margin-bottom: 4px;
}

.btn {
  appearance: none; border: 0; cursor: pointer;
  font: 700 15px/1 var(--font); letter-spacing: 0.22em; color: var(--text);
  padding: 15px 12px; width: 100%;
  background: linear-gradient(180deg, rgba(40, 60, 90, 0.9), rgba(16, 24, 40, 0.95));
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  box-shadow: inset 0 0 0 1px rgba(63, 240, 255, 0.35);
  transition: transform 0.06s, filter 0.15s;
}
.btn:active { transform: scale(0.98); filter: brightness(1.3); }
.btn:disabled { opacity: 0.4; }
.btn.primary {
  color: #001018;
  background: linear-gradient(180deg, #8ff8ff, var(--accent) 50%, #14a8c0);
  box-shadow: 0 0 18px rgba(63, 240, 255, 0.5);
}
.btn.accent { color: #fff; background: linear-gradient(180deg, #ff7aa8, var(--accent2)); }
.btn.small { font-size: 12px; padding: 11px 8px; }
.btn.tiny { width: 34px; padding: 8px 0; font-size: 16px; letter-spacing: 0; }
.row { display: flex; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 10px; letter-spacing: 0.3em; color: var(--dim); margin-bottom: 6px; }
input {
  font: 700 18px var(--mono); color: var(--text); letter-spacing: 0.15em;
  background: rgba(0, 0, 0, 0.45); border: 1px solid rgba(63, 240, 255, 0.4);
  padding: 12px; outline: none; text-transform: uppercase; width: 100%;
  user-select: text; -webkit-user-select: text;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 12px rgba(63, 240, 255, 0.3); }
.code-input { text-align: center; font-size: 40px; letter-spacing: 0.4em; padding: 14px 0 14px 0.4em; }

.status { font-size: 13px; color: var(--dim); text-align: center; min-height: 1.2em; }
.status.error { color: #ff6b7d; }

.room { display: flex; gap: 14px; align-items: center; }
.qr-frame {
  flex: none; padding: 8px; background: #e8fbff;
  box-shadow: 0 0 0 2px var(--accent), 0 0 24px rgba(63, 240, 255, 0.45);
}
#qr { display: block; width: 150px; height: 150px; image-rendering: pixelated; }
.code-box { display: flex; flex-direction: column; gap: 6px; }
.code-box .label { font-size: 10px; letter-spacing: 0.3em; color: var(--dim); }
.code-box .code { font: 800 42px var(--mono); letter-spacing: 0.15em; color: #fff; text-shadow: 0 0 16px rgba(63, 240, 255, 0.8); }
.code-box .hint { font-size: 11px; color: var(--dim); line-height: 1.4; }

.list-title { font-size: 10px; letter-spacing: 0.3em; color: var(--dim); margin-top: 6px; }
.pilots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.pilots li {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: rgba(255, 255, 255, 0.04); border-left: 3px solid var(--c, var(--accent));
  font: 600 14px var(--font); letter-spacing: 0.08em;
}
.pilots li .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.pilots li .meta { margin-left: auto; font: 600 10px var(--mono); color: var(--dim); text-align: right; }
.pilots li .meta.good { color: #5dff9a; }

.bots-row { display: flex; align-items: center; gap: 8px; font-size: 10px; letter-spacing: 0.15em; color: var(--dim); }
.bots-row > span:first-child { flex: 1; }
.bots-row #bots-count, .bots-row #limit-count { font: 700 16px var(--mono); color: var(--text); min-width: 22px; text-align: center; }
.bots-row .sep { flex: 1; }

.linkinfo { font: 600 11px var(--mono); color: var(--dim); text-align: center; }

.scanner { position: relative; width: 100%; aspect-ratio: 1; background: #000; overflow: hidden; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scan-reticle {
  position: absolute; inset: 18%; border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35), 0 0 20px rgba(63, 240, 255, 0.6);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.45; } }

.setting { display: flex; flex-direction: column; gap: 8px; font-size: 12px; letter-spacing: 0.12em; color: var(--dim); }
.setting.check { flex-direction: row; align-items: center; gap: 12px; color: var(--text); letter-spacing: 0.03em; font-size: 14px; }
.setting input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.setting input[type=range] { padding: 0; border: 0; background: none; accent-color: var(--accent); }

.manual { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.45; color: #c8deea; display: flex; flex-direction: column; gap: 6px; }
.manual b { color: #fff; }

.calib-phone { margin: 8px auto 4px; width: 54px; height: 92px; border: 2px solid var(--accent); border-radius: 10px; position: relative; animation: wobble 2.4s ease-in-out infinite; box-shadow: 0 0 16px rgba(63, 240, 255, 0.4); }
.calib-phone div { position: absolute; inset: 8px 5px; background: rgba(63, 240, 255, 0.15); border-radius: 3px; }
@keyframes wobble { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
.overlay p { margin: 4px 0; text-align: center; font-size: 14px; line-height: 1.45; color: #c8deea; }
.overlay p.warn { color: #ffb347; font-size: 12px; }

.scores { width: 100%; border-collapse: collapse; font: 600 13px var(--font); }
.scores th { font-size: 10px; letter-spacing: 0.2em; color: var(--dim); text-align: left; padding: 4px 6px; font-weight: 600; }
.scores td { padding: 7px 6px; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.scores th.n { text-align: right; }
.scores td.n { text-align: right; font-family: var(--mono); }
.scores tr.me td { background: rgba(63, 240, 255, 0.08); }
.winner { text-align: center; font: 900 24px var(--font); letter-spacing: 0.12em; padding: 6px 0; text-shadow: 0 0 18px currentColor; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); transform: translateX(-50%);
  z-index: 50; padding: 10px 16px; background: rgba(10, 18, 32, 0.95);
  border: 1px solid var(--accent); font-size: 13px; letter-spacing: 0.05em; max-width: 90vw; text-align: center;
}

.foot { position: fixed; bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); font: 10px var(--mono); color: #3d5266; letter-spacing: 0.2em; }
