/* =========================================================
   TOKENS
   ========================================================= */
:root{
  /* Dark Code style ink-navy base with a subtle blue undertone */
  --bg: #080B12;
  --bg-elevated: #0E141F;
  --surface: rgba(140,160,255,0.045);
  --surface-solid: #121A28;
  --ink: #EEF2F9;
  --ink-soft: #AAB6CA;
  --muted: #71809A;
  --border: rgba(160,180,255,0.12);
  --border-soft: rgba(160,180,255,0.065);

  /* glass tokens (floating pill / glassmorphism surfaces) */
  --glass-bg: rgba(255,255,255,0.045);
  --glass-bg-strong: rgba(150,170,255,0.09);
  --glass-border: rgba(255,255,255,0.09);
  --glass-border-strong: rgba(170,195,255,0.22);

  /* signal (cyan-mint), sky (blue), violet, ember (orange), slate */
  --green: #2BE7C0;   --green-soft: rgba(43,231,192,0.14);   --green-text: #7CF4DA;
  --blue: #4EA8FF;    --blue-soft: rgba(78,168,255,0.14);    --blue-text: #9AC9FF;
  --purple: #9F7BFF;  --purple-soft: rgba(159,123,255,0.17); --purple-text: #C9B8FF;
  --amber: #FF9B4D;   --amber-soft: rgba(255,155,77,0.16);   --amber-text: #FFC48F;
  --slate: #8FA1BE;   --slate-soft: rgba(143,161,190,0.14);  --slate-text: #C7D3E5;

  --accent: var(--green);
  --accent-soft: var(--green-soft);
  --accent-text: var(--green-text);

  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, monospace;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35), 0 1px 1px rgba(0,0,0,.25);
  --shadow-md: 0 10px 28px rgba(0,0,0,.45), 0 2px 8px rgba(0,0,0,.32);
  --shadow-lg: 0 22px 54px rgba(2,4,10,.6);
  --sidebar-w: 300px;
  --header-h: 104px;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
html{ scrollbar-width:none; -ms-overflow-style:none; }
html::-webkit-scrollbar{ width:0; height:0; display:none; }
body{
  margin:0;
  background-color: var(--bg);
  /* ambient orb glow, matching Dark Code's ink-navy canvas */
  background-image:
    radial-gradient(720px 420px at 8% -6%, rgba(43,231,192,0.10), transparent 60%),
    radial-gradient(680px 460px at 108% 8%, rgba(159,123,255,0.09), transparent 60%),
    radial-gradient(900px 600px at 50% 115%, rgba(78,168,255,0.06), transparent 60%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1,h2,h3{ font-family: var(--font-display); margin:0; color:var(--ink); }
p{ margin:0; line-height:1.65; color: var(--ink-soft); }
code{ font-family: var(--font-mono); }
button{ font-family: inherit; cursor:pointer; }
:focus-visible{ outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce){ *{ animation-duration: .001ms !important; transition-duration: .001ms !important; } }

/* =========================================================
   APP SHELL
   ========================================================= */
.app-shell{
  display:flex;
  min-height:100vh;
  max-width: var(--container, 1240px);
  margin: 0 auto;
  padding: 0 24px;
  gap: 22px;
  align-items: flex-start;
}

/* ---------------- Sidebar ---------------- */
/* Floating glass card, inset within the same left/right bounds as the
   site header, with breathing room above/below instead of touching
   the viewport edges. */
.sidebar{
  width: var(--sidebar-w);
  flex-shrink:0;
  height: calc(100vh - 104px - 40px);
  position: sticky; top:124px;
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow-md);
  display:flex; flex-direction:column;
  overflow: hidden;
  padding: 20px 0 0;
}
.sidebar-brand{ display:flex; align-items:center; gap:11px; padding: 4px 20px 18px; border-bottom:1px solid var(--border-soft); margin-bottom:14px;}
.topic-topic-brand-mark{
  width:34px; height:34px; border-radius:9px;
  background: linear-gradient(135deg, var(--green), var(--purple));
  color:#0A0E17; font-family:var(--font-display); font-weight:700; font-size:14px;
  display:flex; align-items:center; justify-content:center;
  box-shadow: 0 4px 14px rgba(43,231,192,.25);
}
.topic-topic-brand-text{ display:flex; flex-direction:column; line-height:1.25; }
.topic-topic-brand-title{ font-family:var(--font-display); font-weight:600; font-size:15px; }
.topic-topic-brand-sub{ font-size:11.5px; color:var(--muted); letter-spacing:.02em; }

.sidebar-search-wrap{ position:relative; margin: 0 16px 14px; }
.search-icon{ position:absolute; left:11px; top:50%; transform:translateY(-50%); color:var(--muted); pointer-events:none; }
#sidebar-search{
  width:100%; padding:9px 12px 9px 34px; border-radius:10px;
  border:1px solid var(--border); background: var(--bg);
  font-size:13.5px; color:var(--ink); font-family:var(--font-body);
  transition: border-color .15s, box-shadow .15s;
}
#sidebar-search:focus{ outline:none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,.12); }

