:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c2330;
  --line: #2d3646;
  --text: #d7dee8;
  --dim: #8b96a5;
  --accent: #58a6ff;
  --good: #43d17a;
  --warn: #e3b341;
  --bad: #f85149;
  --read: #4ea3ff;
  --write: #ff9d3c;
  --lookup: #43d17a;
  --analytics: #b48cff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "SF Mono", "Cascadia Code", Consolas, Menlo, monospace;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
#title { font-size: 17px; font-weight: 700; letter-spacing: 2px; color: var(--bad); }
#subtitle { font-size: 10px; color: var(--dim); }
.stat { text-align: right; }
.stat-label { font-size: 9px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
.stat-value { font-size: 15px; font-variant-numeric: tabular-nums; }
.stat.big .stat-value { font-size: 22px; color: var(--accent); font-weight: 700; }
#controls { margin-left: auto; display: flex; gap: 6px; align-items: center; }
button {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 10px;
  font: inherit;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.sel { background: var(--accent); color: #08131f; border-color: var(--accent); }
#btn-insights { color: var(--warn); }

/* ---------- workload mix bar ---------- */
#mixbar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 4px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  font-size: 10px;
}
#mix-profile {
  color: var(--warn);
  white-space: nowrap;
  display: flex;
  align-items: center;
  letter-spacing: 1px;
  cursor: help;
}
#mix-segments {
  flex: 1 1 auto;
  display: flex;
  border-radius: 4px;
  overflow: hidden;
  min-width: 0;
}
.mix-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
  height: 18px;
  color: var(--text);
  cursor: help;
  transition: width .4s ease;
  border-right: 1px solid var(--bg);
}
.mix-seg:last-child { border-right: none; }

/* ---------- main area ---------- */
#main { display: flex; flex: 1 1 auto; min-height: 0; }
#stage { position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden; }
/* absolute so the canvas bitmap size can never feed back into flex layout
   (that feedback only ratchets up — the window-gobbling bug) */
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#legend {
  position: absolute;
  left: 12px;
  bottom: 8px;
  color: var(--dim);
  font-size: 11px;
  display: flex;
  gap: 14px;
  pointer-events: none;
}
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

#winbar {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 380px; height: 26px;
  background: var(--panel2);
  border: 1px solid var(--good);
  border-radius: 5px;
  overflow: hidden;
  z-index: 5;
}
#winbar-fill { height: 100%; width: 0; background: rgba(67, 209, 122, .35); }
#winbar-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--good); font-size: 12px; letter-spacing: 1px;
}

/* ---------- toasts ---------- */
#toasts {
  position: absolute;
  top: 44px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px;
  z-index: 5; pointer-events: none;
}
.toast {
  background: var(--panel2);
  border: 1px solid var(--warn);
  border-radius: 6px;
  padding: 8px 14px;
  min-width: 320px;
  box-shadow: 0 4px 18px rgba(0,0,0,.5);
  animation: toast-in .25s ease-out;
}
.toast .t-name { color: var(--warn); font-weight: 700; }
.toast .t-blurb { color: var(--dim); font-size: 11px; margin-top: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- component probe (observability hover) ---------- */
#probe {
  position: absolute;
  z-index: 8;
  width: 268px;
  background: rgba(10, 14, 20, .97);
  border: 1px solid #3d4a5f;
  border-radius: 6px;
  padding: 8px 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .7);
  pointer-events: none;
  font-size: 11px;
}
#probe .p-title { font-weight: 700; font-size: 12px; color: var(--text); }
#probe .p-sub { color: var(--dim); font-size: 10px; margin-bottom: 6px; }
#probe .p-sec {
  font-size: 9px; letter-spacing: 1.5px; color: var(--dim);
  border-top: 1px solid var(--line); padding-top: 4px; margin-top: 5px;
}
#probe .p-row { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; }
#probe .p-row .k { color: var(--dim); }
#probe .p-row .v { font-variant-numeric: tabular-nums; text-align: right; }
#probe .p-note { color: var(--dim); font-size: 10px; font-style: italic; margin-top: 5px; line-height: 1.4; }
#probe .warnv { color: var(--warn); }
#probe .badv { color: var(--bad); }
#probe .goodv { color: var(--good); }

