/* ===========================
   強化學習教學網站 - 全域樣式
   設計風格：明亮清爽 + 萊姆綠主題（#92DC50）
   =========================== */

/* ── 字體引入 ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&family=Noto+Sans+TC:wght@300;400;500;700&display=swap');

/* ── CSS 變數（設計系統） ── */
:root {
  /* 主色盤（亮色主題） */
  --clr-bg:           #f4faf0;         /* 極淡綠背景 */
  --clr-surface:      #eaf4e3;         /* 次要背景 */
  --clr-surface-2:    #ffffff;         /* 卡片白色 */
  --clr-border:       rgba(100, 185, 50, 0.3);
  --clr-border-light: rgba(100, 185, 50, 0.15);

  /* 萊姆綠主調 #92DC50 */
  --clr-primary:       #92DC50;        /* 主色 */
  --clr-primary-dark:  #72b83a;        /* 深一點（Hover 用） */
  --clr-primary-darker:#5a9429;        /* 更深（Active 用） */
  --clr-primary-light: #aee876;        /* 淺色 */
  --clr-primary-glow:  rgba(146, 220, 80, 0.15);

  /* 強調色 */
  --clr-accent:   #e67e22;             /* 橘色（公式變數） */
  --clr-accent-2: #1abc9c;             /* 青綠（洞察框） */
  --clr-danger:   #e74c3c;
  --clr-success:  #27ae60;

  /* 文字色 */
  --clr-text:       #1c2a14;           /* 深墨綠文字 */
  --clr-text-muted: #4a6035;           /* 次要文字 */
  --clr-text-dim:   #8aaa75;           /* 淡化文字 */

  /* 漸層 */
  --gradient-primary: linear-gradient(135deg, #92DC50 0%, #5cb32b 100%);
  --gradient-hero:    linear-gradient(135deg, #f0fae8 0%, #e2f5d0 50%, #f4faf0 100%);
  --gradient-glow:    radial-gradient(ellipse at center, rgba(146,220,80,0.12) 0%, transparent 70%);

  /* 排版 */
  --font-sans: 'Inter', 'Noto Sans TC', sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --font-zh:   'Noto Sans TC', 'Inter', sans-serif;

  /* 尺寸 */
  --nav-h:       64px;
  --container-w: 1100px;
  --radius-sm:   8px;
  --radius-md:   14px;
  --radius-lg:   20px;
  --radius-xl:   28px;

  /* 陰影 */
  --shadow-card:   0 4px 24px rgba(100,185,50,0.12), 0 1px 4px rgba(0,0,0,0.05);
  --shadow-glow:   0 0 32px rgba(146,220,80,0.35);
  --shadow-accent: 0 0 20px rgba(230,126,34,0.2);

  /* 動畫 */
  --ease-smooth: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  background-color: var(--clr-bg);
  color: var(--clr-text);
  font-family: var(--font-sans);
  line-height: 1.7;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* 中文字段使用中文字體 */
p, li, td, th, span, div {
  font-family: var(--font-zh);
}
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
}

/* 超連結 */
a {
  color: var(--clr-primary-dark);
  text-decoration: none;
  transition: color 0.2s;
}
a:hover { color: var(--clr-primary-darker); }

/* 選取文字顏色 */
::selection {
  background: var(--clr-primary);
  color: #fff;
}

/* ───────────────────────────────
   導航列
─────────────────────────────── */
#navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  z-index: 1000;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--clr-border-light);
  transition: background 0.3s, box-shadow 0.3s;
}
#navbar.scrolled {
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 4px 24px rgba(100,185,50,0.12);
}

.nav-inner {
  max-width: var(--container-w);
  margin: 0 auto;
  padding: 0 2rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
}
.logo-icon { font-size: 1.3rem; }
.logo-accent {
  color: var(--clr-primary-dark);
  font-weight: 800;
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 0.25rem;
  flex-wrap: nowrap;
}

