:root {
  --bg: #0a0e1a;
  --bg-elev: #111726;
  --bg-panel: #141a2b;
  --tile-light: #2a3142;
  --tile-dark: #1e2433;
  --accent: #4a9eff;
  --accent-dim: rgba(74, 158, 255, 0.18);
  --accent-glow: rgba(74, 158, 255, 0.4);
  --success: #4affaf;
  --danger: #ff6d6d;
  --text: #e0e6f0;
  --text-dim: #8a94ad;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --radius: 12px;
  --radius-sm: 8px;
  --sans: Inter, -apple-system, "Segoe UI", system-ui, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 800px at 15% -10%, rgba(74, 158, 255, 0.08), transparent 60%),
    radial-gradient(900px 600px at 110% 105%, rgba(138, 80, 255, 0.06), transparent 60%);
  background-attachment: fixed;
}

/* -------------------- Top bar -------------------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  background: rgba(10, 14, 26, 0.72);
  z-index: 2;
}
.topbar-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1;
}
.brand span {
  color: var(--accent);
  font-weight: 600;
}
.tagline {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 500;
}
.topbar-center {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: center;
}
.chip {
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(74, 158, 255, 0.28);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  white-space: nowrap;
}
.status {
  font-size: 14px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: color 240ms ease;
}
.status.dim { color: var(--text-dim); }
.status.victory { color: var(--success); }
.status.defeat { color: var(--danger); }
.topbar-right {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

/* -------------------- Buttons -------------------- */
.btn, .btn-ghost {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  transition: transform 120ms ease, background 150ms ease, border-color 150ms ease;
  white-space: nowrap;
}
.btn:hover, .btn-ghost:hover {
  background: #1a2134;
  border-color: var(--border-strong);
}
.btn:active, .btn-ghost:active {
  transform: translateY(1px);
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  padding: 7px 12px;
}
.btn-ghost:hover {
  color: var(--text);
}
.btn-primary {
  background: var(--accent);
  color: #0a0e1a;
  border-color: var(--accent);
  box-shadow: 0 8px 28px -10px var(--accent-glow);
  padding: 12px 24px;
  font-size: 14px;
}
.btn-primary:hover {
  background: #66b0ff;
  border-color: #66b0ff;
}

/* -------------------- Canvas stage -------------------- */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 0;
}
canvas#board {
  width: min(82vmin, 760px);
  height: min(82vmin, 760px);
  max-width: 100%;
  max-height: calc(100svh - 240px);
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
  filter: drop-shadow(0 24px 60px rgba(0, 0, 0, 0.55));
}

/* -------------------- Bottom bar -------------------- */
.bottombar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
  background: rgba(10, 14, 26, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.army-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}
.army {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.army::-webkit-scrollbar { display: none; }
.army-piece {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  font-size: 26px;
  line-height: 1;
  color: #f5f5f5;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  font-family: "Segoe UI Symbol", "Apple Symbols", serif;
}
.army-piece small {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  font-family: var(--mono);
}
.run-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* -------------------- Floating hint -------------------- */
.hint {
  position: fixed;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(10, 14, 26, 0.78);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
  max-width: calc(100% - 40px);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 2;
}
.king-glyph {
  color: var(--danger);
  font-size: 14px;
  font-family: "Segoe UI Symbol", "Apple Symbols", serif;
}

/* -------------------- Overlays -------------------- */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 14, 26, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
}
.overlay.visible {
  display: flex;
  animation: fadeIn 300ms ease;
}
.overlay-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 34px 30px;
  max-width: 580px;
  width: 100%;
  text-align: center;
  box-shadow:
    0 40px 90px -20px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(74, 158, 255, 0.08);
  animation: slideUp 360ms cubic-bezier(0.22, 1, 0.36, 1);
}
.overlay-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin-bottom: 8px;
  color: var(--text);
}
.overlay-subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 26px;
}
.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Draft cards */
.draft-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.draft-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 16px;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
  font: inherit;
  color: inherit;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.draft-card:hover {
  background: #1a2134;
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 18px 40px -20px var(--accent-glow);
}
.draft-glyph {
  font-size: 58px;
  line-height: 1;
  color: #f5f5f5;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
  font-family: "Segoe UI Symbol", "Apple Symbols", serif;
}
.draft-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}
.draft-desc {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  min-height: 32px;
}

/* End/win stats */
.end-stats {
  display: flex;
  gap: 32px;
  justify-content: center;
  margin-bottom: 26px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 600;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  font-family: var(--mono);
}

/* -------------------- Animations -------------------- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* -------------------- Responsive -------------------- */
@media (max-width: 720px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 12px 16px;
  }
  .topbar-left { gap: 0; }
  .brand { font-size: 16px; }
  .tagline { display: none; }
  .topbar-center {
    grid-column: 1 / -1;
    order: 3;
    gap: 10px;
    justify-content: flex-start;
  }
  .btn-ghost {
    font-size: 12px;
    padding: 6px 10px;
  }
  .stage {
    padding: 8px;
  }
  canvas#board {
    width: 94vmin;
    height: 94vmin;
    max-height: calc(100svh - 270px);
  }
  .bottombar {
    padding: 10px 14px 14px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .army-piece { font-size: 22px; }
  .army { gap: 8px; }
  .run-id { display: none; }
  .hint {
    bottom: 100px;
    font-size: 11px;
    max-width: calc(100% - 24px);
    white-space: normal;
    line-height: 1.35;
  }
  .draft-cards {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .draft-glyph { font-size: 46px; }
  .overlay-panel {
    padding: 26px 20px;
    border-radius: 14px;
  }
  .overlay-title { font-size: 22px; }
  .end-stats { gap: 24px; }
}

@media (max-width: 420px) {
  .hint { display: none; }
}
