  :root {
    --bg: #1a1a2e; --card: #16213e; --accent: #0f3460; --highlight: #e94560; --text: #eee; --muted: #888; --border: #2a2a4a;
    --input-bg: #1a1a2e; --input-border: #333; --hover-row: rgba(255,255,255,0.03);
    --good-bg: #1a4731; --good-fg: #2ecc71; --mid-bg: #4a3a1a; --mid-fg: #f39c12; --low-bg: #4a1a1a; --low-fg: #e74c3c;
    --error-bg: #4a1a2a; --error-fg: #e94560;
  }
  [data-theme="light"] {
    --bg: #f0f2f5; --card: #ffffff; --accent: #4a6fa5; --highlight: #d63031; --text: #222; --muted: #777; --border: #ddd;
    --input-bg: #fff; --input-border: #ccc; --hover-row: rgba(0,0,0,0.03);
    --good-bg: #d4edda; --good-fg: #155724; --mid-bg: #fff3cd; --mid-fg: #856404; --low-bg: #f8d7da; --low-fg: #721c24;
    --error-bg: #f8d7da; --error-fg: #c0392b;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

  /* Header */
  .header { padding: 10px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
  .header h1 { font-size: 1.1rem; }
  .header .status-text { font-size: 0.8rem; color: var(--muted); }

  /* Panels */
  .panel { padding: 16px; overflow-y: auto; flex-shrink: 0; font-size: 13px; }
  .panel:last-child { flex: 1; }
  .panel h2 { font-size: 0.85em; color: var(--highlight); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 1px; font-weight: 500; }
  .panel h3 { font-size: 0.85em; color: var(--muted); margin: 12px 0 6px; font-weight: 400; letter-spacing: 0.3px; }
  #centerPanel { font-family: -apple-system, BlinkMacSystemFont, sans-serif; }
  #rightPanel { font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace; }

  /* Resize handles */
  .resize-handle { width: 4px; cursor: col-resize; background: var(--border); flex-shrink: 0; transition: background 0.15s; }
  .resize-handle:hover, .resize-handle.active { background: var(--highlight); }

  /* Reference text in practice */
  .ref-display { font-size: 1.05em; color: var(--text); line-height: 1.5; padding: 8px 0 4px; font-style: italic; opacity: 0.85; }

  /* Section dividers */
  .section { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
  .section:last-child { border-bottom: none; }

  /* Forms — all em-based */
  label { display: block; font-size: 0.9em; color: var(--muted); margin-bottom: 3px; }
  input[type="file"] { width: 100%; font-size: 0.95em; margin-bottom: 8px; color: var(--text); }
  input[type="text"], input[type="number"] {
    width: 100%; padding: 6px 10px; border: 1px solid var(--input-border); border-radius: 5px;
    background: var(--input-bg); color: var(--text); margin-bottom: 8px; font-size: 1em;
  }
  button {
    padding: 7px 14px; border: none; border-radius: 5px; cursor: pointer;
    font-size: 1em; font-weight: 600; transition: opacity 0.2s;
  }
  button:hover { opacity: 0.85; }
  button:disabled { opacity: 0.4; cursor: not-allowed; }
  .btn-primary { background: var(--highlight); color: white; }
  .btn-secondary { background: var(--accent); color: white; }
  .btn-sm { padding: 5px 10px; font-size: 0.9em; }

  /* Recording button */
  .btn-rec { background: #c0392b; color: white; min-width: 80px; }
  .btn-rec.recording { background: #e74c3c; animation: pulse 1s infinite; }
  @keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

  /* Audio players */
  audio { width: 100%; height: 32px; margin-top: 4px; }

  /* Inline row */
  .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .row-compact { display: flex; gap: 6px; align-items: end; }

  /* Score grid */
  .score-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px; }
  .score-item { background: var(--bg); border-radius: 6px; padding: 8px; text-align: center; }
  .score-item .label { font-size: 0.8em; color: var(--muted); text-transform: uppercase; }
  .score-item .value { font-size: 1.8em; font-weight: bold; margin-top: 2px; }
  .score-item .value.good { color: var(--good-fg); }
  .score-item .value.mid { color: var(--mid-fg); }
  .score-item .value.low { color: var(--low-fg); }

  /* Word comparison table — all em-based */
  .compare-table { width: 100%; border-collapse: collapse; font-size: 1em; }
  .compare-table th { text-align: left; padding: 4px 6px; color: var(--muted); border-bottom: 1px solid var(--border); font-weight: 500; font-size: 0.9em; }
  .compare-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
  .compare-table tr:hover { background: var(--hover-row); }
  .compare-table .ref-word { color: var(--text); font-weight: 600; }
  .compare-table .learner-word { font-weight: 600; }
  .compare-table .learner-word.good { color: var(--good-fg); }
  .compare-table .learner-word.mid { color: var(--mid-fg); }
  .compare-table .learner-word.low { color: var(--low-fg); }
  .compare-table .score-val { font-weight: 600; }
  .compare-table .score-val.good { color: var(--good-fg); }
  .compare-table .score-val.mid { color: var(--mid-fg); }
  .compare-table .score-val.low { color: var(--low-fg); }
  .compare-table .score-bar { display: inline-block; height: 5px; border-radius: 3px; vertical-align: middle; margin-right: 4px; }
  .compare-table .phonemes { font-size: 0.9em; color: var(--muted); font-family: monospace; }
  .compare-table .phoneme { display: inline-block; padding: 1px 3px; margin: 0.5px; border-radius: 2px; font-size: 1em; }
  .compare-table .phoneme.good { background: var(--good-bg); color: var(--good-fg); }
  .compare-table .phoneme.mid { background: var(--mid-bg); color: var(--mid-fg); }
  .compare-table .phoneme.low { background: var(--low-bg); color: var(--low-fg); }
  .match-icon { font-size: 1em; }
  .match-icon.match { color: var(--good-fg); }
  .match-icon.mismatch { color: var(--low-fg); }
  .match-icon.missing { color: var(--muted); }
  .error-tag { font-size: 0.8em; padding: 1px 4px; border-radius: 3px; margin-left: 3px; background: var(--error-bg); color: var(--error-fg); }

  /* History cards */
  .history-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; cursor: pointer; transition: border-color 0.2s; }
  .history-card:hover { border-color: var(--highlight); }
  .history-card .hc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .history-card .hc-text { font-weight: 600; font-size: 0.95em; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .history-card .hc-date { font-size: 0.78em; color: var(--muted); white-space: nowrap; }
  .history-card .hc-scores { display: flex; gap: 8px; margin-top: 6px; font-size: 0.82em; }
  .history-card .hc-score { padding: 2px 8px; border-radius: 4px; font-weight: 600; }
  .history-card .hc-score.good { background: var(--good-bg); color: var(--good-fg); }
  .history-card .hc-score.mid { background: var(--mid-bg); color: var(--mid-fg); }
  .history-card .hc-score.low { background: var(--low-bg); color: var(--low-fg); }
  .history-card .hc-score.none { background: var(--bg); color: var(--muted); }
  .history-card .hc-attempts { font-size: 0.78em; color: var(--muted); margin-top: 4px; }
  .history-card .hc-check { flex-shrink: 0; width: 18px; height: 18px; cursor: pointer; accent-color: var(--highlight); }
  .history-card .hc-tag { font-size: 0.72em; padding: 1px 6px; border-radius: 3px; background: rgba(79,158,255,0.12); color: #4f9eff; margin-left: 4px; }
  .history-card .hc-tag.title { background: rgba(62,207,142,0.12); color: #3ecf8e; }
  .tag-filter-btn { padding: 4px 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg); color: var(--muted); font-size: 0.82em; cursor: pointer; transition: all 0.15s; }
  .tag-filter-btn:hover { border-color: var(--highlight); color: var(--text); }
  .tag-filter-btn.active { border-color: var(--highlight); background: rgba(233,69,96,0.1); color: var(--highlight); font-weight: 600; }

  /* Notion-style tag editor */
  .tag-editor { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-height: 28px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--input-bg); cursor: text; transition: border-color 0.15s; }
  .tag-editor:focus-within { border-color: var(--highlight); }
  .tag-pill { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 10px; font-size: 0.78em; font-weight: 500; background: rgba(79,158,255,0.12); color: #4f9eff; white-space: nowrap; user-select: none; transition: background 0.1s; }
  .tag-pill:nth-child(5n+2) { background: rgba(62,207,142,0.12); color: #3ecf8e; }
  .tag-pill:nth-child(5n+3) { background: rgba(255,193,7,0.12); color: #e6ac00; }
  .tag-pill:nth-child(5n+4) { background: rgba(187,134,252,0.12); color: #bb86fc; }
  .tag-pill:nth-child(5n+5) { background: rgba(255,107,74,0.12); color: #ff6b4a; }
  .tag-pill .tag-x { cursor: pointer; font-size: 1.1em; line-height: 1; opacity: 0.5; margin-left: 1px; }
  .tag-pill .tag-x:hover { opacity: 1; }
  .tag-input { border: none; outline: none; background: transparent; color: var(--text); font-size: 0.82em; min-width: 60px; flex: 1; padding: 2px 0; }
  .tag-input::placeholder { color: var(--muted); opacity: 0.6; }
  .tag-suggest { position: absolute; top: 100%; left: 0; right: 0; z-index: 10; background: var(--card); border: 1px solid var(--border); border-radius: 6px; margin-top: 2px; max-height: 120px; overflow-y: auto; display: none; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
  .tag-suggest.open { display: block; }
  .tag-suggest-item { padding: 5px 10px; font-size: 0.82em; cursor: pointer; color: var(--text); }
  .tag-suggest-item:hover, .tag-suggest-item.active { background: rgba(233,69,96,0.08); }
  .tag-suggest-item .tag-new { color: var(--muted); font-style: italic; }
  .tag-picker { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
  .tag-pick { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.72em; font-weight: 500; cursor: pointer; transition: opacity 0.12s, transform 0.1s; user-select: none; opacity: 0.55; }
  .tag-pick:hover { opacity: 1; transform: scale(1.05); }
  .tag-pick.used { opacity: 0.25; pointer-events: none; text-decoration: line-through; }
  .tag-readonly { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.75em; font-weight: 500; opacity: 0.7; }
  .tag-readonly:nth-child(5n+1) { background: rgba(79,158,255,0.10); color: #4f9eff; }
  .tag-readonly:nth-child(5n+2) { background: rgba(62,207,142,0.10); color: #3ecf8e; }
  .tag-readonly:nth-child(5n+3) { background: rgba(255,193,7,0.10); color: #e6ac00; }
  .tag-readonly:nth-child(5n+4) { background: rgba(187,134,252,0.10); color: #bb86fc; }
  .tag-readonly:nth-child(5n+5) { background: rgba(255,107,74,0.10); color: #ff6b4a; }
  .tag-pick:nth-child(5n+1) { background: rgba(79,158,255,0.12); color: #4f9eff; }
  .tag-pick:nth-child(5n+2) { background: rgba(62,207,142,0.12); color: #3ecf8e; }
  .tag-pick:nth-child(5n+3) { background: rgba(255,193,7,0.12); color: #e6ac00; }
  .tag-pick:nth-child(5n+4) { background: rgba(187,134,252,0.12); color: #bb86fc; }
  .tag-pick:nth-child(5n+5) { background: rgba(255,107,74,0.12); color: #ff6b4a; }

  /* Phonological rules */
  .rule-list { list-style: none; padding: 0; margin: 0; }
  .rule-item { display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 0.9em; line-height: 1.45; }
  .rule-item:last-child { border-bottom: none; }
  .rule-badge { flex-shrink: 0; font-size: 0.72em; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap; }
  .rule-badge.liaison { background: rgba(79,158,255,0.15); color: #4f9eff; }
  .rule-badge.elision { background: rgba(255,107,74,0.15); color: #ff6b4a; }
  .rule-badge.weak { background: rgba(255,193,7,0.15); color: #ffc107; }
  .rule-badge.flap { background: rgba(62,207,142,0.15); color: #3ecf8e; }
  .rule-badge.assimilation { background: rgba(187,134,252,0.15); color: #bb86fc; }
  .rule-desc { color: var(--text); }
  .rule-words { font-weight: 600; color: var(--highlight); }

  /* Explanation */
  .explanation-box { font-size: 1em; line-height: 1.55; white-space: pre-wrap; background: var(--bg); border-radius: 6px; padding: 10px; margin-top: 8px; max-height: 300px; overflow-y: auto; }

  /* Status messages */
  .status-msg { font-size: 0.9em; color: var(--muted); margin-top: 4px; }
  .status-msg.error { color: var(--low-fg); }

  /* Placeholder state for empty panels */
  .placeholder { color: var(--muted); font-size: 1em; text-align: center; padding: 40px 16px; }

  .hidden { display: none !important; }

  /* Drop zone */
  .drop-zone { border: 2px dashed var(--border); border-radius: 8px; padding: 24px 12px; text-align: center;
    cursor: pointer; position: relative; background: var(--bg); transition: border-color 0.2s, background 0.2s; }
  .drop-zone:hover, .drop-zone.over { border-color: var(--highlight); background: rgba(233,69,96,0.05); }
  .drop-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
  .dz-icon { font-size: 2em; margin-bottom: 6px; }
  .dz-text { font-size: 1em; font-weight: 600; }
  .dz-hint { font-size: 0.8em; color: var(--muted); margin-top: 4px; }

  /* Title library cards */
  .title-card { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 4px; cursor: pointer; transition: all 0.12s; font-size: 0.85em; }
  .title-card:hover { border-color: var(--highlight); background: rgba(233,69,96,0.03); }
  .title-card.active { border-color: var(--highlight); background: rgba(233,69,96,0.08); }
  .title-card .tc-icon { font-size: 1.1em; flex-shrink: 0; }
  .title-card .tc-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .title-card .tc-badges { display: flex; gap: 3px; flex-shrink: 0; }
  .title-card .tc-badge { font-size: 0.7em; padding: 1px 5px; border-radius: 3px; font-weight: 500; }
  .title-card .tc-badge.video { background: rgba(79,158,255,0.15); color: #4f9eff; }
  .title-card .tc-badge.srt { background: rgba(62,207,142,0.15); color: #3ecf8e; }
  .title-card .tc-badge.study { background: rgba(255,193,7,0.15); color: #ca8a04; }
  .title-card .tc-size { font-size: 0.75em; color: var(--muted); white-space: nowrap; }
  .dz-file-info { font-size: 0.85em; color: var(--text); margin-top: 8px; padding: 6px 10px; background: var(--bg); border-radius: 5px; border: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
  .dz-file-info .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Video preview (left panel) */
  .video-preview { margin-top: 8px; border-radius: 6px; overflow: hidden; background: #000; border: 1px solid var(--border); }
  .video-preview video { width: 100%; display: block; border-radius: 6px; }
  .video-preview.hidden { display: none; }

  /* Preview waveform (left panel) */
  .preview-wave-wrap { position: relative; margin-top: 6px; border-radius: 6px; overflow-x: auto; overflow-y: hidden; background: var(--bg); border: 1px solid var(--border); }
  .preview-controls { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 0.85em; }
  .preview-controls .play-btn { background: var(--accent); color: white; border: none; border-radius: 50%; width: 26px; height: 26px; cursor: pointer; font-size: 0.9em; display: flex; align-items: center; justify-content: center; }
  .preview-controls .play-btn:hover { opacity: 0.85; }
  .zoom-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 0.8em; color: var(--muted); }
  .zoom-slider { -webkit-appearance: none; appearance: none; flex: 1; height: 4px; border-radius: 2px; background: var(--border); outline: none; cursor: pointer; }
  .zoom-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: var(--highlight); cursor: pointer; }
  .ab-time-row { display: flex; gap: 6px; align-items: end; margin-top: 6px; }
  .ab-badge { font-size: 0.8em; font-weight: 700; padding: 2px 6px; border-radius: 4px; }
  .ab-badge.a { background: rgba(79,158,255,0.2); color: #4f9eff; }
  .ab-badge.b { background: rgba(255,107,74,0.2); color: #ff6b4a; }

  /* Audio switcher */
  .audio-switcher { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
  .audio-sw-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 5px 8px;
    border: 1px solid var(--border); border-radius: 5px; background: none; color: var(--muted);
    font-size: 0.82em; cursor: pointer; transition: all 0.15s; }
  .audio-sw-btn:hover { border-color: var(--muted); color: var(--text); }
  .audio-sw-btn.active { border-color: var(--highlight); color: var(--highlight); background: rgba(233,69,96,0.08); }
  .audio-sw-btn .sw-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border); }
  .audio-sw-btn.active .sw-dot { background: var(--highlight); box-shadow: 0 0 5px var(--highlight); }
  .audio-sw-btn .sw-play { font-size: 0.9em; }
  .rewind-btn { background: none; border: 1px solid var(--border); border-radius: 5px; padding: 5px 8px;
    color: var(--muted); cursor: pointer; font-size: 0.9em; transition: all 0.15s; }
  .rewind-btn:hover { border-color: var(--muted); color: var(--text); }
  .rewind-btn.active { border-color: var(--highlight); color: var(--highlight); background: rgba(233,69,96,0.08); }
  .vol-sync-btn { background: none; border: 1px solid var(--border); border-radius: 5px; padding: 5px 8px;
    font-size: 0.82em; color: var(--muted); cursor: pointer; white-space: nowrap; }
  .vol-sync-btn:hover { border-color: var(--muted); color: var(--text); }
  .vol-sync-btn.synced { border-color: #2ecc71; color: #2ecc71; }
  .vol-mixer-btn { background: none; border: none; font-size: 0.9em; color: var(--muted); cursor: pointer; padding: 4px; }
  .vol-mixer-btn:hover { color: var(--text); }
  .vol-mixer { display: none; padding: 6px 10px; margin-bottom: 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); font-size: 0.8em; }
  .vol-mixer.open { display: block; }
  .vol-mixer-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
  .vol-mixer-row label { width: 60px; color: var(--muted); }
  .vol-mixer-row input[type=range] { flex: 1; height: 4px; -webkit-appearance: none; appearance: none; background: var(--border); border-radius: 2px; outline: none; cursor: pointer; }
  .vol-mixer-row input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: var(--highlight); cursor: pointer; }
  .vol-mixer-row .vol-db { width: 45px; text-align: right; font-family: monospace; color: var(--muted); }

  /* Selection highlight overlay */
  .select-overlay { position: absolute; top: 0; height: 100%; pointer-events: auto; z-index: 4; border-radius: 2px; cursor: grab; }
  .select-overlay:active { cursor: grabbing; }
  .select-handle { position: absolute; top: 0; width: 6px; height: 100%; cursor: ew-resize; z-index: 5; }
  .select-handle:hover { background: rgba(255,255,255,0.3); }
  .select-handle.left { left: 0; }
  .select-handle.right { right: 0; }

  /* F0 canvas overlay */
  .f0-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
  .wave-expand-btn { position: absolute; top: 2px; right: 6px; z-index: 4; background: none; border: 1px solid var(--border); border-radius: 3px; color: var(--muted); font-size: 0.8em; padding: 0 4px; cursor: pointer; line-height: 1.4; min-width: 0; }
  .wave-expand-btn:hover { border-color: var(--highlight); color: var(--text); }

  /* Waveform */
  .waveform-container { position: relative; margin-top: 6px; border-radius: 6px; overflow: hidden; background: var(--bg); }
  .waveform-label { position: absolute; top: 2px; left: 6px; font-size: 0.7em; color: var(--muted); z-index: 2; pointer-events: none; }
  .wave-region-label { font-size: 0.65em; color: var(--text); padding: 1px 3px; opacity: 0.8; }
  .speed-control { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 0.8em; color: var(--muted); }
  .speed-btn { background: none; border: 1px solid var(--border); border-radius: 3px; padding: 1px 6px; font-size: 0.85em; color: var(--muted); cursor: pointer; min-width: 0; font-weight: 400; }
  .speed-btn:hover { border-color: var(--highlight); color: var(--text); }
  .speed-btn.active { border-color: var(--highlight); color: var(--highlight); font-weight: 600; }

  /* Header toolbar */
  .toolbar { display: flex; align-items: center; gap: 12px; }
  .toolbar-group { display: flex; align-items: center; gap: 4px; font-size: 0.72rem; color: var(--muted); }
  .toolbar-group label { display: inline; font-size: 0.7rem; margin: 0; }
  .font-size-input { width: 48px; padding: 2px 4px; font-size: 0.72rem; border: 1px solid var(--border); border-radius: 3px; background: var(--input-bg); color: var(--text); text-align: center; }
  .theme-btn { background: none; border: 1px solid var(--border); border-radius: 4px; padding: 3px 8px; font-size: 0.75rem; color: var(--muted); cursor: pointer; transition: all 0.15s; }
  .theme-btn:hover { border-color: var(--highlight); color: var(--text); }
  .toolbar-sep { width: 1px; height: 16px; background: var(--border); }

  /* Main tabs */
  .main-tabs { display: flex; border-bottom: 2px solid var(--border); padding: 0 20px; background: var(--card); }
  .main-tab { padding: 10px 24px; cursor: pointer; font-size: 0.9rem; font-weight: 600; color: var(--muted);
    border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s; user-select: none; }
  .main-tab:hover { color: var(--text); }
  .main-tab.active { color: var(--highlight); border-bottom-color: var(--highlight); }
  .tab-content { display: none; height: calc(100vh - 88px); overflow: hidden; }
  #tabContentHistory { overflow-y: auto; }
  .tab-content.active { display: block; }

  /* Tab 1 (Setup): two-column layout */
  .setup-layout { display: flex; width: 100%; height: 100%; }
  .setup-left { width: 320px; flex-shrink: 0; padding: 16px; overflow-y: auto; font-size: 13px; }
  .setup-right { flex: 1; padding: 16px; overflow-y: auto; font-size: 13px; }
  .setup-left h2, .setup-right h2 { font-size: 0.85em; color: var(--highlight); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 1px; font-weight: 500; }

  /* SRT drop zone */
  .srt-drop-zone { border: 2px dashed var(--border); border-radius: 8px; padding: 16px 12px; text-align: center;
    cursor: pointer; position: relative; background: var(--bg); transition: border-color 0.2s; margin-bottom: 12px; }
  .srt-drop-zone:hover, .srt-drop-zone.over { border-color: var(--highlight); background: rgba(233,69,96,0.05); }
  .srt-drop-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
  .srt-file-info { font-size: 0.85em; color: var(--text); margin-bottom: 8px; padding: 6px 10px; background: var(--bg); border-radius: 5px; border: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
  .srt-entry-count { font-size: 0.8em; color: var(--muted); }

  /* SRT Toolbar */
  .srt-toolbar { display: none; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-bottom: 8px; padding: 7px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-size: 0.8em; }
  .srt-toolbar.visible { display: flex; }
  .srt-tg { display: flex; align-items: center; gap: 5px; }
  .srt-tg label { font-size: 0.78em; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; margin: 0; }
  .srt-more-menu { display: none; position: absolute; right: 0; top: 100%; margin-top: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); z-index: 20; min-width: 120px; }
  .srt-more-menu.open { display: block; }
  .srt-more-item { padding: 6px 12px; font-size: 0.82em; cursor: pointer; color: var(--text); white-space: nowrap; }
  .srt-more-item:hover { background: rgba(233,69,96,0.08); }
  .srt-sep { width: 1px; height: 18px; background: var(--border); }
  .srt-btn { display: inline-flex; align-items: center; justify-content: center; height: 26px; min-width: 26px; padding: 0 7px; border: 1px solid var(--border); border-radius: 4px; background: var(--card); color: var(--text); font-size: 0.82em; cursor: pointer; transition: all .12s; user-select: none; white-space: nowrap; }
  .srt-btn:hover { background: var(--hover-row); border-color: var(--muted); }
  .srt-btn.primary { background: var(--highlight); color: #fff; border-color: var(--highlight); }
  .srt-btn.primary:hover { opacity: .9; }
  .srt-fsd { font-family: monospace; font-size: 0.82em; min-width: 22px; text-align: center; }

  /* SRT Marker Palette */
  .srt-mp { display: flex; gap: 3px; align-items: center; }
  .srt-ms { width: 18px; height: 18px; border-radius: 3px; border: 2px solid transparent; cursor: pointer; transition: all .12s; }
  .srt-ms:hover { transform: scale(1.15); }
  .srt-ms.active { border-color: var(--text); box-shadow: 0 0 0 1px rgba(128,128,128,.15); }
  .srt-ms.eraser { background: var(--card) !important; border: 2px dashed var(--border); display: flex; align-items: center; justify-content: center; font-size: 10px; }
  .srt-ms.eraser.active { border-color: var(--text); border-style: solid; }

  /* SRT Search Bar */
  .srt-search-bar { display: none; gap: 6px; align-items: center; margin-bottom: 8px; padding: 6px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; flex-wrap: wrap; }
  .srt-search-bar.visible { display: flex; }
  .srt-search-input { flex: 1; min-width: 100px; height: 26px; padding: 0 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 0.82em; outline: none; background: var(--input-bg); color: var(--text); margin-bottom: 0; }
  .srt-search-input:focus { border-color: var(--highlight); }
  .srt-filter-chips { display: flex; gap: 3px; flex-wrap: wrap; align-items: center; }
  .srt-chip { display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px; border-radius: 4px; font-size: 0.75em; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--card); transition: all .12s; user-select: none; }
  .srt-chip:hover { background: var(--hover-row); }
  .srt-chip.active { border-color: var(--highlight); background: rgba(233,69,96,0.08); }
  .srt-chip .srt-dot { width: 8px; height: 8px; border-radius: 2px; }
  .srt-chip-clear { font-size: 0.75em; color: var(--highlight); cursor: pointer; white-space: nowrap; }
  .srt-chip-clear:hover { text-decoration: underline; }
  .srt-del { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 0.85em; padding: 2px 4px; border-radius: 3px; opacity: 0.4; transition: all .12s; }
  .srt-del:hover { opacity: 1; color: #ef4444; background: rgba(239,68,68,0.1); }
  .srt-table th.srt-sortable { cursor: pointer; }
  .srt-table th.srt-sortable:hover { color: var(--text); }
  .srt-result-count { font-size: 0.75em; color: var(--muted); white-space: nowrap; margin-left: auto; }

  /* SRT Viewer table */
  .srt-table-wrap { overflow: auto; max-height: calc(100vh - 260px); border: 1px solid var(--border); border-radius: 6px; background: var(--card); }
  .srt-table { width: 100%; border-collapse: collapse; font-size: 0.85em; table-layout: fixed; }
  .srt-table thead th { position: sticky; top: 0; text-align: left; padding: 7px 10px; font-size: 0.8em; font-weight: 600; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; z-index: 1; overflow: hidden; text-overflow: ellipsis; }
  .srt-crh { position: absolute; right: 0; top: 0; bottom: 0; width: 5px; cursor: col-resize; background: transparent; z-index: 2; transition: background .12s; }
  .srt-crh:hover, .srt-crh.dragging { background: var(--highlight); opacity: .35; }
  .srt-table td { padding: 5px 10px; border-bottom: 1px solid var(--border); vertical-align: top; line-height: 1.5; overflow: hidden; text-overflow: ellipsis; }
  .srt-table tbody tr:last-child td { border-bottom: none; }
  .srt-table tr { cursor: pointer; transition: background 0.1s; }
  .srt-table tr:hover { background: var(--hover-row); }
  .srt-table tr.srt-selected { background: rgba(233,69,96,0.12); }
  .srt-table tr.srt-hidden { display: none; }
  .srt-table .srt-num { font-family: monospace; color: var(--muted); text-align: right; }
  .srt-table .srt-time { font-family: monospace; white-space: nowrap; }
  .srt-table .srt-dur { font-family: monospace; white-space: nowrap; text-align: right; }
  .srt-table .srt-text { word-break: break-word; cursor: text; }
  .srt-table .srt-tags { overflow: visible; }

  /* SRT Notion-like Tags */
  .srt-tc { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; min-height: 22px; }
  .srt-tb { display: inline-flex; align-items: center; gap: 2px; padding: 1px 7px; border-radius: 4px; font-size: 0.78em; font-weight: 500; white-space: nowrap; cursor: default; transition: background .1s; }
  .srt-tb .srt-tx { cursor: pointer; opacity: 0; margin-left: 1px; font-size: 0.9em; line-height: 1; transition: opacity .1s; }
  .srt-tb:hover .srt-tx { opacity: .7; } .srt-tb .srt-tx:hover { opacity: 1; }
  .srt-tb.tc-gray { background: rgba(150,150,150,.15); color: var(--muted); }
  .srt-tb.tc-red { background: rgba(239,68,68,.15); color: #ef4444; }
  .srt-tb.tc-orange { background: rgba(249,115,22,.15); color: #f97316; }
  .srt-tb.tc-yellow { background: rgba(234,179,8,.15); color: #ca8a04; }
  .srt-tb.tc-green { background: rgba(34,197,94,.15); color: #22c55e; }
  .srt-tb.tc-blue { background: rgba(59,130,246,.15); color: #3b82f6; }
  .srt-tb.tc-purple { background: rgba(139,92,246,.15); color: #8b5cf6; }
  .srt-tb.tc-pink { background: rgba(236,72,153,.15); color: #ec4899; }
  .srt-tag-plus { width: 18px; height: 18px; border-radius: 3px; border: none; background: transparent; cursor: pointer; font-size: 13px; color: var(--muted); display: flex; align-items: center; justify-content: center; transition: color .12s; flex-shrink: 0; padding: 0; min-height: 0; }
  .srt-tag-plus:hover { color: var(--highlight); }

  /* SRT Tag Dropdown */
  .srt-tag-dd { position: absolute; z-index: 100; background: var(--card); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.15); max-height: 180px; overflow-y: auto; min-width: 140px; padding: 4px 0; }
  .srt-tag-dd .srt-dd-item { padding: 4px 10px; font-size: 0.8em; cursor: pointer; display: flex; align-items: center; gap: 5px; }
  .srt-tag-dd .srt-dd-item:hover, .srt-tag-dd .srt-dd-item.sel { background: var(--hover-row); }
  .srt-tag-dd .srt-dd-dot { width: 8px; height: 8px; border-radius: 2px; }
  .srt-tag-dd .srt-dd-new { padding: 4px 10px; font-size: 0.75em; color: var(--muted); cursor: pointer; }
  .srt-tag-dd .srt-dd-new:hover { background: var(--hover-row); color: var(--highlight); }
  .srt-tag-dd .srt-dd-colors { display: flex; gap: 3px; padding: 5px 10px; border-top: 1px solid var(--border); margin-top: 2px; }
  .srt-tag-dd .srt-dd-cs { width: 14px; height: 14px; border-radius: 3px; cursor: pointer; border: 2px solid transparent; transition: all .1s; }
  .srt-tag-dd .srt-dd-cs:hover { transform: scale(1.2); }
  .srt-tag-dd .srt-dd-cs.active { border-color: var(--text); }
  .srt-dd-input { width: 100%; height: 24px; padding: 0 6px; border: 1px solid var(--border); border-radius: 3px; font-size: 0.8em; outline: none; background: var(--input-bg); color: var(--text); margin-bottom: 0; }
  .srt-dd-input:focus { border-color: var(--highlight); }

  /* SRT Marker highlights */
  .srt-table mark[data-color="yellow"] { background: rgba(254,240,138,.6); border-radius: 2px; padding: 0 1px; }
  .srt-table mark[data-color="green"] { background: rgba(187,247,208,.6); border-radius: 2px; padding: 0 1px; }
  .srt-table mark[data-color="blue"] { background: rgba(191,219,254,.6); border-radius: 2px; padding: 0 1px; }
  .srt-table mark[data-color="pink"] { background: rgba(251,207,232,.6); border-radius: 2px; padding: 0 1px; }
  .srt-table mark[data-color="orange"] { background: rgba(254,215,170,.6); border-radius: 2px; padding: 0 1px; }
  .srt-hint { font-size: 0.72em; color: var(--muted); white-space: nowrap; margin-left: auto; }

  /* Hotkey settings modal */
  .hk-gear { background: none; border: 1px solid var(--border); border-radius: 4px; padding: 3px 8px; font-size: 0.8rem; color: var(--muted); cursor: pointer; transition: all 0.15s; }
  .hk-gear:hover { border-color: var(--highlight); color: var(--text); }
  .hk-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 500; display: flex; align-items: center; justify-content: center; }
  .hk-modal { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 20px 24px; min-width: 380px; max-width: 480px; max-height: 80vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
  .hk-modal h3 { font-size: 0.9rem; margin-bottom: 14px; color: var(--highlight); text-transform: uppercase; letter-spacing: 0.5px; }
  .hk-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
  .hk-row:last-child { border-bottom: none; }
  .hk-label { flex: 1; font-size: 0.85em; color: var(--text); }
  .hk-key { width: 80px; height: 28px; text-align: center; border: 1px solid var(--border); border-radius: 5px; background: var(--bg); color: var(--text); font-family: monospace; font-size: 0.85em; font-weight: 600; cursor: pointer; transition: border-color 0.15s; }
  .hk-key:focus { border-color: var(--highlight); outline: none; background: rgba(233,69,96,0.05); }
  .hk-key.capturing { border-color: var(--highlight); animation: hk-pulse 1s infinite; }
  @keyframes hk-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(233,69,96,0.3); } 50% { box-shadow: 0 0 0 4px rgba(233,69,96,0.1); } }
  .hk-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
  .hk-footer button { padding: 6px 16px; border-radius: 5px; font-size: 0.85em; cursor: pointer; }
  .hk-reset { background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
  .hk-reset:hover { border-color: var(--muted); color: var(--text); }
  .hk-close { background: var(--highlight); border: 1px solid var(--highlight); color: #fff; }
  .hk-close:hover { opacity: 0.9; }

  /* Tab 2 (Practice): center + right side by side */
  .practice-layout { display: flex; width: 100%; height: 100%; }

  /* ─── Responsive: Mobile ─── */
  @media (max-width: 768px) {
    body { overflow: auto; }

    /* Header */
    .header { padding: 8px 12px; flex-wrap: wrap; gap: 6px; }
    .header h1 { font-size: 0.9rem; width: 100%; }
    .toolbar { flex-wrap: wrap; gap: 6px; }
    .toolbar-group { display: none; } /* Hide font size controls on mobile */
    .toolbar-sep { display: none; }

    /* Tabs */
    .main-tabs { padding: 0 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .main-tab { padding: 8px 14px; font-size: 0.82rem; white-space: nowrap; }
    .tab-content { height: auto; min-height: calc(100vh - 80px); overflow-y: auto; }

    /* Setup: 2-col → 1-col stack */
    .setup-layout { flex-direction: column; height: auto; }
    .setup-left { width: 100%; flex-shrink: 1; max-height: none; }
    .setup-right { width: 100%; border-top: 1px solid var(--border); }
    .srt-table-wrap { max-height: 50vh; }

    /* Practice: side-by-side → stack */
    .practice-layout { flex-direction: column; height: auto; }
    .practice-layout > .panel { width: 100% !important; flex: none; }
    .resize-handle { display: none; }

    /* Panels */
    .panel { padding: 12px; }
    .panel h2 { font-size: 0.8em; }

    /* Buttons: touch-friendly size */
    button { min-height: 36px; }
    .btn-rec { min-width: 70px; min-height: 40px; font-size: 1em; }
    .speed-btn { padding: 4px 10px; min-height: 30px; }

    /* Score grid: 5 cols → wrap */
    .score-grid { grid-template-columns: repeat(3, 1fr); }

    /* Compare table: tighter */
    .compare-table th, .compare-table td { padding: 3px 4px; font-size: 0.88em; }

    /* History cards */
    .history-card { padding: 10px 12px; }
    .history-card .hc-scores { flex-wrap: wrap; }

    /* Drop zone */
    .drop-zone { padding: 16px 10px; }
    .dz-icon { font-size: 1.5em; }

    /* Video preview */
    .video-preview video { max-height: 200px; }

    /* Waveform: slightly taller for touch */
    .waveform-container { min-height: 80px; }

    /* Preview controls */
    .preview-controls .play-btn { width: 36px; height: 36px; font-size: 1.1em; }

    /* AB time inputs */
    .ab-time-row { flex-wrap: wrap; }
    .ab-time-row input[type="text"] { width: 100px; }

    /* Rules list */
    .rule-item { font-size: 0.85em; }
    .rule-badge { font-size: 0.68em; }
  }

  /* Small phones */
  @media (max-width: 400px) {
    .main-tab { padding: 7px 10px; font-size: 0.78rem; }
    .score-grid { grid-template-columns: repeat(2, 1fr); }
    .header h1 { font-size: 0.8rem; }
  }
