:root {
  --bg0: #0c0e14;
  --bg1: #151922;
  --panel: rgba(12, 14, 20, 0.88);
  --ink: #e8ecf4;
  --muted: #8b93a7;
  --accent: #5ec8ff;
  --accent2: #7c5cff;
  --danger: #ff5c7a;
  --c0: #3d8bfd;
  --c1: #e85d4c;
  --c2: #4caf70;
  --c3: #c9a227;
  --font: "Segoe UI", "Trebuchet MS", sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg0);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}
.lobby-page { touch-action: manipulation; overflow: auto; }
.lobby-bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(94, 200, 255, 0.18), transparent 45%),
    radial-gradient(ellipse at 80% 90%, rgba(124, 92, 255, 0.16), transparent 40%),
    linear-gradient(160deg, #0c0e14, #1a2030 50%, #0c0e14);
}
.lobby-bg::after {
  content: "";
  position: absolute; inset: 0;
  background-image: linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}
.lobby {
  position: relative; z-index: 1;
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2rem 1.25rem 3rem; gap: 1.25rem;
}
.lobby-brand { text-align: center; }
.lobby-brand h1 {
  font-size: clamp(2.6rem, 11vw, 4rem);
  letter-spacing: 0.12em;
  font-weight: 800;
}
.lobby-brand p {
  margin-top: 0.35rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--accent);
  opacity: 0.9;
}
.lobby-card {
  width: min(380px, 100%);
  background: var(--panel);
  backdrop-filter: blur(10px);
  padding: 1.2rem;
  border: 1px solid rgba(94, 200, 255, 0.22);
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 14px 100%, 0 calc(100% - 14px));
}
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.field span { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
input {
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(232,236,244,0.18);
  color: var(--ink);
  padding: 0.75rem 0.9rem;
  font-size: 1rem;
  outline: none;
}
input:focus { border-color: var(--accent); }
.lobby-actions { margin-bottom: 1rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(232,236,244,0.25);
  background: rgba(0,0,0,0.35);
  color: var(--ink);
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
}
.btn.primary {
  background: linear-gradient(180deg, #5ec8ff, #3a8ec4);
  border-color: #8adfff;
  color: #061018;
  font-weight: 800;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.game-list-wrap > span {
  display: block; font-size: 0.72rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 0.5rem;
}
.game-list { list-style: none; display: flex; flex-direction: column; gap: 0.45rem; max-height: 240px; overflow-y: auto; }
.game-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.7rem 0.85rem; background: rgba(0,0,0,0.35);
  border: 1px solid rgba(232,236,244,0.12); cursor: pointer;
}
.game-list li:active, .game-list li:hover { border-color: var(--accent); }
.game-list .host-name { font-weight: 700; }
.game-list .meta { font-size: 0.72rem; color: var(--muted); }
.game-list .empty {
  opacity: 0.5; text-align: center; justify-content: center; cursor: default;
  border-style: dashed;
}
.hint { margin-top: 0.85rem; font-size: 0.72rem; color: var(--muted); text-align: center; }
.error { color: #ff8a9a; font-size: 0.85rem; margin-top: 0.5rem; text-align: center; }
.hidden { display: none !important; }
.waiting-title { text-align: center; margin-bottom: 1rem; }
.waiting-title span { display: block; font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.waiting-title strong { font-size: 1.2rem; color: var(--accent); }
.player-list { list-style: none; margin-bottom: 1rem; }
.player-list li {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0; border-bottom: 1px solid rgba(255,255,255,0.06);
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c0); }
.dot.c1 { background: var(--c1); }
.dot.c2 { background: var(--c2); }
.dot.c3 { background: var(--c3); }
.dot.c4 { background: #7c5cff; }
.dot.c5 { background: #ff9f43; }
.dot.c6 { background: #26c6da; }
.dot.c7 { background: #e056fd; }

.game-page { background: #0c0e14; touch-action: none; overscroll-behavior: none; }
.game-page,
.game-page * { touch-action: none; -webkit-text-size-adjust: 100%; }
.game-page input,
.game-page textarea { touch-action: manipulation; font-size: 16px; }
.group-bar {
  position: fixed;
  left: calc(8px + env(safe-area-inset-left, 0px));
  top: 50%;
  transform: translateY(-50%);
  z-index: 11;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  pointer-events: auto;
}
.group-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(232, 236, 244, 0.28);
  background: rgba(0, 0, 0, 0.55);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  position: relative;
}
.group-btn.has-units { border-color: rgba(94, 200, 255, 0.65); color: var(--accent); }
.group-btn.active {
  background: linear-gradient(180deg, #5ec8ff, #3a8ec4);
  border-color: #8adfff;
  color: #061018;
}
.group-btn .group-count {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 0.48rem;
  line-height: 1;
  opacity: 0.85;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud {
  position: fixed; top: 0; left: 0; right: 0; pointer-events: none; z-index: 10;
  padding: env(safe-area-inset-top, 8px) 10px 0;
}
.hud-top { display: flex; align-items: center; gap: 0.5rem; pointer-events: auto; }
.stat {
  background: var(--panel); padding: 0.4rem 0.7rem;
  border: 1px solid rgba(94,200,255,0.2); min-width: 72px;
}
.stat .label { display: block; font-size: 0.58rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.stat strong { font-size: 1.05rem; color: var(--accent); }
.btn-icon {
  margin-left: auto;
  background: linear-gradient(180deg, #5ec8ff, #3a8ec4);
  border: 1px solid #8adfff; color: #061018;
  padding: 0.55rem 0.85rem; font-size: 0.78rem; letter-spacing: 0.06em;
  text-transform: uppercase; font-weight: 800; cursor: pointer;
}
.btn-icon.ghost {
  margin-left: 0.35rem; background: rgba(0,0,0,0.5);
  border-color: rgba(232,236,244,0.3); color: var(--ink); font-weight: 600;
}
.btn-icon#btn-menu { margin-left: auto; margin-right: 0; }
.menu-list { margin-bottom: 0.75rem; }
.menu-danger {
  border-color: rgba(255, 92, 122, 0.55);
  color: #ffb3c0;
  background: rgba(80, 20, 30, 0.45);
}
.overlay-stats { margin: 0.85rem 0 1rem; max-height: 42vh; overflow: auto; }
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.stats-table th,
.stats-table td {
  padding: 0.4rem 0.35rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}
.stats-table th { color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.stats-table td:nth-child(n+2) { text-align: right; font-variant-numeric: tabular-nums; }
.overlay-card { max-height: 90vh; overflow-y: auto; }
#minimap {
  position: fixed; right: 10px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  width: 112px; height: 112px; border: 1px solid rgba(94,200,255,0.35);
  background: rgba(0,0,0,0.55); pointer-events: auto; z-index: 10;
  touch-action: none; cursor: crosshair;
}
.zoom-bar {
  position: fixed;
  right: 10px;
  bottom: calc(132px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  pointer-events: auto;
}
.zoom-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(94, 200, 255, 0.45);
  background: rgba(0, 0, 0, 0.62);
  color: var(--accent);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.zoom-btn:active { transform: scale(0.95); background: rgba(94, 200, 255, 0.18); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--panel); backdrop-filter: blur(10px);
  border-top: 1px solid rgba(94,200,255,0.35);
  padding: 0.5rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  max-height: 55vh; overflow-y: auto; touch-action: manipulation;
  animation: sheetIn 0.22s ease-out;
}
@keyframes sheetIn {
  from { transform: translateY(100%); opacity: 0.5; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 40px; height: 4px; margin: 0.25rem auto 0.75rem;
  background: rgba(255,255,255,0.25);
}
.sheet h2 {
  font-size: 0.85rem; letter-spacing: 0.1em; text-transform: uppercase;
  margin-bottom: 0.75rem; color: var(--muted);
}
.sheet-hint { font-size: 0.75rem; color: var(--muted); margin: -0.35rem 0 0.75rem; }
.build-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; margin-bottom: 0.75rem;
}
.build-item {
  background: rgba(0,0,0,0.35); border: 1px solid rgba(232,236,244,0.15);
  padding: 0.7rem 0.45rem; text-align: center; cursor: pointer; color: var(--ink); font-size: 0.78rem;
}
.build-item .cost { display: block; color: var(--accent); margin-top: 0.25rem; font-weight: 700; }
.build-item:disabled { opacity: 0.35; pointer-events: none; }
.select-info {
  position: fixed;
  left: calc(52px + env(safe-area-inset-left, 0px));
  bottom: calc(140px + env(safe-area-inset-bottom, 0px));
  z-index: 11; background: var(--panel); padding: 0.45rem 0.7rem; font-size: 0.75rem;
  border: 1px solid rgba(94,200,255,0.2); max-width: 60%; pointer-events: none;
}
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(6,8,14,0.78);
  display: flex; align-items: center; justify-content: center; touch-action: manipulation;
}
.overlay-card {
  background: var(--panel); border: 1px solid rgba(94,200,255,0.4);
  padding: 1.5rem; width: min(320px, 90%); text-align: center;
}
.overlay-card h2 { font-size: 1.5rem; letter-spacing: 0.08em; margin-bottom: 0.5rem; color: var(--accent); }
.overlay-card p { margin-bottom: 1.2rem; color: var(--muted); }
.toast {
  position: fixed; top: 20%; left: 50%; transform: translateX(-50%); z-index: 40;
  background: rgba(0,0,0,0.88); padding: 0.6rem 1rem; font-size: 0.85rem;
  border: 1px solid rgba(94,200,255,0.3); pointer-events: none;
  animation: fadeToast 2s ease-out forwards;
}
@keyframes fadeToast {
  0% { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
