:root {
  --bg: #0a0a0a;
  --panel: #111;
  --border: #1a1a22;
  --fg: #e5e5e5;
  --dim: #888;
  --accent: #4ade80;
  --error: #f87171;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  overflow: hidden;
}

/* ── header ─────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 0.75rem; }
.home-link { text-decoration: none; }
.home-link h1 {
  font-size: 1.5rem;
  background: linear-gradient(135deg, #fff, #888);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.home-link h1::before {
  content: '> ';
  color: var(--accent);
  -webkit-text-fill-color: var(--accent);
}
.tagline { color: var(--dim); font-size: 0.8rem; }

.actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
  position: relative;
  margin-left: auto;
}
.actions .sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 0.25rem;
}

button, select {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 4px;
}
button:hover, select:hover { border-color: var(--accent); color: var(--accent); }
button:active { transform: translateY(1px); }
select { padding-right: 1.5rem; min-width: 140px; }

#run-btn { color: var(--accent); }
#run-btn:hover { background: var(--accent); color: var(--bg); }

.template-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-top: 0.25rem;
  display: flex;
  flex-direction: column;
  min-width: 180px;
  z-index: 10;
  overflow: hidden;
}
.template-menu[hidden] { display: none; }
.template-menu button {
  border: 0;
  border-radius: 0;
  text-align: left;
  background: transparent;
}
.template-menu button:hover { background: var(--border); }

/* ── main grid ──────────────────────────────────────── */

main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  min-height: 0;
}
.editor-pane, .preview-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.editor-pane { border-right: 1px solid var(--border); }

#editor {
  flex: 1 1 auto;
  overflow: auto;
  min-height: 0;
}
.cm-editor { height: 100%; font-size: 0.9rem; }
.cm-editor.cm-focused { outline: none; }
.cm-scroller { font-family: inherit !important; }

.error-panel {
  border-top: 1px solid var(--border);
  background: #1a0f0f;
  color: var(--error);
  font-size: 0.8rem;
  max-height: 30%;
  overflow: auto;
}
.error-head {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid #2a1515;
}
.error-label { font-weight: bold; letter-spacing: 0.05em; }
#error-close { border: 0; background: transparent; color: var(--error); padding: 0; line-height: 1; }
#error-body {
  padding: 0.5rem 0.75rem 0.75rem;
  white-space: pre-wrap;
  font-family: inherit;
}

.preview-pane { background: #000; }
#preview {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

/* ── toast ──────────────────────────────────────────── */

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.5rem 1rem;
  border-radius: 4px;
  z-index: 100;
  font-size: 0.85rem;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

/* ── footer ─────────────────────────────────────────── */

footer {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--dim);
  flex-wrap: wrap;
}
footer .status { color: var(--accent); }
footer .credits { margin-left: auto; margin-right: 1rem; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── mobile: stack editor over preview ──────────────── */

@media (max-width: 800px) {
  body { overflow: auto; }
  main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(240px, 40vh) minmax(240px, 40vh);
  }
  .editor-pane { border-right: 0; border-bottom: 1px solid var(--border); }
  header { padding: 0.5rem 0.75rem; gap: 0.5rem; }
  .actions { margin-left: 0; width: 100%; }
  footer .credits { display: none; }
}
