/* Photo Lab: colour tokens (light, then dark), the top bar, the library, develop (sides, stage, panel), controls,
   dialogs and menus, then phones. */

:root {
    --bg: #ffffff;
    --bg-2: #f4f4f2;
    --bg-3: #ebebe8;
    --ink: #2b2a27;
    --ink-2: #6f6e69;
    --ink-3: #8c8b86;
    --line: #e4e3df;
    --hover: rgba(0, 0, 0, 0.05);
    --accent: #3b63fb;
    --accent-ink: #ffffff;
    --accent-soft: rgba(59, 99, 251, 0.12);
    --danger: #e03e3e;
    --stage: #9a9a9e;
    --star: #e5a50a;
    --shadow: 0 10px 32px rgba(0, 0, 0, 0.16), 0 1px 3px rgba(0, 0, 0, 0.12);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #232325;
        --bg-2: #1b1b1d;
        --bg-3: #2c2c2f;
        --ink: #ededeb;
        --ink-2: #a9a8a4;
        --ink-3: #8a8984;
        --line: #38383b;
        --hover: rgba(255, 255, 255, 0.07);
        --accent: #6d8cff;
        --accent-soft: rgba(109, 140, 255, 0.18);
        --stage: #3a3a3d;
        --shadow: 0 10px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #232325;
    --bg-2: #1b1b1d;
    --bg-3: #2c2c2f;
    --ink: #ededeb;
    --ink-2: #a9a8a4;
    --ink-3: #8a8984;
    --line: #38383b;
    --hover: rgba(255, 255, 255, 0.07);
    --accent: #6d8cff;
    --accent-soft: rgba(109, 140, 255, 0.18);
    --stage: #3a3a3d;
    --shadow: 0 10px 32px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg-2);
    color: var(--ink);
    font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
select option { background: var(--bg); color: var(--ink); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.sl input[type="range"]:focus-visible { outline-offset: 3px; border-radius: 4px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 13px; margin: 0 0 12px; }
.keys kbd { font: 600 12px/1 ui-monospace, monospace; background: var(--bg-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 3px 6px; white-space: nowrap; justify-self: start; }
.keys-h { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); margin: 4px 0 6px; }
.ic { flex: none; display: block; }
.grow { flex: 1; }

/* Which bits show in which view */
body.in-lib .dev-only, body.in-dev .lib-only { display: none !important; }

/* ---------- Buttons and fields ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    white-space: nowrap;
}
.btn:hover { background: var(--bg-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: default; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--ink);
    text-decoration: none;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.on { background: var(--accent-soft); color: var(--accent); }
.icon-btn.sm { width: 24px; height: 24px; }
.icon-btn.sm .ic { width: 15px; height: 15px; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 99px;
    background: var(--bg);
    font-size: 13px;
    white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

select, input[type="text"], input[type="search"], input[type="number"] {
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--bg);
    min-width: 0;
}

.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; }
.field > span { font-size: 12px; color: var(--ink-2); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.small { font-size: 12px; color: var(--ink-2); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--bg); padding: 5px 10px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- Top bar ---------- */

#top {
    position: fixed;
    inset: 0 0 auto;
    height: 52px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    z-index: 20;
}
.home { display: flex; align-items: center; gap: 7px; color: var(--ink); text-decoration: none; font-weight: 600; padding: 4px 6px; border-radius: 8px; }
.home:hover { background: var(--hover); }
.logo { border-radius: 6px; }
.app-name { margin: 0 6px 0 4px; font-size: 16px; font-weight: 650; white-space: nowrap; }
.modes { display: flex; gap: 2px; background: var(--bg-2); padding: 3px; border-radius: 9px; margin-left: 6px; }
.modes button { border: 0; background: none; padding: 5px 13px; border-radius: 7px; font-weight: 500; color: var(--ink-2); }
.modes button.on { background: var(--bg); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
#dev-name { color: var(--ink-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; }

main { position: fixed; inset: 52px 0 0; display: flex; }

/* ---------- Library ---------- */

#lib-side, #dev-left {
    width: 220px;
    flex: none;
    overflow-y: auto;
    background: var(--bg);
    border-right: 1px solid var(--line);
    padding: 8px 0 20px;
}
.side-h {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 4px;
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-2);
}
.side-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 7px 14px;
    border: 0;
    background: none;
    text-align: left;
}
.side-item:hover { background: var(--hover); }
.side-item.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-item .n { margin-left: auto; color: var(--ink-3); font-size: 12px; font-weight: 400; }
.side-item.drop-on { outline: 2px dashed var(--accent); outline-offset: -2px; }

