/* ==========================================================================
   Viewer CSS — Apple HIG Design System
   Equipment Manual Electronic Lookup System
   ========================================================================== */

/* 1. Google Fonts Import
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* 2. CSS Variables
   ========================================================================== */
:root {
  /* Colors */
  --primary: #0071E3;
  --primary-light: #0077ED;
  --primary-dark: #005BB5;
  --primary-surface: rgba(0, 113, 227, 0.08);
  --success: #34C759;
  --success-surface: rgba(52, 199, 89, 0.1);
  --warning: #FF9F0A;
  --warning-surface: rgba(255, 159, 10, 0.1);
  --danger: #FF3B30;
  --danger-surface: rgba(255, 59, 48, 0.1);
  --info: #5AC8FA;
  --info-surface: rgba(90, 200, 250, 0.1);

  /* Surfaces */
  --surface: #FFFFFF;
  --surface-alt: #F5F5F7;
  --surface-elevated: #F5F5F7;
  --surface-overlay: rgba(0, 0, 0, 0.4);

  /* Text */
  --text-primary: #1D1D1F;
  --text-secondary: #86868B;
  --text-tertiary: #AEAEB2;
  --text-on-primary: #FFFFFF;

  /* Borders */
  --border: rgba(60, 60, 67, 0.2);
  --border-light: rgba(60, 60, 67, 0.12);
  --border-focus: #0071E3;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-2xl: 48px;
  --spacing-3xl: 64px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  /* Layout */
  --nav-height: 83px;
  --header-height: 52px;
  --toolbar-total-height: 91px;
  --toc-sidebar-width: 240px;
  --content-max-width: 720px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  /* Z-index */
  --z-index-header: 100;
  --z-index-nav: 100;
  --z-index-overlay: 200;
  --z-index-modal: 300;
  --z-index-toast: 400;

  /* Transitions */
  --transition-fast: 120ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-normal: 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-slow: 350ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* Dark mode — explicit data-theme */
[data-theme="dark"] {
  --primary: #0A84FF;
  --primary-light: #409CFF;
  --primary-dark: #0A84FF;
  --primary-surface: rgba(10, 132, 255, 0.12);
  --success: #30D158;
  --success-surface: rgba(48, 209, 88, 0.15);
  --warning: #FFD60A;
  --warning-surface: rgba(255, 214, 10, 0.12);
  --danger: #FF453A;
  --danger-surface: rgba(255, 69, 58, 0.15);
  --info: #64D2FF;
  --info-surface: rgba(100, 210, 255, 0.12);
  --surface: #000000;
  --surface-alt: #1C1C1E;
  --surface-elevated: #2C2C2E;
  --surface-overlay: rgba(0, 0, 0, 0.5);
  --text-primary: #F5F5F7;
  --text-secondary: #98989D;
  --text-tertiary: #636366;
  --text-on-primary: #FFFFFF;
  --border: rgba(84, 84, 88, 0.65);
  --border-light: rgba(84, 84, 88, 0.36);
  --border-focus: #0A84FF;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.35), 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.4), 0 4px 8px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 16px 32px rgba(0, 0, 0, 0.5), 0 8px 16px rgba(0, 0, 0, 0.3);
}

/* Dark mode — system preference fallback */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #0A84FF;
    --primary-light: #409CFF;
    --primary-dark: #0A84FF;
    --primary-surface: rgba(10, 132, 255, 0.12);
    --success: #30D158;
    --success-surface: rgba(48, 209, 88, 0.15);
    --warning: #FFD60A;
    --warning-surface: rgba(255, 214, 10, 0.12);
    --danger: #FF453A;
    --danger-surface: rgba(255, 69, 58, 0.15);
    --info: #64D2FF;
    --info-surface: rgba(100, 210, 255, 0.12);
    --surface: #000000;
    --surface-alt: #1C1C1E;
    --surface-elevated: #2C2C2E;
    --surface-overlay: rgba(0, 0, 0, 0.5);
    --text-primary: #F5F5F7;
    --text-secondary: #98989D;
    --text-tertiary: #636366;
    --text-on-primary: #FFFFFF;
    --border: rgba(84, 84, 88, 0.65);
    --border-light: rgba(84, 84, 88, 0.36);
    --border-focus: #0A84FF;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.35), 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.4), 0 4px 8px rgba(0, 0, 0, 0.2);
    --shadow-xl: 0 16px 32px rgba(0, 0, 0, 0.5), 0 8px 16px rgba(0, 0, 0, 0.3);
  }
}

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

button, a, [role="button"] {
  touch-action: manipulation;
  cursor: pointer;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--surface-alt);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* Dark mode smooth transition */
body {
  transition: background-color 200ms ease, color 200ms ease;
}

/* Image overflow protection in rich text content */
.chapter-view-body img {
  max-width: 100%;
  height: auto;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height, 0px) + var(--safe-bottom) + 24px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-primary);
  color: var(--surface);
  padding: 10px 24px;
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  font-weight: 500;
  z-index: var(--z-index-toast);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

img { max-width: 100%; height: auto; display: block; }
video { max-width: 100%; height: auto; display: block; border-radius: var(--radius-md); }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }

th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