.sidebar-nav{ flex:1; overflow-y:auto; padding: 2px 10px 24px; }
.sidebar-nav::-webkit-scrollbar{ width:6px; }
.sidebar-nav::-webkit-scrollbar-thumb{ background: rgba(160,180,255,0.18); border-radius:6px; }

.nav-category{ margin-bottom: 4px; }
.nav-category-head{
  width:100%; display:flex; align-items:center; gap:9px;
  padding:9px 10px; background:none; border:none; border-radius:9px;
  font-family: var(--font-display); font-weight:600; font-size:11.5px;
  letter-spacing:.06em; text-transform:uppercase; color: var(--ink-soft);
  transition: background .15s;
}
.nav-category-head:hover{ background: var(--bg); }
.nav-dot{ width:7px; height:7px; border-radius:50%; flex-shrink:0; }
.nav-category-title{ flex:1; text-align:left; }
.chev{ color:var(--muted); transition: transform .2s; }
.nav-category-head.closed .chev{ transform: rotate(90deg); }

.nav-list{ display:flex; flex-direction:column; gap:1px; padding: 2px 0 10px 4px; overflow:hidden; max-height:900px; transition: max-height .25s ease, opacity .2s ease; opacity:1; }
.nav-list.closed{ max-height:0; opacity:0; padding-top:0; padding-bottom:0; }

.topic-nav-item{
  display:flex; align-items:center; gap:9px; text-align:left;
  padding:7.5px 10px 7.5px 14px; border:none; background:none; border-radius:8px;
  font-size:13.3px; color: var(--ink-soft); position:relative;
  transition: background .12s, color .12s;
}
.topic-nav-item:hover{ background: var(--bg); color: var(--ink); }
.topic-nav-item-num{ font-family: var(--font-mono); font-size:11px; color: var(--muted); flex-shrink:0; width:26px; }
.topic-nav-item-title{ line-height:1.3; }
.topic-nav-item.active{ background: var(--accent-soft, var(--green-soft)); color: var(--ink); font-weight:600; }
.topic-nav-item.active::before{
  content:""; position:absolute; left:0; top:8px; bottom:8px; width:3px; border-radius:3px;
  background: var(--green);
}
.nav-empty{ padding:16px 12px; font-size:13px; color:var(--muted); }

.sidebar-scrim{ display:none; }

