:root {
  color-scheme: dark;
  --bg: #111214;
  --panel: #1a1b1e;
  --panel-2: #26272b;
  --border: #2f3136;
  --text: #ececee;
  --muted: #9a9ca3;
  --accent: #f2b33d;
  --accent-ink: #1d1500;
  --warn: #e5734f;
  --tile: 200px;
  --tl-w: 200px;
  --toolbar-h: 64px; /* updated from JS */
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* never let a component's display override `hidden` */

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
body.noscroll { overflow: hidden; }

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 24px;
  padding: 12px 16px 8px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.toolbar h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: .01em; }
.sources, .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.controls { margin-left: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); font-weight: 600; }

/* Black & white preview filter (view only — files are never modified). */
body.bw .thumb img,
body.bw .tl-thumb img,
body.bw #viewerImg { filter: grayscale(1); }

.info { color: var(--muted); font-size: 13px; margin-right: 8px; }
.info.ok { color: var(--text); }

/* Welcome / empty states with a drop zone */
.hero { max-width: 640px; margin: 7vh auto 48px; padding: 0 16px; text-align: center; }
.hero-title { margin: 0 0 8px; font-size: 34px; font-weight: 700; letter-spacing: -.01em; }
.hero-desc { margin: 0 0 28px; color: var(--muted); font-size: 16px; }
.hero-alt { margin: 18px 0 0; }
.hero-note { margin: 22px 0 0; color: var(--muted); font-size: 12px; }
.hero-note code { color: var(--text); }
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 44px 24px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover,
.dropzone:focus-visible,
body.dragging .dropzone {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--panel));
  outline: none;
}
.dropzone svg { width: 44px; height: 44px; margin-bottom: 6px; color: var(--accent); }
.dropzone b { font-size: 17px; }
.dropzone .dz-sub { color: var(--muted); font-size: 13px; }
.dropzone .dz-plus {
  margin-top: 14px;
  padding: 7px 16px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
}
.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.link:hover { color: var(--text); }

