:root {
  --bg: #f6f6f4; --panel: #ffffff; --fg: #1b1b1a; --muted: #6b6b66; --line: #e3e2de;
  --accent: #2f6fde; --accent-fg: #fff; --chip: #eeede9; --tile: #e7e6e2; --shadow: 0 1px 3px rgb(0 0 0 / .08);
  --radius: 10px; --side: 280px; --row: 200px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111112; --panel: #1b1b1d; --fg: #ececea; --muted: #9a9a95; --line: #2c2c2f;
    --accent: #6d9cff; --accent-fg: #0b1020; --chip: #26262a; --tile: #202023; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 10px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 20px; }
.login input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.login .error { color: #d33; min-height: 1.4em; margin: 0; }

/* app shell */
header.top { position: sticky; top: 0; z-index: 20; display: flex; gap: 8px; align-items: center;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
header.top .brand { font-weight: 650; white-space: nowrap; }
header.top .search { flex: 1; min-width: 0; }
header.top .search input { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
.layout { display: grid; grid-template-columns: var(--side) 1fr; min-height: calc(100dvh - 57px); }
aside.filters { position: sticky; top: 57px; height: calc(100dvh - 57px); overflow: auto; padding: 14px 16px 40px;
  border-right: 1px solid var(--line); background: var(--panel); }
main { padding: 12px 16px 60px; min-width: 0; }
.toggle-filters { display: none; }
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  aside.filters { position: fixed; inset: 57px 0 0 0; width: min(88vw, 340px); height: auto; z-index: 15;
    transform: translateX(-102%); transition: transform .2s; box-shadow: 4px 0 24px rgb(0 0 0 / .25); }
  body.show-filters aside.filters { transform: none; }
  body.show-filters .filters-backdrop { display: block; }
  aside.filters .filters-done { display: block; }
  aside.filters { padding-bottom: 0; }
  .toggle-filters { display: inline-block; }
  header.top .brand { display: none; }
  :root { --row: 130px; }
}

.filters h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.filters .dates { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.filters .dates input { width: 100%; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid transparent; background: var(--chip); border-radius: 999px; padding: 3px 10px; font-size: 13px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .n { color: var(--muted); margin-left: 4px; font-size: 12px; }
.chip.on { background: var(--accent); color: var(--accent-fg); }
.chip.on .n { color: inherit; opacity: .8; }
.more { background: none; border: 0; color: var(--accent); padding: 3px 4px; font-size: 13px; }
.hist { display: flex; align-items: flex-end; gap: 2px; height: 64px; }
.hist button { flex: 1; min-width: 3px; border: 0; padding: 0; background: var(--accent); opacity: .45; border-radius: 2px 2px 0 0; }
.hist button:hover, .hist button.on { opacity: 1; }
.hist-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.switch { display: flex; align-items: center; gap: 8px; margin: 6px 0; }

.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.bar .count { margin-right: auto; color: var(--muted); }
.bar select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.active { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.active .chip::after { content: " ×"; }

/* grid */
.month { font-weight: 650; margin: 18px 0 8px; font-size: 15px; }
.month:first-child { margin-top: 4px; }
.grid { display: flex; flex-wrap: wrap; gap: 4px; }
.grid::after { content: ""; flex-grow: 1e4; }
.tile { position: relative; height: var(--row); flex: var(--r, 1) 1 calc(var(--row) * var(--r, 1)); max-width: calc(var(--row) * var(--r, 1) * 2.2);
  background: var(--tile); border-radius: 4px; overflow: hidden; border: 0; padding: 0; }
.grid.square .tile { --r: 1 !important; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.tile:hover img { transform: scale(1.03); }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.badge { position: absolute; right: 6px; bottom: 6px; background: rgb(0 0 0 / .65); color: #fff; font-size: 11px;
  padding: 1px 6px; border-radius: 4px; pointer-events: none; }
.badge.fav { left: 6px; right: auto; }
.tile .noimg { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 12px; padding: 6px; text-align: center; word-break: break-all; }
.sentinel { height: 1px; }
.status { text-align: center; color: var(--muted); padding: 24px; }

/* lightbox */
dialog.lb { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #000; color: #eee; }
dialog.lb::backdrop { background: #000; }
.lb-wrap { display: grid; grid-template-columns: 1fr 340px; height: 100%; }
.lb-stage { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100dvh; object-fit: contain; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgb(0 0 0 / .4); color: #fff; border: 0;
  width: 44px; height: 64px; font-size: 26px; border-radius: 6px; }
.lb-nav.prev { left: 8px; } .lb-nav.next { right: 8px; }
.lb-close { position: absolute; top: 8px; right: 8px; z-index: 2; background: rgb(0 0 0 / .5); color: #fff; border: 0;
  width: 38px; height: 38px; border-radius: 50%; font-size: 20px; }
.lb-meta { background: #141416; overflow: auto; padding: 16px; font-size: 13px; }
.lb-meta h2 { font-size: 15px; margin: 0 0 4px; word-break: break-all; }
.lb-meta dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0; }
.lb-meta dt { color: #999; }
.lb-meta dd { margin: 0; word-break: break-word; }
.lb-meta .chips .chip { background: #2a2a2e; color: #ddd; }
.lb-meta h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #999; margin: 16px 0 6px; }
.lb-meta pre { white-space: pre-wrap; word-break: break-all; background: #0c0c0d; padding: 8px; border-radius: 6px; font-size: 11px; max-height: 280px; overflow: auto; }
.lb-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.lb-actions a { text-decoration: none; }
@media (max-width: 800px) {
  .lb-wrap { grid-template-columns: 1fr; grid-template-rows: 62dvh auto; overflow: auto; }
  .lb-stage img, .lb-stage video { max-height: 62dvh; }
}
.filters .error { color: #d33; font-size: 13px; }
.status .chips { justify-content: center; margin: 8px 0; }
.noplay { display: grid; gap: 10px; place-items: center; text-align: center; padding: 16px; }
.noplay img { max-height: 70dvh; opacity: .6; }
.lb-chapters .chip.on { background: var(--accent); color: var(--accent-fg); }

.kbd-help { position: fixed; inset: auto 16px 16px auto; z-index: 50; max-width: calc(100vw - 32px); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; font-size: 13px; box-shadow: 0 8px 24px #0008; }
.kbd-help h3 { margin: 0 0 8px; font-size: 14px; }
.kbd-help dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
.kbd-help dd { margin: 0; color: var(--muted); }
.kbd-help kbd { border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; font-family: inherit; }
.chips.quick { margin-top: 8px; }
.tile .hover-preview { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.tile .badge { z-index: 1; }
@media (prefers-reduced-motion: reduce) {
  .tile img { transition: none; }
  .tile:hover img { transform: none; }
}
.kbd-help.library { inset: 56px auto auto 16px; max-height: calc(100vh - 80px); overflow: auto; min-width: 260px; }
.kbd-help.library h3 + dl, .kbd-help.library dl + h3 { margin-top: 10px; }
.kbd-help.library .btn { margin-top: 8px; }
button.brand { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }

/* ---- UX pass (2026-10-07) ---- */
/* buttons in the (always dark) viewer panel: readable in light mode too */
.lb-meta .btn { background: #26262a; border-color: #3a3a40; color: #eee; }
.lb-meta .btn:hover { border-color: #77777f; }
.lb-meta .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.lb-meta .btn:disabled { opacity: .6; cursor: default; }
/* date fields fit the sidebar */
.filters .dates label { min-width: 0; display: grid; gap: 2px; }
.filters .dates input { min-width: 0; }
/* keyboard focus is always visible */
.btn:focus-visible, .chip:focus-visible, .more:focus-visible, .brand:focus-visible, select:focus-visible,
.hist button:focus-visible, .lb-nav:focus-visible, .lb-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* month headings stay in view while scrolling a long month */
.month { position: sticky; top: 57px; z-index: 5; padding: 6px 0; margin: 12px 0 4px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); }
@media (max-width: 800px) {
  #logout { padding: 6px 8px; font-size: 13px; }
}
.lb-pos { position: absolute; top: 14px; left: 14px; z-index: 2; color: #bbb; font-size: 13px; background: rgb(0 0 0 / .45);
  padding: 2px 8px; border-radius: 999px; pointer-events: none; }
.lb-pos:empty { display: none; }
.lb-tech { margin-top: 16px; border-top: 1px solid #2a2a2e; padding-top: 10px; }
.lb-tech summary { cursor: pointer; color: #999; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.lb-tech dl { margin-top: 10px; }
.status .empty-title { font-size: 16px; color: var(--fg); margin-bottom: 4px; }
.active .chip, .status .chip.on { cursor: pointer; }
.grid.skeleton .skel { height: var(--row); flex: var(--r, 1) 1 calc(var(--row) * var(--r, 1)); border-radius: 4px;
  background: var(--tile); animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .55; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .grid.skeleton .skel { animation: none; } }

/* phone filter drawer: backdrop behind it, a sticky button back to the results */
.filters-backdrop { display: none; position: fixed; inset: 57px 0 0 0; z-index: 14; background: rgb(0 0 0 / .35); }
.filters-done { display: none; position: sticky; bottom: 0; margin: 18px -16px 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line); }
.filters-done .btn { width: 100%; padding: 10px; }
.lb-stage img { height: auto; }
.lb-stage img.lowres { filter: blur(6px); transform: scale(1.01); }
.help-btn { width: 34px; padding: 6px 0; font-weight: 650; }
@media (max-width: 800px) { .help-btn { display: none; } }  /* phones have no keyboard shortcuts */
/* hover caption on tiles (desktop) */
.tile-cap { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; padding: 18px 64px 6px 8px; font-size: 12px; color: #fff;
  text-align: left; background: linear-gradient(transparent, rgb(0 0 0 / .6)); opacity: 0; transition: opacity .15s;
  pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile:hover .tile-cap, .tile:focus-visible .tile-cap { opacity: 1; }
@media (hover: none) { .tile-cap { display: none; } }
.to-top { position: fixed; right: 18px; bottom: 18px; z-index: 12; width: 42px; height: 42px; border-radius: 50%;
  font-size: 18px; box-shadow: 0 2px 10px rgb(0 0 0 / .2); }
.login .btn.primary { padding: 10px; }
.login .btn.primary:disabled { opacity: .7; cursor: progress; }
.login .switch { margin: -6px 0 0; font-size: 13px; }
.login input[type="checkbox"] { width: auto; padding: 0; margin: 0; }
