/* =========================================================
   Photo color grading — tokens, shell, editor & panels
   Matches the site's dark glass language used by exif.html.
   ========================================================= */

:root {
    --bg: #0a0c10;
    --text: #e9edf3;
    --muted: #8b94a3;
    --line: rgba(255, 255, 255, .09);
    --line-soft: rgba(255, 255, 255, .055);
    --accent: #6ea8fe;
    --accent-2: #9d7bff;
    --good: #3ddc97;
    --danger: #ff7b8a;
    --radius: 16px;
    --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", monospace;
    --demo-split: 50%;
    --demo-left-mid: 25%;
    --demo-right-mid: 75%;
}

* { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    scrollbar-gutter: stable;
}
html::-webkit-scrollbar { width: 4px; height: 4px; }
html::-webkit-scrollbar-track { background-color: #1b1f22; }
html::-webkit-scrollbar-thumb { background: #4e4e4e; border-radius: 2px; }
html::-webkit-scrollbar-thumb:hover { background: #6a6a6a; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    line-height: 1.5;
    background:
        radial-gradient(1100px 700px at 10% -12%, rgba(110, 168, 254, .16), transparent 60%),
        radial-gradient(900px 620px at 105% 8%, rgba(157, 123, 255, .14), transparent 55%),
        radial-gradient(900px 560px at 50% 118%, rgba(61, 220, 151, .07), transparent 60%),
        var(--bg);
    background-attachment: fixed;
}

body::before,
body::after {
    content: "";
    position: fixed;
    z-index: -2;
    width: 56vmax;
    height: 56vmax;
    border-radius: 50%;
    pointer-events: none;
    filter: blur(72px);
    opacity: .55;
}
body::before {
    top: -24vmax;
    left: -14vmax;
    background: radial-gradient(circle, rgba(110, 168, 254, .3), rgba(110, 168, 254, 0) 66%);
    animation: aurora-a 19s ease-in-out infinite alternate;
}
body::after {
    right: -18vmax;
    bottom: -28vmax;
    background: radial-gradient(circle, rgba(157, 123, 255, .26), rgba(157, 123, 255, 0) 66%);
    animation: aurora-b 24s ease-in-out infinite alternate;
}
@keyframes aurora-a { to { transform: translate3d(9vmax, 7vmax, 0) scale(1.1); } }
@keyframes aurora-b { to { transform: translate3d(-8vmax, -6vmax, 0) scale(1.14); } }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }

.glass {
    background-color: rgba(16, 19, 25, 0);
    background-image: linear-gradient(180deg, rgba(255, 255, 255, .075), rgba(255, 255, 255, .04));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    backdrop-filter: blur(18px) saturate(1.12);
    -webkit-backdrop-filter: blur(18px) saturate(1.12);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .07);
    transition: background-color .55s ease;
}
body.has-photo-bg .glass { background-color: rgba(14, 17, 23, .62); }

@keyframes rise-in {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: none; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes title-sheen {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}
@keyframes ring-pulse {
    0% { transform: scale(.9); opacity: .55; }
    70%, 100% { transform: scale(1.2); opacity: 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .05);
    color: var(--text);
    font-size: 13px;
    white-space: nowrap;
    transition: background .16s ease, border-color .16s ease, transform .16s ease, box-shadow .2s ease;
}
.btn:hover { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .18); }
.btn:active { transform: translateY(1px); }
.btn.primary {
    border-color: rgba(110, 168, 254, .5);
    background: linear-gradient(135deg, rgba(110, 168, 254, .26), rgba(157, 123, 255, .22));
    box-shadow: 0 6px 20px rgba(110, 168, 254, .14);
}
.btn.primary:hover {
    background: linear-gradient(135deg, rgba(110, 168, 254, .38), rgba(157, 123, 255, .32));
    box-shadow: 0 8px 28px rgba(110, 168, 254, .28);
}
.btn.danger {
    border-color: rgba(255, 123, 138, .5);
    background: rgba(255, 123, 138, .14);
    color: #ffd9de;
}
.btn.danger:hover {
    background: rgba(255, 123, 138, .24);
    border-color: rgba(255, 123, 138, .68);
}
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn.is-pressed { background: rgba(110, 168, 254, .24); border-color: rgba(110, 168, 254, .55); }
#compareBtn { touch-action: none; user-select: none; -webkit-user-select: none; }

.spinner {
    width: 10px;
    height: 10px;
    border: 1.5px solid rgba(255, 255, 255, .2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    flex: none;
}

/* ---------- photo backdrop ---------- */
.photo-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
    background: var(--bg);
    opacity: 0;
    transition: opacity .55s ease;
}
.photo-bg.show { opacity: 1; }
.photo-bg-layer {
    position: absolute;
    inset: -4vmax;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0;
    transform: scale(1.04);
    filter: saturate(1.08) brightness(.82);
    transition: opacity .7s ease;
}
.photo-bg-layer.visible { opacity: 1; }
.photo-bg-shade {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(120% 90% at 50% 12%, rgba(10, 12, 16, .04), rgba(10, 12, 16, .4) 82%),
        linear-gradient(180deg, rgba(10, 12, 16, .16), rgba(10, 12, 16, .48)),
        linear-gradient(135deg, rgba(110, 168, 254, .1), rgba(157, 123, 255, .08) 55%, transparent);
}

/* ---------- corner icon — identical to worldforge.html ---------- */
.gallery_icon {
    display: block;
    position: absolute;
    top: 16px;
    right: 16px;
    width: 53.3333px;
    height: 53.3333px;
    cursor: pointer;
    border-radius: 100%;
    text-indent: 4rem;
    overflow: hidden;
    white-space: nowrap;
    background-size: 20px 20px;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 9998;
}
.gallery_icon::before {
    content: '';
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 100%;
    background-color: var(--background-color, rgba(255, 255, 255, 0));
    transition: background-color .2s ease-in-out;
}
.gallery_icon:hover::before { background-color: rgba(255, 255, 255, .15); }
.gallery_icon:active::before { background-color: rgba(255, 255, 255, .3); }