th {
  background: var(--surface-alt);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

td { color: var(--text-primary); font-variant-numeric: tabular-nums; }

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: none;
  margin: var(--spacing-md) 0;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.table-wrapper table { margin: 0; border: none; }
.table-wrapper th:first-child,
.table-wrapper td:first-child { padding-left: 14px; }
.table-wrapper th:last-child,
.table-wrapper td:last-child { padding-right: 14px; }

.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 8px 20px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 9999;
  text-decoration: none;
  transition: top 0.2s ease;
}

.skip-link:focus { top: 0; }

/* 4. Header
   ========================================================================== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  padding-top: var(--safe-top);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  padding-left: var(--spacing-sm);
  padding-right: var(--spacing-md);
  z-index: var(--z-index-header);
  border-bottom: 1px solid var(--border-light);
}

.header-back {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--primary);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.header-back:hover { background: var(--primary-surface); }
.header-back:active { background: rgba(0, 113, 227, 0.12); }
.header-back svg { width: 22px; height: 22px; }

.header-title {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 var(--spacing-xs);
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.header-actions { display: flex; gap: 2px; align-items: center; }

.header-action-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--primary);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.header-action-btn:hover { background: var(--primary-surface); }
.header-action-btn:active { background: rgba(0, 113, 227, 0.12); }
.header-action-btn svg { width: 20px; height: 20px; }

/* Navbar search box */
.navbar-search {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 0 var(--spacing-sm);
  height: 36px;
  min-width: 240px;
  margin-right: var(--spacing-xs);
}

.navbar-search svg { color: var(--text-tertiary); flex-shrink: 0; }

.navbar-search input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.navbar-search input::placeholder { color: var(--text-tertiary); }

/* Mobile menu toggle */
.menu-toggle {
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
}

/* 5. Bottom Nav
   ========================================================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: stretch;
  z-index: var(--z-index-nav);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--text-tertiary);
  padding: 4px 0;
  min-height: 44px;
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  touch-action: manipulation;
}

.nav-item svg { width: 22px; height: 22px; flex-shrink: 0; transition: transform var(--transition-fast); }
.nav-item:active svg { transform: scale(0.88); }

.nav-item-label {
  font-size: 0.65rem;
  font-weight: 500;
  line-height: 1.2;
  transition: all var(--transition-fast);
}

.nav-item.active { color: var(--primary-light); }
.nav-item.active .nav-item-label { font-weight: 600; }

/* 6. Hero
   ========================================================================== */
.hero-section {
  background: var(--surface);
  padding: var(--spacing-2xl) var(--spacing-lg) var(--spacing-xl);
  color: var(--text-primary);
  position: relative;
  overflow: hidden;
  text-align: center;
}

.hero-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: var(--spacing-sm);
  letter-spacing: -0.02em;
  line-height: 1.18;
  position: relative;
}

.hero-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: var(--spacing-lg);
  line-height: 1.47;
  position: relative;
  font-weight: 400;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* 7. Device Grid + Cards
   ========================================================================== */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--spacing-md);
  padding: 0;
  max-width: 1200px;
  margin: 0 auto;
}

/* Device card — supports both .device-card-* and legacy .device-grid-* class names */
.device-card,
.device-grid-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  position: relative;
  overflow: hidden;
}

.device-card:hover,
.device-grid-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: rgba(0, 113, 227, 0.2);
}

.device-card:active,
.device-grid-card:active {
  transform: scale(0.98);
}

.device-card-cover {
  width: 100%;
  height: 140px;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  overflow: hidden;
  margin: calc(-1 * var(--spacing-lg)) calc(-1 * var(--spacing-lg)) var(--spacing-md);
  width: calc(100% + 2 * var(--spacing-lg));
}
.device-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.device-card-cover-placeholder {
  background: linear-gradient(135deg, var(--primary-surface), var(--surface-alt));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  opacity: 0.6;
}
.device-card-body {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.device-card-icon,
.device-grid-card-icon {
  width: 48px;
  height: 48px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: var(--spacing-md);
  flex-shrink: 0;
}

.device-card-name,
.device-grid-name {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 4px;
}

.device-card-model,
.device-grid-model {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  margin-bottom: var(--spacing-sm);
}

.device-card-desc,
.device-grid-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.47;
  margin-bottom: 0;
}

.device-card-tags,
.device-grid-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: var(--spacing-md);
}

.device-card-tag,
.device-grid-tag {
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--primary-surface);
  color: var(--primary);
  font-weight: 500;
}

/* Card arrow indicator */
.device-card::after,
.device-grid-card::after {
  content: '';
  position: absolute;
  right: var(--spacing-lg);
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--text-tertiary);
  border-bottom: 1.5px solid var(--text-tertiary);
  transform: translateY(-50%) rotate(-45deg);
  transition: border-color var(--transition-fast), right var(--transition-fast);
}
.device-card:hover::after,
.device-grid-card:hover::after {
  border-color: var(--primary);
  right: calc(var(--spacing-lg) - 2px);
}

/* 8. Search Bar
   ========================================================================== */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 0 var(--spacing-md);
  height: 44px;
  max-width: 1200px;
  margin: 0 auto var(--spacing-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.search-bar:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}
.search-bar svg { color: var(--text-tertiary); flex-shrink: 0; }

