
:root {
  --bg: #0E1620;
  --surface: #162030;
  --surface2: #1e2d40;
  --text: #e8eaf0;
  --text-muted: #7a8ca0;
  --accent: #613CC4;
  --accent-dark: #4e2fa0;
  --border: #243348;
  --bubble-bg: #ffffff;
  --shadow: 0 8px 32px rgba(0,0,0,0.55);
  --fact-font-size: 12px;
}
body.theme-light {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface2: #f0f1f8;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e4e5f0;
  --bubble-bg: #ffffff;
  --shadow: 0 8px 32px rgba(0,0,0,0.1);
}
body.theme-high-contrast {
  --bg: #000;
  --surface: #000;
  --surface2: #000;
  --text: #fff;
  --text-muted: #fff;
  --accent: #FFD700;
  --accent-dark: #FFD700;
  --border: #fff;
  --bubble-bg: #000;
  --shadow: none;
}
body.theme-dark {
  --bg: #0E1620;
  --surface: #162030;
  --surface2: #1e2d40;
  --text: #e8eaf0;
  --text-muted: #7a8ca0;
  --accent: #613CC4;
  --accent-dark: #4e2fa0;
  --border: #243348;
  --bubble-bg: #ffffff;
  --shadow: 0 8px 32px rgba(0,0,0,0.55);
}
body.font-small { --fact-font-size: 11px; }
body.font-large { --fact-font-size: 15px; }

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; height: 100vh; display: flex; flex-direction: column; transition: background 0.2s, color 0.2s; }

/* Nav */
.nav { display: flex; align-items: center; justify-content: space-between; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.nav-brand { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -0.3px; }
.nav-actions { display: flex; gap: 10px; align-items: center; }
.nav-btn { background: transparent; border: none; color: var(--text-muted); padding: 6px 8px; font-size: 17px; cursor: pointer; border-radius: 6px; line-height: 1; }
.nav-btn:hover { color: var(--accent); }
.theme-seg-group { display: flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; padding: 3px; gap: 2px; }
.theme-seg-btn { padding: 4px 12px; border: none; border-radius: 16px; background: transparent; color: var(--text-muted); font-size: 12px; font-weight: 500; cursor: pointer; transition: all 0.15s; }
.theme-seg-btn.active { background: var(--accent); color: #fff; }
.theme-seg-btn:not(.active):hover { color: var(--text); }

/* 3-column layout: hero | player | facts */
.main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr); flex: 1; overflow: hidden; min-height: 0; }

