/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-card-hover: #222;
  --bg-code: #161616;
  --text: #e0e0e0;
  --text-muted: #888;
  --text-heading: #fff;
  --accent: #d4845a;
  --accent-light: #e8a87c;
  --accent-glow: rgba(212, 132, 90, 0.15);
  --border: #2a2a2a;
  --border-light: #333;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --blue: #60a5fa;
  --purple: #a78bfa;
  --max-width: 860px;
  --radius: 12px;
  --radius-sm: 8px;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}

/* === Layout === */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 24px; }

/* === Header / Nav === */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 15, 15, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.5px;
}

.site-nav { display: flex; gap: 8px; align-items: center; }

.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.site-nav a:hover, .site-nav a.active {
  color: var(--text);
  background: var(--bg-card);
}

/* Hamburger */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  margin: 5px 0;
  transition: all 0.3s;
  border-radius: 2px;
}

.hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

.mobile-nav {
  display: none;
  position: fixed;
  top: 53px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 15, 15, 0.95);
  backdrop-filter: blur(12px);
  z-index: 99;
  padding: 24px;
  overflow-y: auto;
}

.mobile-nav.active { display: block; }

.mobile-nav a {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  transition: all 0.2s;
}

.mobile-nav a:hover, .mobile-nav a.active {
  color: var(--text);
  background: var(--bg-card);
}

/* === Hero === */
.hero {
  padding: 80px 0 60px;
  text-align: center;
}

.hero h1 {
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 800;
  color: var(--text-heading);
  line-height: 1.2;
  margin-bottom: 20px;
  letter-spacing: -1px;
}

.hero .subtitle {
  font-size: clamp(16px, 2.5vw, 20px);
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto 32px;
  line-height: 1.6;
}

.hero .highlight { color: var(--accent); }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-light); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

/* === Chapter Cards (Homepage) === */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin: 40px 0;
}

.chapter-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chapter-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.chapter-card .chapter-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.chapter-card h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-heading);
  line-height: 1.3;
}

.chapter-card p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* === Content Pages === */
.page-header {
  padding: 48px 0 32px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}

.page-header .chapter-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.page-header h1 {
  font-size: clamp(26px, 4vw, 36px);
  font-weight: 800;
  color: var(--text-heading);
  line-height: 1.2;
  letter-spacing: -0.5px;
}

.page-header .lead {
  font-size: 18px;
  color: var(--text-muted);
  margin-top: 12px;
  line-height: 1.6;
}

.content { padding-bottom: 80px; }

.content h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-heading);
  margin: 48px 0 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  letter-spacing: -0.3px;
}

.content h2:first-child { border-top: none; margin-top: 0; padding-top: 0; }

.content h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-heading);
  margin: 32px 0 12px;
}

.content p { margin: 12px 0; }

.content ul, .content ol {
  margin: 12px 0;
  padding-left: 24px;
}

.content li { margin: 6px 0; }

/* === Blockquote (Analogy boxes) === */
.analogy {
  background: var(--accent-glow);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 20px 24px;
  margin: 24px 0;
  font-size: 16px;
  line-height: 1.7;
}

.analogy strong { color: var(--accent-light); }

/* === Info/Warning/Tip boxes === */
.box {
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  margin: 24px 0;
  border-left: 3px solid;
  font-size: 15px;
}

.box-tip { background: rgba(74, 222, 128, 0.08); border-color: var(--green); }
.box-warning { background: rgba(251, 191, 36, 0.08); border-color: var(--yellow); }
.box-danger { background: rgba(248, 113, 113, 0.08); border-color: var(--red); }
.box-info { background: rgba(96, 165, 250, 0.08); border-color: var(--blue); }

.box-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.box-tip .box-label { color: var(--green); }
.box-warning .box-label { color: var(--yellow); }
.box-danger .box-label { color: var(--red); }
.box-info .box-label { color: var(--blue); }

/* === Code blocks === */
.code-block {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  margin: 20px 0;
  overflow-x: auto;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
}

code {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--accent-light);
}

/* === Tables === */
.table-wrapper {
  overflow-x: auto;
  margin: 20px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

thead { background: var(--bg-card); }

th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 700;
  color: var(--text-heading);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tr:last-child td { border-bottom: none; }

tr:hover { background: var(--bg-card); }

/* === Comparison blocks === */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
}

.compare-bad, .compare-good {
  border-radius: var(--radius-sm);
  padding: 20px;
  font-size: 14px;
}

.compare-bad {
  background: rgba(248, 113, 113, 0.06);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.compare-good {
  background: rgba(74, 222, 128, 0.06);
  border: 1px solid rgba(74, 222, 128, 0.2);
}

.compare-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.compare-bad .compare-label { color: var(--red); }
.compare-good .compare-label { color: var(--green); }

/* === Chapter Navigation (bottom) === */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  padding: 32px 0;
  margin-top: 48px;
  border-top: 1px solid var(--border);
  gap: 16px;
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: all 0.2s;
  max-width: 48%;
}

.chapter-nav a:hover { border-color: var(--accent); background: var(--bg-card); }

.chapter-nav .nav-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.chapter-nav .nav-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-heading);
}

.chapter-nav .next { margin-left: auto; text-align: right; }

/* === Footer === */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 32px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover { text-decoration: underline; }

/* === Responsive === */
@media (max-width: 768px) {
  body { font-size: 16px; }

  .site-nav { display: none; }
  .hamburger { display: block; }

  .hero { padding: 48px 0 40px; }
  .chapter-grid { grid-template-columns: 1fr; }
  .compare { grid-template-columns: 1fr; }

  .page-header { padding: 32px 0 24px; }
  .content h2 { font-size: 20px; margin-top: 36px; }

  .chapter-nav { flex-direction: column; }
  .chapter-nav a { max-width: 100%; }
  .chapter-nav .next { text-align: left; }

  table { font-size: 14px; }
  th, td { padding: 10px 12px; }
}

@media (max-width: 480px) {
  .container { padding: 0 16px; }
  .hero h1 { font-size: 26px; }
  .analogy { padding: 16px 18px; }
}
