* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  background: #05060c;
  color: #f4f7fb;
  font-family: "Exo 2", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  user-select: none;
}
#space-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 78% 110%, rgba(70,110,200,0.28), transparent 42%),
    radial-gradient(ellipse at 18% 8%, rgba(90,40,130,0.28), transparent 46%),
    radial-gradient(ellipse at 60% 40%, rgba(30,50,90,0.2), transparent 50%),
    #05060c;
}
#space-bg::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1px 1px at 8% 12%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 22% 38%, rgba(255,255,255,0.55), transparent),
    radial-gradient(1.5px 1.5px at 40% 18%, rgba(200,220,255,0.7), transparent),
    radial-gradient(1px 1px at 62% 72%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 81% 22%, rgba(255,230,200,0.55), transparent),
    radial-gradient(1.5px 1.5px at 88% 58%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 14% 78%, rgba(200,220,255,0.5), transparent),
    radial-gradient(1px 1px at 52% 48%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 33% 88%, rgba(255,255,255,0.55), transparent),
    radial-gradient(1px 1px at 71% 8%, rgba(255,255,255,0.45), transparent);
  opacity: 0.9;
}
.screen { z-index: 1; }
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
#title-screen.screen, #end-screen.screen {
  overflow-y: auto;
  align-items: flex-start;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}
#title-screen .title-panel, #end-screen .title-panel { margin: auto; }
.hidden { display: none !important; }

/* Title */
.title-panel {
  position: relative;
  text-align: center;
  padding: 48px 56px;
  background: linear-gradient(160deg, rgba(16,20,32,0.92) 0%, rgba(8,10,16,0.94) 100%);
  border: 1px solid #3a4560;
  border-radius: 16px;
  box-shadow: 0 0 60px rgba(62, 106, 225, 0.22), inset 0 1px 0 rgba(255,255,255,0.06);
  max-width: 520px;
  backdrop-filter: blur(8px);
}
.orbit-ring {
  width: 72px; height: 72px; margin: 0 auto 20px;
  border: 2px solid #3E6AE1; border-radius: 50%;
  position: relative;
  box-shadow: 0 0 24px rgba(62,106,225,0.45);
  animation: spin 12s linear infinite;
}
.orbit-ring::after {
  content: ""; position: absolute; top: -5px; left: 50%;
  width: 10px; height: 10px; margin-left: -5px;
  background: #3E6AE1; border-radius: 50%;
  box-shadow: 0 0 10px #3E6AE1;
}
@keyframes spin { to { transform: rotate(360deg); } }
h1 {
  font-family: Orbitron, "Exo 2", "Segoe UI", sans-serif;
  font-size: 2.4rem; font-weight: 700; letter-spacing: 0.08em;
  color: #f4f7fb;
}
h1 span { color: #3E6AE1; display: block; }
@media (min-width: 720px) {
  h1 { font-size: 1.85rem; letter-spacing: 0.08em; white-space: nowrap; }
  h1 span { display: inline; }
}
.tagline {
  margin-top: 6px; color: #c5cee0; letter-spacing: 0.22em;
  text-transform: uppercase; font-size: 0.75rem;
}
.blurb {
  margin: 22px 0 28px; color: #d5dcec; line-height: 1.5; font-size: 0.95rem;
}
.btn-primary {
  background: #3E6AE1; color: #fff; border: none;
  padding: 14px 36px; font-size: 1rem; font-weight: 700;
  letter-spacing: 0.12em; border-radius: 8px; cursor: pointer;
  box-shadow: 0 0 28px rgba(62,106,225,0.45);
  transition: transform 0.12s, background 0.12s;
}
.btn-primary:hover { background: #557cf0; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(1px); }
.controls-hint {
  margin-top: 28px; display: grid; gap: 8px;
  color: #c5cee0; font-size: 0.8rem; text-align: left;
}
kbd {
  display: inline-block; min-width: 36px; padding: 2px 6px;
  background: #1a1d27; border: 1px solid #2a3144; border-radius: 4px;
  color: #e8edf7; font-family: inherit; font-size: 0.75rem;
  text-align: center; margin-right: 6px;
}

/* Game */
#game-screen { background: #05060c; }
#game {
  display: block;
  background: #0a0a0b;
  cursor: crosshair;
  box-shadow: 0 0 0 1px #1a1f2e;
  max-width: 100vw; max-height: 100vh;
  touch-action: none;
}
#minimap {
  position: absolute; right: 16px; bottom: 110px;
  background: #070814; border: 1px solid #3a4560; border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  z-index: 5;
  touch-action: none;
}

