/* Layout: one-screen tool. Top bar (path, find, view), a single virtual scroller, a thin status line. */
:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1d2422;
  --muted: #6c7773;
  --line: #dde2dd;
  --accent: #0b6b7a;
  --accent-ink: #ffffff;
  --bullet: #56615d;
  --halo: #d3dad5;
  --hl: #ffe08a;
  --hl-ink: #2a2100;
  --hl-cur: #ff9a3d;
  --cur-bg: #fff6df;
  --mark: #c08400;
  --done: #98a29e;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #131817; --panel: #1b2221; --ink: #e3e9e6; --muted: #8d9995; --line: #2b3432;
    --accent: #63c7d6; --accent-ink: #0c1415; --bullet: #a3aeaa; --halo: #37423f;
    --hl: #6e5600; --hl-ink: #fff3c9; --hl-cur: #c7650e; --cur-bg: #2a2617; --mark: #e0aa2e; --done: #68736f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131817; --panel: #1b2221; --ink: #e3e9e6; --muted: #8d9995; --line: #2b3432;
  --accent: #63c7d6; --accent-ink: #0c1415; --bullet: #a3aeaa; --halo: #37423f;
  --hl: #6e5600; --hl-ink: #fff3c9; --hl-cur: #c7650e; --cur-bg: #2a2617; --mark: #e0aa2e; --done: #68736f;
}

[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/22px var(--sans); overflow: hidden; }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }

/* ---- top bar ---- */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.crumbs { display: flex; align-items: center; gap: 2px; flex: 1 1 200px; min-width: 0; overflow: hidden; white-space: nowrap; }
.crumbs button {
  border: 0; background: none; padding: 4px 6px; border-radius: 6px; cursor: pointer;
  max-width: 18ch; overflow: hidden; text-overflow: ellipsis; color: var(--muted);
}
.crumbs button:hover { background: var(--bg); color: var(--ink); }
.crumbs button.here { color: var(--ink); font-weight: 600; cursor: default; }
.crumbs .sep { color: var(--muted); opacity: .6; }

.find {
  display: flex; align-items: center; gap: 2px; flex: 3 1 300px; min-width: 0;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 2px 3px 2px 10px;
}
.find:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent); }
#q { flex: 1; min-width: 0; border: 0; background: none; font: inherit; color: inherit; outline: none; padding: 5px 0; }
#q::placeholder { color: var(--muted); }
.count { font: 12px var(--mono); color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; padding: 0 6px; }
.ib { border: 0; background: none; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; color: var(--muted); padding: 0; }
.ib:hover { background: var(--panel); color: var(--ink); }
#filter { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 2px 10px; height: 28px; cursor: pointer; font-size: 13px; }
#filter[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { border: 0; background: var(--panel); padding: 5px 12px; cursor: pointer; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.tools { display: none; gap: 4px; flex: 1 1 100%; overflow-x: auto; }
.tools button { flex: none; min-width: 40px; height: 34px; border: 1px solid var(--line); background: var(--bg); border-radius: 6px; }
@media (pointer: coarse) { .tools.on { display: flex; } }

/* ---- scroller ---- */
.stage { position: relative; min-height: 0; }
#scroller { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; overflow-anchor: none; outline: none; }
#spacer { position: relative; overflow: hidden; }
#rows { position: absolute; top: 0; left: 0; right: 0; margin-inline: auto; width: min(100%, 920px); --ind: 26px; will-change: transform; }
.album #rows { width: min(100%, 1280px); }
@media (max-width: 560px) { #rows { --ind: 16px; } }
#map { position: absolute; top: 0; bottom: 0; right: var(--sbw, 0px); width: 10px; height: 100%; cursor: pointer; }
#empty { position: absolute; left: 0; right: 0; top: 30%; text-align: center; color: var(--muted); padding: 0 24px; pointer-events: none; }

/* ---- outline rows ---- */
.row { position: relative; display: flex; align-items: flex-start; min-height: 30px; padding: 0 44px 0 calc(10px + var(--d, 0) * var(--ind)); }
.row::before {
  content: ""; position: absolute; left: 11px; top: 0; bottom: 0; width: calc(var(--d, 0) * var(--ind)); pointer-events: none;
  background: repeating-linear-gradient(to right, transparent 0 calc(var(--ind) - 1px), var(--line) calc(var(--ind) - 1px) var(--ind));
}
.tog { flex: none; width: 18px; height: 30px; border: 0; background: none; padding: 0; cursor: pointer; color: var(--muted); visibility: hidden; opacity: 0; }
.row.kids .tog { visibility: visible; }
.row:hover .tog, .row:focus-within .tog { opacity: 1; }
@media (pointer: coarse) { .row.kids .tog { opacity: 1; } }
.tog::before {
  content: ""; display: block; margin: 0 auto; width: 6px; height: 6px;
  border-right: 1.5px solid; border-bottom: 1.5px solid; transform: translateY(-2px) rotate(45deg); transition: transform .12s;
}
.row.closed .tog::before { transform: translateX(-2px) rotate(-45deg); }
.row.part .tog::before { border-style: dotted; }
.dot { flex: none; width: 18px; height: 30px; display: grid; place-items: center; cursor: pointer; }
.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--bullet); }
.row.closed .dot::before { box-shadow: 0 0 0 4px var(--halo); }
.dot:hover::before { background: var(--accent); }
.body { flex: 1; min-width: 0; padding-left: 6px; }
.txt { box-sizing: border-box; min-height: 30px; padding: 4px 0; outline: none; white-space: pre-wrap; overflow-wrap: anywhere; }
.row.done .txt { text-decoration: line-through; color: var(--done); }
.row.dim .txt { color: var(--muted); }
.row.cur { background: var(--cur-bg); }
.row.cur::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--hl-cur); }
.nohl .row.hit .txt { background: color-mix(in srgb, var(--hl) 45%, transparent); }
.cnt { flex: none; margin: 6px 0 0 8px; font: 11px/18px var(--mono); padding: 0 7px; border-radius: 9px; background: var(--hl); color: var(--hl-ink); font-variant-numeric: tabular-nums; }
.cnt:empty { display: none; }
.act { position: absolute; right: 10px; top: 3px; width: 24px; height: 24px; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; opacity: 0; padding: 0; }
.row:hover .act, .row:focus-within .act { opacity: 1; }
.act:hover { background: var(--line); color: var(--ink); }

