/* === CSS Variables === */
:root {
  --bg-primary: #f8f9fa;
  --bg-panel: #ffffff;
  --bg-input: #f1f3f5;
  --bg-toolbar: #212529;
  --bg-status: #343a40;
  --text-primary: #212529;
  --text-secondary: #4a5568;
  --text-light: #f8f9fa;
  --border-color: #dee2e6;
  --primary: #4361ee;
  --primary-hover: #3a56d4;
  --primary-light: #dbe4ff;
  --danger: #e94560;
  --success: #0a8f6e;
  --warning: #d4a017;
  --info: #118ab2;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 8px;
  --toolbar-height: 40px;
  --status-height: 0px;
  --transition: 0.2s ease;
}
/* === Reset & Base === */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}
button {
  cursor: pointer; border: none; border-radius: 6px;
  padding: 8px 14px; font-size: 13px; font-family: inherit;
  transition: background var(--transition), transform 0.1s;
}
button:active { transform: scale(0.97); }
button:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input { font-family: inherit; font-size: 16px; border: 1px solid var(--border-color); border-radius: 6px; padding: 8px 12px; background: var(--bg-input); color: var(--text-primary); }
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
/* === Toolbar (Light Theme) === */
#toolbar {
  height: var(--toolbar-height); background: #ffffff;
  border-bottom: 1px solid #e5e7eb; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  display: flex; align-items: center;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  padding-top: env(safe-area-inset-top, 0px); gap: 10px; z-index: 200; position: relative;
}
/* Brand */
.app-brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.brand-logo { height: 32px; width: auto; }
.brand-name { font-size: 17px; font-weight: 800; background: linear-gradient(135deg, #2563EB, #4361ee); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; letter-spacing: -0.3px; }
#toolbar .app-title { color: var(--text-secondary); font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; padding-left: 10px; border-left: 1px solid #e5e7eb; }
.app-author {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 500; color: #6B7280;
  text-decoration: none; white-space: nowrap;
  padding: 3px 10px; border-radius: 14px;
  background: #F3F4F6; transition: all 0.15s;
}
.app-author:hover { color: #2563EB; background: #EFF6FF; }
.app-author svg { opacity: 0.6; }
.app-author:hover svg { opacity: 1; }
.toolbar-spacer { flex: 1; }
.toolbar-btn {
  background: var(--primary); color: #fff;
  padding: 6px 14px; font-size: 13px; border-radius: 8px;
  min-height: 34px; display: inline-flex;
  align-items: center; justify-content: center; gap: 4px; font-weight: 600;
}
.toolbar-btn:hover { background: var(--primary-hover); }
.toolbar-btn:active { background: #3148c2; transform: scale(0.93); }
.toolbar-btn.active { background: var(--primary); box-shadow: 0 0 0 3px rgba(67,97,238,0.25); }
/* === Layout === */
#main-layout { display: flex; height: calc(100vh - var(--toolbar-height)); }
/* === Graph Container === */
#graph-container {
  flex: 1; position: relative; background: #f8f9fb; overflow: hidden;
  touch-action: none; -webkit-user-select: none; user-select: none;
  -webkit-font-smoothing: antialiased; cursor: pointer; height: 100%;
}
#graph-container canvas { display: block; }
#graph-container .sigma-labels { opacity: 0 !important; }
#graph-container .sigma-hovers { opacity: 0 !important; }
/* === Stats Bar (Floating) === */
.kg-stats-bar {
  position: absolute; top: 12px; left: 12px; right: auto;
  background: rgba(255,255,255,0.94); backdrop-filter: blur(10px);
  border: 1px solid rgba(0,0,0,0.06); border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  padding: 8px 14px; display: flex; align-items: center; gap: 12px;
  font-size: 12px; color: var(--text-secondary); z-index: 15; flex-wrap: wrap;
}
.kg-stats-bar .stat-item { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.kg-stats-bar .stat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.kg-stats-bar .stat-value { font-weight: 600; color: var(--text-primary); }
.kg-stats-bar .stat-sep { width: 1px; height: 16px; background: var(--border-color); }
/* === Legend Bar (Floating Panel) === */
.kg-legend-bar {
  position: absolute; bottom: 12px; left: 60px; right: auto;
  background: rgba(255,255,255,0.94); backdrop-filter: blur(10px);
  border: 1px solid rgba(0,0,0,0.06); border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  padding: 8px 12px; display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text-secondary); z-index: 15; flex-wrap: wrap;
  max-width: calc(100vw - 300px);
}
.kg-legend-bar .legend-item {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  padding: 4px 8px; border-radius: 6px; transition: all var(--transition);
  background: none; border: none; font-family: inherit; font-size: inherit; color: inherit; min-height: 0;
}
.kg-legend-bar .legend-item:hover { background: var(--bg-input); }
.kg-legend-bar .legend-item.dimmed { opacity: 0.35; text-decoration: line-through; }
.kg-legend-bar .legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
/* === Zoom Overlay === */
.kg-zoom-overlay {
  position: absolute; bottom: 60px; left: 12px;
  display: flex; flex-direction: column; gap: 6px; z-index: 15;
}
.kg-zoom-overlay button {
  width: 40px; height: 40px; border-radius: 50%;
  background: #ffffff; border: 1px solid rgba(0,0,0,0.08);
  font-size: 18px; display: flex; align-items: center; justify-content: center;
  color: var(--text-primary); box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  backdrop-filter: blur(6px); padding: 0; transition: all var(--transition);
}
.kg-zoom-overlay button:hover { background: var(--bg-input); box-shadow: 0 4px 12px rgba(0,0,0,0.15); transform: scale(1.05); }
.kg-zoom-overlay button:active { background: var(--primary-light); transform: scale(0.95); }
/* === Minimap === */
.kg-minimap {
  position: absolute; bottom: 48px; right: 12px;
  width: 200px; height: 150px; background: rgba(255,255,255,0.9);
  border: 1px solid rgba(0,0,0,0.06); border-radius: 12px;
  z-index: 15; overflow: hidden; box-shadow: 0 4px 16px rgba(0,0,0,0.08); cursor: pointer;
  backdrop-filter: blur(8px);
}
.kg-minimap canvas { display: block; width: 100%; height: 100%; }
/* === Graph Info Badge === */
.graph-info-badge {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6); color: #fff; padding: 6px 16px;
  border-radius: 20px; font-size: 12px; pointer-events: none; z-index: 16; transition: opacity 0.3s;
}
/* === Focus Back Button === */
.focus-back-btn {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(124, 58, 237, 0.92); color: #fff; padding: 8px 20px;
  border-radius: 20px; font-size: 13px; font-weight: 600; z-index: 17;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2); display: none; align-items: center;
  gap: 8px; cursor: pointer; backdrop-filter: blur(6px);
}
.focus-back-btn.active { display: flex; }
.focus-back-btn:hover { background: rgba(124, 58, 237, 1); }
.focus-back-btn:active { transform: translateX(-50%) scale(0.97); }
/* === Viewer Info Card === */
.viewer-info-card {
  position: absolute; top: 50%; right: 16px; transform: translateY(-50%);
  width: 300px; max-width: calc(100vw - 32px); max-height: calc(100% - 80px);
  overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(12px); border: 1px solid var(--border-color);
  border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  padding: 16px; z-index: 50; animation: viewerCardIn 0.2s ease-out;
  overscroll-behavior: contain;
}
@keyframes viewerCardIn {
  from { opacity: 0; transform: translateY(-50%) translateX(12px); }
  to { opacity: 1; transform: translateY(-50%) translateX(0); }
}
@keyframes viewerCardInMobile {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.viewer-info-close {
  position: absolute; top: 8px; right: 8px; width: 36px; height: 36px;
  border-radius: 50%; background: var(--bg-input); border: none;
  font-size: 18px; color: var(--text-secondary); display: flex;
  align-items: center; justify-content: center; cursor: pointer; padding: 0; min-height: 0;
}
.viewer-info-close:hover { background: #e9ecef; color: var(--text-primary); }
.viewer-info-breadcrumb { font-size: 11px; color: var(--text-secondary); margin-bottom: 8px; line-height: 1.5; word-break: break-word; padding-right: 28px; }
.viewer-info-breadcrumb .breadcrumb-sep { margin: 0 4px; color: #adb5bd; }
.viewer-info-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.viewer-info-label { font-size: 18px; font-weight: 700; color: var(--text-primary); word-break: break-word; }
.viewer-info-badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; color: #fff; text-transform: uppercase; letter-spacing: 0.5px; flex-shrink: 0; }
.viewer-info-note { font-size: 13px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 12px; white-space: pre-wrap; word-break: break-word; }
.viewer-info-note:empty { display: none; }
.viewer-info-section-title { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-secondary); margin-bottom: 6px; }
.viewer-info-neighbors { max-height: 200px; overflow-y: auto; margin-bottom: 12px; }
.viewer-info-neighbor { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text-primary); transition: background var(--transition); }
.viewer-info-neighbor:hover { background: var(--bg-input); }
.viewer-info-neighbor .node-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.viewer-info-neighbor .neighbor-relation { font-size: 11px; color: #adb5bd; margin-left: auto; flex-shrink: 0; }
.viewer-info-explore-section { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.explore-prompt-chip { display: inline-block; padding: 6px 11px; background: var(--primary-light); color: var(--primary); text-decoration: none; border-radius: 16px; font-size: 12px; font-weight: 500; line-height: 1.4; transition: background var(--transition), color var(--transition); cursor: pointer; word-break: break-word; }
.explore-prompt-chip:hover { background: var(--primary); color: #fff; }
/* === Viewer Search === */
.viewer-search { position: relative; flex: 1; max-width: 300px; margin: 0 8px; }
.viewer-search input { width: 100%; height: 36px; padding: 6px 12px 6px 36px; font-size: 13px; border-radius: 20px; border: 1px solid #e5e7eb; background: #f1f3f4; color: var(--text-primary); transition: all var(--transition); }
.viewer-search input::placeholder { color: #9ca3af; }
.viewer-search input:focus { background: #fff; border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(67,97,238,0.12); }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #9ca3af; pointer-events: none; z-index: 1; }
.viewer-search-results { position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px; background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.15); max-height: 240px; overflow-y: auto; display: none; z-index: 300; }
.viewer-search-results.active { display: block; }
.viewer-search-result { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; color: var(--text-primary); transition: background var(--transition); }
.viewer-search-result:hover { background: var(--bg-input); }
.viewer-search-result .node-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
/* === Empty State === */
.empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 14px; text-align: center; line-height: 1.8; pointer-events: none; z-index: 5; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.3; }
/* === Responsive === */
@media (max-width: 900px) {
  .kg-zoom-overlay button { width: 44px; height: 44px; font-size: 20px; }
  .kg-legend-bar .legend-item { padding: 6px 8px; min-height: 44px; }
  .viewer-info-close { width: 44px; height: 44px; font-size: 20px; }
}
@media (max-width: 768px) {
  #toolbar { padding: 0 10px; gap: 6px; }
  .brand-logo { height: 26px; }
  .brand-name { font-size: 14px; }
  #toolbar .app-title { font-size: 12px; max-width: 20vw; }
  .toolbar-btn { min-height: 34px; padding: 5px 10px; font-size: 12px; }
  .kg-zoom-overlay button { width: 42px; height: 42px; font-size: 18px; }
  .kg-minimap { width: 140px; height: 105px; }
  .kg-stats-bar { padding: 6px 10px; gap: 8px; font-size: 12px; }
  .kg-legend-bar { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; padding: 4px 10px; gap: 8px; }
  .viewer-info-card { width: 280px; right: 8px; padding: 14px; max-height: calc(100% - 60px); }
  .viewer-info-label { font-size: 16px; }
  .viewer-info-neighbors { max-height: 160px; }
  .viewer-search-results { max-height: 180px; }
  .viewer-search-result { padding: 10px 12px; min-height: 44px; }
}
@media (max-width: 600px) {
  #toolbar { padding: 0 6px; gap: 4px; height: 38px; }
  .brand-logo { height: 22px; }
  .brand-name { font-size: 13px; }
  #toolbar .app-title { display: none; }
  .app-author { display: none; }
  .toolbar-btn { min-height: 32px; padding: 4px 10px; font-size: 11px; }
  .kg-minimap { width: 110px; height: 82px; }
  .kg-stats-bar { padding: 3px 8px; font-size: 11px; }
  .kg-legend-bar { padding: 3px 8px; gap: 6px; font-size: 11px; }
  .kg-legend-bar .legend-item { padding: 4px 6px; min-height: 36px; }
  .kg-zoom-overlay button { width: 44px; height: 44px; font-size: 20px; }
  .viewer-search { max-width: 160px; }
  .viewer-search input { font-size: 16px; height: 34px; padding-left: 34px; }
  .viewer-info-card { position: absolute; top: auto; bottom: 50px; right: 0; left: 0; width: 100%; max-width: 100%; transform: none; border-radius: 12px 12px 0 0; max-height: 65vh; max-height: 65dvh; animation: viewerCardInMobile 0.2s ease-out; }
  .viewer-info-neighbors { max-height: 120px; }
  .viewer-info-explore-section { gap: 4px; }
  .explore-prompt-chip { font-size: 11px; padding: 4px 8px; }
}
@media (max-width: 380px) {
  #toolbar { gap: 2px; }
  .brand-name { display: none; }
  .kg-minimap { display: none; }
  .viewer-search { max-width: 120px; margin: 0 4px; }
  .viewer-info-card { padding: 12px; }
  .viewer-info-label { font-size: 15px; }
}
/* === Fast Reader (RSVP) === */
.fast-reader-panel {
  position: absolute; inset: 0; z-index: 120;
  opacity: 0; visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.fast-reader-panel.active { opacity: 1; visibility: visible; }
.fr-backdrop {
  position: absolute; inset: 0;
  background: rgba(10, 10, 20, 0.92);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
.fr-container {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.fr-header {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
}
.fr-title {
  font-size: 13px; font-weight: 600; color: rgba(255,255,255,0.4);
  text-transform: uppercase; letter-spacing: 1.5px;
}
.fr-close-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.1); border: none;
  color: rgba(255,255,255,0.6); font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; min-height: 0;
  transition: all 0.2s;
}
.fr-close-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }
.fr-body {
  position: relative;
  width: 90%; max-width: 700px;
  padding: 48px 0;
}
.fr-sentence {
  font-family: 'Noto Sans Mono', 'Consolas', monospace;
  font-size: 15px; line-height: 1;
  color: rgba(255,255,255,0.3);
  text-align: center;
  padding: 0 16px;
  width: 90%; max-width: 700px;
  height: 20px;
  white-space: nowrap;
  overflow: hidden;
  margin-bottom: 12px;
}
.fr-sentence .fr-sent-active {
  color: rgba(255,255,255,0.85);
}
.fr-sentence .fr-sent-ellip {
  color: rgba(255,255,255,0.15);
}
.fr-guide-line {
  position: absolute; left: 10%; right: 10%;
  height: 1px; background: rgba(255,255,255,0.08);
}
.fr-guide-top { top: 0; }
.fr-guide-bottom { bottom: 0; }
.fr-notch {
  position: absolute; left: 50%; width: 2px; height: 14px;
  background: rgba(255,255,255,0.15); transform: translateX(-50%);
}
.fr-notch-top { top: -14px; }
.fr-notch-bottom { bottom: -14px; }
.fr-word-area {
  display: flex; align-items: center; justify-content: center;
  min-height: 80px; padding: 16px 0;
  width: 100%; position: relative;
}
.fr-word {
  font-family: 'Noto Sans Mono', 'Consolas', 'SF Mono', 'Menlo', monospace;
  font-size: 52px; font-weight: 400; color: #e6e6e6;
  white-space: nowrap; letter-spacing: 0;
  display: flex; align-items: baseline;
  position: relative; width: 100%;
}
.fr-word .fr-before {
  color: #e6e6e6; flex: 1; text-align: right;
  overflow: hidden; min-width: 0;
}
.fr-word .fr-orp {
  color: #DC143C; font-weight: 700;
  flex-shrink: 0; text-align: center;
  width: 0.65em; display: inline-block;
}
.fr-word .fr-after {
  color: #e6e6e6; flex: 1; text-align: left;
  overflow: hidden; min-width: 0;
}
.fr-word .fr-complete { color: rgba(255,255,255,0.5); font-size: 28px; font-weight: 500; flex: 1; text-align: center; }
/* Progress bar — seekable */
.fr-progress-wrap {
  width: 90%; max-width: 700px;
  margin-top: 32px; padding: 10px 0;
  cursor: pointer; position: relative;
  -webkit-user-select: none; user-select: none;
}
.fr-progress-bar {
  width: 100%; height: 4px;
  background: rgba(255,255,255,0.10);
  border-radius: 3px; overflow: visible;
  position: relative;
}
.fr-progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #DC143C, #ff4d6d);
  border-radius: 3px; transition: width 0.08s linear;
  position: relative;
}
.fr-progress-thumb {
  position: absolute; right: -7px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; border-radius: 50%;
  background: #DC143C; box-shadow: 0 0 6px rgba(220,20,60,0.5);
  opacity: 0; transition: opacity 0.15s;
}
.fr-progress-wrap:hover .fr-progress-thumb,
.fr-progress-wrap.dragging .fr-progress-thumb { opacity: 1; }
.fr-progress-wrap:hover .fr-progress-bar { height: 6px; }
.fr-progress-wrap.dragging .fr-progress-bar { height: 6px; }
.fr-progress-time {
  display: flex; justify-content: space-between;
  font-size: 11px; color: rgba(255,255,255,0.25);
  margin-top: 6px; padding: 0 2px;
}
.fr-controls {
  display: flex; align-items: center; gap: 12px;
  margin-top: 24px; flex-wrap: wrap; justify-content: center;
}
.fr-ctrl-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.08); border: none;
  color: rgba(255,255,255,0.7); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; min-height: 0;
  transition: all 0.2s;
}
.fr-ctrl-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
.fr-play-btn {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(220,20,60,0.25); color: #DC143C;
}
.fr-play-btn:hover { background: rgba(220,20,60,0.4); }
.fr-speed {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.06); border-radius: 20px;
  padding: 4px 8px;
}
.fr-speed-btn {
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(255,255,255,0.1); border: none;
  color: rgba(255,255,255,0.7); font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; min-height: 0;
  transition: all 0.2s;
}
.fr-speed-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }
.fr-wpm {
  font-size: 13px; font-weight: 600; color: rgba(255,255,255,0.5);
  min-width: 42px; text-align: center;
}
.fr-wpm::after { content: ' wpm'; font-weight: 400; font-size: 10px; }
.fr-info { font-size: 12px; color: rgba(255,255,255,0.3); }
.fr-controls-info {
  display: flex; align-items: center; justify-content: center;
  gap: 16px; margin-top: 12px;
}
/* Fast Reader toolbar button */
.toolbar-btn-fr {
  background: none; color: var(--text-secondary);
  padding: 6px 12px; font-size: 13px; border-radius: 8px;
  min-height: 34px; display: none; align-items: center; gap: 5px;
  font-weight: 500; border: 1px solid #e5e7eb;
  transition: all var(--transition);
}
.toolbar-btn-fr:hover { background: #f1f3f5; color: var(--text-primary); border-color: #d1d5db; }
.toolbar-btn-fr.active { background: #1a1a2e; color: #DC143C; border-color: #1a1a2e; }
.toolbar-btn-fr.has-content { display: inline-flex; }
/* Fast Reader responsive */
@media (max-width: 768px) {
  .fr-word { font-size: 40px; }
  .fr-body { width: 95%; }
  .fr-controls { gap: 8px; }
  .fr-play-btn { width: 48px; height: 48px; }
  .fr-sentence { font-size: 14px; }
}
@media (max-width: 600px) {
  .fr-word { font-size: 32px; }
  .fr-controls { gap: 6px; }
  .fr-ctrl-btn { width: 36px; height: 36px; }
  .fr-sentence { font-size: 13px; padding: 0 8px; }
  .fr-play-btn { width: 44px; height: 44px; }
  .toolbar-btn-fr span.btn-text { display: none; }
}

/* === Video Export Dialog === */
.vex-overlay {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: all 0.25s;
}
.vex-overlay.visible { opacity: 1; visibility: visible; }
.vex-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.vex-dialog {
  position: relative; z-index: 1;
  background: linear-gradient(160deg, #1a1a2e 0%, #16162a 100%);
  border-radius: 18px; width: 440px; max-width: 92vw;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
  color: #e6e6e6;
}
.vex-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 24px 0;
}
.vex-title { font-weight: 700; font-size: 18px; letter-spacing: 0.01em; }
.vex-close {
  background: none; border: none; color: rgba(255,255,255,0.4);
  font-size: 22px; cursor: pointer; padding: 2px 6px; min-height: 0;
  border-radius: 6px; transition: all 0.15s;
}
.vex-close:hover { color: #fff; background: rgba(255,255,255,0.08); }
.vex-body { padding: 20px 24px 24px; }
.vex-field { margin-bottom: 18px; }
.vex-field label {
  display: block; font-size: 12px; font-weight: 600;
  color: rgba(255,255,255,0.45); margin-bottom: 10px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
/* Ratio cards */
.vex-ratio-grid { display: flex; gap: 8px; }
.vex-ratio-card {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 14px 6px 10px; border-radius: 12px; cursor: pointer;
  background: rgba(255,255,255,0.03); border: 2px solid transparent;
  transition: all 0.2s;
}
.vex-ratio-card:hover { background: rgba(255,255,255,0.06); }
.vex-ratio-card.active {
  border-color: #DC143C; background: rgba(220,20,60,0.08);
}
.vex-ratio-shape {
  background: rgba(255,255,255,0.1); border-radius: 3px;
  margin-bottom: 8px; transition: background 0.2s;
}
.vex-ratio-card.active .vex-ratio-shape { background: rgba(220,20,60,0.25); }
.vex-rs-p { width: 24px; height: 42px; }
.vex-rs-l { width: 42px; height: 24px; }
.vex-rs-s { width: 34px; height: 34px; }
.vex-rs-f { width: 30px; height: 38px; }
.vex-ratio-name {
  font-size: 11px; font-weight: 700;
  color: rgba(255,255,255,0.55); margin-bottom: 3px;
}
.vex-ratio-card.active .vex-ratio-name { color: #DC143C; }
.vex-ratio-sub {
  font-size: 9px; line-height: 1.3;
  color: rgba(255,255,255,0.25); text-align: center;
}
/* Speed row */
.vex-speed-row { display: flex; align-items: center; gap: 12px; }
.vex-speed-row input[type="range"] { flex: 1; accent-color: #DC143C; }
#vex-wpm-val {
  font-weight: 700; font-size: 15px; min-width: 36px; text-align: right;
  font-variant-numeric: tabular-nums;
}
.vex-field select {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.08);
  color: #e6e6e6; font-size: 14px; transition: border-color 0.15s;
}
.vex-field select:focus { border-color: rgba(220,20,60,0.4); outline: none; }
/* Preview */
.vex-preview {
  text-align: center; font-size: 13px;
  color: rgba(255,255,255,0.4); margin-bottom: 20px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
/* Export button */
.vex-export-btn {
  width: 100%; padding: 13px; border: none; border-radius: 12px;
  background: #DC143C; color: #fff; font-weight: 700;
  font-size: 15px; cursor: pointer; transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(220,20,60,0.25);
}
.vex-export-btn:hover {
  background: #c01236; box-shadow: 0 6px 20px rgba(220,20,60,0.35);
  transform: translateY(-1px);
}
.vex-export-btn:active { transform: translateY(0); }
/* Progress */
.vex-progress-area { text-align: center; }
.vex-progress-text {
  font-size: 14px; color: rgba(255,255,255,0.5); margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}
.vex-pbar-bg {
  width: 100%; height: 5px; border-radius: 2.5px;
  background: rgba(255,255,255,0.06); overflow: hidden; margin-bottom: 16px;
}
.vex-pbar-fill {
  height: 100%; width: 0; border-radius: 2.5px;
  background: linear-gradient(90deg, #DC143C, #FF4060);
  transition: width 0.3s;
}
.vex-cancel-btn {
  padding: 8px 20px; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px; background: none; color: rgba(255,255,255,0.5);
  font-size: 13px; cursor: pointer; min-height: 0; transition: all 0.15s;
}
.vex-cancel-btn:hover { border-color: rgba(255,255,255,0.3); color: #fff; }
/* FR export button in header */
.fr-export-btn {
  background: none; border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.5); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; display: flex;
  align-items: center; gap: 6px; font-size: 12px;
  font-weight: 500; min-height: 0; transition: all 0.2s;
}
.fr-export-btn:hover {
  background: rgba(255,255,255,0.06); color: #fff;
  border-color: rgba(255,255,255,0.25);
}
@media (max-width: 600px) {
  .vex-dialog { width: 95vw; }
  .fr-export-btn span { display: none; }
  .vex-ratio-sub { display: none; }
}

/* === Article Reader Panel === */
#article-reader {
  position: absolute; inset: 0; z-index: 100;
  background: #fff;
  overflow-y: auto; overflow-x: hidden;
  opacity: 0; visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
#article-reader.active { opacity: 1; visibility: visible; }
#article-reader { -webkit-user-select: text; user-select: text; cursor: text; }
.article-reader-inner {
  max-width: 720px; margin: 0 auto;
  padding: 48px 24px 80px;
  font-size: 17px; line-height: 1.85; color: #1a1a2e;
}
.article-reader-inner h2 {
  font-size: 22px; font-weight: 700; color: #1e293b;
  margin: 36px 0 14px; padding-bottom: 8px;
  border-bottom: 2px solid #e5e7eb;
}
.article-reader-inner h3 {
  font-size: 18px; font-weight: 600; color: #334155;
  margin: 28px 0 10px;
}
.article-reader-inner p { margin-bottom: 16px; }
.article-reader-inner ul, .article-reader-inner ol {
  margin: 12px 0 16px 24px;
}
.article-reader-inner li { margin-bottom: 8px; }
.article-reader-inner strong { color: #0f172a; }
.article-reader-inner blockquote {
  margin: 20px 0; padding: 14px 20px;
  border-left: 4px solid var(--primary);
  background: #f0f4ff; border-radius: 0 8px 8px 0;
  font-style: italic; color: #475569;
}
.article-reader-inner table {
  width: 100%; border-collapse: collapse; margin: 16px 0;
  font-size: 15px;
}
.article-reader-inner th, .article-reader-inner td {
  border: 1px solid #e5e7eb; padding: 10px 14px; text-align: left;
}
.article-reader-inner th { background: #f8fafc; font-weight: 600; color: #334155; }
.article-reader-inner .article-lead {
  font-size: 19px; line-height: 1.7; color: #334155;
  font-weight: 500; margin-bottom: 24px;
  padding-bottom: 20px; border-bottom: 1px solid #f1f5f9;
}
/* Article copy button */
.article-copy-btn {
  position: fixed; top: calc(var(--toolbar-height) + 16px); right: 24px;
  z-index: 105; background: #fff; color: #475569;
  border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 8px 14px; font-size: 13px; font-weight: 500;
  display: none; align-items: center; gap: 6px;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transition: all 0.2s;
}
.article-copy-btn:hover { background: #f8fafc; border-color: #d1d5db; color: #1e293b; }
.article-copy-btn.copied { background: #10b981; color: #fff; border-color: #10b981; }
/* copy button visibility controlled by JS toggleArticle() */
/* ChatGPT context menu */
.chatgpt-ctx-menu {
  position: fixed; z-index: 9999;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12); padding: 4px;
  min-width: 200px; display: none;
}
.chatgpt-ctx-menu.visible { display: block; }
.chatgpt-ctx-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; font-size: 14px; color: #1a1a2e;
  border-radius: 8px; cursor: pointer; text-decoration: none;
  transition: background 0.15s;
}
.chatgpt-ctx-item:hover { background: #f0f4ff; }
.chatgpt-ctx-item svg { flex-shrink: 0; }
/* Video toolbar button */
.toolbar-btn-video {
  background: none; color: var(--text-secondary);
  padding: 6px 12px; font-size: 13px; border-radius: 8px;
  min-height: 34px; display: inline-flex; align-items: center; gap: 5px;
  font-weight: 500; border: 1px solid #e5e7eb;
  transition: all var(--transition); cursor: pointer;
}
.toolbar-btn-video:hover { background: #fff1f3; color: #DC143C; border-color: #f5b8c4; }
.toolbar-btn-video:active { transform: scale(0.96); }
.toolbar-btn-video svg { color: #DC143C; }
@media (max-width: 600px) {
  .toolbar-btn-video span.btn-text { display: none; }
}

/* Video modal */
.video-modal {
  position: fixed; inset: 0; z-index: 10010;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity 0.2s, visibility 0.2s;
}
.video-modal.active { opacity: 1; visibility: visible; }
.video-modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.82);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
}
.video-modal-dialog {
  position: relative; z-index: 1;
  width: min(960px, 92vw);
  max-height: 90vh;
}
.video-modal-frame {
  position: relative; width: 100%;
  background: #000; border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
}
.video-modal-iframe-wrap {
  position: relative; width: 100%; padding-bottom: 56.25%; height: 0;
}
.video-modal-iframe-wrap iframe {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0;
}
.video-modal-close {
  position: absolute; top: -44px; right: 0;
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.12); color: #fff; border: none;
  font-size: 22px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
.video-modal-close:hover { background: rgba(255,255,255,0.22); transform: scale(1.05); }
@media (max-width: 600px) {
  .video-modal-dialog { width: 96vw; }
  .video-modal-close { top: -40px; width: 32px; height: 32px; font-size: 20px; }
}

/* Article toolbar button */
.toolbar-btn-article {
  background: none; color: var(--text-secondary);
  padding: 6px 12px; font-size: 13px; border-radius: 8px;
  min-height: 34px; display: none; align-items: center; gap: 5px;
  font-weight: 500; border: 1px solid #e5e7eb;
  transition: all var(--transition);
}
.toolbar-btn-article:hover { background: #f1f3f5; color: var(--text-primary); border-color: #d1d5db; }
.toolbar-btn-article.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.toolbar-btn-article.active:hover { background: var(--primary-hover); }
.toolbar-btn-article.has-content { display: inline-flex; }
/* Article close floating button */
.article-close-btn {
  position: fixed; bottom: 28px; right: 28px;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 20px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(67,97,238,0.4);
  z-index: 110; cursor: pointer; border: none;
  transition: all 0.2s; opacity: 0; pointer-events: none;
}
.article-close-btn.active { opacity: 1; pointer-events: auto; }
.article-close-btn:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(67,97,238,0.5); }
.article-close-btn:active { transform: scale(0.95); }
/* Responsive article */
@media (max-width: 768px) {
  .article-reader-inner { padding: 32px 16px 60px; font-size: 16px; }
  .article-reader-inner h2 { font-size: 20px; }
  .article-reader-inner .article-lead { font-size: 17px; }
  .article-close-btn { bottom: 20px; right: 20px; width: 44px; height: 44px; }
}
@media (max-width: 600px) {
  .article-reader-inner { padding: 24px 14px 56px; font-size: 15px; line-height: 1.75; }
  .article-reader-inner h2 { font-size: 18px; margin: 28px 0 10px; }
  .toolbar-btn-article span.btn-text { display: none; }
}

/* ============================================
   SHARE SYSTEM
   ============================================ */
.share-wrapper { position: relative; }

.toolbar-btn-share {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px; background: rgba(255,255,255,0.05);
  color: #d1d5db; font-size: 13px; cursor: pointer;
  transition: all 0.2s;
}
.toolbar-btn-share:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.25);
  color: #fff;
}
.toolbar-btn-share svg { flex-shrink: 0; }

.share-dropdown {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: #1e1e2e; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px; padding: 6px; min-width: 220px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 1000; animation: shareDropIn 0.15s ease-out;
}
.share-dropdown.active { display: block; }

@keyframes shareDropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.share-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 7px; cursor: pointer;
  color: #d1d5db; font-size: 13px; text-decoration: none;
  transition: background 0.15s;
  border: none; background: none; width: 100%; text-align: left;
}
.share-item:hover { background: rgba(255,255,255,0.08); color: #fff; }

.share-item-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.share-item-icon.fb { background: #1877F2; }
.share-item-icon.zalo { background: #0068FF; }
.share-item-icon.x { background: #000; border: 1px solid rgba(255,255,255,0.15); }
.share-item-icon.link { background: rgba(255,255,255,0.1); }
.share-item-icon.embed { background: rgba(255,255,255,0.1); }

.share-item-text { display: flex; flex-direction: column; }
.share-item-label { font-weight: 500; line-height: 1.2; }
.share-item-sub { font-size: 11px; color: rgba(255,255,255,0.35); line-height: 1.3; }

.share-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #10b981; color: #fff; padding: 10px 20px;
  border-radius: 8px; font-size: 13px; font-weight: 500;
  box-shadow: 0 4px 20px rgba(16,185,129,0.4);
  z-index: 9999; opacity: 0; transition: opacity 0.3s;
  pointer-events: none;
}
.share-toast.visible { opacity: 1; }

/* ============================================
   EMBED MODE
   ============================================ */
body.embed-mode #toolbar { display: none; }
body.embed-mode #main-layout { height: 100vh; }
body.embed-mode .article-close-btn,
body.embed-mode .article-copy-btn,
body.embed-mode #chatgpt-ctx-menu { display: none; }

.embed-brand {
  display: none; position: absolute; bottom: 12px; right: 12px;
  background: rgba(10,10,24,0.85); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; padding: 6px 12px;
  color: rgba(255,255,255,0.6); font-size: 11px;
  text-decoration: none; z-index: 100;
  transition: all 0.2s;
}
.embed-brand:hover { color: #fff; background: rgba(10,10,24,0.95); }
.embed-brand img { width: 16px; height: 16px; vertical-align: middle; margin-right: 4px; }
body.embed-mode .embed-brand { display: flex; align-items: center; gap: 4px; }

/* ============================================
   SSR HIDDEN CONTENT (accessible to crawlers)
   ============================================ */
.seo-only {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden !important; clip: rect(0,0,0,0) !important;
  white-space: nowrap !important; border: 0 !important;
}

/* ============================================
   ENTITY LINKS IN ARTICLE
   ============================================ */
.entity-link {
  color: #4f46e5; cursor: pointer;
  border-bottom: 1px dotted rgba(79,70,229,0.3);
  transition: all 0.15s;
}
.entity-link:hover {
  color: #4338ca;
  border-bottom-color: #4338ca;
  background: rgba(79,70,229,0.06);
  border-radius: 2px;
}

/* ============================================
   INFO CARD SHARE BUTTON
   ============================================ */
.viewer-info-share {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; margin-bottom: 8px;
  border: 1px solid rgba(255,255,255,0.12); border-radius: 6px;
  background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.6);
  font-size: 12px; cursor: pointer; transition: all 0.2s;
  width: 100%; justify-content: center;
}
.viewer-info-share:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* Clickable breadcrumb */
.viewer-info-breadcrumb span:not(:last-child):hover {
  color: var(--primary); text-decoration: underline;
}

/* ============================================
   EMBED CODE MODAL
   ============================================ */
.embed-code-box {
  background: #0d0d1a; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px; padding: 10px; font-size: 12px;
  font-family: 'Noto Sans Mono', monospace; color: #a5b4fc;
  word-break: break-all; line-height: 1.5; margin-top: 8px;
  cursor: pointer; transition: border-color 0.2s;
}
.embed-code-box:hover { border-color: rgba(255,255,255,0.25); }

/* ============================================
   RESPONSIVE SHARE
   ============================================ */
@media (max-width: 768px) {
  .toolbar-btn-share .btn-text { display: none; }
  .share-dropdown { right: -40px; min-width: 200px; }
}
@media (max-width: 480px) {
  .share-dropdown {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    border-radius: 16px 16px 0 0; min-width: 100%;
    padding: 12px 12px 28px;
    animation: shareSlideUp 0.2s ease-out;
  }
  .share-dropdown.active::before {
    content: ''; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4); z-index: -1; pointer-events: none;
  }
  .share-item { padding: 14px 16px; }
  .share-item-icon { width: 36px; height: 36px; }
}
@keyframes shareSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