#lib-center { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#lib-bar { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg); position: relative; z-index: 4; }
#filter-btn { height: 32px; border-radius: 8px; }
#filter-btn b { background: var(--accent-ink); color: var(--accent); border-radius: 99px; min-width: 18px; height: 18px; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }
#filters { position: absolute; top: calc(100% + 4px); left: 14px; width: 280px; padding: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 8; }
#filters .field select { width: 100%; }
#filters-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 29; }
#lib-count { white-space: nowrap; }
.search { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; background: var(--bg); flex: 0 1 300px; min-width: 120px; color: var(--ink-2); }
.search input { border: 0; height: 32px; padding: 0; flex: 1; background: none; color: var(--ink); outline: none; }
#thumb-size { width: 110px; }

#grid {
    --cell: 180px;
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--cell), 1fr));
    gap: 10px;
    align-content: start;
    outline: none;
}
.cell {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    background: var(--bg-3);
    overflow: hidden;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.cell img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }

/* Wide screens: rows of photos in their own shape, each row filling the width */
#grid.fit { display: flex; flex-wrap: wrap; gap: 8px; }
#grid.fit::after { content: ""; flex: 999 1 0; }
#grid.fit .cell { aspect-ratio: auto; height: var(--cell); flex: var(--ar) 1 calc(var(--ar) * var(--cell)); max-width: calc(var(--ar) * var(--cell) * 1.6); }
#grid.fit .cell img { object-fit: cover; }
.no-match { grid-column: 1 / -1; width: 100%; text-align: center; padding: 30px; display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.cell.sel { outline: 3px solid var(--accent); outline-offset: -3px; }
.cell.cur { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.cell.rejected img { opacity: 0.35; }
.cell .meta {
    position: absolute;
    inset: auto 0 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 18px 8px 6px;
    font-size: 12px;
    color: #fff;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
    opacity: 0;
    transition: opacity 0.12s;
}
.cell:hover .meta, .cell.sel .meta, .cell .meta.keep { opacity: 1; }
.cell .stars { color: #ffd34d; display: inline-flex; }
.cell .stars i { font-style: normal; padding: 0 1px; }
.cell .stars i:not(.on) { display: none; }
.cell .flag { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; border-radius: 5px; }
.cell .flag:not(.set) { display: none; }
@media (hover: hover) {
    /* Hovering a cell: every star and the flag can be clicked */
    .cell:hover .stars i:not(.on) { display: inline; color: rgba(255, 255, 255, 0.55); }
    .cell:hover .stars i { cursor: pointer; }
    .cell:hover .stars i:hover { color: #ffd34d; transform: scale(1.2); }
    .cell:hover .flag { display: inline-flex; cursor: pointer; }
    .cell .flag:hover { background: rgba(255, 255, 255, 0.2); }
}
.cell .badges { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.cell .badge { background: rgba(0, 0, 0, 0.55); color: #fff; border-radius: 5px; padding: 1px 5px; font-size: 11px; font-weight: 600; }
.cell .label { position: absolute; top: 6px; left: 6px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; }
.cell .check { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; background: rgba(0, 0, 0, 0.25); display: none; }
body.selecting .cell .check { display: block; }
.cell.sel .check { background: var(--accent); border-color: var(--accent); }
.lbl-red { background: #e5484d; } .lbl-yellow { background: #f5c400; } .lbl-green { background: #30a46c; } .lbl-blue { background: #3e63dd; } .lbl-purple { background: #8e4ec6; }

#lib-empty { position: absolute; inset: 60px 0 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }
#lib-empty h2 { margin: 12px 0 6px; }
#lib-empty p { max-width: 440px; color: var(--ink-2); margin: 0 0 14px; }
.empty-art { color: var(--accent); }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-bottom: 14px; }
#drop-hint { position: absolute; inset: 10px; border: 3px dashed var(--accent); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 600; background: var(--accent-soft); z-index: 5; pointer-events: none; }

body.no-info #lib-info { display: none; }
.mosaic { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; margin-bottom: 10px; }
.mosaic img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 4px; background: var(--bg-3); display: block; }
#lib-info { width: 260px; flex: none; overflow-y: auto; background: var(--bg); border-left: 1px solid var(--line); padding: 14px; }
#lib-info h3 { margin: 0 0 4px; font-size: 14px; word-break: break-all; }
#lib-info .preview { width: 100%; border-radius: 8px; background: var(--bg-3); display: block; margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: 80px 1fr; gap: 4px 8px; font-size: 13px; margin: 10px 0; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; word-break: break-word; }

.rate { display: inline-flex; align-items: center; gap: 1px; }
.rate button { border: 0; background: none; padding: 2px; color: var(--ink-3); font-size: 17px; line-height: 1; }
.rate button.on { color: var(--star); }
.flags { display: inline-flex; gap: 2px; }
.flags button.on.pick { color: var(--accent); background: var(--accent-soft); }
.flags button.on.reject { color: var(--danger); background: rgba(224, 62, 62, 0.12); }
.labels { display: inline-flex; gap: 6px; }
.labels button { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.labels button.on { border-color: var(--ink); }
.labels .none { background: var(--bg-3); }

#sel-bar {
    position: absolute;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    z-index: 6;
    max-width: calc(100vw - 24px);
    overflow-x: auto;
}
#sel-bar .count { padding: 0 8px; font-weight: 600; white-space: nowrap; }
#sel-bar .btn { height: 32px; }

/* ---------- Develop ---------- */

#dev-left { width: 230px; }
#stage-col { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--stage); }
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; }
#view, #ovl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ovl { cursor: default; }
#compare-label { position: absolute; top: 10px; left: 0; right: 0; display: flex; justify-content: space-around; pointer-events: none; }
#compare-label span { background: rgba(0, 0, 0, 0.55); color: #fff; padding: 2px 9px; border-radius: 6px; font-size: 12px; }
#slide-tip { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.62); color: #fff; padding: 4px 12px; border-radius: 99px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; pointer-events: none; white-space: nowrap; }
#busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
#busy i { width: 34px; height: 34px; border: 3px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#stage-bar { display: flex; align-items: center; gap: 2px; padding: 4px 8px; background: var(--bg); border-top: 1px solid var(--line); }
#stage-bar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
#stage-bar #rate-bar { display: flex; align-items: center; gap: 10px; }

#film-grip { height: 5px; margin-bottom: -5px; position: relative; z-index: 2; cursor: ns-resize; flex: none; }
#film-grip:hover { background: var(--accent-soft); }
#film { --film: 78px; display: flex; gap: 4px; padding: 6px; overflow-x: auto; background: var(--bg-2); border-top: 1px solid var(--line); height: var(--film); flex: none; }
#film button { flex: none; height: 100%; aspect-ratio: 1; border: 2px solid transparent; border-radius: 6px; padding: 0; background: var(--bg-3); overflow: hidden; position: relative; }
#film .fs { position: absolute; left: 2px; bottom: 2px; font-size: 10px; line-height: 1; color: #ffd34d; background: rgba(0, 0, 0, 0.55); padding: 2px 3px; border-radius: 3px; }
#film .fe { position: absolute; right: 3px; top: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1.5px #fff; }
#film .ff { position: absolute; left: 2px; top: 2px; color: #fff; background: rgba(0, 0, 0, 0.55); border-radius: 3px; padding: 1px; display: flex; }
#film button img { width: 100%; height: 100%; object-fit: cover; display: block; }
#film button.cur { border-color: var(--accent); }
#film button.sel:not(.cur) { border-color: var(--ink-3); }

#dev-right { width: 320px; flex: none; display: flex; flex-direction: column; background: var(--bg); border-left: 1px solid var(--line); min-height: 0; }
#hist { width: 100%; height: 110px; display: block; background: var(--bg-2); flex: none; }
#hist-info { font-size: 11px; color: var(--ink-2); text-align: center; padding: 2px 6px; min-height: 18px; flex: none; }
#tools { display: flex; justify-content: space-around; padding: 4px 8px; border-bottom: 1px solid var(--line); border-top: 1px solid var(--line); flex: none; }
#tools button { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 0; background: none; padding: 5px 8px; border-radius: 8px; font-size: 11px; color: var(--ink-2); }
#tools button.on { background: var(--accent-soft); color: var(--accent); }
#panel { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 20px; }
#panel-foot { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); flex: none; }
#panel-foot .btn { flex: 1; justify-content: center; padding: 0 4px; }
#panel-foot .icon-btn { width: 34px; height: 28px; flex: none; }

/* Wide screens: the sections' icons above them (jump to one) */
.sec-index { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 1px; padding: 4px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.sec-index .icon-btn { width: 30px; height: 30px; color: var(--ink-2); position: relative; }
.sec-index .icon-btn.open { color: var(--ink); }
.sec-index .icon-btn.dot::after { content: ""; position: absolute; right: 4px; top: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }

/* Panel sections */
.sec { border-bottom: 1px solid var(--line); }
.sec > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after { content: ""; margin-left: auto; width: 7px; height: 7px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); transition: transform 0.15s; }
.sec[open] > summary::after { transform: rotate(-135deg); }
.sec > summary .icon-btn { margin: -6px 0; }
.sec-body { padding: 0 14px 12px; }
.sub-h { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); margin: 10px 0 2px; display: flex; align-items: center; gap: 6px; }
.sub-h .grow + * { margin-left: auto; }

/* A slider row: name, value, then the track */
.sl { display: grid; grid-template-columns: 1fr 52px; align-items: center; gap: 0 6px; padding: 3px 0; }
.sl label { font-size: 13px; color: var(--ink); cursor: default; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sl .val { width: 52px; height: 22px; padding: 0 4px; border: 1px solid transparent; border-radius: 5px; background: none; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.sl .val:focus { border-color: var(--line); background: var(--bg); color: var(--ink); outline: none; }
.sl.changed label { font-weight: 600; }
.sl.changed .val { color: var(--ink); }
.sl input[type="range"] { grid-column: 1 / -1; width: 100%; margin: 2px 0 0; height: 18px; background: none; -webkit-appearance: none; appearance: none; touch-action: pan-y; }
.sl input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: var(--track, var(--line)); }
.sl input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: var(--track, var(--line)); }
.sl input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: var(--bg); border: 2px solid var(--ink-2); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }
.sl input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--bg); border: 2px solid var(--ink-2); }
.sl.changed input[type="range"]::-webkit-slider-thumb { border-color: var(--accent); }

