/* Deima's Album — warm paper & terracotta */
:root {
  --bg: #f5efe4;
  --surface: #fffaf2;
  --surface-2: #efe6d7;
  --ink: #2a211d;
  --muted: #7a6a60;
  --line: #e3d7c4;
  --accent: #b8523a;
  --accent-ink: #fffaf2;
  --accent-soft: #f3dcd2;
  --sage: #6f8468;
  --tile: #e8dccb;
  --shadow: 0 1px 2px rgb(60 30 10 / .08), 0 8px 24px rgb(60 30 10 / .08);
  --row-h: 140px;
  --gap: 4px;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16120f;
    --surface: #211b17;
    --surface-2: #2b231e;
    --ink: #f2e9dc;
    --muted: #a8998b;
    --line: #3a302a;
    --accent: #e07a5f;
    --accent-ink: #1b1411;
    --accent-soft: #3d2620;
    --sage: #9bb193;
    --tile: #2a221d;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}
@media (min-width: 640px) { :root { --row-h: 200px; --gap: 6px; } }
@media (min-width: 1200px) { :root { --row-h: 240px; } }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg circle[r="1.8"] { fill: currentColor; stroke: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.spacer { flex: 1; }

.brand {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  letter-spacing: -.01em;
  font-size: 2.2rem;
  margin: 0;
  line-height: 1.1;
}
.brand.small { font-size: 1.55rem; }

/* ---------- buttons & inputs */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: .55rem 1.1rem;
  cursor: pointer;
  font-weight: 600;
  transition: transform .1s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--accent); padding: .35rem .9rem; font-size: .9rem; }
.btn.wide { width: 100%; padding: .8rem; font-size: 1.05rem; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px;
  border: 0; border-radius: 50%;
  background: transparent; color: inherit;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.light { color: #fff; }
.icon-btn.light:hover { background: rgb(255 255 255 / .12); }
input[type="text"], input[type="password"], input[type="search"], input[type="number"], input:not([type]), select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .6rem .75rem;
  outline: none;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .tag-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

/* ---------- login */
.login {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--sage) 22%, transparent), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 36px 28px 24px;
  text-align: center;
  display: grid; gap: 14px;
}
.login-icon { margin: 0 auto 4px; border-radius: 20px; transform: rotate(-4deg); }
.login-sub { margin: -6px 0 6px; color: var(--muted); }
.login-error { color: var(--accent); min-height: 1.5em; margin: 0; font-size: .95rem; }
.login-card.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner { max-width: 1600px; margin: 0 auto; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); display: grid; gap: 10px; }
.brand-row { display: flex; align-items: center; gap: 10px; position: relative; }
.count { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.filters { display: flex; gap: 8px; }
.search { position: relative; flex: 1; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.search input { padding-left: 36px; border-radius: 999px; }
.filters select { width: auto; border-radius: 999px; padding-right: 2rem; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: .25rem .8rem;
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip small { color: var(--muted); margin-left: 4px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip[aria-pressed="true"] small { color: inherit; opacity: .8; }
.chip.special { border-style: dashed; }

.menu {
  position: absolute; right: 0; top: 46px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px; min-width: 220px;
  display: grid; z-index: 20;
}
.menu button { text-align: left; background: none; border: 0; padding: .6rem .8rem; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

.scan-bar { position: relative; font-size: .85rem; color: var(--muted); text-align: center; padding: 4px 16px 6px; }
.scan-bar i { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--accent); transition: width .5s; }

/* ---------- gallery: justified rows with pure CSS flex */
.gallery { max-width: 1600px; margin: 0 auto; padding: 8px max(8px, env(safe-area-inset-right)) 40px max(8px, env(safe-area-inset-left)); }
.group { margin-top: 18px; }
.group h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  margin: 0 8px 10px;
  display: flex; align-items: baseline; gap: 10px;
}
.group h2 small { font-family: var(--sans); font-size: .85rem; font-weight: 400; color: var(--muted); }
.rows { display: flex; flex-wrap: wrap; gap: var(--gap); }
.rows::after { content: ""; flex-grow: 1e9; }
.tile {
  --r: 1;
  position: relative;
  flex-grow: calc(var(--r) * 100);
  width: calc(var(--r) * var(--row-h));
  max-width: 100%;
  aspect-ratio: var(--r);
  max-height: calc(var(--row-h) * 1.6);
  background: var(--tile);
  border-radius: 6px;
  overflow: hidden;
  cursor: zoom-in;
  padding: 0; border: 0;
}
.tile img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .35s ease, transform .5s ease;
}
.tile img.loaded { opacity: 1; }
.tile:hover img { transform: scale(1.025); }
.tile .cap {
  position: absolute; inset: auto 0 0 0;
  padding: 26px 10px 8px;
  color: #fff; font-size: .82rem; line-height: 1.3; text-align: left;
  background: linear-gradient(transparent, rgb(0 0 0 / .6));
  opacity: 0; transition: opacity .2s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile:hover .cap, .tile:focus-visible .cap { opacity: 1; }
@media (hover: none) { .tile .cap { display: none; } }

.sentinel { height: 1px; }
.empty { text-align: center; color: var(--muted); padding: 80px 24px; max-width: 520px; margin: 0 auto; }
.empty h2 { font-family: var(--serif); color: var(--ink); font-weight: 600; }
.empty code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

/* ---------- viewer */
.viewer {
  position: fixed; inset: 0; z-index: 50;
  background: #0d0b0a;
  display: grid;
  grid-template-columns: 1fr auto;
  color: #fff;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.stage { position: relative; overflow: hidden; touch-action: pan-y pinch-zoom; user-select: none; -webkit-user-select: none; }
.v-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  padding: 58px 12px 12px;
  transition: transform .25s ease, opacity .25s;
}
.v-img.low { filter: blur(6px); transform: scale(1.01); }
.v-img.dragging { transition: none; }
.v-top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 4px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: linear-gradient(rgb(0 0 0 / .55), transparent);
}
.v-pos { font-size: .9rem; opacity: .75; margin-left: 4px; }
.nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 52px; border-radius: 50%;
  border: 0; background: rgb(255 255 255 / .1); color: #fff;
  display: grid; place-items: center; cursor: pointer;
  transition: background .2s;
}
.nav:hover { background: rgb(255 255 255 / .22); }
.nav.prev { left: 14px; } .nav.next { right: 14px; }
.nav[disabled] { opacity: 0; pointer-events: none; }
@media (hover: none) { .nav { display: none; } }
.v-caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 40px 20px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgb(0 0 0 / .65));
  font-size: .95rem; pointer-events: none;
}
.v-caption:empty { display: none; }
.v-caption b { font-family: var(--serif); font-size: 1.05rem; }

