/* ==========================================================================
   Apple Design Language - 統測資電通 (TVE EE & CS Master)
   Designed with minimalism, elegance, SF Pro typography, and restrained contrast.
   ========================================================================== */

:root {
  /* Apple Dark Theme (Default) */
  --bg-body: #000000;
  --bg-surface: #161617;
  --bg-surface-elevated: #1d1d1f;
  --bg-surface-subtle: #242426;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.18);
  --text-primary: #f5f5f7;
  --text-secondary: #86868b;
  --text-tertiary: #6e6e73;
  --apple-blue: #0071e3;
  --apple-blue-hover: #0077ed;
  --apple-green: #30d158;
  --apple-orange: #ff9f0a;
  --apple-red: #ff453a;
  --apple-purple: #bf5af2;
  --nav-bg: rgba(0, 0, 0, 0.82);
  --segmented-bg: #1d1d1f;
  --segmented-active: #2c2c2e;
  --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --radius-card: 16px;
  --radius-pill: 980px;
  --radius-sm: 8px;
}

body.light-theme {
  /* Apple Light Theme */
  --bg-body: #f5f5f7;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-surface-subtle: #fbfbfd;
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.16);
  --text-primary: #1d1d1f;
  --text-secondary: #86868b;
  --text-tertiary: #a1a1a6;
  --apple-blue: #0071e3;
  --apple-blue-hover: #0077ed;
  --apple-green: #28cd41;
  --apple-orange: #ff9500;
  --apple-red: #ff3b30;
  --nav-bg: rgba(245, 245, 247, 0.85);
  --segmented-bg: #e5e5ea;
  --segmented-active: #ffffff;
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "PingFang TC", "Noto Sans TC", sans-serif;
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  letter-spacing: -0.011em;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* 頂部導覽列 (Apple Header) */
.navbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 1.5rem;
  height: 52px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  letter-spacing: -0.015em;
}

.nav-brand .logo-badge {
  color: var(--apple-blue);
  font-size: 1.1rem;
}

.nav-brand small {
  color: var(--text-secondary);
  font-weight: 400;
  font-size: 0.8rem;
  margin-left: 4px;
}

.nav-mobile-actions {
  display: none;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-menu::-webkit-scrollbar { display: none; }

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 400;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
  white-space: nowrap;
  cursor: pointer;
}

.nav-link:hover {
  color: var(--text-primary);
}

.nav-link.active {
  color: var(--text-primary);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.08);
}
body.light-theme .nav-link.active {
  background: rgba(0, 0, 0, 0.06);
}

.nav-link.highlight-tab {
  color: var(--apple-green);
  font-weight: 600;
}

.theme-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.theme-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}

/* 主要容器 */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem 1.25rem;
}

/* Apple 標誌性 Hero 區域 */
.hero {
  text-align: center;
  padding: 3.5rem 1rem 3rem 1rem;
  margin-bottom: 2.5rem;
}

.hero-eyebrow {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--apple-blue);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.hero h1 {
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  line-height: 1.15;
  margin-bottom: 1rem;
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
}

.hero p {
  font-size: 1.15rem;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 680px;
  margin: 0 auto 2rem auto;
  font-weight: 400;
}

.hero-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Apple 按鈕風格 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
  text-decoration: none;
}

.btn-primary {
  background: var(--apple-blue);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--apple-blue-hover);
  transform: scale(1.02);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}
.btn-secondary:hover {
  border-color: var(--border-hover);
  background: var(--bg-surface-subtle);
}

.btn-accent-green {
  background: rgba(48, 209, 88, 0.15);
  color: var(--apple-green);
  border: 1px solid rgba(48, 209, 88, 0.3);
}
.btn-accent-green:hover {
  background: var(--apple-green);
  color: #000000;
}

.btn-danger {
  background: rgba(255, 69, 58, 0.15);
  color: var(--apple-red);
  border: 1px solid rgba(255, 69, 58, 0.3);
}
.btn-danger:hover {
  background: var(--apple-red);
  color: #ffffff;
}

