/* OrbaLang Playground — dependency-free, dark theme. */

:root {
  --bg: #0a0e18;
  --bg-panel: #121829;
  --bg-panel-2: #171f34;
  --bg-inset: #080b14;
  --border: #263049;
  --border-soft: #1c2438;
  --text: #e8eef9;
  --text-dim: #93a0be;
  --accent: #5b9aff;
  --accent-2: #7aa2ff;
  --accent-soft: rgba(91, 154, 255, 0.18);
  --ok: #42d392;
  --warn: #ffbf66;
  --err: #ff7085;
  --kw: #82a8ff;
  --type: #42d392;
  --str: #ffd18a;
  --num: #d9a8ff;
  --com: #5c6888;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "Lucida Console", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(91, 154, 255, 0.12), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(66, 211, 146, 0.08), transparent 50%),
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #151d31 0%, var(--bg-panel) 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex: none;
  z-index: 2;
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-orb {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #b8d4ff, var(--accent) 55%, #1b3a75);
  box-shadow: 0 0 14px rgba(91, 154, 255, 0.65);
}
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -0.01em; }
.brand-name em { font-style: normal; color: var(--accent-2); }
.brand-ver {
  font-size: 11px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 10px; padding: 2px 8px;
  background: rgba(255, 255, 255, 0.03);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.select-label { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
select {
  background: var(--bg-panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; padding: 5px 10px; max-width: 220px;
}
select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.btn {
  background: var(--bg-panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; padding: 6px 13px; cursor: pointer;
  text-decoration: none; display: inline-block; line-height: 1.4;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--accent); background: #1a2440; }
.btn:active { transform: translateY(1px); }
.btn-accent {
  background: linear-gradient(180deg, #6aa8ff 0%, var(--accent) 100%);
  border-color: #4a86e8; color: #061022; font-weight: 650;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset;
}
.btn-accent:hover { filter: brightness(1.06); background: linear-gradient(180deg, #78b2ff 0%, #6aa8ff 100%); }
.btn-sm { font-size: 12px; padding: 4px 10px; }
.btn-link { color: var(--text-dim); background: transparent; }
.btn-link:hover { color: var(--text); }
.btn[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent-soft); border-color: var(--accent); }

/* ---------- layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 320px minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 0;
  min-height: 0;
  padding: 10px 10px 12px;
  gap: 10px;
}
.layout.tutorial-hidden { grid-template-columns: 0 minmax(0, 1fr) minmax(0, 1fr); }
.layout.tutorial-hidden .tutorial { display: none; }

/* ---------- tutorial ---------- */
.tutorial {
  display: flex; flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  min-height: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tutorial-head { padding: 12px 14px 8px; flex: none; background: rgba(255, 255, 255, 0.02); }
.tutorial-progress {
  height: 5px; border-radius: 999px; background: var(--bg-inset); overflow: hidden;
}
.tutorial-progress-bar {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--ok));
  transition: width 0.4s ease;
  border-radius: 999px;
}
.tutorial-nav {
  display: flex; align-items: center; justify-content: space-between; margin-top: 10px;
}
.tut-counter { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.tutorial-body { flex: 1; overflow-y: auto; padding: 6px 14px 14px; min-height: 0; }
.tutorial-body h2 { font-size: 17px; margin: 6px 0 8px; letter-spacing: -0.02em; }
.tut-content { font-size: 13px; line-height: 1.6; color: var(--text); }
.tut-content p { margin: 8px 0; }
.tut-content code {
  font-family: var(--mono); font-size: 12px;
  background: var(--bg-inset); border: 1px solid var(--border-soft);
  border-radius: 5px; padding: 1px 6px;
}
.tut-content pre {
  background: var(--bg-inset); border: 1px solid var(--border-soft);
  border-radius: 8px; padding: 10px 12px; overflow-x: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
}
.tut-content pre code { background: none; border: none; padding: 0; }

.tut-checks { list-style: none; margin: 14px 0 10px; padding: 0; }
.tut-checks li {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 13px; padding: 7px 10px; border-radius: 8px; margin-bottom: 5px;
  background: var(--bg-panel-2); color: var(--text-dim);
  border: 1px solid transparent;
  transition: background 0.25s, color 0.25s, border-color 0.25s;
}
.tut-checks li::before { content: "○"; color: var(--text-dim); flex: none; margin-top: 1px; }
.tut-checks li.pass {
  color: var(--text);
  background: rgba(66, 211, 146, 0.10);
  border-color: rgba(66, 211, 146, 0.25);
}
.tut-checks li.pass::before { content: "✓"; color: var(--ok); font-weight: 700; }

.tut-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.tut-hint {
  margin-top: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.55;
  border-left: 3px solid var(--warn);
  background: rgba(255, 191, 102, 0.08);
  border-radius: 0 8px 8px 0;
}
.tut-hint code { font-family: var(--mono); font-size: 12px; }
.tut-done {
  margin-top: 12px; padding: 12px; text-align: center;
  border: 1px solid rgba(66, 211, 146, 0.45); border-radius: 10px;
  background: rgba(66, 211, 146, 0.08);
  animation: pop 0.3s ease;
}
@keyframes pop { from { transform: scale(0.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tut-done-badge { display: block; color: var(--ok); font-weight: 650; margin-bottom: 8px; }

.tutorial-toc {
  flex: none; border-top: 1px solid var(--border-soft);
  padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 5px;
  background: rgba(0, 0, 0, 0.12);
}
.toc-dot {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-panel-2);
  color: var(--text-dim); font-size: 11px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s, color 0.15s, transform 0.1s;
}
.toc-dot.current { border-color: var(--accent); color: var(--accent); font-weight: 700; box-shadow: 0 0 0 2px var(--accent-soft); }
.toc-dot.done { border-color: var(--ok); color: var(--ok); }
.toc-dot:hover { border-color: var(--accent); transform: translateY(-1px); }

/* ---------- panes ---------- */
.editor-pane, .output-pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--bg-panel);
}
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent);
  border-bottom: 1px solid var(--border-soft);
  flex: none;
}
.pane-title { font-size: 12px; color: var(--text-dim); font-family: var(--mono); letter-spacing: 0.02em; }
.kind-badge {
  font-size: 11px; border-radius: 999px; padding: 2px 9px;
  border: 1px solid var(--border); color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.kind-badge.function { color: var(--accent); border-color: rgba(91, 154, 255, 0.45); background: var(--accent-soft); }
.kind-badge.rule { color: var(--warn); border-color: rgba(255, 191, 102, 0.45); background: rgba(255, 191, 102, 0.08); }

/* ---------- editor (grid-stacked overlay — keeps highlight aligned) ---------- */
.editor { flex: 1; display: flex; min-height: 0; background: var(--bg-inset); }
.gutter {
  flex: none; width: 48px; overflow: hidden;
  padding: 12px 0; text-align: right;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  color: var(--com); background: #070a12;
  border-right: 1px solid var(--border-soft);
  user-select: none;
}
.gutter div { padding-right: 12px; min-height: 19.5px; }
.gutter div.err-line { color: var(--err); font-weight: 700; }

.editwrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: grid;
}
.editwrap > .highlight,
.editwrap > textarea {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0;
  word-spacing: 0;
  font-variant-ligatures: none;
  font-feature-settings: normal;
  tab-size: 2;
  -moz-tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  overflow: auto;
  border: none;
  border-radius: 0;
}

.highlight { pointer-events: none; color: var(--text); background: transparent; }
.highlight code { display: block; min-height: 100%; margin: 0; }
.editwrap textarea {
  background: transparent;
  color: transparent;
  caret-color: var(--accent-2);
  resize: none;
  outline: none;
}
.editwrap textarea::selection { background: rgba(91, 154, 255, 0.35); color: transparent; }

.tok-kw { color: var(--kw); font-weight: 600; }
.tok-type { color: var(--type); }
.tok-str { color: var(--str); }
.tok-num { color: var(--num); }
.tok-com { color: var(--com); font-style: italic; }
.line-err {
  background: rgba(255, 112, 133, 0.16);
  box-shadow: inset 3px 0 0 var(--err);
  display: inline-block;
  width: 100%;
  margin: 0 -14px;
  padding: 0 14px;
}

/* ---------- status bar ---------- */
.statusbar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; font-size: 12px; font-family: var(--mono);
  background: #0e1424;
  border-top: 1px solid var(--border-soft);
  min-height: 32px; cursor: default;
}
.statusbar.ok #status-text { color: var(--ok); }
.statusbar.err { cursor: pointer; }
.statusbar.err:hover { background: rgba(255, 112, 133, 0.06); }
.statusbar.err #status-text { color: var(--err); }
.status-icon::before { content: "●"; color: var(--text-dim); }
.statusbar.ok .status-icon::before { color: var(--ok); }
.statusbar.err .status-icon::before { color: var(--err); }

/* ---------- output ---------- */
.target-chips {
  flex: none; display: flex; flex-wrap: wrap; gap: 5px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-soft);
}
.chip {
  font-size: 12px; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-panel-2);
  color: var(--text-dim); cursor: pointer; font-family: var(--mono);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); background: #1a2440; }
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-2);
  box-shadow: 0 0 0 1px rgba(91, 154, 255, 0.15) inset;
}
.output {
  flex: 1; margin: 0; padding: 12px 14px; overflow: auto;
  font-family: var(--mono); font-size: 13px; line-height: 1.55;
  background: var(--bg-inset); min-height: 0;
}
.output code { font-family: inherit; }
.output .out-err { color: var(--err); white-space: pre-wrap; }
.output .out-note { color: var(--text-dim); font-style: italic; white-space: pre-wrap; }
.output .out-kw { color: #79c0ff; }
.output .out-type { color: #ffa657; }
.output .out-str { color: #a5d6ff; }
.output .out-num { color: #d2a8ff; }
.output .out-com { color: var(--com); font-style: italic; }
.output .out-md-h { color: var(--accent-2); font-weight: 650; }
.output .out-md-meta { color: var(--text-dim); }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 280px minmax(0, 1fr);
    grid-template-rows: minmax(280px, 1fr) minmax(280px, 1fr);
  }
  .tutorial { grid-row: 1 / span 2; }
  .layout.tutorial-hidden { grid-template-columns: 0 minmax(0, 1fr); grid-template-rows: 1fr 1fr; }
}
@media (max-width: 820px) {
  .layout {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 8px;
  }
  .tutorial, .editor-pane, .output-pane { min-height: 340px; flex: none; }
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; }
}

/* ---------- footer ---------- */
.playground-footer {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 20px;
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}
.playground-footer a { color: var(--accent); text-decoration: none; }
.playground-footer a:hover { text-decoration: underline; }
.playground-footer .tm-note { opacity: 0.75; font-size: 11px; }