.cg-exit {
    position: fixed;
    top: 16px;
    left: auto;
    right: calc(16px - (100vw - 100%));
    background-image: url('../../images/exit-w.png');
}
@media screen and (max-width: 1680px) {
    .gallery_icon { top: 12px; right: 12px; width: 40px; height: 40px; }
    .cg-exit { top: 12px; right: calc(12px - (100vw - 100%)); }
}
@media screen and (max-width: 736px) {
    .gallery_icon { top: 12.8333px; right: 12.8333px; width: 33px; height: 33px; background-size: 14px 14px; }
    .cg-exit { top: 12.8333px; right: calc(12.8333px - (100vw - 100%)); }
}
@media screen and (max-width: 360px) {
    .gallery_icon { top: 11.6667px; right: 11.6667px; width: 30px; height: 30px; }
    .cg-exit { top: 11.6667px; right: calc(11.6667px - (100vw - 100%)); }
}

/* =========================================================
   Split comparison backdrop (landing page)
   ========================================================= */
.grade-demo {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
    background: var(--bg);
    opacity: 0;
    visibility: hidden;
    transition: opacity .9s ease, visibility 0s linear .9s;
}
.grade-demo.show {
    opacity: 1;
    visibility: visible;
    transition: opacity .9s ease;
}
.grade-demo-layer {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}
.grade-demo-layer.graded {
    clip-path: inset(0 calc(100% - var(--demo-split)) 0 0);
    -webkit-clip-path: inset(0 calc(100% - var(--demo-split)) 0 0);
}
.grade-demo.css-grade .grade-demo-layer.graded {
    filter: saturate(1.38) contrast(1.14) brightness(1.04) sepia(.08) hue-rotate(-6deg);
}

/* The hi-res pair is decoded first, then cross-faded over the thumbnail
   layers so replacing the background never flashes. */
.grade-demo-layer.hi {
    opacity: 0;
    transition: opacity .38s ease;
}
.grade-demo-layer.hi.show { opacity: 1; }
/* The hi-res original must not sit over the graded half while fading in,
   otherwise the left side briefly mixes back towards the original. */
.grade-demo-layer.hi.original {
    clip-path: inset(0 0 0 var(--demo-split));
    -webkit-clip-path: inset(0 0 0 var(--demo-split));
}
.grade-demo-line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--demo-split);
    width: 1px;
    margin-left: -.5px;
    background: rgba(255, 255, 255, .55);
    box-shadow: 0 0 20px rgba(0, 0, 0, .4), 0 0 2px rgba(255, 255, 255, .35);
}
.grade-demo-shade {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(120% 72% at 50% 42%, rgba(10, 12, 16, .02) 32%, rgba(10, 12, 16, .32) 100%),
        linear-gradient(180deg, rgba(10, 12, 16, .7) 0%, rgba(10, 12, 16, .4) 22%,
            rgba(10, 12, 16, .18) 46%, rgba(10, 12, 16, .32) 72%, rgba(10, 12, 16, .68) 100%);
}

.grade-demo-ui {
    position: fixed;
    inset: 0;
    z-index: 6;
    pointer-events: none;
}
.grade-demo-ui.show { animation: fade-in .9s .18s ease both; }
.demo-tag {
    position: absolute;
    top: max(74px, calc(env(safe-area-inset-top) + 64px));
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .13);
    background: rgba(8, 11, 16, .5);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    font-size: 10.5px;
    letter-spacing: .12em;
    line-height: 1;
    color: #c7d0dd;
    white-space: nowrap;
}
.demo-tag::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
}
.demo-tag-graded {
    left: var(--demo-left-mid);
    color: #a9c8ff;
}
.demo-tag-original {
    left: var(--demo-right-mid);
    color: #b7bfca;
}
.demo-handle {
    position: absolute;
    left: var(--demo-split);
    bottom: max(18px, calc(env(safe-area-inset-bottom) + 10px));
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 38px;
    padding: 0 16px 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, .2);
    background: rgba(10, 14, 21, .68);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    backdrop-filter: blur(16px) saturate(1.2);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .42), inset 0 1px 0 rgba(255, 255, 255, .12);
    color: #edf3fb;
    font-size: 12px;
    letter-spacing: .04em;
    line-height: 1;
    white-space: nowrap;
    cursor: ew-resize;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.demo-handle:hover,
.grade-demo-ui.is-dragging .demo-handle {
    background: rgba(18, 26, 40, .84);
    border-color: rgba(110, 168, 254, .55);
    box-shadow: 0 12px 36px rgba(0, 0, 0, .46), 0 0 0 4px rgba(110, 168, 254, .08),
        inset 0 1px 0 rgba(255, 255, 255, .14);
}
.demo-handle:focus-visible {
    outline: 2px solid rgba(110, 168, 254, .8);
    outline-offset: 3px;
}
.demo-handle svg { width: 16px; height: 16px; color: var(--accent); flex: none; }
body.demo-dragging { cursor: ew-resize; user-select: none; -webkit-user-select: none; }