/* 卡片與容器 */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 1.75rem;
  box-shadow: var(--card-shadow);
  margin-bottom: 1.5rem;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.card:hover {
  border-color: var(--border-hover);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.card-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Apple 標籤 (Badges) */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-primary {
  background: rgba(0, 113, 227, 0.12);
  color: var(--apple-blue);
}

.badge-secondary {
  background: rgba(134, 134, 139, 0.12);
  color: var(--text-secondary);
}

.badge-success {
  background: rgba(48, 209, 88, 0.12);
  color: var(--apple-green);
}

.badge-warning {
  background: rgba(255, 159, 10, 0.12);
  color: var(--apple-orange);
}

.badge-danger {
  background: rgba(255, 69, 58, 0.12);
  color: var(--apple-red);
}

.badge-purple {
  background: rgba(175, 82, 222, 0.15);
  color: #d084f7;
  border: 1px solid rgba(175, 82, 222, 0.32);
}

/* 專業(一) vs 專業(二) 專屬色彩區隔 */
.badge-p1 {
  background: rgba(0, 113, 227, 0.12);
  color: #2997ff;
  border: 1px solid rgba(0, 113, 227, 0.28);
}

.badge-p2 {
  background: rgba(175, 82, 222, 0.15);
  color: #d084f7;
  border: 1px solid rgba(175, 82, 222, 0.32);
}

.apple-tag-p1 {
  display: inline-flex;
  align-items: center;
  background: rgba(0, 113, 227, 0.12);
  color: #2997ff;
  border: 1px solid rgba(0, 113, 227, 0.25);
  padding: 3px 9px;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.apple-tag-p2 {
  display: inline-flex;
  align-items: center;
  background: rgba(175, 82, 222, 0.15);
  color: #d084f7;
  border: 1px solid rgba(175, 82, 222, 0.3);
  padding: 3px 9px;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
}

/* 網格系統 */
.grid-cols-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

.grid-cols-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

/* iOS 分段控制器 (Segmented Control) */
.segmented-control {
  display: inline-flex;
  background: var(--segmented-bg);
  padding: 3px;
  border-radius: var(--radius-pill);
  gap: 2px;
  max-width: 100%;
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.segmented-btn {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.segmented-btn:hover {
  color: var(--text-primary);
}

.segmented-btn.active {
  background: var(--segmented-active);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

/* 輸入框 */
.search-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--apple-blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.2);
}

/* 新手生活比喻卡片 (Beginner Cards) */
.analogy-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.analogy-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

.analogy-icon {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
  display: inline-block;
}

.analogy-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.analogy-sub {
  font-size: 0.82rem;
  color: var(--apple-blue);
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.analogy-box {
  background: var(--bg-surface-elevated);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  border-left: 3px solid var(--apple-green);
}

.analogy-exam-tip {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* 陷阱防雷卡 (Pitfall Alert) */
.pitfall-card {
  background: var(--bg-surface);
  border-left: 4px solid var(--apple-orange);
  border-radius: 0 var(--radius-card) var(--radius-card) 0;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

/* 科目分支標題與橫幅 */
.branch-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 1.25rem 1.5rem;
  margin: 2.25rem 0 1.25rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.branch-banner.p1 {
  border-left: 5px solid var(--apple-blue);
}

.branch-banner.p2 {
  border-left: 5px solid var(--apple-purple);
}

.sub-branch-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 1.75rem 0 1rem 0;
  color: var(--text-primary);
  font-size: 1.12rem;
  font-weight: 600;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
}

/* 分支入口門戶大廳 (Branch Entrance Portal) */
.portal-entry-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 1.85rem;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.portal-entry-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.4);
}

.portal-entry-card.p1-portal {
  border-top: 5px solid var(--apple-blue);
}

.portal-entry-card.p2-portal {
  border-top: 5px solid var(--apple-purple);
}

.portal-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 1rem;
}

.portal-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.portal-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.portal-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1.25rem;
}

.portal-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 1.5rem;
}

.portal-chip {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.portal-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}

.branch-breadcrumb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 10px;
}

/* 練習區章節卡片 (Quiz Chapter Card) */
.quiz-chapter-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 1.25rem 1.4rem;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.quiz-chapter-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-hover);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.quiz-chapter-card.p1-border {
  border-left: 4px solid var(--apple-blue);
}

.quiz-chapter-card.p2-border {
  border-left: 4px solid var(--apple-purple);
}

.chapter-code-badge {
  font-family: "SF Mono", Menlo, Monaco, monospace;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(0, 113, 227, 0.12);
  color: var(--apple-blue);
}

.chapter-code-badge.p2-badge {
  background: rgba(175, 82, 222, 0.12);
  color: var(--apple-purple);
}

