:root {
  --bg: #1a1b26;
  --surface: #1f2335;
  --surface-2: #24283b;
  --text: #a9b1d6;
  --muted: #565f89;
  --accent: #7aa2f7;
  --border: #292e42;
  --shadow: rgba(0, 0, 0, 0.4);
  --mono: "JetBrains Mono", "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;

  --tok-keyword: #bb9af7;
  --tok-builtin: #7aa2f7;
  --tok-string: #9ece6a;
  --tok-number: #ff9e64;
  --tok-comment: #565f89;
  --tok-operator: #89ddff;
}

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

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--display);
}

.page {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

/* ── Toolbar ──────────────────────────────────── */

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.logo {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--muted);
  text-transform: uppercase;
}

.toolbar-links {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.docs-btn {
  text-decoration: none;
  font-family: var(--display);
  font-size: 12px;
}

/* ── IDE layout ───────────────────────────────── */

.ide {
  display: grid;
  grid-template-columns: 2fr 1fr;
  min-height: 0;
}

.side {
  display: grid;
  grid-template-rows: 1fr 1fr;
  min-height: 0;
}

/* ── Panels ───────────────────────────────────── */

.panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid var(--border);
}

.panel--code {
  border-left: none;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.panel--code .code-shell {
  flex: 1 1 0;
}

.panel--io + .panel--io {
  border-top: 1px solid var(--border);
}

.panel__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  height: 36px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sample-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--display);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
}

.sample-select:hover {
  color: var(--text);
  border-color: var(--muted);
}

.sample-select option,
.sample-select optgroup {
  background: var(--surface-2);
  color: var(--text);
}

.sample-select optgroup {
  font-style: normal;
  font-weight: 600;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ── Editor ───────────────────────────────────── */

textarea {
  background: transparent;
  border: none;
  padding: 14px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  tab-size: 2;
  resize: none;
  outline: none;
  min-height: 0;
  height: 100%;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.code-shell {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: flex;
}

.line-numbers {
  padding: 14px 0 14px 14px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
  text-align: right;
  user-select: none;
  min-width: 36px;
  overflow: hidden;
  white-space: pre-wrap;
}

.code-area {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.code-highlight {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 14px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  color: var(--text);
  pointer-events: none;
  z-index: 0;
  background: transparent;
  overflow: auto;
}

.code-input {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--text);
  background: transparent;
}

/* ── Tokens ───────────────────────────────────── */

.token-keyword  { color: var(--tok-keyword); }
.token-builtin  { color: var(--tok-builtin); }
.token-number   { color: var(--tok-number); }
.token-string   { color: var(--tok-string); }
.token-comment  { color: var(--tok-comment); }
.token-operator { color: var(--tok-operator); }

/* ── Output ───────────────────────────────────── */

.output {
  padding: 14px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  min-height: 0;
  overflow: auto;
}

/* ── Buttons ──────────────────────────────────── */


.btn {
  background: var(--accent);
  border: none;
  color: #0b1a22;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s;
}

.btn.play {
  padding: 0;
  background: none;
  color: var(--muted);
  border-radius: 4px;
  width: auto;
  height: auto;
  justify-content: center;
}

.btn.play:hover {
  color: var(--text);
}

.btn.play svg {
  display: block;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

/* ── Autocomplete ────────────────────────────── */

.autocomplete {
  position: absolute;
  z-index: 10;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 0;
  min-width: 280px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 12px var(--shadow);
  display: none;
  font-family: var(--mono);
  font-size: 13px;
}

.autocomplete.visible { display: block; }

.ac-item {
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.ac-item.active, .ac-item:hover {
  background: var(--accent);
  color: #0b1a22;
}

.ac-item .ac-kind {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.ac-item.active .ac-kind, .ac-item:hover .ac-kind {
  color: #0b1a22;
  opacity: 0.6;
}

.ac-item .ac-kind.stdlib {
  color: var(--tok-string);
}

/* ── Settings ─────────────────────────────────── */

.settings-btn {
  background: transparent !important;
  border: none !important;
  color: var(--muted);
  padding: 4px 6px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
}

.settings-btn:hover {
  color: var(--text);
}

.settings-btn svg {
  display: block;
}

.settings-popup {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 160px;
  box-shadow: 0 8px 24px var(--shadow);
  z-index: 50;
}

.settings-popup.visible {
  display: block;
}

.settings-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.theme-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--display);
  color: var(--text);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.theme-option:hover {
  background: var(--border);
}

.theme-option.active {
  background: var(--accent);
  color: #0b1a22;
}

.theme-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}

.theme-option.active .theme-swatch {
  border-color: rgba(0,0,0,0.3);
}

/* ── Mobile ───────────────────────────────────── */

@media (max-width: 720px) {
  .ide {
    grid-template-columns: 1fr;
    grid-template-rows: 2fr 1fr;
  }

  .side {
    grid-template-rows: 1fr 1fr;
  }

  .panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