/* glassmorphism: blur behind every translucent surface card */
.vis-card, .output-card, .chart-card, .func-card, .practice-card,
.practice-box, .hint-box, .rel-card, .stub-card, .flow-step{
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ---------------- Mobile top bar (topic sidebar toggle) ---------------- */
.topic-mobile-topbar{ display:none; }

/* ---------------- Main content ---------------- */
.main-scroll{
  flex:1; min-width:0; height:100vh; overflow-y:auto; scroll-behavior:smooth; padding-top:20px;
  scrollbar-width:none;      /* Firefox */
  -ms-overflow-style:none;   /* old Edge / IE */
}
.main-scroll::-webkit-scrollbar{ width:0; height:0; display:none; } /* Chrome / Safari / new Edge */
.lesson-root{ max-width: 980px; margin: 0 auto; padding: 44px 48px 100px; opacity:0; transform: translateY(6px); }
.lesson-root.show{ opacity:1; transform:none; transition: opacity .35s ease, transform .35s ease; }

/* =========================================================
   LESSON HEADER
   ========================================================= */
.lesson-header{ margin-bottom: 36px; }
.eyebrow{
  display:flex; align-items:center; gap:10px;
  font-family: var(--font-mono); font-size:12.5px; color: var(--accent-text);
  text-transform:uppercase; letter-spacing:.07em; margin-bottom:10px; font-weight:600;
}
.level-pill{
  font-family: var(--font-body); text-transform:none; letter-spacing:0;
  background: var(--accent-soft); color: var(--accent-text);
  padding:2px 9px; border-radius:20px; font-size:11.5px; font-weight:600;
}
.lesson-header h1{ font-size: 34px; font-weight:700; letter-spacing:-.01em; margin-bottom:10px; }
.tagline{ font-size:16px; color: var(--muted); max-width: 640px; }

/* =========================================================
   SECTIONS
   ========================================================= */
.section{ margin-bottom: 44px; padding-top: 6px; }
.section-head{ display:flex; align-items:baseline; gap:12px; margin-bottom:18px; }
.section-num{
  font-family: var(--font-mono); font-size:12px; color: var(--accent);
  background: var(--accent-soft); border-radius:6px; padding:3px 7px; font-weight:600;
}
.section-head h2{ font-size:19px; font-weight:600; }

/* ---------- Section 1: intro ---------- */
.intro-grid{ display:flex; flex-direction:column; gap:22px; }
.intro-text p{ font-size:15px; margin-bottom:16px; }
.realworld{ background: var(--accent-soft); border-radius: var(--radius-md); padding:14px 16px; border:1px solid var(--border-soft); }
.realworld-label{ display:block; font-family:var(--font-display); font-size:11.5px; font-weight:600; text-transform:uppercase; letter-spacing:.05em; color:var(--accent-text); margin-bottom:5px; }
.realworld p{ font-size:14px; color: var(--ink-soft); }

.flow-diagram{ display:flex; align-items:center; gap:6px; flex-wrap: nowrap; overflow-x:auto; padding: 6px 2px; }
.flow-diagram--wrap{ flex-wrap:wrap; }
.flow-step{
  flex-shrink:0; background: var(--surface); border:1.5px solid var(--border);
  border-radius: var(--radius-sm); padding:10px 16px; font-size:13.5px; font-weight:600;
  color: var(--ink); box-shadow: var(--shadow-sm); white-space:nowrap;
}
.flow-arrow{ color: var(--accent); font-size:16px; flex-shrink:0; }

/* ---------- Section 2: concept visuals ---------- */
.visual-stack{ display:flex; flex-direction:column; gap:18px; }
.vis-card{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-lg);
  padding:20px 22px; box-shadow: var(--shadow-sm);
}
.vis-title{ font-family:var(--font-display); font-weight:600; font-size:14.5px; margin-bottom:14px; color:var(--ink); }
.vis-caption{ margin-top:12px; font-size:13px; color:var(--muted); font-style:italic; }

/* mini tables shared */
.mini-table{ border-collapse: collapse; width:100%; font-size:13.5px; }
.mini-table th, .mini-table td{ padding:8px 14px; text-align:left; border-bottom:1px solid var(--border-soft); }
.mini-table thead th{
  font-family:var(--font-display); font-size:11.5px; text-transform:uppercase; letter-spacing:.04em;
  color: var(--muted); font-weight:600; border-bottom:2px solid var(--border);
}
.mini-table tbody tr:last-child td{ border-bottom:none; }
.mini-table tbody tr:hover{ background: var(--bg); }

.series-table .idx{ color: var(--muted); font-family:var(--font-mono); width:60px; }
.series-table td:nth-child(2){ font-family:var(--font-mono); font-weight:600; }

.df-table .idx-col{ width:40px; color:var(--muted); font-family:var(--font-mono); background: var(--slate-soft); font-size:12px; }
.df-table thead th{ background: var(--bg); }
.df-table.df-highlight thead th{ background: var(--accent-soft); color: var(--accent-text); }
.df-table .col-flag{ background: var(--accent-soft); font-weight:700; color:var(--accent-text); }

.df-legend{ display:flex; gap:16px; margin-top:14px; font-size:12px; color:var(--muted); }
.df-legend .dot{ display:inline-block; width:8px; height:8px; border-radius:2px; margin-right:5px; }
.dot-idx{ background: var(--slate); } .dot-col{ background: var(--accent); } .dot-row{ background: var(--border); border:1px solid var(--muted); }