/* 測驗樣式 */
.quiz-opt-btn {
  width: 100%;
  text-align: left;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  margin-bottom: 10px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: all 0.15s ease;
  box-sizing: border-box;
}

.quiz-opt-btn:hover {
  border-color: var(--border-hover);
  background: var(--bg-surface-subtle);
}

.quiz-opt-btn.selected {
  border-color: var(--apple-blue);
  background: rgba(0, 113, 227, 0.12);
  color: var(--apple-blue);
  font-weight: 600;
}

.opt-letter {
  display: inline-flex;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
  margin-top: 1px;
}

.opt-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: break-word;
  line-height: 1.5;
}

.quiz-opt-btn.selected .opt-letter {
  background: var(--apple-blue);
  color: #ffffff;
  border-color: var(--apple-blue);
}

/* 統測官方原卷電路與波形圖容器 (Apple Minimal Card) */
.quiz-real-diagram-wrap {
  text-align: center;
  padding: 16px 20px;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  margin: 14px auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  box-sizing: border-box;
}

[data-theme="dark"] .quiz-real-diagram-wrap {
  background: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

.quiz-real-diagram-wrap img {
  max-width: 100%;
  max-height: 480px;
  height: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  border-radius: 6px;
  image-rendering: -webkit-optimize-contrast;
}

/* KaTeX 數學公式在選項與題目中的美化與排版適配 */
.katex {
  font-size: 1.08em;
  text-rendering: optimizeLegibility;
}
.quiz-opt-btn .katex {
  color: inherit;
}
.katex-display {
  margin: 0.5em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

/* 新手求助抽屜與白話解析 */
.hint-drawer-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #38bdf8;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-bottom: 1.25rem;
}

.hint-drawer-btn:hover {
  background: rgba(56, 189, 248, 0.16);
  border-color: #38bdf8;
  transform: translateY(-1px);
}

.question-hint-box {
  background: var(--bg-surface-elevated);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: 0.88rem;
  line-height: 1.65;
  animation: fadeIn 0.25s ease;
}

.hint-sub-section {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.hint-sub-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* 6 大代號密碼卡片 */
.decoder-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 1.35rem;
  margin-bottom: 1rem;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.decoder-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

.decoder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.decoder-code-pill {
  font-family: "SF Mono", Menlo, Monaco, monospace;
  background: rgba(0, 113, 227, 0.12);
  color: var(--apple-blue);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
}

.decoder-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.decoder-body {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.decoder-highlight {
  margin-top: 8px;
  background: var(--bg-surface-elevated);
  padding: 8px 12px;
  border-radius: 8px;
  border-left: 3px solid var(--apple-green);
  font-size: 0.84rem;
  color: var(--text-primary);
}

.quiz-chapter-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 1.35rem;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  position: relative;
}

.quiz-chapter-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-hover);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.quiz-chapter-card.p1-card:hover {
  border-color: rgba(0, 113, 227, 0.45);
}

.quiz-chapter-card.p2-card:hover {
  border-color: rgba(175, 82, 222, 0.45);
}

.chapter-badge-p1 {
  background: rgba(0, 113, 227, 0.14);
  color: var(--apple-blue);
  border: 1px solid rgba(0, 113, 227, 0.28);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}

.chapter-badge-p2 {
  background: rgba(175, 82, 222, 0.14);
  color: var(--apple-purple);
  border: 1px solid rgba(175, 82, 222, 0.28);
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
}

.chapter-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.chapter-card-title {
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 6px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chapter-card-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 1rem;
}

.chapter-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
  font-size: 0.82rem;
}

.quiz-top-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
}

/* 圓形小球答題卡 (Apple Circular Bubble Answer Grid) */
.quiz-question-grid, #quiz-question-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-top: 1.25rem;
  padding: 4px;
}

.grid-item {
  width: 40px;
  height: 40px;
  border-radius: 50% !important; /* 完美圓形小球 */
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-elevated);
  border: 1.5px solid var(--border-subtle);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
  margin: 0 auto;
  user-select: none;
}

.grid-item:hover {
  transform: scale(1.15);
  border-color: var(--apple-blue);
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3);
}

/* 已作答小球 (Filled Apple Blue Sphere) */
.grid-item.answered {
  background: var(--apple-blue) !important;
  border-color: var(--apple-blue) !important;
  color: #ffffff !important;
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(0, 113, 227, 0.45);
}