/* keep the reading layer legible over a photographic backdrop */
body.has-demo-bg .intro h1 { filter: drop-shadow(0 2px 18px rgba(0, 0, 0, .5)); }
body.has-demo-bg .intro p { color: #c2ccda; text-shadow: 0 1px 14px rgba(0, 0, 0, .75); }
body.has-demo-bg .feature-row span {
    background: rgba(9, 12, 17, .52);
    border-color: rgba(255, 255, 255, .1);
    color: #aeb8c6;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
body.has-demo-bg .dropzone {
    background:
        radial-gradient(520px 280px at 50% 0%, rgba(110, 168, 254, .14), transparent 72%),
        linear-gradient(160deg, rgba(17, 23, 33, .62), rgba(8, 11, 17, .48));
    -webkit-backdrop-filter: blur(12px) saturate(1.18);
    backdrop-filter: blur(12px) saturate(1.18);
}
body.has-demo-bg .dropzone:hover,
body.has-demo-bg .dropzone:focus-visible {
    background:
        radial-gradient(540px 300px at 50% 0%, rgba(110, 168, 254, .2), transparent 72%),
        linear-gradient(160deg, rgba(23, 31, 44, .68), rgba(10, 14, 21, .52));
}

@media (prefers-reduced-motion: reduce) {
    .grade-demo,
    .grade-demo.show,
    .grade-demo-layer.hi,
    .grade-demo-ui.show {
        animation: none;
        transition: none;
    }
}

/* =========================================================
   Empty state
   ========================================================= */
.empty-view {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 80px 24px;
}
.empty-inner {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 860px;
    pointer-events: none;
}
.empty-inner .intro,
.empty-inner .dropzone,
.empty-inner .batch-import,
.empty-inner .privacy,
.empty-inner .feature-row { pointer-events: auto; }

.intro {
    max-width: 760px;
    margin: 0 auto 28px;
    text-align: center;
    animation: rise-in .65s cubic-bezier(.2, .75, .25, 1) both;
}
.intro h1 {
    margin: 0;
    font-size: 32px;
    font-weight: 600;
    letter-spacing: .02em;
    background: linear-gradient(105deg, #ffffff 8%, #bcd4ff 38%, #ded0ff 62%, #ffffff 92%);
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: title-sheen 10s ease-in-out infinite;
}
.intro p { margin: 9px auto 0; max-width: 660px; font-size: 13.5px; line-height: 1.6; color: var(--muted); }
.intro .intro-stats { margin-top: 12px; font-variant-numeric: tabular-nums; }
.intro-stats span { color: var(--accent); font-weight: 600; }

.dropzone {
    min-height: 330px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 40px 28px;
    text-align: center;
    border: 1.5px dashed rgba(255, 255, 255, .26);
    border-radius: 26px;
    background:
        radial-gradient(520px 280px at 50% 0%, rgba(110, 168, 254, .16), transparent 72%),
        linear-gradient(160deg, rgba(22, 28, 39, .46), rgba(9, 12, 18, .28));
    -webkit-backdrop-filter: blur(8px) saturate(1.22);
    backdrop-filter: blur(8px) saturate(1.22);
    cursor: pointer;
    outline: none;
    box-shadow: 0 30px 90px rgba(0, 0, 0, .36), inset 0 1px 0 rgba(255, 255, 255, .06),
        0 0 70px rgba(110, 168, 254, .06);
    animation: fade-in .6s .06s ease both;
    transition: border-color .22s ease, background .22s ease, transform .22s ease, box-shadow .22s ease;
}
.dropzone:hover, .dropzone:focus-visible {
    border-color: rgba(110, 168, 254, .68);
    background:
        radial-gradient(540px 300px at 50% 0%, rgba(110, 168, 254, .22), transparent 72%),
        linear-gradient(160deg, rgba(28, 35, 48, .5), rgba(11, 15, 22, .32));
    transform: translateY(-3px);
    box-shadow: 0 32px 84px rgba(0, 0, 0, .34), 0 0 0 4px rgba(110, 168, 254, .06),
        0 0 64px rgba(110, 168, 254, .15), inset 0 1px 0 rgba(255, 255, 255, .07);
}
.dropzone .drop-icon {
    position: relative;
    width: 66px;
    height: 66px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    margin-bottom: 14px;
    background: linear-gradient(135deg, rgba(110, 168, 254, .2), rgba(157, 123, 255, .18));
    border: 1px solid rgba(110, 168, 254, .35);
    box-shadow: 0 10px 30px rgba(110, 168, 254, .18);
    transition: transform .3s cubic-bezier(.2, .8, .2, 1), box-shadow .3s ease;
}
.dropzone:hover .drop-icon {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 14px 38px rgba(110, 168, 254, .28);
}
.dropzone .drop-icon::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 1px solid rgba(110, 168, 254, .28);
    animation: ring-pulse 3.2s ease-out infinite;
    pointer-events: none;
}
.dropzone .drop-icon svg { width: 30px; height: 30px; color: var(--accent); }
.dropzone h2 { margin: 0; font-size: 21px; font-weight: 600; text-shadow: 0 0 26px rgba(110, 168, 254, .18); }
.dropzone p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.dropzone .link { color: var(--accent); border-bottom: 1px solid rgba(110, 168, 254, .5); padding-bottom: 1px; }
.formats { margin-top: 18px; font-size: 11px; letter-spacing: .16em; color: rgba(139, 148, 163, .8); text-transform: uppercase; }

.batch-import { margin-top: 14px; text-align: center; }

.feature-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 18px;
    animation: fade-in .6s .12s ease both;
}
.feature-row span {
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .03);
    font-size: 11.5px;
    letter-spacing: .04em;
    color: var(--muted);
}

.privacy {
    width: max-content;
    max-width: calc(100% - 32px);
    margin: 16px auto 0;
    padding: 6px 14px;
    border-radius: 999px;
    text-align: center;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    background: rgba(10, 13, 18, .42);
    border: 1px solid rgba(255, 255, 255, .05);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    animation: fade-in .6s .18s ease both;
}
.privacy svg { width: 13px; height: 13px; color: var(--good); }
.privacy-short { display: none; }

/* =========================================================
   Workspace
   ========================================================= */
