/* ==========================================================================
   Instagram System Design — Learning Guide
   ========================================================================== */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #5b6b7b;
  --border: #e3e8ee;
  --accent: #c13584;          /* Instagram magenta */
  --accent-2: #5851db;        /* Instagram purple */
  --accent-soft: #fbeaf4;
  --link: #3b5bdb;
  --code-bg: #f1f3f5;
  --client: #0277bd;  --client-bg: #e1f5fe;
  --edge: #ef6c00;    --edge-bg: #fff3e0;
  --svc: #2e7d32;     --svc-bg: #e8f5e9;
  --async: #6a1b9a;   --async-bg: #f3e5f5;
  --store: #f9a825;   --store-bg: #fff8e1;
  --ext: #455a64;     --ext-bg: #eceff1;
  --ok: #2e7d32; --warn: #b26a00; --danger: #c62828; --info: #1565c0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); color: var(--text); background: var(--bg);
  line-height: 1.65; font-size: 16px; -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: .1em .35em; border-radius: 4px; }
pre { font-family: var(--mono); font-size: 13.5px; line-height: 1.5; background: #0f172a; color: #e2e8f0; padding: 16px 18px; border-radius: var(--radius); overflow-x: auto; }
pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
kbd { font-family: var(--mono); font-size: .85em; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 .35em; background: #fff; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; height: 56px; display: flex; align-items: center; gap: 16px;
  padding: 0 20px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.topbar .brand:hover { text-decoration: none; }
.topbar .brand .logo {
  width: 28px; height: 28px; border-radius: 8px;
  background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285AEB 90%);
  display: inline-block;
}
.topbar .spacer { flex: 1; }
.topbar a.top-link { color: var(--muted); font-size: 14px; white-space: nowrap; }
.topbar a.top-link:hover { color: var(--accent); text-decoration: none; }
.progress-pill { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.progress-bar { width: 120px; height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); width: 0; transition: width .4s; }
.menu-btn { display: none; border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 4px 10px; font-size: 18px; cursor: pointer; }

/* ---------- 3-column lesson layout ---------- */
.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr) 230px; gap: 0; max-width: 1500px; margin: 0 auto; }
.sidebar {
  position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; padding: 18px 14px 40px 18px;
  border-right: 1px solid var(--border); background: var(--surface); font-size: 14px;
}
.sidebar .search { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; margin-bottom: 12px; }
.sidebar .part-title { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 18px 6px 6px; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; color: var(--text); }
.sidebar li a:hover { background: var(--bg); text-decoration: none; }
.sidebar li a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar li a .num { font-size: 11px; color: var(--muted); min-width: 20px; }
.sidebar li a .check { margin-left: auto; color: var(--ok); font-size: 13px; visibility: hidden; }
.sidebar li a.done .check { visibility: visible; }
.sidebar .home-link { display: block; padding: 8px 10px; border-radius: 8px; background: var(--bg); color: var(--text); font-weight: 600; margin-bottom: 10px; }

