    :root{
      --bg:#08111f;
      --panel:#0d1a2c;
      --line:rgba(255,255,255,.10);
      --text:#eaf2ff;
      --muted:rgba(234,242,255,.72);
      --green:#22c55e;
      --red:#ef4444;
      --purple:#8b5cf6;
      --blue:#3b82f6;
      --yellow:#f59e0b;
      --shadow:0 20px 60px rgba(0,0,0,.35);
    
      --surface-1:rgba(255,255,255,.035);
      --surface-2:rgba(255,255,255,.05);
      --surface-3:rgba(255,255,255,.10);
      --surface-hover:rgba(255,255,255,.08);
      --line-strong:rgba(255,255,255,.18);
      --on-brand:#fff;
    
      --tint-danger-fg:#ffd6d6;
      --tint-info-fg:#d6e8ff;
      --tint-success-fg:#d7ffe3;
      --tint-warn-fg:#ffe3b3;
    }

    /* Stage 89: LIGHT MODE. Values and their measured contrast ratios are
       specified in `14 DESIGN.md` §2.1b — ported from the app's light theme,
       not invented. Dark stays the default: this block only applies once
       something stamps data-theme="light" on <html>. */
    :root[data-theme="light"]{
      --bg:#FAF7F0;
      --panel:#FFFFFF;
      --line:#E2E8F0;
      --text:#111827;
      --muted:#475569;
      --green:#047857;
      --red:#DC2626;
      --purple:#7C3AED;
      --blue:#2563EB;
      --yellow:#B45309;
      --shadow:0 10px 30px rgba(11,22,51,.10);
    
      --surface-1:#FFFFFF;
      --surface-2:#F8FAFC;
      --surface-3:#F1F5F9;
      --surface-hover:#E2E8F0;
      --line-strong:#CBD5E1;
      --on-brand:#FFFFFF;
    
      --tint-danger-fg:#991B1B;
      --tint-info-fg:#1E40AF;
      --tint-success-fg:#065F46;
      --tint-warn-fg:#92400E;
    }

    *{box-sizing:border-box}
    body{
      margin:0;
      background:
        radial-gradient(1000px 500px at 15% 0%, rgba(99,102,241,.18), transparent 55%),
        radial-gradient(900px 420px at 100% 0%, rgba(59,130,246,.14), transparent 50%),
        var(--bg);
      color:var(--text);
      font-family:system-ui, Arial, sans-serif;
    }

    .wrap{
      max-width:1580px;
      margin:18px auto;
      padding:0 14px 24px;
    }

    .topbar{
      display:flex;
      justify-content:space-between;
      align-items:center;
      gap:12px;
      flex-wrap:wrap;
      padding:14px 16px;
      border:1px solid var(--line);
      border-radius:20px;
      background:linear-gradient(180deg, var(--surface-2), var(--surface-1));
      box-shadow:var(--shadow);
    }

    .brand{
      display:flex;
      gap:12px;
      align-items:center;
    }

    .logo{
      width:46px;height:46px;border-radius:14px;
      display:grid;place-items:center;
      font-weight:900;
      background:linear-gradient(135deg,#7c3aed,#3b82f6);
      color:var(--on-brand);
    }

    .brand h1{
      margin:0;
      font-size:22px;
      font-weight:900;
    }

    .brand p{
      margin:4px 0 0;
      color:var(--muted);
      font-size:13px;
    }

    .btn{
      border:none;
      outline:none;
      cursor:pointer;
      border-radius:14px;
      padding:11px 16px;
      font-weight:800;
      color:var(--text);
      background:var(--surface-hover);
      border:1px solid var(--line);
      transition:.18s ease;
      text-decoration:none;
      display:inline-flex;
      align-items:center;
      justify-content:center;
      gap:8px;
    }

    .btn:hover{transform:translateY(-1px)}
    .btn.primary{background:linear-gradient(135deg,#8b5cf6,#3b82f6);border:none}
    .btn.success{background:linear-gradient(135deg,#16a34a,#22c55e);border:none}
    .btn.warn{background:linear-gradient(135deg,#f59e0b,#ef4444);border:none}
    .btn.ghost{background:var(--surface-1)}
    .btn.danger{background:linear-gradient(135deg,#dc2626,#ef4444);border:none}
    .btn:disabled{opacity:.6;cursor:not-allowed;transform:none}

    .math-toolbar{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin:8px 0 10px;
}

.math-chip{
  border:1px solid var(--surface-3);
  background:var(--surface-2);
  color:var(--text);
  border-radius:10px;
  padding:8px 10px;
  font-size:12px;
  font-weight:800;
  cursor:pointer;
}

.math-chip:hover{
  background:rgba(139,92,246,.16);
  border-color:rgba(139,92,246,.35);
}

.math-help{
  font-size:12px;
  color:var(--muted);
  line-height:1.5;
  margin-top:6px;
  white-space:pre-wrap;
}

    .grid{
      --left-col:380px;
      --middle-col:minmax(420px, 1fr);
      --right-col:500px;

      display:grid;
      grid-template-columns:var(--left-col) 10px var(--middle-col) 10px var(--right-col);
      gap:0;
      column-gap:10px;
      margin-top:16px;
      align-items:stretch;
    }

    .column-resizer{
      width:10px;
      height:clamp(420px, 74vh, 920px);
      cursor:col-resize;
      border-radius:999px;
      background:var(--surface-hover);
      border:1px solid var(--surface-3);
      align-self:stretch;
      transition:.15s ease;
    }

    .column-resizer:hover,
    .column-resizer.dragging{
      background:rgba(59,130,246,.45);
      border-color:rgba(59,130,246,.65);
    }

    .column-resizer::after{
      content:"";
      display:block;
      width:3px;
      height:42px;
      margin:calc(clamp(190px, 37vh, 440px) - 21px) auto 0;
      border-radius:999px;
      background:var(--line-strong);
    }

    .resize-reset-btn{
      position:fixed;
      right:18px;
      bottom:18px;
      z-index:999;
      border:none;
      border-radius:999px;
      padding:10px 14px;
      cursor:pointer;
      font-weight:900;
      color:var(--on-brand);
      background:linear-gradient(135deg,#2563eb,#7c3aed);
      box-shadow:0 12px 30px rgba(0,0,0,.35);
    }

    .panel{
      border:1px solid var(--line);
      border-radius:20px;
      background:linear-gradient(180deg, var(--surface-2), var(--surface-1));
      box-shadow:var(--shadow);
      overflow:hidden;
      height:clamp(420px, 74vh, 920px);
      display:flex;
      flex-direction:column;
      min-height:0;
    }

    .panel-head{
      padding:14px 16px;
      border-bottom:1px solid var(--line);
      display:flex;
      justify-content:space-between;
      align-items:center;
      gap:10px;
      background:var(--surface-1);
    }

    .panel-head h2,.panel-head h3{
      margin:0;
      font-size:16px;
      font-weight:900;
    }

    .panel-body{
      padding:14px;
      flex:1;
      overflow-y:auto;
      overflow-x:auto;
      min-height:0;
    }

    .field{margin-bottom:12px}
    .field label{
      display:block;
      margin-bottom:6px;
      color:var(--muted);
      font-size:12px;
      font-weight:700;
    }

    input, select, textarea{
      width:100%;
      border-radius:12px;
      border:1px solid var(--surface-3);
      background:var(--surface-1);
      color:var(--text);
      padding:10px 12px;
      font:inherit;
      outline:none;
    }

    select{
      color:var(--text);
      background-color:var(--surface-1);
      color-scheme:dark;
    }

    select option{
      color:#0f172a;
      background-color:var(--text);
    }

    select option:checked{
      color:var(--on-brand);
      background-color:#2563eb;
    }

    select option:hover,
    select option:focus{
      color:var(--on-brand);
      background-color:#2563eb;
    }

    select optgroup{
      color:#0f172a;
      background-color:var(--text);
      font-weight:900;
    }

    /* Fixes checkboxes taking 100% width and breaking the left list */
    input[type="checkbox"], input[type="radio"] {
      width: auto !important;
      margin: 0;
      cursor: pointer;
      transform: scale(1.15);
    }

    /* Ensures long titles wrap cleanly */
    .item-title {
      word-break: break-word;
      overflow-wrap: anywhere;
    }

    textarea{
      min-height:160px;
      resize:vertical;
      font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    }

    .small{
      font-size:12px;
      color:var(--muted);
    }

    .mono-help{
      font-size:12px;
      color:var(--muted);
      line-height:1.5;
      margin-top:6px;
      white-space:pre-wrap;
    }

    .list{
      display:grid;
      gap:10px;
      overflow:auto;
    }

    .item{
      border:1px solid var(--surface-3);
      border-radius:16px;
      background:var(--surface-1);
      padding:12px;
      cursor:pointer;
      transition:.15s ease;
    }

    .item:hover{
      background:rgba(139,92,246,.08);
      border-color:rgba(139,92,246,.35);
    }

    .item.active{
      background:rgba(59,130,246,.12);
      border-color:rgba(59,130,246,.40);
    }

    .item-title{
      font-weight:800;
      line-height:1.45;
      font-size:14px;
    }

    .meta{
      margin-top:8px;
      display:flex;
      flex-wrap:wrap;
      gap:8px;
    }

    .pill{
      display:inline-flex;
      align-items:center;
      gap:6px;
      padding:6px 10px;
      border-radius:999px;
      border:1px solid var(--line);
      background:var(--surface-1);
      font-size:11px;
      color:var(--muted);
      font-weight:700;
    }

    .pill.bad{
      background:rgba(239,68,68,.12);
      border-color:rgba(239,68,68,.24);
      color:var(--tint-danger-fg);
    }

    .pill.good{
      background:rgba(34,197,94,.12);
      border-color:rgba(34,197,94,.24);
      color:var(--tint-success-fg);
    }

    .pill.type{
      background:rgba(59,130,246,.12);
      border-color:rgba(59,130,246,.24);
      color:var(--tint-info-fg);
    }

    .pill.pending{
      background:rgba(245,158,11,.12);
      border-color:rgba(245,158,11,.24);
      color:var(--tint-warn-fg);
    }

    .pill.approved{
      background:rgba(34,197,94,.12);
      border-color:rgba(34,197,94,.24);
      color:var(--tint-success-fg);
    }

    .pill.rejected{
      background:rgba(239,68,68,.12);
      border-color:rgba(239,68,68,.24);
      color:var(--tint-danger-fg);
    }

    .row{
      display:flex;
      gap:10px;
      flex-wrap:wrap;
    }

    .row .field{
      flex:1;
      min-width:120px;
    }

    .section-box{
      border:1px solid var(--surface-3);
      border-radius:16px;
      padding:12px;
      background:var(--surface-1);
      margin-bottom:12px;
    }

    .section-box h4{
      margin:0 0 10px;
      font-size:14px;
      font-weight:900;
    }

    .check-row{
      display:flex;
      flex-wrap:wrap;
      gap:10px;
      margin-top:8px;
    }

    .check-chip{
      display:inline-flex;
      align-items:center;
      gap:8px;
      padding:8px 10px;
      border-radius:12px;
      border:1px solid var(--surface-3);
      background:var(--surface-1);
      color:var(--text);
      font-size:13px;
      font-weight:700;
    }

    .check-chip input{
      width:auto;
      margin:0;
      transform:scale(1.15);
    }

    .preview-box{
      border:1px solid var(--surface-3);
      border-radius:16px;
      background:var(--surface-1);
      padding:14px;
      margin-bottom:12px;
    }

    .preview-q{
      font-size:20px;
      font-weight:800;
      line-height:1.7;
      margin-bottom:12px;
    }

    .preview-type{
      margin-bottom:10px;
      display:inline-flex;
      align-items:center;
      gap:6px;
      padding:6px 10px;
      border-radius:999px;
      border:1px solid var(--line);
      background:var(--surface-1);
      font-size:12px;
      color:var(--muted);
      font-weight:700;
    }

    .preview-opt{
      padding:10px 12px;
      border-radius:12px;
      border:1px solid var(--surface-hover);
      background:var(--surface-1);
      margin-bottom:8px;
      line-height:1.75;
      font-size:16px;
    }

    .compare-card{
      border:1px solid var(--surface-3);
      border-radius:14px;
      background:var(--surface-1);
      padding:12px;
      min-height:120px;
    }

    .compare-content{
      white-space:pre-wrap;
      line-height:1.55;
      font-size:13px;
      color:var(--muted);
      word-break:break-word;
    }

    .empty{
      color:var(--muted);
      text-align:center;
      padding:20px;
      border:1px dashed var(--line-strong);
      border-radius:16px;
    }

    .hidden{
      display:none !important;
    }

    .live-math-preview{
      margin-top:8px;
      padding:10px 14px;
      border:1px solid rgba(59,130,246,.28);
      border-radius:12px;
      background:rgba(59,130,246,.06);
      font-size:15px;
      line-height:1.8;
      word-break:break-word;
      color:var(--text);
    }

    .live-math-preview-label{
      font-size:11px;
      font-weight:800;
      color:rgba(59,130,246,.8);
      letter-spacing:.04em;
      margin-bottom:6px;
    }

    .status-bar{
      margin-top:8px;
      font-size:13px;
      font-weight:700;
    }

    .status-ok{color:var(--tint-success-fg)}
    .status-err{color:var(--tint-danger-fg)}

    .preview-q mjx-container,
.preview-opt mjx-container,
#previewSolution mjx-container{
  font-size: 118% !important;
}

#previewQuestion,
#previewBody,
#previewSolution{
  line-height: 1.9;
  word-break: break-word;
}

#previewSolution{
  white-space: normal;
  line-height: 2;
  font-size: 16px;
}

#previewSolution mjx-container{
  display: inline-block;
  margin: 0 .12em !important;
  vertical-align: middle;
}

#previewSolution mjx-container[display="true"]{
  display: block;
  margin: 10px 0 !important;
}

.solution-line{
  margin: 4px 0;
  line-height: 1.9;
}

.solution-step{
  margin: 8px 0;
  line-height: 1.95;
}

.media-block{
  margin:12px 0;
  display:flex;
}

.media-block.align-left{
  justify-content:flex-start;
}

.media-block.align-center{
  justify-content:center;
}

.media-block.align-right{
  justify-content:flex-end;
}

.preview-media-img{
  display:block;
  width:100%;
  height:auto;
  border-radius:12px;
  border:1px solid var(--surface-3);
  box-shadow:0 10px 24px rgba(0,0,0,.25);
  background:var(--surface-1);
}

.preview-media-iframe{
  display:block;
  width:100%;
  min-height:320px;
  border:1px solid var(--surface-3);
  border-radius:12px;
  background:#fff;
}

.preview-media-frame{
  width:min(100%, var(--img-width, 420px));
  max-width:100%;
}

.preview-media-caption{
  margin-top:6px;
  font-size:12px;
  color:var(--muted);
  text-align:center;
}

.diagram-fallback{
  border:1px dashed var(--line-strong);
  border-radius:12px;
  padding:18px 12px;
  text-align:center;
  color:var(--muted);
  background:var(--surface-1);
}

mjx-container[jax="SVG"]{
  margin: 0 .08em;
}


.math-popup-overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.45);
  display:none;
  align-items:center;
  justify-content:center;
  z-index:9999;
}

.math-popup{
  width:min(920px, 94vw);
  max-height:84vh;
  overflow:auto;
  background:linear-gradient(180deg, #0f1b31, #0b1425);
  border:1px solid var(--surface-3);
  border-radius:20px;
  box-shadow:0 20px 60px rgba(0,0,0,.45);
  padding:18px;
}

.math-popup-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin-bottom:14px;
}

.math-popup-title{
  font-size:18px;
  font-weight:900;
}

.math-popup-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(180px, 1fr));
  gap:12px;
}

.math-group{
  border:1px solid var(--surface-3);
  border-radius:16px;
  padding:12px;
  background:var(--surface-1);
}

.math-group h4{
  margin:0 0 10px;
  font-size:13px;
  font-weight:900;
  color:var(--muted);
}

.math-key{
  width:100%;
  margin-bottom:8px;
  border:1px solid var(--surface-3);
  background:var(--surface-2);
  color:var(--text);
  border-radius:10px;
  padding:9px 10px;
  text-align:left;
  cursor:pointer;
  font-weight:700;
}

.math-key:hover{
  background:rgba(139,92,246,.16);
  border-color:rgba(139,92,246,.35);
}

.left-math-dock{
  border:1px solid var(--surface-3);
  border-radius:16px;
  background:linear-gradient(180deg, var(--surface-2), var(--surface-1));
  padding:12px;
  box-shadow:var(--shadow);
}

.left-math-dock.hidden{
  display:none !important;
}

.left-math-dock-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin-bottom:10px;
}

