:root {
  --bg: #07080c;
  --bg-elev: #0c0e14;
  --surface: #11141c;
  --surface-2: #171b26;
  --line: rgba(232, 184, 109, 0.14);
  --line-strong: rgba(232, 184, 109, 0.28);
  --gold: #e8b86d;
  --gold-2: #f3d7a1;
  --ink: #f4efe6;
  --muted: #8b8494;
  --danger: #ef7a7a;
  --ok: #7fd1ae;
  --info: #8bb4e8;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --font: "Manrope", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

body {
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(232, 184, 109, 0.08), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, rgba(127, 209, 174, 0.05), transparent 45%),
    var(--bg);
}

button, input, select { font-family: inherit; }

.app {
  height: 100%;
  display: grid;
  grid-template-rows: 64px 1fr 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(17, 20, 28, 0.92), rgba(12, 14, 20, 0.88));
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #f3d7a1, #c9923e 55%, #8a5a18);
  color: #1a140c;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18), 0 8px 20px rgba(232, 184, 109, 0.25);
}

.brand h1 {
  font-family: var(--display);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.brand h1 span {
  display: block;
  font-family: var(--font);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 600;
}

.top-actions, .toolbar, .stage-tools, .status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: 160ms ease;
}

.btn:hover {
  border-color: var(--line-strong);
  background: #1d2230;
  transform: translateY(-1px);
}

.btn:active { transform: translateY(0); }

.btn-gold {
  background: linear-gradient(180deg, #f0cc8a, #d7a352);
  color: #1a140c;
  border-color: #f3d7a1;
  box-shadow: 0 8px 18px rgba(232, 184, 109, 0.18);
}

.btn-gold:hover { filter: brightness(1.05); }

.btn-ghost { background: transparent; }

.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-icon {
  width: 36px;
  padding: 0;
  justify-content: center;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1.35fr) 8px minmax(380px, 1fr);
  min-height: 0;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.02), transparent 30%),
    var(--bg-elev);
}

.canvas-stack {
  position: absolute;
  inset: 16px 16px 56px 16px;
  border-radius: 22px;
  overflow: hidden;
  background: #0a0c11;
  box-shadow:
    inset 0 0 0 1px var(--line),
    var(--shadow);
}

.canvas-stack canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.canvas-stack canvas.is-panning { cursor: grabbing; }

#overlay { pointer-events: none; }

.stage-tools {
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 14px;
  justify-content: space-between;
}

.chip {
  height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(17, 20, 28, 0.82);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.chip input { accent-color: var(--gold); }

.chip.active {
  color: var(--gold-2);
  border-color: var(--line-strong);
}

.v-split, .h-split {
  background: transparent;
  position: relative;
}

.v-split::after, .h-split::after {
  content: "";
  position: absolute;
  background: var(--line);
}

.v-split { cursor: col-resize; }
.v-split::after { top: 12%; bottom: 12%; width: 1px; left: 3px; }
.h-split { cursor: row-resize; height: 8px; }
.h-split::after { left: 18%; right: 18%; height: 1px; top: 3px; }

.studio {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 52px 1fr 8px 150px;
  background: var(--surface);
  border-left: 1px solid transparent;
}

.toolbar {
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  gap: 6px;
}

.speed-wrap {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.speed-wrap input[type="range"] {
  width: 92px;
  accent-color: var(--gold);
}

#editor-host {
  min-height: 0;
  overflow: hidden;
}

.CodeMirror {
  height: 100%;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  background: transparent;
}

.cm-s-studio { background: #0c0e14; color: #ece6da; }
.cm-s-studio .CodeMirror-gutters {
  background: #0a0c11;
  border: none;
}
.cm-s-studio .CodeMirror-linenumber { color: #4a4654; padding: 0 10px; }
.cm-s-studio .CodeMirror-cursor { border-left: 2px solid var(--gold); }
.cm-s-studio .CodeMirror-selected { background: rgba(232, 184, 109, 0.16); }
.cm-s-studio .cm-keyword { color: #e8b86d; font-weight: 600; }
.cm-s-studio .cm-number { color: #8fd3c0; }
.cm-s-studio .cm-string { color: #f0d9a6; }
.cm-s-studio .cm-comment { color: #6d6877; font-style: italic; }
.cm-s-studio .cm-variable { color: #d7e0ea; }
.cm-s-studio .cm-operator { color: #e08f7a; }
.cm-s-studio .cm-def { color: #c7b8ff; }
.cm-s-studio .CodeMirror-activeline-background { background: rgba(255,255,255,0.025); }
.cm-exec-line { background: rgba(232, 184, 109, 0.10); }
.cm-error-line { background: rgba(239, 122, 122, 0.14); }

.console {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #0a0c11;
  border-top: 1px solid var(--line);
}

.console-head {
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
}

#log {
  flex: 1;
  overflow: auto;
  padding: 8px 14px 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: #c8c2b8;
  white-space: pre-wrap;
}

.log-error { color: var(--danger); }
.log-ok { color: var(--ok); }
.log-info { color: var(--info); }

.status {
  border-top: 1px solid var(--line);
  padding: 0 16px;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  background: #0a0c11;
  font-variant-numeric: tabular-nums;
}

.status b { color: var(--gold-2); font-weight: 600; }

.kbd {
  font-family: var(--mono);
  font-size: 10px;
  border: 1px solid var(--line);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--gold-2);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.72);
  display: none;
  place-items: center;
  z-index: 40;
  padding: 24px;
}

.modal-backdrop.open { display: grid; }

.modal {
  width: min(920px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.modal header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 22px 8px;
}

.modal header h2 {
  font-family: var(--display);
  font-size: 26px;
  font-weight: 500;
}

.examples {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 12px 22px 22px;
}

.example-card {
  text-align: left;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: inherit;
  cursor: pointer;
}

.example-card:hover { border-color: var(--gold); }
.example-card strong { display: block; font-size: 14px; margin-bottom: 6px; }
.example-card span { color: var(--muted); font-size: 12px; line-height: 1.45; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-left: 6px;
}

.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  50% { box-shadow: 0 0 0 6px rgba(232, 184, 109, 0.12); }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a3142; border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 980px) {
  .app { grid-template-rows: 58px 1fr 28px; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: 42vh 8px 1fr; }
  .v-split { cursor: row-resize; }
  .brand h1 { font-size: 16px; }
  .top-actions .btn span.label { display: none; }
}
