/* ESP32 物联网开发教程 */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --card: #1c2128;
  --card-hover: #262c36;
  --border: rgba(180,185,210,0.12);
  --border-bright: rgba(180,185,210,0.26);
  --text: #e6edf3;
  --text-2: #adbac7;
  --text-3: #768390;
  --accent: #e06c1a;
  --accent-2: #f5933a;
  --accent-glow: rgba(224,108,26,0.12);
  --green: #4ade80;
  --blue: #60a5fa;
  --red: #f87171;
  --cyan: #22d3ee;
  --yellow: #fbbf24;
  --purple: #c084fc;
  --radius: 10px;
  --radius-lg: 14px;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  min-height: 100vh;
}

/* ── NAV ── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 2rem;
  height: 56px;
  background: rgba(13,17,23,0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.nav-back {
  color: var(--accent-2);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  transition: color 0.2s;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.nav-back:hover { color: var(--accent); border-color: var(--border-bright); }

.nav-title {
  color: var(--text-2);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── HERO (index) ── */
.hero {
  position: relative;
  padding: 6rem 2rem 5rem;
  text-align: center;
  overflow: hidden;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(224,108,26,0.08) 0%, #161b22 50%, #0d1117 100%);
}
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle 400px at 20% 50%, rgba(224,108,26,0.1) 0%, transparent 70%),
    radial-gradient(circle 400px at 80% 50%, rgba(245,147,58,0.07) 0%, transparent 70%);
  pointer-events: none;
}

.hero-badge {
  display: inline-block;
  padding: 4px 14px;
  background: var(--accent-glow);
  border: 1px solid var(--border-bright);
  border-radius: 99px;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
}

.hero h1 {
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #f5933a 0%, #e06c1a 40%, #fbbf24 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  filter: drop-shadow(0 0 30px rgba(224,108,26,0.4));
}

.hero-sub {
  color: var(--text-2);
  font-size: 1.15rem;
  max-width: 560px;
  margin: 0 auto 2.5rem;
}

.hero-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 2.5rem;
}
.hero-chip {
  padding: 5px 14px;
  background: var(--card);
  border: 1px solid var(--border-bright);
  border-radius: 99px;
  color: var(--accent-2);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.hero-chip.blue  { color: var(--blue);  border-color: rgba(96,165,250,0.3); }
.hero-chip.cyan  { color: var(--cyan);  border-color: rgba(34,211,238,0.3); }
.hero-chip.green { color: var(--green); border-color: rgba(74,222,128,0.3); }

.hero-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 3rem;
}
.hero-tag {
  padding: 5px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text-2);
  font-size: 0.82rem;
  font-weight: 500;
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 3rem;
  flex-wrap: wrap;
}
.stat-item { text-align: center; }
.stat-num {
  display: block;
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}
.stat-label { font-size: 0.8rem; color: var(--text-3); }

/* ── CHAPTER HERO ── */
.chapter-hero {
  padding: 4rem 2rem 3rem;
  text-align: center;
  background: radial-gradient(ellipse at top, #161b22 0%, #0d1117 70%);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.chapter-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle 300px at 50% 100%, rgba(224,108,26,0.1) 0%, transparent 70%);
  pointer-events: none;
}

.ch-num {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}

.chapter-hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
  margin-bottom: 0.75rem;
  color: var(--text);
  text-shadow: 0 0 40px rgba(224,108,26,0.3);
}

.chapter-hero p {
  color: var(--text-2);
  font-size: 1.05rem;
  max-width: 600px;
  margin: 0 auto;
}

/* ── CONTAINER ── */
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

/* ── SECTION HEADINGS ── */
.section-title {
  text-align: center;
  margin-bottom: 2.5rem;
}
.section-title h2 {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text);
}
.section-title p { color: var(--text-2); margin-top: 0.4rem; }

/* ── CARDS (index chapter cards) ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.6rem;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  transition: background 0.2s, border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}
.card:hover {
  background: var(--card-hover);
  border-color: var(--border-bright);
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(224,108,26,0.15);
}

.card-num {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
  text-transform: uppercase;
}
.card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}
.card p {
  font-size: 0.85rem;
  color: var(--text-2);
  line-height: 1.55;
  flex: 1;
}
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.3rem;
}
.tag {
  padding: 2px 8px;
  background: rgba(224,108,26,0.1);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.72rem;
  color: var(--text-3);
}

/* ── FEATURES (index) ── */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}
.feature-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.feature-icon {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}
.feature-item h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-2);
  margin-bottom: 0.25rem;
}
.feature-item p { font-size: 0.83rem; color: var(--text-2); }

/* ── CONTENT (chapter pages) ── */
.content {
  max-width: 820px;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
}

.content h2 {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text);
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.content h2::before {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 60px;
  height: 2px;
  background: var(--accent);
}

.content h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-2);
  margin: 1.8rem 0 0.7rem;
}

.content p {
  color: var(--text-2);
  margin-bottom: 1rem;
  line-height: 1.85;
}

.content ul, .content ol {
  color: var(--text-2);
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}
.content li { margin-bottom: 0.4rem; line-height: 1.75; }
.content strong { color: var(--text); font-weight: 700; }

/* ── PROGRESS ── */
.progress {
  height: 4px;
  background: var(--surface-2);
  border-radius: 99px;
  margin-bottom: 2.5rem;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #e06c1a, #f5933a);
  border-radius: 99px;
  box-shadow: 0 0 8px rgba(224,108,26,0.5);
  transition: width 0.6s ease;
}

/* ── CALLOUT ── */
.callout {
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  border-left: 4px solid;
  font-size: 0.9rem;
  line-height: 1.7;
}
.callout .callout-title {
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}
.callout p { margin-bottom: 0; color: inherit; }
.callout ul { color: inherit; }