/* 當前作答中小球 (Pulsing Halo Ring) */
.grid-item.current {
  border-color: #ffffff !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 2.5px var(--bg-surface), 0 0 0 4.5px var(--apple-blue);
  transform: scale(1.12);
  font-weight: 700;
}

body.light-theme .grid-item.current {
  border-color: #1d1d1f !important;
  color: #1d1d1f !important;
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px var(--apple-blue);
}

.grid-item.current.answered {
  background: var(--apple-blue) !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 2.5px var(--bg-surface), 0 0 0 4.5px var(--apple-blue), 0 4px 12px rgba(0, 113, 227, 0.5);
}

/* 答題卡底部狀態小球圖例 (Bubble Legend) */
.quiz-grid-legend {
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin-top: 1.25rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.quiz-grid-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.quiz-legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}
.quiz-legend-dot.unanswered {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
}
.quiz-legend-dot.answered {
  background: var(--apple-blue);
}
.quiz-legend-dot.current {
  background: transparent;
  border: 2px solid var(--apple-blue);
}

.review-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.review-item.correct {
  border-left: 4px solid var(--apple-green);
}

.review-item.wrong {
  border-left: 4px solid var(--apple-red);
}

.explanation-box {
  background: var(--bg-surface-elevated);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
  color: var(--text-primary);
  margin-top: 10px;
  line-height: 1.6;
}

/* 公式卡片 - Apple 磨砂質感與科目專屬標色 */
.formula-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 1.25rem;
  margin-bottom: 1.1rem;
  transition: all 0.22s ease;
  position: relative;
}

.formula-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.formula-card.p1-card {
  border-left: 4px solid var(--apple-blue);
}

.formula-card.p2-card {
  border-left: 4px solid #af52de;
}

.formula-code-box {
  background: rgba(255, 255, 255, 0.03);
  color: #f1f5f9;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 0.96rem;
  font-weight: 500;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  margin: 10px 0;
  border: 1px solid var(--border-subtle);
  letter-spacing: 0.01em;
}

body.light-theme .formula-code-box {
  background: #f8fafc;
  color: #0f172a;
  border-color: #e2e8f0;
}

.formula-card.p1-card .formula-code-box {
  border-color: rgba(0, 113, 227, 0.22);
  background: linear-gradient(135deg, rgba(0, 113, 227, 0.05) 0%, rgba(0, 113, 227, 0.01) 100%);
}

.formula-card.p2-card .formula-code-box {
  border-color: rgba(175, 82, 222, 0.28);
  background: linear-gradient(135deg, rgba(175, 82, 222, 0.06) 0%, rgba(175, 82, 222, 0.01) 100%);
}

/* 微處理機試算儀折疊容器 (Non-intrusive Tool Drawer) */
.apple-tool-drawer {
  background: var(--bg-surface);
  border: 1px solid rgba(175, 82, 222, 0.32);
  border-radius: var(--radius-card);
  margin-bottom: 1.5rem;
  overflow: hidden;
  transition: all 0.25s ease;
  box-shadow: 0 4px 20px rgba(175, 82, 222, 0.06);
}

.apple-tool-drawer-header {
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  background: linear-gradient(135deg, rgba(175, 82, 222, 0.09) 0%, rgba(88, 86, 214, 0.04) 100%);
  user-select: none;
  transition: background 0.2s ease;
}

.apple-tool-drawer-header:hover {
  background: linear-gradient(135deg, rgba(175, 82, 222, 0.14) 0%, rgba(88, 86, 214, 0.08) 100%);
}

.apple-tool-drawer-body {
  padding: 16px 18px;
  border-top: 1px solid rgba(175, 82, 222, 0.2);
}

/* 隨機換題數值按鈕樣式 */
.btn-randomize-val {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, rgba(255, 159, 10, 0.15) 0%, rgba(255, 69, 58, 0.12) 100%);
  color: #ff9f0a;
  border: 1px solid rgba(255, 159, 10, 0.35);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-randomize-val:hover {
  background: linear-gradient(135deg, rgba(255, 159, 10, 0.25) 0%, rgba(255, 69, 58, 0.22) 100%);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(255, 159, 10, 0.2);
}

.btn-randomize-val:active {
  transform: scale(0.97);
}

