/* Neutral greys throughout so the UI doesn't bias color judgments. */
:root {
    color-scheme: dark;
    --bg: #1e1e1e;
    --panel: #262626;
    --card: #2d2d2d;
    --line: #3c3c3c;
    --text: #e6e6e6;
    --muted: #9a9a9a;
    --accent: #4d9be6;
    --accent-ink: #ffffff;
    --danger: #e0645c;
    --control: #383838;
    --control-hover: #444444;
    --viewer-bg: #181818;
    --plot-bg: #202020;
    --plot-grid: #363636;
    --plot-text: #bdbdbd;
    --plot-hist: rgba(255, 255, 255, 0.09);
    --plot-ink: #0d0d0d;
    --rainbow-0: #ff5a52; --rainbow-1: #ff9d3a; --rainbow-2: #ffd93d; --rainbow-3: #4cd964;
    --rainbow-4: #4aa8ff; --rainbow-5: #7b7bff; --rainbow-6: #c77dff;
    --radius: 6px;
    font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: light) {
    :root {
        color-scheme: light;
        --bg: #e8e8e8;
        --panel: #f2f2f2;
        --card: #fafafa;
        --line: #d2d2d2;
        --text: #1d1d1d;
        --muted: #6b6b6b;
        --accent: #1f6fbf;
        --control: #e4e4e4;
        --control-hover: #d8d8d8;
        --viewer-bg: #cfcfcf;
        --plot-bg: #ffffff;
        --plot-grid: #e2e2e2;
        --plot-text: #555555;
        --plot-hist: rgba(0, 0, 0, 0.08);
        --plot-ink: #1d1d1d;
        --rainbow-0: #d62828; --rainbow-1: #e8740c; --rainbow-2: #c9a400; --rainbow-3: #2a9d3a;
        --rainbow-4: #1f6fd1; --rainbow-5: #4b3fc4; --rainbow-6: #8e3bc4;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); display: flex; flex-direction: column; overflow: hidden; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }

button, select, input {
    font: inherit; color: var(--text); background: var(--control);
    border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 10px; min-height: 28px;
}
button { cursor: pointer; }
button:hover:not(:disabled), select:hover { background: var(--control-hover); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.1); background: var(--accent); }
button.danger { color: var(--danger); }
button.icon { width: 28px; padding: 0; font-weight: 600; border-radius: 50%; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=number] { width: 64px; padding: 3px 6px; }

/* Top bar */
.topbar {
    display: flex; align-items: center; gap: 16px; padding: 8px 14px;
    background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-size: 16px; margin: 0; font-weight: 700; letter-spacing: 0.2px; }
/* Rainbow letters, cycling by index. */
.brand .r0 { color: var(--rainbow-0); } .brand .r1 { color: var(--rainbow-1); } .brand .r2 { color: var(--rainbow-2); }
.brand .r3 { color: var(--rainbow-3); } .brand .r4 { color: var(--rainbow-4); } .brand .r5 { color: var(--rainbow-5); }
.brand .r6 { color: var(--rainbow-6); }
.group { display: flex; align-items: center; gap: 8px; }
.group label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.spacer { flex: 1; }

main { flex: 1; display: flex; min-height: 0; }

/* Image viewer */
.viewer { position: relative; flex: 1; min-width: 0; background: var(--viewer-bg); overflow: hidden; touch-action: none; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.stage canvas { display: block; }
.stage.pixelated canvas { image-rendering: pixelated; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.viewer.panning { cursor: grabbing; }
.viewer.loaded { cursor: crosshair; }
.empty {
    position: absolute; inset: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    border: 2px dashed var(--line); border-radius: 12px; text-align: center; font-size: 15px;
}
.empty p { margin: 4px 0; }
.viewer.dragover .empty { border-color: var(--accent); }
.viewer-toolbar {
    position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 6px;
    background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line);
    border-radius: 8px; padding: 5px 8px; max-width: calc(100% - 24px); flex-wrap: wrap;
}
.viewer-toolbar button, .viewer-toolbar select { min-height: 26px; padding: 2px 8px; }
.sep { width: 1px; height: 18px; background: var(--line); margin: 0 2px; }
#zoom-label { min-width: 44px; text-align: right; }
.progress {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 10px;
    background: var(--panel); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Side panel */
.panel {
    width: 340px; flex: none; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line);
    padding: 10px; display: flex; flex-direction: column; gap: 10px;
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.card h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.row { display: flex; gap: 8px; }
.row.end { justify-content: flex-end; }
.actions .row button { flex: 1; }
.status { margin: 8px 0 0; min-height: 1.4em; }

.palette { display: flex; gap: 6px; min-height: 44px; }
.palette button {
    position: relative; flex: 1; height: 44px; padding: 0; border-radius: 6px; border: 1px solid rgba(0,0,0,0.3);
}
.palette button:hover { filter: brightness(1.08); }
.palette button.selected { outline: 2px solid var(--text); outline-offset: 2px; }
.palette button .pin {
    position: absolute; right: 3px; top: 3px; width: 10px; height: 10px; border-radius: 50%;
    background: #fff; border: 2px solid #111;
}
.palette button .label {
    position: absolute; left: 4px; bottom: 2px; font-size: 10px; color: #fff; text-shadow: 0 0 3px #000, 0 0 2px #000;
}

.ab-details { margin-top: 10px; }
.ab-details summary { cursor: pointer; color: var(--muted); font-size: 12px; user-select: none; }
.ab-details summary:hover { color: var(--text); }
.ab-view { display: block; width: 100%; aspect-ratio: 1; margin-top: 8px; border-radius: 6px; touch-action: none;
    background: repeating-conic-gradient(var(--control) 0 25%, var(--card) 0 50%) 0 0 / 12px 12px; }
.ab-slice { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.ab-slice input { flex: 1; min-height: 0; padding: 0; border: none; background: none; accent-color: var(--accent); }
.ab-slice output { width: 2em; text-align: right; font-variant-numeric: tabular-nums; }

.chips { display: flex; gap: 6px; margin-bottom: 8px; }
.chips button {
    flex: 1; height: 22px; min-height: 22px; padding: 0; border-radius: 11px; border: 2px solid transparent;
}
.chips button[aria-checked=true] { border-color: var(--text); }
.curves { width: 100%; aspect-ratio: 1; display: block; border-radius: 6px; cursor: crosshair; touch-action: none; }

.selection-title { margin: 0 0 8px; font-weight: 600; }
.compare-swatches { display: flex; gap: 8px; margin-bottom: 10px; }
.compare-swatches > div { flex: 1; display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 11px; }
.swatch { height: 34px; border-radius: 6px; border: 1px solid rgba(0,0,0,0.3); }
#delete-btn { width: 100%; margin-top: 10px; }
.curve-fields { display: flex; gap: 12px; }
.curve-fields label { display: flex; align-items: center; gap: 6px; color: var(--muted); }

/* Lab picker */
.labpicker { display: flex; flex-direction: column; gap: 8px; }
.lp-plane-wrap { position: relative; width: 100%; aspect-ratio: 1; border-radius: 6px; overflow: hidden; cursor: crosshair; touch-action: none;
    background: repeating-conic-gradient(var(--control) 0 25%, var(--card) 0 50%) 0 0 / 12px 12px; }
.lp-plane { width: 100%; height: 100%; display: block; image-rendering: auto; }
.lp-marks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.lp-axis { stroke: rgba(0,0,0,0.25); stroke-width: 0.3; }
.lp-handle, .lp-ref { position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; pointer-events: none; }
.lp-handle { border: 2px solid #fff; box-shadow: 0 0 0 1.5px #000, 0 1px 4px rgba(0,0,0,0.5); }
.lp-ref { width: 10px; height: 10px; margin: -5px 0 0 -5px; border: 1.5px dashed #000; background: rgba(255,255,255,0.5); }
.lp-l-wrap { position: relative; height: 16px; border-radius: 8px; overflow: visible; cursor: ew-resize; touch-action: none; }
.lp-l-wrap.locked { opacity: 0.4; cursor: default; }
.lp-l { width: 100%; height: 100%; display: block; border-radius: 8px; }
.lp-l-handle { position: absolute; top: -3px; width: 8px; height: 22px; margin-left: -4px; border-radius: 3px; border: 2px solid #fff; box-shadow: 0 0 0 1.5px #000; pointer-events: none; }
.lp-fields { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lp-fields label { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.lp-fields input { width: 58px; }
.lp-hex { margin-left: auto; color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.lp-gamut-note { color: var(--muted); font-size: 11px; }

dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px; max-width: 560px; padding: 18px 22px; }
dialog::backdrop { background: rgba(0,0,0,0.45); }
dialog h2 { margin-top: 0; }
dialog a { color: var(--accent); }
dialog li { margin-bottom: 4px; }

@media (max-width: 800px) {
    body { overflow: auto; }
    main { flex-direction: column; }
    .viewer { min-height: 60vh; }
    .panel { width: 100%; border-left: none; border-top: 1px solid var(--line); overflow: visible; }
    .topbar { gap: 8px; }
}