.nav-link {
  display: block;
  padding: 0.35rem 0.75rem;
  color: var(--clr-text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}
.nav-link:hover,
.nav-link.active {
  color: var(--clr-primary-darker);
  background: var(--clr-primary-glow);
}

.nav-toggle {
  display: none;
  background: none;
  border: 1.5px solid var(--clr-border);
  color: var(--clr-text);
  font-size: 1.2rem;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}
.nav-toggle:hover {
  background: var(--clr-primary-glow);
}

/* ───────────────────────────────
   英雄區塊
─────────────────────────────── */
#hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: calc(var(--nav-h) + 3rem) 2rem 6rem;
}

.hero-bg {
  position: absolute;
  inset: 0;
  background: var(--gradient-hero);
}

/* 神經網路動畫 Canvas */
#heroCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.35;
}

.hero-content {
  position: relative;
  z-index: 2;
  text-align: center;
  max-width: 700px;
}

.hero-badge {
  display: inline-block;
  padding: 0.4rem 1rem;
  background: var(--clr-primary-glow);
  border: 1px solid var(--clr-border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--clr-primary-darker);
  margin-bottom: 1.5rem;
  animation: fadeInDown 0.8s var(--ease-smooth) both;
}

.hero-title {
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 1.25rem;
  letter-spacing: -0.02em;
  color: var(--clr-text);
  animation: fadeInDown 0.9s var(--ease-smooth) 0.1s both;
}

/* 標題漸層文字 */
.gradient-text {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--clr-text-muted);
  margin-bottom: 2rem;
  animation: fadeInDown 1s var(--ease-smooth) 0.2s both;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 3rem;
  animation: fadeInUp 1s var(--ease-smooth) 0.3s both;
}

/* 主按鈕：萊姆綠實心 */
.btn-primary {
  display: inline-block;
  padding: 0.75rem 1.75rem;
  background: var(--gradient-primary);
  color: #fff;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: var(--shadow-glow);
  transition: transform 0.2s var(--ease-spring), box-shadow 0.2s;
  letter-spacing: 0.01em;
}
.btn-primary:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 0 40px rgba(146,220,80,0.55);
  color: #fff;
}

/* 次要按鈕：白底萊姆綠框 */
.btn-secondary {
  display: inline-block;
  padding: 0.75rem 1.75rem;
  background: #fff;
  color: var(--clr-primary-dark);
  border: 1.5px solid var(--clr-primary-dark);
  border-radius: 999px;
  font-weight: 600;
  font-size: 1rem;
  transition: background 0.2s, border-color 0.2s, transform 0.2s, color 0.2s;
}
.btn-secondary:hover {
  background: var(--clr-primary-glow);
  border-color: var(--clr-primary-darker);
  transform: translateY(-2px);
  color: var(--clr-primary-darker);
}

/* 英雄統計數字 */
.hero-stats {
  display: flex;
  gap: 2.5rem;
  justify-content: center;
  animation: fadeInUp 1s var(--ease-smooth) 0.4s both;
}
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stat-num {
  font-size: 2rem;
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat-label {
  font-size: 0.8rem;
  color: var(--clr-text-muted);
  font-family: var(--font-zh);
}

/* ───────────────────────────────
   主體 Section
─────────────────────────────── */
.section {
  padding: 6rem 2rem;
}
.section-alt {
  background: var(--clr-surface);
}

.container {
  max-width: var(--container-w);
  margin: 0 auto;
}

/* Section Header */
.section-header {
  text-align: center;
  margin-bottom: 3.5rem;
}
.chapter-badge {
  display: inline-block;
  padding: 0.3rem 0.9rem;
  background: var(--clr-primary-glow);
  border: 1px solid var(--clr-border);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--clr-primary-dark);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
  font-weight: 700;
}
.section-header h2 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
  margin-bottom: 0.75rem;
  color: var(--clr-text);
}
.section-desc {
  color: var(--clr-text-muted);
  font-size: 1.05rem;
  max-width: 600px;
  margin: 0 auto;
}

/* ───────────────────────────────
   卡片系統
─────────────────────────────── */
.card-grid {
  display: grid;
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}
.card-grid.three-col { grid-template-columns: repeat(3, 1fr); }
.card-grid.two-col   { grid-template-columns: repeat(2, 1fr); }

.info-card {
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  transition: border-color 0.3s, transform 0.3s, box-shadow 0.3s;
}
.info-card:hover {
  border-color: var(--clr-border);
  transform: translateY(-4px);
  box-shadow: var(--shadow-card);
}

