* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d0f13;
  color: #dfe3ea;
  font: 13px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  user-select: none;
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.panel {
  position: absolute;
  background: rgba(16, 19, 24, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  padding: 10px 12px;
  backdrop-filter: blur(6px);
  min-width: 210px;
}

.panel.hidden { display: none; }

#resources { top: 12px; left: 12px; }
#hud       { top: 12px; right: 12px; }
#help      { bottom: 12px; left: 12px; opacity: 0.85; }
#build     { bottom: 12px; right: 12px; width: 240px; }

/* ---- minimap ---- */

#minimap-panel {
  top: 12px;
  left: 12px;
  min-width: 0;
  padding: 6px;
  line-height: 0;
}

/* Width and height are set in script: the canvas takes the map's aspect. */
#minimap {
  display: block;
  cursor: pointer;
  image-rendering: pixelated;
  border-radius: 4px;
}

/* The resource readout sits under the minimap; its top is set in script,
   since the minimap's height depends on the shape of the map. */
#resources { top: 224px; left: 12px; }

/* ---- skirmish setup ---- */

#setup {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* "safe" so a tall lobby scrolls from its top instead of having its first
     rows clipped above the viewport, which centring alone does. */
  justify-content: safe center;
  gap: 14px;
  padding: 24px;
  overflow: auto;
  background: radial-gradient(ellipse at 50% 30%, #1a2028, #0b0d11 70%);
}

#setup.hidden { display: none; }

#setup h1 {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.setup-sub { color: #8b93a3; margin-bottom: 8px; }

.setup-row { width: min(760px, 100%); }

.setup-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8b93a3;
  margin-bottom: 6px;
}

/* ---- lobby slot table ---- */

