:root {
  --bg: #0b0b0b;
  --bg-card: #161616;
  --bg-card-hover: #1e1e1e;
  --accent: #c9a84c;
  --accent-hover: #e0be6a;
  --accent-dim: rgba(201, 168, 76, 0.12);
  --text: #ede8dc;
  --text-muted: #7a7060;
  --text-dim: #444;
  --border: #242424;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ── Layout ─────────────────────────────────── */
.container { max-width: 1280px; margin: 0 auto; padding: 0 20px; }

/* ── Header ──────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(11,11,11,0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}

header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.logo { display: flex; flex-direction: column; line-height: 1.2; }
.logo-name { font-size: 1.25rem; font-weight: 700; color: var(--accent); letter-spacing: 0.02em; }
.logo-sub { font-size: 0.68rem; color: var(--text-muted); letter-spacing: 0.12em; text-transform: uppercase; }

/* ── Breadcrumb ──────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.82rem; color: var(--text-muted); flex-wrap: wrap;
}
.breadcrumb a { color: var(--accent); }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-sep { color: var(--text-dim); }

/* ── Hero / Page title ───────────────────────── */
.page-header { padding: 36px 0 28px; }
.page-title { font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 800; margin-bottom: 6px; }
.page-subtitle { color: var(--text-muted); font-size: 0.9rem; }

/* ── Cards Grid ──────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  padding-bottom: 60px;
}

@media (max-width: 480px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* ── Card ────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  display: flex; flex-direction: column; gap: 8px;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.15s;
  position: relative; overflow: hidden;
}

.card::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--accent-dim), transparent);
  opacity: 0; transition: opacity 0.2s;
}

.card:hover { background: var(--bg-card-hover); border-color: rgba(201,168,76,0.35); transform: translateY(-2px); }
.card:hover::before { opacity: 1; }
.card:active { transform: translateY(0); }

.card-icon { font-size: 1.6rem; }
.card-title { font-size: 0.97rem; font-weight: 600; line-height: 1.4; }
.card-meta { font-size: 0.78rem; color: var(--text-muted); }
.card-arrow { font-size: 0.75rem; color: var(--accent); margin-top: 4px; }

/* Year cards */
.card.year-card { padding: 32px 20px; align-items: center; text-align: center; }
.card.year-card .card-title { font-size: 2.2rem; font-weight: 900; color: var(--accent); letter-spacing: -0.02em; }

/* ── Photo Grid ──────────────────────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 5px;
  padding-bottom: 60px;
}

@media (min-width: 540px) { .photo-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
@media (min-width: 900px) { .photo-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; } }

.photo-item {
  position: relative; aspect-ratio: 3/2; overflow: hidden;
  border-radius: 6px; cursor: pointer; background: var(--bg-card);
  content-visibility: auto;
  contain-intrinsic-size: 0 180px;
}

.photo-item img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform 0.3s ease;
}

.photo-item:hover img { transform: scale(1.05); }

.photo-item .photo-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.6) 0%, transparent 55%);
  opacity: 0; transition: opacity 0.2s;
  display: flex; align-items: flex-end; padding: 8px;
}

.photo-item:hover .photo-overlay { opacity: 1; }

.photo-name { font-size: 0.68rem; color: rgba(255,255,255,0.85); word-break: break-all; }

/* ── Skeleton ────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, #1c1c1c 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
  border-radius: var(--radius);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card { height: 96px; border-radius: var(--radius); }
.skeleton-photo { aspect-ratio: 3/2; border-radius: 6px; }

/* ── Lightbox ────────────────────────────────── */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.96);
  flex-direction: column; align-items: center; justify-content: center;
}

.lightbox.active { display: flex; }

.lightbox-img-container {
  flex: 1; display: flex; align-items: center; justify-content: center;
  width: 100%; overflow: hidden; padding: 56px 12px 56px;
}

.lightbox-img {
  max-width: 100%; max-height: 100%; object-fit: contain; display: block;
  border-radius: 4px;
}

.lightbox-top {
  position: fixed; top: 0; left: 0; right: 0;
  padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.75) 0%, transparent 100%);
  z-index: 1001;
}