/* 隨機數值提示浮動通知 */
.random-val-toast {
  animation: toastFade 2.5s forwards ease;
  position: fixed;
  top: 70px;
  right: 20px;
  background: rgba(26, 26, 30, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid #ff9f0a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 0.88rem;
  z-index: 9999;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

@keyframes toastFade {
  0% { opacity: 0; transform: translateY(-10px); }
  15% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* 頁尾 */
.footer {
  text-align: center;
  padding: 3rem 1rem;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font-size: 0.8rem;
  line-height: 1.6;
}

@media (max-width: 768px) {
  .hero h1 { font-size: 2rem; }
  .grid-cols-2, .grid-cols-3 { grid-template-columns: 1fr; }
  .navbar { height: 52px; padding: 0 1rem; flex-direction: row; justify-content: space-between; align-items: center; }
  .quiz-question-grid { grid-template-columns: repeat(4, 1fr); }
}


/* ==========================================================================
   ✨ 極簡現代清單樣式 (Clean Minimalist List & TOC)
   ========================================================================== */
.clean-chapter-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 1rem;
}

.clean-chapter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  gap: 14px;
}

.clean-chapter-row:hover {
  border-color: var(--border-hover);
  background: var(--bg-surface-elevated);
  transform: translateX(4px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.clean-chapter-row.p1-row:hover {
  border-left: 4px solid var(--apple-blue);
}

.clean-chapter-row.p2-row:hover {
  border-left: 4px solid var(--apple-purple);
}

.clean-chapter-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.clean-chapter-code {
  font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.clean-chapter-code.p1 {
  color: var(--apple-blue);
  background: rgba(0, 113, 227, 0.1);
  border-color: rgba(0, 113, 227, 0.25);
}

.clean-chapter-code.p2 {
  color: var(--apple-purple);
  background: rgba(175, 82, 222, 0.1);
  border-color: rgba(175, 82, 222, 0.25);
}

.clean-chapter-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.clean-chapter-title {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clean-chapter-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.clean-chapter-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 簡潔次科目切換膠囊列 */
.subsubject-pill-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 10px 2px;
  margin-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.subsubject-pill {
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.subsubject-pill:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.subsubject-pill.active {
  background: var(--apple-blue);
  color: #ffffff;
  border-color: var(--apple-blue);
  font-weight: 600;
}

.subsubject-pill.active.p2-pill {
  background: var(--apple-purple);
  border-color: var(--apple-purple);
}

/* 簡潔入口大卡片 */
.minimal-portal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.minimal-portal-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-hover);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.minimal-portal-card.p1-card {
  border-top: 4px solid var(--apple-blue);
}

.minimal-portal-card.p2-card {
  border-top: 4px solid var(--apple-purple);
}


/* ==========================================================================
   📱 手機/行動裝置極致體驗優化 (Mobile Native App Adaptation)
   ========================================================================== */

/* 做題佈局容器 (桌機雙欄、手機單欄堆疊) */
.quiz-play-layout {
  display: grid;
  grid-template-columns: 2.4fr 1fr;
  gap: 1.5rem;
}

/* 手機底部原生風格導覽列 (Mobile Bottom Tab Bar) */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  /* 容器與版面邊距微調，留出充足底部安全距離，絕不被底部導覽列遮擋 */
  .container {
    padding: 0 12px;
    padding-bottom: 125px !important;
  }

  /* 頂部導覽列精簡化：手機只留 Logo 與右上角外觀切換 Icon */
  .navbar {
    height: 52px;
    padding: 0 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .nav-mobile-actions {
    display: flex !important;
    align-items: center;
  }

  .theme-icon-btn.mobile-nav-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem !important;
    background: var(--bg-surface-elevated, rgba(255, 255, 255, 0.08));
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.15));
    color: var(--text-primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
  }
  .theme-icon-btn.mobile-nav-btn:active {
    transform: scale(0.92);
  }

  .nav-menu {
    display: none !important; /* 手機端隱藏頂部密集選單 */
  }

  /* 顯示手機底部原生活力導覽列 */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-surface-elevated);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-subtle);
    z-index: 9999;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
  }

  .mobile-tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 500;
    gap: 3px;
    flex: 1;
    height: 100%;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-tab-item .tab-icon {
    font-size: 1.25rem;
    line-height: 1;
    transition: transform 0.15s ease;
  }

  .mobile-tab-item .tab-svg {
    transition: transform 0.15s ease, stroke 0.15s ease;
    margin-bottom: 2px;
  }

  .mobile-tab-item.active .tab-svg {
    stroke: var(--apple-blue);
    transform: scale(1.08);
  }

  .mobile-tab-item.active {
    color: var(--apple-blue) !important;
    font-weight: 600;
  }

  .mobile-tab-item.active {
    color: var(--apple-blue);
    font-weight: 700;
  }

  .mobile-tab-item.active .tab-icon {
    transform: scale(1.15);
  }

  /* Hero 區塊字體縮小與手機適配 */
  .hero {
    padding: 1.75rem 1rem;
    margin-bottom: 1.5rem;
  }
  .hero h1 {
    font-size: 1.5rem !important;
    line-height: 1.35;
  }
  .hero p {
    font-size: 0.88rem !important;
  }

  /* 首頁大卡片手機單欄 */
  .grid-cols-2, .grid-cols-3 {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* 測驗做題區手機單欄化，並確保下方充足間距 */
  .quiz-play-layout {
    grid-template-columns: 1fr !important;
    gap: 1.25rem;
    padding-bottom: 2.5rem;
    margin-bottom: 2rem;
  }

  /* 章節清單列在手機螢幕自動轉換為緊湊好點擊的卡片行 */
  .clean-chapter-row {
    flex-direction: column;
    align-items: stretch;
    padding: 14px 14px;
    gap: 10px;
  }

  .clean-chapter-left {
    width: 100%;
    gap: 10px;
  }

  .clean-chapter-title {
    font-size: 0.95rem;
    white-space: normal;
  }

  .clean-chapter-sub {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .clean-chapter-right {
    width: 100%;
    display: flex;
    justify-content: stretch;
    gap: 8px;
    border-top: 1px dashed var(--border-subtle);
    padding-top: 10px;
  }

  .clean-chapter-right .btn {
    flex: 1;
    text-align: center;
    justify-content: center;
    padding: 8px 12px !important;
    font-size: 0.85rem !important;
    min-height: 40px;
  }

  /* 答題選項按鈕增大觸控範圍 (防止誤觸) */
  .quiz-opt-btn {
    padding: 14px 16px;
    font-size: 0.92rem;
    min-height: 48px;
    line-height: 1.45;
  }

  /* 防止 iOS 輸入框聚焦時自動放大畫面 (文字至少 16px) */
  input[type="text"], input[type="number"], select, textarea {
    font-size: 16px !important;
  }

  /* 次科目膠囊列手機流暢橫向滾動 */
  .subsubject-pill-bar, .subsubject-segmented-bar {
    padding: 4px 0 10px 0;
  }
  .subsubject-pill, .segmented-btn {
    padding: 7px 14px;
    font-size: 0.82rem;
  }

  /* Canvas 電路圖全寬響應 */
  canvas {
    max-width: 100% !important;
    height: auto !important;
  }

  /* 手機端弱點分析彈窗全螢幕與流暢捲動優化 */
  .apple-modal-overlay {
    padding: 10px !important;
    align-items: flex-end !important;
  }
  .apple-modal-sheet {
    max-height: 90vh !important;
    border-radius: 20px 20px 0 0 !important;
    width: 100% !important;
  }
  .apple-modal-header {
    padding: 14px 16px !important;
  }
  .apple-modal-body {
    padding: 14px 16px !important;
  }

  /* 手機端題目排版防跑版與代碼適配 */
  #quiz-q-text {
    font-size: 1.05rem !important;
    line-height: 1.62 !important;
    margin-bottom: 1rem !important;
  }
  .apple-quiz-code-snippet {
    font-size: 0.82rem !important;
    padding: 10px 12px !important;
    margin: 8px 0 12px 0 !important;
    border-radius: 8px !important;
  }
  .quiz-real-diagram-wrap {
    padding: 8px !important;
    margin: 10px 0 !important;
  }
  .quiz-real-diagram-wrap img {
    max-height: 240px !important;
  }
}


/* ==========================================================================
   Apple Design Language - Past Exam Grid & Minimalist UI
   ========================================================================== */

.apple-quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 1.75rem;
}