.left-math-dock-title{
  font-size:15px;
  font-weight:900;
}

.left-math-dock-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(150px, 1fr));
  gap:10px;
  max-height:320px;
  overflow:auto;
}

.left-math-dock .math-group{
  margin:0;
}

.left-panel-body{
  display:flex;
  flex-direction:column;
  gap:12px;
  min-height:0;
}

.left-panel-body .list{
  flex:0 0 var(--left-list-height, 320px);
  min-height:140px;
  max-height:none;
  overflow:auto;
}

.left-panel-body #leftMathDock{
  flex:1 1 auto;
  min-height:120px;
  overflow:auto;
}

.left-list-resizer{
  height:10px;
  min-height:10px;
  cursor:row-resize;
  border-radius:999px;
  background:var(--surface-hover);
  border:1px solid var(--surface-3);
  transition:.15s ease;
  position:relative;
  flex:0 0 auto;
}

.left-list-resizer:hover,
.left-list-resizer.dragging{
  background:rgba(59,130,246,.45);
  border-color:rgba(59,130,246,.65);
}

.left-list-resizer::after{
  content:"";
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%, -50%);
  width:42px;
  height:3px;
  border-radius:999px;
  background:var(--line-strong);
}


    @media (max-width:1280px){
      .grid{
        grid-template-columns:1fr;
        row-gap:14px;
      }
      .column-resizer{display:none}
      .left-panel-body .list{
        flex:0 0 auto;
        max-height:420px;
      }
      .left-list-resizer{display:none}
      .panel{height:auto; min-height:auto}
      .list{max-height:420px}
    }

    @media (min-width:1100px) and (max-width:1280px){
      .grid{
        grid-template-columns:1fr 1fr !important;
        row-gap:14px;
      }
      .panel:last-child{
        grid-column:1 / -1;
      }
    }

    @media (max-width:900px){
      html, body{
        width:100%;
        max-width:100%;
        overflow-x:hidden;
      }

      .wrap{
        width:100% !important;
        max-width:100% !important;
        padding:0 10px 20px !important;
      }

      .topbar{
        width:100% !important;
        max-width:100% !important;
        margin:10px auto 0 !important;
        padding:10px 12px !important;
        border-radius:16px !important;
        align-items:flex-start !important;
      }

      .brand{
        width:100% !important;
        min-width:0 !important;
      }

      .brand h1{
        font-size:18px !important;
        line-height:1.15 !important;
      }

      .brand p{
        font-size:12px !important;
        line-height:1.35 !important;
      }

      .grid{
        display:grid !important;
        grid-template-columns:1fr !important;
        gap:14px !important;
      }

      .column-resizer,
      .left-list-resizer,
      .resize-reset-btn{
        display:none !important;
      }

      .panel{
        height:auto !important;
        min-height:auto !important;
        max-height:none !important;
      }

      .panel-body{
        max-height:none !important;
        overflow:visible !important;
      }

      .left-panel-body .list,
      .list{
        max-height:420px !important;
        overflow:auto !important;
      }

      textarea{
        min-height:120px !important;
      }

      .row{
        display:grid !important;
        grid-template-columns:1fr !important;
        gap:10px !important;
      }

      .row .field{
        min-width:0 !important;
      }

      input,
      select,
      textarea{
        width:100% !important;
        max-width:100% !important;
        font-size:16px !important;
      }
    }

    /* ── Inline validation ────────────────────────────────────── */
    input.field-error,
    select.field-error,
    textarea.field-error{
      border-color:rgba(239,68,68,.65) !important;
      background:rgba(239,68,68,.06) !important;
    }

    .field-error-hint{
      margin-top:5px;
      font-size:12px;
      font-weight:700;
      color:var(--tint-danger-fg);
    }

    /* Non-blocking note — amber, deliberately not the red of a hard error. */
    .field-warning-hint{
      margin-top:5px;
      font-size:12px;
      font-weight:700;
      color:var(--tint-warn-fg);
    }

    /* ── Focus rings (keyboard nav + cross-browser) ───────────────── */
    input:focus,
    select:focus,
    textarea:focus{
      border-color:rgba(59,130,246,.55);
      box-shadow:0 0 0 2px rgba(59,130,246,.18);
      outline:none;
    }

    input.field-error:focus,
    select.field-error:focus,
    textarea.field-error:focus{
      border-color:rgba(239,68,68,.65) !important;
      box-shadow:0 0 0 2px rgba(239,68,68,.18) !important;
    }

    .btn:focus-visible{
      outline:2px solid rgba(59,130,246,.7);
      outline-offset:2px;
    }

    .item:focus-visible,
    .math-key:focus-visible,
    .math-chip:focus-visible{
      outline:2px solid rgba(59,130,246,.7);
      outline-offset:2px;
    }

    /* ── Loading states ───────────────────────────────────────────── */
    @keyframes pulse-opacity{
      0%,100%{opacity:.45}
      50%{opacity:1}
    }

    .loading-pulse{
      animation:pulse-opacity 1.4s ease-in-out infinite;
    }