/* 強調卡片：萊姆綠邊框 */
.highlight-card {
  border-color: rgba(146,220,80,0.4);
  background: rgba(146,220,80,0.06);
}
.highlight-card:hover {
  border-color: var(--clr-primary);
  box-shadow: 0 4px 28px rgba(146,220,80,0.22);
}

.card-icon {
  font-size: 2rem;
  margin-bottom: 0.75rem;
}
.info-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--clr-text);
}
.info-card p {
  font-size: 0.9rem;
  color: var(--clr-text-muted);
  margin-bottom: 0.75rem;
}
.card-example {
  font-size: 0.8rem;
  color: var(--clr-accent);
  background: rgba(230,126,34,0.08);
  border: 1px solid rgba(230,126,34,0.2);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  display: inline-block;
}

/* ───────────────────────────────
   概念區塊
─────────────────────────────── */
.concept-block {
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2.5rem;
}
.concept-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--clr-text);
}

/* 元素網格 */
.element-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}
.element-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.4rem;
  padding: 1.25rem 1rem;
  background: var(--clr-bg);
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius-md);
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  cursor: default;
}
.element-item:hover {
  border-color: var(--clr-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(146,220,80,0.15);
}
.elem-symbol { font-size: 1.8rem; }
.elem-name   { font-size: 0.9rem; font-weight: 600; color: var(--clr-text); }
.elem-desc   { font-size: 0.78rem; color: var(--clr-text-muted); }

/* ───────────────────────────────
   循環圖
─────────────────────────────── */
.loop-diagram {
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2.5rem;
}
.loop-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  margin: 2rem 0;
  flex-wrap: wrap;
}
.loop-node {
  padding: 1rem 2rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  color: #fff;
}
/* Agent 節點：主色漸層 */
.node-agent {
  background: var(--gradient-primary);
  box-shadow: var(--shadow-glow);
  color: #fff;
}
/* Environment 節點：深青色 */
.node-env {
  background: linear-gradient(135deg, #1abc9c, #0e8c70);
  box-shadow: 0 0 24px rgba(26,188,156,0.3);
}
.loop-arrows {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 200px;
}
.arrow-top, .arrow-bottom {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.arrow-label {
  font-size: 0.8rem;
  color: var(--clr-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.arrow-line {
  flex: 1;
  height: 2px;
  background: var(--clr-border);
  position: relative;
}
.right-arrow::after {
  content: '▶';
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: var(--clr-primary-dark);
}
.left-arrow::before {
  content: '◀';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: var(--clr-accent-2);
}
.loop-caption {
  text-align: center;
  font-size: 0.85rem;
  color: var(--clr-text-muted);
}

/* ───────────────────────────────
   數學區塊
─────────────────────────────── */
.math-block {
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
}
.math-block h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--clr-text);
}
.math-block p {
  color: var(--clr-text-muted);
  margin-bottom: 1rem;
  line-height: 1.8;
}

/* 公式框 */
.formula-box {
  background: var(--clr-bg);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  margin: 1rem 0;
  overflow-x: auto;
  text-align: center;
}
/* 重點公式框：萊姆綠邊框 */
.formula-box.primary {
  border-color: rgba(146,220,80,0.5);
  background: rgba(146,220,80,0.05);
  box-shadow: 0 0 20px rgba(146,220,80,0.1);
}
.formula-box.small {
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
}

/* KaTeX 字體大小調整 */
.formula-box .katex { font-size: 1.1em; }
.formula-box.small .katex { font-size: 1em; }

/* 變數說明表 */
.formula-explain {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 1rem 0;
}
.formula-explain.wide { max-width: 100%; }
.var-row {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  font-size: 0.9rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--clr-border-light);
}
.var-row:last-child { border-bottom: none; }
.var {
  min-width: 180px;
  font-family: var(--font-mono);
  color: var(--clr-accent);
  font-size: 0.88rem;
  flex-shrink: 0;
}

/* 洞察框：青綠底色 */
.insight-box {
  background: rgba(26,188,156,0.07);
  border: 1px solid rgba(26,188,156,0.25);
  border-left: 3px solid var(--clr-accent-2);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  color: var(--clr-text);
  margin: 1rem 0;
  line-height: 1.7;
}

/* ───────────────────────────────
   推導步驟區塊
─────────────────────────────── */
.derivation-block {
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
}
.derivation-block h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--clr-text);
}

