:root {
  --paper: #efece3;
  --panel: #f7f5ee;
  --ink: #16150f;
  --muted: #7b776a;
  --line: #16150f;
  --soft: #d6d1c2;
  --hot: #e2401c;
  --water: #1c6fe2;
  --term: #12120f;
  --term-ink: #ece7d6;
  --hover: #fff;
  --sky: #e3ecee;
  --mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 13px/1.45 var(--mono);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

/* ---------- layout ---------- */
main {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  gap: 20px;
  padding: 18px 20px 12px;
}
.col { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }
.side { overflow-y: auto; scrollbar-width: thin; padding: 0 4px 6px 0; }
.stage { gap: 12px; }
h2, .brand, .label { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; margin: 0; font-weight: 700; }
.brand small { display: block; font-weight: 400; letter-spacing: 0.04em; text-transform: none; color: var(--muted); margin-top: 2px; }
.classline { font-size: 11px; color: var(--muted); margin-top: 4px; }
.classline b { color: var(--ink); }
.label small { font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--muted); margin-left: 6px; }
.panel { border: 1px solid var(--line); background: var(--panel); padding: 12px; }

/* ---------- score + wallet ---------- */
.big { font-size: 46px; font-weight: 700; line-height: 1.05; letter-spacing: -0.04em; }
.sub { color: var(--muted); font-size: 11px; }
.cash { font-size: 26px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.warn { color: var(--hot); font-weight: 700; font-size: 11px; }
.selfline { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); margin-top: -4px; }
.spin { width: 9px; height: 9px; border: 2px solid var(--hot); border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.meter { display: block; height: 6px; border: 1px solid var(--line); background: var(--panel); }
.meter i { display: block; height: 100%; width: 0; background: var(--ink); transition: width 0.15s linear; }
.meter.water i { background: var(--water); }
.meter.bad i { background: var(--hot); }
.meter.ok i { background: #2f9e5b; }

/* ---------- buttons ---------- */
button {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); padding: 6px 10px; cursor: pointer;
  box-shadow: 2px 2px 0 var(--line); transition: transform 0.04s, box-shadow 0.04s, background 0.1s;
}
button:hover:not(:disabled) { background: var(--hover); }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
button:disabled { color: var(--muted); border-color: var(--soft); box-shadow: 2px 2px 0 var(--soft); cursor: default; }
button:focus-visible { outline: 2px solid var(--hot); outline-offset: 2px; }
button.link { border: 0; box-shadow: none; background: none; padding: 0; text-decoration: underline; color: var(--muted); }
.btns { display: flex; gap: 8px; }
.btns button { flex: 1; white-space: nowrap; }

#feed {
  position: relative; padding: 18px 12px; background: var(--ink); color: var(--paper);
  box-shadow: 4px 4px 0 var(--hot); display: flex; flex-direction: column; align-items: center; gap: 2px;
  user-select: none; -webkit-user-select: none; margin-right: 4px; flex: none;
}
#feed:hover:not(:disabled) { background: var(--ink); filter: brightness(1.2); }
#feed:active:not(:disabled) { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--hot); }
.feed-title { font-size: 19px; font-weight: 700; letter-spacing: 0.14em; }
.feed-sub { font-size: 11px; opacity: 0.75; }
.pop { position: absolute; top: -6px; pointer-events: none; color: var(--hot); font-weight: 700; white-space: nowrap; transform: translateX(-50%); animation: pop 0.8s ease-out forwards; }
.pop.auto { font-weight: 400; font-size: 11px; opacity: 0.8; }
@keyframes pop { to { transform: translate(-50%, -34px); opacity: 0; } }

/* ---------- hardware ---------- */
.row + .row { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--soft); }
.rowhead { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.rowhead > span { color: var(--muted); }
.auto { margin-left: auto; display: flex; align-items: center; gap: 4px; cursor: pointer; color: var(--muted); font-size: 11px; }
.auto input { accent-color: var(--ink); margin: 0; }
.hint { color: var(--muted); font-size: 11px; margin: 6px 0 8px; }

/* ---------- the world ---------- */
.viewport {
  position: relative; flex: 1; min-height: 320px; border: 1px solid var(--line);
  background: var(--sky); overflow: hidden; box-shadow: 4px 4px 0 var(--soft);
}
.viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.viewport.no3d canvas { display: none; }
.vp-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px; pointer-events: none; }
.vp-name { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; text-transform: uppercase; line-height: 1.1; }
.dots { display: flex; gap: 4px; margin-top: 8px; }
.dots i { width: 9px; height: 9px; border: 1px solid var(--line); background: transparent; }
.dots i.done { background: var(--ink); }
.dots i.here { background: var(--hot); border-color: var(--hot); }
.vp-planet { text-align: right; font-size: 11px; color: var(--muted); }
.vp-planet b { display: block; color: var(--ink); font-size: 14px; }

