    /* ─────────────────────────────────────────────────────────────
       ACCENT TOKENS — every accent surface in the UI derives from these.
       #dynamic-theme (settings.js) overrides the hue/sat/light numbers per
       theme; the semantic tokens below recompute live so the WHOLE UI
       recolours — active tabs, icon, focus glow, caret, primary button…
       `--primary-*` is the lead accent, `--accent2-*` its dual-tone partner.
       ───────────────────────────────────────────────────────────── */
    :root {
      --primary-hue: 252;
      --primary-sat: 85%;
      --primary-light: 68%;
      --accent2-hue: 292;
      --accent2-sat: 82%;
      --accent2-light: 66%;

      --accent:        hsl(var(--primary-hue), var(--primary-sat), var(--primary-light));
      --accent-2:      hsl(var(--accent2-hue), var(--accent2-sat), var(--accent2-light));
      --accent-bright: hsl(var(--primary-hue), var(--primary-sat), calc(var(--primary-light) + 14%));
      /* Signature dual-tone gradient used across active/primary surfaces */
      --accent-grad:   linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
    }

    /* Scoped reset to avoid breaking MathLive internals */
    #editor-window,
    #editor-window * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    html,
    body {
      background: transparent;
      margin: 0;
      padding: 0;
      font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      color: #e2e8f0;
      overflow: hidden;
      width: 100vw;
      height: 100vh;
      color-scheme: dark;
      display: flex;
      align-items: flex-end;
      justify-content: center;
      padding-bottom: 2.5vh;
      box-sizing: border-box;
      pointer-events: none;
      /* Let clicks pass to content.js overlay if not hitting panel */
    }

    body.demo-mode {
      align-items: center;
      padding-bottom: 0;
    }

    /* ─────────────────────────────────────────────────────────────
       LIGHT MODE — shared by every `mode:'light'` theme preset.
       `body.theme-light <sel>` out-specifies the dark rules below, and
       accent colours (from #dynamic-theme, often !important) stay vivid.
       The editor-window background is already light (preset bg HSL).
       ───────────────────────────────────────────────────────────── */
    body.theme-light {
      color-scheme: light;
      color: #3a4254;
    }

    /* Strong text (titles, math, inputs, headings, symbol glyphs) */
    body.theme-light #title,
    body.theme-light math-field,
    body.theme-light #mf,
    body.theme-light #latex-code,
    body.theme-light .settings-header h2,
    body.theme-light #tab-editor-title,
    body.theme-light .settings-body summary,
    body.theme-light .setting-group label,
    body.theme-light .tab-text-input,
    body.theme-light #tab-mf,
    body.theme-light .tab-symbol-chip,
    body.theme-light .pal-btn,
    body.theme-light .swatch-name { color: #1f2937 !important; }

    /* Secondary text (buttons, tabs, hints) */
    body.theme-light .header-btn,
    body.theme-light .rate-btn,
    body.theme-light .cat-tab:not(.active),
    body.theme-light .hint,
    body.theme-light .mode-label { color: #5b6678; }

    /* Elevated WHITE surfaces — clean light cards (not muddy black overlays).
       Resets the dark-mode 3D shadows/border-bottom so keys look crisp. */
    body.theme-light .pal-btn,
    body.theme-light .cat-tab:not(.active),
    body.theme-light .header-btn,
    body.theme-light .rate-btn,
    body.theme-light #mf-wrap,
    body.theme-light .tab-text-input,
    body.theme-light #tab-mf,
    body.theme-light .tab-symbol-chip,
    body.theme-light .theme-swatch,
    body.theme-light .settings-body details,
    body.theme-light kbd,
    body.theme-light .hint kbd {
      background: rgba(255, 255, 255, 0.9) !important;
      border-color: rgba(15, 23, 42, 0.1) !important;
      border-bottom-color: rgba(15, 23, 42, 0.14) !important;
      box-shadow: 0 1px 2px rgba(15, 23, 42, 0.07), 0 2px 5px rgba(15, 23, 42, 0.05) !important;
    }

    body.theme-light .pal-btn:hover,
    body.theme-light .cat-tab:not(.active):hover,
    body.theme-light .header-btn:hover,
    body.theme-light .rate-btn:hover,
    body.theme-light .theme-swatch:hover {
      background: #ffffff !important;
      border-color: rgba(15, 23, 42, 0.18) !important;
      box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12) !important;
    }

    body.theme-light .pal-btn:active {
      background: rgba(15, 23, 42, 0.05) !important;
      box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.12) !important;
    }

    /* Recessed insets (latex bar, symbol tray) */
    body.theme-light #latex-preview,
    body.theme-light .tab-symbol-list {
      background: rgba(15, 23, 42, 0.04) !important;
      border-color: rgba(15, 23, 42, 0.07) !important;
      box-shadow: none !important;
    }

    /* Glass panels → light glass */
    body.theme-light #settings-panel,
    body.theme-light #tab-panel,
    body.theme-light #history-panel,
    body.theme-light #snippets-panel,
    body.theme-light #pro-panel,
    body.theme-light #keyboard-window {
      background: rgba(255, 255, 255, 0.92) !important;
      border-color: rgba(15, 23, 42, 0.1) !important;
    }

    /* History / snippets entries in light mode */
    body.theme-light #history-panel h2,
    body.theme-light #snippets-panel h2,
    body.theme-light .entry-face { color: #1f2937 !important; }
    body.theme-light .entry-list {
      background: rgba(15, 23, 42, 0.04) !important;
      border-color: rgba(15, 23, 42, 0.07) !important;
    }
    body.theme-light .entry-row {
      background: rgba(255, 255, 255, 0.9) !important;
      border-color: rgba(15, 23, 42, 0.1) !important;
      box-shadow: 0 1px 2px rgba(15, 23, 42, 0.07) !important;
    }
    body.theme-light .entry-row:hover {
      border-color: rgba(15, 23, 42, 0.22) !important;
    }
    body.theme-light .snip-tab {
      color: #5b6678 !important;
      background: rgba(255, 255, 255, 0.9) !important;
      border-color: rgba(15, 23, 42, 0.1) !important;
    }
    body.theme-light .snip-tab.active {
      color: #1f2937 !important;
      background: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.18) !important;
      border-color: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.55) !important;
    }
    body.theme-light .snip-tab.new-tab { background: transparent !important; }

    /* Dividers */
    body.theme-light #header,
    body.theme-light .settings-header,
    body.theme-light #footer,
    body.theme-light .settings-body details[open] summary { border-color: rgba(15, 23, 42, 0.08) !important; }

    /* Unchecked toggle track */
    body.theme-light .switch .slider {
      background-color: rgba(15, 23, 42, 0.13) !important;
      border-color: rgba(15, 23, 42, 0.12) !important;
      box-shadow: none !important;
    }
    body.theme-light .switch .slider:before {
      background-color: #ffffff !important;
      box-shadow: 0 1px 3px rgba(15, 23, 42, 0.3) !important;
    }

    /* Pro / licensing bits */
    body.theme-light #rate-banner { color: #1f2937; }
    body.theme-light .license-status { color: #5b6678; }
    body.theme-light .pro-feature-line { color: #3a4254; }
    body.theme-light .pro-perks { color: #5b6678; }
    body.theme-light .swatch-lock {
      background: rgba(15, 23, 42, 0.55);
      border-color: rgba(255, 255, 255, 0.3);
    }

    /* Inline code chips (e.g. the \frac / \alpha hints) */
    body.theme-light .setting-group label code {
      background: rgba(15, 23, 42, 0.06) !important;
      color: #475569 !important;
    }

    /* Scrollbars */
    body.theme-light ::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.18) !important; }
    body.theme-light ::-webkit-scrollbar-thumb:hover { background: rgba(15, 23, 42, 0.3) !important; }

    /* ── Panel ── */
    #editor-window {
      pointer-events: auto;
      /* Catch clicks inside editor */
      width: 1000px;
      max-width: 95vw;
      height: 700px;
      max-height: 88vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      background: linear-gradient(145deg, #1a1b2e 0%, #16172b 50%, #111227 100%);
      border-radius: 20px;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
      position: relative;
      /* Animating entrance */
      animation: popIn 0.28s cubic-bezier(.34, 1.56, .64, 1) forwards;
    }

    /* Holds all window content at the design size; #dynamic-theme injects its
       width/height (= popupWidth/popupHeight) and transform: scale(zoom), so the
       whole UI scales as one piece when the window is corner-dragged. */
    #editor-scale {
      position: absolute;
      top: 0;
      left: 0;
      display: flex;
      flex-direction: column;
      transform-origin: top left;
    }

    @keyframes popIn {
      0% {
        transform: translateY(30px) scale(0.97);
        opacity: 0;
      }

      100% {
        transform: translateY(0) scale(1);
        opacity: 1;
      }
    }

    /* ── Header ── */
    #header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 24px 12px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.06);
      flex-shrink: 0;
    }

    #title {
      font-size: 16px;
      font-weight: 600;
      color: #f8fafc;
      display: flex;
      align-items: center;
      gap: 9px;
    }

    .icon {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 40px;
      height: 40px;
      border-radius: 12px;
      background: linear-gradient(135deg,
        hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.18) 0%,
        hsla(var(--accent2-hue), var(--accent2-sat), var(--accent2-light), 0.18) 100%);
      border: 1px solid hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.35);
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 10px hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.28);
    }

    .icon svg {
      width: 22px;
      height: 22px;
      fill: none;
      stroke: var(--accent-bright);
      stroke-width: 2;
      stroke-linecap: round;
      stroke-linejoin: round;
    }

    .header-btn {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 40px;
      height: 40px;
      border-radius: 12px;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%);
      border: 1px solid rgba(255, 255, 255, 0.08);
      border-bottom-color: rgba(0, 0, 0, 0.5);
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 4px rgba(0, 0, 0, 0.3);
      color: #94a3b8;
      cursor: pointer;
      transition: all 0.1s ease;
      font-size: 18px;
      line-height: 1;
    }

    .header-btn:hover {
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
      border-color: rgba(255, 255, 255, 0.3);
      color: #f8fafc;
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 8px rgba(255, 255, 255, 0.2);
      transform: translateY(-1px);
    }

    #close-btn:hover {
      background: linear-gradient(180deg, rgba(239, 68, 68, 0.15) 0%, rgba(239, 68, 68, 0.05) 100%);
      border-color: rgba(239, 68, 68, 0.3);
      color: #fca5a5;
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 8px rgba(239, 68, 68, 0.2);
    }

    .header-btn:active {
      transform: translateY(1px);
      background: rgba(0, 0, 0, 0.2);
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
      border-color: rgba(0, 0, 0, 0.5);
    }

    .rate-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      height: 40px;
      padding: 0 16px;
      border-radius: 12px;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%);
      border: 1px solid rgba(255, 255, 255, 0.08);
      border-bottom-color: rgba(0, 0, 0, 0.5);
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 4px rgba(0, 0, 0, 0.3);
      color: #94a3b8;
      font-size: 13px;
      font-weight: 500;
      text-decoration: none;
      cursor: pointer;
      transition: all 0.1s ease;
      line-height: 1;
    }

    .rate-btn:hover {
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
      border-color: rgba(255, 255, 255, 0.3);
      color: #f8fafc;
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 8px rgba(255, 255, 255, 0.2);
      transform: translateY(-1px);
    }

    .rate-btn:active {
      transform: translateY(1px);
      background: rgba(0, 0, 0, 0.2);
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
      border-color: rgba(0, 0, 0, 0.5);
    }

    /* ── Mode selector ── */
    #mode-bar {
      display: flex;
      gap: 5px;
      padding: 9px 23px 0;
      flex-shrink: 0;
    }

    #mode-selector {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 4px;
    }

    .mode-label {
      color: #64748b;
      font-family: inherit;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s ease;
    }

    .mode-label.active {
      color: var(--accent-bright);
      font-weight: 600;
      text-shadow: 0 0 8px hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.4);
    }

    .switch {
      position: relative;
      display: inline-block;
      width: 42px;
      height: 24px;
    }

    .switch input {
      opacity: 0;
      width: 0;
      height: 0;
    }

    .switch .slider {
      position: absolute;
      cursor: pointer;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: rgba(255, 255, 255, 0.08);
      border: 1px solid rgba(255, 255, 255, 0.1);
      transition: .3s;
      border-radius: 24px;
    }

    .switch .slider:before {
      position: absolute;
      content: "";
      height: 18px;
      width: 18px;
      left: 2px;
      bottom: 2px;
      background-color: #94a3b8;
      transition: .3s;
      border-radius: 50%;
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    }

    .switch input:checked+.slider {
      background-color: hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.28);
      border-color: hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.5);
    }

    .switch input:checked+.slider:before {
      transform: translateX(18px);
      background-color: var(--accent-bright);
    }

    /* ── Body ── */
    #body {
      padding: 20px 24px;
      flex: 1 1 0;
      display: flex;
      flex-direction: column;
      gap: 20px;
      overflow-y: auto;
      min-height: 0;
      /* crucial for flex overflow */
    }

    /* ── MathField wrapper ── */
    #mf-wrap {
      border-radius: 14px;
      border: 1px solid rgba(255, 255, 255, 0.08);
      background: rgba(0, 0, 0, 0.25);
      padding: 4px 16px;
      transition: border-color 0.2s ease, box-shadow 0.2s ease;
      flex-shrink: 0;
    }

    #mf-wrap:focus-within {
      border-color: hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.6);
      box-shadow:
        0 0 0 3px hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.16),
        0 4px 20px hsla(var(--accent2-hue), var(--accent2-sat), var(--accent2-light), 0.14);
    }

    /* MathField element */
    math-field,
    #mf {
      display: block;
      width: 100%;
      min-height: 92px;
      font-size: 1.55rem;
      padding: 16px 18px;
      border: none;
      border-radius: 14px;
      background: transparent;
      color: #e2e8f0;
      outline: none;
      --caret-color: var(--accent-bright);
      --selection-background-color: hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.32);
      --contains-highlight-background-color: hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.14);
      --smart-fence-color: hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.55);
      --_keyboard-zindex: 2147483645;
    }

    /* ── Categories Tab Bar ── */
    #category-tabs {
      display: flex;
      overflow-x: auto;
      gap: 16px;
      padding: 20px 24px 10px 24px;
      margin: -20px -24px 0 -24px;
      flex-shrink: 0;
    }

    #category-tabs::-webkit-scrollbar {
      height: 6px;
    }

    #category-tabs::-webkit-scrollbar-track {
      background: transparent;
    }

    #category-tabs::-webkit-scrollbar-thumb {
      background: rgba(255, 255, 255, 0.1);
      border-radius: 3px;
    }

    #category-tabs::-webkit-scrollbar-thumb:hover {
      background: rgba(255, 255, 255, 0.2);
    }

    .cat-tab {
      padding: 14px 32px;
      border-radius: 30px;
      background: rgba(255, 255, 255, 0.04);
      border: 1px solid rgba(255, 255, 255, 0.1);
      color: #94a3b8;
      font-family: inherit;
      font-size: 15px;
      font-weight: 500;
      line-height: 1.4;
      cursor: pointer;
      transition: all 0.2s ease;
      white-space: nowrap;
      user-select: none;
      flex-shrink: 0;
      box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    }

    .cat-tab:hover {
      background: rgba(255, 255, 255, 0.08);
      color: #cbd5e1;
      border-color: rgba(255, 255, 255, 0.2);
    }

    .cat-tab.active {
      background: var(--accent-grad);
      border-color: var(--accent-bright);
      color: #ffffff;
      box-shadow:
        0 0 24px hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.5),
        0 2px 10px hsla(var(--accent2-hue), var(--accent2-sat), var(--accent2-light), 0.35),
        inset 0 2px 4px rgba(255, 255, 255, 0.3);
      font-weight: 700;
      text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    }

    .cat-tab { display: inline-flex; align-items: center; gap: 8px; }

    .cat-tab .cat-tab-edit {
      opacity: 0;
      font-size: 0.85em;
      line-height: 1;
      cursor: pointer;
      transition: opacity 0.15s ease, color 0.15s ease;
      color: inherit;
    }
    .cat-tab:hover .cat-tab-edit,
    .cat-tab.active .cat-tab-edit { opacity: 0.65; }
    .cat-tab .cat-tab-edit:hover { opacity: 1; }

    /* Drag-to-reorder: tabs are click-to-select at rest (pointer), and only show
       the grabbing hand while an actual drag is in progress. */
    .cat-tab.dragging { opacity: 0.45; cursor: grabbing; }

    .new-tab-chip {
      border-style: dashed;
      border-color: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.5);
      color: hsl(var(--primary-hue, 250), var(--primary-sat, 80%), calc(var(--primary-light, 65%) + 15%));
    }
    .new-tab-chip:hover {
      background: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.12);
      border-color: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.8);
    }

    .pro-badge {
      display: inline-block;
      font-size: 9px;
      font-weight: 800;
      letter-spacing: 0.6px;
      line-height: 1;
      padding: 3px 6px;
      border-radius: 6px;
      color: #fff;
      background: var(--accent-grad);
      box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
      vertical-align: middle;
    }
    h2 .pro-badge { font-size: 10px; margin-left: 6px; }

    /* ── Palette Container ── */
    #palette-container {
      flex: 1 1 auto;
      overflow-y: auto;
      min-height: 0;
      border-radius: 16px;
      background: rgba(0, 0, 0, 0.15);
      border: 1px solid rgba(255, 255, 255, 0.04);
      padding: 16px;
    }

    #palette-container::-webkit-scrollbar {
      width: 5px;
    }

    #palette-container::-webkit-scrollbar-track {
      background: transparent;
    }

    #palette-container::-webkit-scrollbar-thumb {
      background: rgba(255, 255, 255, 0.1);
      border-radius: 3px;
    }

    #palette-container::-webkit-scrollbar-thumb:hover {
      background: rgba(255, 255, 255, 0.2);
    }

    #palette {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
      gap: 12px;
      flex-shrink: 0;
    }

    .pal-btn {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 56px;
      border-radius: 12px;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.03) 100%);
      border: 1px solid rgba(255, 255, 255, 0.12);
      border-bottom-color: rgba(0, 0, 0, 0.6);
      box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        0 2px 4px rgba(0, 0, 0, 0.3),
        0 4px 8px rgba(0, 0, 0, 0.2);
      color: #e2e8f0;
      font-family: 'KaTeX_Math', 'Times New Roman', serif;
      font-size: 22px;
      font-style: normal;
      cursor: pointer;
      transition: all 0.1s ease;
      user-select: none;
      -webkit-user-select: none;
    }

    /* MathLive/KaTeX markup inside a button forces its own text cursor and
       selectable text — make it purely decorative so the button owns the
       pointer cursor and every click. */
    .pal-btn * {
      cursor: pointer !important;
      pointer-events: none;
      user-select: none;
      -webkit-user-select: none;
    }

    .pal-btn:hover {
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.04) 100%);
      border-color: rgba(255, 255, 255, 0.15);
      border-bottom-color: rgba(0, 0, 0, 0.5);
      color: #fff;
      box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        0 3px 6px rgba(0, 0, 0, 0.5),
        0 6px 12px rgba(0, 0, 0, 0.3);
      transform: translateY(-1px);
    }

    .pal-btn:active {
      transform: translateY(1px);
      background: rgba(255, 255, 255, 0.02);
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.2);
      border-color: rgba(0, 0, 0, 0.5);
      border-top-color: rgba(0, 0, 0, 0.8);
    }

    /* ── LaTeX preview ── */
    #latex-preview {
      border-radius: 11px;
      border: 1px solid rgba(255, 255, 255, 0.06);
      background: rgba(0, 0, 0, 0.3);
      padding: 11px 16px;
      display: flex;
      align-items: flex-start;
      gap: 11px;
      min-height: 43px;
      flex-shrink: 0;
    }

    #latex-preview .label {
      font-size: 11px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--accent-bright);
      white-space: nowrap;
      padding-top: 3px;
    }

    #latex-code {
      flex: 1;
      font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', 'Menlo', monospace;
      font-size: 14px;
      color: #94a3b8;
      word-break: break-all;
      line-height: 1.5;
      user-select: all;
      -webkit-user-select: all;
    }

    /* ── Footer ── */
    #footer {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 24px;
      border-top: 1px solid rgba(255, 255, 255, 0.06);
      flex-shrink: 0;
      gap: 16px;
    }

    .hint {
      font-size: 14px;
      color: #64748b;
      line-height: 1.4;
    }

    .hint kbd {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 2px 8px;
      border-radius: 6px;
      background: rgba(255, 255, 255, 0.06);
      border: 1px solid rgba(255, 255, 255, 0.08);
      font-family: inherit;
      font-size: 12px;
      color: #94a3b8;
      margin: 0 2px;
    }

    .action-group {
      display: flex;
      gap: 16px;
      flex-shrink: 0;
    }

    .btn {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      padding: 14px 32px;
      border-radius: 14px;
      font-family: inherit;
      font-size: 16px;
      font-weight: 600;
      line-height: 1.4;
      cursor: pointer;
      transition: all 0.15s ease;
      white-space: nowrap;
      flex-shrink: 0;
      text-decoration: none; /* anchors styled as buttons (e.g. Get Pro) */
      box-sizing: border-box;
    }

    .btn.secondary {
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%);
      border: 1px solid rgba(255, 255, 255, 0.1);
      border-bottom-color: rgba(0, 0, 0, 0.4);
      color: #cbd5e1;
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    .btn.secondary:hover {
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.09) 0%, rgba(255, 255, 255, 0.04) 100%);
      color: #f8fafc;
      border-color: rgba(255, 255, 255, 0.15);
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 4px 8px rgba(0, 0, 0, 0.3);
      transform: translateY(-1px);
    }

    .btn.secondary:active {
      transform: translateY(1px);
      background: rgba(255, 255, 255, 0.02);
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
      border-color: rgba(0, 0, 0, 0.5);
    }

    .btn.primary {
      background: var(--accent-grad);
      color: #fff;
      border: 1px solid rgba(255, 255, 255, 0.15);
      border-bottom-color: rgba(0, 0, 0, 0.3);
      border-radius: 14px;
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 4px 16px hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.5);
      font-size: 17px;
      padding: 14px 40px;
    }

    .btn.primary:hover {
      background: linear-gradient(135deg, var(--accent-bright) 0%, var(--accent-2) 100%);
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 6px 20px hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.55);
      transform: translateY(-1px);
    }

    .btn.primary:active {
      transform: translateY(1px);
      box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
      border-color: rgba(0, 0, 0, 0.4);
    }

    /* ── Scrollbar (for mode selector, etc, if needed) ── */

    /* ── Loading state ── */
    #loading {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 92px;
      color: #64748b;
      font-size: 15px;
    }

    #loading.hidden {
      display: none;
    }

    /* ── Matrix Selector ── */
    #matrix-selector {
      display: none;
      position: fixed;
      background: #16172b;
      border: 1px solid rgba(255, 255, 255, 0.12);
      border-radius: 10px;
      padding: 10px;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
      z-index: 9999;
      flex-direction: column;
      gap: 8px;
    }

    #matrix-selector.visible {
      display: flex;
      pointer-events: auto;
    }

    .matrix-row {
      display: flex;
      gap: 6px;
    }

    .matrix-cell {
      width: 28px;
      height: 28px;
      border: 1px solid rgba(255, 255, 255, 0.1);
      border-radius: 5px;
      cursor: pointer;
      background: rgba(255, 255, 255, 0.03);
      transition: all 0.1s ease;
    }

    .matrix-cell.highlight {
      background: hsla(var(--primary-hue), var(--primary-sat), var(--primary-light), 0.6);
      border-color: var(--accent-2);
      box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
    }

    #matrix-label {
      text-align: center;
      font-size: 13px;
      color: #e2e8f0;
      font-weight: 600;
      margin-top: 2px;
    }

    /* ── Settings Overlay ── */
    #settings-overlay {
      position: absolute;
      inset: 0;
      z-index: 99999;
      pointer-events: none;
      /* Let clicks pass through to editor */
      display: flex;
      align-items: flex-start;
      justify-content: flex-end;
      padding: 24px;
      /* Fixed position relative to the screen */
      opacity: 0;
      transition: opacity 0.2s ease;
    }

    #settings-overlay.visible {
      opacity: 1;
    }

    #settings-overlay.visible #settings-panel {
      pointer-events: auto;
    }

    #settings-panel {
      pointer-events: none;
      /* Only catch clicks when visible */
      background: rgba(17, 18, 39, 0.85);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      width: 340px;
      max-height: 100%;
      border-radius: 16px;
      border: 1px solid rgba(255, 255, 255, 0.15);
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
      display: flex;
      flex-direction: column;
    }

    .settings-header {
      padding: 16px 24px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.06);
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-shrink: 0;
    }

    .settings-header h2 {
      font-size: 18px;
      font-weight: 600;
      color: #fff;
      margin: 0;
    }

    .settings-body {
      padding: 24px;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 16px;
      /* flex:1 + min-height:0 lets this region actually shrink and scroll within
         the capped-height panel instead of overflowing/clipping the bottom. */
      flex: 1 1 auto;
      min-height: 0;
    }

    /* Keep each settings group at its natural height so the body overflows and
       scrolls — otherwise flex shrinks the open <details> (overflow:hidden) and
       clips its content (e.g. the bottom theme swatches). */
    .settings-body > * {
      flex-shrink: 0;
    }

    .settings-body::-webkit-scrollbar {
      width: 6px;
    }

    .settings-body::-webkit-scrollbar-track {
      background: transparent;
    }

    .settings-body::-webkit-scrollbar-thumb {
      background: rgba(255, 255, 255, 0.1);
      border-radius: 3px;
    }

    .settings-body::-webkit-scrollbar-thumb:hover {
      background: rgba(255, 255, 255, 0.2);
    }

    /* ── Details / Summary Accordions ── */
    .settings-body details {
      border: 1px solid rgba(255, 255, 255, 0.08);
      border-radius: 12px;
      background: rgba(255, 255, 255, 0.02);
      overflow: hidden;
      transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .settings-body details[open] {
      border-color: hsla(var(--primary-hue, 160), var(--primary-sat, 100%), var(--primary-light, 45%), 0.4);
      background: rgba(0, 0, 0, 0.25);
      box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    }

    .settings-body summary {
      padding: 14px 18px;
      font-size: 14.5px;
      font-weight: 600;
      color: #e2e8f0;
      cursor: pointer;
      list-style: none; /* Hide default triangle */
      display: flex;
      justify-content: space-between;
      align-items: center;
      user-select: none;
      transition: background-color 0.2s ease, color 0.2s ease;
    }

    .settings-body summary::-webkit-details-marker {
      display: none; /* Hide default triangle in Safari */
    }

    .settings-body summary:hover {
      background: rgba(255, 255, 255, 0.04);
      color: #fff;
    }

    /* Custom chevron indicator */
    .settings-body summary::after {
      content: "";
      width: 7px;
      height: 7px;
      border-right: 2.5px solid #94a3b8;
      border-bottom: 2.5px solid #94a3b8;
      transform: rotate(-45deg);
      transition: transform 0.25s ease, border-color 0.25s ease;
      margin-right: 4px;
    }

    .settings-body details[open] summary::after {
      transform: rotate(45deg);
      border-color: hsl(var(--primary-hue, 160), var(--primary-sat, 100%), var(--primary-light, 45%));
    }

    .settings-body details[open] summary {
      border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    .details-content {
      padding: 18px;
      display: flex;
      flex-direction: column;
      gap: 16px;
      animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }

    @keyframes slideDown {
      from {
        opacity: 0;
        transform: translateY(-8px);
      }
      to {
        opacity: 1;
        transform: translateY(0);
      }
    }

    .setting-group {
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .setting-group label {
      display: flex;
      justify-content: space-between;
      color: #cbd5e1;
      font-size: 13.5px;
      font-weight: 500;
    }

    .setting-group input[type="range"] {
      width: 100%;
      accent-color: hsl(var(--primary-hue, 160), var(--primary-sat, 100%), var(--primary-light, 45%));
      background: rgba(255, 255, 255, 0.08);
      height: 6px;
      border-radius: 3px;
      outline: none;
      -webkit-appearance: none;
    }

    .setting-group input[type="range"]::-webkit-slider-runnable-track {
      background: rgba(255, 255, 255, 0.05);
      border-radius: 3px;
      height: 6px;
    }

    .setting-group input[type="range"]::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: hsl(var(--primary-hue, 160), var(--primary-sat, 100%), var(--primary-light, 45%));
      cursor: pointer;
      margin-top: -4px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
      transition: transform 0.1s ease;
    }

    .setting-group input[type="range"]::-webkit-slider-thumb:hover {
      transform: scale(1.2);
    }

    /* ── Theme preset picker ── */
    .preset-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
      gap: 10px;
    }

    .theme-swatch {
      display: flex;
      flex-direction: column;
      align-items: stretch;
      gap: 6px;
      padding: 6px;
      border-radius: 10px;
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(255, 255, 255, 0.02);
      cursor: pointer;
      font-family: inherit;
      transition: border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    }

    .theme-swatch:hover {
      transform: translateY(-2px);
      border-color: rgba(255, 255, 255, 0.25);
    }

    .theme-swatch.selected {
      border-color: hsl(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%));
      box-shadow: 0 0 0 1px hsl(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%)),
        0 4px 14px hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.3);
    }

    .swatch-preview {
      position: relative;
      height: 38px;
      border-radius: 7px;
      border: 1px solid rgba(255, 255, 255, 0.12);
      overflow: hidden;
      display: block;
    }

    .swatch-dot {
      position: absolute;
      left: 8px;
      bottom: 8px;
      width: 30px;
      height: 14px;
      border-radius: 8px;
      border: 1px solid rgba(255, 255, 255, 0.25);
      box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.35);
    }

    .swatch-name {
      font-size: 11px;
      font-weight: 600;
      color: #cbd5e1;
      text-align: center;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .theme-swatch.selected .swatch-name {
      color: hsl(var(--primary-hue, 250), var(--primary-sat, 80%), calc(var(--primary-light, 65%) + 18%));
    }

    .theme-swatch.locked { opacity: 0.75; }
    .theme-swatch.locked:hover { opacity: 1; }
    .swatch-lock {
      position: absolute;
      top: 4px;
      right: 4px;
      font-size: 8px;
      font-weight: 800;
      letter-spacing: 0.5px;
      line-height: 1;
      padding: 2px 4px;
      border-radius: 4px;
      color: #fff;
      background: rgba(0, 0, 0, 0.55);
      border: 1px solid rgba(255, 255, 255, 0.25);
    }

    /* ── Rate-us banner ── */
    #rate-banner {
      display: flex;
      align-items: center;
      gap: 10px;
      flex-shrink: 0;
      margin-top: 10px;
      padding: 8px 12px;
      border-radius: 10px;
      border: 1px solid hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.35);
      background: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.12);
      font-size: 13px;
      color: #e2e8f0;
    }
    .rate-banner-text { flex: 1 1 auto; }
    .rate-banner-btn {
      border: none;
      cursor: pointer;
      font-family: inherit;
      font-weight: 700;
      font-size: 12px;
      padding: 6px 12px;
      border-radius: 8px;
      color: #fff;
      background: linear-gradient(135deg,
        hsl(var(--primary-hue, 250), var(--primary-sat, 80%), calc(var(--primary-light, 65%) - 10%)),
        hsl(var(--primary-hue, 250), var(--primary-sat, 80%), calc(var(--primary-light, 65%) - 20%)));
    }
    .rate-banner-btn:hover { filter: brightness(1.12); }
    .rate-banner-close {
      border: none;
      background: transparent;
      color: inherit;
      opacity: 0.6;
      cursor: pointer;
      font-size: 13px;
      padding: 4px 6px;
      border-radius: 6px;
    }
    .rate-banner-close:hover { opacity: 1; }

    /* ── MathPaster Pro (license + upgrade modal) ── */
    .license-status {
      font-size: 13px;
      font-weight: 600;
      color: #94a3b8;
      margin-bottom: 10px;
    }
    .license-status.pro {
      color: hsl(var(--primary-hue, 250), var(--primary-sat, 80%), calc(var(--primary-light, 65%) + 15%));
    }
    .license-row {
      display: flex;
      gap: 10px;
      align-items: stretch;
      margin-bottom: 8px;
    }
    .license-row .tab-text-input { flex: 1 1 auto; min-width: 0; }
    .license-row .btn { flex-shrink: 0; }
    .license-msg.ok { color: #34d399; }
    .license-buy-link {
      display: inline-block;
      font-size: 13px;
      font-weight: 600;
      text-decoration: none;
      margin-top: 2px;
      color: hsl(var(--primary-hue, 250), var(--primary-sat, 80%), calc(var(--primary-light, 65%) + 15%));
    }
    .license-buy-link:hover { text-decoration: underline; }
    #license-deactivate-btn { margin-top: 10px; }

    #pro-overlay {
      position: absolute;
      inset: 0;
      z-index: 100001;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 24px;
      background: rgba(0, 0, 0, 0.45);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s ease;
    }
    #pro-overlay.visible { opacity: 1; pointer-events: auto; }

    #pro-panel {
      background: rgba(17, 18, 39, 0.92);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      width: 400px;
      max-width: 100%;
      max-height: 100%;
      border-radius: 16px;
      border: 1px solid rgba(255, 255, 255, 0.15);
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
      display: flex;
      flex-direction: column;
      transform: scale(0.96);
      transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    }
    #pro-overlay.visible #pro-panel { transform: scale(1); }

    .pro-feature-line {
      margin: 0 0 12px 0;
      font-size: 14px;
      color: #cbd5e1;
    }
    .pro-perks {
      margin: 0 0 16px 0;
      padding: 0 0 0 18px;
      display: flex;
      flex-direction: column;
      gap: 8px;
      font-size: 13px;
      color: #94a3b8;
    }
    .pro-perks li::marker {
      color: hsl(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%));
    }

    /* ── Custom Tab Editor Modal ── */
    #tab-overlay,
    #history-overlay,
    #snippets-overlay {
      position: absolute;
      inset: 0;
      z-index: 100000;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 24px;
      background: rgba(0, 0, 0, 0.45);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s ease;
    }
    #tab-overlay.visible,
    #history-overlay.visible,
    #snippets-overlay.visible { opacity: 1; pointer-events: auto; }

    #tab-panel,
    #history-panel,
    #snippets-panel {
      background: rgba(17, 18, 39, 0.92);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      width: 440px;
      max-width: 100%;
      max-height: 100%;
      border-radius: 16px;
      border: 1px solid rgba(255, 255, 255, 0.15);
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
      display: flex;
      flex-direction: column;
      transform: scale(0.96);
      transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    }
    #tab-overlay.visible #tab-panel,
    #history-overlay.visible #history-panel,
    #snippets-overlay.visible #snippets-panel { transform: scale(1); }

    /* ── Insert History & Snippets entry list ── */
    .entry-list {
      display: flex;
      flex-direction: column;
      gap: 8px;
      max-height: 360px;
      overflow-y: auto;
      padding: 8px;
      border-radius: 12px;
      background: rgba(0, 0, 0, 0.2);
      border: 1px solid rgba(255, 255, 255, 0.06);
    }
    .entry-empty {
      color: #6b7280;
      font-size: 13px;
      text-align: center;
      padding: 28px 8px;
    }
    .entry-row {
      position: relative;
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 10px 38px 10px 12px;
      border-radius: 10px;
      cursor: pointer;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.03) 100%);
      border: 1px solid rgba(255, 255, 255, 0.12);
      color: #fff;
      transition: border-color 0.15s ease, transform 0.1s ease;
    }
    .entry-row:hover {
      border-color: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.6);
      transform: translateY(-1px);
    }
    .entry-main { flex: 1 1 auto; min-width: 0; }
    .entry-name {
      display: block;
      font-size: 12px;
      color: #9ca3af;
      margin-bottom: 2px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .entry-face {
      font-size: 20px;
      overflow-x: hidden;
      overflow-y: visible;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .entry-meta { flex: 0 0 auto; font-size: 11px; color: #6b7280; }
    .entry-delete {
      position: absolute;
      right: 8px;
      top: 50%;
      transform: translateY(-50%);
      width: 18px;
      height: 18px;
      border-radius: 50%;
      border: none;
      background: #ef4444;
      color: #fff;
      font-size: 13px;
      line-height: 1;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
      transition: transform 0.12s ease, background 0.12s ease;
    }
    .entry-delete:hover { transform: translateY(-50%) scale(1.15); background: #dc2626; }

    /* PRO badge tucked into the snippets header button */
    .header-btn-pro { position: relative; overflow: visible; }
    .header-pro-badge {
      position: absolute;
      top: -6px;
      right: -6px;
      font-size: 7px;
      padding: 1px 4px;
      letter-spacing: 0.4px;
      pointer-events: none;
    }

    /* Snippets free-tier teaser */
    #snippets-teaser { display: flex; flex-direction: column; gap: 16px; }
    .snippets-teaser-preview {
      filter: blur(2px);
      opacity: 0.5;
      pointer-events: none;
      user-select: none;
    }
    .snippets-teaser-cta { text-align: center; }
    .snippets-teaser-cta .pro-feature-line { margin: 0 0 14px; }

    /* Snippet tabs (folders) */
    .snippet-tabs {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      margin-bottom: 12px;
    }
    .snip-tab {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 6px 12px;
      border-radius: 8px;
      font-size: 12px;
      font-family: inherit;
      cursor: pointer;
      color: #cbd5e1;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%);
      border: 1px solid rgba(255, 255, 255, 0.1);
      transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
    }
    .snip-tab:hover { border-color: rgba(255, 255, 255, 0.2); color: #fff; }
    .snip-tab.active {
      color: #fff;
      background: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.22);
      border-color: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.6);
    }
    .snip-tab-label { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .snip-tab-edit { opacity: 0.55; font-size: 11px; }
    .snip-tab-edit:hover { opacity: 1; }
    .snip-tab.new-tab {
      color: #9ca3af;
      background: transparent;
      border-style: dashed;
    }
    .snip-tab.new-tab:hover { color: #fff; border-color: rgba(255, 255, 255, 0.3); }
    .snip-tab-btn { flex: 0 0 auto; padding: 8px 14px; }

    .tab-text-input {
      width: 100%;
      box-sizing: border-box;
      padding: 11px 14px;
      border-radius: 10px;
      border: 1px solid rgba(255, 255, 255, 0.12);
      background: rgba(0, 0, 0, 0.25);
      color: #fff;
      font-family: inherit;
      font-size: 15px;
      outline: none;
      transition: border-color 0.2s ease, box-shadow 0.2s ease;
    }
    .tab-text-input::placeholder { color: #6b7280; }
    .tab-text-input:focus {
      border-color: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.6);
      box-shadow: 0 0 0 3px hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.12);
    }

    .setting-group label code {
      background: rgba(0, 0, 0, 0.35);
      padding: 1px 5px;
      border-radius: 4px;
      font-size: 0.92em;
      color: hsl(var(--primary-hue, 250), var(--primary-sat, 80%), calc(var(--primary-light, 65%) + 18%));
    }

    .tab-add-row {
      display: flex;
      gap: 10px;
      align-items: stretch;
    }
    #tab-mf {
      flex: 1 1 auto;
      min-width: 0;
      background: rgba(0, 0, 0, 0.25);
      border: 1px solid rgba(255, 255, 255, 0.12);
      border-radius: 10px;
      padding: 8px 12px;
      font-size: 20px;
      color: #fff;
      --caret-color: hsl(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%));
    }
    #tab-mf:focus-within {
      border-color: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.6);
      box-shadow: 0 0 0 3px hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.12);
    }
    #tab-add-btn { flex: 0 0 auto; padding: 8px 18px; }
    #tab-mf::part(menu-toggle),
    #tab-mf::part(virtual-keyboard-toggle) { display: none; }

    .tab-symbol-list {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      min-height: 56px;
      padding: 12px;
      border-radius: 12px;
      background: rgba(0, 0, 0, 0.2);
      border: 1px solid rgba(255, 255, 255, 0.06);
      align-content: flex-start;
    }
    .tab-symbol-empty {
      color: #6b7280;
      font-size: 13px;
      align-self: center;
      width: 100%;
      text-align: center;
    }
    .tab-symbol-chip {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      min-width: 48px;
      height: 48px;
      padding: 0 12px;
      border-radius: 10px;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.03) 100%);
      border: 1px solid rgba(255, 255, 255, 0.12);
      color: #fff;
      font-size: 20px;
    }
    .tab-symbol-face { display: inline-flex; align-items: center; }
    .tab-symbol-remove {
      position: absolute;
      top: -7px;
      right: -7px;
      width: 18px;
      height: 18px;
      border-radius: 50%;
      border: none;
      background: #ef4444;
      color: #fff;
      font-size: 13px;
      line-height: 1;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
      transition: transform 0.12s ease, background 0.12s ease;
    }
    .tab-symbol-remove:hover { transform: scale(1.15); background: #dc2626; }

    .tab-error {
      color: #f87171;
      font-size: 13px;
      min-height: 16px;
    }

    /* ── Browse-symbols picker ── */
    .symbol-browse-toggle {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }
    .symbol-browse-toggle .browse-caret {
      font-size: 11px;
      transition: transform 0.2s ease;
    }
    .symbol-browse-toggle.open .browse-caret { transform: rotate(180deg); }

    .symbol-picker {
      margin-top: 10px;
      padding: 12px;
      border-radius: 12px;
      background: rgba(0, 0, 0, 0.2);
      border: 1px solid rgba(255, 255, 255, 0.06);
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    .symbol-picker[hidden] { display: none; }
    .symbol-search { font-size: 14px; padding: 9px 12px; }

    .symbol-cat-nav {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
    }
    .symbol-cat-chip {
      padding: 4px 10px;
      border-radius: 999px;
      border: 1px solid rgba(255, 255, 255, 0.12);
      background: rgba(255, 255, 255, 0.04);
      color: #cbd5e1;
      font-size: 12px;
      font-family: inherit;
      cursor: pointer;
      white-space: nowrap;
      transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
    }
    .symbol-cat-chip:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
    .symbol-cat-chip.active {
      background: var(--accent-grad);
      border-color: var(--accent-bright);
      color: #fff;
    }

    .symbol-grid {
      max-height: 240px;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 12px;
      padding-right: 4px;
    }
    .symbol-grid::-webkit-scrollbar { width: 6px; }
    .symbol-grid::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }
    .symbol-section[hidden] { display: none; }
    .symbol-section-title {
      font-size: 10.5px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.07em;
      color: var(--accent-bright);
      margin-bottom: 6px;
    }
    .symbol-section-cells {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
      gap: 6px;
    }
    .symbol-cell {
      position: relative;
      height: 48px;
      border-radius: 9px;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.03) 100%);
      border: 1px solid rgba(255, 255, 255, 0.1);
      color: #e2e8f0;
      font-family: 'KaTeX_Math', 'Times New Roman', serif;
      font-size: 17px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      overflow: hidden;
      transition: transform 0.1s ease, border-color 0.12s ease, background 0.12s ease;
    }
    .symbol-cell[hidden] { display: none; }
    .symbol-cell:hover {
      background: rgba(255, 255, 255, 0.1);
      border-color: rgba(255, 255, 255, 0.2);
      color: #fff;
      transform: translateY(-1px);
    }
    .symbol-cell.selected {
      border-color: var(--accent-bright);
      background: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.18);
      box-shadow: inset 0 0 0 1px var(--accent-bright);
    }
    .symbol-cell.selected::after {
      content: "✓";
      position: absolute;
      top: 1px;
      right: 3px;
      font-family: system-ui, -apple-system, sans-serif;
      font-size: 10px;
      font-weight: 700;
      color: var(--accent-bright);
    }
    .symbol-noresults {
      color: #6b7280;
      font-size: 13px;
      text-align: center;
      padding: 12px 0;
    }
    .symbol-noresults[hidden] { display: none; }

    .tab-editor-actions {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      margin-top: 4px;
    }
    .tab-editor-actions #tab-delete-btn {
      color: #f87171;
      background: rgba(239, 68, 68, 0.08);
      border-color: rgba(239, 68, 68, 0.3);
    }
    .tab-editor-actions #tab-delete-btn:hover { background: rgba(239, 68, 68, 0.16); }
    .tab-editor-actions #tab-save-btn { margin-left: auto; }

    /* ── Settings: Tabs group (reset to default) ── */
    .settings-note {
      margin: 0 0 12px;
      font-size: 13px;
      line-height: 1.5;
      color: #94a3b8;
    }
    .settings-pencil {
      display: inline-block;
      padding: 0 4px;
      color: #cbd5e1;
    }
    #reset-tabs-btn[hidden], .reset-confirm[hidden] { display: none; }
    .reset-confirm {
      display: flex;
      flex-direction: column;
      gap: 10px;
      padding: 12px;
      border-radius: 12px;
      border: 1px solid rgba(239, 68, 68, 0.3);
      background: rgba(239, 68, 68, 0.08);
    }
    .reset-confirm-text { font-size: 13px; line-height: 1.5; color: #fca5a5; }
    .reset-confirm-actions { display: flex; gap: 10px; }
    .reset-confirm-actions .btn { flex: 1; padding: 10px 16px; font-size: 14px; }
    .reset-confirm-danger {
      color: #fecaca;
      background: rgba(239, 68, 68, 0.16);
      border-color: rgba(239, 68, 68, 0.45);
    }
    .reset-confirm-danger:hover {
      color: #fff;
      background: rgba(239, 68, 68, 0.28);
      border-color: rgba(239, 68, 68, 0.6);
    }

    /* ── Keyboard Window ── */
    #keyboard-window {
      position: absolute;
      pointer-events: auto;
      z-index: 20000;
      background: #16172b;
      border: 1px solid rgba(255, 255, 255, 0.12);
      border-radius: 16px;
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      width: 680px;
      height: 280px;
      /* Animating entrance */
      animation: popIn 0.28s cubic-bezier(.34, 1.56, .64, 1) forwards;
    }

    #keyboard-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 8px 16px;
      background: rgba(255, 255, 255, 0.03);
      border-bottom: 1px solid rgba(255, 255, 255, 0.06);
      cursor: grab;
      user-select: none;
      flex-shrink: 0;
    }

    #keyboard-title {
      font-size: 13px;
      font-weight: 600;
      color: #94a3b8;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .keyboard-drag-icon {
      font-size: 16px;
      color: #64748b;
      cursor: grab;
    }

    #keyboard-container {
      flex: 1;
      overflow: hidden;
      position: relative;
      width: 100%;
      height: 100%;
    }

    /* ── Keyboard Resize Handles ── */
    .kbd-resize-handle {
      position: absolute;
      width: 14px;
      height: 14px;
      z-index: 10001;
      background: transparent;
      transition: background 0.2s ease;
    }
    .kbd-resize-handle:hover {
      background: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.35);
    }
    .kbd-resize-tl { top: 0; left: 0; cursor: nwse-resize; border-top-left-radius: 16px; }
    .kbd-resize-tr { top: 0; right: 0; cursor: nesw-resize; border-top-right-radius: 16px; }
    .kbd-resize-bl { bottom: 0; left: 0; cursor: nesw-resize; border-bottom-left-radius: 16px; }
    .kbd-resize-br { bottom: 0; right: 0; cursor: nwse-resize; border-bottom-right-radius: 16px; }

    /* ── MathLive Keyboard Styling Override ── */
    mathlive-virtual-keyboard {
      display: block !important;
      position: absolute !important;
      inset: 0 !important;
      width: 100% !important;
      height: 100% !important;
      transform: none !important;
      z-index: 1 !important;
      pointer-events: auto !important;

      /* Keyboard scaling variables */
      --keycap-height: var(--kbd-keycap-height, 34px) !important;
      --keycap-gap: 3px !important;
      --keycap-font-size: calc(var(--kbd-keycap-height, 34px) * 0.426) !important;
      --keycap-small-font-size: calc(var(--kbd-keycap-height, 34px) * 0.324) !important;
      --keycap-shift-font-size: calc(var(--kbd-keycap-height, 34px) * 0.324) !important;
      --keycap-glyph-size: calc(var(--kbd-keycap-height, 34px) * 0.412) !important;
      --keyboard-background: #16172b !important;
    }

    /* Autocomplete suggestion list must float above the custom-tab modal (z-index 100000) */
    #mathlive-suggestion-popover,
    .ML__popover {
      z-index: 2147483000 !important;
    }

    #mathlive-suggestion-popover,
    .ML__keyboard,
    .MLK__container,
    .MLK__keyboard-panel,
    .MLK__plate,
    .mathfield-suggest {
      pointer-events: auto !important;
      --keycap-height: var(--kbd-keycap-height, 34px) !important;
      --keycap-gap: 3px !important;
      --keycap-font-size: calc(var(--kbd-keycap-height, 34px) * 0.426) !important;
      --keycap-small-font-size: calc(var(--kbd-keycap-height, 34px) * 0.324) !important;
      --keycap-shift-font-size: calc(var(--kbd-keycap-height, 34px) * 0.324) !important;
      --keycap-glyph-size: calc(var(--kbd-keycap-height, 34px) * 0.412) !important;
      --keyboard-background: #16172b !important;
    }

    /* ── Resize Handles ── */
    .resize-handle {
      position: absolute;
      width: 16px;
      height: 16px;
      z-index: 10000;
      background: transparent;
      transition: background 0.2s ease;
    }
    .resize-handle:hover {
      background: hsla(var(--primary-hue, 250), var(--primary-sat, 80%), var(--primary-light, 65%), 0.35);
    }
    .resize-tl {
      top: 0;
      left: 0;
      cursor: nwse-resize;
      border-top-left-radius: 20px;
    }
    .resize-tr {
      top: 0;
      right: 0;
      cursor: nesw-resize;
      border-top-right-radius: 20px;
    }
    .resize-bl {
      bottom: 0;
      left: 0;
      cursor: nesw-resize;
      border-bottom-left-radius: 20px;
    }
    .resize-br {
      bottom: 0;
      right: 0;
      cursor: nwse-resize;
      border-bottom-right-radius: 20px;
    }
