:root {
  color-scheme: light dark;
  --bg: #f4f2ec;
  --panel: #fffdf8;
  --ink: #1e201d;
  --muted: #676960;
  --line: #dedbd1;
  --accent: #2f5d4b;
  --accent-ink: #ffffff;
  --danger: #9d3d32;
  --shadow: 0 10px 30px rgba(30, 32, 29, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141613;
    --panel: #1d201b;
    --ink: #eceee6;
    --muted: #a7aa9f;
    --line: #33372f;
    --accent: #9ad5bb;
    --accent-ink: #142019;
    --danger: #e08f83;
    --shadow: 0 12px 34px rgba(0, 0, 0, .28);
  }
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-link { display: inline-flex; align-items: center; gap: 6px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.header-search { flex: 1 1 220px; }
.header-search input { width: 100%; padding: 8px 11px; font-size: .9rem; }
.search-add { display: flex; align-items: center; gap: 8px; flex: 1 1 340px; max-width: 540px; }
.search-toggle { display: none; width: 34px; height: 34px; padding: 0; place-items: center; border-radius: 50%; background: transparent; color: var(--accent); border-color: var(--line); }
.add-menu { position: relative; }
.add-trigger { width: 34px; height: 34px; padding: 0; border-radius: 50%; font-size: 1.15rem; line-height: 1; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.add-dropdown { position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; display: grid; min-width: 140px; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.add-dropdown[hidden] { display: none; }
.add-dropdown button { width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; background: transparent; color: var(--ink); border-color: transparent; padding: 8px 10px; font-weight: 500; }
.add-dropdown button:hover { background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
}
.topnav { display: flex; align-items: center; justify-content: center; gap: 18px; font-size: .92rem; margin-left: 0; }
.topnav a { color: var(--ink); }
.topnav .stat { color: var(--muted); font-size: .82rem; }
.topnav .quiet { color: var(--muted); }
.topnav .logout-danger { color: var(--danger); }
.topnav .logout-danger:hover { color: var(--danger); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 34px 28px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 22px; }
.eyebrow { margin: 0 0 4px; font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 0; font-size: clamp(1.9rem, 4vw, 3rem); letter-spacing: -.035em; line-height: 1.05; }
h2 { margin: 0; font-size: 1.05rem; letter-spacing: -.01em; }
.muted, .small { color: var(--muted); }
.small { font-size: .8rem; }
.breadcrumb { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
.filters, .create-row, .album-admin {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin: 0 0 24px;
}
input, select, button {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
  padding: 9px 11px;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
.filters input[type="search"] { flex: 1 1 240px; min-width: 180px; }
.filters select { flex: 0 1 230px; }
button, .button {
  cursor: pointer;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}
button:hover, .button:hover { filter: brightness(1.06); text-decoration: none; }
button.ghost, .button.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
button.danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); color: var(--danger); }
button.tiny { padding: 5px 8px; font-size: .76rem; border-radius: 7px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.photo-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); position: relative; }
.photo-card.is-favorite { border-color: color-mix(in srgb, #c99a2e 55%, var(--line)); }
.photo-badges { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.photo-badges form { margin-left: auto; }
.star { border: 0; background: color-mix(in srgb, var(--panel) 82%, transparent); color: #b8860b; font-size: 1.15rem; line-height: 1; padding: 4px 7px; border-radius: 8px; backdrop-filter: blur(5px); }
.star.static { display: inline-block; margin-right: auto; }
.badge { display: inline-block; background: color-mix(in srgb, var(--danger) 18%, var(--panel)); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 38%, var(--line)); border-radius: 999px; padding: 3px 8px; font-size: .7rem; font-weight: 700; }
.badge:hover { text-decoration: none; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 2px; }
.tag { display: inline-block; font-size: .72rem; padding: 2px 7px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line)); }
.tag:hover { text-decoration: none; }
.edit { margin: 5px 0; }
.edit > summary { cursor: pointer; font-size: .74rem; color: var(--muted); }
.edit form { display: flex; gap: 5px; margin-top: 6px; }
.edit input { flex: 1; min-width: 0; padding: 5px 7px; font-size: .76rem; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: .84rem; color: var(--muted); }
.check input { width: auto; padding: 0; }
.filters input[type="date"] { flex: 0 1 145px; min-width: 130px; }
.photo-link { display: block; background: color-mix(in srgb, var(--line) 55%, var(--panel)); }
.photo-link img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; }
.photo-meta { padding: 10px 11px 11px; }
.caption { margin: 0 0 4px; font-size: .88rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.photo-actions form { display: flex; gap: 5px; align-items: center; }
.photo-actions select { padding: 4px 6px; font-size: .74rem; max-width: 118px; }
.empty { padding: 52px 24px; text-align: center; background: var(--panel); border: 1px dashed var(--line); border-radius: 16px; }
.empty h2 { margin-bottom: 6px; }
.empty p { margin: 0; color: var(--muted); }
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.album-card { display: block; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 15px; overflow: hidden; box-shadow: var(--shadow); }
.album-card:hover { text-decoration: none; transform: translateY(-1px); }
.album-cover { aspect-ratio: 16 / 10; background: color-mix(in srgb, var(--line) 60%, var(--panel)); }
.album-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album-placeholder { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: .82rem; }
.album-body { padding: 13px 14px; }
.album-body p { margin: 3px 0 0; }
.album-admin { padding-top: 4px; }
.foot { max-width: 1180px; margin: 0 auto; padding: 0 28px 34px; color: var(--muted); font-size: .78rem; }
.lightbox { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; overflow: hidden; background: rgba(10, 12, 10, .88); backdrop-filter: blur(8px); }
.mini-overlay { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px; background: rgba(10, 12, 10, .62); backdrop-filter: blur(4px); }
.mini-overlay[hidden] { display: none; }
.mini-card { position: relative; width: min(100%, 430px); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px; box-shadow: var(--shadow); }
.mini-card h2 { margin: 4px 0 8px; font-size: 1.4rem; }
.mini-card form { display: grid; gap: 8px; margin-top: 14px; }
.mini-card p { margin: 0; }
.mini-close { position: absolute; top: 12px; right: 12px; border: 0; background: transparent; color: var(--muted); font-size: 1.4rem; line-height: 1; padding: 2px 6px; }
.favorite-album .album-cover { background: color-mix(in srgb, #c99a2e 18%, var(--panel)); }
.favorite-album h2::after { content: " ★"; color: #b8860b; }
.lightbox[hidden] { display: none; }
.lightbox-open { overflow: hidden; }
.lb-image { max-width: calc(100vw - 32px); max-height: calc(100vh - 170px); width: auto; height: auto; object-fit: contain; border-radius: 12px; box-shadow: 0 24px 70px rgba(0, 0, 0, .55); }
.lb-nav, .lb-close {
  position: absolute;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(20, 22, 20, .72);
  color: #fff;
  font-weight: 700;
}
.lb-nav { top: 50%; transform: translateY(-50%); width: 46px; height: 64px; border-radius: 12px; font-size: 2rem; line-height: 1; }
.lb-prev { left: 18px; }
.lb-next { right: 18px; }
.lb-close { top: 16px; right: 18px; width: 40px; height: 40px; border-radius: 50%; font-size: 1.5rem; line-height: 1; }
.lb-bar { position: absolute; bottom: 54px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 40px); color: #f4f4ef; font-size: .84rem; }
.lb-counter { font-variant-numeric: tabular-nums; opacity: .8; white-space: nowrap; }
.lb-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 390px); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 30px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 1.8rem; margin: 14px 0 6px; }
.login-card form { display: grid; gap: 8px; margin-top: 20px; }
.login-card label { font-size: .82rem; color: var(--muted); }
.login-card input { width: 100%; }
.login-card button { margin-top: 6px; }
.error { color: var(--danger); font-size: .9rem; }
@media (max-width: 640px) {
  .topbar { display: flex; padding: 12px 16px; align-items: stretch; flex-direction: column; gap: 9px; }
  .header-stats { order: 1; align-self: flex-end; }
  .search-add { order: 2; width: 100%; max-width: none; }
  .topnav { order: 3; width: 100%; justify-content: center; gap: 14px; flex-wrap: wrap; margin-left: 0; }
  .topnav .stat { display: none; }
  .search-toggle { display: inline-grid; }
  .header-search { display: none; flex: 1 1 140px; }
  .header-search.is-open { display: block; }
  .wrap { padding: 22px 16px 48px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 10px; }
  .foot { padding: 0 16px 24px; }
}

/* Albums home + tag-based CRUD */
.page-title { display: flex; align-items: flex-start; gap: 12px; }
.page-tools { position: relative; display: flex; align-items: center; }
.back-icon {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  margin-top: 2px; border: 1px solid var(--line); border-radius: 50%;
  color: var(--ink); font-size: 1.15rem; line-height: 1; flex: none;
}
.back-icon:hover { text-decoration: none; background: var(--panel); }
.icon-button {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border-radius: 50%; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); font-size: 1.35rem; line-height: 1;
}
.actions-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  width: min(360px, calc(100vw - 32px)); padding: 16px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow);
}
.actions-panel[hidden] { display: none; }
.actions-panel h2 { margin: 0 0 4px; font-size: 1rem; }
.actions-panel .small { margin: 0 0 12px; }
.action-form { display: grid; gap: 7px; margin: 0 0 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.action-form:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }
.action-form label { display: grid; gap: 3px; font-size: .78rem; color: var(--muted); }
.action-form input, .action-form select { width: 100%; padding: 7px 9px; }
.action-form .check { display: flex; align-items: center; }
.action-form .check input { width: auto; }
.album-card { position: relative; }
.album-link { display: block; color: inherit; }
.album-link:hover { text-decoration: none; }
.select-check {
  position: absolute; top: 8px; left: 8px; z-index: 3; width: 18px; height: 18px;
  accent-color: var(--accent); cursor: pointer;
}
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
@media (orientation: landscape) {
  .photo-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
.thumb-cell {
  position: relative; aspect-ratio: 1 / 1; overflow: hidden; border-radius: 10px;
  background: color-mix(in srgb, var(--line) 55%, var(--panel)); border: 1px solid var(--line);
}
.thumb-cell .lightbox-link, .thumb-cell img { display: block; width: 100%; height: 100%; }
.thumb-cell img { object-fit: cover; }
.thumb-cell .select-check { top: 4px; left: 4px; }
.date-group { margin: 0 0 26px; }
.date-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 0 9px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.date-heading h2 { margin: 0; font-size: .9rem; letter-spacing: .01em; }
.day-select { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; color: var(--muted); cursor: pointer; }
.day-select input { accent-color: var(--accent); }
.lb-info { display: grid; gap: 2px; min-width: 0; }
.lb-tags-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lb-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lb-tag { display: inline-block; padding: 2px 7px; border-radius: 999px; background: rgba(185, 230, 207, .14); color: #b9e6cf; border: 1px solid rgba(185, 230, 207, .3); font-size: .78rem; }
.lb-select { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 3; display: inline-flex; align-items: center; }
.lb-select input { width: 18px; height: 18px; accent-color: var(--accent); }
.lb-tags { margin: 0; color: #b9e6cf; font-weight: 650; }
.lb-caption { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .9; }
.lb-date { margin: 0; opacity: .65; font-size: .78rem; }

@media (max-width: 640px) {
  .page-head { align-items: flex-start; gap: 12px; flex-wrap: wrap; }
  .page-title { flex: 1; min-width: 0; }
  .page-tools { display: contents; }
  .page-tools .icon-button { order: 2; margin-left: auto; }
  .album-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .actions-panel { order: 3; flex: 0 0 100%; position: static; width: 100%; margin-top: 8px; }
  .action-menu { position: static; margin-top: 4px; }
}
.thumb-cell .fav-form { position: absolute; right: 4px; bottom: 4px; z-index: 3; }
.thumb-cell .star { opacity: .5; font-size: .9rem; padding: 2px 5px; }
.thumb-cell .star.is-on { opacity: 1; }
.action-fields { display: grid; gap: 7px; }
.action-fields[hidden] { display: none; }
.selection-count { margin: 0; font-size: .8rem; color: var(--muted); }
.action-select { position: relative; display: grid; gap: 3px; }
.field-label { font-size: .78rem; color: var(--muted); }
.action-trigger { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 8px 10px; background: var(--panel); color: var(--ink); border-color: var(--line); font-weight: 500; text-align: left; }
.action-menu { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 5; display: grid; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow); }
.action-menu[hidden] { display: none; }
.action-menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 9px; background: transparent; color: var(--ink); border-color: transparent; text-align: left; font-weight: 500; }
.action-menu button:hover { background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.action-menu .icon { width: 15px; height: 15px; }
@media (max-width: 640px) {
  .lb-image { max-height: calc(100vh - 150px); }
  .lb-bar { gap: 8px; font-size: .78rem; }
  .lb-nav { width: 38px; height: 52px; font-size: 1.6rem; }
  .lb-prev { left: 8px; }
  .lb-next { right: 8px; }
}
.topnav .nav-link { padding: 5px 9px; border-radius: 999px; }
.topnav .nav-link.is-active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 700; }
.header-stats { justify-self: end; color: var(--muted); font-size: .8rem; white-space: nowrap; }

.lb-edit { padding: 2px 7px; border: 1px solid rgba(255,255,255,.25); border-radius: 999px; background: rgba(20,22,20,.7); color: #f4f4ef; font-size: .76rem; }
.lb-edit-form { display: grid; gap: 5px; margin: 3px 0 5px; }
.lb-edit-form[hidden] { display: none; }
.lb-edit-form label { display: grid; gap: 2px; font-size: .72rem; color: rgba(255,255,255,.72); }
.lb-edit-form input { width: min(60vw, 300px); padding: 4px 7px; border-radius: 6px; font-size: .8rem; }
.lb-edit-form button { justify-self: start; padding: 4px 9px; border-radius: 6px; font-size: .76rem; }

/* Portrait header: brand, section links, and counts on one line */
@media (max-width: 640px) {
  .topbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 9px 12px;
  }
  .brand { flex: 0 0 auto; gap: 6px; font-size: .82rem; white-space: nowrap; }
  .brand-mark { width: 24px; height: 24px; border-radius: 7px; font-size: .64rem; }
  .topnav {
    order: 2;
    width: auto;
    margin: 0;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 2px;
  }
  .topnav .nav-link { padding: 4px 6px; font-size: .72rem; gap: 3px; }
  .topnav .nav-link .icon { width: 14px; height: 14px; }
  .header-stats {
    order: 3;
    align-self: center;
    font-size: .6rem;
    letter-spacing: -.02em;
    white-space: nowrap;
  }
}

/* Selection actions: icons appear only when items are selected */
.page-head { position: relative; }
.page-tools[hidden] { display: none; }
.selection-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.selection-actions[hidden] { display: none; }
.selection-actions .icon { width: 14px; height: 14px; }
.selection-actions .selection-delete { color: var(--danger); }
.selection-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.selection-panel[hidden] { display: none; }
.selection-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.selection-panel-head .small { margin: 0; }
.selection-close { border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; line-height: 1; padding: 0 2px; }
.selection-fields { display: grid; gap: 7px; }
.selection-fields[hidden] { display: none; }
.selection-fields label { display: grid; gap: 3px; font-size: .78rem; color: var(--muted); }
.selection-fields select, .selection-fields input { width: 100%; padding: 7px 9px; }
.selection-confirm { justify-self: start; }
@media (max-width: 640px) {
  .page-head { align-items: flex-start; flex-wrap: wrap; gap: 10px; }
  .page-title { flex: 1; min-width: 0; }
  .page-tools { display: flex; width: auto; margin-left: auto; flex: none; }
  .selection-panel { position: static; order: 3; flex: 0 0 100%; width: 100%; margin-top: 2px; }
}

/* Lightbox metadata: checkbox / date / tag links, plain text only */
.lb-bar { bottom: 18px; gap: 0; }
.lb-info { display: block; min-width: 0; }
.lb-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  overflow: visible;
  white-space: normal;
  opacity: 1;
  font-size: .84rem;
  font-weight: 500;
}
.lb-select {
  position: static;
  top: auto;
  left: auto;
  transform: none;
  z-index: auto;
  display: inline-flex;
  align-items: center;
  margin: 0 2px 0 0;
}
.lb-select input { width: 16px; height: 16px; }
.lb-date { margin: 0; opacity: .85; font-size: .84rem; white-space: nowrap; }
.lb-sep { opacity: .55; }
.lb-tags { display: inline; color: #b9e6cf; font-weight: 650; }
.lb-tags .lb-tag { display: inline; padding: 0; border: 0; background: transparent; color: inherit; font-size: inherit; }
.lb-tags a:hover { text-decoration: underline; }