.lightbox-bottom {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 100%);
  z-index: 1001;
}

.lb-counter  { color: rgba(255,255,255,0.55); font-size: 0.82rem; white-space: nowrap; }
.lb-filename { font-size: 0.78rem; color: rgba(255,255,255,0.5); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: center; }

/* Icon buttons */
.btn-icon {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #fff; font-size: 1rem;
  transition: background 0.2s; flex-shrink: 0;
}

.btn-icon:hover { background: rgba(255,255,255,0.18); }
.btn-icon.accent { background: var(--accent); border-color: var(--accent); color: #000; font-weight: 700; }
.btn-icon.accent:hover { background: var(--accent-hover); }

/* Arrows */
.lb-arrow {
  position: fixed; top: 50%; transform: translateY(-50%); z-index: 1001;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 50%; width: 50px; height: 50px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: rgba(255,255,255,0.7); font-size: 1.4rem;
  transition: background 0.2s, color 0.2s;
}

.lb-arrow:hover { background: rgba(255,255,255,0.16); color: #fff; }
.lb-arrow.prev { left: 14px; }
.lb-arrow.next { right: 14px; }

@media (max-width: 520px) { .lb-arrow { display: none; } }

/* ── Pagination ──────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  flex-wrap: wrap;
  position: sticky; bottom: 0; z-index: 20;
  background: rgba(11,11,11,0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  .pagination { bottom: 56px; }
}

/* ── Scroll status (infinite scroll) ──────────── */
.scroll-status {
  text-align: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  font-size: 0.78rem;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .scroll-status { padding-bottom: calc(56px + 16px + env(safe-area-inset-bottom)); }
}

/* ── Multi-select ─────────────────────────────── */
.select-check {
  position: absolute; top: 6px; left: 6px; z-index: 3;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.65);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.15s;
  font-size: 0.7rem; color: transparent; font-weight: 800;
}
.select-check:hover { border-color: #fff; background: rgba(0,0,0,0.7); }
.select-check.checked {
  background: var(--accent); border-color: var(--accent); color: #000;
}
.select-check.checked::after { content: '✓'; }

.photo-item.selected img { outline: 3px solid var(--accent); outline-offset: -3px; }

.select-check-inline {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--border); background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.15s; font-size: 0.65rem; color: transparent; font-weight: 800;
}
.select-check-inline:hover { border-color: var(--accent); }
.select-check-inline.checked { background: var(--accent); border-color: var(--accent); color: #000; }
.select-check-inline.checked::after { content: '✓'; }

.list-item.selected { background: var(--accent-dim); }

.selection-bar {
  display: none;
  align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 20px;
  background: var(--accent-dim);
  border-bottom: 1px solid var(--border);
}
.selection-bar.active { display: flex; }
.selection-count { font-size: 0.84rem; color: var(--accent); font-weight: 600; margin-right: auto; }

/* ── Buttons ─────────────────────────────────── */
.btn {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 20px; color: var(--text);
  cursor: pointer; font-size: 0.9rem; font-family: var(--font);
  transition: all 0.18s; display: inline-flex; align-items: center; gap: 8px;
}

.btn:hover { background: var(--bg-card-hover); border-color: rgba(201,168,76,0.4); color: var(--accent); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--accent); border-color: var(--accent);
  color: #000; font-weight: 700;
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #000; }

.page-info { color: var(--text-muted); font-size: 0.85rem; padding: 0 4px; white-space: nowrap; }

/* ── Status Page ─────────────────────────────── */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 18px;
}

.stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); margin-bottom: 10px; }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-value.ok { color: #56c173; }
.stat-value.warn { color: #f0a63a; }
.stat-value.err { color: #e05252; }
.stat-value.sm { font-size: 1rem; }

/* ── States ──────────────────────────────────── */
.empty-state, .error-state {
  grid-column: 1 / -1;
  text-align: center; padding: 72px 20px; color: var(--text-muted);
}

.state-icon { font-size: 2.8rem; margin-bottom: 14px; opacity: 0.4; }

/* ── Input ───────────────────────────────────── */
.input {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; color: var(--text); font-size: 0.9rem; font-family: var(--font);
  width: 100%; outline: none; transition: border-color 0.2s;
}

.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-dim); }

/* ── Trigger section ─────────────────────────── */
.trigger-box {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin-top: 20px;
}

.trigger-box h3 { font-size: 0.95rem; margin-bottom: 8px; }
.trigger-box p { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 18px; line-height: 1.6; }

.trigger-row { display: flex; gap: 10px; flex-wrap: wrap; }
.trigger-row .input { flex: 1; min-width: 0; }

#trigger-result { margin-top: 14px; font-size: 0.85rem; line-height: 1.6; }
#trigger-result a { color: var(--accent); text-decoration: underline; }

/* ── Private badge ───────────────────────────── */
.badge-private {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.68rem; padding: 2px 7px; border-radius: 100px;
  background: var(--accent-dim); color: var(--accent);
  border: 1px solid rgba(201,168,76,0.2);
  font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
}

/* ── Loading spinner ─────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; display: inline-block;
}

/* ── Divider ─────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 28px 0; }

/* ══════════════════════════════════════════════
   SIDEBAR LAYOUT  (index.html SPA)
   ══════════════════════════════════════════════ */

body.spa { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }

.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  height: calc(100vh - 52px);
  min-height: 0;
}

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
  width: 260px;
  min-width: 160px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #0e0e0e;
  border-right: 1px solid var(--border);
  overflow: hidden;
  user-select: none;
  min-height: 0;
}