.workspace {
    /* Scrollable height of the tool panel. The photo library is capped to the
       same value so the two cards end on the same line. */
    --panel-h: calc(100vh - 150px);
    max-width: 1680px;
    margin: 0 auto;
    padding: 64px 22px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 100vh;
}

.cg-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 12px 10px 16px;
    min-height: 60px;
    animation: fade-in .45s ease both;
}
.cg-file { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.cg-file-name {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cg-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* Separates the history pair from the destructive reset action. */
.cg-actions-sep {
    flex: none;
    width: 1px;
    height: 22px;
    margin: 0 6px;
    background: rgba(255, 255, 255, .16);
}
.select {
    height: 34px;
    padding: 0 8px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .05);
    font-size: 12px;
    outline: none;
}
.select:focus { border-color: rgba(110, 168, 254, .55); }
.select option { background: #141820; color: var(--text); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .03);
    color: var(--muted);
    font-family: var(--mono);
}

.cg-body {
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr) 366px;
    gap: 16px;
    align-items: start;
    flex: 1;
}

/* ---------- photo library ---------- */
.cg-sidebar {
    position: sticky;
    top: 74px;
    /* +2px: the tool panel's card adds a border on top and bottom. */
    max-height: calc(var(--panel-h) + 2px);
    display: flex;
    flex-direction: column;
    animation: fade-in .45s ease both;
}

.cg-side-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex: none;
    padding: 8px 8px 8px 13px;
    border-bottom: 1px solid var(--line);
    font-size: 10.5px;
    letter-spacing: .12em;
    color: var(--muted);
    text-transform: uppercase;
    white-space: nowrap;
}
.cg-side-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cg-count { font-family: var(--mono); letter-spacing: 0; }
.cg-side-actions { display: flex; align-items: center; gap: 4px; flex: none; }

.btn.small {
    height: 28px;
    padding: 0 9px;
    border-radius: 8px;
    font-size: 11.5px;
    gap: 5px;
}
.btn.small svg { width: 13px; height: 13px; }
.btn.icon-only { width: 28px; padding: 0; justify-content: center; }
.btn.ghost {
    background: transparent;
    border-color: transparent;
    color: var(--muted);
}
.btn.ghost:hover { background: rgba(255, 255, 255, .07); color: var(--text); }

.cg-file-list {
    /* Reach past the card's left border, like the tool panel does on the
       right, so the scrollbar hangs in the page margin instead of over the
       thumbnails. JS replaces the fallback with the measured gutter. */
    width: calc(100% + var(--rail-extra, 12px));
    min-width: 0;
    margin-left: calc(-1 * var(--rail-extra, 12px));
    padding: 8px 8px 8px 10px;
    /* The vertical scrollbar follows the inline direction, so RTL moves it to
       the left edge. Cards get their own direction back below. */
    direction: rtl;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .16) transparent;
}
.cg-file-list::-webkit-scrollbar { width: 8px; height: 8px; }
.cg-file-list::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 255, 255, .16);
    border: 2px solid transparent;
    background-clip: padding-box;
}
.cg-file-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, .26);
    background-clip: padding-box;
}

.cg-file-item {
    direction: ltr;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 20px;
    gap: 9px;
    align-items: center;
    padding: 8px;
    margin-bottom: 3px;
    border-radius: 11px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, box-shadow .2s ease, transform .15s ease;
}
.cg-file-item:hover { background: rgba(255, 255, 255, .05); transform: translateX(2px); }
.cg-file-item.active {
    background: rgba(110, 168, 254, .13);
    border-color: rgba(110, 168, 254, .38);
    box-shadow: 0 6px 20px rgba(40, 80, 160, .12);
}
.cg-file-item:focus-visible { outline: 2px solid rgba(110, 168, 254, .6); outline-offset: 1px; }

.cg-file-thumb {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    background: #12151c;
    border: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 8.5px;
    color: var(--muted);
    letter-spacing: .04em;
}
.cg-thumb-ext {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
}
.cg-file-thumb img {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cg-file-meta { min-width: 0; }
.cg-file-name {
    font-size: 12px;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cg-file-sub {
    margin-top: 3px;
    font-size: 10.5px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    overflow: hidden;
}
.cg-file-sub .dot { opacity: .5; }
.cg-file-sub .err { color: var(--danger); }
.cg-file-sub .edited { color: var(--accent); }

.cg-file-remove {
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    opacity: 0;
    transition: opacity .15s ease, background .15s ease, color .15s ease;
}
.cg-file-remove svg { width: 12px; height: 12px; }
.cg-file-remove:hover { background: rgba(255, 123, 138, .16); color: var(--danger); }
.cg-file-item:hover .cg-file-remove,
.cg-file-item:focus-within .cg-file-remove { opacity: 1; }
@media (hover: none) {
    .cg-file-remove { opacity: .72; }
}

/* ---------- stage ---------- */
.cg-stage {
    min-width: 0;
    /* Match the two glass cards (+2px borders) so all three columns end on
       the same line; the canvas area below takes the remaining height. */
    height: calc(var(--panel-h) + 2px);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fade-in .45s ease both;
}
.cg-canvas-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(100vh - 240px);
    flex: 1 1 auto;
    min-height: 360px;
    border-radius: 12px;
    overflow: hidden;
    background: radial-gradient(120% 100% at 50% 0%, #121722, #080a0e 72%);
    border: 1px solid var(--line-soft);
}
#previewCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .5);
}
/* Transparent direct-manipulation layer for the active mask. JS positions
   it exactly over the preview canvas, DPR-scaled. */
.cg-mask-overlay {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 3;
    opacity: 0;
    pointer-events: none;
    touch-action: none;
    transition: opacity .15s ease;
}
.cg-mask-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}
/* Temporarily faded out while a slider is being adjusted. The layer stays
   interactive so the user can grab the mask again immediately. */
.cg-mask-overlay.peeking { opacity: 0; }