.slot-table {
  width: min(760px, 100%);
  /* Twenty rows would push the map and the start button off the screen, so the
     list scrolls. `flex: none` is what makes that safe: giving a flex child
     its own overflow sets min-height to 0, and the column then crushes it to
     nothing the moment the page is taller than the viewport — which is how the
     lobby ended up showing its header and no players at all. */
  flex: none;
  max-height: 44vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slot-row {
  display: grid;
  grid-template-columns: 28px 150px 130px 1fr;
  gap: 10px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.slot-row.head {
  background: none;
  border-color: transparent;
  padding-bottom: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8b93a3;
}

.slot-row.off { opacity: 0.45; }

.slot-index {
  font-size: 12px;
  color: #6f7788;
  text-align: center;
}

.seg { display: flex; gap: 4px; }

.seg-btn {
  flex: 1;
  padding: 5px 6px;
  font-size: 12px;
  white-space: nowrap;
}

.seg-btn.on { background: #35608f; border-color: #4a86c8; color: #fff; }
.seg-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.team-seg .seg-btn { flex: 0 0 28px; padding: 5px 0; text-align: center; }

.setup-warn {
  width: min(760px, 100%);
  min-height: 18px;
  font-size: 12px;
  color: #ffb454;
}

/* ---- lobby map ---- */

.map-picker {
  width: min(760px, 100%);
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 4px 0 2px;
}

.map-picker-canvas {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  image-rendering: pixelated;
  background: #0b0d11;
}

.map-picker-hint {
  font-size: 12px;
  color: #8b93a3;
  min-height: 16px;
  text-align: center;
}

.team-select,
.region-select {
  padding: 5px 6px;
  font: inherit;
  font-size: 12px;
  color: #cfd6e2;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  max-width: 100%;
}

.team-select:disabled,
.region-select:disabled { opacity: 0.4; }
.region-line { margin: -2px 0 4px 14px; opacity: 0.8; }

/* The room panel is narrow, so its copy of the map scales to fit rather than
   pushing the panel out to the map's natural width. */
#online-lobby .map-picker { width: 100%; }
#online-lobby .map-picker-canvas { width: 100%; }

.seed-row { display: flex; align-items: center; gap: 10px; }
.seed-row .setup-label { margin-bottom: 0; }

.small-btn { padding: 6px 12px; font-size: 12px; }

#start-btn:disabled {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  color: #6f7788;
  cursor: not-allowed;
}

.faction-btn {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
  text-align: left;
  padding: 12px;
  line-height: 1.35;
}

.faction-btn .fn { font-size: 16px; font-weight: 700; }
.faction-btn .fb { color: #b6bdc9; font-size: 12px; }
.faction-btn .fs { color: #7f8798; font-size: 11px; }
.faction-btn .fu { color: #8fd4a8; font-size: 11px; }

.faction-btn.on {
  background: rgba(74, 134, 200, 0.24);
  border-color: #4a86c8;
}

.seed-input {
  width: 180px;
  padding: 7px 9px;
  font: inherit;
  color: #cfd6e2;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
}

#start-btn {
  margin-top: 6px;
  padding: 11px 34px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #fff;
  background: #35608f;
  border-color: #4a86c8;
}

#start-btn:hover { background: #427099; }

/* ---- online ---- */

.online-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.online-row .setup-label { margin-bottom: 0; }
.code-input { width: 190px; text-transform: uppercase; }
.online-status { font-size: 12px; color: #8fd4a8; }

#online-lobby {
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 11;
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
}

#online-lobby.hidden { display: none; }
#online-lobby .small-btn { margin-top: 4px; width: 100%; }

/* ---- online room table ---- */

.room-table {
  /* Twenty slots must not push the map and the start button off the panel. */
  max-height: 34vh;
  overflow-y: auto;
  margin: 4px 0;
}

.room-row {
  display: grid;
  grid-template-columns: 1fr 96px 128px 64px;
  gap: 6px;
  align-items: center;
  padding: 3px 0;
}

.room-row.off { opacity: 0.5; }
.room-who { font-size: 13px; }
#online-lobby .room-toggle { margin-top: 0; font-size: 11px; padding: 4px 6px; }
#online-lobby .room-toggle:disabled { visibility: hidden; }

/* Transient one-liners: why an order did nothing. Sits above the build panel
   so it never covers the thing the player just clicked. */
#toast {
  position: absolute;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  color: #f2f5f9;
  background: rgba(20, 24, 30, 0.92);
  border: 1px solid rgba(255, 214, 140, 0.5);
  pointer-events: none;
}

#toast.hidden { display: none; }

#netstatus {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  padding: 6px 14px;
  border-radius: 6px;
  background: rgba(16, 19, 24, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 13px;
  color: #ffb454;
}

#netstatus.hidden { display: none; }
#netstatus.bad { color: #ff7a6d; border-color: #a33; }

/* ---- match result ---- */

#result {
  position: absolute;
  top: 32%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

#result.hidden { display: none; }

#result-title {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.8);
}

#result-title.win { color: #6fe08a; }
#result-title.lose { color: #ff7a6d; }

#result-sub {
  margin-top: 6px;
  font-size: 14px;
  color: #c3cad6;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9);
}

.row, .res {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 1px 0;
}

.row span, .res span { color: #8b93a3; }
.row b, .res b { font-weight: 600; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

.res b { font-size: 15px; }
.res b.warn { color: #ffb454; }

.buttons { display: flex; gap: 6px; margin-top: 8px; }

button {
  padding: 5px 8px;
  font: inherit;
  font-size: 12px;
  color: #cfd6e2;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  cursor: pointer;
}

.buttons button { flex: 1; }
button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
button.on { background: #35608f; border-color: #4a86c8; color: #fff; }

/* ---- build / production panel ---- */

.panel-title {
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8b93a3;
  margin-bottom: 8px;
}

.panel-hint {
  margin-top: 8px;
  font-size: 11px;
  color: #6f7788;
  line-height: 1.35;
}

.build-grid { display: grid; gap: 5px; }

.build-btn {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  padding: 7px 9px;
  overflow: hidden;
}

.build-btn .bi { display: block; width: 22px; height: 22px; }
.build-btn .bn { font-weight: 600; }
.build-btn .bc { color: #8fd4a8; font-size: 11px; }
.build-btn .bt { color: #7a8294; font-size: 11px; }

.build-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.build-btn.active { border-color: #4a86c8; background: rgba(74, 134, 200, 0.22); }

/* Fills left to right as the item at the head of the queue completes. */
.build-btn .bfill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: rgba(90, 190, 255, 0.18);
  pointer-events: none;
  transition: width 120ms linear;
}

/*
 * Fixed height, not auto. The panel is anchored to the bottom of the screen,
 * so any growth pushes its contents UPWARD — and a player queueing five units
 * clicks the same button five times in a row. With an auto-sized queue the
 * first chip shifts the button out from under the second click.
 */
.queue {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  margin-top: 8px;
  height: 74px;
  overflow: hidden;
}

.queue-chip {
  padding: 3px 7px;
  font-size: 11px;
  border-radius: 4px;
}

.queue-chip:hover { border-color: #e2574c; color: #ffb0a8; }
