/* Dark mode overrides. Activated by <html data-theme="dark">.
   The toggle lives in the footer; shared/dark-mode.js applies the attribute
   before paint to avoid a flash. */

html[data-theme="dark"] {
  color-scheme: dark;
  --voca-ink: #e7ecf3;
  --voca-muted: #94a3b8;
  --voca-line: #1f2a3c;
  --voca-blue: #60a5fa;
  --voca-blue-dark: #93c5fd;
  --voca-green: #4ade80;
  --voca-red: #f87171;
  --voca-header-bg: rgba(15,23,42,.92);
  --voca-card: #111a2b;
  --voca-bg: #0b1322;
}

html[data-theme="dark"] body.voca-page {
  background: var(--voca-bg);
  color: var(--voca-ink);
}

/* === Sticky header === */
html[data-theme="dark"] .top-panel {
  background: var(--voca-header-bg);
  border-bottom-color: rgba(30,41,59,.6);
  box-shadow: 0 4px 18px rgba(0,0,0,.35);
}
html[data-theme="dark"] .brand-link { color: #cbd5e1; }
html[data-theme="dark"] .brand-link:hover { color: #f1f5f9; }
html[data-theme="dark"] .brand-link:hover .brand-voca { color: #93c5fd; }
html[data-theme="dark"] .brand-link .brand-voca { color: #60a5fa; }
html[data-theme="dark"] .page-title { color: #f1f5f9; }

html[data-theme="dark"] .font-size-controls {
  border-color: #1f2a3c;
  background: #0f172a;
}
html[data-theme="dark"] .font-size-controls button {
  background: #111a2b;
  border-color: #1f2a3c;
  color: #cbd5e1;
}
html[data-theme="dark"] .font-size-controls button:hover { background: #1f2a3c; color: #93c5fd; }
html[data-theme="dark"] .font-size-controls #fontResetBtn { color: #94a3b8; }
html[data-theme="dark"] .header-meta .stats { color: #cbd5e1; }
html[data-theme="dark"] .rank-status { color: #94a3b8; }
html[data-theme="dark"] .rank-status.ready { color: #4ade80; }
html[data-theme="dark"] .rank-status.error { color: #fbbf24; }

/* === Controls bar (search, filters, buttons) === */
html[data-theme="dark"] .controls input[type="search"],
html[data-theme="dark"] .controls input[type="text"] {
  background: #0f172a;
  color: #e7ecf3;
  border-color: #1f2a3c;
}
html[data-theme="dark"] .controls input[type="search"]::placeholder { color: #64748b; }
html[data-theme="dark"] .controls input:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(96,165,250,.2); }
html[data-theme="dark"] .controls select {
  background: #0f172a;
  color: #cbd5e1;
  border-color: #1f2a3c;
}
html[data-theme="dark"] .check-filter-label { color: #cbd5e1; }
html[data-theme="dark"] .controls button,
html[data-theme="dark"] .loop-btn {
  background: #111a2b;
  border-color: #1f2a3c;
  color: #cbd5e1;
}
html[data-theme="dark"] .controls button:hover { background: #1f2a3c; border-color: #475569; }
html[data-theme="dark"] #checkVisibleBtn { background: #111a2b; border-color: #7f1d1d; color: #fca5a5; }
html[data-theme="dark"] #checkVisibleBtn:hover { background: #1f1212; }
html[data-theme="dark"] .loop-btn { background: #0f766e; border-color: #0f766e; color: #fff; }
html[data-theme="dark"] .loop-btn:hover { background: #115e59; border-color: #115e59; }
html[data-theme="dark"] .loop-btn.active { background: #dc2626; border-color: #dc2626; }
html[data-theme="dark"] .controls button.global-search-jump {
  background: #0f172a;
  border-color: #1e3a8a;
  color: #93c5fd;
}
html[data-theme="dark"] .controls button.global-search-jump:hover { background: #16284d; border-color: #60a5fa; }

/* === Help / details === */
html[data-theme="dark"] .help summary { background: #0f172a; color: #cbd5e1; border-color: #1f2a3c; }
html[data-theme="dark"] .help summary:hover { background: #1f2a3c; }
html[data-theme="dark"] .help-content { background: #111a2b; color: #cbd5e1; border-color: #1f2a3c; }
html[data-theme="dark"] .help-content b { color: #f1f5f9; }

/* === Frequency legend === */
html[data-theme="dark"] .legend-item { background: #111a2b; border-color: #1f2a3c; color: #94a3b8; }

/* === Voca action buttons (Random/Focus/Slide/Shortcuts) === */
html[data-theme="dark"] .voca-divider { background: rgba(71,85,105,.5); }
html[data-theme="dark"] .voca-action-btn { background: #111a2b; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .voca-action-btn:hover { background: #1f2a3c; border-color: #475569; }

/* === Word table === */
html[data-theme="dark"] .main-content { /* width stays the same */ }
html[data-theme="dark"] .table-wrap {
  background: #0d1424;
  border-color: #1f2a3c;
  box-shadow: 0 4px 18px rgba(0,0,0,.3);
}
html[data-theme="dark"] .word-table { background: transparent; }
html[data-theme="dark"] .word-table thead {
  background: #0f172a;
  color: #cbd5e1;
}
html[data-theme="dark"] .word-table th {
  border-bottom-color: #1f2a3c;
}
html[data-theme="dark"] .word-table td {
  border-bottom-color: #1f2a3c;
  color: var(--voca-ink);
}
html[data-theme="dark"] .word-table tbody tr:hover td { background: #162238; }

/* Word table — specific text elements (these have hardcoded colors in page CSS) */
html[data-theme="dark"] .word-main { color: #f1f5f9 !important; }
html[data-theme="dark"] .hanzi { color: #f1f5f9 !important; }
html[data-theme="dark"] .pinyin { color: #7dd3fc !important; }
html[data-theme="dark"] .meaning-main { color: #e2e8f0 !important; }
html[data-theme="dark"] .word-subline { color: #94a3b8 !important; }
html[data-theme="dark"] .subline-label { color: #64748b !important; }
html[data-theme="dark"] .forms-cell { color: #94a3b8 !important; }
html[data-theme="dark"] .english-def { color: #64748b !important; }
html[data-theme="dark"] .rank-number { color: #94a3b8 !important; }
html[data-theme="dark"] .hsk-number { color: #64748b !important; }

/* HSK level tags */
html[data-theme="dark"] .hsk-level-tag { background: #1e3a8a; color: #93c5fd; }
html[data-theme="dark"] .hsk-level-tag.l1 { background: #14532d; color: #86efac; }
html[data-theme="dark"] .hsk-level-tag.l2 { background: #1e3a8a; color: #93c5fd; }
html[data-theme="dark"] .hsk-level-tag.l3 { background: #422006; color: #fbbf24; }
html[data-theme="dark"] .hsk-level-tag.l4 { background: #4c1d95; color: #c4b5fd; }
html[data-theme="dark"] .hsk-level-tag.l5 { background: #431407; color: #fdba74; }
html[data-theme="dark"] .hsk-level-tag.l6 { background: #831843; color: #f9a8d4; }

/* Tier badges keep their vivid colors (they're meant to stand out). */
/* Checked row */
html[data-theme="dark"] tr.checked-row td { background: #2a1224 !important; }
html[data-theme="dark"] tr.checked-row .word-main,
html[data-theme="dark"] tr.checked-row .hanzi { color: #fca5a5 !important; }

/* Focused row */
html[data-theme="dark"] tr.word-row-focused { outline-color: #60a5fa; background: #16284d !important; }
html[data-theme="dark"] tr.word-row-focused.checked-row { background: #3a1a2a !important; }

/* Mobile table rows */
@media (max-width: 760px) {
  html[data-theme="dark"] .table-wrap { background: transparent; }
  html[data-theme="dark"] .word-table tbody tr {
    background: #0d1424 !important;
    border-color: #1f2a3c;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
  }
  html[data-theme="dark"] .word-table tbody tr:hover { background: #162238 !important; }
}

/* === Action buttons (보기/듣기/사전) === */
html[data-theme="dark"] .action-button { background: #111a2b; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .action-button:hover { background: #1f2a3c; }
html[data-theme="dark"] .action-art,
html[data-theme="dark"] .voca-art-trigger { background: #1e1b3a; border-color: #4c1d95; color: #c4b5fd; }
html[data-theme="dark"] .action-art:hover,
html[data-theme="dark"] .voca-art-trigger:hover { background: #2e2a5a; border-color: #6d28d9; }
html[data-theme="dark"] .action-audio,
html[data-theme="dark"] .audio-btn { background: #0f2917; border-color: #14532d; color: #86efac; }
html[data-theme="dark"] .action-audio:hover,
html[data-theme="dark"] .audio-btn:hover { background: #14532d; border-color: #166534; }
html[data-theme="dark"] .audio-btn.playing { background: #facc15 !important; border-color: #eab308 !important; color: #1e293b !important; }
html[data-theme="dark"] .action-dict,
html[data-theme="dark"] .dict-link { background: #0f1d3a; border-color: #1e3a8a; color: #93c5fd; }
html[data-theme="dark"] .action-dict:hover,
html[data-theme="dark"] .dict-link:hover { background: #16284d; border-color: #2563eb; }

/* === Checkbox === */
html[data-theme="dark"] .check-box { background: #0f172a; border-color: #475569; }

/* === Checked section (bottom of page) === */
html[data-theme="dark"] .checked-section { background: #0d1424; border-color: #1f2a3c; }
html[data-theme="dark"] .checked-section h2 { color: #fca5a5; }
html[data-theme="dark"] .checked-item { background: #111a2b; border-color: #7f1d1d; }
html[data-theme="dark"] .checked-item .word-mini { color: #fca5a5; }
html[data-theme="dark"] .checked-item .checked-sub { color: #94a3b8; }
html[data-theme="dark"] .checked-item button { background: #0f172a; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .checked-item button.remove { color: #f87171; border-color: #7f1d1d; }
html[data-theme="dark"] .empty { color: #64748b; }

/* === Scroll-to-top button === */
html[data-theme="dark"] .scroll-top-btn { background: #1f2a3c; color: #cbd5e1; border-color: #1f2a3c; }
html[data-theme="dark"] .scroll-top-btn:hover { background: #2a3a52; }

/* === Page loading overlay === */
html[data-theme="dark"] .page-loading { background: rgba(11,19,34,.92); }
html[data-theme="dark"] .page-loading-card { background: #111a2b; border-color: #1f2a3c; box-shadow: 0 18px 54px rgba(0,0,0,.5); }
html[data-theme="dark"] .page-loading-title { color: #f1f5f9; }
html[data-theme="dark"] .page-loading-message { color: #94a3b8; }
html[data-theme="dark"] .page-loading-track { background: #0f172a; }
html[data-theme="dark"] .page-loading-bar { background: linear-gradient(90deg, #60a5fa, #38bdf8); }
html[data-theme="dark"] .page-loading-footer { color: #64748b; }
html[data-theme="dark"] .page-loading-retry { background: #2563eb; border-color: #2563eb; color: #fff; }

/* === Voca modal (random/focus/slide/shortcuts cards) === */
html[data-theme="dark"] .voca-modal { background: rgba(0,0,0,.82); }
html[data-theme="dark"] .voca-modal .voca-card-inner {
  background: linear-gradient(135deg, #0d1424, #111a2b 60%, #0f2917);
  color: #e7ecf3;
  box-shadow: 0 30px 90px rgba(0,0,0,.6);
}
html[data-theme="dark"] .voca-modal .voca-card-tag { color: #93c5fd; background: #1e3a8a; }
html[data-theme="dark"] .voca-modal .voca-card-close { color: #94a3b8; }
html[data-theme="dark"] .voca-modal .voca-card-close:hover { color: #f1f5f9; }
html[data-theme="dark"] .voca-modal .voca-card-progress { color: #94a3b8; }
html[data-theme="dark"] .voca-modal .voca-card-word { color: #f1f5f9; }
html[data-theme="dark"] .voca-modal .voca-card-pron { color: #7dd3fc; }
html[data-theme="dark"] .voca-modal .voca-card-meaning { color: #e2e8f0; }
html[data-theme="dark"] .voca-modal .voca-card-def { color: #94a3b8; }
html[data-theme="dark"] .voca-modal .voca-card-actions button { background: #111a2b; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .voca-modal .voca-card-actions button:hover { background: #1f2a3c; border-color: #475569; }

/* === Global-search panel === */
html[data-theme="dark"] .global-search-shell { background: #111a2b; border-color: #1f2a3c; box-shadow: 0 4px 16px rgba(0,0,0,.4); }
html[data-theme="dark"] .global-search-intro h2 { color: #f1f5f9; }
html[data-theme="dark"] .global-search-intro p { color: #94a3b8; }
html[data-theme="dark"] .global-search-input-row input,
html[data-theme="dark"] .global-search-input-row select {
  background: #0f172a; color: #e7ecf3; border-color: #1f2a3c;
}
html[data-theme="dark"] .global-search-input-row input::placeholder { color: #64748b; }
html[data-theme="dark"] .global-search-input-row input:focus,
html[data-theme="dark"] .global-search-input-row select:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(96,165,250,.2); }
html[data-theme="dark"] .global-search-panel { background: #0d1424; border-top-color: #1f2a3c; }
html[data-theme="dark"] .global-search-heading { background: #0f172a; color: #93c5fd; border-bottom-color: #1f2a3c; }
html[data-theme="dark"] .global-search-heading span { color: #94a3b8; }
html[data-theme="dark"] .global-search-result { background: #111a2b; border-color: #1f2a3c; color: #e7ecf3; }
html[data-theme="dark"] .global-search-result.is-focused { border-color: #60a5fa; box-shadow: 0 0 0 2px rgba(96,165,250,.4); }
html[data-theme="dark"] .global-search-word { color: #f1f5f9; }
html[data-theme="dark"] .global-search-result.is-focused .global-search-word { color: #93c5fd; }
html[data-theme="dark"] .global-search-secondary { color: #94a3b8; }
html[data-theme="dark"] .global-search-meaning { color: #cbd5e1; }
html[data-theme="dark"] .global-search-definition { color: #94a3b8; }
html[data-theme="dark"] .global-search-meta { color: #94a3b8; }
html[data-theme="dark"] .global-search-action { background: #0f172a; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .global-search-action:hover { background: #1f2a3c; border-color: #475569; }
html[data-theme="dark"] .global-search-action.action-view { background: #0f1d3a; border-color: #1e3a8a; color: #93c5fd; }
html[data-theme="dark"] .global-search-action.action-listen { background: #0f2917; border-color: #14532d; color: #86efac; }
html[data-theme="dark"] .global-search-action.action-dictionary { background: #0f1d3a; border-color: #1e3a8a; color: #93c5fd; }
html[data-theme="dark"] .global-search-action.action-open-book { background: #0f172a; border-color: #1f2a3c; }
html[data-theme="dark"] .global-search-chip { background: #111a2b; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .global-search-chip .chip-count { background: #1f2a3c; color: #93c5fd; }
html[data-theme="dark"] .global-search-chip:hover { background: #1f2a3c; }
html[data-theme="dark"] .global-search-more-bar { background: #0d1424; border-top-color: #1f2a3c; }
html[data-theme="dark"] .global-search-more-btn { background: #0f1d3a; border-color: #1e3a8a; color: #93c5fd; }
html[data-theme="dark"] .global-search-more-btn:hover { background: #16284d; }
html[data-theme="dark"] .global-search-kbd-hint { background: #0d1424; border-top-color: #1f2a3c; color: #64748b; }
html[data-theme="dark"] .global-search-empty { color: #94a3b8; }
html[data-theme="dark"] .global-search-filter-bar { background: #0f172a; border-bottom-color: #1f2a3c; }
html[data-theme="dark"] .global-search-filter-chip { background: #111a2b; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .global-search-filter-chip:hover { border-color: #60a5fa; color: #93c5fd; }
html[data-theme="dark"] .global-search-filter-chip.is-active { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
html[data-theme="dark"] .global-search-print-btn { background: #111a2b; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .global-search-print-btn:hover { background: #0f1d3a; border-color: #60a5fa; color: #93c5fd; }
html[data-theme="dark"] .word-table tbody tr.global-search-focus-target td { background: #3a2a08 !important; }

/* === Footer === */
html[data-theme="dark"] .site-footer { background: #0b1322; color: #94a3b8; border-top-color: #1f2a3c; }
html[data-theme="dark"] .site-footer-brand { color: #cbd5e1; }
html[data-theme="dark"] .site-footer-brand strong { color: #60a5fa; }
html[data-theme="dark"] .site-footer-tagline { color: #94a3b8; }
html[data-theme="dark"] .site-footer-desc { color: #64748b; }
html[data-theme="dark"] .site-footer-col h4 { color: #cbd5e1; }
html[data-theme="dark"] .site-footer-col a,
html[data-theme="dark"] .site-footer-col .footer-link-btn { color: #94a3b8; }
html[data-theme="dark"] .site-footer-col a:hover,
html[data-theme="dark"] .site-footer-col .footer-link-btn:hover { color: #93c5fd; }
html[data-theme="dark"] .site-footer-guide li { color: #64748b; }
html[data-theme="dark"] .site-footer-guide li::before { color: #60a5fa; }
html[data-theme="dark"] .site-footer-guide kbd { background: #0f172a; border-color: #1f2a3c; color: #e7ecf3; }
html[data-theme="dark"] .site-footer-bottom { border-top-color: #1f2a3c; color: #64748b; }
html[data-theme="dark"] .site-footer-contact { color: #64748b; }
html[data-theme="dark"] .theme-toggle-btn { background: #111a2b; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .theme-toggle-btn:hover { background: #1f2a3c; border-color: #60a5fa; }

/* === Word-art viewer === */
html[data-theme="dark"] .voca-wordart-overlay { background: rgba(0,0,0,.85); }
html[data-theme="dark"] .voca-wordart-card { background: #0d1424; border-color: #1f2a3c; }
html[data-theme="dark"] .voca-wordart-label { color: #94a3b8; }

/* === Modal / shortcuts === */
html[data-theme="dark"] .modal { background: #111a2b; color: #e7ecf3; }
html[data-theme="dark"] .modal-header { border-bottom-color: #1f2a3c; }
html[data-theme="dark"] .modal-header h4 { color: #f1f5f9; }
html[data-theme="dark"] .modal-close { color: #94a3b8; }
html[data-theme="dark"] .modal-close:hover { color: #f1f5f9; }
html[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,.65); }
html[data-theme="dark"] .shortcuts-table th { color: #94a3b8; }
html[data-theme="dark"] .shortcuts-table th,
html[data-theme="dark"] .shortcuts-table td { border-bottom-color: #1f2a3c; }
html[data-theme="dark"] .shortcuts-table kbd { background: #0f172a; border-color: #1f2a3c; color: #e7ecf3; }
html[data-theme="dark"] .shortcuts-note { background: #0f172a; color: #94a3b8; }

/* === Voca toast === */
html[data-theme="dark"] .voca-toast { background: #1f2a3c; color: #f1f5f9; }

/* === Export modal === */
html[data-theme="dark"] .export-summary { background: #0f1d3a; border-color: #1e3a8a; color: #93c5fd; }
html[data-theme="dark"] .export-form-row label { color: #e7ecf3; }
html[data-theme="dark"] .export-form-row select,
html[data-theme="dark"] .export-form-row input { background: #0f172a; color: #e7ecf3; border-color: #1f2a3c; }
html[data-theme="dark"] .export-preview { background: #0f172a; color: #cbd5e1; border-color: #1f2a3c; }
html[data-theme="dark"] .export-actions button { background: #111a2b; border-color: #1f2a3c; color: #cbd5e1; }
html[data-theme="dark"] .export-actions button.primary { background: #1d4ed8; color: #fff; border-color: #1d4ed8; }

/* === Index-specific dark mode (overrides in index.html <style>) === */
/* These are kept in index.html's <style> block for specificity. */

/* Print: dark mode should NOT apply when printing. */
@media print {
  html[data-theme="dark"] { color-scheme: light; }
  html[data-theme="dark"] body,
  html[data-theme="dark"] body.voca-page { background: #ffffff !important; color: #000000 !important; }
  html[data-theme="dark"] * { color: #000000 !important; background: #ffffff !important; }
}