.derivation-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}
/* 左側連線：萊姆綠漸層 */
.derivation-steps::before {
  content: '';
  position: absolute;
  left: 22px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, var(--clr-primary), var(--clr-accent-2));
  border-radius: 2px;
}

.deriv-step {
  padding: 1.5rem 1.5rem 1.5rem 3.5rem;
  position: relative;
  border-bottom: 1px solid var(--clr-border-light);
}
.deriv-step:last-child { border-bottom: none; }

/* 步驟節點圓圈 */
.deriv-step::before {
  content: '';
  position: absolute;
  left: 14px;
  top: 1.6rem;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--clr-bg);
  border: 2px solid var(--clr-primary);
}
/* 最終步驟：填滿主色 */
.highlight-step::before {
  background: var(--clr-primary);
  box-shadow: var(--shadow-glow);
}

.step-num {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--clr-primary-dark);
  margin-bottom: 0.5rem;
  font-family: var(--font-sans);
}
.deriv-step p {
  font-size: 0.92rem;
  color: var(--clr-text-muted);
  margin-bottom: 0.5rem;
  line-height: 1.7;
}
.step-note {
  font-size: 0.82rem !important;
  color: var(--clr-text-dim) !important;
  font-style: italic;
}

/* 高亮步驟：淡綠底色 */
.highlight-step {
  background: rgba(146,220,80,0.06);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

/* 兩欄數學 */
.two-col-math {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 1rem 0;
}
.math-col h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--clr-text);
}
.math-col p {
  font-size: 0.88rem;
  color: var(--clr-text-muted);
}

/* ───────────────────────────────
   演算法偽碼
─────────────────────────────── */
.algo-block {
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
}
.algo-block h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--clr-text);
}
.code-block {
  background: #1e2a15;           /* 深墨綠底色，呼應主色 */
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  overflow-x: auto;
}
.code-block pre {
  padding: 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.9;
  color: #c8e6a0;               /* 淡綠色文字 */
  white-space: pre;
}
.code-block code {
  font-family: var(--font-mono);
}