.row.title { padding-left: 34px; }
.row.title::before, .row.title .tog, .row.title .dot { display: none; }
.row.title .txt { font: 600 24px/32px var(--sans); padding: 18px 0 8px; text-wrap: balance; }

.pics { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 8px; }
.pics img { display: block; height: 84px; border-radius: 4px; cursor: zoom-in; background: var(--line); }
.more { height: 84px; min-width: 64px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel); color: var(--muted); cursor: pointer; font: 13px var(--mono); }

::highlight(find) { background-color: var(--hl); color: var(--hl-ink); }
::highlight(find-cur) { background-color: var(--hl-cur); color: #1a1000; }

/* ---- album rows ---- */
.ahead { box-sizing: border-box; height: 44px; display: flex; align-items: flex-end; gap: 10px; padding: 0 12px 7px; cursor: pointer; white-space: nowrap; }
.ahead .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ahead .p, .ahead .c { color: var(--muted); font-size: 12px; flex: none; }
.ahead .p { overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.ahead:hover .t { color: var(--accent); }
.ahead.cur .t { background: var(--cur-bg); box-shadow: -3px 0 0 var(--hl-cur); padding-left: 6px; }
.strip { display: flex; gap: 4px; padding: 0 12px 4px; overflow: hidden; }
.strip img { display: block; flex: none; object-fit: cover; cursor: zoom-in; background: var(--line); border-radius: 2px; }

/* ---- status ---- */
.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; padding-block: 5px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-top: 1px solid var(--line); background: var(--panel); color: var(--muted); font: 12px/18px var(--mono);
}
.status .sp { flex: 1; }
.status button { border: 0; background: none; padding: 0; cursor: pointer; color: var(--muted); font: inherit; text-decoration: underline; text-underline-offset: 2px; }
.status button:hover { color: var(--ink); }

/* ---- lightbox ---- */
#lb { position: fixed; inset: 0; z-index: 20; background: rgba(9, 12, 12, .94); display: grid; grid-template-columns: 56px minmax(0, 1fr) 56px; grid-template-rows: minmax(0, 1fr) auto; align-items: center; color: #e8eeeb; }
#lb img { grid-column: 2; grid-row: 1; max-width: 100%; max-height: 100%; margin: auto; display: block; min-height: 0; object-fit: contain; }
#lb button { border: 0; background: none; color: inherit; cursor: pointer; }
#lbP, #lbN { font-size: 34px; height: 100%; }
#lbP { grid-column: 1; grid-row: 1; } #lbN { grid-column: 3; grid-row: 1; }
#lbX { position: absolute; top: 10px; right: 14px; font-size: 28px; width: 40px; height: 40px; }
#lb .cap { grid-column: 1 / -1; grid-row: 2; display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; padding: 10px 20px 16px; font-size: 13px; }
#lb .cap #lbC { flex: 1 1 200px; min-width: 0; }
#lb .cap #lbK { font-family: var(--mono); opacity: .7; }
#lb .cap #lbD { text-decoration: underline; opacity: .8; }

@media (prefers-reduced-motion: reduce) { .tog::before { transition: none; } }