.search-clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: var(--surface-alt);
  border-radius: 50%;
  color: var(--text-tertiary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.search-clear-btn:hover { background: var(--border-light); color: var(--text-secondary); }

.search-bar input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.search-bar input::placeholder { color: var(--text-tertiary); }

/* 9. Reader Toolbar (reserved for future reader-mode toolbar)
   ========================================================================== */
.reader-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-light);
  z-index: var(--z-index-header);
}

.reader-toolbar-row {
  display: flex;
  align-items: center;
  height: 48px;
  padding: 0 var(--spacing-md);
}

.reader-toolbar-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--primary);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.reader-toolbar-btn.secondary {
  color: var(--text-secondary);
}

.reader-toolbar-btn:hover { background: var(--primary-surface); }

.reader-toolbar .theme-btn {
  width: 40px;
  height: 40px;
  background: none;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
}

.reader-toolbar .theme-btn:hover { background: var(--primary-surface); }

.reader-toolbar-title {
  flex: 1;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.reader-progress {
  height: 2px;
  background: var(--border-light);
}

.reader-progress-bar {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
}

.reader-chapter-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-md);
  padding: var(--spacing-sm) var(--spacing-md);
}

.reader-chapter-nav-btn {
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--primary);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0 8px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  font-family: var(--font-sans);
}

.reader-chapter-nav-btn:disabled { opacity: 0.4; }

.reader-chapter-indicator {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 500;
}

/* Chapter Bottom Nav (in-content) */
.chapter-bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-md);
  margin-top: var(--spacing-2xl);
  padding-top: var(--spacing-xl);
  border-top: 1px solid var(--border-light);
}

.chapter-bottom-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px var(--spacing-lg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.chapter-bottom-btn:hover {
  background: var(--primary-surface);
  border-color: rgba(0, 113, 227, 0.2);
}
.chapter-bottom-btn:active {
  transform: scale(0.97);
}

.chapter-bottom-btn-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  overflow: hidden;
}
.chapter-bottom-btn.next .chapter-bottom-btn-inner { align-items: flex-end; }

.chapter-bottom-btn-label {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-weight: 400;
  line-height: 1;
}

.chapter-bottom-btn-title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--primary);
  line-height: 1.3;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-bottom-indicator {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* 10. Reader Layout
   ========================================================================== */
.reader-layout {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  min-height: calc(100vh - var(--toolbar-total-height));
  padding-top: var(--toolbar-total-height);
}

.toc-sidebar {
  width: var(--toc-sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: var(--toolbar-total-height);
  height: calc(100vh - var(--toolbar-total-height));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-right: 1px solid var(--border-light);
  padding: var(--spacing-md) 0;
  display: none;
}

.toc-sidebar-section { margin-bottom: var(--spacing-md); }

.toc-sidebar-group-title {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--spacing-sm) var(--spacing-md) var(--spacing-xs);
  user-select: none;
}

.toc-sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 7px var(--spacing-md) 7px calc(var(--spacing-md) + 4px);
  font-size: 0.84rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 0;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  border-left: 2px solid transparent;
  line-height: 1.4;
}

.toc-sidebar-item:hover { color: var(--text-primary); background: var(--surface-alt); }

.toc-sidebar-item.active {
  color: var(--primary);
  background: var(--primary-surface);
  border-left-color: var(--primary);
  font-weight: 500;
}

.toc-sidebar-item-num {
  font-size: 0.72rem;
  font-weight: 700;
  color: inherit;
  min-width: 18px;
  font-family: var(--font-mono);
  opacity: 0.7;
}

.toc-sidebar-item.active .toc-sidebar-item-num { opacity: 1; }

.reader-content {
  flex: 1;
  min-width: 0;
  padding: var(--spacing-xl) 40px calc(var(--nav-height) + var(--safe-bottom) + var(--spacing-xl));
}

.reader-content-inner {
  max-width: var(--content-max-width);
  margin: 0 auto;
}

/* 11. Chapter View
   ========================================================================== */
.chapter-view {
  animation: chapterFade 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.chapter-view-header {
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--border-light);
}

.chapter-view-number {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--spacing-xs);
  font-family: var(--font-mono);
}

.chapter-view-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.chapter-view-body {
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--text-secondary);
}

.chapter-view-body p { margin: 16px 0; }

.chapter-view-body h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 28px 0 12px;
}

.chapter-view-body h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 24px 0 10px;
}

.chapter-view-body h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 20px 0 8px;
}

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

.chapter-view-body li { margin-bottom: 4px; line-height: 1.7; }

.chapter-view-body strong,
.chapter-view-body b { color: var(--text-primary); font-weight: 600; }

.chapter-view-body blockquote {
  background: var(--surface-alt);
  border-left: 3px solid var(--primary);
  padding: 12px 16px;
  margin: 16px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.chapter-view-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.92rem;
}

.chapter-view-body table td,
.chapter-view-body table th {
  border-bottom: 1px solid var(--border-light);
  padding: 10px 14px;
  text-align: left;
}

.chapter-view-body table th {
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chapter-view-body table td { color: var(--text-primary); }

.chapter-view-body code {
  background: var(--surface-alt);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--primary);
}

.chapter-view-body pre {
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 16px 0;
  overflow-x: auto;
}

.chapter-view-body pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.chapter-view-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 16px 0;
  display: block;
}