/* Left column — hero */
.hero { padding: 32px 28px; display: flex; flex-direction: column; gap: 20px; overflow-y: auto; border-right: 1px solid var(--border); background: var(--hero-bg, transparent); min-width: 0; }
:root .hero, body.theme-dark .hero { --hero-bg: radial-gradient(ellipse 70% 60% at 10% 15%, rgba(97,60,196,0.15) 0%, transparent 100%); }
body.theme-light .hero { --hero-bg: transparent; }
.hero-title { font-size: 32px; font-weight: 800; line-height: 1.15; letter-spacing: -0.5px; }
.hero-subtitle { font-size: 13px; color: var(--text-muted); line-height: 1.65; margin-top: 6px; }
.mode-tiles-label { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1.2px; }
.apply-settings-btn { width: 100%; padding: 10px; border-radius: 50px; border: 1.5px solid var(--accent); background: transparent; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s; animation: pulse-border 1.8s ease infinite; }
.apply-settings-btn:hover { background: var(--accent); color: #fff; }
@keyframes pulse-border { 0%,100% { border-color: var(--accent); opacity:1; } 50% { border-color: var(--accent-dark); opacity:0.75; } }

/* URL input */
.url-input-area { display: flex; flex-direction: column; gap: 10px; }
#video-url { width: 100%; padding: 10px 14px; border-radius: 10px; border: 1.5px solid var(--border); font-size: 13px; background: var(--surface2); color: var(--text); transition: border-color 0.15s; }
#video-url:focus { outline: none; border-color: var(--accent); }
#load-btn { width: 100%; padding: 12px 24px; border-radius: 50px; border: none; background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; transition: background 0.15s; }
#load-btn:hover { background: var(--accent-dark); }
body.theme-high-contrast #load-btn { color: #000; }
#load-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Fact controls */
.fact-controls { display: flex; flex-direction: column; gap: 12px; }
.fact-control { display: flex; flex-direction: column; gap: 4px; }
.control-label { font-size: 12px; color: var(--text-muted); }
.slider-row { display: flex; align-items: center; gap: 6px; }
.nudge-btn { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface2); color: var(--text); font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nudge-btn:hover { border-color: var(--accent); }
input[type=range] { flex: 1; accent-color: var(--accent); }

/* Mode tiles */
.mode-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.mode-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 10px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-muted); font-size: 11px; cursor: pointer; transition: all 0.15s; }
.mode-tile:hover { border-color: var(--accent); color: var(--text); }
.mode-tile.active { border-color: var(--accent); background: var(--accent); color: #fff; }
.mode-icon { font-size: 20px; }

/* Center column — player section (flex-column: player above, a11y bar below) */
.player-section { display: flex; flex-direction: column; overflow: hidden; min-height: 0; min-width: 0; background: var(--bg); padding: 14px 12px 0; }

/* Accessibility bar — footer of the player column */
.player-a11y-bar { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 8px 12px; flex-shrink: 0; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; margin: 8px 0 10px; }
.a11y-bar-label { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.8px; white-space: nowrap; }
.a11y-bar-divider { width: 1px; height: 16px; background: var(--border); flex-shrink: 0; }
.a11y-bar-group { display: flex; gap: 4px; align-items: center; }
.a11y-bar-font-btn { padding: 3px 9px; border-radius: 20px; border: 1px solid var(--border); background: transparent; color: var(--text-muted); cursor: pointer; transition: all 0.15s; line-height: 1.4; }
.a11y-bar-font-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.a11y-bar-font-btn:hover:not(.active) { border-color: var(--accent); color: var(--text); }
.a11y-bar-font-btn.small { font-size: 10px; }
.a11y-bar-font-btn.default { font-size: 12px; }
.a11y-bar-font-btn.large { font-size: 14px; }
.a11y-bar-toggle-row { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); white-space: nowrap; }
/* Toggle switch */
.a11y-toggle { position: relative; display: inline-block; width: 34px; height: 20px; flex-shrink: 0; }
.a11y-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.a11y-toggle-track { position: absolute; inset: 0; background: var(--border); border-radius: 20px; cursor: pointer; transition: background 0.2s; }
.a11y-toggle-track::before { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.a11y-toggle input:checked + .a11y-toggle-track { background: var(--accent); }
.a11y-toggle input:checked + .a11y-toggle-track::before { transform: translateX(14px); }
.player-container { position: relative; background: #000; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); flex-shrink: 0; }
.player-container::before { content: ''; display: block; padding-top: 56.25%; }
#youtube-player { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Fact bubble — floating dialog card matching panel cards */
#overlay-container { position: absolute; bottom: 56px; left: 14px; display: flex; flex-direction: column-reverse; gap: 8px; pointer-events: none; max-width: 220px; z-index: 10; }
.fact-bubble { background: var(--surface2); border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; font-size: var(--fact-font-size); line-height: 1.5; color: var(--text); box-shadow: 0 6px 28px rgba(0,0,0,0.38); position: relative; animation: bubble-in 0.25s ease; text-align: center; }
.fact-bubble::after { content: ''; position: absolute; bottom: -9px; left: 22px; width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 9px solid var(--surface2); filter: drop-shadow(0 3px 2px rgba(0,0,0,0.18)); }
.bubble-icon { display: block; font-size: 16px; margin-bottom: 4px; }
.bubble-text { display: block; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Banner and on-demand */
.banner-fact { position: absolute; bottom: 10px; left: 12px; right: 62px; background: rgba(10,10,20,0.88); color: #fff; padding: 10px 14px; font-size: var(--fact-font-size); line-height: 1.6; opacity: 0; transition: opacity 0.35s ease; border-radius: 10px; text-align: center; white-space: normal; word-break: break-word; }
.ondemand-btn { position: absolute; bottom: 14px; right: 14px; width: 38px; height: 38px; border-radius: 50%; background: var(--accent); border: none; color: #fff; font-size: 15px; font-weight: 700; cursor: pointer; box-shadow: 0 4px 16px rgba(97,60,196,0.55); display: flex; align-items: center; justify-content: center; transition: transform 0.15s, box-shadow 0.15s; }
.ondemand-btn:hover { transform: scale(1.1); box-shadow: 0 6px 22px rgba(97,60,196,0.7); }
.ondemand-badge { position: absolute; top: -3px; right: -3px; width: 17px; height: 17px; border-radius: 50%; background: #e53e3e; color: #fff; font-size: 9px; font-weight: 700; display: none; align-items: center; justify-content: center; border: 2px solid var(--bg); }
.ondemand-btn.has-fact .ondemand-badge { display: flex; }

/* Next fact dot */
.next-fact-dot { position: absolute; bottom: 0; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); transform: translateX(-50%); pointer-events: none; z-index: 5; box-shadow: 0 0 6px var(--accent); }

/* Right column — facts panel (3rd grid column) */
.facts-panel { min-width: 0; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.panel-header { padding: 14px 14px 10px; font-size: 15px; font-weight: 700; color: var(--text); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.panel-tabs { display: flex; border-bottom: 1px solid var(--border); }
.panel-tab { flex: 1; padding: 6px 2px; font-size: 11px; background: transparent; border: none; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-content { flex: 1; padding: 10px; overflow-y: auto; display: none; }
.panel-content.visible { display: block; }
.panel-hint { color: var(--text-muted); font-size: 12px; line-height: 1.5; }

/* Sidebar section at top of panel */
.sidebar-panel-section { padding: 10px 10px 0; flex-shrink: 0; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 4px; }
.sidebar-display { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 12px; background: var(--surface2); border-radius: 12px; border: 1px solid var(--border); text-align: center; opacity: 0; }
.sidebar-display.sidebar-fade { animation: sidebar-cycle 6s ease forwards; }
.sidebar-sparkle { font-size: 20px; }
.sidebar-text { font-size: 13px; color: var(--text); line-height: 1.5; }
@keyframes sidebar-cycle { 0% { opacity:0; transform:translateY(6px); } 12% { opacity:1; transform:none; } 80% { opacity:1; } 100% { opacity:0; } }

/* Shared card list — used by all panel tabs */
.history-toolbar { margin-bottom: 8px; }
.history-filter-btn { font-size: 11px; padding: 3px 8px; border-radius: 20px; border: 1px solid var(--border); background: transparent; color: var(--text-muted); cursor: pointer; }
.history-filter-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(97,60,196,0.1); }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-entry { background: var(--surface2); border-radius: 10px; padding: 10px 12px; border: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.history-entry-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 6px; }
.history-text { font-size: 13px; color: var(--text); line-height: 1.4; flex: 1; }
.history-ts { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 2px 8px; font-size: 11px; color: var(--text-muted); cursor: pointer; flex-shrink: 0; white-space: nowrap; }
.history-ts:hover { border-color: var(--accent); color: var(--accent); }
.history-star { background: none; border: none; cursor: pointer; font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.history-star.starred { color: #f5a623; }
.history-empty { color: var(--text-muted); font-size: 12px; }

/* Panel actions */
.panel-actions { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; border-top: 1px solid var(--border); }
.action-btn { flex: 1; padding: 6px 4px; border-radius: 20px; border: 1px solid var(--border); background: transparent; color: var(--text-muted); font-size: 12px; cursor: pointer; white-space: nowrap; }
.action-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Toast notification */
.app-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); padding: 10px 20px; border-radius: 8px; font-size: 13px; font-weight: 500; z-index: 300; box-shadow: 0 4px 16px rgba(0,0,0,0.3); animation: toast-in 0.25s ease; display: flex; align-items: center; gap: 10px; }
.app-toast.error { background: #e53e3e; color: #fff; }
.app-toast.info  { background: var(--accent); color: #fff; }
@keyframes toast-in { from { opacity:0; transform: translateX(-50%) translateY(8px); } to { opacity:1; transform: translateX(-50%) translateY(0); } }
.toast-retry-btn { padding: 3px 12px; border-radius: 20px; border: 1.5px solid rgba(255,255,255,0.5); background: rgba(255,255,255,0.15); color: #fff; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.toast-retry-btn:hover { background: rgba(255,255,255,0.28); }

/* Accessibility panel */
.a11y-panel { position: fixed; top: 0; right: 0; height: 100vh; width: 280px; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow); z-index: 100; transform: translateX(100%); transition: transform 0.25s ease; }
.a11y-panel.open { transform: none; }
.a11y-panel-inner { padding: 20px; display: flex; flex-direction: column; gap: 20px; }
.a11y-close { align-self: flex-end; background: none; border: none; font-size: 18px; color: var(--text-muted); cursor: pointer; }
.a11y-title { font-size: 16px; font-weight: 700; }
.a11y-section { display: flex; flex-direction: column; gap: 8px; }
.a11y-section h3 { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.a11y-row { display: flex; gap: 6px; }
.font-btn, .theme-btn, .speed-btn { padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border); background: transparent; color: var(--text-muted); font-size: 13px; cursor: pointer; }
.font-btn.active, .theme-btn.active, .speed-btn.active { border-color: var(--accent); background: var(--accent); color: #fff; }
.toggle-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.toggle-label input { accent-color: var(--accent); }

/* Responsive */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .hero { border-right: none; border-bottom: 1px solid var(--border); }
  .facts-panel { border-left: none; border-top: 1px solid var(--border); height: 220px; }
  .player-section { padding: 10px 10px 0; }
}
body.theme-high-contrast .fact-bubble,
body.theme-high-contrast .facts-panel,
body.theme-high-contrast .nav,
body.theme-high-contrast .hero,
body.theme-high-contrast #video-url,
body.theme-high-contrast .mode-tile,
body.theme-high-contrast .a11y-panel { border-width: 3px; }
body.theme-high-contrast .fact-bubble { border-color: var(--accent); }
body.theme-high-contrast .fact-bubble::after { border-top-color: var(--surface2); }
body.theme-high-contrast .banner-fact { background: #000; border-top: 2px solid var(--accent); }
body.theme-high-contrast .history-entry { border-width: 2px; border-color: var(--border); }
body.theme-high-contrast .history-ts { border-width: 2px; }
body.theme-high-contrast .panel-a11y-bar { border-width: 2px; }
body.theme-high-contrast #load-btn { background: var(--accent); color: #000; font-weight: 700; }