.apple-segmented-bar {
  display: inline-flex;
  background: var(--bg-surface-elevated);
  padding: 4px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  gap: 4px;
}

.apple-segment-btn {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 7px 20px;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
}

.apple-segment-btn:hover {
  color: var(--text-primary);
}

.apple-segment-btn.active {
  background: var(--apple-blue);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 113, 227, 0.35);
}

body.light-theme .apple-segment-btn.active {
  background: #ffffff;
  color: #1d1d1f;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* Past Exam Grid & Cards */
.apple-exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.apple-exam-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 1.6rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.25s cubic-bezier(0.25, 1, 0.5, 1);
  position: relative;
  min-height: 190px;
}

.apple-exam-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-3px);
  box-shadow: var(--card-shadow);
}

.apple-exam-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.apple-exam-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--apple-blue);
  background: rgba(0, 113, 227, 0.12);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
}

.apple-exam-count {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.apple-exam-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.apple-exam-sub {
  font-size: 0.86rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  line-height: 1.5;
}

.apple-exam-meta {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
  margin-bottom: 1.1rem;
}

.apple-exam-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.apple-exam-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Apple Tag */
.apple-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(0, 113, 227, 0.12);
  color: var(--apple-blue);
  letter-spacing: -0.01em;
}

/* Apple Quiz Active Banner */
.apple-quiz-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.apple-quiz-mode-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.apple-quiz-meta {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

/* Apple Disclosure / Accordion */
.apple-hint-card {
  margin-bottom: 1.25rem;
  border-radius: 14px;
  border: 1px solid rgba(0, 113, 227, 0.25);
  background: var(--bg-surface-elevated);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 113, 227, 0.06);
}

