:root {
  --bg: #fafaf7;
  --panel: #ffffff;
  --ink: #1c2230;
  --ink-soft: #5b6475;
  --line: #e6e4dd;
  --accent: #2563eb;
  --accent-ink: #1d4ed8;
  --accent-soft: #eff4ff;
  --good: #15803d;
  --bad: #b91c1c;
  --code-bg: #0f172a;
  --code-ink: #e2e8f0;
  --radius: 12px;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(250, 250, 247, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 28px; height: 60px;
}
.brand {
  font-weight: 800; font-size: 20px; color: var(--ink);
  letter-spacing: -0.02em;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); }
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 14px;
  color: var(--ink-soft);
}
.tab:hover { background: var(--accent-soft); text-decoration: none; }
.tab.active { background: var(--accent); color: #fff; }
.gh-link { margin-left: auto; font-size: 14px; font-weight: 600; color: var(--ink-soft); }

/* ---------- layout ---------- */
.tab-panel { display: none; max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }
.tab-panel.active { display: block; }

.hero { padding: 28px 0 20px; max-width: 720px; }
.hero h1 { font-size: 38px; letter-spacing: -0.03em; margin: 0 0 10px; line-height: 1.1; }
.hero p { color: var(--ink-soft); font-size: 17px; margin: 0; }
.hero-small { padding-top: 16px; }
.hero-small h1 { font-size: 30px; }

/* ---------- playground ---------- */
.playground {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px;
  margin-top: 8px;
}
@media (max-width: 900px) { .playground { grid-template-columns: 1fr; } }

.pane {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 1px 2px rgba(20, 24, 40, 0.04);
}
.pane-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: #fcfcfa; min-height: 48px; flex-wrap: wrap;
}
.pane-title { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.bar-spacer { flex: 1; }

.btn {
  font-family: var(--sans); font-weight: 600; font-size: 14px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 7px 16px; cursor: pointer; transition: background 0.15s;
}
.btn-run { background: var(--accent); color: #fff; }
.btn-run:hover { background: var(--accent-ink); }
.btn-run:disabled { background: #b6c4e3; cursor: wait; }
.btn-stop { background: var(--bad); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--accent-soft); }

#example-picker {
  font-family: var(--sans); font-size: 13px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
  max-width: 190px;
}
.trace-toggle { font-size: 13px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; cursor: pointer; }

#editor-host { min-height: 460px; }
#editor-host .CodeMirror { height: 460px; font-family: var(--mono); font-size: 14px; line-height: 1.6; }
#editor-host textarea.fallback {
  width: 100%; height: 460px; border: 0; padding: 14px;
  font-family: var(--mono); font-size: 14px; resize: vertical;
}

#output {
  flex: 1; margin: 0; padding: 14px; overflow: auto;
  background: var(--code-bg); color: var(--code-ink);
  font-family: var(--mono); font-size: 13.5px; line-height: 1.6;
  min-height: 460px; max-height: 510px; white-space: pre-wrap; word-break: break-word;
}
.out-dim { color: #748199; }
.out-err { color: #fca5a5; }
.out-ok { color: #86efac; }
.out-fail { color: #fca5a5; font-weight: 600; }
.out-trace { color: #93b4f8; }

/* ---------- practice ---------- */
.problem-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px; margin-top: 10px;
}
.problem-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; cursor: pointer; transition: border-color 0.15s, transform 0.1s;
}
.problem-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.problem-card h3 { margin: 0 0 6px; font-size: 17px; }
.problem-card p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.pill {
  display: inline-block; font-size: 11.5px; font-weight: 700;
  padding: 2px 9px; border-radius: 999px; margin-bottom: 10px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.pill.easy { background: #dcfce7; color: var(--good); }
.pill.medium { background: #fef3c7; color: #b45309; }

.problem-detail { max-width: 860px; }
.back-link { display: inline-block; margin: 6px 0 14px; font-weight: 600; cursor: pointer; }
.problem-detail h2 { font-size: 28px; margin: 4px 0 4px; letter-spacing: -0.02em; }
.problem-detail .statement { color: var(--ink); font-size: 15.5px; }
.code-block {
  background: var(--code-bg); color: var(--code-ink); border-radius: 10px;
  padding: 14px 16px; font-family: var(--mono); font-size: 13.5px; line-height: 1.6;
  overflow: auto; white-space: pre; margin: 12px 0;
}
.detail-actions { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
details.reveal {
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  padding: 12px 16px; margin: 10px 0;
}
details.reveal summary { font-weight: 700; cursor: pointer; color: var(--accent-ink); }
.explanation p { font-size: 15px; }
.explanation li { font-size: 15px; margin-bottom: 6px; }

/* ---------- docs ---------- */
.docs-layout {
  display: grid; grid-template-columns: 230px 1fr 340px; gap: 20px; margin-top: 8px;
}
@media (max-width: 1080px) {
  .docs-layout { grid-template-columns: 1fr; }
  .docs-side { position: static; }
  .chat-panel { position: static; height: 420px; }
}
.docs-side { position: sticky; top: 76px; align-self: start; }
#docs-search {
  width: 100%; padding: 10px 12px; font-family: var(--sans); font-size: 14px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  margin-bottom: 14px;
}
#docs-search:focus { outline: 2px solid var(--accent); border-color: transparent; }
#docs-nav a {
  display: block; padding: 6px 10px; border-radius: 8px;
  color: var(--ink-soft); font-size: 14px; font-weight: 600;
}
#docs-nav a:hover { background: var(--accent-soft); text-decoration: none; }

.docs-main { min-width: 0; }
.docs-cat { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); margin: 26px 0 10px; }
.docs-cat:first-child { margin-top: 4px; }
.doc-entry {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 12px;
}
.doc-entry h3 { margin: 0 0 6px; font-size: 17px; }
.doc-entry .doc-desc { margin: 0 0 10px; color: var(--ink); font-size: 14.5px; }
.doc-syntax {
  font-family: var(--mono); font-size: 13px; color: var(--accent-ink);
  background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px;
  white-space: pre-wrap;
}
.doc-entry .code-block { margin: 0; font-size: 13px; }
.doc-try { font-size: 13px; font-weight: 600; cursor: pointer; color: var(--accent-ink); background: none; border: none; padding: 6px 0 0; }
.no-results { color: var(--ink-soft); padding: 20px 4px; }

/* ---------- chat ---------- */
.chat-panel {
  position: sticky; top: 76px; align-self: start;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; height: calc(100vh - 110px); max-height: 720px;
  overflow: hidden;
}
.chat-head {
  padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 14px;
  display: flex; align-items: center; gap: 8px; background: #fcfcfa;
}
.chat-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg {
  max-width: 92%; padding: 10px 13px; border-radius: 12px; font-size: 14px;
}
.chat-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.bot { align-self: flex-start; background: #f1f0ec; border-bottom-left-radius: 4px; }
.chat-msg.bot code, .chat-msg.bot pre {
  font-family: var(--mono); font-size: 12.5px;
}
.chat-msg.bot pre {
  background: var(--code-bg); color: var(--code-ink); padding: 10px; border-radius: 8px;
  overflow-x: auto; margin: 8px 0 2px; white-space: pre-wrap;
}
.chat-msg.bot .chat-title { font-weight: 700; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
#chat-input {
  flex: 1; padding: 9px 12px; font-family: var(--sans); font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px;
}
#chat-input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--line); padding: 22px 20px 40px; text-align: center;
  color: var(--ink-soft); font-size: 13.5px;
}
.site-footer a { margin-left: 8px; }