.chapter-view-body .figure {
  text-align: center;
  margin: 20px 0;
}

.chapter-view-body .figure img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 0 auto 8px;
  display: block;
  box-shadow: var(--shadow-sm);
}

.chapter-view-body .figure-caption {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  margin-top: 4px;
  font-style: italic;
}

.chapter-view-body .figure-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--spacing-md);
  margin: 16px 0;
}

.chapter-view-body .figure-grid .figure {
  margin: 0;
}

/* Chapter pagination */
.chapter-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--spacing-2xl);
  padding-top: var(--spacing-lg);
  border-top: 1px solid var(--border-light);
}

.chapter-pagination-btn {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: 8px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: 40px;
  font-family: var(--font-sans);
}

.chapter-pagination-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-surface);
}

.chapter-pagination-btn:active { transform: scale(0.97); }

.chapter-pagination-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.chapter-pagination-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.chapter-pagination-indicator {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-weight: 500;
}

/* 12. TOC Drawer
   ========================================================================== */
.toc-drawer-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface-overlay);
  z-index: var(--z-index-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.toc-drawer-overlay.open { opacity: 1; visibility: visible; }

.toc-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70vh;
  background: var(--surface-elevated);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  z-index: calc(var(--z-index-overlay) + 1);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
}

.toc-drawer.open { transform: translateY(0); }

.toc-drawer-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 6px;
  flex-shrink: 0;
}

.toc-drawer-handle::after {
  content: '';
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.toc-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px var(--spacing-lg) var(--spacing-md);
  flex-shrink: 0;
}

.toc-drawer-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.toc-drawer-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface-alt);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
}

.toc-drawer-close:active { background: var(--border-light); }

.toc-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--spacing-md) calc(var(--nav-height) + var(--safe-bottom) + var(--spacing-md));
  -webkit-overflow-scrolling: touch;
}

.toc-drawer-group { margin-bottom: var(--spacing-sm); }

.toc-drawer-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px var(--spacing-md);
  cursor: pointer;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.toc-drawer-group-header:active { background: var(--border-light); }

.toc-drawer-group-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
}

.toc-drawer-group-arrow {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  transition: transform 0.25s ease;
}

.toc-drawer-group-arrow.open { transform: rotate(90deg); }

.toc-drawer-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 10px var(--spacing-md) 10px calc(var(--spacing-md) + 8px);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.toc-drawer-item:active { background: var(--border-light); }

.toc-drawer-item-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 20px;
  font-family: var(--font-mono);
}

.toc-drawer-item-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* 13. Callouts
   ========================================================================== */
.callout {
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  margin: var(--spacing-md) 0;
  display: flex;
  gap: var(--spacing-md);
  line-height: 1.7;
  font-size: 0.9rem;
  align-items: flex-start;
  border: none;
}

.callout-icon { flex-shrink: 0; width: 22px; height: 22px; margin-top: 2px; }
.callout-content { flex: 1; }
.callout-label { font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }

.callout.danger { background: rgba(255, 59, 48, 0.08); color: var(--danger); }
.callout.warning { background: rgba(255, 159, 10, 0.08); color: var(--warning); }
.callout.caution { background: rgba(255, 159, 10, 0.08); color: #c77c00; }
.callout.info { background: rgba(90, 200, 250, 0.08); color: var(--info); }

/* 14. Search Overlay
   ========================================================================== */
.search-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface);
  z-index: var(--z-index-modal);
  display: none;
  flex-direction: column;
}

.search-overlay.open { display: flex; }

.search-overlay-header {
  display: flex;
  align-items: center;
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--border-light);
  gap: var(--spacing-sm);
}

.search-overlay-input {
  flex: 1;
  height: 44px;
  border: none;
  background: none;
  font-size: 1rem;
  font-family: var(--font-sans);
  color: var(--text-primary);
  outline: none;
}

.search-overlay-input::placeholder { color: var(--text-tertiary); }

.search-overlay-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.search-overlay-item {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.search-overlay-item:hover { background: var(--surface-alt); }

/* Search history */
.search-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
}
.search-history-clear {
  border: none;
  background: none;
  color: var(--primary);
  font-size: 0.75rem;
  cursor: pointer;
  font-family: var(--font-sans);
}
.search-history-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.search-history-item svg { flex-shrink: 0; color: var(--text-tertiary); }

.search-overlay-item-meta {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin-bottom: 2px;
  font-weight: 500;
}

.search-overlay-item-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 4px;
}

.search-overlay-item-preview {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.search-overlay-count {
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-light);
  font-weight: 500;
}

.search-highlight {
  background: rgba(255, 214, 10, 0.4);
  border-radius: 2px;
  padding: 0 2px;
}

.search-highlight-active {
  background: rgba(0, 113, 227, 0.2);
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-radius: 3px;
  padding: 1px 3px;
  animation: highlight-pulse 0.6s ease 2;
}

@keyframes highlight-pulse {
  0%, 100% { outline-color: var(--primary); }
  50% { outline-color: transparent; }
}

/* 15. Skeleton + States
   ========================================================================== */
.skeleton {
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--border-light) 50%, var(--surface-alt) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.state-empty,
.state-error {
  text-align: center;
  padding: var(--spacing-2xl);
}