#hud-top {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 18px; align-items: center;
  background: rgba(8,10,16,0.92); border: 1px solid #3a4560;
  border-radius: 10px; padding: 8px 18px;
  backdrop-filter: blur(8px); z-index: 5;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.res { display: flex; align-items: center; gap: 6px; font-size: 0.95rem; color: #f4f7fb; }
.res .dot { width: 8px; height: 8px; border-radius: 50%; }
.res.goo .dot { background: #d4a017; box-shadow: 0 0 6px #d4a017; }
.res.energy .dot { background: #3E6AE1; box-shadow: 0 0 6px #3E6AE1; }
.res.pop .dot { background: #4ade80; }
#clock { color: #d5dcec; font-size: 0.85rem; margin-left: 8px; border-left: 1px solid #2a3144; padding-left: 14px; }

#hud-bottom {
  position: absolute; left: 16px; right: 210px; bottom: 12px;
  display: flex; gap: 12px; align-items: stretch; z-index: 5;
}
#selected-panel {
  min-width: 200px; max-width: 280px;
  background: rgba(8,10,16,0.94); border: 1px solid #3a4560;
  border-radius: 10px; padding: 10px 14px;
}
#sel-name { font-weight: 700; color: #f4f7fb; margin-bottom: 6px; font-size: 1rem; }
#sel-hp { height: 6px; background: #1a1d27; border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
#sel-hp-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #3E6AE1, #6b8ff5); transition: width 0.1s; }
#sel-info { font-size: 0.8rem; color: #c5cee0; line-height: 1.4; }

#build-menu, #train-menu {
  display: flex; gap: 8px; flex-wrap: wrap;
  background: rgba(8,10,16,0.94); border: 1px solid #3a4560;
  border-radius: 10px; padding: 8px;
}
.build-btn, .train-btn {
  background: #141824; color: #eef2fa; border: 1px solid #3a4560;
  border-radius: 8px; padding: 8px 12px; cursor: pointer;
  font-size: 0.78rem; line-height: 1.3; min-width: 88px;
  transition: border-color 0.12s, background 0.12s;
}
.build-btn:hover, .train-btn:hover,
.build-btn.active, .train-btn.active {
  border-color: #3E6AE1; background: #1a2240; color: #fff;
}
.build-btn small, .train-btn small { color: #6b7388; font-size: 0.7rem; }

#msg {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(62,106,225,0.9); color: #fff;
  padding: 8px 20px; border-radius: 8px; font-weight: 600;
  z-index: 10; pointer-events: none;
  animation: fadeup 2.5s forwards;
}
@keyframes fadeup {
  0% { opacity: 0; transform: translateX(-50%) translateY(8px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

#end-screen h1 { font-size: 3rem; }
#end-screen #end-title.win { color: #4ade80; text-shadow: 0 0 30px rgba(74,222,128,0.4); }
#end-screen #end-title.lose { color: #f87171; text-shadow: 0 0 30px rgba(248,113,113,0.4); }
#end-sub { margin: 12px 0 8px; color: #a8b0c4; }
.end-tip { margin: 0 0 24px; color: #8b93a8; font-size: 14px; max-width: 520px; margin-left: auto; margin-right: auto; }

#beacon-hud {
  display: flex; align-items: center; gap: 8px;
  color: #d5dcec; font-size: 0.8rem;
  border-left: 1px solid #2a3144; padding-left: 14px;
}
#beacon-bar-wrap {
  display: inline-block; width: 70px; height: 6px;
  background: #1a1d27; border-radius: 3px; overflow: hidden;
  vertical-align: middle;
}
#beacon-bar {
  display: block; height: 100%; width: 50%;
  background: #6b7388; transition: width 0.2s, background 0.2s;
}

/* Title actions */
.title-actions {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.btn-secondary {
  background: transparent; color: #c5cad8;
  border: 1px solid #3E6AE1;
  padding: 12px 32px; font-size: 0.95rem; font-weight: 700;
  letter-spacing: 0.12em; border-radius: 8px; cursor: pointer;
  box-shadow: 0 0 18px rgba(62,106,225,0.2);
  transition: transform 0.12s, background 0.12s, color 0.12s;
}
.btn-secondary:hover {
  background: rgba(62,106,225,0.18); color: #fff;
  transform: translateY(-1px);
}
.btn-secondary:active { transform: translateY(1px); }
.tutorial-hint {
  margin-top: 14px; color: #3E6AE1; font-size: 0.82rem;
  letter-spacing: 0.04em;
  animation: pulse-hint 2.4s ease-in-out infinite;
}
@keyframes pulse-hint {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

/* Tutorial overlay — dimmer is pointer-events none; card catches clicks */
#tutorial-overlay {
  position: absolute; inset: 0;
  z-index: 20;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 16px 118px;
  background: linear-gradient(to top, rgba(10,10,11,0.55) 0%, transparent 42%);
}
#tutorial-overlay.hidden { display: none !important; }
.tutorial-card {
  pointer-events: auto;
  max-width: 520px; width: 100%;
  background: rgba(12,14,20,0.94);
  border: 1px solid #2a3144;
  border-radius: 12px;
  padding: 16px 20px 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.55), 0 0 0 1px rgba(62,106,225,0.15);
  backdrop-filter: blur(10px);
  text-align: left;
}
.tutorial-step-label {
  font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: #3E6AE1; margin-bottom: 6px; font-weight: 600;
}
.tutorial-card h2 {
  font-size: 1.15rem; font-weight: 700; color: #f2f4f8;
  letter-spacing: 0.02em; margin-bottom: 8px;
}
.tutorial-card p {
  color: #a8b0c4; font-size: 0.88rem; line-height: 1.5;
  margin-bottom: 14px;
}
.tutorial-actions {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.tut-btn {
  padding: 10px 22px; font-size: 0.85rem;
}
.btn-ghost {
  background: transparent; color: #6b7388;
  border: 1px solid #2a3144;
  padding: 9px 16px; font-size: 0.8rem; font-weight: 600;
  letter-spacing: 0.06em; border-radius: 8px; cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.btn-ghost:hover { color: #c5cad8; border-color: #3E6AE1; }

/* v2 additions */
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.choice-label { width: 100%; color: #c5cee0; font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; margin-top: 6px; }
.chip {
  background: #141824; color: #e8eaf0; border: 1px solid #2a3144;
  border-radius: 8px; padding: 7px 14px; cursor: pointer;
  font-size: 0.82rem; font-weight: 600;
}
.chip.active, .chip:hover { border-color: #3E6AE1; background: #1a2240; }
#map-blurb { color: #d5dcec; font-size: 0.8rem; min-height: 1.2em; margin-bottom: 8px; }
#objectives {
  position: absolute; top: 58px; left: 16px; z-index: 5;
  background: rgba(8,10,16,0.94); border: 1px solid #3a4560;
  border-radius: 10px; padding: 10px 12px; width: 250px;
  color: #f4f7fb; font-size: 0.8rem; line-height: 1.45;
}
#objectives .obj-title { color: #3E6AE1; font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 6px; font-weight: 700; }
#objectives .done { color: #4ade80; }
#research-menu, #ability-menu {
  display: flex; gap: 8px; flex-wrap: wrap;
  background: rgba(8,10,16,0.94); border: 1px solid #3a4560;
  border-radius: 10px; padding: 8px;
}
.research-btn, .ability-btn {
  background: #141824; color: #eef2fa; border: 1px solid #3a4560;
  border-radius: 8px; padding: 8px 12px; cursor: pointer;
  font-size: 0.78rem; line-height: 1.3; min-width: 96px;
}
.research-btn:hover, .ability-btn:hover { border-color: #3E6AE1; background: #1a2240; }
.research-btn.done { opacity: 0.5; cursor: default; }
.research-btn small, .ability-btn small, .build-btn small, .train-btn small { display: block; color: #a8b0c4; }
#pause-overlay {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5,5,6,0.72);
}
#pause-overlay .title-panel { max-width: 380px; }
#pause-overlay .title-actions { margin-top: 12px; }
#end-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px;
  text-align: left; margin: 8px 0 22px; color: #e8eaf0; font-size: 0.85rem;
}
#end-stats span { color: #a8b0c4; display: block; font-size: 0.72rem; }
#end-stats b { font-weight: 700; }
#diff-label { color: #d5dcec; font-size: 0.78rem; text-transform: capitalize; }
#beacon-hold { color: #e8eaf0; font-size: 0.75rem; min-width: 36px; }
.hotkey-col { display: grid; gap: 6px; }
.title-panel { max-width: 580px; }
#game-screen { flex-direction: column; }

.res.money .dot { background: #f5c518; box-shadow: 0 0 6px #f5c518; }
.res.minerals .dot { background: #9bb4c8; box-shadow: 0 0 6px #9bb4c8; }
.res.food .dot { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
#hud-top { flex-wrap: wrap; max-width: min(1100px, 96vw); gap: 12px; }
.build-btn.locked, .train-btn.locked, .research-btn.locked {
  opacity: 0.48; border-color: #3a3140;
}
.build-btn .cap-line, .train-btn .cap-line, .research-btn .cap-line {
  display: block; color: #f0c987; font-size: 0.68rem; margin-top: 2px;
}
.build-btn, .train-btn { min-width: 112px; }

/* Quick UX pass: How to play + resource tooltip cursor */
.how-to-play {
  margin: 16px auto 0;
  text-align: left;
  max-width: 460px;
  background: rgba(12, 16, 28, 0.86);
  border: 1px solid #3a4560;
  border-radius: 10px;
  padding: 8px 12px;
  color: #d5dcec;
  font-size: 0.82rem;
  line-height: 1.45;
}
.how-to-play summary {
  cursor: pointer;
  color: #e8eaf0;
  font-weight: 700;
  letter-spacing: 0.04em;
  list-style: none;
}
.how-to-play summary::-webkit-details-marker { display: none; }
.how-to-play summary::before {
  content: "▸ ";
  color: #3E6AE1;
}
.how-to-play[open] summary::before { content: "▾ "; }
.how-to-play ul {
  margin: 8px 0 4px 0;
  padding-left: 18px;
}
.how-to-play li { margin: 4px 0; }
.how-to-play strong { color: #e8eaf0; }
.how-to-play.in-game-help {
  position: absolute;
  top: 58px;
  left: 278px;
  z-index: 5;
  margin: 0;
  max-width: 280px;
  background: rgba(8,10,16,0.94);
  backdrop-filter: blur(8px);
}
.res[title] { cursor: help; }
.build-btn.locked, .train-btn.locked, .research-btn.locked {
  cursor: help;
}


/* Optional match timer + score summary */
#clock.timer-on {
  color: #e8eaf0;
  font-weight: 700;
}
#clock.timer-low {
  color: #f87171;
}
#end-screen h1.draw { color: #f0c987; text-shadow: 0 0 30px rgba(240,201,135,0.4); }
#end-stats .score-final,
#end-stats .score-best {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-top: 6px;
  border-top: 1px solid #2a3144;
}
#end-stats .score-final b { color: #4ade80; font-size: 1.15rem; }
#end-stats .score-formula {
  grid-column: 1 / -1;
}
#end-stats .score-formula b {
  font-weight: 500;
  color: #a8b0c4;
  font-size: 0.72rem;
  line-height: 1.4;
}
#end-screen .title-panel { max-width: 640px; }


/* Narrow / touch layout */
@media (max-width: 900px) {
  .title-panel { padding: 28px 18px; width: 100%; }
  h1 { font-size: 1.7rem; }
  .controls-hint { font-size: 0.72rem; }
  #hud-top {
    left: 8px; right: 8px; transform: none;
    width: auto; max-width: none;
    gap: 8px; padding: 6px 10px;
    font-size: 0.75rem;
  }
  #msg { top: 118px; }
  #objectives { display: none; }
  .how-to-play.in-game-help { display: none; }
  #minimap { right: 8px; bottom: auto; top: 86px; width: 108px; height: 72px; }
  #hud-bottom {
    left: 8px; right: 8px; bottom: 8px;
    flex-wrap: wrap;
    max-height: 34vh;
    overflow-y: auto;
    gap: 6px;
  }
  #selected-panel { min-width: 0; flex: 1 1 100%; padding: 6px 8px; max-height: 56px; overflow: hidden; }
  #selected-panel.is-empty { display: none; }
  #sel-info { display: none; }
  .build-btn, .train-btn, .research-btn, .ability-btn {
    min-height: 36px;
    min-width: 0;
    flex: 1 1 30%;
    padding: 5px 8px;
    font-size: 0.7rem;
  }
  #tutorial-overlay { padding: 0 10px 38vh; }
}
@media (max-width: 560px) {
  #minimap { width: 96px; height: 64px; }
}
