:root {
  --bg: #05080f;
  --panel: #0c121c;
  --panel-2: #101a28;
  --border: #2a3a54;
  --text: #e8eef8;
  --muted: #8b9bb4;
  --iron: #5b8def;
  --ghost: #3ecf8e;
  --warn: #f0a050;
  --danger: #e85d4c;
  --pixel: "Press Start 2P", "Space Grotesk", monospace;
  --glow-iron: 0 0 24px rgba(91, 141, 239, 0.35);
  --glow-ghost: 0 0 24px rgba(62, 207, 142, 0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif; }

a { color: var(--iron); }
button { font-family: inherit; cursor: pointer; border: none; }

/* Attract trailer behind menus */
#attract-canvas {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  background: #05080f;
}

/* Screens */
.screen { display: none; position: fixed; inset: 0; z-index: 2; }
.screen.active { display: flex; flex-direction: column; }
#screen-game.active { display: block; z-index: 3; }
#screen-menu.active { z-index: 2; background: transparent; }

/* Menu shell */
.menu-shell {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 24px; gap: 18px;
  background:
    radial-gradient(ellipse 80% 55% at 50% -10%, rgba(91,141,239,.28), transparent 55%),
    radial-gradient(ellipse 50% 40% at 90% 100%, rgba(62,207,142,.14), transparent),
    radial-gradient(ellipse 40% 30% at 10% 80%, rgba(168,85,247,.08), transparent),
    linear-gradient(180deg, #080c16 0%, var(--bg) 40%, #04060c 100%);
  overflow-y: auto;
  position: relative;
}
/* Menu over live attract: keep UI readable, let battle show through */
.menu-shell--over-attract {
  background:
    radial-gradient(ellipse 70% 50% at 50% 20%, rgba(5,8,15,.55), transparent 70%),
    linear-gradient(180deg, rgba(5,8,15,.42) 0%, rgba(5,8,15,.55) 45%, rgba(5,8,15,.78) 100%);
}
.menu-shell--over-attract .logo,
.menu-shell--over-attract .tagline,
.menu-shell--over-attract .factions,
.menu-shell--over-attract .menu-actions {
  position: relative;
  z-index: 2;
}
.menu-shell--over-attract .fac-card {
  background: linear-gradient(160deg, rgba(12,18,30,.88), rgba(8,12,20,.9));
  backdrop-filter: blur(10px);
}
.menu-shell--over-attract .btn-main {
  backdrop-filter: blur(6px);
}
.menu-shell::before {
  content: "";
  position: absolute; inset: 0; pointer-events: none; opacity: 0.07;
  background-image:
    linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000 20%, transparent 75%);
}
.menu-shell--over-attract::before { opacity: 0.04; }
.logo {
  font-family: var(--pixel); font-size: clamp(1rem, 3vw, 1.45rem);
  letter-spacing: 0.04em; text-align: center; line-height: 1.6;
  text-shadow: 0 0 28px rgba(91,141,239,.65), 0 0 60px rgba(91,141,239,.25);
  position: relative; z-index: 1;
}
.logo-badge {
  display: inline-block; margin-top: 8px; font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 10px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
  color: #9bb8f0; background: rgba(91,141,239,.12); border: 1px solid rgba(91,141,239,.35);
  padding: 4px 10px; border-radius: 999px;
}
.logo span { color: var(--iron); }
.tagline { color: var(--muted); max-width: 420px; text-align: center; font-size: .95rem; }
.menu-actions { display: flex; flex-direction: column; gap: 10px; width: min(320px, 100%); margin-top: 8px; }
.btn-main {
  padding: 14px 18px; border-radius: 10px; font-weight: 700; font-size: 1rem;
  background: linear-gradient(180deg, #3a6fd4, #2a4fa0); color: #fff;
  border: 1px solid #6aa0ff; box-shadow: 0 4px 0 #1a3060;
}
.btn-main:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-main.ghost { background: linear-gradient(180deg, #2a8a5c, #1a5c3c); border-color: #5dff8a; box-shadow: 0 4px 0 #0d3020; }
.btn-main.dim { background: #1a2230; border-color: var(--border); box-shadow: 0 4px 0 #0a1018; color: var(--muted); }
.btn-sm {
  padding: 10px 14px; border-radius: 8px; background: #1a2230; color: var(--text);
  border: 1px solid var(--border); font-weight: 600;
}
.btn-sm:hover { border-color: var(--iron); }
.btn-sm.on { background: #1e3a6a; border-color: var(--iron); color: #fff; }
.back-row { width: min(720px, 100%); margin-bottom: 4px; }
.factions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: min(640px, 100%);
}
.fac-card {
  background: linear-gradient(160deg, rgba(20,28,42,.95), rgba(10,14,22,.95));
  border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; text-align: left;
  box-shadow: 0 8px 32px rgba(0,0,0,.35);
  position: relative; z-index: 1;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.fac-card:hover { transform: translateY(-2px); }
.fac-card.iron { border-color: rgba(91,141,239,.4); box-shadow: var(--glow-iron); }
.fac-card.ghost { border-color: rgba(62,207,142,.4); box-shadow: var(--glow-ghost); }
.fac-card h3 { font-size: 1.05rem; margin-bottom: 6px; }
.fac-card.iron h3 { color: var(--iron); }
.fac-card.ghost h3 { color: var(--ghost); }
.fac-card p { color: var(--muted); font-size: .88rem; line-height: 1.45; }

/* Campaign */
#screen-campaign .menu-shell,
#screen-skirmish .menu-shell,
#screen-how .menu-shell,
#screen-brief .menu-shell { justify-content: flex-start; padding-top: 28px; }
#campaign-list { width: min(640px, 100%); display: flex; flex-direction: column; gap: 10px; }
.mission-card {
  display: flex; gap: 14px; text-align: left; width: 100%;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; color: var(--text);
}
.mission-card:hover:not(.locked) { border-color: var(--iron); }
.mission-card.locked { opacity: .4; cursor: not-allowed; }
.mc-num {
  font-family: var(--pixel); font-size: 11px; color: var(--iron);
  background: #152238; border-radius: 8px; padding: 10px 8px; align-self: flex-start;
}
.mc-body strong { display: block; margin-bottom: 4px; }
.mc-body p { color: var(--muted); font-size: .88rem; margin-bottom: 6px; }
.mc-meta { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.sk-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0 14px; }
.how-box {
  width: min(560px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px; color: var(--muted); font-size: .92rem; line-height: 1.55;
}
.how-box h3 { color: var(--text); margin: 12px 0 6px; font-size: .95rem; }
.how-box h3:first-child { margin-top: 0; }
.how-box kbd {
  display: inline-block; background: #1a2230; border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px; font-size: .8rem; color: var(--text);
}

.brief-box {
  width: min(520px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; text-align: center;
}
.brief-box h2 { font-family: var(--pixel); font-size: .85rem; line-height: 1.6; margin-bottom: 12px; color: var(--iron); }
.brief-box p { color: var(--muted); margin-bottom: 10px; }
#brief-faction { color: var(--ghost); font-weight: 600; margin-bottom: 18px; display: block; }

/* Game layout */
#screen-game {
  background: #000;
  position: fixed;
  inset: 0;
  z-index: 2;
}
#game-wrap {
  position: absolute;
  top: 0; left: 0; right: 280px; bottom: 0;
  min-height: 200px;
  background: #060a0e;
  box-shadow: inset 0 0 80px rgba(0,0,0,.45);
}
#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  background: #0a1410;
}
#sidebar {
  position: absolute; top: 0; right: 0; bottom: 0; width: 280px;
  background:
    linear-gradient(180deg, rgba(14,20,32,.98), rgba(8,12,20,.98)),
    linear-gradient(90deg, rgba(91,141,239,.06), transparent 40%);
  border-left: 1px solid rgba(91,141,239,.22);
  box-shadow: -12px 0 40px rgba(0,0,0,.4);
  display: flex; flex-direction: column; z-index: 5;
  font-size: 13px;
  backdrop-filter: blur(8px);
}
#hud-top {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid rgba(91,141,239,.18); align-items: center;
  background: linear-gradient(180deg, rgba(20,32,52,.5), transparent);
}
.hud-pill {
  display: inline-flex; align-items: center; gap: 4px;
  background: linear-gradient(180deg, #1a2a40, #121c2c);
  border: 1px solid rgba(91,141,239,.28); border-radius: 999px;
  padding: 5px 11px; font-weight: 700; font-size: 12px;
  box-shadow: 0 0 12px rgba(91,141,239,.08);
}
.hud-pill.warn { color: var(--warn); border-color: #6a4020; }
#hud-faction { letter-spacing: .08em; }
.hud-actions { margin-left: auto; display: flex; gap: 6px; }
.hud-actions button {
  background: #1a2230; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px; font-size: 11px; font-weight: 600;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; background: transparent; color: var(--muted); padding: 8px 4px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 2px solid transparent;
}
.tab.on { color: var(--iron); border-bottom-color: var(--iron); }
.tab-panel { display: none; flex: 1; overflow-y: auto; padding: 8px; }
.tab-panel.on { display: block; }
.prod-btn {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  background: linear-gradient(160deg, #182234, #101820); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 8px 10px; margin-bottom: 7px; text-align: left; font-size: 12px;
  gap: 10px; transition: border-color .12s, transform .1s, background .12s, box-shadow .12s;
}
.prod-btn.with-icon { justify-content: flex-start; }
.prod-btn:hover {
  border-color: var(--iron); transform: translateY(-1px);
  background: linear-gradient(160deg, #1e2e48, #152030);
  box-shadow: 0 4px 16px rgba(91,141,239,.15);
}
.prod-btn.active {
  border-color: var(--ghost); background: linear-gradient(160deg, #0e281c, #0a1c14);
  box-shadow: 0 0 0 1px var(--ghost), 0 0 16px rgba(62,207,142,.2);
}
.prod-btn em { color: var(--ghost); font-style: normal; font-weight: 700; font-size: 11px; }
.prod-icon {
  width: 40px; height: 40px; border-radius: 6px; flex-shrink: 0;
  image-rendering: pixelated; background: #0a1018; border: 1px solid #2a3548;
}
.prod-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.prod-meta b { font-weight: 600; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud-credits::before { content: "⚙ "; opacity: .7; }
#hud-power::before { content: "⚡ "; }
#sel-panel {
  padding: 8px 12px; border-top: 1px solid var(--border); color: var(--muted);
  font-size: 11px; min-height: 44px;
}
.super-row { padding: 8px 12px; border-top: 1px solid var(--border); }
.super-bar { height: 8px; background: #1a2230; border-radius: 4px; overflow: hidden; margin-bottom: 6px; }
#super-fill { height: 100%; width: 0; background: linear-gradient(90deg, #a05020, #ffcc44); transition: width .2s; }
#btn-super {
  width: 100%; padding: 8px; border-radius: 8px; font-weight: 700; font-size: 12px;
  background: #3a2010; color: #ffcc88; border: 1px solid #6a4020;
}
#btn-super:disabled { opacity: .4; cursor: not-allowed; }
#btn-super:not(:disabled):hover { background: #5a3018; }

#toast {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(18,28,48,.95), rgba(10,14,24,.95));
  border: 1px solid rgba(91,141,239,.55); color: var(--text);
  padding: 9px 18px; border-radius: 10px; font-weight: 600; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 8;
  max-width: 60%; text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.45), 0 0 24px rgba(91,141,239,.2);
  letter-spacing: 0.02em;
}
#toast.show { opacity: 1; }

#end-overlay {
  display: none; position: absolute; inset: 0; z-index: 20;
  background: radial-gradient(ellipse at center, rgba(10,16,32,.75), rgba(0,0,0,.88));
  align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
#end-overlay.show { display: flex; }
.end-card {
  background: linear-gradient(160deg, #121c2c, #0a1018);
  border: 2px solid var(--iron); border-radius: 18px;
  padding: 28px 32px; text-align: center; min-width: 280px;
  box-shadow: 0 0 0 1px rgba(91,141,239,.2), 0 24px 64px rgba(0,0,0,.55), var(--glow-iron);
}
.end-card h2 { font-family: var(--pixel); font-size: .9rem; margin-bottom: 10px; color: var(--ghost); text-shadow: 0 0 20px rgba(62,207,142,.4); }
.end-card p { color: var(--muted); margin-bottom: 18px; }
.end-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.hint-bar {
  position: absolute; left: 12px; bottom: 12px; z-index: 6;
  background: linear-gradient(180deg, rgba(12,18,28,.88), rgba(8,12,18,.88));
  border: 1px solid rgba(91,141,239,.22); border-radius: 10px;
  padding: 7px 12px; font-size: 11px; color: var(--muted); max-width: calc(100% - 320px);
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
}

@media (max-width: 900px) {
  #game-wrap { inset: 0 0 42% 0; }
  #sidebar { top: auto; height: 42%; width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .hint-bar { display: none; }
}
