:root {
  color-scheme: dark;
  --bg: #05070c;
  --panel: rgba(11, 16, 27, 0.94);
  --line: #202a3d;
  --text: #d8e4f2;
  --muted: #71839b;
  --cyan: #30e7ff;
  --magenta: #ff3ad4;
  --red: #ff4e68;
  --green: #69ff9f;
  --orange: #ffad42;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at 50% -20%, #14213a 0%, var(--bg) 46%); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .18; background: repeating-linear-gradient(0deg, transparent 0 3px, #9fe8ff0b 3px 4px); }
button { font: inherit; color: inherit; }
.app-shell { min-height: 100vh; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.topbar { border: 1px solid var(--line); background: var(--panel); padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 10px 40px #0008; }
.eyebrow { color: var(--cyan); font-size: 10px; letter-spacing: .22em; font-weight: 800; }
.eyebrow.danger { color: var(--red); }
h1 { margin: 1px 0 0; font-size: 22px; letter-spacing: .16em; }
.hud { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.hud div { border-left: 2px solid var(--cyan); min-width: 80px; padding: 3px 10px; background: #ffffff05; }
.hud span, .readout span { display: block; color: var(--muted); font-size: 9px; letter-spacing: .13em; }
.hud strong { font-size: 16px; }
.workspace { display: grid; grid-template-columns: 210px minmax(600px, 1fr) 225px; gap: 12px; min-height: 0; flex: 1; }
.panel { border: 1px solid var(--line); background: var(--panel); padding: 12px; overflow: auto; }
.panel h2 { font-size: 12px; letter-spacing: .16em; color: var(--cyan); margin: 2px 0 12px; }
.panel h3 { font-size: 10px; letter-spacing: .14em; color: var(--muted); margin: 18px 0 8px; }
.guide p { margin: 6px 0; color: #9fb0c4; font-size: 10px; line-height: 1.4; display: flex; justify-content: space-between; gap: 8px; }
.guide p b { color: var(--text); font-weight: 600; white-space: nowrap; }
.guide p span { color: var(--muted); text-align: right; }
.tech-list { list-style: none; margin: 0; padding: 0; }
.tech-list li { border-bottom: 1px solid var(--line); padding: 6px 2px; font-size: 10px; color: #9fb0c4; }
.tech-list li b { display: block; font-size: 10px; letter-spacing: .04em; }
.tech-list li small { color: var(--muted); font-size: 9px; }
.tech-list li.locked { color: #4d5c72; }
.tech-list li.locked b { color: #4d5c72; }
.context-menu { position: absolute; z-index: 6; min-width: 180px; background: #070c14f7; border: 1px solid var(--cyan); box-shadow: 0 12px 32px #000c; }
.context-menu.hidden { display: none; }
.context-menu button { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; border: none; border-bottom: 1px solid var(--line); background: transparent; padding: 10px 12px; font-size: 11px; text-align: left; }
.context-menu button:last-child { border-bottom: none; }
.context-menu button:hover { background: #30e7ff14; border-color: transparent; }
.context-menu button .cost { color: var(--orange); font-size: 10px; white-space: nowrap; }
.context-menu button.locked { color: #55647a; cursor: not-allowed; }
.context-menu button.locked .cost { color: #55647a; }
.panel-section { margin-top: 14px; display: grid; gap: 7px; }
button { border: 1px solid #35435b; background: #111827; padding: 8px 10px; cursor: pointer; font-size: 11px; }
button:hover { border-color: var(--cyan); }
button.primary { background: linear-gradient(90deg, #0b8395, #1f4d7b); border-color: var(--cyan); font-weight: 800; letter-spacing: .06em; }
button:disabled { opacity: .4; cursor: not-allowed; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.legend p, .tips p { margin: 7px 0; color: #9fb0c4; font-size: 10px; line-height: 1.45; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; box-shadow: 0 0 8px currentColor; }
.cyan { color: var(--cyan); background: var(--cyan); }.magenta { color: var(--magenta); background: var(--magenta); }.red { color: var(--red); background: var(--red); }.green { color: var(--green); background: var(--green); }
.game-frame { position: relative; min-width: 0; min-height: 560px; border: 1px solid #30415e; background: #020308; overflow: hidden; box-shadow: 0 0 40px #0ac8ff13; }
canvas { width: 100%; height: 100%; min-height: 560px; display: block; cursor: crosshair; image-rendering: pixelated; touch-action: none; user-select: none; }
.toast { position: absolute; left: 50%; bottom: 18px; translate: -50% 15px; opacity: 0; transition: .18s; background: #080d16e8; border: 1px solid var(--cyan); color: var(--text); padding: 8px 14px; font-size: 11px; pointer-events: none; }
.toast.show { opacity: 1; translate: -50% 0; }
.toast.error { border-color: var(--red); }
.cell-tooltip {
  position: absolute;
  left: 12px;
  top: 12px;
  max-width: min(360px, 70%);
  padding: 8px 10px;
  border: 1px solid #3a4d6a;
  background: #070c14f0;
  color: #d5e2f2;
  font-size: 11px;
  letter-spacing: .04em;
  pointer-events: none;
  z-index: 3;
  box-shadow: 0 8px 24px #0008;
  white-space: pre-line;
}
.cell-tooltip.hidden { display: none; }
.cell-tooltip.off { border-color: var(--red); color: #ffc4cd; }
.hud .power-ok { border-left-color: var(--cyan); }
.hud .power-warn { border-left-color: var(--orange); }
.hud .power-bad { border-left-color: var(--red); }
.readout { border-bottom: 1px solid var(--line); padding: 7px 3px; display: flex; align-items: center; justify-content: space-between; }
.readout span { max-width: 110px; }
.readout strong { color: var(--cyan); font-size: 12px; }
.event-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.event-log li { border-left: 2px solid #34445f; padding-left: 8px; color: #91a3b9; font-size: 9px; line-height: 1.35; }
.event-log li.hot { border-color: var(--red); color: #ffc0ca; }
.event-log li.good { border-color: var(--green); color: #a8ffc3; }
.modal { position: absolute; inset: 0; display: grid; place-items: center; background: #03050bd9; backdrop-filter: blur(5px); padding: 20px; }
.modal.hidden { display: none; }
.modal-card { width: min(780px, 95%); border: 1px solid var(--cyan); background: #0a101de8; padding: 24px; box-shadow: 0 0 60px #19d5ff25; }
.modal-card.compact { width: min(430px, 95%); text-align: center; }
.modal-card h2 { margin: 5px 0; }
.modal-card p { color: #90a2b8; font-size: 12px; }
.upgrade-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.upgrade { text-align: left; min-height: 140px; padding: 14px; border-color: #34445f; background: linear-gradient(160deg, #111a2a, #080d16); }
.upgrade:hover { border-color: var(--magenta); translate: 0 -2px; }
.upgrade b { display: block; color: var(--magenta); margin-bottom: 8px; }
.upgrade span { display: block; color: #aab8c9; font-size: 11px; line-height: 1.5; }
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 175px minmax(500px, 1fr); }
  .intel-panel { display: none; }
}
@media (max-width: 760px) {
  .app-shell { padding: 6px; }
  .topbar { align-items: flex-start; gap: 8px; }
  .hud div { min-width: 58px; padding: 2px 5px; }
  .workspace { display: block; }
  .tools-panel { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
  .tools-panel h2, .legend, .tech-list { display: none; }
  .guide { width: 100%; }
  .panel-section { display: flex; margin: 0; }
  .game-frame, canvas { min-height: 480px; }
  .upgrade-grid { grid-template-columns: 1fr; }
}
