/* ============================================================
   Machine Learning A to Z — style.css
   Base theme, layout, header/footer, homepage.
   Chapter components live in components.css.
   Theme: CSS variables, dark default, light alternate.
   ============================================================ */

/* ---------- 1. Theme variables ---------- */

:root,
html[data-theme='dark'] {
  --bg: #0d1117;
  --surface: #161b26;
  --surface-2: #1d2433;
  --text: #e6e9f2;
  --text-light: #98a2b8;
  --border: #262e40;
  --primary: #7c9aff;
  --primary-light: #a8bcff;
  --accent: #3fd6a8;
  --accent-light: #7ce6c6;
  --warning: #ffb454;
  --danger: #ff7a7a;
  --success: #3fd6a8;
  --code-bg: #10151f;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.3);
  --hero-grad: linear-gradient(135deg, #131a2c 0%, #1a2240 55%, #12283c 100%);
  --radius: 10px;
  --radius-sm: 6px;
  color-scheme: dark;
}

html[data-theme='light'] {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #1c2333;
  --text-light: #5a6478;
  --border: #d9dfec;
  --primary: #3b5bdb;
  --primary-light: #6e8bff;
  --accent: #0ca678;
  --accent-light: #12b886;
  --warning: #d97706;
  --danger: #e03131;
  --success: #0ca678;
  --code-bg: #f1f4fa;
  --shadow: 0 8px 28px rgba(25, 35, 60, 0.12);
  --shadow-sm: 0 2px 10px rgba(25, 35, 60, 0.08);
  --hero-grad: linear-gradient(135deg, #eef2ff 0%, #e7fbf4 100%);
  color-scheme: light;
}

/* ---------- 2. Reset & base ---------- */

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  transition: background 0.25s ease, color 0.25s ease;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.3;
  color: var(--text);
  margin: 0 0 0.5em;
}

p {
  margin: 0 0 1em;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  color: var(--primary-light);
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

code {
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- 3. Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
  color: var(--text);
}

.brand-icon {
  font-size: 1.5rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-sub {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-light);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.site-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  align-items: center;
}

.site-nav a {
  color: var(--text-light);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
}

.site-nav a:hover {
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}

.site-nav a.active {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--primary);
  transform: scale(1.06);
}

/* ---------- 4. Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: 80px;
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 44px 24px 36px;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 36px;
}

.footer-brand .brand-text {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.footer-tagline {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-top: 8px;
  max-width: 42ch;
}

.footer-links h4,
.footer-meta h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  margin-bottom: 12px;
}

.footer-links a {
  display: block;
  color: var(--text-light);
  font-size: 0.9rem;
  padding: 4px 0;
}

.footer-links a:hover {
  color: var(--primary);
}

.footer-meta p {
  color: var(--text-light);
  font-size: 0.85rem;
  margin: 0 0 8px;
}

/* ---------- 5. Homepage: hero ---------- */

.hero {
  background: var(--hero-grad);
  border-bottom: 1px solid var(--border);
  padding: 84px 0 72px;
  text-align: center;
}

.hero-kicker {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 999px;
  padding: 5px 14px;
  margin-bottom: 20px;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3.1rem);
  font-weight: 800;
  margin: 0 0 16px;
  letter-spacing: -0.02em;
}

.hero h1 .accent {
  background: linear-gradient(90deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-sub {
  color: var(--text-light);
  font-size: 1.1rem;
  max-width: 62ch;
  margin: 0 auto 32px;
}

.hero-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-block;
  padding: 12px 26px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
}

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

.btn-primary:hover {
  background: var(--primary-light);
  color: #fff;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 35%, transparent);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ---------- 6. Homepage: stats bar ---------- */

.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  max-width: 900px;
  margin: -34px auto 0;
  padding: 0 24px;
  position: relative;
  z-index: 5;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- 7. Homepage: sections ---------- */

.home-section {
  padding: 64px 0 8px;
}

.home-section > .container > h2 {
  font-size: 1.7rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.section-intro {
  color: var(--text-light);
  max-width: 70ch;
  margin-bottom: 28px;
}

/* Parts grid */
.parts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 18px;
}

.part-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.part-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.part-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.part-card-icon {
  font-size: 1.5rem;
}

.part-card-num {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary);
}

.part-card h3 {
  font-size: 1.02rem;
  margin: 0;
}

.part-card p {
  color: var(--text-light);
  font-size: 0.88rem;
  margin: 0 0 10px;
}

.part-card-range {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- 8. Chapter table ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.chapters-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 640px;
}

.chapters-table th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.chapters-table td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.chapters-table tbody tr:hover td {
  background: color-mix(in srgb, var(--primary) 5%, transparent);
}

.chapters-table .part-row td {
  background: var(--surface-2);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--primary);
  letter-spacing: 0.02em;
  padding-top: 13px;
  padding-bottom: 13px;
}

.ch-num {
  color: var(--text-light);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.ch-title a {
  color: var(--text);
  font-weight: 600;
}

.ch-title a:hover {
  color: var(--primary);
}

.ch-title .plain {
  color: var(--text-light);
  font-weight: 500;
}

.ch-focus {
  color: var(--text-light);
  font-size: 0.85rem;
}

/* Status chips */
.chip {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.chip-published {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

.chip-preview {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent);
}

.chip-planned {
  color: var(--text-light);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* ---------- 9. Guide (how to use) ---------- */

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}

.guide-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.guide-card .guide-num {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  color: var(--primary);
  font-weight: 800;
  margin-bottom: 12px;
}

.guide-card h3 {
  font-size: 1rem;
}

.guide-card p {
  color: var(--text-light);
  font-size: 0.88rem;
  margin: 0;
}

/* ---------- 10. Utilities & responsive ---------- */

.text-center { text-align: center; }

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

@media (max-width: 860px) {
  .footer-inner {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .site-nav a {
    padding: 8px 8px;
    font-size: 0.85rem;
  }

  .brand-text .brand-sub {
    display: none;
  }
}

@media (max-width: 560px) {
  .site-nav {
    display: none;
  }

  .hero {
    padding: 60px 0 56px;
  }
}