/* Spot repair overlay sits above the mask tint. */
.cg-spot-overlay {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 4;
    opacity: 0;
    pointer-events: none;
    touch-action: none;
    transition: opacity .15s ease;
}
.cg-spot-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}
body.geometry-editing .cg-spot-overlay {
    opacity: 0 !important;
    pointer-events: none !important;
}
/* While retouching, the red mask tint would hide the blemishes. */
body.spot-editing .cg-mask-overlay {
    opacity: 0 !important;
    pointer-events: none !important;
}
body.spot-dragging {
    user-select: none;
    -webkit-user-select: none;
}
body.spot-dragging * {
    user-select: none !important;
    -webkit-user-select: none !important;
}

body.mask-dragging {
    user-select: none;
    -webkit-user-select: none;
}
body.mask-dragging * {
    user-select: none !important;
    -webkit-user-select: none !important;
}
/* Grid / crop rectangle layer. It sits above the mask handles and takes
   over the picture while crop or straighten is being edited. */
.cg-geometry-overlay {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 4;
    opacity: 0;
    pointer-events: none;
    touch-action: none;
    transition: opacity .15s ease;
}
.cg-geometry-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}
/* The mask overlay would sit under the crop grid and respond to drags. */
body.geometry-editing .cg-mask-overlay {
    opacity: 0 !important;
    pointer-events: none !important;
}
/* Leave a small matte around the picture so crop handles that sit on the
   border can be drawn whole, centred on the guide line. */
body.geometry-editing .cg-canvas-wrap { padding: 10px; }
body.geometry-dragging {
    user-select: none;
    -webkit-user-select: none;
}
body.geometry-dragging * {
    user-select: none !important;
    -webkit-user-select: none !important;
}
/* Zoom / pan controls floating over the lower-right corner of the stage. */
.cg-zoom {
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(10, 14, 20, .74);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, .35);
    user-select: none;
    -webkit-user-select: none;
}
.cg-zoom[hidden] { display: none; }
.cg-zoom button {
    min-width: 26px;
    height: 24px;
    padding: 0 6px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 11.5px;
    line-height: 1;
    cursor: pointer;
    transition: background .14s ease, color .14s ease;
}
.cg-zoom button:hover {
    background: rgba(255, 255, 255, .08);
    color: var(--text);
}
.cg-zoom button:disabled { opacity: .38; cursor: default; }
.cg-zoom button:disabled:hover { background: transparent; color: var(--muted); }
.cg-zoom .cg-zoom-val { min-width: 44px; color: var(--text); }
.cg-zoomed #previewCanvas { cursor: grab; }
.cg-pan-ready #previewCanvas,
.cg-pan-ready .cg-mask-overlay { cursor: grab !important; }
.cg-panning,
.cg-panning * { cursor: grabbing !important; }
.cg-stage-foot {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 4px 2px;
    font-size: 11.5px;
    color: var(--muted);
}
.cg-stage-foot .mono { font-size: 11px; }
.cg-stage-foot kbd {
    font-family: var(--mono);
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 5px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .05);
}

/* ---------- panel ---------- */
.cg-panel-wrap {
    position: sticky;
    top: 64px;
    animation: fade-in .45s ease both;
}
.cg-panel {
    /* Reach past the card's right border so the scrollbar lives in the page
       margin instead of taking width away from the sliders. */
    width: calc(100% + var(--panel-extra, 12px));
    padding-right: 2px;
    max-height: var(--panel-h);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .16) transparent;
}
.cg-panel::-webkit-scrollbar { width: 8px; }
.cg-panel::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 255, 255, .16);
    border: 2px solid transparent;
    background-clip: padding-box;
}
.cg-panel::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .26); background-clip: padding-box; }
/* Overlay scrollbars take no layout width, so the widened panel would let the
   sliders spill past the glass card. Keep it flush in that case. */
@media (min-width: 981px) {
    .has-overlay-scroll .cg-panel {
        width: 100%;
        padding-right: 0;
    }
}

