
  :root{
    --paper:   #ECEFF3;
    --panel:   #FFFFFF;
    --ink:     #171B22;
    --graphite:#5B6472;
    --hairline:#D3D8DE;
    --hairline-strong:#B7BEC7;
    --scint:   #4B3FCB;
    --scint-dim: #E6E3FA;
    --amber:   #E0932E;
    --amber-dim: #FBE9D2;
    --danger:  #C1445E;
    --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  }
  * { box-sizing: border-box; }
  html, body {
    margin: 0; padding: 0; height: 100%;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
  }
  body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  /* ---------- Toolbar ---------- */
  #toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--hairline);
    flex-shrink: 0;
    overflow-x: auto;
  }
  #toolbar .brand {
    font-weight: 600;
    font-size: 14.5px;
    letter-spacing: 0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 4px;
    white-space: nowrap;
  }
  #toolbar .brand .dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--scint);
    flex-shrink: 0;
  }
  .btn {
    font-family: var(--font-ui);
    font-size: 13px;
    padding: 7px 13px;
    border-radius: 5px;
    border: 1px solid var(--hairline-strong);
    background: var(--panel);
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: border-color .12s, background .12s;
  }
  .btn:hover { border-color: var(--graphite); }
  .btn:active { background: var(--paper); }
  .btn.primary {
    background: var(--scint);
    border-color: var(--scint);
    color: #fff;
    font-weight: 500;
  }
  .btn.primary:hover { background: #3f34ad; border-color: #3f34ad; }
  .btn.toggle.active {
    background: var(--scint-dim);
    border-color: var(--scint);
    color: var(--scint);
    font-weight: 500;
  }
  .seg {
    display: flex;
    flex-shrink: 0;
    border: 1px solid var(--hairline-strong);
    border-radius: 5px;
    overflow: hidden;
  }
  .seg .btn {
    border: none;
    border-radius: 0;
    border-right: 1px solid var(--hairline-strong);
  }
  .seg .btn:last-child { border-right: none; }
  #toolbar .spacer { flex: 1; }
  #fileInput, #rootInput { display: none; }
  #toolbar .hint {
    font-size: 12px;
    color: var(--graphite);
    font-family: var(--font-mono);
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ---------- Main layout ---------- */
  #main {
    flex: 1;
    display: flex;
    min-height: 0;
  }
  #plotWrap {
    flex: 1;
    position: relative;
    background: var(--panel);
    margin: 12px 0 12px 12px;
    border: 1px solid var(--hairline);
    border-radius: 6px;
    overflow: hidden;
    min-width: 0;
  }
  #plotSvg { width: 100%; height: 100%; display: block; cursor: crosshair; }
  #emptyState {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px;
    color: var(--graphite);
    text-align: center;
    padding: 24px;
  }
  #emptyState .glyph {
    width: 46px; height: 46px;
    border: 1.5px solid var(--hairline-strong);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
  }
  #emptyState .glyph svg { width: 22px; height: 22px; stroke: var(--graphite); }
  #emptyState p { margin: 0; font-size: 13.5px; max-width: 280px; line-height: 1.5; }
  #emptyState .btn { margin-top: 2px; }

  #tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--ink);
    color: #fff;
    font-family: var(--font-mono);
    font-size: 11.5px;
    padding: 6px 9px;
    border-radius: 4px;
    line-height: 1.5;
    white-space: nowrap;
    display: none;
    z-index: 5;
  }

  #toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%) translateY(0);
    background: var(--ink);
    color: #fff;
    padding: 10px 16px;
    border-radius: 7px;
    font-size: 12.5px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.18);
    z-index: 20;
    display: none;
    max-width: 460px;
    line-height: 1.5;
    cursor: pointer;
  }
  #toast.error { background: var(--danger); }
  #toast .sub { color: rgba(255,255,255,0.7); font-family: var(--font-mono); font-size: 11px; margin-top: 2px; }

  /* ---------- Side panel ---------- */
  #side {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 12px 12px 12px 0;
    gap: 12px;
    overflow-y: auto;
  }
  .panel {
    background: var(--panel);
    border: 1px solid var(--hairline);
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
  }
  .panel-head {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--graphite);
    padding: 9px 12px;
    border-bottom: 1px solid var(--hairline);
  }
  .panel-body { padding: 4px 0; }
  .panel-body.pad { padding: 10px 12px; }

  #fileList { display: flex; flex-direction: column; max-height: 260px; overflow-y: auto; }
  .file-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    cursor: pointer;
    border-left: 2px solid transparent;
  }
  .file-row:hover { background: var(--paper); }
  .file-row.active { border-left-color: var(--scint); background: var(--scint-dim); }
  .file-row .swatch {
    width: 9px; height: 9px; border-radius: 50%;
    flex-shrink: 0;
  }
  .file-row .name {
    flex: 1;
    font-size: 12.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .file-row .count {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--graphite);
    flex-shrink: 0;
  }
  .file-row input[type=checkbox] { flex-shrink: 0; accent-color: var(--scint); }
  .file-row .remove {
    flex-shrink: 0;
    width: 16px; height: 16px;
    display: none;
    align-items: center; justify-content: center;
    color: var(--graphite);
    border-radius: 3px;
    font-size: 13px;
    line-height: 1;
  }
  .file-row:hover .remove { display: flex; }
  .file-row .remove:hover { background: var(--hairline); color: var(--danger); }

  .stat-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 5px 12px;
    font-size: 12.5px;
    gap: 10px;
  }
  .stat-row .label { color: var(--graphite); white-space: nowrap; }
  .stat-row .value {
    font-family: var(--font-mono);
    font-size: 12.5px;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .stat-row .value.hl { color: var(--amber); font-weight: 600; }

  .roi-file-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--hairline);
  }
  .roi-file-swatch {
    width: 9px; height: 9px; border-radius: 50%;
    flex-shrink: 0;
  }
  .roi-file-select {
    flex: 1;
    min-width: 0;
    font-family: var(--font-ui);
    font-size: 12.5px;
    padding: 5px 7px;
    border: 1px solid var(--hairline-strong);
    border-radius: 4px;
    background: var(--paper);
    color: var(--ink);
  }
  .roi-file-select:focus { outline: none; border-color: var(--scint); background: var(--panel); }

  .roi-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--hairline);
  }
  .roi-input {
    width: 0;
    flex: 1 1 0;
    min-width: 44px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    padding: 5px 7px;
    border: 1px solid var(--hairline-strong);
    border-radius: 4px;
    background: var(--paper);
    color: var(--ink);
  }
  .roi-input:focus {
    outline: none;
    border-color: var(--scint);
    background: var(--panel);
  }
  /* hide native number spinners so the field stays compact */
  .roi-input::-webkit-outer-spin-button, .roi-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
  .roi-input[type=number] { -moz-appearance: textfield; }
  .roi-dash { color: var(--graphite); flex-shrink: 0; }
  .roi-unit { font-size: 11px; color: var(--graphite); flex-shrink: 0; width: 26px; }
  .btn.small { padding: 5px 9px; font-size: 12px; flex-shrink: 0; }

  #roiEmpty {
    padding: 16px 12px;
    font-size: 12px;
    color: var(--graphite);
    line-height: 1.5;
  }

  /* ---------- Footer status bar ---------- */
  #footer {
    flex-shrink: 0;
    display: flex;
    gap: 22px;
    align-items: center;
    padding: 7px 16px;
    background: var(--panel);
    border-top: 1px solid var(--hairline);
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--graphite);
    overflow-x: auto;
    white-space: nowrap;
  }
  #footer .k { color: var(--ink); }
  #footer .sep { color: var(--hairline-strong); }

  /* scrollbars, subtle */
  ::-webkit-scrollbar { width: 9px; height: 9px; }
  ::-webkit-scrollbar-thumb { background: var(--hairline-strong); border-radius: 5px; }
  ::-webkit-scrollbar-track { background: transparent; }