/* ───────────────────────────────
   互動展示
─────────────────────────────── */
.interactive-block {
  background: var(--clr-surface-2);
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
}
.interactive-block h3 {
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--clr-text);
}
.interactive-block > p {
  color: var(--clr-text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

/* GridWorld */
.gridworld-container {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  align-items: flex-start;
}
.gridworld {
  display: grid;
  grid-template-columns: repeat(5, 60px);
  grid-template-rows: repeat(5, 60px);
  gap: 4px;
  flex-shrink: 0;
}
.gw-cell {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  background: var(--clr-bg);
  border-color: var(--clr-border-light);
  position: relative;
}
.gw-cell:hover {
  transform: scale(1.08);
  border-color: var(--clr-primary);
  box-shadow: 0 0 12px rgba(146,220,80,0.25);
}
.gw-cell.selected {
  border-color: var(--clr-primary);
  box-shadow: 0 0 16px rgba(146,220,80,0.3);
}
.gw-cell.gw-goal  { background: rgba(80,250,123,0.12); border-color: rgba(80,250,123,0.45); }
.gw-cell.gw-trap  { background: rgba(231,76,60,0.1);   border-color: rgba(231,76,60,0.4); }
.gw-cell.gw-wall  { background: rgba(100,110,80,0.18); border-color: transparent; cursor: not-allowed; }
.gw-cell.gw-start { background: rgba(146,220,80,0.14); border-color: rgba(146,220,80,0.45); }

.gridworld-info {
  flex: 1;
  min-width: 200px;
  background: var(--clr-bg);
  border: 1px solid var(--clr-border-light);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  font-size: 0.88rem;
  min-height: 200px;
}
.gridworld-info p { color: var(--clr-text-muted); }

.gridworld-legend {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--clr-text-muted);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.legend-color {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}
.legend-color.green { background: rgba(80,250,123,0.55); }
.legend-color.red   { background: rgba(231,76,60,0.55); }
.legend-color.gray  { background: rgba(100,110,80,0.45); }
/* 起點改為萊姆綠 */
.legend-color.blue  { background: rgba(146,220,80,0.6); }

/* Q-Learning Demo */
.ql-demo {}
.ql-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

/* 互動按鈕：萊姆綠系 */
.btn-demo {
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--clr-primary);
  background: var(--clr-primary-glow);
  color: var(--clr-text);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, color 0.2s;
  font-family: var(--font-zh);
}
.btn-demo:hover {
  background: var(--clr-primary);
  color: #fff;
  transform: translateY(-1px);
}
/* 重置按鈕 */
.btn-reset {
  border-color: rgba(231,76,60,0.5);
  background: rgba(231,76,60,0.07);
  color: var(--clr-text);
}
.btn-reset:hover {
  background: rgba(231,76,60,0.18);
  color: var(--clr-text);
}
.ql-info {
  font-size: 0.85rem;
  color: var(--clr-text-muted);
  margin-left: auto;
}
.ql-grid-wrap {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  align-items: flex-start;
}
.ql-grid {
  display: grid;
  grid-template-columns: repeat(4, 70px);
  grid-template-rows: repeat(4, 70px);
  gap: 4px;
  flex-shrink: 0;
}
.ql-cell {
  width: 70px;
  height: 70px;
  border-radius: 8px;
  background: var(--clr-bg);
  border: 2px solid var(--clr-border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  position: relative;
  transition: border-color 0.2s;
}
/* Agent 格：萊姆綠邊框 */
.ql-cell.ql-agent { border-color: var(--clr-primary); box-shadow: 0 0 14px rgba(146,220,80,0.3); }
.ql-cell.ql-goal  { background: rgba(80,250,123,0.1); border-color: rgba(80,250,123,0.5); }
.ql-cell.ql-trap  { background: rgba(231,76,60,0.1);  border-color: rgba(231,76,60,0.45); }
.ql-cell.ql-wall  { background: rgba(100,110,80,0.15); }

.ql-qvals {
  flex: 1;
  min-width: 200px;
}
.ql-qvals h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--clr-text-muted);
}
#qlTable {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.qt-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}
.qt-label { color: var(--clr-text-muted); min-width: 60px; }
/* Q 值進度條：萊姆綠 */
.qt-bar-wrap { flex: 1; background: var(--clr-bg); border-radius: 4px; height: 14px; overflow: hidden; border: 1px solid var(--clr-border-light); }
.qt-bar { height: 100%; background: var(--gradient-primary); border-radius: 4px; transition: width 0.5s var(--ease-smooth); }
.qt-val { min-width: 52px; text-align: right; color: var(--clr-accent); font-size: 0.78rem; }

/* ───────────────────────────────
   備份圖
─────────────────────────────── */
.backup-diagram {
  display: flex;
  justify-content: center;
  gap: 3rem;
  flex-wrap: wrap;
}
.backup-v {
  text-align: center;
}
.bd-title {
  font-size: 0.9rem;
  color: var(--clr-text-muted);
  margin-bottom: 0.75rem;
  font-family: var(--font-mono);
}
.backup-svg {
  width: 200px;
  height: 220px;
}

/* ───────────────────────────────
   比較表格
─────────────────────────────── */
.comparison-table {
  margin-bottom: 2rem;
}
.comparison-table .concept-title { margin-bottom: 1rem; }

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--clr-border-light);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
thead th {
  background: var(--clr-surface);
  padding: 0.9rem 1rem;
  text-align: left;
  font-weight: 700;
  color: var(--clr-text);
  white-space: nowrap;
  border-bottom: 2px solid var(--clr-border);
}
tbody td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--clr-border-light);
  color: var(--clr-text-muted);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
/* Hover 行：淡綠底 */
tbody tr:hover td { background: rgba(146,220,80,0.05); }
/* 高亮行（PPO）：萊姆綠底 */
.highlight-row td { background: rgba(146,220,80,0.08); }
.highlight-row td strong { color: var(--clr-primary-dark); }