/* histogram */
.cg-hist {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--line);
    background: rgba(13, 16, 22, .94);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-radius: var(--radius) var(--radius) 0 0;
}
.hist-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 11px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
}
.hist-head .clip { font-family: var(--mono); font-size: 10px; letter-spacing: 0; text-transform: none; }
#histogram {
    display: block;
    width: 100%;
    height: 108px;
    border-radius: 9px;
    background: #090c11;
    border: 1px solid var(--line-soft);
}
.hist-legend {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 7px;
    font-size: 10.5px;
    font-family: var(--mono);
    color: var(--muted);
}
.hist-legend .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.hist-legend .dot.r { background: #ff6b6b; }
.hist-legend .dot.g { background: #5ddc8a; }
.hist-legend .dot.b { background: #6ea8fe; }
.hist-legend .dot.l { background: #e9edf3; margin-left: 4px; }

/* presets */
.cg-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--line-soft);
}
.preset {
    height: 27px;
    padding: 0 8px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .04);
    font-size: 11px;
    color: #dfe6f1;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.preset:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .2); transform: translateY(-1px); }
.preset.active {
    background: rgba(110, 168, 254, .2);
    border-color: rgba(110, 168, 254, .55);
    color: #fff;
}

/* grading templates */
.cg-template {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 14px 11px;
    border-bottom: 1px solid var(--line-soft);
}
.cg-template-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.cg-template-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: #cfd7e4;
}
.cg-template-actions { display: flex; gap: 5px; flex: none; }
.cg-template-hint {
    margin: 0;
    font-size: 10.5px;
    line-height: 1.55;
    color: var(--muted);
}

/* sections */
.cg-controls { padding-bottom: 6px; }
.sec { border-bottom: 1px solid var(--line-soft); }
.sec > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    list-style: none;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: #cfd7e4;
    user-select: none;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary:hover { color: #fff; }
.sec > summary .chev {
    width: 14px;
    height: 14px;
    color: var(--muted);
    transition: transform .2s ease;
}
.sec[open] > summary .chev { transform: rotate(90deg); }
.sec > summary .sec-sub {
    margin-left: auto;
    font-size: 10px;
    letter-spacing: .04em;
    text-transform: none;
    color: var(--muted);
    font-weight: 400;
}
.sec-note {
    margin: 0 14px 4px;
    font-size: 11.5px;
    line-height: 1.65;
    color: var(--muted);
}

/* low-light auto analysis */
.repair-auto {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 2px 14px 8px;
}
.repair-auto .btn { flex: none; }
.repair-info {
    flex: 1;
    min-width: 0;
    font-size: 10.5px;
    line-height: 1.45;
    color: var(--muted);
    overflow: hidden;
}

/* local masks */
/* Three equal cells, each holding its button and help icon, so the icons
   never wrap onto a row of their own. */
.mask-toolbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 2px 14px 10px;
}
.mask-add-group {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}
.mask-add {
    flex: 1 1 auto;
    min-width: 0;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 8px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .04);
    color: #dfe6f1;
    font-size: 11.5px;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.mask-add svg { width: 14px; height: 14px; flex: none; }
.mask-add:hover {
    background: rgba(110, 168, 254, .14);
    border-color: rgba(110, 168, 254, .45);
    color: #fff;
}
.mask-list { display: flex; flex-direction: column; gap: 4px; padding: 0 14px 8px; }
.mask-empty {
    margin: 0 0 8px;
    font-size: 11.5px;
    line-height: 1.7;
    color: var(--muted);
}
.mask-chip {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: background .15s ease, border-color .15s ease;
}
.mask-chip.active {
    background: rgba(110, 168, 254, .12);
    border-color: rgba(110, 168, 254, .4);
}
.mask-chip.off .mask-name { color: var(--muted); }
.mask-pick {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 27px;
    padding: 0 7px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: #dfe6f1;
    font-size: 12px;
    text-align: left;
}
.mask-pick:hover { background: rgba(255, 255, 255, .05); }
.mask-ico {
    width: 14px;
    height: 14px;
    flex: none;
    border-radius: 50%;
    border: 1.5px solid var(--accent);
}
.mask-ico.linear {
    border: 0;
    border-radius: 3px;
    background: linear-gradient(90deg, rgba(110, 168, 254, .12), var(--accent));
}
.mask-ico.band {
    border: 0;
    border-radius: 2px;
    background: linear-gradient(180deg,
        rgba(110, 168, 254, .12) 0%,
        var(--accent) 38%,
        var(--accent) 62%,
        rgba(110, 168, 254, .12) 100%);
    transform: skewY(-18deg);
}
.mask-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mask-eye {
    width: 26px;
    height: 26px;
    flex: none;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--muted);
}
.mask-eye:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.mask-eye[aria-pressed="false"] { color: rgba(255, 255, 255, .3); }
.mask-eye svg { width: 15px; height: 15px; }
.mask-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 2px 14px 9px;
}

/* spot repair */
.mask-add.active,
.mask-add[aria-pressed="true"] {
    background: rgba(110, 168, 254, .18);
    border-color: rgba(110, 168, 254, .55);
    color: #fff;
}
.spot-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 2px 14px 8px;
}
.spot-toolbar .mask-add { flex: 0 1 auto; }
.spot-toolbar .mask-act { height: 30px; }
.spot-ico {
    width: 14px;
    height: 14px;
    flex: none;
    position: relative;
    border-radius: 50%;
    border: 1.5px solid var(--accent);
}
.spot-ico:after {
    content: '';
    position: absolute;
    inset: 3.5px;
    border-radius: 50%;
    background: var(--accent);
}
.mask-act {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .04);
    color: #dfe6f1;
    font-size: 11px;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.mask-act:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .2); }
.mask-act svg { width: 13px; height: 13px; flex: none; }
.mask-act[aria-pressed="true"] {
    background: rgba(110, 168, 254, .18);
    border-color: rgba(110, 168, 254, .55);
    color: #fff;
}
.mask-act.danger { color: var(--danger); border-color: rgba(255, 123, 138, .28); }
.mask-act.danger:hover {
    background: rgba(255, 90, 110, .14);
    border-color: rgba(255, 123, 138, .55);
}
.mask-subhead {
    padding: 9px 14px 2px;
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
}
.mask-geom { border-bottom: 1px solid var(--line-soft); padding-bottom: 2px; }
.mask-hint {
    margin: 1px 14px 7px;
    font-size: 11px;
    line-height: 1.6;
    color: var(--muted);
}

/* crop & straighten */
.geo-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 14px 9px;
}
.geo-tab {
    height: 28px;
    padding: 0 11px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .04);
    color: #dfe6f1;
    font-size: 11.5px;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.geo-tab:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .2); }
.geo-tab.active {
    background: rgba(110, 168, 254, .2);
    border-color: rgba(110, 168, 254, .58);
    color: #fff;
}
.geo-done {
    height: 28px;
    margin-left: auto;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid rgba(110, 168, 254, .45);
    background: linear-gradient(135deg, rgba(110, 168, 254, .24), rgba(157, 123, 255, .2));
    color: #fff;
    font-size: 11.5px;
    transition: background .15s ease, opacity .15s ease;
}
.geo-done:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(110, 168, 254, .38), rgba(157, 123, 255, .32));
}
.geo-done:disabled {
    opacity: .38;
    cursor: default;
}
.geo-subhead {
    padding: 9px 14px 2px;
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
}
.geo-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 2px 14px 8px;
}
.geo-act {
    height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .04);
    color: #dfe6f1;
    font-size: 11px;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.geo-act:hover { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .2); }