.before-after{ display:flex; align-items:center; gap:18px; flex-wrap:wrap; }
.ba-col{ flex:1; min-width:200px; }
.ba-label{ font-size:11.5px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); margin-bottom:8px; }
.ba-before .mini-table{ background: rgba(248,113,113,0.10); border-radius:8px; overflow:hidden;}
.ba-before .ba-label{ color:#FB9494; }
.ba-after .mini-table{ background: var(--accent-soft); border-radius:8px; overflow:hidden; }
.ba-after .ba-label{ color: var(--accent-text); }
.ba-arrow{ font-size:20px; color:var(--muted); flex-shrink:0; }

.kv-table .kv-key{ color:var(--muted); font-weight:600; width:40%; }
.kv-table .kv-val{ font-family:var(--font-mono); font-weight:600; color:var(--ink); }

/* ---------- Section 3: code ---------- */
.code-grid{ display:grid; grid-template-columns: 1.6fr 1fr; gap:18px; align-items:start; }
.code-block{
  background:#0A0F18; border:1px solid var(--border-soft); border-radius: var(--radius-lg); overflow:hidden; box-shadow: var(--shadow-md);
}
.code-toolbar{ display:flex; align-items:center; gap:10px; padding:10px 14px; background:#101827; border-bottom:1px solid #1E2A3D; }
.code-dots{ display:flex; gap:6px; }
.code-dots span{ width:9px; height:9px; border-radius:50%; background:#354258; }
.code-lang{ font-family:var(--font-mono); font-size:11.5px; color:#7C8CA6; flex:1; }
.copy-btn{
  display:flex; align-items:center; gap:5px; background:#1B2536; color:#C4CEE0; border:1px solid #2A3750;
  padding:5px 10px; border-radius:7px; font-size:12px; font-weight:500; transition: background .15s, color .15s;
}
.copy-btn:hover{ background:#243244; color:#fff; }
.copy-btn.copied{ background: var(--green); border-color: var(--green); color:#06251F; }
.code-pre{ margin:0; padding:16px 0; overflow-x:auto; font-family:var(--font-mono); font-size:13px; line-height:1.75; }
.code-line{ display:flex; padding:0 18px; }
.line-no{ width:28px; flex-shrink:0; color:#3D4C64; user-select:none; text-align:right; margin-right:16px; }
.line-content{ white-space:pre; color:#DCE4F0; }
.tok-keyword{ color:#FF7EA6; }
.tok-string{ color:#7CE7C0; }
.tok-number{ color:#7DC4FF; }
.tok-func{ color:#C3A6FF; }
.tok-comment{ color:#5A6C88; font-style:italic; }

.code-explain{
  background: var(--accent-soft); border:1px solid var(--border-soft); border-radius: var(--radius-lg);
  padding:18px 20px; height:100%;
}
.explain-badge{ font-family:var(--font-display); font-size:11.5px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color: var(--accent-text); margin-bottom:9px; }
.code-explain p{ font-size:13.8px; color: var(--ink-soft); }

/* ---------- Section 4: output ---------- */
.output-card{ background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-lg); padding:18px 20px; box-shadow: var(--shadow-sm); }
.output-tag{
  display:inline-block; font-family:var(--font-mono); font-size:11px; color: var(--green-text); background: var(--green-soft);
  border:1px solid rgba(43,231,192,0.28);
  padding:3px 9px; border-radius:6px; margin-bottom:14px; letter-spacing:.03em;
}
.output-text{ font-family:var(--font-mono); font-size:13.5px; color: var(--ink); background:var(--bg); padding:14px 16px; border-radius:9px; margin:0; white-space:pre-wrap; }
.output-dtype{ margin-top:10px; font-family:var(--font-mono); font-size:12px; color:var(--muted); }

/* ---------- Section 5: charts ---------- */
.chart-grid{ display:grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap:18px; }
.chart-card{ background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-lg); padding:18px 20px 8px; box-shadow: var(--shadow-sm); }
.chart-title{ font-family:var(--font-display); font-weight:600; font-size:14px; margin-bottom:8px; }
.chart-svg{ width:100%; height:auto; overflow:visible; }
.axis-line{ stroke:var(--border); stroke-width:1.5; }
.bar-val{ font-family:var(--font-mono); font-size:10.5px; fill:var(--ink-soft); font-weight:600; }
.bar-lbl{ font-family:var(--font-body); font-size:11px; fill:var(--muted); }
.pie-wrap{ display:flex; align-items:center; gap:14px; flex-wrap:wrap; }
.pie-svg{ width:180px; height:auto; flex-shrink:0; }
.pie-legend{ display:flex; flex-direction:column; gap:8px; flex:1; min-width:140px; }
.legend-row{ display:flex; align-items:center; gap:8px; font-size:13px; color:var(--ink-soft); }
.legend-row b{ margin-left:auto; color:var(--ink); }
.legend-row .dot{ width:9px; height:9px; border-radius:3px; flex-shrink:0; }

/* ---------- Section 6: function cards ---------- */
.func-grid{ display:grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap:14px; }
.func-card{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md);
  padding:16px 17px; box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s, border-color .15s;
}
.func-card:hover{ transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--accent); }
.func-name{ font-family:var(--font-mono); font-weight:700; font-size:14px; color: var(--accent-text); margin-bottom:6px; }
.func-purpose{ font-size:12.8px; color: var(--ink-soft); margin-bottom:12px; min-height:32px; }
.func-example{ background: var(--bg); border-radius:7px; padding:8px 10px; margin-bottom:9px; overflow-x:auto; }
.func-example code{ font-size:12px; color: var(--ink); white-space:pre; }
.func-output{ font-size:11.5px; color:var(--muted); }
.func-output span{ font-weight:700; text-transform:uppercase; letter-spacing:.04em; margin-right:6px; font-size:10px; }

/* ---------- Section 7: practice ---------- */
.practice-card{
  background: linear-gradient(180deg, var(--accent-soft), var(--surface) 55%);
  border:1px solid var(--border); border-radius: var(--radius-lg); padding:22px 24px; box-shadow: var(--shadow-sm);
}
.practice-row{ display:flex; gap:14px; margin-bottom:18px; }
.practice-icon{
  flex-shrink:0; width:38px; height:38px; border-radius:10px; background:var(--surface);
  border:1.5px solid var(--accent); color:var(--accent-text);
  display:flex; align-items:center; justify-content:center; font-size:16px;
}
.practice-label{ font-family:var(--font-display); font-size:11.5px; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:var(--accent-text); margin-bottom:6px; }
.practice-task{ font-size:15px; color: var(--ink); font-weight:500; }
.practice-meta{ display:flex; gap:14px; flex-wrap:wrap; }
.practice-box{ background: var(--surface); border:1px solid var(--border); border-radius:10px; padding:12px 14px; flex:1; min-width:200px; }
.practice-box-label{ font-size:11px; font-weight:700; text-transform:uppercase; color:var(--muted); letter-spacing:.04em; margin-bottom:6px; }
.practice-box code{ font-size:13px; color:var(--ink); white-space:pre-wrap; }
.hint-box{ flex:1; min-width:200px; background:var(--surface); border:1px dashed var(--border); border-radius:10px; padding:12px 14px; }
.hint-box summary{ cursor:pointer; font-size:12.5px; font-weight:700; color: var(--accent-text); }
.hint-box p{ margin-top:9px; font-size:13px; }

/* ---------- Section 8: related ---------- */
.related-grid{ display:grid; grid-template-columns: 1fr 1fr; gap:14px; }
.rel-card{
  background: var(--surface); border:1.5px solid var(--border); border-radius: var(--radius-md);
  padding:14px 16px; text-align:left; display:flex; flex-direction:column; gap:4px;
  transition: border-color .15s, transform .15s;
}
.rel-card:hover{ border-color: var(--accent, var(--green)); transform: translateY(-2px); }
.rel-card:last-child{ align-items:flex-end; text-align:right; }
.rel-label{ font-size:11px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); font-weight:700; }
.rel-title{ font-family:var(--font-display); font-weight:600; font-size:14px; color:var(--ink); }
.rel-empty{ color:var(--muted); font-size:13px; justify-content:center; align-items:center; flex-direction:row; }
.chip-row{ display:flex; gap:8px; flex-wrap:wrap; margin-top:14px; }
.chip{
  background: var(--bg); border:1px solid var(--border); border-radius:20px; padding:6px 13px;
  font-size:12.5px; color:var(--ink-soft); transition: background .15s;
}
.chip:hover{ background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }

/* ---------- Stub state ---------- */
.stub-card{
  background: var(--surface); border:1.5px dashed var(--border); border-radius: var(--radius-lg);
  padding:44px 30px; text-align:center; display:flex; flex-direction:column; align-items:center; gap:10px; margin-bottom:32px;
}
.stub-card h3{ font-size:17px; }
.stub-card p{ max-width:420px; font-size:13.8px; }