/* The AI's panel, styled like an agent's "thinking" trace: finished steps, one live step, then what it says. */
.speech {
  position: absolute; left: 16px; bottom: 16px; width: min(440px, calc(100% - 32px));
  background: #17171a; color: #e9e9ec; padding: 10px 14px 10px; border-radius: 12px;
  border: 1px solid #2e2e33; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif; font-size: 13px;
}
.trace-head { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #9a9aa3; margin-bottom: 6px; }
.chev { font-size: 9px; }
.steps { color: #6c6c75; }
.need { margin-left: auto; font-size: 11px; font-weight: 600; color: #17171a; background: var(--hot); border-radius: 999px; padding: 1px 8px; }
.need:empty { display: none; }
.trace, .thinking { border-left: 1px solid #34343a; margin-left: 4px; padding-left: 12px; }
.step { display: flex; align-items: baseline; gap: 8px; color: #7d7d86; font-size: 12px; padding: 2px 0; }
.step::before { content: "✓"; color: #5c5c64; font-size: 10px; margin-left: -17px; background: #17171a; width: 10px; text-align: center; flex: none; }
.step span:first-child { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step .secs { color: #5c5c64; font-variant-numeric: tabular-nums; }
.thinking { display: flex; align-items: center; gap: 8px; padding-top: 3px; padding-bottom: 3px; }
.spinner { width: 10px; height: 10px; margin-left: -17px; border-radius: 50%; border: 1.5px solid #6c6c75; border-top-color: #fff; background: #17171a; animation: spin 0.7s linear infinite; flex: none; box-sizing: border-box; }
.shimmer {
  background: linear-gradient(90deg, #8d8d96 0%, #8d8d96 35%, #ffffff 50%, #8d8d96 65%, #8d8d96 100%);
  background-size: 220% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.8s linear infinite; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@keyframes shimmer { from { background-position: 110% 0; } to { background-position: -110% 0; } }
.speech-text { min-height: 36px; margin-top: 8px; padding-top: 8px; border-top: 1px solid #2e2e33; font-size: 13.5px; line-height: 1.4; }
.speech.news .speech-text { color: #e8be55; }
.iq { font-size: 11px; color: #6c6c75; margin-top: 4px; }

/* ---------- news ticker ---------- */
.ticker { display: flex; align-items: stretch; border: 1px solid var(--line); background: var(--term); color: var(--term-ink); flex: none; margin-right: 4px; overflow: hidden; }
.tick-live { background: var(--hot); color: #fff; font-weight: 700; letter-spacing: 0.14em; font-size: 11px; padding: 6px 10px; display: flex; align-items: center; gap: 6px; flex: none; }
.tick-live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: throb 1s ease-in-out infinite; }
@keyframes throb { 50% { opacity: 0.35; } }
.tick-clip { flex: 1; overflow: hidden; min-width: 0; }
.tick-track { display: inline-flex; white-space: nowrap; padding: 6px 0; animation: tick 60s linear infinite; will-change: transform; }
@keyframes tick { to { transform: translateX(-50%); } }
.tick-track span { padding: 0 18px; font-size: 12px; }
.tick-track .mkt { color: #e8be55; font-weight: 700; }
.tick-track .brk { color: var(--hot); font-weight: 700; padding-right: 0; }

/* ---------- next territory ---------- */
.expand {
  display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 18px; align-items: center;
  text-align: left; padding: 12px 16px; flex: none; margin: 0 4px 4px 0;
}
.expand:not(:disabled) { background: var(--hot); color: #fff; border-color: var(--line); box-shadow: 4px 4px 0 var(--line); animation: ready 1s ease-in-out infinite; }
.expand:not(:disabled):hover { background: var(--hot); filter: brightness(1.1); }
@keyframes ready { 50% { transform: translateY(-2px); } }
.ex-main, .ex-reqs { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ex-reqs { gap: 8px; }
.ex-kicker { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; }
.ex-title { font-weight: 700; font-size: 16px; color: var(--ink); }
.expand:not(:disabled) .ex-title { color: #fff; }
.ex-desc { font-size: 11px; }
.req { display: flex; flex-direction: column; gap: 3px; }
.req-label { display: flex; justify-content: space-between; font-size: 11px; gap: 8px; }
.req-label b { color: var(--ink); }
.expand:not(:disabled) .req-label b { color: #fff; }

/* ---------- research ---------- */
#projects { display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.proj { text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 9px 11px; }
.proj b { grid-column: 1; }
.proj .cost { grid-column: 2; grid-row: 1; white-space: nowrap; font-weight: 700; }
.proj .fx { grid-column: 1 / -1; font-size: 11px; color: var(--hot); }
.proj em { grid-column: 1 / -1; font-size: 11px; font-style: normal; color: var(--muted); }
.proj:disabled .fx, .proj:disabled .cost { color: var(--muted); font-weight: 400; }
.proj.final:not(:disabled) { background: var(--hot); color: #fff; }
.proj.final:not(:disabled) em, .proj.final:not(:disabled) .fx { color: #fff; }
.empty { color: var(--muted); font-size: 11px; border: 1px dashed var(--soft); padding: 12px; }

/* ---------- footer ---------- */
footer { display: flex; gap: 14px; padding: 8px 20px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); align-items: center; flex: none; }
footer a { color: var(--hot); }
.spacer { flex: 1; }

/* ---------- territory takeover: flashes, then lets you watch the camera pull back ---------- */
.takeover {
  position: absolute; inset: 0; z-index: 3; cursor: pointer; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 8px;
  text-align: center; padding: 84px 24px 24px; animation: tk-out 4.6s ease both; pointer-events: none;
}
@keyframes tk-out { 0%, 85% { opacity: 1; } 100% { opacity: 0; } }
.tk-small { letter-spacing: 0.4em; text-transform: uppercase; font-size: 12px; background: var(--ink); color: var(--paper); padding: 3px 10px; }
.tk-name { font-size: clamp(26px, 4.2vw, 60px); font-weight: 700; line-height: 0.95; letter-spacing: -0.04em;
  text-transform: uppercase; background: var(--hot); padding: 6px 18px; animation: slam 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) 0.15s both; }
@keyframes slam { from { transform: scale(3); opacity: 0; } }
.tk-mult { font-size: clamp(18px, 2.4vw, 32px); font-weight: 700; background: #fff; color: var(--hot); padding: 2px 14px;
  animation: slam 0.4s cubic-bezier(0.2, 1.6, 0.4, 1) 0.9s both; }
.tk-nums { font-size: 15px; background: var(--ink); color: var(--paper); padding: 3px 10px; animation: rise 0.4s ease 1.2s both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
body.quake main { animation: quake 0.6s linear; }
@keyframes quake {
  10% { transform: translate(-6px, 3px); } 25% { transform: translate(7px, -4px); } 40% { transform: translate(-5px, -3px); }
  55% { transform: translate(4px, 5px); } 70% { transform: translate(-3px, 2px); } 85% { transform: translate(2px, -1px); }
}

/* ---------- art style experiments ---------- */
[data-theme="terminal"] {
  --paper: #0b0d0a; --panel: #11140e; --ink: #b9f5a0; --muted: #62845a; --line: #3d6a33; --soft: #1f2d1b;
  --hot: #ffb000; --water: #4ad2ff; --term: #050604; --term-ink: #b9f5a0; --hover: #1a2215; --sky: #0e130c;
}
[data-theme="blueprint"] {
  --paper: #10386b; --panel: #15437e; --ink: #edf4ff; --muted: #9fbbe0; --line: #edf4ff; --soft: #2d5c99;
  --hot: #ffd23f; --water: #7fe0ff; --term: #0a2547; --term-ink: #edf4ff; --hover: #1c529a; --sky: #1a4d8c;
}
[data-theme="blueprint"] .expand:not(:disabled), [data-theme="terminal"] .expand:not(:disabled),
[data-theme="blueprint"] .expand:not(:disabled) *, [data-theme="terminal"] .expand:not(:disabled) *,
[data-theme="blueprint"] .takeover, [data-theme="terminal"] .takeover { color: #111; }
[data-theme="blueprint"] .tk-mult, [data-theme="terminal"] .tk-mult { background: #111; color: var(--hot); }

/* ---------- ending ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 10, 8, 0.94); display: grid; place-items: center; padding: 24px; z-index: 10; }
.ending-box { max-width: 620px; width: 100%; color: #ece7d6; font-size: 16px; }
.ending-box p { margin: 0 0 14px; animation: rise 0.6s ease both; }
.ending-box p:first-child { color: #e2401c; font-weight: 700; letter-spacing: 0.1em; font-size: 22px; }
.ending-stats { color: #8a8676; font-size: 12px; margin: 22px 0; }
.ending-box button { background: #12120f; color: #ece7d6; border-color: #ece7d6; box-shadow: 2px 2px 0 #e2401c; }
.ending-box button:hover:not(:disabled) { background: #000; }

@media (max-width: 1080px) {
  html, body { height: auto; }
  main { grid-template-columns: 1fr; }
  .stage { order: -1; }
  .viewport { min-height: 380px; }
  .side { overflow: visible; }
  .expand { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