.geo-act.active {
    background: rgba(110, 168, 254, .18);
    border-color: rgba(110, 168, 254, .55);
    color: #fff;
}
.geo-ratio-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 14px 8px;
}
.geo-ratio-label {
    flex: none;
    font-size: 12px;
    color: #dfe6f1;
}
.geo-ratio-select {
    flex: 1;
    min-width: 0;
    height: 30px;
}
.geo-crop-size {
    flex: none;
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
}
.geo-hint {
    margin: 1px 14px 8px;
    font-size: 11px;
    line-height: 1.6;
    color: var(--muted);
}

/* Manual rotation angle, in 0.1° steps */
.geo-angle-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 0 14px 8px;
    margin-top: -3px;
}
.geo-angle-label {
    flex: none;
    font-size: 12px;
    color: #dfe6f1;
}
.geo-angle-input {
    width: 82px;
    height: 30px;
    padding: 0 8px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .05);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    text-align: right;
    outline: none;
    -moz-appearance: textfield;
    appearance: textfield;
}
.geo-angle-input::-webkit-outer-spin-button,
.geo-angle-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.geo-angle-input:focus {
    border-color: rgba(110, 168, 254, .55);
}
.geo-angle-unit {
    font-size: 12px;
    color: var(--muted);
}
.geo-angle-hint {
    font-size: 10.5px;
    color: var(--muted);
}

/* sliders */
.ctrl { padding: 7px 14px 9px; }
.ctrl-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 5px;
}
.ctrl-label { font-size: 12.5px; color: #dfe6f1; cursor: default; }
.ctrl-val {
    min-width: 46px;
    text-align: right;
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.ctrl-val.changed { color: var(--accent); }

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 18px;
    background: transparent;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, .12) var(--a, 0%),
        var(--accent) var(--a, 0%),
        var(--accent) var(--b, 0%),
        rgba(255, 255, 255, .12) var(--b, 0%));
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -5px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(110, 168, 254, .18), 0 2px 8px rgba(0, 0, 0, .5);
    transition: box-shadow .15s ease, transform .15s ease;
}
input[type="range"]:hover::-webkit-slider-thumb { box-shadow: 0 0 0 5px rgba(110, 168, 254, .24), 0 2px 10px rgba(0, 0, 0, .5); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.08); }
input[type="range"]::-moz-range-track {
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, .12) var(--a, 0%),
        var(--accent) var(--a, 0%),
        var(--accent) var(--b, 0%),
        rgba(255, 255, 255, .12) var(--b, 0%));
}
input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(110, 168, 254, .18), 0 2px 8px rgba(0, 0, 0, .5);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 5px rgba(110, 168, 254, .3), 0 2px 10px rgba(0, 0, 0, .5);
}

/* curve editor */
.curve-tabs { display: flex; gap: 6px; padding: 2px 14px 9px; }
.curve-tab {
    height: 25px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .04);
    font-size: 11px;
    font-family: var(--mono);
    color: var(--muted);
}
.curve-tab:hover { background: rgba(255, 255, 255, .1); }
.curve-tab.active { color: #111722; background: #fff; border-color: #fff; }
.curve-wrap { padding: 0 14px 12px; }
.curve-canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 9px;
    background: #090c11;
    border: 1px solid var(--line-soft);
    cursor: crosshair;
    touch-action: none;
}
.curve-tip { margin-top: 7px; font-size: 10.5px; color: var(--muted); line-height: 1.5; }

/* HSL */
.hsl-bands { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.hsl-band {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, .04);
    font-size: 11.5px;
    color: #dfe6f1;
}
.hsl-band i { width: 8px; height: 8px; border-radius: 50%; background: var(--band); }
.hsl-band:hover { background: rgba(255, 255, 255, .1); }
.hsl-band.active { border-color: rgba(255, 255, 255, .52); background: rgba(255, 255, 255, .14); }
.hsl-empty { padding: 0 14px 10px; font-size: 10.5px; color: var(--muted); }

/* =========================================================
   Overlays
   ========================================================= */
.drag-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(8, 10, 14, .8);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
    pointer-events: none;
}
.drag-overlay.show { display: flex; }
.drag-overlay div {
    padding: 46px 68px;
    border: 2px dashed rgba(110, 168, 254, .7);
    border-radius: 24px;
    background: rgba(110, 168, 254, .09);
    font-size: 19px;
    letter-spacing: .04em;
    box-shadow: 0 0 80px rgba(110, 168, 254, .18);
}

/* template import dialog */
.tmpl-modal {
    position: fixed;
    inset: 0;
    z-index: 9500;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(5, 7, 10, .62);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}
.tmpl-dialog {
    width: min(430px, 100%);
    padding: 18px 20px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(14, 17, 23, .96);
    box-shadow: 0 28px 80px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .07);
    animation: rise-in .18s ease;
}
.tmpl-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.tmpl-kicker {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--muted);
}
.tmpl-close {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    transition: background .15s ease, color .15s ease;
}
.tmpl-close:hover { background: rgba(255, 255, 255, .08); color: var(--text); }
.tmpl-close svg { width: 15px; height: 15px; }
.tmpl-dialog h3 {
    margin: 10px 0 5px;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.35;
    word-break: break-word;
}
.tmpl-meta {
    margin: 0;
    font-size: 12px;
    line-height: 1.6;
    color: var(--muted);
}
.tmpl-warn {
    margin: 10px 0 0;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(240, 182, 107, .1);
    border: 1px solid rgba(240, 182, 107, .24);
    font-size: 11.5px;
    line-height: 1.55;
    color: #f0c48b;
}
.tmpl-actions {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
    margin-top: 18px;
    flex-wrap: wrap;
}
.export-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    background: rgba(5, 7, 10, .58);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}
.export-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 26px;
    font-size: 13.5px;
    color: var(--text);
}
.export-card .spinner { width: 18px; height: 18px; border-width: 2px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 30px;
    z-index: 300;
    transform: translate(-50%, 20px);
    padding: 10px 20px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(24, 28, 36, .94);
    box-shadow: 0 14px 40px rgba(0, 0, 0, .45);
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    max-width: min(90vw, 560px);
    text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1280px) {
    .cg-body { grid-template-columns: 210px minmax(0, 1fr) 330px; }
}

