:root {
  --void: #07090c;
  --panel: #0d1218;
  --panel-edge: #1c2733;
  --cyan: #39d8ff;
  --cyan-dim: #1d7fa0;
  --amber: #ffb340;
  --danger: #ff4d5e;
  --text: #cfe4ef;
  --text-dim: #75899a;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--void);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

/* ---------- top bar ---------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 16px;
  height: 52px;
  flex: 0 0 auto;
  background: linear-gradient(180deg, #0f151c, #0a0e13);
  border-bottom: 1px solid var(--panel-edge);
  /* Never wrap to a second row: the board's height budget depends on the bar
     staying exactly one row tall. Items compress instead. */
  flex-wrap: nowrap;
  overflow: hidden;
}

.brand {
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(57, 216, 255, 0.35);
}
.brand .slash { color: var(--amber); }

.stat { display: flex; flex-direction: column; line-height: 1.2; white-space: nowrap; }
.stat label, #power label {
  font-size: 9px;
  letter-spacing: 1.4px;
  color: var(--text-dim);
}
.stat .value { font-size: 15px; font-weight: 700; }
#stat-scrap .value { color: var(--amber); }
#stat-core .value { color: var(--cyan); }
#stat-core.critical .value { color: var(--danger); }

#power {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1 1 160px;
  min-width: 120px;
  max-width: 300px;
}
#power .value {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.powerbar {
  position: relative;
  height: 9px;
  background: #0a1016;
  border: 1px solid var(--panel-edge);
  overflow: hidden;
}
.powerbar .gen {
  position: absolute; inset: 0 auto 0 0;
  width: 100%;
  background: linear-gradient(90deg, #10424f, #17606f);
}
.powerbar .draw {
  position: absolute; inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, var(--cyan-dim), var(--cyan));
  transition: width 90ms linear;
}
.powerbar.brownout .draw { background: linear-gradient(90deg, #8c2733, var(--danger)); }

.controls { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* Segmented speed control: one button per speed, so the current one is
   readable at a glance and any speed is a single click away. */
.segmented { display: flex; }
.segmented button {
  border-radius: 0;
  border-right-width: 0;
  padding: 5px 9px;
  min-width: 34px;
}
.segmented button:first-child { border-top-left-radius: 2px; border-bottom-left-radius: 2px; }
.segmented button:last-child {
  border-right-width: 1px;
  border-top-right-radius: 2px;
  border-bottom-right-radius: 2px;
}

.panel-toggles { display: flex; gap: 6px; margin-right: 4px; }
.panel-toggles button { font-size: 10px; padding: 5px 8px; opacity: 0.6; }
.panel-toggles button.active { opacity: 1; }

/* ---------- layout ---------- */

#stage {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.panel {
  width: 224px;
  flex: 0 0 224px;
  background: var(--panel);
  border-right: 1px solid var(--panel-edge);
  padding: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: flex-basis 160ms ease, width 160ms ease, padding 160ms ease;
}
#inspector { border-right: none; border-left: 1px solid var(--panel-edge); }

/* Collapsed panels give their width to the board, which rescales to use it. */
.panel.collapsed {
  flex-basis: 0;
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-width: 0;
  overflow: hidden;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--text-dim);
  font-weight: 600;
}

/* The board never scrolls. The canvas is scaled to fit whatever space is left
   after the panels, so the whole battlefield is always visible. */
#board {
  position: relative;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, #0b1017 0%, var(--void) 70%);
}

canvas {
  display: block;
  image-rendering: auto;
  box-shadow: 0 0 0 1px var(--panel-edge), 0 18px 50px rgba(0, 0, 0, 0.55);
}

/* ---------- shop ---------- */