.state-empty-icon { margin-bottom: var(--spacing-md); }
.state-empty-text { color: var(--text-tertiary); font-size: 0.95rem; }
.state-error-text { color: var(--danger); font-size: 1rem; margin-bottom: var(--spacing-md); }

.state-retry-btn {
  padding: 10px 28px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: var(--text-on-primary);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font-sans);
}

/* 16. About Section + Footer
   ========================================================================== */
.about-section {
  background: var(--surface);
  padding: var(--spacing-xl) var(--spacing-lg);
  text-align: center;
  max-width: 720px;
  margin: 0 auto;
}

.about-content { max-width: 480px; margin: 0 auto; }

.about-logo {
  display: inline-block;
  font-size: 2.2rem;
  font-weight: 300;
  letter-spacing: 0.18em;
  color: var(--text-primary);
  margin-bottom: var(--spacing-md);
  text-transform: uppercase;
}

.about-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--spacing-sm);
}

.about-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.8;
}

/* Features Section */
.features-section {
  padding: var(--spacing-lg);
  max-width: 720px;
  margin: 0 auto;
}

.features-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-md);
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  text-align: center;
}

.feature-icon {
  color: var(--primary);
  margin-bottom: var(--spacing-sm);
  display: flex;
  justify-content: center;
}

.feature-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.feature-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* CTA Section */
.cta-section {
  text-align: center;
  padding: var(--spacing-xl) var(--spacing-lg) var(--spacing-2xl);
}

.cta-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  background: var(--primary);
  color: var(--text-on-primary);
  border: none;
  border-radius: var(--radius-full);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-md);
}

.cta-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.cta-button:active {
  transform: scale(0.97);
}

.site-footer {
  text-align: center;
  padding: var(--spacing-2xl) var(--spacing-md) var(--spacing-xl);
  border-top: 1px solid var(--border-light);
}

.footer-logo {
  display: inline-block;
  font-size: 1.5rem;
  font-weight: 300;
  letter-spacing: 0.15em;
  color: var(--text-primary);
  margin-bottom: var(--spacing-sm);
  font-family: var(--font-sans);
  text-transform: uppercase;
}

.footer-company {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--spacing-md);
}

.footer-contact-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-lg);
}

.footer-contact-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  user-select: none;
}

.footer-contact-text:hover {
  color: var(--primary);
  background: var(--primary-surface);
}

.footer-contact-text.copied {
  color: var(--success);
}

.footer-copy {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-top: var(--spacing-sm);
}

.footer-icp {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-top: var(--spacing-xs);
}

.footer-icp a {
  color: inherit;
  text-decoration: none;
  transition: color var(--transition-fast);
}

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

/* 17. Theme Button
   ========================================================================== */
.theme-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.theme-btn:hover { background: var(--border-light); }

/* Theme toggle (legacy switch in index.html) */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-md);
  background: var(--surface-elevated);
  border-radius: var(--radius-md);
  border: none;
  box-shadow: var(--shadow-xs);
}

.theme-toggle-label {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
}

.theme-toggle-switch {
  position: relative;
  width: 46px;
  height: 26px;
  background: var(--border);
  border-radius: 13px;
  transition: background var(--transition-fast);
  border: none;
  padding: 0;
}

.theme-toggle-switch.active { background: var(--primary-light); }

.theme-toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition-fast);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.theme-toggle-switch.active::after { transform: translateX(20px); }

/* 18. Scroll Top
   ========================================================================== */
.scroll-top-btn {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 14px);
  right: 14px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--text-on-primary);
  border: none;
  box-shadow: var(--shadow-lg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.scroll-top-btn:hover { box-shadow: var(--shadow-xl); transform: translateY(-2px); }
.scroll-top-btn:active { transform: scale(0.9); }
.scroll-top-btn.visible { display: flex; }
.scroll-top-btn svg { width: 18px; height: 18px; }

/* 19. Section Header
   ========================================================================== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--spacing-md);
  margin-bottom: var(--spacing-md);
}

.section-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.section-link {
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
}

.section-link:hover { text-decoration: underline; }

/* 20. Specs Table
   ========================================================================== */
.specs-section { margin: var(--spacing-lg) 0; }

.specs-section-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--spacing-md);
}

.specs-group-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--spacing-xs);
  padding: 0 var(--spacing-xs);
}

.specs-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-md);
}

