:root {
  /* Phos "Night" theme */
  --bg: #0B0D10;
  --bg-2: #0F1115;
  --surface: #15181D;
  --surface-2: #1B1F25;
  --raised: #1F242B;
  --line: #23272E;
  --line-2: #2F3540;
  --text: #ECEEF1;
  --text-2: #C9CFD6;
  --muted: #9AA3AE;
  --dim: #5A626D;
  --accent: #F5B547;
  --glow: #FFD58A;
  --accent-ink: #1A1206;
  --danger: #E5484D;
  --ok: #5BC27E;
  --radius: 10px;
  --font: Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: Sora, Manrope, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.primary:hover { background: #FFD58A; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 700; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.icon { width: 44px; min-height: 44px; padding: 0; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .5; cursor: default; }
select, input[type=text], input[type=password] { min-height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); font-weight: 600; font-size: 14px; }
input[type=text], input[type=password] { width: 100%; font-weight: 500; }
label.inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); background: var(--bg); }
.login-art { position: relative; overflow: hidden; }
.login-art .tiles { position: absolute; left: -60px; top: -90px; display: grid; grid-template-columns: repeat(6, 170px); gap: 14px; transform: rotate(-8deg); }
.login-art .tiles i { display: block; height: 210px; border-radius: 12px; box-shadow: 0 0 0 1px rgba(255,255,255,.05); }
.login-art::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 50%, rgba(11,13,16,0) 0%, rgba(11,13,16,.55) 40%, rgba(11,13,16,.97) 78%), linear-gradient(90deg, rgba(11,13,16,0) 60%, var(--bg) 100%); }
.login-art .glow { position: absolute; left: 50%; top: 50%; z-index: 1; width: 420px; height: 420px; transform: translate(-50%, -50%); border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle, rgba(255,213,138,.5) 0%, rgba(245,181,71,.16) 36%, rgba(245,181,71,0) 70%); }
.login-side { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .wordmark { font-size: 64px; }
.login .tagline { margin: -6px 0 6px; color: var(--muted); font-size: 15px; }
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; grid-template-rows: 240px 1fr; }
  .login-art .glow { width: 280px; height: 280px; }
  .login-art .glow svg { width: 110px; height: 110px; }
}
.login form { width: 100%; max-width: 380px; padding: 32px; border-radius: 18px; background: transparent; display: flex; flex-direction: column; gap: 16px; }
.login h1 { margin: 0; font-family: var(--display); font-size: 24px; font-weight: 400; letter-spacing: -.02em; }
.login .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.login .err { color: #FF8A8E; font-size: 14px; min-height: 20px; }

/* ---------- shell ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 10px 20px; background: #121519; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.wordmark { font-family: var(--display); font-weight: 300; font-size: 25px; letter-spacing: -.045em; line-height: 1; color: #F4F1EA; }
.wordmark b { color: var(--accent); font-weight: 300; }
.brand img { width: 28px; height: 28px; }
.crumbs { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); overflow: hidden; white-space: nowrap; }
.crumbs a { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.crumbs a:hover { color: var(--text); }
.crumbs .cur { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 20px; border: 1px solid var(--line-2); background: var(--surface-2); font-weight: 700; }
.layout { display: flex; min-height: calc(100vh - 61px); }
.sidebar { flex: 0 0 256px; padding: 18px 12px; border-right: 1px solid var(--line); background: var(--bg-2); display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 61px; height: calc(100vh - 61px); overflow-y: auto; }
.sidebar h2 { margin: 0 0 6px 10px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.nav-item { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 10px; border-radius: var(--radius); color: var(--text-2); font-size: 14px; font-weight: 600; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--raised); color: #fff; }
.nav-item .label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .badge { font-size: 11px; color: var(--muted); border: 1px solid var(--line-2); border-radius: 6px; padding: 2px 6px; font-weight: 600; }
.nav-item .count { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 400; }
.scan-mini { margin-top: auto; padding: 14px; border-radius: 12px; background: var(--surface); border: 1px solid #262C34; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.scan-mini .row { display: flex; justify-content: space-between; gap: 8px; }
.bar { height: 6px; border-radius: 3px; background: #262C34; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); transition: width .4s; }
.content { flex: 1 1 auto; min-width: 0; padding: 26px 30px 60px; display: flex; flex-direction: column; gap: 26px; }
.bottomnav { display: none; }

/* ---------- headings ---------- */
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.page-head { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-end; }
.page-head .info { flex: 1 1 380px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.page-head h1 { margin: 0; font-family: var(--display); font-size: 38px; line-height: 1.1; font-weight: 400; letter-spacing: -.025em; overflow-wrap: anywhere; }
.page-head .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; color: var(--text-2); }
.page-head .meta span.sep { color: #4A525C; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 10px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.desc { margin: 0; color: var(--text-2); font-size: 14px; max-width: 70ch; }
h2.section { margin: 0; font-size: 16px; font-weight: 700; }
h2.section span { color: var(--muted); font-weight: 500; }

/* ---------- album cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; gap: 8px; color: var(--text); min-width: 0; }
.card .cover { position: relative; aspect-ratio: 16 / 10; border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.card:hover .cover img { transform: scale(1.03); }
.card .cover .n { position: absolute; right: 8px; bottom: 8px; font: 600 11px var(--mono); padding: 3px 7px; border-radius: 6px; background: rgba(11,13,16,.8); }
.card .cover .empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--dim); font-size: 13px; }
.card .t { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.card .t b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .t span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.cards.big { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.cards.big .cover { aspect-ratio: 16 / 9; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 8px; }
.chip .c { font-family: var(--mono); font-size: 11px; opacity: .8; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.selbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px 8px 16px; border-radius: 12px; background: var(--raised); border: 1px solid #36404C; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.selbar .n { font-weight: 700; font-size: 14px; margin-right: 4px; }
.selbar .spacer { flex: 1 1 auto; }

/* ---------- media grid ---------- */
.gridwrap { display: flex; gap: 14px; align-items: flex-start; }
.grid { flex: 1 1 auto; min-width: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tile, 150px), 1fr)); gap: 12px; }
.tile { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 0; border: 0; background: none; text-align: left; min-width: 0; -webkit-touch-callout: none; user-select: none; }
.tile .th { position: relative; width: 100%; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); transition: transform .12s, box-shadow .12s; }
.tile .th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .nm { font: 400 11px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .q { position: absolute; top: 7px; right: 7px; font: 700 10px var(--mono); padding: 3px 6px; border-radius: 5px; background: var(--bg); color: var(--accent); }
.tile .dur { position: absolute; left: 7px; bottom: 7px; font: 500 11px var(--mono); padding: 2px 6px; border-radius: 5px; background: rgba(11,13,16,.8); display: flex; align-items: center; gap: 4px; }
.tile .fav { position: absolute; top: 7px; left: 7px; color: var(--accent); }
.tile .fav svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.tile .box { display: none; position: absolute; top: 7px; left: 7px; width: 24px; height: 24px; border-radius: 12px; border: 2px solid var(--text); background: rgba(11,13,16,.45); align-items: center; justify-content: center; }
.tile .box svg { width: 14px; height: 14px; stroke: transparent; stroke-width: 3; fill: none; }
.tile .nothumb { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--dim); font-size: 12px; }
.selecting .tile .box { display: flex; }
.selecting .tile .fav { display: none; }
.tile.sel .th { transform: scale(.94); box-shadow: 0 0 0 3px var(--accent); }
.tile.sel .box { background: var(--accent); border-color: var(--accent); }
.tile.sel .box svg { stroke: var(--accent-ink); }
.tile.flash .th { box-shadow: 0 0 0 3px var(--accent); }
.rail { flex: 0 0 30px; position: sticky; top: 76px; display: flex; flex-direction: column; align-items: center; padding: 6px 0; border-radius: 15px; background: #14171B; border: 1px solid var(--line); }
.rail button { width: 26px; height: 21px; padding: 0; border: 0; border-radius: 10px; background: none; font: 700 11px var(--mono); color: var(--text); }
.rail button.off { color: var(--dim); }
.rail button.cur { background: var(--accent); color: var(--accent-ink); }
.pager { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--line); }
.pager .pages { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pager .pg { width: 44px; height: 44px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--surface); font-weight: 600; }
.pager .pg[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.empty-state { padding: 60px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line-2); border-radius: 14px; }
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- panels / tables ---------- */
.panel { padding: 22px; border-radius: 14px; border: 1px solid var(--line); background: #121519; display: flex; flex-direction: column; gap: 14px; }
.panel h2 { margin: 0; font-size: 16px; font-weight: 700; }
.tablewrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--line); background: #121519; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; padding: 12px 16px; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 700; white-space: nowrap; }
table.t td { padding: 10px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
table.t td.num { text-align: right; font-family: var(--mono); font-size: 13px; }
table.t td.path { font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.cols { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.cols > * { flex: 1 1 440px; min-width: 0; }
.scan-card { border-color: #3A3020; background: #15140F; }
.scan-card .big { font: 500 44px var(--mono); color: var(--accent); letter-spacing: -.02em; }
.phases { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.phases li { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.phases li span { height: 4px; border-radius: 2px; background: #3A3A30; }
.phases li.done span { background: var(--ok); }
.phases li.cur { color: var(--text); font-weight: 700; }
.phases li.cur span { background: var(--accent); }
.stats { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 4px 0 0; font: 500 18px var(--mono); }
pre.code { margin: 0; padding: 14px; border-radius: 10px; background: #0A0B0D; border: 1px solid #1E232A; font: 400 12px/1.6 var(--mono); color: var(--text-2); overflow-x: auto; }
.method { font: 700 11px var(--mono); padding: 2px 6px; border-radius: 4px; }
.method.get { color: var(--ok); background: #15241B; }
.method.post { color: var(--accent); background: #2A2113; }

/* ---------- viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.viewer .vtop { position: absolute; top: 0; left: 0; right: 0; z-index: 4; display: flex; align-items: center; gap: 6px; padding: 8px 12px 28px; padding-top: max(8px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0,0,0,.78), rgba(0,0,0,0)); transition: opacity .25s; }
.viewer .vtop .btn.ghost:hover { background: rgba(255,255,255,.08); }
.viewer .vtop .btn[aria-pressed="true"] { background: rgba(245,181,71,.18); color: var(--accent); border-color: transparent; }
.viewer.idle { cursor: none; }
.viewer.idle .vtop, .viewer.idle .navbtn, .viewer.idle .controls { opacity: 0; pointer-events: none; }
.viewer .navbtn, .viewer .controls { transition: opacity .25s; }
.viewer .vtop .name { flex: 1 1 auto; min-width: 0; font: 500 13px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer .vbody { flex: 1 1 auto; min-height: 0; display: flex; position: relative; }
.viewer .stage { flex: 1 1 auto; min-width: 0; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.viewer .stage img, .viewer .stage video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.viewer.fit-cover .stage img, .viewer.fit-cover .stage video { object-fit: cover; }
.viewer.fit-fill .stage img, .viewer.fit-fill .stage video { object-fit: fill; }
.viewer.fit-none .stage img, .viewer.fit-none .stage video { object-fit: none; }
.viewer .fitsel { min-height: 36px; padding: 0 8px; font-size: 13px; background: rgba(21,24,29,.85); border-color: rgba(255,255,255,.12); }
@media (max-width: 860px) { .viewer .fitsel { max-width: 96px; } .viewer .vtop .name { font-size: 11px; } }
.viewer .navbtn { position: absolute; top: 50%; transform: translateY(-50%); width: 52px; height: 52px; border-radius: 26px; border: 0; background: rgba(21,24,29,.75); color: var(--text); display: flex; align-items: center; justify-content: center; }
.viewer .navbtn.prev { left: 14px; }
.viewer .navbtn.next { right: 14px; }
.viewer .side { position: absolute; top: 0; right: 0; bottom: 0; z-index: 5; width: 340px; max-width: 100%; padding: 64px 18px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
  background: rgba(11,13,16,.96); border-left: 1px solid #1E232A; transform: translateX(105%); transition: transform .2s ease; }
.viewer.info-open .side { transform: none; }
.viewer.info-open .vtop { z-index: 6; }
.viewer .controls { position: relative; z-index: 3; }
.card .cover .n { display: inline-flex; gap: 8px; align-items: center; }
.card .cover .nc { display: inline-flex; align-items: center; gap: 4px; }
.card .cover .nc svg.i { width: 12px; height: 12px; stroke-width: 2; }
.viewer .side dl { margin: 0; display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 8px 12px; font-size: 13px; }
.viewer .side dt { color: var(--muted); }
.viewer .side dd { margin: 0; overflow-wrap: anywhere; }
.player { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; }
.player .vwrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.controls { display: flex; flex-direction: column; gap: 8px; padding: 10px 14px 14px; background: #0B0D10; border-top: 1px solid #1E232A; }
.controls .row { display: flex; align-items: center; gap: 10px; }
.controls .time { font: 500 13px var(--mono); white-space: nowrap; }
.controls input[type=range] { width: 100%; accent-color: var(--accent); height: 22px; }
.controls .spacer { flex: 1 1 auto; }
.note { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.note .dot { width: 8px; height: 8px; border-radius: 4px; background: var(--accent); flex: none; }
.note .dot.ok { background: var(--ok); }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 80; background: rgba(5,6,8,.72); display: flex; align-items: flex-start; justify-content: center; padding: 14vh 16px 16px; }
.modal { width: 100%; max-width: 440px; max-height: 76vh; overflow-y: auto; padding: 24px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 14px; }
.modal h2 { margin: 0; font-size: 20px; font-weight: 800; }
.modal p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--text-2); }
.modal .acts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal .list { display: flex; flex-direction: column; gap: 4px; }
.modal .list button { text-align: left; min-height: 44px; padding: 0 12px; border-radius: 8px; border: 0; background: var(--surface-2); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.modal .list button:hover { background: var(--raised); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; z-index: 100; padding: 12px 18px; border-radius: 12px; background: #2A313B; border: 1px solid #3A434F; font-size: 14px; font-weight: 600; transition: all .2s; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- phone ---------- */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar { padding: 8px 10px; gap: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  .topbar .brand .wordmark, .topbar .qsel-label { display: none; }
  #qsel { max-width: 112px; min-height: 36px; padding: 0 6px; font-size: 13px; }
  .controls select { max-width: 150px; }
  .content { padding: 16px 10px 110px; gap: 18px; }
  .page-head h1 { font-size: 26px; }
  .page-head .actions .btn .lbl { display: none; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -10px; padding: 0 10px; scrollbar-width: none; }
  .chip { flex: none; }
  .toolbar { gap: 10px; }
  .tools { width: 100%; justify-content: space-between; }
  .grid { --tile: 104px; gap: 3px; }
  .tile .th { border-radius: 2px; }
  .tile .nm { display: none; }
  .gridwrap { gap: 4px; }
  .rail { flex-basis: 22px; border-radius: 11px; top: 64px; }
  .rail button { width: 22px; height: 16px; font-size: 9px; }
  .selbar { top: 60px; }
  .selbar .lbl { display: none; }
  .bottomnav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #121519; border-top: 1px solid var(--line); padding: 4px 4px max(10px, env(safe-area-inset-bottom)); }
  .bottomnav a { min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; }
  .bottomnav a.active { color: var(--accent); }
  .bottomnav svg.i { width: 22px; height: 22px; }
  .viewer .side { width: 100%; }
  .viewer .navbtn { width: 44px; height: 44px; }
  .viewer .navbtn.prev { left: 6px; }
  .viewer .navbtn.next { right: 6px; }
  .phases { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scan-card .big { font-size: 32px; }
}
@media (min-width: 861px) { .only-phone { display: none !important; } }

/* ---------- library manager ---------- */
.libtable tr.off td { opacity: .55; }
.libtable tr.off td:last-child, .libtable tr.off td:nth-last-child(2) { opacity: 1; }
.libtable td.path div.bad { color: #FF8A8E; }
.kbadge { font-size: 12px; border: 1px solid var(--line-2); border-radius: 6px; padding: 3px 8px; }
.switch { position: relative; display: inline-flex; width: 44px; height: 26px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { flex: 1; border-radius: 13px; background: var(--line-2); transition: background .15s; position: relative; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 10px; background: var(--text); transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--accent-ink); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.libform { gap: 16px; }
.libform .fld { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; border: 0; font-size: 13px; color: var(--muted); font-weight: 600; min-width: 0; }
.libform legend { padding: 0; margin-bottom: 8px; }
.libform .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.libform input[type=number] { min-height: 40px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text); font-weight: 600; }
.libform select, .libform input[type=text] { background: var(--surface-2); }
.libform .radio { color: var(--text); font-size: 14px; font-weight: 500; min-height: 36px; }
.libform input[type=radio], .libform input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text); }
.seg span small { color: var(--muted); font-weight: 500; font-size: 12px; }
.seg input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.pathlist { display: flex; flex-direction: column; gap: 6px; }
.pathrow { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 12px; border-radius: 8px; background: var(--surface-2); color: var(--text); font-weight: 500; }
.pathrow .mono { flex: 1 1 auto; min-width: 0; font-size: 12px; overflow-wrap: anywhere; }
.pathrow .btn.icon { width: 36px; min-height: 36px; }
.userlist { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.formerr { color: #FF8A8E; font-size: 14px; min-height: 0; }
.formerr:empty { display: none; }
.pickpath { font-size: 12px; color: var(--text-2); padding: 8px 10px; border-radius: 8px; background: #0A0B0D; overflow-wrap: anywhere; }
.picklist { max-height: 46vh; overflow-y: auto; }
.picklist button span { display: inline-flex; align-items: center; gap: 8px; }
.picklist button:disabled { opacity: .5; cursor: default; }
@media (max-width: 860px) { .seg { grid-template-columns: 1fr; } }
.content > * { min-width: 0; max-width: 100%; }
.tablewrap { max-width: 100%; width: 100%; position: relative; }
/* full-screen player: controls float over the video */
.player .vwrap { position: absolute; inset: 0; }
.player .controls { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.85)); border-top: 0; padding: 28px 14px max(14px, env(safe-area-inset-bottom)); }

/* ---------- phone fit (iPhone 16e is 390 px wide) ---------- */
/* No sideways scrolling. Only <html> gets "hidden" (it moves to the viewport); <body> uses "clip",
   which doesn't make it a scroll box — otherwise the sticky top bar and selection bars stop sticking. */
html { overflow-x: hidden; max-width: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: clip; max-width: 100%; }
@media (max-width: 860px) {
  /* iOS zooms into any field under 16px on focus and stays zoomed: keep fields at 16px */
  input, select, textarea { font-size: 16px !important; }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; --tile: auto; }
  .gridwrap { gap: 3px; }
  .tile .q { top: 3px; right: 3px; font-size: 8px; padding: 1px 4px; }
  .tile .dur { left: 3px; bottom: 3px; font-size: 9px; padding: 1px 4px; }
  .tile .fav { top: 3px; left: 3px; }
  .tile .box { top: 4px; left: 4px; width: 20px; height: 20px; }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .cards.big { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card .t { font-size: 12px; }
  .card .t span { font-size: 11px; }
  .card .cover { aspect-ratio: 1 / 1; border-radius: 8px; }
  .card .cover .n { right: 4px; bottom: 4px; font-size: 10px; padding: 2px 5px; gap: 5px; }
  .chip { min-height: 34px; padding: 0 11px; font-size: 12px; }
  .tools label.inline { font-size: 12px; }
  .tools select { min-height: 36px; padding: 0 6px; }
  .tools .btn { min-height: 36px; }
  .pager .pg { width: 38px; height: 38px; }
  .page-head { gap: 12px; }
  .page-head h1 { font-size: 24px; }
  .page-head .actions .btn { min-height: 38px; }
  #qsel { max-width: 96px; }
  .crumbs { font-size: 13px; }
  .modal { padding: 18px; }
  .selbar { padding: 6px 8px; gap: 4px; }
  .selbar .btn.small { padding: 0 8px; }
}
@media (max-width: 860px) {
  .tools { gap: 6px; flex-wrap: nowrap; }
  .tools label.inline { font-size: 0; gap: 0; }
  .tools select { max-width: 120px; }
  .tools .btn { padding: 0 10px; font-size: 13px; }
}

/* ---------- scan indicator (all screens) ---------- */
.scanpill { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border-radius: 999px; background: #2A2113; border: 1px solid #5A4520; color: var(--accent); font-size: 13px; font-weight: 600; white-space: nowrap; }
.scanpill[hidden] { display: none; }
.scanpill svg.i { width: 15px; height: 15px; animation: spin 1.4s linear infinite; }
.scanpill .lbl { color: var(--text-2); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.scanpill .eta { color: var(--muted); font-weight: 500; }
@keyframes spin { to { transform: rotate(360deg); } }
#scanline { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: transparent; pointer-events: none; }
#scanline > div { height: 100%; background: var(--accent); transition: width .5s; }
.topbar { position: sticky; }
.scanbadge { position: absolute; left: 8px; top: 8px; display: inline-flex; align-items: center; gap: 5px; font: 600 11px var(--font); padding: 3px 8px; border-radius: 6px; background: rgba(11,13,16,.85); color: var(--accent); }
.scanbadge svg.i { width: 12px; height: 12px; animation: spin 1.4s linear infinite; }
@media (max-width: 860px) {
  .scanpill { padding: 0 9px; min-height: 32px; font-size: 12px; }
  .scanpill .lbl, .scanpill .eta { display: none; }
}

.card[hidden] { display: none; }
#albums .rail { align-self: flex-start; }

[hidden] { display: none !important; }

/* ---------- system page ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi { padding: 16px; border-radius: 12px; background: #121519; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font: 500 24px var(--mono); }
.kpi .v b { font-weight: 500; }
.kpi .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv.good { color: var(--ok); } .lv.warn { color: var(--accent); } .lv.bad { color: #FF8A8E; }
.disk { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.disk:first-of-type { border-top: 0; }
.disk .row { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 14px; }
#sysbody .cols { margin-bottom: 24px; }
@media (max-width: 860px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } .kpi { padding: 12px; } .kpi .v { font-size: 19px; } }
.lv { white-space: nowrap; } table.t td.num { white-space: nowrap; }

/* ---------- framed thumbnails ---------- */
.grid { gap: 10px; }
.tile .th { padding: 3px; background: var(--surface); border: 1px solid var(--line); box-sizing: border-box; }
.tile .th img { border-radius: 7px; }
.tile .th .q { top: 9px; right: 9px; }
.tile .th .dur { left: 9px; bottom: 9px; }
.tile .th .fav, .tile .th .box { top: 9px; left: 9px; }
.tile.sel .th { border-color: var(--accent); }
.viewer .stage img.photo { transition: filter .25s; }
.viewer .stage img.photo.loading { filter: blur(6px); }
@media (max-width: 860px) {
  .grid { gap: 4px; }
  .tile .th { padding: 2px; border-radius: 6px; }
  .tile .th img { border-radius: 4px; }
  .tile .th .q { top: 4px; right: 4px; }
  .tile .th .dur { left: 4px; bottom: 4px; }
  .tile .th .fav, .tile .th .box { top: 5px; left: 5px; }
}

/* ---------- long press & pinned selection bar ---------- */
.tile, .card, .tile img, .card img { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; }
@media (max-width: 860px) {
  .selbar { padding: 6px 8px; gap: 2px; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
  .selbar .btn.small { min-height: 40px; min-width: 40px; padding: 0 9px; }
  .selbar .n { font-size: 13px; margin-right: 0; }
  .selbar [data-act=selclear] { display: none; }
}

/* A–Z rail pinned to the right edge of the screen */
.rail { position: fixed !important; top: 50% !important; right: 10px; transform: translateY(-50%); z-index: 15; align-self: auto; max-height: calc(100vh - 140px); overflow-y: auto; scrollbar-width: none; }
.gridwrap:has(.rail) { padding-right: 40px; }
/* Keep the toolbar and page header clear of the fixed A–Z rail. */
.content:has(.rail) .toolbar, .content:has(.rail) .page-head { padding-right: 40px; }
@media (max-width: 860px) {
  .rail { right: 2px; max-height: calc(100vh - 170px); }
  .gridwrap:has(.rail) { padding-right: 24px; }
  .content:has(.rail) .toolbar, .content:has(.rail) .page-head { padding-right: 24px; }
}

/* album selection */
.card .abox { display: none; position: absolute; top: 8px; left: 8px; width: 26px; height: 26px; border-radius: 13px; border: 2px solid var(--text); background: rgba(11,13,16,.5); align-items: center; justify-content: center; }
.card .abox svg { width: 15px; height: 15px; stroke: transparent; stroke-width: 3; fill: none; }
.aselecting .card .abox { display: flex; }
.card.sel .cover { box-shadow: 0 0 0 3px var(--accent); transform: scale(.96); }
.card.sel .abox { background: var(--accent); border-color: var(--accent); }
.card.sel .abox svg { stroke: var(--accent-ink); }
.card .cover { transition: transform .12s, box-shadow .12s; }

/* list picker */
.checklist { display: flex; flex-direction: column; gap: 4px; max-height: 42vh; overflow-y: auto; }
.checkrow { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 12px; border-radius: 8px; background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer; }
.checkrow span:nth-child(2) { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.checkrow input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.checkrow:has(input:checked) { box-shadow: inset 0 0 0 1px var(--accent); }
.t tr.off td { opacity: .55; }

/* ---------- tools ---------- */
.toolcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.toolcard { padding: 18px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.toolcard.broken { border-color: #5A2A2C; }
.toolcard p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--text-2); flex: 1 1 auto; }
.toolcard .btn { align-self: flex-start; }
.tc-head { display: flex; gap: 12px; align-items: center; }
.tc-head > div { display: flex; flex-direction: column; gap: 2px; }
.tc-icon { width: 36px; height: 36px; flex: none; border-radius: 10px; display: grid; place-items: center; background: rgba(245,181,71,.12); color: var(--accent); }
.tc-icon .i { width: 18px; height: 18px; }
.spill { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 12px; font-size: 12px; font-weight: 700; border: 1px solid var(--line-2); color: var(--text-2); white-space: nowrap; }
.spill.good { color: var(--ok); border-color: #24452F; }
.spill.bad { color: #FF8A8E; border-color: #5A2A2C; }
.spill.warn { color: var(--accent); border-color: #5A4520; }
.spill.run { color: #8DB8FF; border-color: #26364F; }
.spill.ready { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.tbanner { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); font-size: 14px; }
.tbanner.ready { border-color: #5A4520; background: rgba(245,181,71,.07); }
.tbanner.good { border-color: #24452F; background: rgba(91,194,126,.06); }
.tbanner.bad { border-color: #5A2A2C; background: rgba(229,72,77,.06); }
.tbanner.warn { border-color: #5A4520; }
.tbanner.run { border-color: #26364F; background: rgba(141,184,255,.05); }
.acttable td.path { overflow-wrap: anywhere; min-width: 160px; }
.acttable tr.off td { opacity: .5; }
.astate { font-weight: 700; }
.astate.done { color: var(--ok); }
.astate.failed { color: #FF8A8E; }
.astate.skipped, .astate.excluded, .astate.undone { color: var(--muted); }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--surface-2); }

/* viewer zoom */
.viewer .stage img.photo { touch-action: none; transform-origin: 0 0; will-change: transform; cursor: zoom-in; user-select: none; -webkit-user-drag: none; }
.viewer.zoomed .stage img.photo { cursor: grab; }
.viewer.zoomed .stage img.photo.dragging { cursor: grabbing; }
.viewer.zoomed .navbtn { opacity: .35; }

/* one-line page header: kind · title (menu) · count */
.page-head.ph-line { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto) minmax(0, 1fr); align-items: center; gap: 12px; }
.ph-kind { justify-self: start; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.ph-count { justify-self: end; font: 500 14px var(--mono); color: var(--text-2); white-space: nowrap; }
.page-head .ph-title { margin: 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 30px; }
.ph-title button { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 2px 6px; border: 0; border-radius: 10px; background: none; color: var(--text); font: inherit; cursor: pointer; }
.ph-title button:hover { background: var(--surface-2); }
.ph-title button .i { width: 18px; height: 18px; flex: none; color: var(--muted); }
.ph-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ph-sub { font: 500 13px var(--font); color: var(--muted); letter-spacing: 0; }
.filterline { margin-top: 2px; }
@media (max-width: 860px) {
  .page-head .ph-title { font-size: 21px; }
  .page-head.ph-line { gap: 8px; }
  .ph-count { font-size: 12px; }
  .filterline { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }

}

@media (max-width: 860px) {
  /* phone: kind and count take what they need, the title gets the rest */
  .page-head.ph-line { grid-template-columns: auto minmax(0, 1fr) auto; }
  .ph-kind { font-size: 11px; }
  /* selection bar on one row */
  .selbar { flex-wrap: nowrap; }
  .selbar .n { white-space: nowrap; }
  .selbar [data-act=selall] .lbl { display: none; }
  .selbar .btn.small, .selbar .btn.icon { min-width: 40px; padding: 0 8px; }
}

/* zoom on videos too: the picture stays inside its box, under the controls */
.player .vwrap { overflow: hidden; }
.viewer.zoomed .player video { cursor: grab; }
.viewer.zoomed .player video.dragging { cursor: grabbing; }
.viewer .player video { touch-action: none; transform-origin: 0 0; will-change: transform; }

/* Album merger: the chosen albums in the task editor */
.mergelist { display: flex; flex-direction: column; gap: 6px; }
.mergelist .pathrow { padding: 2px 4px 2px 10px; }
.mergelist .pathrow .mono { overflow-wrap: anywhere; }
.mergelist .tag { flex: none; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(240,165,58,.16); color: var(--accent); }

/* Selection bars: start in line 3, then stay pinned at the top centre while scrolling.
   The wrapper is what sticks (its section is as tall as the page); the bar is centred in it. */
#selhost { position: sticky; top: 72px; z-index: 15; display: flex; justify-content: center; pointer-events: none; margin: -10px 0; }
.content > .filterline { margin-top: -12px; }
#selhost:empty { display: none; }
#selhost .selbar { pointer-events: auto; width: fit-content; max-width: 100%; }
@media (max-width: 860px) {
  #selhost { top: calc(env(safe-area-inset-top) + 60px); }
  #selhost .selbar { width: 100%; overflow-x: auto; scrollbar-width: none; }
}

.binalbum { display: flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }

/* Selection bar on phones: two rows. Row 1: count, select all, clear, close.
   Row 2: the actions, each an icon with a short name under it. */
.selbar .sl { display: none; }
@media (max-width: 860px) {
  #selhost .selbar { flex-wrap: wrap; overflow: visible; row-gap: 4px; padding: 6px 6px 4px; }
  #selhost .selbar .n { order: 0; flex: 1 1 auto; padding-left: 6px; }
  #selhost .selbar [data-act=selall] { order: 1; }
  #selhost .selbar [data-act=selclear] { order: 2; display: inline-flex; }
  #selhost .selbar [data-act=sel-exit] { order: 3; }
  #selhost .selbar .spacer { order: 4; flex: 1 0 100%; height: 0; }
  #selhost .selbar .act { order: 5; flex: 1 1 0; min-width: 0; flex-direction: column; gap: 2px; min-height: 48px; padding: 4px 2px; }
  #selhost .selbar .act .lbl { display: none; }
  #selhost .selbar .act .sl { display: block; max-width: 100%; font-size: 10.5px; font-weight: 600; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