/* Drag & drop folders */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 8, 9, .72);
  pointer-events: none; /* drag events keep reaching the window */
}
.drop-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(560px, 100%);
  padding: 48px 24px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  text-align: center;
}
.drop-box b { font-size: 18px; }
.drop-box span { color: var(--muted); font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 200;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.toast kbd {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button {
  padding: 6px 10px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--panel-2); color: var(--text); }

.size { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.size input { width: 100px; accent-color: var(--accent); }

.stats { flex-basis: 100%; color: var(--muted); font-size: 12px; min-height: 17px; }
.stats b { color: var(--text); font-weight: 600; }
.stats .sel { color: var(--accent); }
.stats .busy { color: var(--text); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--tl-w) minmax(0, 1fr);
}
#galleryPage:not(.has-items) .layout { display: none; }
.page[hidden] { display: none; }

/* ---------- Galleries page ---------- */
.home { max-width: 1200px; margin: 0 auto; padding: 8px 16px 48px; }
.home-title { margin: 16px 0 14px; font-size: 20px; font-weight: 650; }
.gallery-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.gallery-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  overflow: hidden;
}
.gc-cover {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 2;
  background: #0a0a0b;
}
.gc-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.gc-cover .placeholder { position: absolute; color: var(--muted); font-size: 12px; }
.gc-cover img.loaded + .placeholder { display: none; }
.gc-body { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px 14px; }
.gc-name { color: var(--text); font-size: 16px; font-weight: 600; text-decoration: none; }
.gc-name:hover { text-decoration: underline; }
.gc-stats { font-size: 13px; color: var(--muted); }
.gc-stats .sel { color: var(--accent); }
.gc-folders { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gc-actions { display: flex; gap: 6px; margin-top: 8px; }
.btn.danger:hover:not(:disabled) { border-color: var(--warn); color: var(--warn); }

/* ---------- Gallery toolbar ---------- */
.title-row { display: flex; align-items: center; gap: 12px; }
a.btn { text-decoration: none; }
.gallery-name { cursor: text; }
.gallery-name:hover { text-decoration: underline dotted; }

.folders { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  font-size: 12px;
}
.chip-name { font-weight: 600; }
.chip-status { color: var(--muted); }
.chip.needs, .chip.unavailable { border-style: dashed; }
.chip.needs .chip-status, .chip.unavailable .chip-status { color: var(--accent); }
.chip.error { border-color: var(--warn); }
.chip.error .chip-status { color: var(--warn); }
.chip button {
  padding: 2px 7px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.chip button:hover { background: var(--panel-2); color: var(--text); }
.chip button.go { color: var(--accent); font-weight: 600; }

/* ---------- Timeline ---------- */
.timeline {
  position: sticky;
  top: var(--toolbar-h);
  height: calc(100vh - var(--toolbar-h));
  overflow-y: auto;
  padding: 0 8px 24px;
  border-right: 1px solid var(--border);
  scrollbar-width: thin;
}
.tl-month {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 12px 6px 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.tl-day {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.tl-day:hover { background: var(--panel); }
.tl-day.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.tl-thumb {
  flex: none;
  width: 56px;
  aspect-ratio: 4 / 3;
  border-radius: 4px;
  background: #0a0a0b;
  overflow: hidden;
}
.tl-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tl-label { display: flex; flex-direction: column; min-width: 0; }
.tl-label b { font-size: 13px; font-weight: 600; }
.tl-label small { color: var(--muted); font-size: 11px; }
.tl-label small .sel { color: var(--accent); }

/* ---------- Day sections ---------- */
.days { padding: 0 16px 40px; min-width: 0; }
.day { scroll-margin-top: var(--toolbar-h); }
.day-head {
  position: sticky;
  top: var(--toolbar-h);
  z-index: 5;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 0 8px;
  background: var(--bg);
}
.day-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.day-count { color: var(--muted); font-size: 12px; }
.day-count .sel { color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  gap: 10px;
}

/* ---------- Tiles ---------- */
.tile {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 0 0 2px transparent;
  transition: box-shadow .12s;
}
.tile.selected { box-shadow: 0 0 0 3px var(--accent); }

.thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #0a0a0b;
  display: grid;
  place-items: center;
  cursor: zoom-in;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.thumb .placeholder { position: absolute; color: var(--muted); font-size: 12px; }
.thumb img.loaded + .placeholder { display: none; }

.lazy { opacity: 0; transition: opacity .2s; }
.lazy.loaded { opacity: 1; }

.check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .85);
  background: rgba(0, 0, 0, .35);
  color: transparent;
  font: 700 15px/1 system-ui, sans-serif;
  cursor: pointer;
  opacity: .55;
  transition: opacity .12s, background .12s;
}
.tile:hover .check, .check:focus-visible { opacity: 1; }
.tile.selected .check { opacity: 1; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 8px;
  font-size: 12px;
}
.meta .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badges { display: inline-flex; gap: 4px; flex-shrink: 0; }
.badge {
  font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 3px 5px;
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--muted);
}
.badge.missing { color: var(--warn); background: transparent; border: 1px dashed currentColor; text-decoration: line-through; }

/* ---------- Empty state ---------- */
.empty {
  max-width: 560px;
  margin: 60px auto;
  padding: 0 16px;
  color: var(--muted);
}
.empty h2 { color: var(--text); font-size: 20px; margin: 0 0 12px; }
.empty ol { padding-left: 20px; }
.empty li { margin: 6px 0; }
.empty b { color: var(--text); }
.empty code { color: var(--text); font-size: 12px; }

/* ---------- Viewer ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: 1fr auto;
  background: rgba(6, 6, 7, .97);
}
.viewer[hidden] { display: none; }
.viewer-stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 16px 64px;
  overflow: hidden;
}
/* Sized from JS to fit the stage in both directions (landscape and portrait). */
.photo-wrap {
  position: relative;
  overflow: hidden; /* clips the crop's dimming shadow to the photo */
  box-shadow: 0 0 0 3px transparent;
}
.photo-wrap[hidden] { display: none; }
.photo-wrap img { display: block; width: 100%; height: 100%; }
.viewer.selected .photo-wrap { box-shadow: 0 0 0 3px var(--accent); }

.crop {
  position: absolute;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .62);
  outline: 1px solid rgba(255, 255, 255, .9);
  cursor: move;
  touch-action: none;
  --line: rgba(255, 255, 255, .3);
  background:
    linear-gradient(to right, transparent calc(33.33% - .5px), var(--line) 0 calc(33.33% + .5px),
      transparent 0 calc(66.67% - .5px), var(--line) 0 calc(66.67% + .5px), transparent 0),
    linear-gradient(to bottom, transparent calc(33.33% - .5px), var(--line) 0 calc(33.33% + .5px),
      transparent 0 calc(66.67% - .5px), var(--line) 0 calc(66.67% + .5px), transparent 0);
}
.crop[hidden] { display: none; }
.crop-info {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}
.crop-info .low { color: var(--warn); }

.crop-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.crop-label { color: var(--muted); font-size: 13px; cursor: pointer; }
.crop-on { width: 16px; height: 16px; margin: 0 2px; accent-color: var(--accent); cursor: pointer; }
.crop-tools:has(.crop-on:not(:checked)) select { opacity: .55; }
.crop-tools select,
.cm-form input {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}
.cm-form { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; color: var(--muted); }
.cm-form input { width: 62px; }
.no-jpg { color: var(--muted); }

.nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 80px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  font-size: 36px;
  cursor: pointer;
}
.nav:hover:not(:disabled) { background: rgba(255, 255, 255, .14); }
.nav:disabled { opacity: .2; cursor: default; }
.nav.prev { left: 8px; }
.nav.next { right: 8px; }

.viewer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.viewer-info, .viewer-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12px; }

@media (max-width: 700px) {
  :root { --tl-w: 84px; }
  .controls { margin-left: 0; }
  .tl-day { flex-direction: column; align-items: stretch; gap: 4px; padding: 4px; }
  .tl-thumb { width: 100%; }
  .tl-label small { display: none; }
  .days { padding: 0 10px 40px; }
  .viewer-stage { padding: 8px; }
  .nav { width: 36px; height: 60px; font-size: 28px; }
  .hint { display: none; }
}
