:root {
  --bg: #1e1f22;
  --bg-deep: #111214;
  --panel: #2b2d31;
  --panel-2: #232428;
  --line: #3f4147;
  --text: #dbdee1;
  --muted: #949ba4;
  --accent: #23a559;
  --accent-hi: #2dc770;
  --accent-dim: #1a7f45;
  --danger: #f23f43;
  --warn: #f0b232;
  --kw: #c678dd;
  --str: #98c379;
  --num: #d19a66;
  --cmt: #6b7280;
  --fn: #61afef;
  --mono: "JetBrains Mono", "IBM Plex Mono", "Cascadia Code", ui-monospace, Menlo, Consolas, monospace;
  --sans: "gg sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--sans);
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { margin: 0; font-size: 1.1rem; font-weight: 700; letter-spacing: 0.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; }
.mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent-hi), var(--accent-dim));
  color: #04140c; font-weight: 800; font-family: var(--mono);
}
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.file-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
#filename {
  width: 160px;
  background: var(--bg-deep); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; font-family: var(--mono); font-size: 0.85rem;
}
#api-key {
  flex: 1; min-width: 200px;
  background: var(--bg-deep); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; font-family: var(--mono); font-size: 0.85rem;
}
.hint { color: var(--muted); font-size: 0.75rem; }

.layout {
  flex: 1;
  display: grid;
  grid-template-rows: 1.35fr 0.85fr;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.editor-pane { border-bottom: 1px solid var(--line); }
.pane-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase;
}
#tab-name {
  color: var(--text);
  font-family: var(--mono);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.82rem;
}

.editor-wrap {
  position: relative;
  flex: 1;
  min-height: 220px;
  overflow: auto;
  background: var(--bg-deep);
}
.highlight, #code {
  margin: 0;
  border: 0;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.5;
  tab-size: 2;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
}
.highlight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: var(--text);
  overflow: hidden;
}
#code {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 220px;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: #fff;
  outline: none;
  overflow: auto;
}

.tok-kw { color: var(--kw); font-weight: 600; }
.tok-str { color: var(--str); }
.tok-num { color: var(--num); }
.tok-cmt { color: var(--cmt); font-style: italic; }
.tok-fn { color: var(--fn); }

.out {
  flex: 1; margin: 0; border: 0;
  background: var(--bg-deep); color: var(--text);
  font-family: var(--mono); font-size: 0.9rem; line-height: 1.45;
  padding: 14px 16px; outline: none; white-space: pre-wrap; word-break: break-word;
  overflow: auto; min-height: 120px;
}
.out.err { color: #ff8e8e; }
.out.ok { color: #b5f2c8; }
.muted { color: var(--muted); }

button, .ghost, .primary {
  appearance: none; border: 1px solid var(--line); background: transparent;
  color: var(--text); border-radius: 6px; padding: 8px 12px;
  font: inherit; cursor: pointer; text-decoration: none;
}
.ghost:hover { border-color: #5c5e66; background: #313338; }
.primary {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  border-color: transparent; color: #fff; font-weight: 700;
  box-shadow: 0 1px 0 #0004;
}
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: 0.55; cursor: wait; filter: none; }

.foot {
  padding: 8px 16px; border-top: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted); font-size: 0.75rem;
}
.foot code { color: #c9d4e3; }

@media (max-width: 700px) {
  .layout { grid-template-rows: 1fr 1fr; }
  #filename { width: 120px; }
}
