:root {
  color-scheme: dark;
  --accent: #06b6d4;
  --accent-glow: #22d3ee;
  --accent-soft: rgba(6, 182, 212, 0.18);
  --bg: #0a1628;
  --bg-card: #142036;
  --bg-deep: #050a18;
  --text: #e0f2fe;
  --text-muted: #7c95b8;
  --border: #2d4163;
  --hazard: #ef4444;
  --crystal: #06b6d4;
  --sample: #fbbf24;
  --pad: #10b981;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(6,182,212,0.10), transparent 60%),
    radial-gradient(800px 400px at 10% 120%, rgba(16,185,129,0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.game-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  background: rgba(5, 10, 24, 0.45); backdrop-filter: blur(8px);
}
.game-header h1 {
  color: var(--accent); font-size: 22px; letter-spacing: 0.5px;
  text-shadow: 0 0 24px rgba(6, 182, 212, 0.35);
}
.back { color: var(--text-muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }
.mode-badge {
  background: var(--bg-card); padding: 4px 12px; border-radius: 16px;
  font-size: 12px; border: 1px solid var(--border); color: var(--text-muted);
}

.explorer-shell {
  display: grid; grid-template-columns: 1fr 520px; gap: 20px;
  padding: 24px; max-width: 1280px; margin: 0 auto;
}

.editor-pane { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.pane-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; flex-wrap: wrap;
}
.level-title { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.api-hint { font-size: 11px; color: var(--text-muted); }
.api-hint code { color: var(--accent); background: rgba(6,182,212,0.08); padding: 2px 6px; border-radius: 4px; }

#code-editor { width: 100%; min-height: 300px; font-family: "Fira Code", ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.CodeMirror {
  border: 1px solid var(--border); border-radius: 8px;
  height: 340px; font-size: 13px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.3) inset;
}
.CodeMirror-gutters { background: #0a1424 !important; border-right-color: var(--border) !important; }

.editor-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn-primary {
  background: var(--accent); color: #04101e; border: none;
  padding: 10px 18px; border-radius: 8px; font-weight: 700;
  cursor: pointer; transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
  box-shadow: 0 6px 18px rgba(6,182,212,0.25);
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.btn-primary:hover:not(:disabled) { background: var(--accent-glow); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-secondary {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); padding: 10px 14px;
  border-radius: 8px; cursor: pointer; font-weight: 500;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.run-status { font-size: 12px; color: var(--text-muted); margin-left: 4px; }
.run-status.busy { color: var(--accent); }
.run-status.err { color: var(--hazard); }

.console {
  background: var(--bg-deep);
  color: #b7ffe2;
  padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border);
  font-family: "Fira Code", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px; min-height: 100px; max-height: 200px;
  overflow: auto; white-space: pre-wrap;
}
.console > div + div { margin-top: 2px; }
.console .err { color: var(--hazard); }
.console .ok  { color: var(--pad); }
.console .info { color: var(--accent); }

.game-pane { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
#map-canvas {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.4);
  max-width: 100%; height: auto;
}
.hud {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  font-size: 12px; padding: 10px 12px;
  background: var(--bg-card); border-radius: 8px; border: 1px solid var(--border);
}
.hud-item { display: flex; flex-direction: column; gap: 2px; color: var(--text-muted); }
.hud strong { color: var(--accent); font-size: 16px; font-variant-numeric: tabular-nums; }
.goal-strip {
  background: rgba(6,182,212,0.06); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 12px;
  color: var(--text-muted); line-height: 1.5;
}
.goal-strip strong { color: var(--text); }

/* Modal */
.modal {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(0,0,0,0.75); z-index: 100;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-card); padding: 28px; border-radius: 14px;
  border: 1px solid var(--accent); text-align: center;
  min-width: 320px; max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5), 0 0 60px rgba(6,182,212,0.12);
}
.modal-card h2 { color: var(--accent); margin-bottom: 12px; font-size: 22px; }
.modal-card p { margin: 6px 0; color: var(--text); font-size: 14px; }
.modal-card p.small { color: var(--text-muted); font-size: 12px; margin-top: 14px; }
.modal-card strong { color: var(--accent); }
.modal-card .name-input {
  margin: 16px 0 8px; padding: 10px 12px;
  width: 100%; background: var(--bg-deep); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.modal-card button {
  background: var(--accent); color: #04101e; border: none;
  padding: 10px 18px; border-radius: 8px; font-weight: 700;
  cursor: pointer; margin-top: 8px;
}
.modal-card button:hover { background: var(--accent-glow); }

@media (max-width: 980px) {
  .explorer-shell { grid-template-columns: 1fr; padding: 16px; }
  .game-pane { order: -1; }
  #map-canvas { width: 100%; }
  .CodeMirror { height: 260px; }
}
