:root {
  --ink: #15191e;
  --panel: rgba(16, 20, 26, 0.82);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #eef2f5;
  --muted: #a9b4be;
  --accent: #f0b63a;
  --danger: #ff5a4f;
  --ok: #5ed26a;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--text); user-select: none; }
canvas#scene, canvas#overlay, canvas#strategic { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#overlay { pointer-events: none; z-index: 1; }
canvas#strategic { z-index: 2; cursor: crosshair; }
[hidden] { display: none !important; }

.screen {
  position: fixed; inset: 0; display: grid; place-items: safe center; z-index: 10;
  overflow-y: auto; padding: 16px 0; /* short windows: the card scrolls instead of being cut off */
  background: radial-gradient(ellipse at 30% 20%, rgba(90, 70, 30, 0.35), rgba(0, 0, 0, 0.92)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 40px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 40px), #07090b;
}
.card {
  width: min(440px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
  padding: 28px 28px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.card h1 { margin: 0 0 6px; font-size: 34px; letter-spacing: 3px; text-transform: uppercase; color: var(--accent); }
.card h2 { margin: 0 0 8px; }
.tag { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.fine { color: var(--muted); font-size: 12px; margin: 12px 0 0; }
.tag.economy { font-size: 12.5px; margin-top: -10px; }
.gold { color: #ffd66a; }
label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 6px; }
input {
  width: 100%; padding: 12px 14px; font-size: 18px; border-radius: 8px; border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.07); color: var(--text); outline: none; user-select: text;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(240, 182, 58, 0.25); }
button {
  margin-top: 12px; width: 100%; padding: 12px; font-size: 16px; font-weight: 600; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--ink); cursor: pointer; font-family: inherit;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.error { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; font-size: 14px; }
.controls { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12.5px; }
kbd { display: inline-block; min-width: 18px; padding: 0 4px; margin-right: 2px; border-radius: 4px; border: 1px solid var(--panel-border); background: rgba(255, 255, 255, 0.1); color: var(--text); font: 11px ui-monospace, monospace; text-align: center; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 10px; pointer-events: auto; }

#topbar { position: absolute; top: 12px; left: 14px; display: flex; gap: 18px; align-items: center; padding: 8px 14px; font-size: 14px; }
#commander { font-weight: 700; padding-left: 16px; position: relative; }
#commander::before { content: ""; position: absolute; left: 0; top: 50%; width: 10px; height: 10px; margin-top: -5px; border-radius: 2px; background: var(--team, #888); }
.stat em { font-style: normal; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; margin-right: 4px; }
.stat b { font-variant-numeric: tabular-nums; }
#credits { color: #ffd66a; }
#power { color: #8fe38a; }
#power.deficit, #miners.deficit { color: var(--danger); animation: blink 1s steps(2) infinite; }
#mined { color: #ffd66a; }
@keyframes blink { 50% { opacity: 0.55; } }

#toasts { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; align-items: center; }
#toasts li { background: var(--panel); border: 1px solid var(--panel-border); border-left: 3px solid var(--ok); border-radius: 7px; padding: 6px 12px; font-size: 13.5px; animation: toast 5s forwards; }
#toasts li.error { border-left-color: var(--danger); color: #ffd2cd; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 6%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

#sidebar { position: absolute; top: 12px; right: 14px; width: 232px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100% - 24px); overflow-y: auto; scrollbar-width: thin; }
#sidebar > * { flex: none; }
#minimap { width: 232px; height: 232px; border-radius: 10px; border: 1px solid var(--panel-border); background: #07090c; pointer-events: auto; cursor: pointer; }
#build { padding: 10px; }
#build h3, .sel-title { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.build-item { margin-top: 6px; }
.build-item button { margin: 0; display: flex; align-items: center; gap: 8px; padding: 9px 10px; font-size: 14px; background: #2c333b; color: var(--text); text-align: left; border: 1px solid transparent; }
.build-item button:hover:not(:disabled) { background: #39424c; }
.build-item button.active { border-color: var(--accent); background: #423a22; }
.build-item button small { color: #ffd66a; font-weight: 600; margin-left: auto; }
.build-item button kbd { margin-left: 4px; }
.why { color: #ff9c92; font-size: 11.5px; margin: 3px 2px 0; min-height: 0; }
.icon { width: 16px; height: 16px; border-radius: 3px; display: inline-block; flex: none; }
.icon.pp { background: linear-gradient(180deg, #e8e3d6 0 55%, #ffd24a 55%); }
.icon.tf { background: linear-gradient(180deg, #8f9488 0 60%, #2a2d31 60%); }
.icon.rf { background: radial-gradient(circle at 70% 35%, #cfc8b6 0 32%, transparent 34%), linear-gradient(180deg, #a49d8c 0 62%, #f5c542 62%); }

#selection { padding: 10px; font-size: 13px; }
.sel-title { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; letter-spacing: 0.5px; }
.sel-title i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.sel-line { color: var(--muted); margin: 3px 0; }
.meter { position: relative; height: 16px; border-radius: 5px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin: 6px 0; }
.meter > div { position: absolute; inset: 0 auto 0 0; background: var(--ok); }
.meter.warn > div { background: #f2c230; }
.meter.bad > div { background: #f04a3a; }
.meter.prod > div { background: #58b8ff; }
.meter.cargo > div { background: #e8b52e; }
.unit.miner b { background: #8a7a4a; }
.meter span { position: absolute; inset: 0; font-size: 11px; line-height: 16px; text-align: center; color: #fff; text-shadow: 0 1px 2px #000; font-weight: 600; }
.meter.mini { height: 4px; margin: 2px 0 0; }
.units { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: 6px; }
.unit { background: rgba(255, 255, 255, 0.08); border-radius: 4px; padding: 4px 3px 3px; }
.unit b { display: block; height: 10px; margin: 0 3px; border-radius: 2px; background: #6b7580; }
.more { font-size: 11px; color: var(--muted); align-self: center; }
#selection button { margin-top: 8px; padding: 9px; font-size: 14px; }

#status { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); background: rgba(160, 60, 30, 0.9); padding: 6px 12px; border-radius: 8px; font-size: 13px; }
#debug {
  position: absolute; left: 14px; bottom: 14px; margin: 0; padding: 10px 12px; max-width: min(560px, calc(100vw - 280px));
  background: rgba(8, 10, 14, 0.85); border: 1px solid var(--panel-border); border-radius: 10px;
  font: 12px/1.45 ui-monospace, Consolas, monospace; color: #d7e3ee; white-space: pre-wrap;
}
/* centred in the space left of the sidebar (never under it) */
#hint { position: absolute; bottom: 12px; left: 14px; right: 260px; text-align: center; overflow: hidden; text-overflow: ellipsis; font-size: 12px; color: rgba(255, 255, 255, 0.7); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); white-space: nowrap; }

/* the connection status sits under the top bar; toasts make room for it */
#hud:has(#status:not([hidden])) #toasts { top: 96px; }
@media (max-height: 760px) {
  #minimap { width: 232px; height: 176px; }
  .build-item button { padding: 6px 10px; }
  #build { padding: 8px 10px; }
}
@media (max-width: 760px) {
  #sidebar { width: 170px; }
  #minimap { width: 170px; height: 170px; }
  #topbar { gap: 10px; font-size: 12px; }
  #hint { display: none; }
}