.panel {
  width: 360px;
  background: var(--surface);
  color: var(--ink);
  overflow-y: auto;
  border-left: 1px solid var(--line);
}
.viewer.no-panel .panel { display: none; }
.viewer:not(.no-panel) .v-caption { display: none; }
.panel-grip { display: none; }
.meta { padding: 24px 22px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 6px; }
.meta h2 { font-family: var(--serif); font-weight: 600; font-size: 1.35rem; margin: 0 0 8px; }
.meta label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 10px; }
.meta textarea { resize: vertical; min-height: 90px; }
.hint { font-size: .85rem; color: var(--muted); margin: 2px 0 0; }
.hint a { color: var(--accent); font-weight: 600; }
.date-row { display: grid; grid-template-columns: 1fr 1.6fr 1.2fr; gap: 6px; }
.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px; cursor: text;
}
.tag-input input { flex: 1; min-width: 120px; border: 0; padding: .3rem .4rem; box-shadow: none !important; background: transparent; }
.tag {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--accent-soft); color: var(--ink);
  border-radius: 999px; padding: .15rem .3rem .15rem .7rem; font-size: .92rem;
}
.tag button { border: 0; background: none; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.tag button:hover { background: rgb(0 0 0 / .08); color: var(--ink); }
.tag svg { width: 14px; height: 14px; }
.meta-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.m-status { color: var(--muted); font-size: .9rem; }
.m-status.ok { color: var(--sage); }
.m-status.err { color: var(--accent); }
.facts { margin: 22px 0 0; padding-top: 14px; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.facts dt { font-weight: 600; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 820px) {
  .viewer { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .panel {
    width: auto; max-height: 62dvh;
    border-left: 0; border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 30px rgb(0 0 0 / .35);
  }
  .panel-grip { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 0; }
  .meta { padding-top: 10px; }
  .v-img { padding: 56px 0 0; }
}

/* ---------- dialog & toast */
.dialog {
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--ink);
  padding: 0; width: min(440px, calc(100% - 32px));
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgb(20 10 5 / .45); }
.dialog-inner { padding: 22px; }
.dialog h2 { font-family: var(--serif); margin: 0 0 4px; }
.people-manage { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; max-height: 55dvh; overflow-y: auto; }
.people-manage li { display: flex; gap: 8px; align-items: center; }
.people-manage small { color: var(--muted); white-space: nowrap; min-width: 4.5em; text-align: right; }
.people-manage .empty-note { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: .6rem 1.1rem; border-radius: 999px; z-index: 100;
  box-shadow: var(--shadow); font-size: .95rem;
  animation: fade .2s;
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
