:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --text: #1d1b19;
  --muted: #6f6a64;
  --line: #e3dfd9;
  --accent: #1d1b19;
  --accent-text: #ffffff;
  --heart: #e0245e;
  --ok: #2f7d4f;
  --danger: #b3261e;
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --surface: #1e1c1b;
    --text: #efebe6;
    --muted: #a49d95;
    --line: #34312e;
    --accent: #efebe6;
    --accent-text: #141312;
    --heart: #ff4d7d;
    --ok: #63c28b;
    --danger: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}
a { color: inherit; text-underline-offset: 3px; }
img { max-width: 100%; display: block; }
h1, h2 { font-family: var(--serif); font-weight: 500; line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); }
h2 { font-size: 1.3rem; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--muted); margin: 0 0 .4rem; }
.eyebrow a { text-decoration: none; }

/* ---------- Forms & buttons ---------- */
.stack { display: grid; gap: 1rem; }
label { display: grid; gap: .35rem; font-weight: 500; }
label small { font-weight: 400; color: var(--muted); }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
input, textarea {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem; width: 100%;
}
input[type=checkbox] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--heart); outline-offset: 2px;
}
.prefix-input { display: flex; align-items: stretch; }
.prefix-input span { white-space: nowrap; padding: .6rem .5rem .6rem .75rem; border: 1px solid var(--line); border-right: 0; border-radius: 8px 0 0 8px; color: var(--muted); background: var(--surface); }
.prefix-input input { border-radius: 0 8px 8px 0; }

button, .button {
  font: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); text-decoration: none; white-space: nowrap;
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.link { background: none; border: 0; padding: 0; text-decoration: underline; color: inherit; border-radius: 0; }
.danger-link { color: var(--danger); background: none; border: 0; padding: 0; text-decoration: underline; }