.callout.info {
  background: rgba(224,108,26,0.08);
  border-color: var(--accent);
  color: #ffd0a0;
}
.callout.info .callout-title { color: var(--accent-2); }

.callout.tip {
  background: rgba(74,222,128,0.07);
  border-color: var(--green);
  color: #c0f0d0;
}
.callout.tip .callout-title { color: var(--green); }

.callout.warning {
  background: rgba(251,191,36,0.08);
  border-color: var(--yellow);
  color: #ffe8a0;
}
.callout.warning .callout-title { color: var(--yellow); }

.callout.danger {
  background: rgba(248,113,113,0.08);
  border-color: var(--red);
  color: #ffd0d0;
}
.callout.danger .callout-title { color: var(--red); }

/* ── CODE ── */
pre {
  background: #090d12;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 1.25rem 0;
  font-size: 0.88rem;
  line-height: 1.7;
  position: relative;
}
pre::before {
  content: attr(data-lang);
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-3);
  text-transform: uppercase;
}
code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.88rem;
}
p code, li code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--accent-2);
  font-size: 0.85em;
}

/* Code highlight spans */
.kw { color: #e06c1a; font-weight: 700; }   /* keyword — 橙 */
.fn { color: #f5933a; }                       /* function — 琥珀 */
.st { color: #4ade80; }                       /* string — 绿 */
.cm { color: #7a6040; font-style: italic; }   /* comment — 暗棕 */
.ty { color: #22d3ee; }                       /* type — 青 */
.nu { color: #c084fc; }                       /* number — 紫 */
.at { color: #f87171; }                       /* attribute/macro — 红 */
.pr { color: #60a5fa; }                       /* punctuation/directive — 蓝 */

/* ── ASCII DIAGRAM ── */
.ascii-diagram {
  background: #090d12;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-2);
  margin: 1.25rem 0;
  overflow-x: auto;
  white-space: pre;
}

/* ── ASCII FLOW ── */
.ascii-flow {
  background: #090d12;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.65;
  color: var(--cyan);
  margin: 1.25rem 0;
  overflow-x: auto;
  white-space: pre;
}

/* ── DEF LIST ── */
.def-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin: 1.25rem 0;
  display: grid;
  gap: 0.9rem;
}
.def-item {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0.75rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border);
}
.def-item:last-child { border-bottom: none; padding-bottom: 0; }
.def-term {
  color: var(--accent-2);
  font-weight: 700;
  font-size: 0.88rem;
  font-family: 'JetBrains Mono', Consolas, monospace;
  padding-top: 2px;
}
.def-desc { color: var(--text-2); font-size: 0.9rem; line-height: 1.65; }

/* ── TWO COL ── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.25rem 0;
}
.two-col-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}
.two-col-item h4 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-2);
  margin-bottom: 0.5rem;
}
.two-col-item p, .two-col-item ul {
  font-size: 0.85rem;
  color: var(--text-2);
  margin: 0;
}
@media (max-width: 600px) { .two-col { grid-template-columns: 1fr; } }

/* ── COMPARE TABLE ── */
.compare-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.88rem;
}
.compare-table th {
  background: var(--surface-2);
  color: var(--accent-2);
  padding: 0.6rem 0.9rem;
  text-align: left;
  font-weight: 700;
  border: 1px solid var(--border);
}
.compare-table td {
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: top;
}
.compare-table tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* ── CHAPTER NAV ── */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.9rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: background 0.2s, border-color 0.2s;
  min-width: 0;
  flex: 1;
  max-width: 45%;
}
.chapter-nav a:hover {
  background: var(--card-hover);
  border-color: var(--border-bright);
}
.chapter-nav .next { text-align: right; }
.nav-dir { font-size: 0.75rem; color: var(--accent); font-weight: 700; }
.nav-title-text { font-size: 0.88rem; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── SITE FOOTER ── */
.site-footer {
  text-align: center;
  padding: 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 0.82rem;
}
.site-footer a { color: var(--accent-2); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

/* ── INLINE HIGHLIGHT ── */
.highlight { color: var(--accent); font-weight: 700; }
.highlight-green { color: var(--green); font-weight: 700; }
.highlight-blue { color: var(--blue); font-weight: 700; }

/* ── CARD LIST (alt layout) ── */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.card-list-item {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.cli-num {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid var(--border-bright);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
  margin-top: 2px;
}
.cli-body h4 { font-size: 0.95rem; font-weight: 700; color: var(--text); margin-bottom: 0.2rem; }
.cli-body p { font-size: 0.85rem; color: var(--text-2); margin: 0; }

/* ── INTRO BLOCK ── */
.intro-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin: 2rem 0;
}
.intro-block h2 {
  font-size: 1.2rem;
  color: var(--accent-2);
  margin-bottom: 1rem;
}
.intro-block p {
  color: var(--text-2);
  line-height: 1.8;
  margin-bottom: 0.75rem;
}
.intro-block p:last-child { margin-bottom: 0; }

/* ── SCROLL ANIMATION ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate { opacity: 0; }
.animate.visible { animation: fadeUp 0.5s ease forwards; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .nav { padding: 0 1rem; }
  .hero { padding: 4rem 1.25rem 3.5rem; }
  .container { padding: 2rem 1.25rem; }
  .content { padding: 2rem 1.25rem 3rem; }
  .def-item { grid-template-columns: 1fr; gap: 0.2rem; }
  .chapter-nav a { padding: 0.75rem 1rem; }
  .hero-stats { gap: 1.5rem; }
}