.tr-temp { --track: linear-gradient(90deg, #3d7bd9, #d9d9d9, #e6b234); }
.tr-tint { --track: linear-gradient(90deg, #36b24a, #d9d9d9, #c548c4); }
.tr-sat { --track: linear-gradient(90deg, #888, #e94a4a); }
.tr-dark { --track: linear-gradient(90deg, #111, #eee); }

.tool-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.tool-row .btn { flex: 1 1 auto; justify-content: center; }
.note { font-size: 12px; color: var(--ink-2); margin: 6px 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; }

/* Tone curve and wheels */
.curve-box { position: relative; margin: 6px 0; }
.curve-box canvas { width: 100%; aspect-ratio: 1; display: block; background: var(--bg-2); border-radius: 6px; touch-action: none; cursor: crosshair; }
.wheels { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.wheels.one { grid-template-columns: 1fr; max-width: 180px; margin: 0 auto; }
.wheel { text-align: center; font-size: 12px; color: var(--ink-2); }
.wheel canvas { width: 100%; aspect-ratio: 1; display: block; touch-action: none; cursor: pointer; }

/* Lists in the left column */
.list-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 14px; border: 0; background: none; text-align: left; font-size: 13px; }
.list-item:hover { background: var(--hover); }
.list-item.on { background: var(--accent-soft); color: var(--accent); }
.list-item.future { color: var(--ink-3); }
.list-item .x { margin-left: auto; opacity: 0; }
.list-item:hover .x { opacity: 1; }
.preset-group > summary { padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; }
.preset-group > summary::-webkit-details-marker { display: none; }
.preset-group > summary::before { content: "▸"; color: var(--ink-3); font-size: 11px; }
.preset-group[open] > summary::before { content: "▾"; }
.preset-group .list-item { padding-left: 28px; }
.preset-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 6px; padding: 4px 12px 10px; }
.preset-tile { position: relative; border: 0; background: none; padding: 0; text-align: left; font-size: 12px; color: var(--ink-2); min-width: 0; }
.preset-tile img, .preset-tile .ph { display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 6px; background: var(--bg-3); border: 2px solid transparent; margin-bottom: 2px; }
.preset-tile:hover img { border-color: var(--line); }
.preset-tile.on img { border-color: var(--accent); }
.preset-tile.on { color: var(--accent); font-weight: 600; }
.preset-tile .nm { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-tile .x { position: absolute; top: 4px; right: 4px; background: var(--bg); opacity: 0; }
.preset-tile:hover .x { opacity: 1; }
.preset-amount { padding: 4px 14px 8px; }

/* Phones: the sections of Edit as chips */
.sec-chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -14px 6px; padding: 2px 14px 6px; scrollbar-width: none; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.sec-chips::-webkit-scrollbar { display: none; }
.sec-chips .chip { flex: none; position: relative; }
.sec-chips .chip.dot::after { content: ""; position: absolute; top: 3px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.sec-chips .chip.on.dot::after { background: var(--accent-ink); }

/* Phones: rating, flag and label behind one button */
.rate-chip { gap: 4px; padding: 0 10px; height: 34px; }
.rate-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.rate-pop { position: fixed; z-index: 60; display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.rate-pop .rate button { font-size: 26px; padding: 4px 5px; }
.rate-pop .flags .icon-btn { width: 40px; height: 40px; }
.rate-pop .labels { gap: 12px; }
.rate-pop .labels button { width: 28px; height: 28px; }

/* Masks */
.part-btns { display: inline-flex; gap: 2px; }
.part-btns .icon-btn { font-size: 15px; font-weight: 700; }
.mask-list { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.mask-item { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.mask-item.on { border-color: var(--accent); background: var(--accent-soft); }
.mask-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; border: 0; background: none; text-align: left; padding: 3px 2px; }
.comp-list { margin: 4px 0 8px 14px; display: flex; flex-direction: column; gap: 2px; }
.comp-item { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 6px; border-radius: 6px; border: 0; background: none; text-align: left; width: 100%; }
.comp-item.on { background: var(--bg-3); font-weight: 600; }
.comp-item .mode { width: 16px; text-align: center; color: var(--ink-2); font-weight: 700; }
.new-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0; }
.new-grid .btn { justify-content: flex-start; }

/* Phones' preset strip */
.preset-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; }
.preset-strip button { flex: none; width: 76px; border: 0; background: none; padding: 0; font-size: 11px; text-align: center; color: var(--ink-2); }
.preset-strip img, .preset-strip .ph { width: 76px; height: 76px; object-fit: cover; border-radius: 8px; display: block; margin-bottom: 3px; background: var(--bg-3); border: 2px solid transparent; }
.preset-strip button.on img { border-color: var(--accent); }

/* ---------- Dialogs, menus, toast ---------- */

.dlg-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.dlg { background: var(--bg); border-radius: 14px; box-shadow: var(--shadow); width: 420px; max-width: 100%; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.dlg.wide { width: 640px; }
.dlg header { display: flex; align-items: center; padding: 12px 12px 4px 18px; }
.dlg h2 { margin: 0; font-size: 16px; flex: 1; }
.dlg-body { padding: 8px 18px; overflow-y: auto; }
.dlg-body p { margin: 0 0 10px; }
.dlg footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; }
.dlg .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.dlg .checks { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; }
.pos-grid { display: grid; grid-template-columns: repeat(3, 26px); gap: 3px; }
.pos-grid button { width: 26px; height: 20px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg-2); padding: 0; }
.pos-grid button.on { background: var(--accent); border-color: var(--accent); }

.pop-menu { position: fixed; z-index: 60; min-width: 190px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; }
.pop-menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px; background: none; text-align: left; }
.pop-menu button:hover { background: var(--hover); }
.pop-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

#toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translate(-50%, 20px);
    background: var(--ink);
    color: var(--bg);
    padding: 9px 16px;
    border-radius: 10px;
    font-size: 13px;
    max-width: calc(100vw - 32px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s, transform 0.18s;
    z-index: 70;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.in-lib:has(#sel-bar:not([hidden])) #toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
.phone-sort { display: none; }

.phone-only { display: none !important; }

/* ---------- Narrower screens ---------- */

/* The left column: shown on wide screens (the sidebar button hides it); on narrower ones it slides over the photo */
body.left-toggled #dev-left { display: none; }
#b-left.on, body.left-toggled #b-left { color: var(--accent); }

@media (max-width: 1180px) {
    #lib-info { display: none; }
    #dev-right { width: 290px; }
    #dev-left { display: none; }
    body.left-toggled #dev-left { display: block; position: absolute; inset: 0 auto 0 0; width: 240px; z-index: 10; box-shadow: var(--shadow); }
}

/* ---------- Phones ---------- */

@media (max-width: 767px) {
    .wide-only { display: none !important; }
    .phone-only { display: inline-flex !important; }
    #top { height: 50px; padding: 0 6px; gap: 2px; }
    main { top: 50px; }
    .app-name { font-size: 15px; }
    body.in-dev .app-name { display: none; }
    #dev-name { max-width: 34vw; }
    #import span { display: none; }
    #import { padding: 0 10px; }
    .home { padding: 4px; gap: 4px; }

    #lib-side {
        position: fixed;
        inset: 50px auto 0 0;
        width: 260px;
        z-index: 30;
        box-shadow: var(--shadow);
        transform: translateX(-105%);
        transition: transform 0.2s;
    }
    body.side-open #lib-side { transform: none; }
    #lib-bar { padding: 8px; gap: 6px; z-index: auto; }
    .phone-sort { display: flex; }
    #lib-bar .grow { display: none; }
    #filters .phone-sort select { width: 100%; }
    #side-toggle { max-width: 130px; }
    #side-toggle span { overflow: hidden; text-overflow: ellipsis; }
    .search { flex: 1 1 0; min-width: 0; }
    #filter-btn { flex: none; padding: 0 10px; }
    #filters {
        position: fixed;
        inset: auto 0 0;
        width: auto;
        border-radius: 16px 16px 0 0;
        padding: 6px 16px calc(16px + env(safe-area-inset-bottom));
        z-index: 30;
    }
    .filters-h { display: flex !important; justify-content: center; padding: 4px 0 10px; font-size: 15px; }
    #filters select { height: 40px; }
    #filters .btn { height: 40px; padding: 0 18px; }
    /* Square cells filling the width; pinch for 2 to 6 columns */
    #grid { padding: 2px; gap: 2px; grid-template-columns: repeat(var(--cols, 3), 1fr); }
    .cell { border-radius: 0; }
    .cell img { object-fit: cover; }
    .cell.sel { outline-width: 3px; }
    .cell.cur { box-shadow: none; }
    .cell .meta { opacity: 0; padding: 14px 5px 3px; font-size: 11px; background: linear-gradient(transparent, rgba(0, 0, 0, 0.45)); pointer-events: none; }
    .cell .meta.keep { opacity: 1; }

    #dev { flex-direction: column; }
    #dev-left { display: none; }
    #stage-col { flex: 1; min-height: 0; }
    #film { display: none; }
    #stage-bar { padding: 2px 4px; gap: 0; }
    #stage-bar .icon-btn { width: 40px; height: 40px; }
    #stage-bar .sep { margin: 0 2px; }
    #b-zoom { display: none; }
    #dev-right {
        width: auto;
        height: 42dvh;
        border-left: 0;
        border-top: 1px solid var(--line);
        flex: none;
    }
    #sheet-grip { display: flex !important; justify-content: center; align-items: center; height: 22px; flex: none; touch-action: none; cursor: ns-resize; }
    #sheet-grip i { width: 40px; height: 4px; border-radius: 2px; background: var(--ink-3); }
    #hist, #hist-info, #tools { display: none; }
    #panel-foot { display: none; }
    #tabs {
        display: flex !important;
        order: 3;
        flex: none;
        gap: 2px;
        overflow-x: auto;
        padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
        background: var(--bg);
        border-top: 1px solid var(--line);
        scrollbar-width: none;
    }
    #tabs::-webkit-scrollbar { display: none; }
    #tabs button { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; border: 0; background: none; padding: 6px 2px; border-radius: 8px; font-size: 11px; color: var(--ink-2); }
    #tabs button.on { color: var(--accent); background: var(--accent-soft); }
    .sec > summary { display: none; }
    .sec { border: 0; }
    .sec-body { padding: 2px 14px 12px; }
    .sl { padding: 4px 0; }
    .sl input[type="range"] { height: 26px; }
    .sl input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -9.5px; }
    .wheels { grid-template-columns: 1fr 1fr 1fr; }
    .curve-box canvas { max-height: 30dvh; aspect-ratio: auto; height: 30dvh; }
    body.in-dev #toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
    .dlg { max-height: calc(100dvh - 24px); }
    .dlg .grid2 { grid-template-columns: 1fr; }
    /* Choosing several: a bar docked at the bottom, icons over short names */
    #sel-bar { position: fixed; left: 0; right: 0; bottom: 0; transform: none; max-width: none; border-radius: 0; border-width: 1px 0 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 0; scrollbar-width: none; z-index: 25; }
    #sel-bar::-webkit-scrollbar { display: none; }
    #sel-bar .count { flex: none; padding: 0 8px 0 6px; font-size: 13px; }
    #sel-bar .btn { flex: none; flex-direction: column; gap: 2px; height: auto; min-width: 54px; padding: 6px 4px; border: 0; background: none; font-size: 11px; }
    #sel-bar .btn .ic { width: 20px; height: 20px; }
    body.selecting #grid { padding-bottom: 76px; }
}