.error { margin: 0; padding: .7rem .9rem; border-radius: 8px; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.notice { margin: 0 0 1rem; padding: .7rem .9rem; border-radius: 8px; background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.empty { color: var(--muted); padding: 3rem 0; text-align: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.75rem); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* ---------- Centered pages: home, gate, login ---------- */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.card.narrow { width: 100%; max-width: 26rem; }
.card.narrow h2 { margin-top: .5rem; font-size: 1.1rem; }
.intro { color: var(--muted); white-space: pre-line; }
.contact { margin: 1.5rem 0 0; color: var(--muted); font-size: .9rem; white-space: pre-line; border-top: 1px solid var(--line); padding-top: 1rem; }

/* ---------- Album page ---------- */
.album-page { padding: 0 clamp(1rem, 3vw, 2.5rem) 4rem; }
.album-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; padding: 2.5rem 0 1.25rem; }
.description { color: var(--muted); max-width: 60ch; white-space: pre-line; margin: 0; }
.who, .preview-note { margin: 0; color: var(--muted); font-size: .9rem; }
.who strong { color: var(--text); font-weight: 500; }

.toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .75rem 1.25rem; flex-wrap: wrap;
  padding: .75rem 0; margin-bottom: 1rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.toolbar .count { display: inline-flex; align-items: center; gap: .35rem; }
.toolbar .count strong { font-weight: 600; }
.toolbar #submit-form { margin-left: auto; }
.toolbar .locked { margin-left: auto; color: var(--muted); font-size: .9rem; }

/* Masonry columns: every photo keeps its own shape (--r = width/height).
   gallery.js places each tile in the shortest column, so the order reads
   left to right. Without JS, plain CSS columns are the fallback. */
.grid {
  --gap: clamp(.4rem, 1vw, .9rem);
  list-style: none; margin: 0; padding: 0;
  column-count: 4; column-gap: var(--gap);
}
@media (max-width: 900px) { .grid { column-count: 3; } }
@media (max-width: 600px) { .grid { column-count: 2; } }
.grid.only-mine .tile:not(.selected) { display: none; }
.tile {
  --r: 1.5;
  position: relative; border-radius: 6px; overflow: hidden; background: var(--line);
  aspect-ratio: var(--r); width: 100%;
  break-inside: avoid; margin-bottom: var(--gap);
}
.grid.masonry, .admin-grid.masonry { columns: auto; position: relative; }
.grid.masonry .tile, .admin-grid.masonry .admin-tile { position: absolute; margin: 0; }
.tile .open { all: unset; cursor: zoom-in; display: block; width: 100%; height: 100%; }
.tile img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s ease; }
.tile:hover img { transform: scale(1.02); }
.tile.selected { outline: 3px solid var(--heart); outline-offset: -3px; }
.tile .others {
  position: absolute; left: .4rem; bottom: .4rem; max-width: calc(100% - 3.6rem);
  font-size: .75rem; padding: .15rem .5rem; border-radius: 999px;
  background: rgba(0,0,0,.55); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Heart */
.heart {
  position: absolute; right: .4rem; bottom: .4rem;
  width: 2.6rem; height: 2.6rem; padding: 0; border-radius: 50%;
  background: rgba(0,0,0,.45); border: 0; color: #fff;
}
.heart:disabled { opacity: .7; }
.heart-icon { display: inline-block; width: 1.25rem; height: 1.25rem; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21s-7.5-4.6-9.6-9.2C.9 8.4 3 4.5 6.7 4.5c2.1 0 3.5 1.1 5.3 3 1.8-1.9 3.2-3 5.3-3 3.7 0 5.8 3.9 4.3 7.3C19.5 16.4 12 21 12 21z' fill='none' stroke='black' stroke-width='2'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21s-7.5-4.6-9.6-9.2C.9 8.4 3 4.5 6.7 4.5c2.1 0 3.5 1.1 5.3 3 1.8-1.9 3.2-3 5.3-3 3.7 0 5.8 3.9 4.3 7.3C19.5 16.4 12 21 12 21z' fill='none' stroke='black' stroke-width='2'/%3E%3C/svg%3E") center/contain no-repeat;
}
.heart[aria-pressed=true] { color: var(--heart); background: #fff; }
.heart[aria-pressed=true] .heart-icon, .heart-icon.on {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21s-7.5-4.6-9.6-9.2C.9 8.4 3 4.5 6.7 4.5c2.1 0 3.5 1.1 5.3 3 1.8-1.9 3.2-3 5.3-3 3.7 0 5.8 3.9 4.3 7.3C19.5 16.4 12 21 12 21z'/%3E%3C/svg%3E");
          mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21s-7.5-4.6-9.6-9.2C.9 8.4 3 4.5 6.7 4.5c2.1 0 3.5 1.1 5.3 3 1.8-1.9 3.2-3 5.3-3 3.7 0 5.8 3.9 4.3 7.3C19.5 16.4 12 21 12 21z'/%3E%3C/svg%3E");
}
.heart-icon.on { color: var(--heart); }
.heart.pop .heart-icon { animation: pop .25s ease; }
@keyframes pop { 50% { transform: scale(1.3); } }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 50; background: #0b0b0b; color: #f2f2f2; display: grid; grid-template-rows: 1fr auto; }
.lightbox[hidden] { display: none; }
.lightbox #lb-img { width: 100%; height: 100%; object-fit: contain; padding: max(env(safe-area-inset-top, 0px), 1rem) 3.5rem 0; min-height: 0; }
.lb-bar { padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom, 0px)); display: grid; gap: .35rem; text-align: center; }
.lb-caption { margin: 0; min-height: 1.5em; }
.lb-others { margin: 0; font-size: .85rem; color: #bbb; }
.lb-others:empty { display: none; }
.lb-actions { display: flex; justify-content: center; align-items: center; gap: .75rem; flex-wrap: wrap; }
.lb-btn { background: rgba(255,255,255,.1); color: #f2f2f2; border-color: rgba(255,255,255,.18); }
.lb-btn[hidden] { display: none; }
.heart.big { position: static; width: 3rem; height: 3rem; background: rgba(255,255,255,.12); }
.heart.big[aria-pressed=true] { background: #fff; }
.lb-pos { color: #999; font-size: .85rem; min-width: 4rem; }
.lb-nav, .lb-close { position: absolute; background: rgba(255,255,255,.08); border: 0; color: #fff; border-radius: 50%; width: 3rem; height: 3rem; font-size: 1.8rem; padding: 0; line-height: 1; }
.lb-nav { top: 50%; transform: translateY(-50%); }
.lb-nav.prev { left: .5rem; }
.lb-nav.next { right: .5rem; }
.lb-close { top: calc(.5rem + env(safe-area-inset-top, 0px)); right: .5rem; }
@media (max-width: 600px) {
  .lightbox #lb-img { padding: 3.5rem 0 0; }
  .lb-nav { top: auto; bottom: 5.5rem; transform: none; }
}

/* ---------- Admin ---------- */
.adminbar { display: flex; justify-content: space-between; align-items: center; padding: .9rem clamp(1rem, 3vw, 2rem); border-bottom: 1px solid var(--line); background: var(--surface); }
.adminbar .brand { text-decoration: none; font-weight: 600; }
.adminbar .brand span { color: var(--muted); font-weight: 400; }
.admin { max-width: 72rem; margin: 0 auto; padding: 1.5rem clamp(1rem, 3vw, 2rem) 4rem; display: grid; gap: 1.25rem; }
.narrow-admin { max-width: 40rem; }
.admin > p { margin: 0; }
.admin-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: 1.25rem; align-items: start; }
.tag { display: inline-block; font: 500 .75rem/1 var(--font); padding: .3rem .55rem; border-radius: 999px; background: var(--line); color: var(--muted); vertical-align: middle; }
.tag.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.tag.new { background: color-mix(in srgb, var(--heart) 16%, transparent); color: var(--heart); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; }
.list th, .list td { text-align: left; padding: .75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tr:last-child td { border-bottom: 0; }
.list th { font-size: .8rem; color: var(--muted); font-weight: 500; }

.selections { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.selections li { display: flex; gap: .5rem 1rem; align-items: center; flex-wrap: wrap; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.selections li:last-child { border-bottom: 0; }

.upload { margin-bottom: 1rem; display: grid; gap: .75rem; }
.dropzone { display: block; border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.5rem; text-align: center; cursor: pointer; font-weight: 400; }
.dropzone.over { border-color: var(--heart); background: color-mix(in srgb, var(--heart) 6%, transparent); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.progress { position: relative; height: 1.6rem; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); transition: width .2s; }
.progress .label { position: relative; display: block; text-align: center; font-size: .8rem; line-height: 1.6rem; mix-blend-mode: difference; color: #fff; }
.upload-errors { margin: 0; padding-left: 1.2rem; color: var(--danger); }
.upload-errors:empty { display: none; }

.admin-grid { list-style: none; margin: 0; padding: 0; column-count: 4; column-gap: .75rem; }
@media (max-width: 900px) { .admin-grid { column-count: 3; } }
@media (max-width: 600px) { .admin-grid { column-count: 2; } }
.admin-tile { --r: 1.5; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: grid; break-inside: avoid; margin-bottom: .75rem; }
.admin-grid:not(.readonly) .admin-tile { cursor: grab; }
.admin-tile.dragging { opacity: .35; }
.admin-tile img { aspect-ratio: var(--r); object-fit: cover; width: 100%; }
.admin-tile a { display: block; }
.admin-tile-body { padding: .5rem; display: grid; gap: .4rem; font-size: .85rem; }
.admin-tile .filename { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, monospace; font-size: .78rem; }
.admin-tile input { padding: .35rem .5rem; font-size: .85rem; }
.selected-by { color: var(--heart); }
.caption-form.saved input { border-color: var(--ok); }
.actions-row { display: flex; gap: 1rem 2rem; flex-wrap: wrap; align-items: center; }
.clear-form { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.filenames { margin-bottom: .75rem; }