.shop-item {
  display: block;
  width: 100%;
  text-align: left;
  background: #111820;
  border: 1px solid var(--panel-edge);
  border-left: 3px solid var(--cyan);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 8px 9px;
  margin-bottom: 7px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
.shop-item:hover { background: #17212b; }
.shop-item.armed { background: #16303c; border-color: var(--cyan); }
.shop-item.unaffordable { opacity: 0.45; }
.shop-item .row1 { display: flex; justify-content: space-between; font-weight: 700; }
.shop-item .cost { color: var(--amber); }
.shop-item .row2 { color: var(--text-dim); font-size: 10px; margin-top: 3px; }
.shop-item .blurb { color: var(--text-dim); font-size: 10px; margin-top: 5px; line-height: 1.4; }
.shop-item .key {
  display: inline-block;
  min-width: 14px;
  text-align: center;
  border: 1px solid var(--panel-edge);
  border-radius: 2px;
  margin-right: 6px;
  color: var(--text-dim);
}

.hint {
  margin-top: 12px;
  color: var(--text-dim);
  font-size: 10px;
  line-height: 1.7;
}
.hint b { color: var(--text); font-weight: 700; }
/* Keep each shortcut on one line so the list never breaks mid-item. */
.hint .keys { display: flex; flex-wrap: wrap; gap: 0 8px; margin-top: 6px; }
.hint .keys span { white-space: nowrap; }

/* ---------- inspector ---------- */

#inspector-body.empty { color: var(--text-dim); font-size: 11px; }

.insp-name { font-size: 14px; font-weight: 700; color: var(--cyan); }
.insp-sub { font-size: 10px; color: var(--text-dim); margin-bottom: 10px; }

.insp-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid #131b23;
  font-size: 11px;
}
.insp-row span:first-child { color: var(--text-dim); }

.meter { height: 7px; background: #0a1016; border: 1px solid var(--panel-edge); margin: 4px 0 10px; }
.meter > div { height: 100%; background: linear-gradient(90deg, #ff7a1a, #ffb340); width: 0; }

button {
  background: #131c24;
  border: 1px solid var(--panel-edge);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover { background: #1b2833; }
button.danger { border-color: #4a2028; color: #ffb0b8; }
button.danger:hover { background: #2a1219; }
button.active { background: #16303c; border-color: var(--cyan); color: var(--cyan); }

.btn-row { display: flex; gap: 6px; margin-top: 10px; }
.btn-row button { flex: 1 1 auto; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- reactor panel ---------- */

#reactor-panel {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--panel-edge);
}

/* ---------- inspector controls ---------- */

.insp-status {
  font-size: 10px;
  letter-spacing: 1.5px;
  font-weight: 700;
  padding: 4px 6px;
  margin-bottom: 8px;
  border: 1px solid var(--panel-edge);
  text-align: center;
}
.insp-status.good { color: var(--cyan); border-color: #16414f; }
.insp-status.hot { color: #ff9a4d; border-color: #4d3216; background: rgba(255, 122, 26, 0.08); }
.insp-status.warn { color: var(--amber); border-color: #4d3a16; background: rgba(255, 179, 64, 0.08); }
.insp-status.bad { color: var(--danger); border-color: #4a2028; background: rgba(255, 77, 94, 0.08); }

.insp-label {
  display: block;
  font-size: 9px;
  letter-spacing: 1.4px;
  color: var(--text-dim);
  margin: 12px 0 4px;
}
.insp-label .dim { letter-spacing: 0; text-transform: none; opacity: 0.7; }

.pri-row { display: flex; gap: 4px; }
.pri-row button { flex: 1 1 0; padding: 5px 0; }

#inspector select {
  width: 100%;
  background: #131c24;
  border: 1px solid var(--panel-edge);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  padding: 5px;
}

.oc-note {
  font-size: 9.5px;
  color: var(--text-dim);
  margin-top: 5px;
  line-height: 1.5;
}

button.upgrade {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 6px;
  padding: 7px 8px;
  border-left: 3px solid var(--amber);
}
button.upgrade .row1 { display: flex; justify-content: space-between; font-weight: 700; }
button.upgrade .cost { color: var(--amber); }
button.upgrade .blurb {
  display: block;
  color: var(--text-dim);
  font-size: 10px;
  margin-top: 4px;
  line-height: 1.4;
  font-weight: 400;
}

/* ---------- toast ---------- */

#toast {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 8, 11, 0.92);
  border: 1px solid #4a2028;
  color: #ffb0b8;
  padding: 6px 12px;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms;
}
#toast.show { opacity: 1; }

/* ---------- responsive chrome ---------- */

/* The board gets whatever the panels do not use, so on smaller windows the
   panels give ground rather than squeezing the battlefield. */
@media (max-width: 1500px) {
  .panel { width: 200px; flex-basis: 200px; }
  #topbar { gap: 16px; }
}

@media (max-width: 1280px) {
  .panel { width: 178px; flex-basis: 178px; padding: 10px; }
  #topbar { gap: 12px; padding: 0 10px; }
  .brand { font-size: 12px; letter-spacing: 1px; }
  .shop-item .blurb { display: none; }
  .hint { display: none; }
}

@media (max-width: 1080px) {
  /* Below this the panels cost more than they are worth; the top-bar toggles
     bring them back on demand. */
  .panel { width: 164px; flex-basis: 164px; }
  .brand { display: none; }
  .panel-toggles button { padding: 5px 6px; }
}

/* ---------- phase widget ---------- */

#phase { display: flex; flex-direction: column; gap: 3px; min-width: 150px; flex: 0 1 auto; }
#phase label {
  font-size: 9px;
  letter-spacing: 1.4px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.phase-row { display: flex; align-items: center; gap: 8px; }
.phase-row .value { font-size: 14px; font-weight: 700; color: var(--cyan); }
#btn-skip { padding: 3px 8px; font-size: 10px; white-space: nowrap; }

/* ---------- wave banner ---------- */

#banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translate(-50%, -8px);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 260ms, transform 260ms;
}
#banner.show { opacity: 1; transform: translate(-50%, 0); }
.banner-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 8px;
  color: var(--cyan);
  text-shadow: 0 0 26px rgba(57, 216, 255, 0.5);
}
.banner-sub {
  font-size: 14px;
  letter-spacing: 4px;
  color: var(--amber);
  margin-top: 2px;
}
.banner-note {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 10px;
  letter-spacing: 0.5px;
}

/* ---------- loadout ---------- */

#loadout { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--panel-edge); }
#loadout:empty { border: none; padding: 0; margin: 0; }
.loadout-item {
  font-size: 10.5px;
  color: var(--amber);
  padding: 3px 0 3px 8px;
  border-left: 2px solid var(--amber);
  margin-bottom: 3px;
  cursor: help;
}

/* ---------- draft ---------- */

#draft {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(4, 6, 9, 0.85);
  z-index: 6;
}
#draft.show { display: grid; }
.draft-card {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-top: 3px solid var(--amber);
  padding: 22px 24px;
  max-width: 720px;
}
.draft-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 5px;
  color: var(--amber);
}
.draft-sub { font-size: 11px; color: var(--text-dim); margin: 4px 0 16px; }
.draft-options { display: flex; gap: 12px; }
.draft-option {
  flex: 1 1 0;
  display: block;
  text-align: left;
  padding: 14px;
  border-left: 3px solid var(--cyan);
  min-width: 0;
}
.draft-option:hover { background: #16303c; border-color: var(--cyan); }
.bp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.draft-option .key { margin: 0; flex: 0 0 auto; }
.bp-name { font-weight: 700; font-size: 13px; color: var(--cyan); }
.bp-blurb {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
  line-height: 1.55;
}

/* ---------- meta menu ---------- */

#meta {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(4, 6, 9, 0.88);
  z-index: 7;
  overflow-y: auto;
  padding: 20px;
}
#meta.show { display: grid; }
.meta-card {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-top: 3px solid var(--cyan);
  padding: 22px 24px;
  width: min(760px, 100%);
}
.meta-head { display: flex; justify-content: space-between; align-items: flex-start; }
.meta-title { font-size: 16px; font-weight: 700; letter-spacing: 5px; color: var(--cyan); }
.meta-sub { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.meta-rp { text-align: right; }
.meta-rp label { display: block; font-size: 9px; letter-spacing: 1.4px; color: var(--text-dim); }
.meta-rp span { font-size: 20px; font-weight: 700; color: var(--amber); }
.meta-stats {
  font-size: 10.5px;
  color: var(--text-dim);
  margin: 12px 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--panel-edge);
}

.unlock-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
button.unlock {
  display: block;
  text-align: left;
  padding: 10px 11px;
  border-left: 3px solid var(--cyan);
}
button.unlock.maxed { border-left-color: var(--amber); opacity: 0.75; }
button.unlock .row1 { display: flex; justify-content: space-between; font-weight: 700; font-size: 12px; }
button.unlock .cost { color: var(--amber); }
button.unlock .blurb {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 6px;
  line-height: 1.45;
  font-weight: 400;
}
.pips { display: flex; gap: 3px; margin-top: 7px; }
.pips i { width: 14px; height: 4px; background: #1c2733; display: block; }
.pips i.on { background: var(--cyan); }

.insp-row.research span:last-child { color: var(--amber); font-weight: 700; }

/* ---------- end card ---------- */

#gameover {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(4, 6, 9, 0.82);
  z-index: 5;
}
#gameover.show { display: grid; }
.end-card {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-top: 3px solid var(--danger);
  padding: 26px 30px;
  min-width: 320px;
  max-width: 460px;
}
.end-card.won { border-top-color: var(--cyan); }
.end-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 5px;
  color: var(--danger);
}
.end-card.won .end-title { color: var(--cyan); }
.end-sub { font-size: 11px; color: var(--text-dim); margin: 4px 0 16px; }
.end-slot { margin-top: 18px; }
