:root {
  --bg: #0d0f14;
  --panel: rgba(18, 21, 29, 0.94);
  --panel-solid: #12151d;
  --card: #1a1e29;
  --line: #262b38;
  --text: #d9dde6;
  --muted: #8a93a6;
  --accent: #e8a33d;
  --accent-2: #f5c46a;
  --good: #6be38c;
  --bad: #ff6b5b;
  --panel-w: 330px;
  --top-h: 48px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 13px/1.4 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
canvas#world { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; cursor: grab; touch-action: none; }
canvas#world.panning { cursor: grabbing; }
canvas#world.tool { cursor: crosshair; }

button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
#topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--top-h); display: flex; align-items: center; gap: 14px;
  padding: 0 12px; background: linear-gradient(180deg, rgba(13,15,20,0.95), rgba(13,15,20,0.82)); border-bottom: 1px solid var(--line);
  z-index: 10; backdrop-filter: blur(6px); white-space: nowrap; overflow-x: auto; scrollbar-width: none; }
#topbar::-webkit-scrollbar { display: none; }
#topbar > * { flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.3px; }
.brand .logo { font-size: 20px; }
.brand .title { color: var(--accent-2); font-size: 15px; }
.clock { font-variant-numeric: tabular-nums; color: var(--text); background: var(--card); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 8px; min-width: 200px; text-align: center; }
.group { display: flex; align-items: center; gap: 4px; }
.group.right { margin-left: auto; }
.icon-btn, .btn, .toggle, .speeds button { background: var(--card); border: 1px solid var(--line); border-radius: 7px; cursor: pointer;
  height: 30px; padding: 0 10px; transition: background 0.12s, border-color 0.12s; }
.icon-btn { width: 32px; padding: 0; font-size: 15px; }
.icon-btn:hover, .btn:hover, .toggle:hover, .speeds button:hover { background: #232838; border-color: #39405a; }
.btn.accent { background: var(--accent); color: #1a1206; border-color: var(--accent); font-weight: 600; }
.btn.accent:hover { background: var(--accent-2); }
.toggle.on, .speeds button.on { background: rgba(232, 163, 61, 0.18); border-color: var(--accent); color: var(--accent-2); }
.speeds { display: flex; gap: 2px; }
.speeds button { padding: 0 7px; font-variant-numeric: tabular-nums; }
.speed-actual { color: var(--bad); font-size: 11px; min-width: 0; }

/* ---------- side panel ---------- */
#panel { position: fixed; top: var(--top-h); right: 0; bottom: 0; width: var(--panel-w); background: var(--panel);
  border-left: 1px solid var(--line); z-index: 9; display: flex; flex-direction: column; transition: transform 0.2s ease;
  backdrop-filter: blur(6px); }
#panel.collapsed { transform: translateX(100%); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: none; padding: 10px 0; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent-2); border-bottom-color: var(--accent); }
.tab-body { display: none; overflow-y: auto; padding: 12px 14px 20px; flex: 1; }
.tab-body.active { display: block; }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 16px 0 6px; font-weight: 600; }
h3:first-child { margin-top: 4px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.kpi-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rows { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; }
.row { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.04); gap: 8px; }
.row:last-child { border-bottom: none; }
.row .k { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.row .v { font-variant-numeric: tabular-nums; text-align: right; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.bar { display: inline-block; vertical-align: middle; height: 6px; background: #0c0e13; border-radius: 3px; overflow: hidden; width: 110px; }
.bar > i { display: block; height: 100%; background: var(--good); border-radius: 3px; }
.bar.warn > i { background: var(--accent); }
.bar.bad > i { background: var(--bad); }
#chart { width: 100%; height: 120px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.legend { color: var(--muted); font-size: 11px; display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.sw { width: 10px; height: 3px; display: inline-block; margin-right: -6px; border-radius: 2px; }
.sw.pop { background: #f5c46a; } .sw.brood { background: #ff8fd8; } .sw.food { background: #6be38c; }
.log { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.log li { padding: 5px 8px; border-left: 3px solid var(--line); margin-bottom: 3px; background: var(--card); border-radius: 0 6px 6px 0; cursor: pointer; }
.log li .t { color: var(--muted); font-size: 10px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.log li.danger { border-left-color: var(--bad); } .log li.victory, .log li.birth { border-left-color: var(--good); }
.log li.food { border-left-color: #9be36b; } .log li.nest { border-left-color: var(--accent); } .log li.weather, .log li.season { border-left-color: #6fb6ff; }
.hint { color: var(--muted); font-size: 12px; }
.slider { display: block; margin: 8px 0; color: var(--text); }
.slider span { float: right; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.slider input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; cursor: pointer; }
.check input { accent-color: var(--accent); }
.select { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; gap: 8px; }
select, input[type=number], input[type=text] { background: var(--card); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 4px 6px; font: inherit; }
.btn-row { display: flex; gap: 6px; margin-top: 10px; }
.btn-row .btn { flex: 1; }
.perf { color: var(--muted); font-size: 11px; font-family: ui-monospace, Menlo, monospace; margin-top: 8px; white-space: pre; }
.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 12px; }
.tool-grid button { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; }
.tool-grid button .sw2 { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.15); }
.tool-grid button.on { border-color: var(--accent); background: rgba(232,163,61,0.15); }
.tool-grid button:hover { border-color: #39405a; }
.inspect-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.inspect-head .badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; color: #111; }
.inspect-head .name { font-size: 16px; font-weight: 700; }

/* ---------- minimap / status / toasts ---------- */
#minimap-wrap { position: fixed; left: 12px; bottom: 12px; z-index: 8; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #000; box-shadow: 0 4px 20px rgba(0,0,0,0.5); cursor: pointer; }
#minimap-wrap.hidden { display: none; }
#minimap { display: block; width: 240px; height: 150px; }
#statusbar { position: fixed; left: 264px; bottom: 12px; z-index: 8; background: rgba(13,15,20,0.8); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 10px; font-size: 11px; color: var(--muted); pointer-events: none; max-width: calc(100vw - 620px); }
#statusbar:empty { display: none; }
#toasts { position: fixed; top: calc(var(--top-h) + 10px); left: 50%; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: rgba(20,23,32,0.95); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 8px 14px; border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4); animation: tin 0.25s ease; max-width: 520px; }
.toast.danger { border-left-color: var(--bad); } .toast.victory, .toast.birth { border-left-color: var(--good); } .toast.weather, .toast.season { border-left-color: #6fb6ff; }
.toast.out { opacity: 0; transition: opacity 0.4s; }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal.hidden { display: none; }
.modal-card { background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; max-width: 820px; width: 100%; max-height: 90vh; overflow-y: auto; position: relative; }
.modal-card h2 { margin: 0 0 8px; color: var(--accent-2); }
.modal-card .close { position: absolute; top: 10px; right: 12px; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.help-cols table { width: 100%; border-collapse: collapse; }
.help-cols td { padding: 3px 4px; border-bottom: 1px solid rgba(255,255,255,0.05); vertical-align: top; }
.help-cols td:first-child { white-space: nowrap; width: 40%; }
kbd { background: #222738; border: 1px solid #343a50; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font: 11px ui-monospace, Menlo, monospace; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .overlays .toggle { padding: 0 6px; }
  .brand .title { display: none; }
  #statusbar { display: none; }
}
@media (max-width: 760px) {
  :root { --panel-w: 100vw; }
  .clock { min-width: 0; }
  .help-cols { grid-template-columns: 1fr; }
  #minimap-wrap { display: none; }
}