.content { padding: 28px 44px 80px; min-width: 0; }
.toc { position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; padding: 28px 16px; font-size: 13px; }
.toc h4 { margin: 0 0 8px; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.toc a { display: block; color: var(--muted); padding: 3px 0 3px 10px; border-left: 2px solid var(--border); }
.toc a.sub { padding-left: 22px; font-size: 12.5px; }
.toc a.active { color: var(--accent); border-left-color: var(--accent); }
.toc a:hover { color: var(--text); text-decoration: none; }

/* ---------- lesson header ---------- */
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.breadcrumb a { color: var(--muted); }
.lesson-header { border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 26px; max-width: 860px; }
.lesson-header h1 { font-size: 2.1rem; line-height: 1.2; margin: 6px 0 10px; }
.lesson-header .summary { font-size: 1.12rem; color: var(--muted); margin: 0 0 16px; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 6px 12px; border-radius: 8px; font: inherit; font-size: 13.5px; cursor: pointer; transition: all .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #a62b70; color: #fff; }
.btn.learned { background: #e8f5e9; border-color: #a5d6a7; color: var(--ok); }

/* ---------- lesson typography ---------- */
.lesson { max-width: 860px; }
.lesson h2 { font-size: 1.55rem; margin: 2.6rem 0 .8rem; padding-top: .4rem; line-height: 1.3; scroll-margin-top: 70px; }
.lesson h3 { font-size: 1.18rem; margin: 1.8rem 0 .6rem; scroll-margin-top: 70px; }
.lesson h4 { font-size: 1rem; margin: 1.3rem 0 .4rem; }
.lesson ul, .lesson ol { padding-left: 1.4rem; }
.lesson li { margin: .3rem 0; }
.lesson strong { color: #111827; }

/* TL;DR */
.tldr { background: linear-gradient(135deg, #fdf2f8, #eef2ff); border: 1px solid #f3d1e6; border-radius: var(--radius); padding: 16px 20px; margin: 0 0 1.6rem; }
.tldr .tldr-title { font-weight: 700; color: var(--accent); font-size: 13px; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px; }
.tldr ul { margin: 0; }

/* Callouts */
.callout { border-left: 4px solid var(--info); background: #eef5fd; border-radius: 0 var(--radius) var(--radius) 0; padding: 12px 16px; margin: 1.2rem 0; }
.callout > :first-child { margin-top: 0; } .callout > :last-child { margin-bottom: 0; }
.callout .callout-title { font-weight: 700; display: block; margin-bottom: 4px; }
.callout.tip { border-color: var(--ok); background: #edf7ee; }
.callout.warn { border-color: var(--warn); background: #fff6e5; }
.callout.danger { border-color: var(--danger); background: #fdecea; }
.callout.instagram { border-color: var(--accent); background: var(--accent-soft); }
.callout.analogy { border-color: var(--accent-2); background: #efeefe; }
.callout.interview { border-color: #00838f; background: #e6f6f7; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 1.2rem 0; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #f3f4f6; font-weight: 700; font-size: 13.5px; }
tr:last-child td { border-bottom: 0; }

/* Diagrams */
.diagram { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 1.4rem 0; box-shadow: var(--shadow); overflow-x: auto; }
.diagram svg { display: block; margin: 0 auto; height: auto; font-family: var(--font); }
.diagram .caption, figure figcaption { text-align: center; font-size: 13px; color: var(--muted); margin-top: 8px; }
figure { margin: 1.4rem 0; }
pre.ascii { background: #fbfcfd; color: #1f2933; border: 1px solid var(--border); font-size: 13px; line-height: 1.45; box-shadow: var(--shadow); }

/* CSS flow diagram */
.flow { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin: 1.4rem 0; padding: 16px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.fnode { padding: 8px 14px; border-radius: 8px; border: 1.5px solid #90a4ae; background: #f5f7f9; font-weight: 600; font-size: 14px; text-align: center; }
.fnode small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.fnode.client { border-color: var(--client); background: var(--client-bg); }
.fnode.edge { border-color: var(--edge); background: var(--edge-bg); }
.fnode.svc { border-color: var(--svc); background: var(--svc-bg); }
.fnode.async { border-color: var(--async); background: var(--async-bg); }
.fnode.store { border-color: var(--store); background: var(--store-bg); }
.fnode.ext { border-color: var(--ext); background: var(--ext-bg); }
.farrow { color: var(--muted); font-size: 20px; font-weight: 700; text-align: center; }
.farrow small { display: block; font-size: 11px; font-weight: 400; }

/* Numbered steps */
ol.steps { list-style: none; counter-reset: step; padding-left: 0; }
ol.steps > li { counter-increment: step; position: relative; padding: 2px 0 10px 44px; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 2px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center;
}

/* Cards grid */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin: 1.2rem 0; }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card h4 { margin: 0 0 6px; font-size: 1rem; }
.card p { margin: 0; font-size: 14px; color: var(--muted); }

/* Pros / cons */
.pros-cons { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 1.2rem 0; }
.pros-cons > div { border-radius: var(--radius); padding: 12px 16px; border: 1px solid var(--border); background: #fff; }
.pros-cons .pros { border-top: 4px solid var(--ok); }
.pros-cons .cons { border-top: 4px solid var(--danger); }
.pros-cons h4 { margin: 0 0 6px; }
.pros-cons ul { margin: 0; padding-left: 1.2rem; }

/* Q&A and quiz (use <details>) */
details { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 0 16px; margin: .7rem 0; box-shadow: var(--shadow); }
details > summary { cursor: pointer; padding: 12px 0; font-weight: 600; list-style: none; position: relative; padding-right: 26px; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "+"; position: absolute; right: 2px; top: 9px; font-size: 20px; color: var(--accent); }
details[open] > summary::after { content: "−"; }
details[open] { padding-bottom: 12px; }
details.quiz > summary::before { content: "❓ "; }
details.qa > summary::before { content: "🎤 "; }

/* Key takeaways */
.takeaways { background: #0f172a; color: #e2e8f0; border-radius: var(--radius); padding: 18px 22px; margin: 1.6rem 0; }
.takeaways h3, .takeaways .t-title { color: #fff; margin-top: 0; font-weight: 700; }
.takeaways li { color: #e2e8f0; }
.takeaways strong { color: #f9a8d4; }
.takeaways a { color: #93c5fd; }

/* Lesson footer */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 2rem; max-width: 860px; }
.pager a { display: block; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; background: #fff; box-shadow: var(--shadow); color: var(--text); }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager .lbl { font-size: 12px; color: var(--muted); }
.pager .ttl { font-weight: 600; }
.pager .next { text-align: right; grid-column: 2; }
.lesson-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 2.4rem; padding-top: 1.2rem; border-top: 1px solid var(--border); max-width: 860px; }

/* ================= Home page ================= */
.home { max-width: 1840px; margin: 0 auto; padding: 0 24px 80px; }
.hero { text-align: center; padding: 40px 10px 18px; }
.hero h1 { font-size: 2.6rem; margin: 0 0 10px; line-height: 1.15; }
.hero h1 .grad { background: linear-gradient(90deg, #f58529, #dd2a7b, #8134af, #515bd4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { font-size: 1.15rem; color: var(--muted); max-width: 860px; margin: 0 auto 18px; }
.hero .cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hero .stats { display: flex; gap: 30px; justify-content: center; margin-top: 22px; color: var(--muted); font-size: 14px; flex-wrap: wrap; }
.hero .stats b { display: block; font-size: 1.5rem; color: var(--text); }

.section-title { font-size: 1.6rem; margin: 44px 0 6px; }
.section-sub { color: var(--muted); margin: 0 0 18px; }
.howto { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.howto .n { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; margin-right: 6px; }

.diagram-shell { background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; }
.diagram-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.diagram-toolbar .lbl { font-weight: 700; font-size: 14px; margin-right: 4px; }
.flow-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.diagram-canvas { overflow-x: auto; }
.diagram-canvas svg { display: block; width: 100%; min-width: 1150px; height: auto; }

/* interactive svg */
#arch a { cursor: pointer; }
#arch a.node > .shape { transition: filter .15s, stroke-width .15s; }
#arch a.node:hover > .shape, #arch a.node.focus > .shape { stroke-width: 3; filter: drop-shadow(0 0 6px rgba(193,53,132,.55)); }
#arch a.grp-link:hover text { fill: var(--accent); text-decoration: underline; }
#arch a.chip-link:hover rect { stroke: var(--accent); fill: #fdf2f8; }
#arch a.chip-link:hover text { fill: var(--accent); }
#arch a.tag-link:hover rect { fill: #fdf2f8; }
#arch a.tag-link:hover text { fill: var(--accent); text-decoration: underline; }
#arch .node, #arch .edge, #arch .chip-link, #arch .grp { transition: opacity .25s; }
#arch.flow-active .node:not(.hl), #arch.flow-active .edge:not(.hl), #arch.flow-active .chip-link, #arch.flow-active .grp, #arch.flow-active .xcut { opacity: .14; }
#arch.flow-active .node.hl > .shape { stroke-width: 3.4; filter: drop-shadow(0 0 8px rgba(193,53,132,.75)); }
#arch .edge.hl path { stroke-width: 3.4; stroke-dasharray: 9 6; animation: dash .9s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -30; } }
#arch a.node.focus > .shape { animation: pulse 1.2s ease-in-out 5; }
#arch a.chip-link.focus rect, #arch a.tag-link.focus rect { stroke: var(--accent); stroke-width: 2.5; fill: #fdf2f8; animation: pulse 1.2s ease-in-out 5; }
#arch a.chip-link.focus text, #arch a.tag-link.focus text, #arch a.grp-link.focus text { fill: var(--accent); font-weight: 700; }
@keyframes pulse { 50% { filter: drop-shadow(0 0 16px rgba(193,53,132,1)); stroke-width: 4; } }

.tooltip {
  position: fixed; z-index: 100; pointer-events: none; max-width: 310px; background: #111827; color: #f9fafb; padding: 10px 12px;
  border-radius: 8px; font-size: 13px; line-height: 1.45; box-shadow: 0 8px 24px rgba(0,0,0,.25); opacity: 0; transition: opacity .12s;
}
.tooltip b { display: block; font-size: 14px; margin-bottom: 2px; }
.tooltip .go { color: #f9a8d4; font-size: 12px; margin-top: 5px; display: block; }

.flow-panel { margin-top: 12px; border: 1px solid #f3d1e6; border-radius: var(--radius); padding: 14px 18px; background: #fffafd; display: none; }
.flow-panel.show { display: block; }
.flow-panel .fp-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.flow-panel .fp-title { font-weight: 700; font-size: 1.05rem; }
.flow-panel .fp-step { font-size: 13px; color: var(--muted); }
.flow-panel .fp-text { margin: 8px 0; font-size: 15.5px; }
.flow-panel .fp-learn { font-size: 13.5px; }
.flow-panel .fp-learn a { margin-right: 6px; display: inline-block; background: #fff; border: 1px solid var(--border); border-radius: 99px; padding: 1px 10px; margin-top: 4px; }
.flow-panel .fp-nav { margin-left: auto; display: flex; gap: 8px; }
.flow-dots { display: flex; gap: 5px; margin-top: 10px; }
.flow-dots span { width: 24px; height: 6px; border-radius: 3px; background: var(--border); cursor: pointer; }
.flow-dots span.on { background: var(--accent); }

.path-part { margin: 26px 0 8px; }
.path-part h3 { margin: 0 0 4px; font-size: 1.2rem; }
.path-part p.pdesc { margin: 0 0 12px; color: var(--muted); font-size: 14.5px; }
.lesson-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
.lesson-card { position: relative; display: block; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; color: var(--text); box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.lesson-card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }
.lesson-card .lc-num { font-size: 12px; color: var(--muted); font-weight: 600; }
.lesson-card .lc-title { font-weight: 700; margin: 2px 0 4px; padding-right: 20px; }
.lesson-card .lc-sum { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.lesson-card .lc-done { position: absolute; top: 12px; right: 14px; color: var(--ok); font-weight: 700; display: none; }
.lesson-card.done .lc-done { display: block; }
.lesson-card.done { background: #f6fbf6; }
.site-footer { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 10px; border-top: 1px solid var(--border); margin-top: 50px; }

/* ---------- responsive ---------- */
@media (max-width: 1250px) {
  .layout { grid-template-columns: 270px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 56px; width: 290px; z-index: 60; transform: translateX(-105%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.12); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
  .content { padding: 20px 18px 60px; }
  .pros-cons { grid-template-columns: 1fr; }
  .progress-bar { width: 70px; }
  .hero h1 { font-size: 2rem; }
}
@media (max-width: 760px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar a.top-link, .progress-pill [data-progress-text] { display: none; }
}
@media print {
  .topbar, .sidebar, .toc, .pager, .lesson-actions { display: none !important; }
  .layout { display: block; }
}