.sidebar-hdr {
  padding: 10px 14px 9px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 5px 0 24px;
}

.sidebar-body::-webkit-scrollbar { width: 3px; }
.sidebar-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Tree items ──────────────────────────────── */
.ti {
  display: flex; align-items: center; gap: 5px;
  border-radius: 5px; cursor: pointer;
  transition: background 0.14s;
  margin: 1px 5px; white-space: nowrap;
}
.ti:hover { background: rgba(255,255,255,0.04); }
.ti.active { background: var(--accent-dim); }
.ti.active .ti-label { color: var(--accent); }

.ti-year  { padding: 6px 8px; }
.ti-year  .ti-label { font-size: 0.87rem; font-weight: 700; }
.ti-event { padding: 4px 8px 4px 16px; }
.ti-event .ti-label { font-size: 0.82rem; }
.ti-session { padding: 4px 8px 4px 28px; }
.ti-session .ti-label { font-size: 0.8rem; color: var(--text-muted); }
.ti-session:hover .ti-label, .ti-session.active .ti-label { color: var(--accent); }

.ti-arrow {
  font-size: 0.58rem; color: var(--text-muted);
  width: 10px; flex-shrink: 0;
  display: inline-block;
  transition: transform 0.18s;
}
.ti.open .ti-arrow { transform: rotate(90deg); }
.ti-label { overflow: hidden; text-overflow: ellipsis; flex: 1; line-height: 1.35; }
.ti-lock  { font-size: 0.7rem; color: var(--accent); opacity: 0.6; flex-shrink: 0; }

.tree-children.hidden { display: none; }
.tree-loading { padding: 4px 28px; font-size: 0.78rem; color: var(--text-muted); }

/* ── Resize handle ───────────────────────────── */
.resize-handle {
  width: 5px; flex-shrink: 0;
  cursor: col-resize; position: relative;
}
.resize-handle::after {
  content: ''; position: absolute; inset: 0;
  left: 50%; transform: translateX(-50%);
  width: 2px; background: var(--border);
  transition: background 0.18s, width 0.15s;
}
.resize-handle:hover::after,
.resize-handle.dragging::after { background: var(--accent); width: 3px; }

/* ── Main content ────────────────────────────── */
.main-content {
  flex: 1; overflow-y: scroll; overflow-x: hidden;
  display: flex; flex-direction: column;
  scrollbar-gutter: stable;  min-height: 0;}