/* v03: keep the original viewer's visual language; extend it for batch analysis. */
[hidden] { display: none !important; }
button:focus-visible, input:focus-visible, select:focus-visible, .name:focus-visible { outline: 2px solid var(--scint); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: not-allowed; }
#toolbar { flex-wrap: wrap; gap: 8px; overflow: visible; }
#toolbar .brand { margin-right: 12px; }
#side { width: 345px; padding-left: 12px; }
#plotSvg { touch-action: none; }
#emptyState h1 { margin: 0; font-size: 22px; font-weight: 600; }
#emptyState p { max-width: 420px; line-height: 1.9; }
#plotNotice { position: absolute; top: 8px; left: 65px; font-size: 11px; color: var(--graphite); pointer-events: none; background: #ffffffdd; border-radius: 4px; }
.panel-head { display: flex; justify-content: space-between; }
#spectrumCount { font-family: var(--font-mono); }
.list-actions { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--hairline); }
.small-note { font-size: 11px; line-height: 1.7; color: var(--graphite); }
.inset { padding: 8px 12px; }
.file-row .remove { border: 0; background: transparent; font-size: 20px; padding: 2px 5px; }
.file-row input { width: 16px; height: 16px; }
.file-row .count { max-width: 80px; overflow: hidden; text-overflow: ellipsis; }
.stat-row .value { max-width: 210px; white-space: normal; overflow-wrap: anywhere; }
.time-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 10px 12px; font-size: 11px; border-top: 1px solid var(--hairline); }
.time-editor input { width: 100px; min-width: 0; padding: 5px; border: 1px solid var(--hairline-strong); border-radius: 4px; }
.export-panel { padding: 0 12px 12px; }
.export-panel .panel-head { margin: 0 -12px 12px; }
.export-panel label { font-size: 12px; display: block; margin-bottom: 6px; }
.export-panel select { width: 100%; padding: 8px; border: 1px solid var(--hairline-strong); border-radius: 4px; background: white; margin-bottom: 10px; }
#exportBtn { width: 100%; }
#importReport { font-size: 12px; padding: 12px; }
#importReport summary { cursor: pointer; }
#importMessages { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.8; margin-top: 8px; max-height: 240px; overflow: auto; }
#footer { gap: 16px; justify-content: space-between; }
#footerFile { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pwaStatus { flex-shrink: 0; color: var(--graphite); }
#toast { white-space: pre-wrap; max-width: min(560px, 90vw); }
dialog { width: min(820px, 95vw); max-height: 85vh; border: 1px solid var(--hairline); border-radius: 12px; padding: 24px; color: var(--ink); line-height: 1.8; font-size: 13px; }
dialog::backdrop { background: #171b2266; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dialog-heading h2 { margin: 0; font-size: 20px; }
dialog table { border-collapse: collapse; width: 100%; }
dialog td, dialog th { text-align: left; padding: 8px; border-bottom: 1px solid var(--hairline); vertical-align: top; }
dialog td:first-child { white-space: nowrap; }
dialog pre { overflow: auto; background: var(--paper); padding: 12px; border-radius: 5px; }
@media (max-width: 800px) {
  body { overflow: auto; height: auto; min-height: 100dvh; }
  #toolbar { position: sticky; top: 0; z-index: 10; padding: 10px; }
  #toolbar .brand { flex-basis: 100%; font-size: 14px; }
  #main { flex-direction: column; }
  #plotWrap { flex: none; height: 48vh; min-height: 300px; margin: 10px; }
  #side { width: 100%; padding: 0 10px 10px; overflow: visible; }
  #footer { position: sticky; bottom: 0; background: var(--panel); font-size: 10px; padding: 8px 10px; }
  #pwaStatus { max-width: 42%; overflow: hidden; text-overflow: ellipsis; }
  #emptyState { padding: 12px; gap: 8px; }
  #emptyState h1 { font-size: 18px; }
  .btn { min-height: 34px; }
  .roi-input { min-height: 34px; }
}

.file-row .remove { display: flex; width: 24px; height: 24px; cursor: pointer; }