.specs-label {
  width: 40%;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.specs-value {
  color: var(--primary);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

/* 21. Page Transitions
   ========================================================================== */
.app-page {
  display: none;
  animation: fadeIn 0.2s ease-out;
}

.app-page.active { display: block; }

#page-devices {
  padding: var(--spacing-lg) var(--spacing-md) var(--spacing-2xl);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes chapterFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header search input (device.html inline search) */
.header-search-input {
  flex: 1;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 var(--spacing-md);
  font-size: 0.88rem;
  background: var(--surface-alt);
  color: var(--text-primary);
  font-family: var(--font-sans);
  outline: none;
  max-width: 240px;
  transition: box-shadow var(--transition-fast);
}

.header-search-input:focus { box-shadow: 0 0 0 2px rgba(0, 113, 227, 0.3); }
.header-search-input::placeholder { color: var(--text-tertiary); }

/* Main content area */
.main-content {
  padding-top: var(--header-height);
  min-height: 100dvh;
}

/* 22. Responsive — Desktop (768px+)
   ========================================================================== */
@media (min-width: 768px) {
  /* --- Reader mode (device.html) --- */
  .toc-sidebar { display: block; }
  .fab-toc { display: none !important; }
  .reader-content { padding-bottom: var(--spacing-2xl); }
  body.reader-mode { padding-bottom: 0; }
  body.reader-mode .bottom-nav { display: none; }
  body.reader-mode .scroll-top-btn { bottom: 24px; }

  /* --- Index page: hide bottom nav on desktop --- */
  body:not(.reader-mode) .bottom-nav { display: none; }
  body:not(.reader-mode) { padding-bottom: 0; }
  body:not(.reader-mode) .scroll-top-btn { bottom: 24px; }

  /* --- Home page sections --- */
  .about-section { max-width: 960px; padding: var(--spacing-3xl) var(--spacing-2xl); }
  .about-content { max-width: 600px; }
  .about-logo { font-size: 2.8rem; }
  .about-title { font-size: 1.25rem; }
  .about-desc { font-size: 0.9375rem; line-height: 1.9; }

  .features-section { max-width: 960px; padding: var(--spacing-2xl); }
  .features-grid { grid-template-columns: repeat(4, 1fr); gap: var(--spacing-lg); }
  .feature-card { padding: var(--spacing-lg); }
  .feature-desc { font-size: 0.8125rem; }

  .cta-section { padding: var(--spacing-2xl) var(--spacing-lg) var(--spacing-3xl); }
  .cta-button { padding: 16px 40px; font-size: 1.0625rem; }

  .site-footer { padding: var(--spacing-3xl) var(--spacing-lg) var(--spacing-2xl); }

  /* --- Devices page (manual tab) --- */
  .search-bar {
    max-width: 560px;
    margin: 0 auto var(--spacing-lg);
    height: 48px;
    border-radius: var(--radius-full);
    padding: 0 var(--spacing-lg);
    box-shadow: var(--shadow-sm);
  }
  .search-bar svg { color: var(--text-tertiary); }

  .device-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--spacing-lg);
    max-width: 1080px;
  }

  .device-card,
  .device-grid-card {
    padding: var(--spacing-lg) var(--spacing-xl);
    border-radius: var(--radius-xl);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  }
  .device-card:hover,
  .device-grid-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
  }
}

/* Wide screen (1200px+) */
@media (min-width: 1200px) {
  .about-section { max-width: 1080px; }
  .features-section { max-width: 1080px; }
  .features-grid { gap: var(--spacing-xl); }

  .device-grid { max-width: 1200px; }

  /* Reader layout wider */
  .reader-layout { max-width: 1400px; }
}

/* Ultra-wide (1600px+) */
@media (min-width: 1600px) {
  .about-section { max-width: 1200px; }
  .about-content { max-width: 720px; }
  .features-section { max-width: 1200px; }
  .about-logo { font-size: 3.2rem; }
  .about-title { font-size: 1.375rem; }
  .about-desc { font-size: 1rem; }
  .feature-card { padding: var(--spacing-xl); }

  .device-grid { max-width: 1400px; }
  .reader-layout { max-width: 1600px; }
}

/* 22. Responsive — Mobile (<768px)
   ========================================================================== */
@media (max-width: 767px) {
  .menu-toggle { display: flex; }
  .navbar-search { display: none; }

  #page-devices {
    padding: var(--spacing-md) var(--spacing-sm) calc(var(--nav-height) + var(--safe-bottom) + var(--spacing-lg));
  }

  .device-grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-sm);
    padding: 0;
  }

  .device-card,
  .device-grid-card { padding: var(--spacing-md); }

  .device-card-icon,
  .device-grid-card-icon { width: 40px; height: 40px; font-size: 20px; }

  .hero-section { padding: var(--spacing-xl) var(--spacing-md) var(--spacing-lg); }
  .hero-title { font-size: 1.75rem; }
  .hero-subtitle { font-size: 0.9375rem; }

  .toc-sidebar { display: none; }
  .fab-toc { display: none; }
  .fab-toc.visible { display: flex; }

  /* Hide top chapter nav on mobile — use bottom-of-content nav instead */
  .reader-chapter-nav { display: none !important; }
  :root { --toolbar-total-height: 50px; }

  .reader-layout {
    flex-direction: column;
    max-width: 100%;
  }

  .reader-content {
    padding: var(--spacing-lg) var(--spacing-md) calc(var(--nav-height) + var(--safe-bottom) + var(--spacing-lg));
  }

  .chapter-view-title { font-size: 1.5rem; }
  .chapter-view-body { font-size: 1rem; }
  .chapter-view-body h3 { font-size: 1.125rem; }

  .table-wrapper {
    margin-left: calc(-1 * var(--spacing-md));
    margin-right: calc(-1 * var(--spacing-md));
    width: calc(100% + 2 * var(--spacing-md));
  }

  .chapter-pagination {
    flex-wrap: wrap;
    gap: var(--spacing-sm);
  }

  .chapter-pagination-btn {
    flex: 1;
    justify-content: center;
    min-width: 0;
    font-size: 0.8125rem;
    padding: 8px 12px;
  }

  .chapter-pagination-indicator {
    width: 100%;
    text-align: center;
    order: -1;
  }

  .specs-table-wrapper {
    margin-left: calc(-1 * var(--spacing-md));
    margin-right: calc(-1 * var(--spacing-md));
    width: calc(100% + 2 * var(--spacing-md));
  }

  .table-wrapper th, .table-wrapper td {
    padding: 9px 10px;
    font-size: 0.78rem;
  }

  .features-grid {
    grid-template-columns: 1fr;
    padding: 0 var(--spacing-md);
  }

  .feature-card { padding: var(--spacing-md); }
}