/* ---------- guru ---------- */
#btn-guru {
  position: absolute;
  right: 12px;
  bottom: 10px;
  z-index: 7;
  padding: 7px 14px;
  border-color: #7a6bd6;
  color: #b9aeff;
  background: rgba(28, 35, 48, .95);
  box-shadow: 0 3px 14px rgba(0, 0, 0, .5);
}
#btn-guru:hover { border-color: #b9aeff; }
#btn-guru.sel { background: #7a6bd6; color: #0d1117; }
#guru-panel {
  position: absolute;
  right: 12px;
  bottom: 48px;
  width: 380px;
  max-height: calc(100% - 64px);
  overflow-y: auto;
  background: rgba(18, 22, 32, .97);
  border: 1px solid #4b41a0;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .7);
  z-index: 7;
  padding: 10px 12px;
}
#guru-head {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 2px;
  color: #b9aeff;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin-bottom: 8px;
}
#guru-close { cursor: pointer; }
#guru-close:hover { color: var(--bad); }
#guru-load { margin-bottom: 9px; }
#guru-load .gl-title { font-size: 9px; color: var(--dim); letter-spacing: 1px; margin-bottom: 3px; }
#guru-load .gl-bar { display: flex; height: 14px; border-radius: 3px; overflow: hidden; background: rgba(0,0,0,.35); }
#guru-load .gl-seg {
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: #0d1117; white-space: nowrap; overflow: hidden;
  transition: width .3s ease;
}
.guru-card {
  border-left: 3px solid var(--dim);
  padding: 7px 0 7px 9px;
  margin-bottom: 9px;
}
.guru-card:last-child { margin-bottom: 0; }
.guru-card.critical { border-left-color: var(--bad); }
.guru-card.warn { border-left-color: var(--warn); }
.guru-card.info { border-left-color: var(--accent); }
.guru-card.good { border-left-color: var(--good); }
.guru-card .gc-head { font-weight: 700; font-size: 12px; margin-bottom: 4px; }
.guru-card.critical .gc-head { color: var(--bad); }
.guru-card.warn .gc-head { color: var(--warn); }
.guru-card.info .gc-head { color: var(--accent); }
.guru-card.good .gc-head { color: var(--good); }
.guru-card .gc-body { font-size: 11.5px; line-height: 1.5; color: var(--text); margin-bottom: 5px; }
.guru-card .gc-action { font-size: 11.5px; line-height: 1.45; color: #b9aeff; }
.guru-card .gc-action::before { content: '→ '; }

/* ---------- management memos ---------- */
#memos {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 310px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 6;
}
.memo {
  background: #f4efe2;
  color: #2a2620;
  border-radius: 3px;
  border-left: 5px solid #8a1c1c;
  padding: 9px 12px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .55);
  cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
  animation: memo-in .3s cubic-bezier(.2, .9, .3, 1.2);
}
.memo.leaving { animation: memo-out .35s ease-in forwards; }
.memo-head {
  font-family: inherit;
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #8a1c1c;
  border-bottom: 1px solid #cdc3ad;
  padding-bottom: 3px;
  margin-bottom: 5px;
  display: flex;
  justify-content: space-between;
}
.memo-subject { font-weight: bold; font-size: 12px; margin-bottom: 3px; }
.memo-body { font-size: 12.5px; line-height: 1.45; }
.memo-from { font-size: 10.5px; color: #6b6357; margin-top: 6px; font-style: italic; }
@keyframes memo-in {
  from { opacity: 0; transform: translateX(28px) rotate(1.5deg); }
}
@keyframes memo-out {
  to { opacity: 0; transform: translateX(28px); }
}

/* ---------- shop ---------- */
#shop {
  flex: 0 0 300px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  display: flex; flex-direction: column;
}
#shop-header {
  padding: 9px 12px;
  font-size: 11px; letter-spacing: 2px; color: var(--dim);
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between;
  position: sticky; top: 0; background: var(--panel); z-index: 2;
}
#stat-income { font-variant-numeric: tabular-nums; }
.shop-item {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
.shop-item .row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.shop-item .name { font-weight: 700; }
.shop-item .owned { color: var(--good); font-size: 11px; }
.shop-item .blurb { color: var(--dim); font-size: 11px; margin: 3px 0; }
.shop-item .tradeoff { color: var(--warn); font-size: 10px; margin-bottom: 5px; }
.shop-item .buttons { display: flex; gap: 4px; }
.shop-item .buttons button { flex: 1 1 auto; padding: 4px; }
.shop-item .buttons button.down { flex: 0 0 30px; color: var(--dim); }
.shop-item .buttons button.down:hover:enabled { color: var(--bad); border-color: var(--bad); }
.shop-item button:disabled { opacity: .35; cursor: default; border-color: var(--line); }
.shop-item button.affordable { border-color: var(--good); color: var(--good); }
.shop-item .run { color: var(--dim); font-size: 10px; margin-bottom: 5px; }
.shop-item .run b { color: var(--warn); font-weight: 400; }

/* ---------- money bar ---------- */
#moneybar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
  font-size: 10px;
}
#money-income { color: var(--good); white-space: nowrap; cursor: help; }
#money-net { white-space: nowrap; font-variant-numeric: tabular-nums; }
#money-track {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: 18px;
}
#money-segments {
  display: flex;
  height: 100%;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(0, 0, 0, .25);
}
#money-marker {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--good);
  transition: left .4s ease;
  pointer-events: none;
}
#money-marker::after {
  content: 'revenue';
  position: absolute;
  left: 4px;
  top: 3px;
  font-size: 9px;
  color: var(--good);
  white-space: nowrap;
}
.cost-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
  height: 100%;
  color: var(--text);
  cursor: help;
  transition: width .4s ease;
  border-right: 1px solid var(--bg);
}
.cost-seg:last-child { border-right: none; }