.apple-hint-trigger {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 18px;
  background: rgba(0, 113, 227, 0.05);
  border: none;
  cursor: pointer;
  color: var(--apple-blue);
  font-size: 0.92rem;
  font-weight: 600;
  transition: background 0.15s ease;
}

.apple-hint-trigger:hover {
  background: rgba(0, 113, 227, 0.1);
}

.apple-hint-label {
  display: flex;
  align-items: center;
  gap: 6px;
  text-align: left;
  line-height: 1.4;
}

.apple-hint-action {
  font-size: 0.8rem;
  color: var(--apple-blue);
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(0, 113, 227, 0.12);
  flex-shrink: 0;
  margin-left: 10px;
}

.apple-hint-content {
  padding: 16px 20px 20px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.apple-hint-block {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--bg-surface-elevated);
  border-left: 3px solid var(--border-subtle);
}

.apple-hint-block:nth-child(1) {
  border-left-color: var(--apple-blue);
}

.apple-hint-block:nth-child(2) {
  border-left-color: var(--apple-purple);
}

.apple-hint-block:nth-child(3) {
  border-left-color: var(--apple-orange);
}

.apple-hint-block:last-child {
  margin-bottom: 0;
}

.apple-hint-tag {
  display: block;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 5px;
}

.apple-hint-text, .apple-hint-block p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin: 0;
}

/* 題目題幹與程式碼排版優化 (防止跑版或代碼擠壓) */
#quiz-q-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
}

.apple-quiz-code-snippet {
  font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.55;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 12px 16px;
  margin: 10px 0 14px 0;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-primary);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}


/* ==========================================================================
   Apple Schematic & Circuit Diagram Containers for Quiz
   ========================================================================== */
.quiz-diagram-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 1.25rem;
  margin: 1rem 0 1.5rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: auto;
  text-align: center;
}

.quiz-diagram-box svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