.main-content::-webkit-scrollbar { width: 10px; }
.main-content::-webkit-scrollbar-track { background: var(--bg); }
.main-content::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 6px;
  border: 2px solid var(--bg);
}
.main-content::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* ── Welcome screen ──────────────────────────── */
.welcome-screen {
  flex: 1; display: flex; align-items: center;
  justify-content: center; padding: 40px 24px;
}
.welcome-inner { text-align: center; max-width: 340px; }
.welcome-icon  { font-size: 3rem; opacity: 0.15; margin-bottom: 18px; }
.welcome-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; }
.welcome-sub   { font-size: 0.84rem; color: var(--text-muted); line-height: 1.8; }

/* ── Photo section header ────────────────────── */
.section-hdr   { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.section-crumb { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 5px; }
.section-crumb .hl { color: var(--accent); }
.section-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 3px; }
.section-meta  { font-size: 0.78rem; color: var(--text-muted); }
.photo-panel   { padding: 12px 14px; }

/* ── Mobile sidebar ──────────────────────────── */
.hamburger {
  display: none; flex-direction: column; gap: 4px;
  width: 34px; height: 34px; align-items: center; justify-content: center;
  cursor: pointer; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card);
}
.hamburger span { display: block; width: 16px; height: 1.5px; background: var(--text-muted); border-radius: 2px; }

.mob-overlay { display: none; position: fixed; inset: 0; z-index: 199; background: rgba(0,0,0,0.5); }
.mob-overlay.on { display: block; }

@media (max-width: 768px) {
  .hamburger { display: flex; }
  .app-body  { position: relative; }
  .sidebar {
    position: fixed; top: 52px; left: 0; bottom: 0;
    z-index: 200; transform: translateX(-100%);
    transition: transform 0.26s cubic-bezier(.4,0,.2,1);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    width: 280px !important;
  }
  .sidebar.open    { transform: translateX(0); }
  .resize-handle   { display: none; }
}

/* ── View toggle ─────────────────────────── */
.section-hdr {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.section-hdr-left { flex: 1; min-width: 0; }

.view-toggle { display: flex; gap: 4px; padding-top: 2px; flex-shrink: 0; }
.view-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 9px;
  color: var(--text-muted); cursor: pointer; font-size: 0.9rem;
  transition: all 0.15s; line-height: 1;
}
.view-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.view-btn:hover  { border-color: rgba(201,168,76,0.4); color: var(--text); }

/* ── Photo list view ─────────────────────── */
.photo-list { display: flex; flex-direction: column; gap: 2px; }

.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 10px; border-radius: 8px;
  cursor: pointer; transition: background 0.14s;
  content-visibility: auto;
  contain-intrinsic-size: 0 68px;
}
.list-item:hover { background: var(--bg-card); }

.list-thumb {
  width: 80px; height: 54px; border-radius: 5px;
  object-fit: cover; flex-shrink: 0; background: var(--bg-card);
  display: block;
}
.list-info { flex: 1; min-width: 0; }
.list-name { font-size: 0.84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-size { font-size: 0.72rem; color: var(--text-muted); margin-top: 3px; }

.list-dl {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; min-width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-muted); font-size: 1rem;
  transition: all 0.15s; flex-shrink: 0;
}
.list-dl:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ── Mobile bottom navigation ────────────── */
.mob-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 150;
  background: rgba(11,11,11,0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
}
.mob-nav-inner {
  display: flex; align-items: stretch;
  max-width: 480px; margin: 0 auto;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; padding: 5px 4px;
  cursor: pointer; background: none; border: none;
  color: var(--text-muted); font-family: var(--font);
  text-decoration: none; transition: color 0.15s;
}
.nav-btn:hover, .nav-btn.on { color: var(--accent); }
.nav-icon  { font-size: 1.2rem; }
.nav-label { font-size: 0.6rem; letter-spacing: 0.05em; text-transform: uppercase; }

/* On mobile: show bottom nav, pad content so it doesn't hide behind nav */
@media (max-width: 768px) {
  .mob-nav    { display: flex; }
  .app-body   { padding-bottom: 56px; }

  /* Larger download button in lightbox for fingers */
  #lb-download {
    position: fixed;
    bottom: calc(56px + 16px);
    right: 16px;
    width: 52px; height: 52px;
    font-size: 1.2rem;
    box-shadow: 0 4px 20px rgba(201,168,76,0.35);
    z-index: 1002;
    border-radius: 50%;
  }
}
