:root {
  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --bg-elevated-2: #fbfbfd;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #98989d;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --java-accent: #f89820;
  --border: rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.12);
  --radius-lg: 20px;
  --radius-md: 12px;
  --code-bg: #1d1f21;
  --code-text: #e6e6e6;
  --sidebar-w: 300px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-elevated-2: #131315;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --text-tertiary: #6e6e73;
    --border: rgba(255, 255, 255, 0.12);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
    --code-bg: #0d0e10;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Inter", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  border-bottom: 1px solid var(--border);
  height: 56px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--java-accent), #ffb85c);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.ghost-link { color: var(--text-secondary); font-size: 14px; text-decoration: none; }
.ghost-link:hover { color: var(--text); }
.sidebar-toggle {
  display: none; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
  align-items: center; justify-content: center; cursor: pointer;
}

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: calc(100vh - 56px); }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-elevated-2);
  overflow-y: auto;
  height: calc(100vh - 56px);
  position: sticky; top: 56px;
  padding: 16px 12px 40px;
}
.sidebar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 999px; padding: 9px 14px; margin-bottom: 14px;
}
.sidebar-search svg { flex-shrink: 0; color: var(--text-tertiary); }
.sidebar-search input {
  border: none; background: none; outline: none; font-size: 14px;
  color: var(--text); width: 100%; font-family: inherit;
}

.nav-category { margin-bottom: 2px; }
.nav-category-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px; border: none; background: none;
  color: var(--text); font-size: 13.5px; font-weight: 600; text-align: left;
  cursor: pointer; font-family: inherit;
}
.nav-category-btn:hover { background: var(--bg-elevated); }
.nav-category-btn .cat-icon { flex-shrink: 0; color: var(--java-accent); display: flex; }
.nav-category-btn .cat-count {
  margin-left: auto; font-size: 11px; font-weight: 500; color: var(--text-tertiary);
  background: var(--bg-elevated); padding: 1px 7px; border-radius: 999px;
}
.nav-category-btn .chevron { transition: transform 0.18s ease; color: var(--text-tertiary); flex-shrink: 0; }
.nav-category.open .chevron { transform: rotate(90deg); }

.nav-topics { list-style: none; margin: 2px 0 8px; padding: 0; display: none; }
.nav-category.open .nav-topics { display: block; }
.nav-topics li { margin: 1px 0; }
.nav-topics a {
  display: block; padding: 7px 14px 7px 38px; border-radius: 8px;
  font-size: 13.5px; color: var(--text-secondary);
}
.nav-topics a:hover { background: var(--bg-elevated); color: var(--text); }
.nav-topics a.active { background: var(--accent); color: #fff; }
.nav-topics a.not-ready { color: var(--text-tertiary); }
.nav-topics a.not-ready::after { content: "soon"; font-size: 10px; margin-left: 6px; opacity: 0.7; }

.sidebar-hidden-msg { padding: 10px 14px; font-size: 13px; color: var(--text-tertiary); display: none; }

/* ---------- Content ---------- */
.content-area { flex: 1; min-width: 0; }
.content-inner { max-width: 760px; margin: 0 auto; padding: 40px 28px 100px; }

/* Home / landing */
.hero {
  display: flex; align-items: center; gap: 40px; padding: 20px 0 44px;
  border-bottom: 1px solid var(--border); margin-bottom: 36px; flex-wrap: wrap;
}
.hero-text { flex: 1; min-width: 260px; }
.hero-text .eyebrow { font-size: 13px; font-weight: 600; color: var(--java-accent); margin: 0 0 10px; }
.hero-text h1 { font-size: clamp(28px, 4vw, 38px); margin: 0 0 14px; letter-spacing: -0.01em; line-height: 1.1; }
.hero-text p { font-size: 16px; color: var(--text-secondary); line-height: 1.6; margin: 0 0 20px; max-width: 480px; }
.hero-image { width: 220px; flex-shrink: 0; }
.hero-image img { width: 100%; height: auto; display: block; }
.hero-stats { display: flex; gap: 22px; flex-wrap: wrap; }
.hero-stat strong { display: block; font-size: 22px; }
.hero-stat span { font-size: 12.5px; color: var(--text-secondary); }

.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.category-card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 16px; display: flex; align-items: center; gap: 12px; transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.category-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.category-card .cat-icon { color: var(--java-accent); flex-shrink: 0; }
.category-card .cat-name { font-size: 13.5px; font-weight: 600; }
.category-card .cat-count { font-size: 12px; color: var(--text-tertiary); }

/* Topic page */
.breadcrumb { font-size: 13px; color: var(--text-tertiary); margin-bottom: 10px; }
.breadcrumb a:hover { color: var(--accent); }
.topic-title { font-size: clamp(26px, 4vw, 34px); margin: 0 0 10px; letter-spacing: -0.01em; line-height: 1.15; }
.topic-summary { font-size: 16px; color: var(--text-secondary); line-height: 1.6; margin: 0 0 32px; }

.topic-body { font-size: 16px; line-height: 1.75; }
.topic-body h3 { font-size: 19px; margin: 32px 0 12px; letter-spacing: -0.005em; }
.topic-body p { margin: 0 0 16px; }
.topic-body ul { margin: 0 0 16px; padding-left: 22px; }
.topic-body li { margin-bottom: 6px; }
.topic-body strong { font-weight: 600; }
.topic-body code {
  font-family: "SF Mono", "SFMono-Regular", ui-monospace, Menlo, monospace;
  background: var(--bg-elevated-2); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 6px; font-size: 0.88em;
}
.topic-body pre {
  background: var(--code-bg); color: var(--code-text); border-radius: var(--radius-md);
  padding: 18px 20px; overflow-x: auto; margin: 0 0 20px; box-shadow: var(--shadow-sm);
}
.topic-body pre code {
  background: none; border: none; padding: 0; font-size: 13.5px; line-height: 1.6; color: inherit;
}

.topic-nav { display: flex; justify-content: space-between; gap: 16px; margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border); }
.topic-nav-link {
  flex: 1; max-width: 48%; display: flex; flex-direction: column; gap: 4px;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-elevated);
}
.topic-nav-link:hover { border-color: var(--accent); }
.topic-nav-link.next { text-align: right; margin-left: auto; }
.topic-nav-link .nav-dir { font-size: 11.5px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; }
.topic-nav-link .nav-title { font-size: 14px; font-weight: 600; }

.coming-soon-box {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px;
  padding: 56px 24px; background: var(--bg-elevated); border: 1px dashed var(--border); border-radius: var(--radius-lg);
}
.coming-soon-box svg { color: var(--java-accent); }
.coming-soon-box p { color: var(--text-secondary); font-size: 14.5px; max-width: 360px; margin: 0; }

.not-found-box { text-align: center; padding: 80px 20px; color: var(--text-secondary); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar-toggle { display: flex; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; z-index: 55;
    transform: translateX(-100%); transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg); width: min(86vw, 320px);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none; position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,0.35); z-index: 54;
  }
  .sidebar-overlay.open { display: block; }
  .content-inner { padding: 28px 18px 80px; }
  .hero { flex-direction: column-reverse; text-align: center; gap: 20px; }
  .hero-text p { max-width: none; }
  .hero-stats { justify-content: center; }
  .topic-nav { flex-direction: column; }
  .topic-nav-link { max-width: none; }
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
