:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #5b6472;
  --border: #e1e4ea;
  --accent: #4f46e5;
  --accent-soft: #eceafe;
  --code-bg: #0f1420;
  --code-head: #181e2d;
  --code-text: #e6e9ef;
  --tk-c: #7d8799;
  --tk-s: #9ece6a;
  --tk-n: #ff9e64;
  --tk-k: #bb9af7;
  --tk-t: #7dcfff;
  --radius: 12px;
  --topbar-h: 58px;
}

html[data-theme="dark"] {
  --bg: #0d1016;
  --surface: #151a23;
  --text: #e6e9ef;
  --muted: #9aa4b2;
  --border: #262d39;
  --accent: #8b8cf8;
  --accent-soft: #23254a;
  --code-bg: #090c12;
  --code-head: #121723;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
}

a { color: var(--accent); }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}
.brand span { color: var(--accent); }

.search {
  flex: 1;
  min-width: 0;
  max-width: 460px;
  margin-left: auto;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.pill-link {
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); }
.menu-btn { display: none; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 18px 14px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.sidebar h3 {
  margin: 14px 10px 6px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.side-link:hover { background: var(--accent-soft); }
.side-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--lang, var(--accent));
  flex: none;
}

.main {
  padding: 28px clamp(16px, 4vw, 48px) 60px;
  max-width: 980px;
  width: 100%;
}

/* Home */
.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.15;
}
.hero p { margin: 0 0 24px; color: var(--muted); font-size: 1.08rem; max-width: 62ch; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.card {
  display: block;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--lang, var(--accent));
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.12); }
.card h3 { margin: 0 0 4px; }
.card p { margin: 0 0 10px; color: var(--muted); font-size: 0.93rem; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
}

/* Language page */
.lang-head { border-left: 6px solid var(--lang, var(--accent)); padding-left: 16px; margin-bottom: 18px; }
.lang-head h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.3rem); }
.lang-head p { margin: 4px 0 8px; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 8px; }

.chips {
  position: sticky;
  top: var(--topbar-h);
  z-index: 5;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0;
  margin-bottom: 8px;
  background: var(--bg);
}
.chip {
  white-space: nowrap;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}
.chip:hover, .chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.lesson {
  scroll-margin-top: calc(var(--topbar-h) + 64px);
  padding: 22px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.lesson h2 { margin: 0 0 6px; font-size: 1.3rem; }
.lesson p { margin: 0 0 14px; color: var(--muted); }

/* Code blocks */
.code {
  border-radius: 10px;
  overflow: hidden;
  background: var(--code-bg);
  margin-top: 6px;
}
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: var(--code-head);
  color: #9aa4b2;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}
.copy-btn {
  border: 1px solid #2c3446;
  background: transparent;
  color: #c6cdda;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
}
.copy-btn:hover { background: #232b3d; }

.code pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  color: var(--code-text);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.55;
  tab-size: 4;
}

.tk-c { color: var(--tk-c); font-style: italic; }
.tk-s { color: var(--tk-s); }
.tk-n { color: var(--tk-n); }
.tk-k { color: var(--tk-k); }
.tk-t { color: var(--tk-t); }

/* Compare + search */
.section-title { margin: 0 0 6px; font-size: 1.6rem; }
.hint { color: var(--muted); margin: 0 0 14px; }

.compare-block { margin-bottom: 18px; }
.compare-block h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; }

.result {
  display: block;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.result:hover { border-color: var(--accent); }
.result strong { display: block; }
.result span { color: var(--muted); font-size: 0.92rem; }

.empty { color: var(--muted); padding: 24px 0; }

.footer {
  padding: 22px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  border-top: 1px solid var(--border);
}

/* Mobile */
@media (max-width: 800px) {
  .menu-btn { display: inline-block; }
  .layout { display: block; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: 270px;
    height: auto;
    z-index: 15;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 24px rgba(0, 0, 0, 0.25); }
  .pill-link { display: none; }
  .brand span { display: none; }
}
