*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-code: #12141c;
  --bg-sidebar: #14161e;
  --border: #2a2f3d;
  --text: #e8eaed;
  --text-muted: #8b93a7;
  --accent: #68217a;
  --accent-light: #9b4dca;
  --accent-glow: rgba(104, 33, 122, 0.25);
  --radius: 10px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --sidebar-width: 380px;
  --header-height: 56px;
}

html { scroll-behavior: smooth; }

/* hide ugly default scrollbars, scroll still works */
.sidebar,
.content-panel,
.lang-screen {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar::-webkit-scrollbar,
.content-panel::-webkit-scrollbar,
.lang-screen::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.hidden { display: none !important; }

/* ── UI language screen ── */
.lang-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, var(--accent-glow) 0%, transparent 60%), var(--bg);
  padding: 1.5rem;
}

.lang-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3rem 2.5rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.lang-card .logo {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 2rem;
  color: var(--text);
}

.lang-card .logo span { color: var(--accent-light); }

.lang-card h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.5rem; }

.lang-card .subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2rem;
}

.lang-buttons { display: flex; flex-direction: column; gap: 0.75rem; }

.lang-btn {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.lang-btn:hover {
  border-color: var(--accent-light);
  background: var(--accent-glow);
}

.lang-flag { font-size: 1.4rem; }

/* ── App ── */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.header {
  border-bottom: 1px solid var(--border);
  background: rgba(15, 17, 23, 0.95);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 100%;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.logo span { color: var(--accent-light); }

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

.nav-link:hover { color: var(--text); }

.nav-link.active {
  color: var(--text);
  background: var(--bg-card);
}

/* Programming languages in header */
.lang-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 1rem;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
}

.lang-nav-btn {
  padding: 0.35rem 0.75rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
}

.lang-nav-btn:hover:not(.disabled) {
  color: var(--text);
  background: var(--bg-card);
  border-color: var(--border);
}

.lang-nav-btn.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.lang-nav-btn.disabled {
  opacity: 0.35;
  cursor: default;
}

.header-right { margin-left: auto; }

.ui-lang-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

.ui-lang-btn:hover { border-color: var(--accent-light); }

/* ── Main ── */
.main { flex: 1; }

.main:has(.course-layout:not(.hidden)) {
  padding: 0;
  overflow: hidden;
}

.app:has(.course-layout:not(.hidden)) .footer {
  display: none;
}

.view { min-height: calc(100vh - var(--header-height)); }

/* Home */
.hero {
  max-width: 700px;
  margin: 0 auto;
  padding: 4rem 1.5rem;
  text-align: center;
}

.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
}

/* ── Course layout: sidebar + content ── */
.course-layout {
  display: flex;
  width: 100%;
  height: calc(100vh - var(--header-height));
  min-height: calc(100vh - var(--header-height));
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100%;
  overflow-y: auto;
}

.sidebar-topics {
  padding: 0.5rem 0;
  flex: 1;
}

/* ── Tree sidebar ── */
.tree-block {
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.tree-block:last-child {
  border-bottom: none;
}

.tree-block-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.tree-block-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.tree-block-title {
  flex: 1;
  line-height: 1.3;
}

.tree-icon-block {
  color: var(--accent-light);
}

.tree-block-chapters {
  display: none;
  padding-bottom: 0.25rem;
}

.tree-block.open .tree-block-chapters {
  display: block;
}

.tree-block-chapters .tree-chapter-btn {
  padding-left: 1.1rem;
  font-size: 0.84rem;
  font-weight: 500;
}

.tree-block-chapters .tree-lessons {
  padding-left: 2.2rem;
}

.tree-chapter {
  margin-bottom: 2px;
}

.tree-chapter-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.tree-chapter-btn:hover {
  background: rgba(255, 255, 255, 0.04);
}

.tree-arrow {
  width: 12px;
  font-size: 0.55rem;
  color: var(--text-muted);
  flex-shrink: 0;
  text-align: center;
}

.tree-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.tree-chapter-btn .tree-icon {
  color: #8b93a7;
}

.tree-chapter-title {
  flex: 1;
  line-height: 1.35;
}

.tree-lessons {
  display: none;
  padding-left: 1.6rem;
}

.tree-chapter.open .tree-lessons {
  display: block;
}

.tree-lesson-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  width: 100%;
  padding: 0.4rem 0.75rem 0.4rem 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  border-radius: 4px;
}

.tree-lesson-btn:hover:not(.disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.tree-lesson-btn.active {
  color: var(--accent-light);
  background: var(--accent-glow);
}

.tree-lesson-btn.disabled {
  opacity: 0.4;
  cursor: default;
}

.tree-lesson-title {
  flex: 1;
  line-height: 1.4;
}

.tree-lesson-btn .tree-icon {
  margin-top: 2px;
  width: 14px;
  height: 14px;
}

/* Content panel */
.content-panel {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 3rem;
  height: 100%;
  min-height: 0;
}

.lesson-article h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.lesson-desc {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.lesson-section { margin-bottom: 2rem; }

.lesson-section h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.lesson-section p {
  color: #c4c9d4;
  margin-bottom: 0.75rem;
  font-size: 0.97rem;
}

.lesson-section ul {
  padding-left: 1.5rem;
  color: #c4c9d4;
  font-size: 0.97rem;
  margin-bottom: 0.75rem;
}

.lesson-section li { margin-bottom: 0.35rem; }

.lesson-section code {
  background: var(--bg-code);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.85em;
}

.code-block {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-x: auto;
  margin: 1rem 0;
}

.code-block pre {
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.7;
  color: #cdd6f4;
  white-space: pre;
}

.code-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.tip-box {
  background: rgba(62, 207, 142, 0.08);
  border: 1px solid rgba(62, 207, 142, 0.25);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  font-size: 0.92rem;
  color: #a8e6c8;
}

.empty-lesson,
.lesson-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

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

@media (max-width: 768px) {
  :root { --sidebar-width: 100%; }

  .course-layout {
    flex-direction: column;
    height: calc(100vh - var(--header-height));
  }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: 240px;
    min-height: 0;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .content-panel {
    flex: 1;
    min-height: 0;
  }

  .content-panel { padding: 1.5rem 1rem; }

  .lang-nav { display: none; }
}