.quiz-real-diagram-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.quiz-real-diagram-wrap img {
  max-width: 100%;
  max-height: 420px;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  background: #ffffff;
  padding: 10px 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.quiz-diagram-caption {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* ==========================================================================
   Apple-Style Comprehensive Hero Cards (專業一 / 專業二 綜合亮點卡)
   ========================================================================== */
.apple-comp-hero-card {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: 1.75rem 2rem;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.apple-comp-hero-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
}

.apple-comp-hero-card.p1 {
  background: radial-gradient(ellipse at 90% 15%, rgba(0, 113, 227, 0.22) 0%, rgba(52, 199, 89, 0.1) 45%, rgba(22, 22, 26, 0.95) 100%);
  border-color: rgba(0, 113, 227, 0.35);
}

.apple-comp-hero-card.p2 {
  background: radial-gradient(ellipse at 90% 15%, rgba(175, 82, 222, 0.22) 0%, rgba(0, 113, 227, 0.12) 45%, rgba(22, 22, 26, 0.95) 100%);
  border-color: rgba(175, 82, 222, 0.35);
}

body.light-theme .apple-comp-hero-card.p1 {
  background: radial-gradient(ellipse at 90% 15%, rgba(0, 113, 227, 0.12) 0%, rgba(52, 199, 89, 0.08) 50%, #ffffff 100%);
  border-color: rgba(0, 113, 227, 0.25);
  box-shadow: 0 8px 24px rgba(0, 113, 227, 0.08);
}

body.light-theme .apple-comp-hero-card.p2 {
  background: radial-gradient(ellipse at 90% 15%, rgba(175, 82, 222, 0.12) 0%, rgba(0, 113, 227, 0.08) 50%, #ffffff 100%);
  border-color: rgba(175, 82, 222, 0.25);
  box-shadow: 0 8px 24px rgba(175, 82, 222, 0.08);
}

.apple-comp-hero-content {
  flex: 1;
  min-width: 290px;
  z-index: 2;
}

.apple-comp-hero-badge-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.apple-comp-hero-title {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin: 0 0 10px 0;
  line-height: 1.35;
}

.apple-comp-hero-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 1.25rem 0;
}

.apple-comp-hero-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.apple-comp-bullet-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 0.75rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.apple-comp-bullet-icon.p1 {
  background: rgba(0, 113, 227, 0.15);
  color: var(--apple-blue);
  border: 1px solid rgba(0, 113, 227, 0.3);
}

.apple-comp-bullet-icon.p2 {
  background: rgba(175, 82, 222, 0.15);
  color: var(--apple-purple);
  border: 1px solid rgba(175, 82, 222, 0.3);
}

/* 考點公式膠囊標籤 */
.apple-math-chip {
  display: inline-block;
  padding: 1px 7px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.14);
  vertical-align: baseline;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

body.light-theme .apple-math-chip {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
  color: #1d1d1f;
}

.apple-comp-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* 右側科技插畫 */
.apple-comp-hero-visual {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

@media (max-width: 860px) {
  .apple-comp-hero-card {
    flex-direction: column;
    align-items: stretch;
    padding: 1.25rem;
    gap: 1.25rem;
  }
  .apple-comp-hero-visual {
    order: -1;
    max-height: 140px;
  }
}

/* ==========================================================================
   📊 學習歷程與弱點分析彈窗樣式 (Apple Sheet Modal)
   ========================================================================== */
.btn-nav-history {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 113, 227, 0.08);
  color: var(--apple-blue);
  border: 1px solid rgba(0, 113, 227, 0.25);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-nav-history:hover {
  background: rgba(0, 113, 227, 0.15);
  border-color: var(--apple-blue);
  transform: translateY(-1px);
}

.apple-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.apple-modal-sheet {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: sheetSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes sheetSlideUp {
  from { transform: translateY(20px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.apple-modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  background: var(--bg-surface-elevated);
}

.apple-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.apple-modal-close:hover {
  background: var(--border-subtle);
  color: var(--text-primary);
}

.apple-modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

/* KPI 卡片 */
.weakness-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 1.5rem;
}

@media (max-width: 600px) {
  .weakness-kpi-grid {
    grid-template-columns: 1fr;
  }
}

.kpi-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  font-weight: 500;
  margin-bottom: 6px;
}

.kpi-val {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.kpi-unit {
  font-size: 0.95rem;
  font-weight: 500;
  margin-left: 2px;
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* 錯題突破橫幅 */
.apple-drill-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(135deg, rgba(255, 69, 58, 0.12) 0%, rgba(255, 159, 10, 0.08) 100%);
  border: 1px solid rgba(255, 69, 58, 0.25);
  border-radius: 16px;
  padding: 16px 20px;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

/* 弱點排行清單 */
.weakness-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.weakness-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 12px 16px;
}

.weakness-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 69, 58, 0.15);
  color: var(--apple-red);
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.weakness-info {
  flex: 1;
  min-width: 0;
}

.weakness-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.weakness-bar-bg {
  width: 100%;
  height: 6px;
  border-radius: 4px;
  background: var(--border-subtle);
  overflow: hidden;
}

.weakness-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--apple-orange), var(--apple-red));
  transition: width 0.3s ease;
}

/* 歷史測驗紀錄項目 */
.session-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  gap: 12px;
}