@media (max-width: 1120px) {
    .cg-body { grid-template-columns: 196px minmax(0, 1fr) 318px; gap: 12px; }
}

@media (max-width: 980px) {
    .workspace { padding: 62px 14px 16px; }
    .cg-body { grid-template-columns: 1fr; }
    .cg-sidebar {
        position: static;
        max-height: none;
        /* Clip the horizontal filmstrip to the card's rounded corners. */
        overflow: hidden;
    }
    .cg-file-list {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px;
        /* The rail only applies to the vertical desktop list. */
        width: auto;
        margin-left: 0;
        direction: ltr;
        scrollbar-gutter: auto;
    }
    .cg-file-item {
        flex: 0 0 220px;
        margin-bottom: 0;
    }
    .cg-stage { height: auto; }
    .cg-canvas-wrap { height: auto; min-height: 0; }
    #previewCanvas { max-height: 58vh; }
    .cg-panel-wrap { position: static; }
    .cg-panel {
        width: auto;
        padding-right: 0;
        max-height: none;
        overflow: visible;
    }
    .cg-hist { position: static; }
    .cg-topbar { flex-wrap: wrap; }
    .cg-actions { flex-wrap: wrap; }
}

@media (max-width: 720px) {
    .empty-view { padding: 72px 14px 40px; }
    .intro h1 { font-size: 24px; }
    .intro p { font-size: 12.5px; }
    .dropzone { min-height: 280px; padding: 32px 20px; border-radius: 20px; }
    .dropzone h2 { font-size: 18px; }
    .privacy { font-size: 11.5px; }
    .privacy-full { display: none; }
    .privacy-short { display: inline; }
    .feature-row span { font-size: 10.5px; padding: 4px 10px; }
    #previewCanvas { max-height: 54vh; }
    .cg-stage-foot .hint { display: none; }
    .cg-file-name { font-size: 13.5px; }
    .cg-actions { gap: 6px; }
    .cg-actions .btn { height: 32px; padding: 0 10px; font-size: 12px; }
    .select { height: 32px; font-size: 11px; }
    .cg-file-item { flex: 0 0 190px; }
}

@media (max-width: 420px) {
    .cg-actions { width: 100%; }
    .cg-actions .btn { flex: 1; justify-content: center; }
    .cg-actions .select { flex: none; }
    .cg-actions-sep { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

/* =========================================================
   Inline parameter help
   ========================================================= */
.ctrl-name {
    display: flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
}
.ctrl-name .ctrl-label { min-width: 0; }

.cg-info {
    width: 17px;
    height: 17px;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 1px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: rgba(188, 201, 220, .46);
    cursor: help;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s ease, background .15s ease;
}
.cg-info svg { display: block; width: 13px; height: 13px; }
.cg-info:hover,
.cg-info:focus-visible,
.cg-info[aria-expanded="true"] {
    color: rgba(230, 238, 250, .96);
    background: rgba(255, 255, 255, .08);
}
.cg-info:focus-visible { outline: none; box-shadow: 0 0 0 2px rgba(110, 168, 254, .45); }

.hist-title,
.cg-template-label { display: inline-flex; align-items: center; gap: 2px; }
.cg-presets .cg-info { align-self: center; }
.curve-tip { display: flex; align-items: flex-start; gap: 3px; }
.curve-tip span { flex: 1; }
.curve-tip .cg-info { margin-top: -2px; }
.mask-toolbar .cg-info,
.mask-actions .cg-info,
.geo-tools .cg-info,
.geo-actions .cg-info { align-self: center; }
.geo-ratio-name { flex: none; gap: 3px; }

.cg-help-pop {
    position: fixed;
    z-index: 400;
    width: max-content;
    max-width: min(312px, calc(100vw - 20px));
    padding: 11px 13px 12px;
    border: 1px solid rgba(255, 255, 255, .13);
    border-radius: 10px;
    background: rgba(13, 16, 22, .975);
    box-shadow: 0 16px 44px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .06);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    color: #c4cfdd;
    font-size: 11.5px;
    line-height: 1.72;
    animation: cg-help-in .12s ease;
}
.cg-help-pop[hidden] { display: none; }
.cg-help-pop::after {
    content: "";
    position: absolute;
    left: var(--arrow, 50%);
    bottom: -5px;
    width: 9px;
    height: 9px;
    margin-left: -5px;
    transform: rotate(45deg);
    background: #0f1218;
    border-right: 1px solid rgba(255, 255, 255, .13);
    border-bottom: 1px solid rgba(255, 255, 255, .13);
}
.cg-help-pop.below::after {
    bottom: auto;
    top: -5px;
    border: 0;
    border-left: 1px solid rgba(255, 255, 255, .13);
    border-top: 1px solid rgba(255, 255, 255, .13);
}
.cg-help-title {
    margin-bottom: 5px;
    font-size: 12px;
    font-weight: 600;
    color: #eef3fb;
}
.cg-help-body p { margin: 0 0 6px; }
.cg-help-body p:last-child { margin-bottom: 0; }
.cg-help-body b { font-weight: 600; color: #dfe7f3; }
.cg-help-body sup {
    font-size: .72em;
    line-height: 0;
    vertical-align: super;
}
.cg-help-note {
    margin: 7px 0 0;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, .09);
    font-size: 11px;
    color: #9fabbe;
}

@keyframes cg-help-in {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: none; }
}
