:root {
  --bg: #0e1319;
  --panel: #161d26;
  --panel-2: #1d2631;
  --line: #2a3542;
  --text: #e6ebf1;
  --muted: #8d9aaa;
  --accent: #4da3ff;
  --good: #3ddc84;
  --warn: #ffb347;
  --bad: #ff5d5d;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body, #app { height: 100%; margin: 0; }

body { background: var(--bg); color: var(--text); font-size: 14px; }

button, select, input { font: inherit; color: inherit; }

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
button.danger { background: var(--bad); border-color: var(--bad); color: #1c0606; font-weight: 600; }
button.ghost { background: transparent; }
button.on { background: var(--accent); border-color: var(--accent); color: #06121f; }

select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
input[type='range'] { width: 100%; accent-color: var(--accent); }

/* ---------- menu ---------- */
.menu { max-width: 860px; margin: 0 auto; padding: 56px 20px; }
.menu h1 { font-size: 40px; margin: 0 0 6px; letter-spacing: -0.5px; }
.menu p.lead { color: var(--muted); margin: 0 0 28px; font-size: 16px; }
.menu .region-pick { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.menu .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.card h2 { margin: 0; font-size: 20px; }
.card p { margin: 0; color: var(--muted); line-height: 1.45; flex: 1; }
.card ul { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.5; }

/* ---------- shared game layout ---------- */
.game { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar .title { font-weight: 700; font-size: 16px; }
.stat { display: flex; flex-direction: column; line-height: 1.15; min-width: 64px; }
.stat span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat b { font-size: 16px; font-variant-numeric: tabular-nums; }
.speed { display: flex; gap: 4px; margin-left: auto; }
.game main { flex: 1; display: flex; min-height: 0; }

/* ---------- region mode ---------- */
.mapwrap { position: relative; flex: 1; min-width: 0; }
.mapwrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; }
.mapwrap canvas.dragging { cursor: grabbing; }
.legend { position: absolute; left: 12px; bottom: 12px; background: rgba(22, 29, 38, 0.9); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--muted); }
.legend .bar { width: 180px; height: 8px; border-radius: 4px; margin: 4px 0; background: linear-gradient(90deg, #ff3b3b, #ff9a3b, #f2d43d, #3ddc84); }
.legend .ends { display: flex; justify-content: space-between; }
.hint { position: absolute; left: 12px; top: 12px; font-size: 12px; color: var(--muted); background: rgba(22, 29, 38, 0.8); padding: 6px 10px; border-radius: 8px; }
.sidebar { width: 360px; flex-shrink: 0; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); }
.sidebar section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sidebar h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-variant-numeric: tabular-nums; }
.kv span { color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.row label { flex: 0 0 96px; color: var(--muted); }
.row output { flex: 0 0 70px; text-align: right; font-variant-numeric: tabular-nums; }
.row.disabled { opacity: 0.45; }
.seg-title { font-weight: 600; margin-bottom: 2px; }
.seg-sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.btn-col { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.note { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.note.err { color: var(--bad); }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: var(--warn); color: #2a1a00; font-weight: 600; margin-left: 6px; }
.events { list-style: none; margin: 0; padding: 0; font-size: 12px; line-height: 1.4; }
.events li { padding: 3px 0; color: var(--muted); }
.events li b { color: var(--text); font-weight: 600; margin-right: 4px; }
.events li.crash { color: #ffa3a3; }
.events li.build { color: #ffd08a; }
.events li.open { color: #9be7bd; }
.chart { width: 100%; height: 90px; display: block; }
.chart-key { display: flex; gap: 12px; font-size: 11px; color: var(--muted); margin-top: 4px; }
.chart-key i { display: inline-block; width: 10px; height: 3px; margin-right: 4px; vertical-align: middle; }

/* ---------- crash mode ---------- */
.crash-main { flex-direction: column; overflow-y: auto; padding: 14px; gap: 12px; }
.crash-main canvas { width: 100%; display: block; background: #0a0e13; border: 1px solid var(--line); border-radius: 8px; }
.road-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #0a0e13; }
.crash-main canvas.road { min-width: 1000px; border: 0; border-radius: 0; cursor: crosshair; touch-action: manipulation; }
.crash-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; align-items: start; }
.crash-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.crash-panel h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.caption { color: var(--muted); font-size: 12px; margin: 4px 2px 0; line-height: 1.4; }
.phase { font-weight: 700; }
.phase.blocked { color: var(--bad); }
.phase.recovering { color: var(--warn); }
.phase.recovered, .phase.flowing { color: var(--good); }

@media (max-width: 900px) {
  .game main { flex-direction: column; }
  .sidebar { width: 100%; border-left: 0; border-top: 1px solid var(--line); max-height: 45%; }
  .mapwrap { min-height: 50%; }
  .crash-grid { grid-template-columns: 1fr; }
  .speed { margin-left: 0; }
}
