    :root {
      --bg:           #f8f9fc;
      --bg-card:      #ffffff;
      --text:         #1a1d2e;
      --text-muted:   #64748b;
      --primary:      rgb(0, 65, 170);
      --primary-soft: rgba(0, 65, 170, 0.08);
      --border:       rgba(0, 65, 170, 0.1);
      --shadow:       0 4px 24px rgba(0, 65, 170, 0.07);
      --shadow-hover: 0 12px 40px rgba(0, 65, 170, 0.14);
      --shadow-hover-btn: 0 6px 16px rgba(0, 65, 170, 0.2);
      --radius:       1rem;
      --font:         'Inter', system-ui, sans-serif;
      --font-title:   'Montserrat', 'Inter', sans-serif;
      --font-mono:    'Fira Code', 'FiraCode', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

      /* Aliases for visualizer-specific components */
      --card:          var(--bg-card);
      --primary-hover: #0056b3;
      --primary-light: var(--primary-soft);
      --primary-border: var(--border);
      --cell-stroke:   #1e293b;
      --boundary-fill: rgba(148, 163, 184, 0.2);
    }

    [data-theme="dark"] {
      --bg:           #0f1117;
      --bg-card:      #181c2a;
      --text:         #e2e8f0;
      --text-muted:   #94a3b8;
      --primary:      rgb(96, 165, 250);
      --primary-soft: rgba(96, 165, 250, 0.1);
      --border:       rgba(96, 165, 250, 0.18);
      --shadow:       0 4px 24px rgba(0, 0, 0, 0.35);
      --shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.5);
      --shadow-hover-btn: 0 6px 16px rgba(96, 165, 250, 0.25);

      /* Dark aliases */
      --card:          var(--bg-card);
      --primary-hover: #93c5fd;
      --primary-light: var(--primary-soft);
      --primary-border: var(--border);
      --cell-stroke:   #0f172a;
      --boundary-fill: rgba(51, 65, 85, 0.45);
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      font-family: var(--font);
      background-color: var(--bg);
      color: var(--text);
      line-height: 1.6;
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      transition: background-color 0.3s ease, color 0.3s ease;
    }

    /* Header Nav */
    .site-header {
      background-color: var(--bg-card);
      border-bottom: 1px solid var(--border);
      padding: 0.85rem 2rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      position: sticky;
      top: 0;
      z-index: 10;
      box-shadow: var(--shadow);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
    }

    .header-left {
      display: flex;
      align-items: center;
      gap: 1.25rem;
    }

    .back-link {
      display: inline-flex;
      align-items: center;
      gap: 0.45rem;
      font-family: var(--font);
      font-size: 0.82rem;
      font-weight: 600;
      color: var(--primary);
      padding: 0.4rem 0.85rem;
      border-radius: 999px;
      border: 1px solid var(--border);
      background-color: var(--bg-card);
      box-shadow: var(--shadow);
      text-decoration: none;
      transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    }

    .back-link:hover {
      color: var(--primary);
      border-color: var(--border);
      background-color: var(--primary-soft);
      box-shadow: var(--shadow-hover);
      text-decoration: none;
    }

    .header-title h1 {
      font-family: var(--font-title);
      font-size: 1.25rem;
      font-weight: 700;
      line-height: 1.2;
      color: var(--text);
      letter-spacing: -0.01em;
    }

    .header-title p {
      font-size: 0.82rem;
      color: var(--text-muted);
      font-weight: 400;
      margin-top: 0.15rem;
    }

    .header-right {
      display: flex;
      align-items: center;
      gap: 0.85rem;
    }

    .badge-primary {
      border-radius: 999px;
      background: var(--primary-soft);
      border: 1px solid var(--border);
      color: var(--primary);
      font-family: var(--font-mono);
      font-weight: 600;
      font-size: 0.8rem;
      padding: 0.35rem 0.85rem;
      box-shadow: var(--shadow);
      white-space: nowrap;
    }

    /* Theme Toggle Button Styling */
    .theme-btn {
      background: var(--bg-card);
      border: 1px solid var(--border);
      color: var(--primary);
      cursor: pointer;
      padding: 0;
      border-radius: 50%;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 2.35rem;
      height: 2.35rem;
      box-shadow: var(--shadow);
      transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    }

    .theme-btn:hover {
      background-color: var(--primary-soft);
      color: var(--primary);
      box-shadow: var(--shadow-hover);
    }

    .theme-btn i, .theme-btn svg {
      font-size: 1rem;
      width: 1rem;
      height: 1rem;
    }

    .theme-btn .sun-icon, .theme-btn .moon-icon { display: none; }
    [data-theme="dark"]  .theme-btn .sun-icon  { display: inline-block; }
    [data-theme="dark"]  .theme-btn .moon-icon { display: none; }
    [data-theme="light"] .theme-btn .sun-icon  { display: none; }
    [data-theme="light"] .theme-btn .moon-icon { display: inline-block; }
    :root:not([data-theme]) .theme-btn .moon-icon { display: inline-block; }

    /* Main Layout Grid */
    .main-layout {
      display: grid;
      grid-template-columns: 400px 1fr;
      gap: 2rem;
      padding: 2rem;
      flex: 1;
      width: 100%;
      max-width: 1200px;
      margin: 0 auto;
    }

    @media (max-width: 1024px) {
      .main-layout {
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
        padding: 1.5rem;
      }

      .guide-panel {
        order: 1;
        width: 100%;
      }

      .workspace-content {
        order: 2;
        width: 100%;
      }
    }

    /* Didactic Guide Sidebar */
    .guide-panel {
      display: flex;
      flex-direction: column;
      gap: 1.5rem;
      height: fit-content;
    }

    .guide-card {
      background-color: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 1.5rem;
      box-shadow: var(--shadow);
      display: flex;
      flex-direction: column;
      gap: 1.25rem;
    }

    /* Reading Perspective Switcher */
    .mode-switcher-container {
      display: flex;
      flex-direction: column;
      gap: 0.4rem;
      width: 100%;
    }

    .mode-switcher {
      display: flex;
      background-color: var(--primary-soft);
      border: 1px solid var(--border);
      border-radius: 999px;
      padding: 3px;
      gap: 3px;
    }

    .mode-btn {
      flex: 1;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 0.45rem;
      padding: 0.45rem 0.85rem;
      font-family: var(--font);
      font-size: 0.8rem;
      font-weight: 600;
      color: var(--text-muted);
      background: transparent;
      border: none;
      border-radius: 999px;
      cursor: pointer;
      transition: all 0.2s ease;
      white-space: nowrap;
    }

    .mode-btn:hover {
      color: var(--text);
    }

    .mode-btn.active {
      background-color: var(--bg-card);
      color: var(--primary);
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    }

    [data-theme="dark"] .mode-btn.active {
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    }

    /* Real-World Context Card */
    .real-world-context-card {
      background: linear-gradient(135deg, var(--primary-soft) 0%, rgba(96, 165, 250, 0.03) 100%);
      border: 1px solid var(--border);
      border-radius: 0.75rem;
      padding: 0.9rem 1.05rem;
      display: flex;
      flex-direction: column;
      gap: 0.45rem;
      transition: all 0.25s ease;
    }

    .context-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .context-badge {
      display: inline-flex;
      align-items: center;
      gap: 0.4rem;
      font-size: 0.72rem;
      font-weight: 700;
      letter-spacing: 0.04em;
      text-transform: uppercase;
      color: var(--primary);
      background-color: var(--bg-card);
      border: 1px solid var(--border);
      padding: 0.2rem 0.55rem;
      border-radius: 999px;
    }

    .context-title {
      font-family: var(--font-title);
      font-size: 0.95rem;
      font-weight: 700;
      color: var(--text);
      margin: 0;
      line-height: 1.35;
    }

    .context-summary {
      font-size: 0.84rem;
      color: var(--text-muted);
      line-height: 1.5;
      margin: 0;
    }

    /* Stepper Progress bar */
    .stepper {
      display: flex;
      justify-content: space-between;
      border-bottom: 1px solid var(--border);
      padding-bottom: 1rem;
      margin-bottom: 0.25rem;
    }

    .step-dot {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 32px;
      height: 32px;
      border-radius: 50%;
      border: 1px solid var(--border);
      font-family: var(--font-mono);
      font-size: 0.82rem;
      font-weight: 700;
      color: var(--text-muted);
      background-color: var(--bg-card);
      cursor: pointer;
      transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    }

    .step-dot:hover {
      border-color: var(--primary);
      color: var(--primary);
    }

    .step-dot.active {
      border-color: var(--primary);
      background-color: var(--primary);
      color: #ffffff;
      box-shadow: 0 0 10px rgba(0, 65, 170, 0.3);
    }

    [data-theme="dark"] .step-dot.active {
      box-shadow: 0 0 12px rgba(96, 165, 250, 0.4);
    }

    .step-dot.completed {
      border-color: var(--primary);
      background-color: var(--primary-soft);
      color: var(--primary);
    }

    /* Stepper Content */
    .step-content {
      display: flex;
      flex-direction: column;
      gap: 1rem;
    }

    .step-content h2 {
      font-family: var(--font-title);
      font-size: 1.2rem;
      font-weight: 700;
      color: var(--text);
      border-bottom: 1px solid var(--border);
      padding-bottom: 0.5rem;
      letter-spacing: -0.01em;
    }

    .step-description {
      font-size: 0.92rem;
      color: var(--text);
      line-height: 1.65;
    }
    
    .step-description p {
      margin-bottom: 0.65rem;
    }

    .step-description p:last-child {
      margin-bottom: 0;
    }

    .step-description ol,
    .step-description ul {
      margin: 0.5rem 0 0.75rem 0;
      padding-left: 1.4rem;
      display: flex;
      flex-direction: column;
      gap: 0.4rem;
    }

    .step-description ol {
      list-style-type: decimal;
    }

    .step-description ul {
      list-style-type: disc;
    }

    .step-description li {
      font-size: 0.9rem;
      line-height: 1.55;
      padding-left: 0.25rem;
    }

    /* UX Callout Boxes */
    .callout-box {
      font-size: 0.88rem;
      padding: 0.85rem 1.1rem;
      line-height: 1.6;
    }

    .callout-box p {
      margin-bottom: 0.4rem;
    }

    .callout-box p:last-child {
      margin-bottom: 0;
    }

    .callout-box ol,
    .callout-box ul {
      margin: 0.4rem 0;
      padding-left: 1.3rem;
      display: flex;
      flex-direction: column;
      gap: 0.3rem;
    }

    .callout-box li {
      font-size: 0.86rem;
      line-height: 1.5;
    }

    .callout-action {
      background-color: rgba(245, 158, 11, 0.08);
      border-left: 3.5px solid #f59e0b;
      border-top: 1px solid rgba(245, 158, 11, 0.2);
      border-bottom: 1px solid rgba(245, 158, 11, 0.2);
      border-right: 1px solid rgba(245, 158, 11, 0.2);
      border-radius: 0 0.65rem 0.65rem 0;
      color: var(--text);
    }

    .callout-action strong {
      color: #d97706;
    }

    .callout-takeaway {
      background-color: var(--primary-soft);
      border-left: 3.5px solid var(--primary);
      border-top: 1px solid var(--border);
      border-bottom: 1px solid var(--border);
      border-right: 1px solid var(--border);
      border-radius: 0 0.65rem 0.65rem 0;
      color: var(--text);
    }

    .callout-takeaway strong {
      color: var(--primary);
    }

    /* Navigation buttons */
    .stepper-nav {
      display: flex;
      justify-content: space-between;
      gap: 1rem;
      margin-top: 0.5rem;
    }

    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 0.45rem 1rem;
      font-family: var(--font);
      font-size: 0.82rem;
      font-weight: 600;
      border-radius: 999px;
      border: 1px solid var(--border);
      background-color: var(--primary-soft);
      color: var(--primary);
      cursor: pointer;
      transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
      gap: 0.5rem;
      box-shadow: var(--shadow);
    }

    .btn:hover {
      background-color: var(--primary);
      color: #ffffff !important;
      border-color: var(--primary);
      box-shadow: var(--shadow-hover);
    }

    .btn-primary {
      background-color: var(--primary);
      color: #ffffff !important;
      border-color: var(--primary);
    }

    .btn-primary:hover {
      background-color: var(--primary-hover);
      border-color: var(--primary-hover);
      box-shadow: var(--shadow-hover);
    }

    .btn-secondary {
      background-color: var(--bg-card);
      color: var(--text);
      border-color: var(--border);
    }
    
    .btn-secondary:hover {
      background-color: var(--primary-soft);
      color: var(--primary) !important;
      border-color: var(--primary);
      box-shadow: var(--shadow-hover);
    }

    /* Workspace Content Area */
    .workspace-content {
      display: flex;
      flex-direction: column;
      gap: 2rem;
      align-items: center;
    }

    .viewport-card {
      background-color: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 1.35rem;
      box-shadow: var(--shadow);
      display: flex;
      flex-direction: column;
      gap: 1rem;
      width: 100%;
      max-width: 600px;
      transition: background-color 0.3s ease, border-color 0.3s ease;
    }

    .viewport-card h3 {
      font-family: var(--font-title);
      font-size: 1rem;
      font-weight: 700;
      color: var(--text);
      border-left: 3px solid var(--primary);
      padding-left: 0.5rem;
      letter-spacing: -0.01em;
    }

    .svg-container {
      width: 100%;
      position: relative;
    }

    .svg-container svg {
      display: block;
      width: 100% !important;
      height: auto !important;
      border: 1px solid var(--border);
      border-radius: 0.75rem;
      background-color: var(--bg-card);
      touch-action: none;
      box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05);
      transition: background-color 0.3s ease, border-color 0.3s ease;
    }

    .canvas-container {
      width: 100%;
      position: relative;
    }

    .canvas-container canvas {
      display: block;
      width: 100% !important;
      height: auto !important;
      border: 1px solid var(--border);
      border-radius: 0.75rem;
      background-color: var(--bg-card);
      box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05);
      transition: background-color 0.3s ease, border-color 0.3s ease;
      image-rendering: pixelated;
    }

    /* Toolbox row in the workspace (Canvas Tools + Go Further) */
    .workspace-row {
      display: flex;
      gap: 1rem;
      width: 100%;
      max-width: 600px;
    }
    .toolbox-card {
      background-color: var(--bg-card);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 1.25rem;
      box-shadow: var(--shadow);
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 0.75rem;
    }
    .toolbox-card h2 {
      font-family: var(--font-title);
      font-size: 1rem;
      font-weight: 700;
      color: var(--primary);
      text-align: center;
      letter-spacing: -0.01em;
    }
    .toolbox-buttons {
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
      width: 100%;
    }
    .toolbox-card .btn-primary {
      margin-top: 0;
    }

    /* Styles for visualizer centroids - site contour (stroke) stays dark */
    .sites circle {
      fill: #ffffff !important;
      stroke: var(--cell-stroke) !important;
      stroke-width: 1.5px !important;
      r: 4px !important;
      opacity: 1 !important;
      visibility: visible !important;
    }

    /* Custom Touch-Friendly Range Sliders */
    input[type="range"] {
      -webkit-appearance: none;
      appearance: none;
      width: 100%;
      height: 6px;
      background: var(--border);
      border-radius: 3px;
      outline: none;
      transition: background 0.2s ease;
      cursor: pointer;
    }
    input[type="range"]::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 22px;
      height: 22px;
      border-radius: 50%;
      background: var(--primary);
      border: 2px solid var(--bg-card);
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
      cursor: pointer;
    }
    input[type="range"]::-moz-range-thumb {
      width: 22px;
      height: 22px;
      border-radius: 50%;
      background: var(--primary);
      border: 2px solid var(--bg-card);
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
      cursor: pointer;
    }

    /* Responsive Grid Classes for Visualizers */
    .bilateral-canvases-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 1rem;
      margin-bottom: 1.25rem;
    }

    .bilateral-col {
      display: flex;
      flex-direction: column;
    }

    /* Mobile Segmented Tab Switcher */
    .mobile-canvas-tabs {
      display: none;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 999px;
      padding: 3px;
      margin-bottom: 1rem;
      width: 100%;
      box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
    }

    .mobile-canvas-tabs .tab-btn {
      flex: 1;
      border: none;
      background: transparent;
      color: var(--text-muted);
      font-family: var(--font);
      font-size: 0.8rem;
      font-weight: 600;
      padding: 0.45rem 0.5rem;
      border-radius: 999px;
      cursor: pointer;
      transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
      text-align: center;
      white-space: nowrap;
    }

    .mobile-canvas-tabs .tab-btn.active {
      background: var(--bg-card);
      color: var(--primary);
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    }

    [data-theme="dark"] .mobile-canvas-tabs .tab-btn.active {
      background: var(--primary-soft);
      color: var(--primary);
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    .workspace-controls-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 1.25rem;
      width: 100%;
      max-width: 100%;
    }

    @media (max-width: 768px) {
      .site-header {
        padding: 0.65rem 1rem;
      }
      .header-left {
        gap: 0.65rem;
        min-width: 0;
      }
      .header-title {
        min-width: 0;
      }
      .header-title h1 {
        font-size: 1.02rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .header-title p {
        display: none;
      }
      .main-layout {
        padding: 1rem 0.75rem;
        gap: 1.25rem;
      }
      .guide-card {
        padding: 1.05rem 0.9rem;
        gap: 0.85rem;
      }
      .mode-btn {
        font-size: 0.75rem;
        padding: 0.4rem 0.5rem;
      }
      .real-world-context-card {
        padding: 0.75rem 0.85rem;
      }
      .step-content {
        gap: 0.75rem;
      }
      .step-content h2 {
        font-size: 1.08rem;
        padding-bottom: 0.35rem;
      }
      .step-description {
        font-size: 0.88rem;
        line-height: 1.55;
      }
      .callout-box {
        padding: 0.65rem 0.85rem;
        font-size: 0.84rem;
        line-height: 1.5;
      }
      .stepper {
        padding-bottom: 0.75rem;
      }
      .viewport-card {
        padding: 1rem;
        border-radius: 0.85rem;
      }
      .workspace-row {
        flex-direction: column;
        gap: 1rem;
      }
      .mobile-canvas-tabs {
        display: flex;
      }
      .bilateral-canvases-grid {
        display: block;
      }
      .bilateral-canvases-grid .bilateral-col {
        display: none;
      }
      .bilateral-canvases-grid .bilateral-col.is-active {
        display: block;
        width: 100%;
        max-width: 440px;
        margin: 0 auto;
      }
      .bilateral-canvases-grid .canvas-container {
        max-width: 440px;
        margin: 0 auto;
      }
      .workspace-controls-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
      }
      .stepper-nav {
        flex-direction: column;
        gap: 0.5rem;
      }
      .stepper-nav .btn {
        width: 100%;
        padding: 0.55rem 1rem;
      }
      .katex-display {
        font-size: 0.76rem !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        padding: 0.35rem 0 !important;
      }
    }

    @media (max-width: 480px) {
      .mobile-canvas-tabs .tab-btn {
        font-size: 0.74rem;
        padding: 0.4rem 0.2rem;
      }
    }

    /* Accessibility Focus Rings */
    .btn:focus-visible,
    .tab-btn:focus-visible,
    .step-dot:focus-visible,
    input[type="range"]:focus-visible,
    select:focus-visible {
      outline: 2px solid var(--primary);
      outline-offset: 2px;
    }

    .math-tooltip {
      position: absolute;
      background-color: var(--bg-card);
      border: 1px solid var(--border);
      border-left-width: 3.5px;
      border-radius: 0.65rem;
      padding: 0.75rem 1rem;
      box-shadow: var(--shadow-hover);
      z-index: 100;
      max-width: min(300px, calc(100vw - 24px));
      box-sizing: border-box;
      font-size: 0.82rem;
      line-height: 1.45;
      color: var(--text);
      opacity: 0;
      visibility: hidden;
      transform: translateY(4px);
      transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
      pointer-events: none;
    }

    .math-tooltip.visible {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
    }

    /* Generic Order-based Color Mapping (Colors 1-8) for KaTeX highlights and tooltips */

    /* Color 1: Blue */
    .katex .math-color-1 {
      color: rgb(29, 78, 216) !important;
      background-color: rgba(59, 130, 246, 0.1);
      box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.35);
    }
    [data-theme="dark"] .katex .math-color-1 {
      color: rgb(147, 197, 253) !important;
      background-color: rgba(96, 165, 250, 0.15);
      box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.4);
    }
    .katex .math-color-1:hover {
      background-color: rgba(59, 130, 246, 0.22) !important;
      box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.6) !important;
    }
    .math-tooltip[data-color-class="math-color-1"] {
      --term-color: rgb(29, 78, 216);
      --term-bg: rgba(59, 130, 246, 0.08);
      --term-border: rgba(59, 130, 246, 0.15);
    }
    [data-theme="dark"] .math-tooltip[data-color-class="math-color-1"] {
      --term-color: rgb(147, 197, 253);
      --term-bg: rgba(147, 197, 253, 0.15);
      --term-border: rgba(147, 197, 253, 0.3);
    }

    /* Color 2: Purple */
    .katex .math-color-2 {
      color: rgb(109, 40, 217) !important;
      background-color: rgba(139, 92, 246, 0.1);
      box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.35);
    }
    [data-theme="dark"] .katex .math-color-2 {
      color: rgb(196, 181, 253) !important;
      background-color: rgba(167, 139, 250, 0.15);
      box-shadow: inset 0 0 0 1px rgba(167, 139, 250, 0.4);
    }
    .katex .math-color-2:hover {
      background-color: rgba(139, 92, 246, 0.22) !important;
      box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.6) !important;
    }
    .math-tooltip[data-color-class="math-color-2"] {
      --term-color: rgb(109, 40, 217);
      --term-bg: rgba(139, 92, 246, 0.08);
      --term-border: rgba(139, 92, 246, 0.15);
    }
    [data-theme="dark"] .math-tooltip[data-color-class="math-color-2"] {
      --term-color: rgb(196, 181, 253);
      --term-bg: rgba(196, 181, 253, 0.15);
      --term-border: rgba(196, 181, 253, 0.3);
    }

    /* Color 3: Green */
    .katex .math-color-3 {
      color: rgb(4, 120, 87) !important;
      background-color: rgba(16, 185, 129, 0.1);
      box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.35);
    }
    [data-theme="dark"] .katex .math-color-3 {
      color: rgb(110, 231, 183) !important;
      background-color: rgba(52, 211, 153, 0.15);
      box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.4);
    }
    .katex .math-color-3:hover {
      background-color: rgba(16, 185, 129, 0.22) !important;
      box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.6) !important;
    }
    .math-tooltip[data-color-class="math-color-3"] {
      --term-color: rgb(4, 120, 87);
      --term-bg: rgba(16, 185, 129, 0.08);
      --term-border: rgba(16, 185, 129, 0.15);
    }
    [data-theme="dark"] .math-tooltip[data-color-class="math-color-3"] {
      --term-color: rgb(74, 222, 128);
      --term-bg: rgba(74, 222, 128, 0.15);
      --term-border: rgba(74, 222, 128, 0.3);
    }

    /* Color 4: Amber */
    .katex .math-color-4 {
      color: rgb(180, 83, 9) !important;
      background-color: rgba(245, 158, 11, 0.1);
      box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.35);
    }
    [data-theme="dark"] .katex .math-color-4 {
      color: rgb(252, 211, 77) !important;
      background-color: rgba(251, 191, 36, 0.15);
      box-shadow: inset 0 0 0 1px rgba(251, 191, 36, 0.4);
    }
    .katex .math-color-4:hover {
      background-color: rgba(245, 158, 11, 0.22) !important;
      box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.6) !important;
    }
    .math-tooltip[data-color-class="math-color-4"] {
      --term-color: rgb(180, 83, 9);
      --term-bg: rgba(245, 158, 11, 0.08);
      --term-border: rgba(245, 158, 11, 0.15);
    }
    [data-theme="dark"] .math-tooltip[data-color-class="math-color-4"] {
      --term-color: rgb(251, 146, 60);
      --term-bg: rgba(251, 146, 60, 0.15);
      --term-border: rgba(251, 146, 60, 0.3);
    }

    /* Color 5: Pink */
    .katex .math-color-5 {
      color: rgb(219, 39, 119) !important;
      background-color: rgba(219, 39, 119, 0.08);
      box-shadow: inset 0 0 0 1px rgba(219, 39, 119, 0.2);
    }
    [data-theme="dark"] .katex .math-color-5 {
      color: rgb(244, 114, 182) !important;
      background-color: rgba(244, 114, 182, 0.15);
      box-shadow: inset 0 0 0 1px rgba(244, 114, 182, 0.3);
    }
    .katex .math-color-5:hover {
      background-color: rgba(244, 63, 94, 0.22) !important;
      box-shadow: inset 0 0 0 1px rgba(244, 63, 94, 0.6) !important;
    }
    .math-tooltip[data-color-class="math-color-5"] {
      --term-color: rgb(219, 39, 119);
      --term-bg: rgba(219, 39, 119, 0.08);
      --term-border: rgba(219, 39, 119, 0.15);
    }
    [data-theme="dark"] .math-tooltip[data-color-class="math-color-5"] {
      --term-color: rgb(244, 114, 182);
      --term-bg: rgba(244, 114, 182, 0.15);
      --term-border: rgba(244, 114, 182, 0.3);
    }

    /* Color 6: Indigo */
    .katex .math-color-6 {
      color: rgb(67, 56, 202) !important;
      background-color: rgba(99, 102, 241, 0.08);
      box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.2);
    }
    [data-theme="dark"] .katex .math-color-6 {
      color: rgb(165, 180, 252) !important;
      background-color: rgba(129, 140, 248, 0.15);
      box-shadow: inset 0 0 0 1px rgba(129, 140, 248, 0.3);
    }
    .katex .math-color-6:hover {
      background-color: rgba(99, 102, 241, 0.22) !important;
      box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.6) !important;
    }
    .math-tooltip[data-color-class="math-color-6"] {
      --term-color: rgb(67, 56, 202);
      --term-bg: rgba(99, 102, 241, 0.08);
      --term-border: rgba(99, 102, 241, 0.15);
    }
    [data-theme="dark"] .math-tooltip[data-color-class="math-color-6"] {
      --term-color: rgb(165, 180, 252);
      --term-bg: rgba(129, 140, 248, 0.15);
      --term-border: rgba(129, 140, 248, 0.3);
    }

    /* Color 7: Teal */
    .katex .math-color-7 {
      color: rgb(13, 148, 136) !important;
      background-color: rgba(13, 148, 136, 0.08);
      box-shadow: inset 0 0 0 1px rgba(13, 148, 136, 0.2);
    }
    [data-theme="dark"] .katex .math-color-7 {
      color: rgb(45, 212, 191) !important;
      background-color: rgba(45, 212, 191, 0.15);
      box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.3);
    }
    .katex .math-color-7:hover {
      background-color: rgba(13, 148, 136, 0.22) !important;
      box-shadow: inset 0 0 0 1px rgba(13, 148, 136, 0.6) !important;
    }
    .math-tooltip[data-color-class="math-color-7"] {
      --term-color: rgb(13, 148, 136);
      --term-bg: rgba(13, 148, 136, 0.08);
      --term-border: rgba(13, 148, 136, 0.15);
    }
    [data-theme="dark"] .math-tooltip[data-color-class="math-color-7"] {
      --term-color: rgb(45, 212, 191);
      --term-bg: rgba(45, 212, 191, 0.15);
      --term-border: rgba(45, 212, 191, 0.3);
    }

    /* Color 8: Yellow */
    .katex .math-color-8 {
      color: rgb(202, 138, 4) !important;
      background-color: rgba(202, 138, 4, 0.08);
      box-shadow: inset 0 0 0 1px rgba(202, 138, 4, 0.2);
    }
    [data-theme="dark"] .katex .math-color-8 {
      color: rgb(253, 224, 71) !important;
      background-color: rgba(253, 224, 71, 0.15);
      box-shadow: inset 0 0 0 1px rgba(253, 224, 71, 0.3);
    }
    .katex .math-color-8:hover {
      background-color: rgba(202, 138, 4, 0.22) !important;
      box-shadow: inset 0 0 0 1px rgba(202, 138, 4, 0.6) !important;
    }
    .math-tooltip[data-color-class="math-color-8"] {
      --term-color: rgb(202, 138, 4);
      --term-bg: rgba(202, 138, 4, 0.08);
      --term-border: rgba(202, 138, 4, 0.15);
    }
    [data-theme="dark"] .math-tooltip[data-color-class="math-color-8"] {
      --term-color: rgb(253, 224, 71);
      --term-bg: rgba(253, 224, 71, 0.15);
      --term-border: rgba(253, 224, 71, 0.3);
    }

    .math-tooltip-title {
      font-weight: 700;
      color: var(--term-color);
      margin-bottom: 0.25rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.5rem;
    }

    .math-tooltip-term {
      font-family: 'Fira Code', monospace;
      font-size: 0.78rem;
      background-color: var(--term-bg);
      padding: 0.1rem 0.3rem;
      border-radius: 4px;
      border: 1px solid var(--term-border);
      color: var(--term-color);
    }

    /* Prevent display math overflow in sidebar */
    .katex-display {
      overflow: visible !important;
      max-width: 100% !important;
      padding: 0.5rem 0 !important;
      font-size: 0.82rem; /* Scale down so it fits completely without scrollbar */
      text-align: center;
    }

    /* Math term pill styles — only safe properties that don't break KaTeX layout */
    .katex [class*="math-term-"] {
      transition: background-color 0.15s ease, box-shadow 0.15s ease;
      border-radius: 3px;
      /* Horizontal padding gives breathing room without breaking fractions/subscripts */
      padding: 0.15em;
      margin: 0 0.04em;
    }