/* ───────────────────────────────
   頁尾
─────────────────────────────── */
#footer {
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border-light);
  padding: 3rem 2rem 2rem;
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 2rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}
.footer-brand .logo-text {
  font-size: 1.1rem;
  font-weight: 700;
}
.footer-brand p {
  color: var(--clr-text-muted);
  font-size: 0.85rem;
  margin-top: 0.35rem;
}
.footer-nav {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.footer-nav a {
  color: var(--clr-text-muted);
  font-size: 0.88rem;
  transition: color 0.2s;
}
.footer-nav a:hover { color: var(--clr-primary-dark); }
.footer-bottom {
  padding-top: 1.5rem;
  border-top: 1px solid var(--clr-border-light);
  text-align: center;
  font-size: 0.8rem;
  color: var(--clr-text-dim);
}

/* ───────────────────────────────
   動畫 Keyframes
─────────────────────────────── */
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* Scroll 進場動畫 */
.scroll-reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s var(--ease-smooth), transform 0.6s var(--ease-smooth);
}
.scroll-reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ───────────────────────────────
   響應式設計
─────────────────────────────── */

/* 平板（≤900px） */
@media (max-width: 900px) {
  .card-grid.three-col { grid-template-columns: 1fr 1fr; }
  .card-grid.two-col   { grid-template-columns: 1fr; }
  .two-col-math        { grid-template-columns: 1fr; }
  .var-row             { flex-direction: column; gap: 0.25rem; }
  .var                 { min-width: auto; }
  .loop-arrows         { min-width: 160px; }
}

/* 手機（≤768px） */
@media (max-width: 768px) {
  /* 隱藏桌機導航，顯示漢堡按鈕 */
  .nav-links { display: none; }
  .nav-links.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: var(--nav-h);
    left: 0; right: 0;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--clr-border-light);
    padding: 1rem;
    gap: 0.25rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  }
  .nav-toggle { display: block; }

  /* Section 間距縮小 */
  .section { padding: 4rem 1.25rem; }

  /* 三欄改一欄 */
  .card-grid.three-col { grid-template-columns: 1fr; }

  /* GridWorld 縮小格子 */
  .gridworld {
    grid-template-columns: repeat(5, 48px);
    grid-template-rows: repeat(5, 48px);
  }
  .gw-cell { width: 48px; height: 48px; font-size: 1rem; }

  /* Q-Learning 格子 */
  .ql-grid {
    grid-template-columns: repeat(4, 56px);
    grid-template-rows: repeat(4, 56px);
  }
  .ql-cell { width: 56px; height: 56px; }

  /* 段落縮排 */
  .deriv-step { padding: 1.25rem 1.25rem 1.25rem 3rem; }

  /* 表格橫向捲動 */
  .table-wrap { border-radius: var(--radius-sm); }
}

/* 小手機（≤480px） */
@media (max-width: 480px) {
  .hero-stats { gap: 1.5rem; }
  .stat-num { font-size: 1.6rem; }

  /* 循環圖垂直排列 */
  .loop-visual { flex-direction: column; }
  .loop-arrows { min-width: auto; width: 200px; }

  /* 導航 Logo 縮小 */
  .nav-logo { font-size: 1rem; }
  .logo-icon { font-size: 1.1rem; }

  /* 英雄按鈕全寬 */
  .hero-actions { flex-direction: column; align-items: center; }
  .btn-primary, .btn-secondary { width: 100%; max-width: 280px; text-align: center; }

  /* 元素網格最小寬 */
  .element-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }

  /* 偽碼字體更小 */
  .code-block pre { font-size: 0.78rem; padding: 1rem; }

  /* GridWorld 更小 */
  .gridworld {
    grid-template-columns: repeat(5, 42px);
    grid-template-rows: repeat(5, 42px);
  }
  .gw-cell { width: 42px; height: 42px; font-size: 0.9rem; }

  /* Q-Learning 更小 */
  .ql-grid {
    grid-template-columns: repeat(4, 52px);
    grid-template-rows: repeat(4, 52px);
  }
  .ql-cell { width: 52px; height: 52px; font-size: 1.1rem; }
}