/* ---------- charts ---------- */
#charts {
  flex: 0 0 118px;
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.chart {
  position: relative;
  overflow: hidden;
  flex: 1 1 0;
  min-width: 0;
  border-right: 1px solid var(--line);
}
.chart:last-child { border-right: none; }
.chart canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- modal ---------- */
#modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(5, 8, 12, .78);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}
.hidden { display: none !important; }
#insight-card, #drawer, #endscreen, #intro {
  background: var(--panel2);
  border: 1px solid var(--warn);
  border-radius: 10px;
  padding: 22px 26px;
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 12px 48px rgba(0,0,0,.6);
}
#endscreen { border-color: var(--accent); }
.card-kicker { font-size: 10px; letter-spacing: 3px; color: var(--warn); margin-bottom: 8px; }
.card-title { font-size: 19px; font-weight: 700; margin-bottom: 10px; }
.card-text { color: var(--text); line-height: 1.55; margin-bottom: 16px; }
#insight-card button, #drawer button, #endscreen button, #intro button { width: 100%; padding: 8px; }
#intro { border-color: var(--accent); }
.drawer-item { border-bottom: 1px solid var(--line); padding: 10px 0; }
.drawer-item .card-title { font-size: 13px; margin-bottom: 4px; }
.drawer-item .card-text { font-size: 11px; color: var(--dim); margin-bottom: 0; }
.drawer-item.locked .card-title { color: var(--dim); }
#drawer-list { margin-bottom: 14px; }
#end-insights { margin-bottom: 16px; }
#end-title.won { color: var(--good); }
#end-title.lost { color: var(--bad); }