/* 23. Print
   ========================================================================== */
@media print {
  .bottom-nav,
  .header,
  .scroll-top-btn,
  .tab-bar,
  .fab-toc,
  .toc-sidebar,
  .reader-toolbar,
  .reader-chapter-nav { display: none !important; }

  body {
    padding-bottom: 0;
    max-width: none;
    font-family: 'Georgia', 'Noto Serif SC', serif;
    background: #fff;
    color: #000;
  }

  .main-content { padding-top: 0; }
  .callout { break-inside: avoid; border: 2px solid #000 !important; background: #f5f5f5 !important; }
  .table-wrapper { overflow: visible; border: 1px solid #ccc; }
  table { font-size: 10pt; }
}

/* 24. Accessibility
   ========================================================================== */
*:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 25. Dark Mode Overrides
   ========================================================================== */

/* Explicit dark theme */
[data-theme="dark"] .header { background: rgba(0, 0, 0, 0.72); border-bottom-color: rgba(84, 84, 88, 0.36); }
[data-theme="dark"] .bottom-nav { background: rgba(0, 0, 0, 0.72); border-top-color: rgba(84, 84, 88, 0.36); }
[data-theme="dark"] .reader-toolbar { background: rgba(0, 0, 0, 0.72); border-bottom-color: rgba(84, 84, 88, 0.36); }
[data-theme="dark"] .navbar-search { background: var(--surface-alt); }
[data-theme="dark"] .navbar-search input { color: var(--text-primary); }
[data-theme="dark"] .device-card-icon,
[data-theme="dark"] .device-grid-card-icon { background: var(--surface-alt); }
[data-theme="dark"] .device-card-tag,
[data-theme="dark"] .device-grid-tag { background: var(--surface-alt); color: var(--text-secondary); }
[data-theme="dark"] .chapter-view-body blockquote { background: rgba(255, 255, 255, 0.03); border-left-color: var(--primary); }
[data-theme="dark"] .chapter-view-body code { background: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .chapter-view-body pre { background: rgba(255, 255, 255, 0.04); }
[data-theme="dark"] .callout.danger { background: rgba(255, 69, 58, 0.15); color: var(--danger); }
[data-theme="dark"] .callout.warning { background: rgba(255, 214, 10, 0.12); color: var(--warning); }
[data-theme="dark"] .callout.caution { background: rgba(255, 214, 10, 0.12); color: #FFD60A; }
[data-theme="dark"] .callout.info { background: rgba(100, 210, 255, 0.12); color: var(--info); }
[data-theme="dark"] .toc-drawer { background: var(--surface-elevated); }
[data-theme="dark"] .toc-drawer-group-header { background: var(--surface-alt); }
[data-theme="dark"] .search-overlay { background: var(--surface); }
[data-theme="dark"] .menu-toggle { color: var(--text-primary); }

/* System dark theme fallback */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .header { background: rgba(0, 0, 0, 0.72); border-bottom-color: rgba(84, 84, 88, 0.36); }
  :root:not([data-theme="light"]) .bottom-nav { background: rgba(0, 0, 0, 0.72); border-top-color: rgba(84, 84, 88, 0.36); }
  :root:not([data-theme="light"]) .reader-toolbar { background: rgba(0, 0, 0, 0.72); border-bottom-color: rgba(84, 84, 88, 0.36); }
  :root:not([data-theme="light"]) .navbar-search { background: var(--surface-alt); }
  :root:not([data-theme="light"]) .navbar-search input { color: var(--text-primary); }
  :root:not([data-theme="light"]) .device-card-icon,
  :root:not([data-theme="light"]) .device-grid-card-icon { background: var(--surface-alt); }
  :root:not([data-theme="light"]) .device-card-tag,
  :root:not([data-theme="light"]) .device-grid-tag { background: var(--surface-alt); color: var(--text-secondary); }
  :root:not([data-theme="light"]) .chapter-view-body blockquote { background: rgba(255, 255, 255, 0.03); border-left-color: var(--primary); }
  :root:not([data-theme="light"]) .chapter-view-body code { background: rgba(255, 255, 255, 0.06); }
  :root:not([data-theme="light"]) .chapter-view-body pre { background: rgba(255, 255, 255, 0.04); }
  :root:not([data-theme="light"]) .callout.danger { background: rgba(255, 69, 58, 0.15); color: var(--danger); }
  :root:not([data-theme="light"]) .callout.warning { background: rgba(255, 214, 10, 0.12); color: var(--warning); }
  :root:not([data-theme="light"]) .callout.caution { background: rgba(255, 214, 10, 0.12); color: #FFD60A; }
  :root:not([data-theme="light"]) .callout.info { background: rgba(100, 210, 255, 0.12); color: var(--info); }
  :root:not([data-theme="light"]) .toc-drawer { background: var(--surface-elevated); }
  :root:not([data-theme="light"]) .toc-drawer-group-header { background: var(--surface-alt); }
  :root:not([data-theme="light"]) .search-overlay { background: var(--surface); }
  :root:not([data-theme="light"]) .menu-toggle { color: var(--text-primary); }
}

/* ===== Sticky Alert Bar ===== */
/* ========== Sticky Alert Carousel ========== */
.alert-sticky-bar {
  position: fixed;
  top: var(--toolbar-total-height, 48px);
  left: 0;
  right: 0;
  z-index: 99;
  pointer-events: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.alert-sticky-track {
  display: flex;
  align-items: center;
}
.alert-sticky-viewport {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.alert-sticky-inner {
  display: flex;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.alert-sticky-slide {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 36px 8px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;
  pointer-events: auto;
  position: relative;
  border-left: 3px solid;
  min-width: 100%;
  box-sizing: border-box;
  transition: opacity 0.2s, transform 0.2s;
}
.alert-sticky-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
}
.alert-sticky-text {
  flex: 1;
  min-width: 0;
}
.alert-sticky-close {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  opacity: 0.4;
  color: inherit;
  display: flex;
  align-items: center;
}
.alert-sticky-close:hover { opacity: 1; }
.alert-sticky-arrow {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  pointer-events: auto;
  border-radius: 4px;
  transition: background 0.15s;
}
.alert-sticky-arrow:hover { background: var(--surface-alt); }
.alert-sticky-dots {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 4px 0 6px;
  pointer-events: none;
}
.alert-sticky-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--border-light);
  transition: all 0.2s;
}
.alert-sticky-dot.active {
  background: var(--text-tertiary);
  width: 12px;
  border-radius: 3px;
}

/* Sticky alert level colors — soft background, left border */
.alert-sticky--danger { background: rgba(255, 59, 48, 0.08); color: #d63031; border-left-color: #ff3b30; }
.alert-sticky--danger .alert-sticky-icon { background: #ff3b30; }
.alert-sticky--warning { background: rgba(255, 149, 0, 0.08); color: #b45309; border-left-color: #ff9500; }
.alert-sticky--warning .alert-sticky-icon { background: #ff9500; }
.alert-sticky--caution { background: rgba(255, 204, 0, 0.08); color: #92640a; border-left-color: #e6b800; }
.alert-sticky--caution .alert-sticky-icon { background: #e6b800; color: #fff; }
.alert-sticky--info { background: rgba(0, 122, 255, 0.08); color: #1a6fbe; border-left-color: #007aff; }
.alert-sticky--info .alert-sticky-icon { background: #007aff; }

/* Dark mode */
[data-theme="dark"] .alert-sticky-bar { background: var(--surface); border-bottom-color: rgba(84, 84, 88, 0.36); }
[data-theme="dark"] .alert-sticky--danger { background: rgba(255, 69, 58, 0.15); color: #ff6b6b; border-left-color: #ff3b30; }
[data-theme="dark"] .alert-sticky--danger .alert-sticky-icon { background: #ff3b30; }
[data-theme="dark"] .alert-sticky--warning { background: rgba(255, 149, 0, 0.12); color: #ffc048; border-left-color: #ff9500; }
[data-theme="dark"] .alert-sticky--warning .alert-sticky-icon { background: #ff9500; }
[data-theme="dark"] .alert-sticky--caution { background: rgba(255, 204, 0, 0.1); color: #ffd666; border-left-color: #e6b800; }
[data-theme="dark"] .alert-sticky--caution .alert-sticky-icon { background: #e6b800; color: #1c1c1e; }
[data-theme="dark"] .alert-sticky--info { background: rgba(0, 122, 255, 0.12); color: #64b5f6; border-left-color: #007aff; }
[data-theme="dark"] .alert-sticky--info .alert-sticky-icon { background: #007aff; }
:root:not([data-theme="light"]) .alert-sticky-bar { background: var(--surface); border-bottom-color: rgba(84, 84, 88, 0.36); }
:root:not([data-theme="light"]) .alert-sticky--danger { background: rgba(255, 69, 58, 0.15); color: #ff6b6b; border-left-color: #ff3b30; }
:root:not([data-theme="light"]) .alert-sticky--danger .alert-sticky-icon { background: #ff3b30; }
:root:not([data-theme="light"]) .alert-sticky--warning { background: rgba(255, 149, 0, 0.12); color: #ffc048; border-left-color: #ff9500; }
:root:not([data-theme="light"]) .alert-sticky--warning .alert-sticky-icon { background: #ff9500; }
:root:not([data-theme="light"]) .alert-sticky--caution { background: rgba(255, 204, 0, 0.1); color: #ffd666; border-left-color: #e6b800; }
:root:not([data-theme="light"]) .alert-sticky--caution .alert-sticky-icon { background: #e6b800; color: #1c1c1e; }
:root:not([data-theme="light"]) .alert-sticky--info { background: rgba(0, 122, 255, 0.12); color: #64b5f6; border-left-color: #007aff; }
:root:not([data-theme="light"]) .alert-sticky--info .alert-sticky-icon { background: #007aff; }
