:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --surface-alt: #f5efe4;
  --ink: #2c1810;
  --ink-soft: #5a4632;
  --muted: #8b7355;
  --border: #e6dbc7;
  --accent: #b8763c;
  --accent-dark: #8f5826;
  --danger: #b3361b;
  --shadow: 0 1px 2px rgba(44, 24, 16, 0.04), 0 8px 24px rgba(44, 24, 16, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --max: 1100px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* overflow-x:clip prevents horizontal scrollbars without creating a
     scrolling context — overflow-x:hidden DOES create one, which scopes
     position:sticky inside it and breaks our floating photo library on
     desktop. clip is the modern, side-effect-free fix. Old Safari ignores
     the value and falls back to visible — acceptable for ~1% of users. */
  overflow-x: clip;
}

/* iOS-style tap highlight when buttons/links are pressed. */
button, a, [role="button"], .photo-card, .book-spine, .library-tile, .page-slot {
  -webkit-tap-highlight-color: rgba(184, 118, 60, 0.1);
}

/* Inputs at exactly 16px on iOS so Safari doesn't auto-zoom on focus.
   1rem in our root size IS 16px; this just locks it in case anything else
   inherits something smaller. */
input, textarea, select { font-size: 16px; }

h1, h2, h3 {
  font-family: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 0.5em;
}

h1 { font-size: clamp(2rem, 4vw, 3rem); line-height: 1.1; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Layout ---- */
.site {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.nav {
  border-bottom: 1px solid var(--border);
  background: rgba(250, 246, 240, 0.85);
  backdrop-filter: saturate(140%) blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.nav-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 14px max(24px, env(safe-area-inset-right)) 14px max(24px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.brand span { color: var(--accent); }

.nav-links { display: flex; gap: 18px; align-items: center; }
.nav-links a { color: var(--ink-soft); font-weight: 500; font-size: 0.95rem; }
.nav-links a:hover { color: var(--accent-dark); text-decoration: none; }

.container {
  max-width: var(--max);
  margin: 0 auto;
  padding:
    48px
    max(24px, env(safe-area-inset-right))
    80px
    max(24px, env(safe-area-inset-left));
  width: 100%;
  flex: 1;
}

.hero {
  text-align: center;
  margin: 24px 0 56px;
}
.hero p {
  color: var(--ink-soft);
  font-size: 1.1rem;
  max-width: 56ch;
  margin: 0 auto;
}

footer {
  border-top: 1px solid var(--border);
  padding:
    28px
    max(24px, env(safe-area-inset-right))
    calc(28px + env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---- Forms ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="date"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184, 118, 60, 0.15);
}

textarea { min-height: 90px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--accent-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { background: var(--muted); cursor: not-allowed; opacity: 0.7; }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-alt); color: var(--ink); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8a2614; }

.btn-small { padding: 7px 12px; font-size: 0.85rem; }

/* ---- Drop zone ---- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  background: var(--surface-alt);
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.dragover { border-color: var(--accent); background: #fbecd9; color: var(--ink); }
.dropzone input { display: none; }
.dropzone .preview { max-width: 100%; max-height: 320px; border-radius: var(--radius-sm); margin-top: 12px; }

/* ---- Photo grids ---- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.photo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s;
}
.photo-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.photo-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--surface-alt);
  display: block;
}
.photo-card.selected {
  outline: 3px solid var(--accent);
  outline-offset: -1px;
}
.photo-card .meta {
  padding: 12px 14px;
  font-size: 0.9rem;
}
.photo-card .meta .date {
  font-weight: 600;
  color: var(--ink);
}
.photo-card .meta .desc {
  color: var(--ink-soft);
  margin-top: 4px;
  font-size: 0.85rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================
   Homepage bookshelf — spines on stacked shelves
   ============================================================ */
.bookshelf {
  margin: 16px -8px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.shelf {
  position: relative;
  padding: 0 6px 0;
}
.shelf-books {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  min-height: 264px;
  padding: 28px 4px 0;
}
.shelf-plank {
  height: 18px;
  background:
    linear-gradient(180deg, #7a5132 0%, #5a3a22 60%, #3d2715 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 235, 200, 0.08),
    0 2px 0 rgba(0, 0, 0, 0.18),
    0 14px 18px -8px rgba(44, 24, 16, 0.35);
  border-radius: 2px;
  margin-bottom: 28px;
  position: relative;
}
.shelf-plank::after {
  /* subtle wood grain */
  content: "";
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(90deg,
      rgba(0,0,0,0.08) 0 1px,
      transparent 1px 18px,
      rgba(255,255,255,0.04) 18px 19px,
      transparent 19px 70px);
  border-radius: inherit;
  pointer-events: none;
}

/* ---- Individual spine ---- */
.book-spine {
  position: relative;
  width: 56px;
  height: 248px;
  border-radius: 2px 4px 4px 2px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1),
              box-shadow 0.2s ease,
              filter 0.2s;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.04),
    inset -2px 0 4px rgba(0,0,0,0.25),
    0 2px 4px rgba(0,0,0,0.25);
  outline: none;
}
.book-spine[data-h="1"] { height: 234px; }
.book-spine[data-h="2"] { height: 262px; }

.book-spine::before {
  /* page-edge highlight on the right side, slight curve on the left */
  content: "";
  position: absolute; inset: 0;
  background:
    linear-gradient(90deg,
      rgba(0,0,0,0.45) 0%,
      rgba(0,0,0,0.0) 6%,
      rgba(255,255,255,0.18) 18%,
      rgba(255,255,255,0) 35%,
      rgba(0,0,0,0) 65%,
      rgba(255,255,255,0.08) 84%,
      rgba(0,0,0,0.35) 100%);
  pointer-events: none;
  z-index: 1;
}

.book-spine .spine-band {
  position: absolute;
  left: 5px; right: 5px;
  height: 3px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.15),
    inset 0 -1px 0 rgba(0,0,0,0.4);
  z-index: 2;
}
.book-spine .spine-band.top { top: 22px; }
.book-spine .spine-band.bottom { bottom: 22px; }

.book-spine .spine-title {
  position: relative;
  z-index: 3;
  writing-mode: vertical-rl;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  color: #fff8ec;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  white-space: nowrap;
  max-height: 72%;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 8px 0;
}

.book-spine:hover,
.book-spine:focus-visible {
  transform: translateY(-10px);
  filter: brightness(1.08);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.08),
    inset -2px 0 4px rgba(0,0,0,0.25),
    0 12px 20px rgba(0,0,0,0.45);
}
.book-spine:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.book-spine:active { transform: translateY(-4px); }

/* Spine palette — deterministic per-book via data-color */
.book-spine[data-color="0"] { background: linear-gradient(180deg, #6c4126, #4a2a14); }
.book-spine[data-color="1"] { background: linear-gradient(180deg, #7d3232, #4f1f1f); }
.book-spine[data-color="2"] { background: linear-gradient(180deg, #355a3a, #1f3a26); }
.book-spine[data-color="3"] { background: linear-gradient(180deg, #2a4567, #16294a); }
.book-spine[data-color="4"] { background: linear-gradient(180deg, #c47338, #8a4519); }
.book-spine[data-color="4"] .spine-title { color: #fff; }
.book-spine[data-color="5"] { background: linear-gradient(180deg, #58447b, #322348); }

/* Pull-out overlay */
body.locked { overflow: hidden; }
.book-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(20, 12, 8, 0.7);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.book-overlay.open { opacity: 1; pointer-events: auto; }

.book-overlay-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  transform-origin: center;
  will-change: transform, opacity;
}

.book-pulled {
  position: relative;
  width: min(80vw, 320px);
  aspect-ratio: 4 / 5;
  border-radius: 4px 14px 14px 4px;
  overflow: hidden;
  background: linear-gradient(135deg, #5a3a22, #2c1810 80%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.06),
    0 36px 70px rgba(0,0,0,0.7),
    0 8px 16px rgba(0,0,0,0.55);
}
.book-pulled .pulled-cover-photo {
  position: absolute; inset: 0;
  background-size: cover;
  background-position: center;
}
.book-pulled .pulled-cover-shade {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,0) 35%, rgba(0,0,0,0.8) 100%),
    linear-gradient(90deg, rgba(0,0,0,0.35), rgba(0,0,0,0) 25%);
}
.book-pulled .pulled-cover-spine-shadow {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 18px;
  background: linear-gradient(90deg, rgba(0,0,0,0.6), rgba(0,0,0,0));
  pointer-events: none;
}
.book-pulled .pulled-cover-title {
  position: absolute;
  inset: auto 22px 22px 28px;
  color: #fff8ec;
}
.book-pulled .pulled-cover-title h3 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: clamp(1.2rem, 3vw, 1.7rem);
  font-weight: 700;
  line-height: 1.1;
  color: #fff8ec;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}
.book-pulled .pulled-cover-meta {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #f3e2c5;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.book-pulled-meta {
  text-align: center;
  color: #f5e9d4;
  max-width: 360px;
}
.book-pulled-meta h2 {
  margin: 0 0 4px;
  color: #f5e9d4;
  font-size: 1.3rem;
}
.book-pulled-meta p {
  margin: 0;
  color: #d9c8b3;
  font-size: 0.95rem;
}

.book-pulled-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.book-pulled-actions .btn-secondary {
  background: rgba(255,255,255,0.08);
  color: #fff8ec;
  border-color: rgba(255,255,255,0.2);
}
.book-pulled-actions .btn-secondary:hover {
  background: rgba(255,255,255,0.16);
  color: #fff8ec;
}

/* ---- Admin moderation row ---- */
.mod-row {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 12px;
  align-items: center;
}
.mod-row img { width: 140px; height: 140px; object-fit: cover; border-radius: var(--radius-sm); }
.mod-row .actions { display: flex; gap: 8px; }
.mod-row .info .date { font-weight: 600; }
.mod-row .info .desc { color: var(--ink-soft); margin-top: 4px; }

/* ============================================================
   Photo book reader — book-style with cover + 2-page spreads
   ============================================================ */

.reader-body { background: #1f1610; }
.reader-body .nav { background: rgba(31, 22, 16, 0.85); border-bottom-color: #3a2a1f; }
.reader-body .nav-links a { color: #d9c8b3; }
.reader-body .nav-links a:hover { color: #f0d9b3; }
.reader-body .brand { color: #f5e9d4; }
.reader-body footer { border-top-color: #3a2a1f; color: #8a755e; }

.reader-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px 16px;
  perspective: 2000px;
}

/* Page sizing — driven by CSS variables, overridable per format */
.book-cover, .spread {
  --page-w: min(38vw, 420px);
  --page-h: calc(var(--page-w) * 1.25);   /* 4:5 portrait default */
  --gutter: 4px;
}
.fmt-landscape.book-cover, .fmt-landscape.spread {
  --page-w: min(42vw, 480px);
  --page-h: calc(var(--page-w) * 0.8);    /* 5:4 */
}
.fmt-square.book-cover, .fmt-square.spread {
  --page-w: min(40vw, 440px);
  --page-h: var(--page-w);                /* 1:1 */
}

/* ---- Cover (front and back) ---- */
.book-cover {
  position: relative;
  width: var(--page-w);
  height: var(--page-h);
  border-radius: 4px 14px 14px 4px;       /* spine on the left */
  overflow: hidden;
  cursor: pointer;
  background: linear-gradient(135deg, #5a3a22, #3a2516 70%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.04),
    0 30px 60px rgba(0,0,0,0.55),
    0 6px 14px rgba(0,0,0,0.5);
  transform: rotateY(-2deg);
  transition: transform 0.3s ease;
  transform-origin: left center;
}
.book-cover.back {
  cursor: default;
  background: linear-gradient(135deg, #3a2516, #1f1410 70%);
  border-radius: 14px 4px 4px 14px;       /* spine on the right */
  transform: rotateY(2deg);
  transform-origin: right center;
}
.book-cover:hover { transform: rotateY(0deg); }
.book-cover .cover-photo {
  position: absolute; inset: 0;
  background-size: cover;
  background-position: center;
  filter: saturate(0.9) contrast(0.95);
}
.book-cover .cover-shade {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,0) 35%, rgba(0,0,0,0.7) 100%),
    linear-gradient(90deg, rgba(0,0,0,0.35), rgba(0,0,0,0) 30%);
}
.book-cover .cover-shade.dark {
  background: linear-gradient(180deg, rgba(0,0,0,0.2), rgba(0,0,0,0.6));
}
.book-cover .cover-text {
  position: absolute;
  inset: auto 28px 28px 28px;
  color: #fff8ec;
  font-family: "Fraunces", Georgia, serif;
}
.book-cover .cover-text h1 {
  color: #fff8ec;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-shadow: 0 2px 6px rgba(0,0,0,0.5);
  margin: 0 0 8px;
}
.book-cover .cover-text h2 {
  color: #fff8ec;
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  margin: 0 0 8px;
}
.book-cover .cover-text p {
  color: #f3e2c5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 0.95rem;
  line-height: 1.5;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  margin: 0;
}
.book-cover .cover-hint {
  display: inline-block;
  margin-top: 14px;
  font-size: 0.85rem;
  color: #f3e2c5;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
.book-cover .cover-spine-shadow {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 18px;
  background: linear-gradient(90deg, rgba(0,0,0,0.6), rgba(0,0,0,0));
  pointer-events: none;
}
.book-cover.back .cover-spine-shadow { left: auto; right: 0; transform: scaleX(-1); }

/* ---- Two-page spread ---- */
.spread {
  display: flex;
  align-items: stretch;
  position: relative;
  width: calc(var(--page-w) * 2 + var(--gutter));
  height: var(--page-h);
  border-radius: 4px;
  background: #2a1d14;
  box-shadow:
    0 30px 60px rgba(0,0,0,0.55),
    0 6px 14px rgba(0,0,0,0.5);
  cursor: pointer;
}
.spread.mobile {
  width: var(--page-w);
}
.spread::before {
  /* gutter shadow down the middle */
  content: "";
  position: absolute;
  left: 50%; top: 0; bottom: 0;
  width: 20px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(0,0,0,0.45), rgba(0,0,0,0) 30%, rgba(0,0,0,0) 70%, rgba(0,0,0,0.45));
  pointer-events: none;
  z-index: 5;
}
.spread.mobile::before { display: none; }

.page {
  position: relative;
  flex: 1;
  background: #f9f3e7;
  overflow: hidden;
  padding: 14px;
}
.page.left  { border-radius: 4px 0 0 4px; }
.page.right { border-radius: 0 4px 4px 0; }
.spread.mobile .page { border-radius: 4px; }
.page.blank {
  background:
    repeating-linear-gradient(135deg, #f9f3e7 0 12px, #f1e8d6 12px 14px);
}

/* ---- Page layouts ---- */
.page-photo {
  width: 100%;
  height: 100%;
  background: #ece2cf;
  border-radius: 3px;
  overflow: hidden;
}
/* Every photo fills its frame and is positioned by the admin-supplied
   object-position (set inline). Photos with different aspect ratios than
   their frame get cropped — the visible portion is the part the admin
   dragged into view in the builder. */
.page-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 50%;
  display: block;
}

.layout-single { padding: 0; }
.layout-single .page-photo { border-radius: 0; }

.page-stack {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 10px;
}
.page-stack.two .page-photo { flex: 1; }
.page-stack:not(.two) .page-photo { flex: 1; min-height: 0; }

.page-row {
  display: flex;
  height: 100%;
  gap: 10px;
}
.page-row.two .page-photo { flex: 1; }

.page-grid {
  display: grid;
  height: 100%;
  gap: 10px;
}
.page-grid.four { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.page-caption {
  flex: 0 0 auto;
  font-family: "Fraunces", Georgia, serif;
  text-align: center;
  color: var(--ink);
  padding-top: 6px;
}
.page-caption .date {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
}
.page-caption .desc {
  display: block;
  font-style: italic;
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-top: 2px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.page-empty { width: 100%; height: 100%; }

/* ---- Reader controls ---- */
.reader-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 0 8px;
}
.reader-arrow {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid #4a3525;
  background: rgba(255,255,255,0.04);
  color: #f5e9d4;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.reader-arrow:hover { background: rgba(255,255,255,0.1); }
.reader-arrow:active { transform: translateY(1px); }
.reader-arrow:disabled { opacity: 0.3; cursor: not-allowed; }
.reader-progress {
  font-family: "Fraunces", Georgia, serif;
  font-size: 0.95rem;
  color: #c5b59a;
  letter-spacing: 0.04em;
  min-width: 14ch;
  text-align: center;
}

/* ---- Page-flip animations ---- */
.spread, .book-cover {
  transform-style: preserve-3d;
}
@keyframes flipOutNext {
  from { opacity: 1; transform: rotateY(-2deg) translateX(0); }
  to   { opacity: 0; transform: rotateY(-25deg) translateX(-30px); }
}
@keyframes flipOutPrev {
  from { opacity: 1; transform: rotateY(2deg) translateX(0); }
  to   { opacity: 0; transform: rotateY(25deg) translateX(30px); }
}
@keyframes flipInNext {
  from { opacity: 0; transform: rotateY(25deg) translateX(30px); }
  to   { opacity: 1; transform: rotateY(0) translateX(0); }
}
@keyframes flipInPrev {
  from { opacity: 0; transform: rotateY(-25deg) translateX(-30px); }
  to   { opacity: 1; transform: rotateY(0) translateX(0); }
}
.flip-out-next { animation: flipOutNext 0.28s ease-in forwards; }
.flip-out-prev { animation: flipOutPrev 0.28s ease-in forwards; }
.flip-in-next  { animation: flipInNext 0.4s ease-out; }
.flip-in-prev  { animation: flipInPrev 0.4s ease-out; }

/* ============================================================
   Mobile / phones
   Single comprehensive block covering layout, components, reader,
   and admin builder for screens ≤720px (covers all phones in
   portrait + most in landscape).
   ============================================================ */
@media (max-width: 720px) {
  /* ---- Layout shell ---- */
  .container {
    padding:
      28px max(16px, env(safe-area-inset-right))
      48px max(16px, env(safe-area-inset-left));
  }
  .nav-inner {
    padding: 12px max(16px, env(safe-area-inset-right))
             12px max(16px, env(safe-area-inset-left));
    gap: 12px;
  }
  .brand { font-size: 1.2rem; }
  .nav-links { gap: 14px; }
  .nav-links a { font-size: 0.9rem; }

  h1 { font-size: clamp(1.7rem, 6.5vw, 2.4rem); }
  h2 { font-size: 1.3rem; }
  h3 { font-size: 1.05rem; }

  .hero { margin: 8px 0 32px; }
  .hero p { font-size: 1rem; }

  .card { padding: 20px 18px; }

  /* ---- Buttons: hit a 44px minimum tap target ---- */
  .btn { padding: 12px 18px; font-size: 1rem; min-height: 44px; }
  .btn-small { padding: 9px 14px; font-size: 0.92rem; min-height: 38px; }

  /* ---- Inputs feel chunkier on touch ---- */
  input[type="text"], input[type="date"], input[type="email"],
  input[type="password"], textarea, select {
    padding: 13px 14px;
  }

  /* ---- Photo grids ---- */
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }

  /* ---- Bookshelf on phones: smaller spines, shorter shelves ---- */
  .bookshelf { margin: 12px -12px 0; }
  .shelf { padding: 0 8px; }
  .shelf-books { gap: 3px; padding: 18px 4px 0; min-height: 220px; }
  .book-spine {
    width: 44px;
    height: 208px;
  }
  .book-spine[data-h="1"] { height: 196px; }
  .book-spine[data-h="2"] { height: 220px; }
  .book-spine .spine-title { font-size: 0.82rem; }
  .book-spine .spine-band.top { top: 16px; }
  .book-spine .spine-band.bottom { bottom: 16px; }
  .shelf-plank { height: 14px; margin-bottom: 22px; }
  .book-spine:hover { transform: translateY(-6px); }     /* less lift on touch */

  /* Pulled-out modal on mobile */
  .book-pulled { width: min(78vw, 280px); }
  .book-pulled-meta { padding: 0 12px; }
  .book-pulled-meta h2 { font-size: 1.15rem; }
  .book-pulled-meta p { font-size: 0.9rem; }
  .book-pulled-actions { width: 100%; padding: 0 12px; }
  .book-pulled-actions .btn { flex: 1; min-width: 0; }

  /* ---- Tabs: scroll horizontally if they don't fit ---- */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-left: -16px;
    margin-right: -16px;
    padding: 0 16px;
    flex-wrap: nowrap;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; padding: 12px 14px; font-size: 0.95rem; }

  /* ---- Pending-review row: stack image + info, actions wrap below ---- */
  .mod-row {
    grid-template-columns: 96px 1fr;
    grid-template-rows: auto auto;
    gap: 12px;
    padding: 12px;
  }
  .mod-row img { width: 96px; height: 96px; }
  .mod-row .info { min-width: 0; }
  .mod-row .actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  /* ---- Admin book row ---- */
  .admin-book-row {
    grid-template-columns: 60px 1fr auto;
    gap: 12px;
    padding: 10px 12px;
  }
  .admin-book-cover { width: 60px; height: 76px; }
  .admin-book-meta h3 { font-size: 1rem; }
  .admin-book-meta p { font-size: 0.85rem; }

  /* ---- Book builder ---- */
  .builder-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .builder-header h2 { font-size: 1.3rem; }
  .builder-header .row { flex-wrap: wrap; }
  .builder-meta { padding: 18px 16px; }
  .builder-row { flex-direction: column; gap: 14px; }

  .format-picker { gap: 8px; }
  .format-option { min-width: 0; padding: 10px 8px 8px; flex: 1 1 28%; }
  .format-card.portrait { width: 30px; height: 38px; }
  .format-card.landscape { width: 42px; height: 34px; }
  .format-card.square { width: 36px; height: 36px; }
  .format-name { font-size: 0.85rem; }
  .format-aspect { font-size: 0.72rem; }

  .builder-grid { gap: 14px; grid-template-columns: 1fr; }

  /* Keep the photo library reachable on phones. It sticks just below the
     site nav and scrolls internally so it never takes more than ~35vh, no
     matter how many photos you have. */
  .builder-library {
    position: sticky;
    top: 56px;                 /* matches the mobile nav height */
    max-height: 36vh;
    overflow-y: auto;
    z-index: 20;
    padding: 12px 14px 14px;
    -webkit-overflow-scrolling: touch;
  }
  .builder-library h3 { font-size: 0.95rem; }
  .library-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }

  .builder-pages { padding: 14px; }
  .page-card { padding: 12px; cursor: default; }
  .page-card-header { flex-wrap: wrap; gap: 8px; }
  .page-card-header > .row:last-child {
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
    justify-content: flex-end;
  }
  .layout-select { flex: 1 1 140px; }
  .page-slots { height: 180px; }
  .page-handle { display: none; }   /* drag-handle dragging isn't reliable on touch — use ↑/↓ buttons */

  /* ---- Upload form ---- */
  .dropzone { padding: 24px 16px; }
  .dropzone .preview { max-height: 240px; }

  /* Generic row layouts wrap on mobile */
  .row { flex-wrap: wrap; }
  .row.between { gap: 8px 12px; }

  /* ---- Photo book reader ---- */
  .reader-stage {
    padding:
      14px max(8px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }
  .book-cover, .spread { --page-w: min(90vw, 380px); }
  .book-cover .cover-text { inset: auto 18px 18px 18px; }
  .book-cover .cover-text h1 { font-size: clamp(1.4rem, 5.5vw, 2rem); }
  .book-cover .cover-text p { font-size: 0.88rem; }
  .reader-controls { gap: 14px; padding: 14px 0 8px; }
  .reader-arrow { width: 48px; height: 48px; font-size: 1.7rem; }
  .reader-progress { font-size: 0.88rem; min-width: 9ch; }

  .page { padding: 10px; }
  .page-stack { gap: 8px; }
  .page-row { gap: 8px; }
  .page-grid { gap: 8px; }
  .page-caption .date { font-size: 0.8rem; }
  .page-caption .desc { font-size: 0.78rem; }

  /* footer respects iPhone home-indicator area */
  footer {
    padding:
      24px max(16px, env(safe-area-inset-right))
      calc(24px + env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }
}

/* ============================================================
   Very narrow screens (≤380px). Tighten further.
   ============================================================ */
@media (max-width: 380px) {
  .container {
    padding:
      24px max(12px, env(safe-area-inset-right))
      40px max(12px, env(safe-area-inset-left));
  }
  .nav-inner { padding: 10px 12px; gap: 8px; }
  .brand { font-size: 1.1rem; }
  .nav-links { gap: 10px; }
  .nav-links a { font-size: 0.85rem; }
  .book-spine { width: 38px; height: 184px; }
  .book-spine[data-h="1"] { height: 172px; }
  .book-spine[data-h="2"] { height: 198px; }
  .book-spine .spine-title { font-size: 0.74rem; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .library-grid { grid-template-columns: repeat(3, 1fr); }
  .format-option { padding: 8px 6px; }
  .format-name { font-size: 0.78rem; }
  .format-aspect { font-size: 0.68rem; }
}

/* ============================================================
   Landscape phones — keep the reader vertical-centered, prevent
   the spread from getting squished by the URL bar.
   ============================================================ */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .book-cover, .spread {
    --page-w: min(40vw, 320px);
    --page-h: calc(var(--page-w) * 1.25);
  }
  .fmt-landscape.book-cover, .fmt-landscape.spread {
    --page-w: min(44vw, 360px);
    --page-h: calc(var(--page-w) * 0.8);
  }
  .fmt-square.book-cover, .fmt-square.spread {
    --page-w: min(40vw, 320px);
    --page-h: var(--page-w);
  }
  .reader-stage { padding: 8px; }
  .reader-controls { padding: 8px 0; }
}

/* ---- Toasts / messages ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.95rem;
}
.alert-success { background: #e9f5e1; color: #2f5a1c; border: 1px solid #c5e3b4; }
.alert-error { background: #fce8e3; color: #762315; border: 1px solid #f0b3a4; }
.alert-info { background: #f1ebe1; color: #5a4632; border: 1px solid var(--border); }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
}
.muted { color: var(--muted); font-size: 0.9rem; }

.hidden { display: none !important; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.tab {
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); }

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

.book-builder-photos {
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px;
  margin: 0 -4px;
}

/* ============================================================
   Admin: book builder
   ============================================================ */
.container-wide { max-width: 1320px; }

.builder { padding-top: 12px; }
.builder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.builder-header h2 { margin: 0; }

.builder-meta { padding: 22px 24px; margin-bottom: 16px; }
.builder-row { display: flex; gap: 16px; }
.builder-row .field { flex: 1; }

/* Format picker */
.format-picker {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.format-option {
  flex: 1;
  min-width: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}
.format-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.format-option:has(input:checked) {
  border-color: var(--accent);
  background: #fbecd9;
}
.format-card {
  display: block;
  background: linear-gradient(135deg, #5a3a22, #2c1810 80%);
  border-radius: 2px 6px 6px 2px;
  box-shadow: 0 4px 8px rgba(44, 24, 16, 0.2);
}
.format-card.portrait { width: 36px; height: 45px; }
.format-card.landscape { width: 50px; height: 40px; }
.format-card.square { width: 44px; height: 44px; }
.format-name { font-weight: 600; font-size: 0.9rem; }
.format-aspect { font-size: 0.78rem; color: var(--muted); }

/* Builder grid (library + pages) */
.builder-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 980px) {
  .builder-grid { grid-template-columns: 1fr; }
}

.builder-library {
  position: sticky;
  top: 80px;
  align-self: start;                 /* keep library at its natural height — defeats grid-stretch */
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding: 18px;
  z-index: 5;
}
.builder-library h3 {
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0;
}
.library-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.library-tile {
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-alt);
  cursor: grab;
  transition: transform 0.1s, box-shadow 0.1s;
}
.library-tile:hover { transform: scale(1.04); box-shadow: var(--shadow); }
.library-tile.dragging { opacity: 0.4; }
.library-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Pages list */
.builder-pages { padding: 18px; }
.builder-bottom-actions {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.builder-pages h3 {
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0;
}
.pages-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.page-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
  transition: box-shadow 0.15s, transform 0.05s, border-color 0.15s;
  cursor: grab;
}
.page-card:hover { box-shadow: var(--shadow); }
.page-card.dragging { opacity: 0.5; }
.page-card.drop-before { border-top: 3px solid var(--accent); }
.page-card.drop-after { border-bottom: 3px solid var(--accent); }
.page-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.page-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 1.1rem;
  user-select: none;
}
.page-num {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  font-size: 1rem;
}
.layout-select {
  width: auto;
  padding: 6px 10px;
  font-size: 0.88rem;
}

/* Page slot grids per layout — match the reader visually */
.page-slots {
  display: grid;
  gap: 8px;
  height: 220px;
}
.page-slots.layout-single { grid-template-columns: 1fr; }
.page-slots.layout-single-caption { grid-template-columns: 1fr; }
.page-slots.layout-two-horizontal { grid-template-columns: 1fr 1fr; }
.page-slots.layout-two-vertical { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.page-slots.layout-grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.page-slot {
  position: relative;
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.page-slot.empty:hover { background: #f1ebe1; }
.page-slot.active { border-color: var(--accent); border-style: solid; background: #fbecd9; }
.page-slot.drop-target { border-color: var(--accent); border-style: solid; background: #fbecd9; }
.page-slot.filled { border-style: solid; }
.page-slot img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  touch-action: none;          /* let our pointer handlers own touch gestures */
}
.page-slot.dragging-photo img { cursor: grabbing; }
.slot-hint {
  position: absolute;
  left: 50%; bottom: 6px;
  transform: translateX(-50%);
  padding: 3px 8px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.page-slot.filled:hover .slot-hint { opacity: 1; }
.page-slot.dragging-photo .slot-hint { opacity: 0; }
.slot-placeholder { color: var(--muted); font-size: 0.85rem; padding: 6px; text-align: center; }
.slot-clear {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.slot-clear:hover { background: rgba(0,0,0,0.75); }

/* Admin book list */
.admin-book-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-book-row {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.admin-book-cover {
  width: 80px;
  height: 100px;
  border-radius: 2px 6px 6px 2px;
  background: linear-gradient(135deg, #5a3a22, #2c1810 80%) center/cover;
  background-size: cover;
  box-shadow: 0 4px 8px rgba(44, 24, 16, 0.18);
}
.admin-book-meta h3 { margin: 0 0 2px; font-size: 1.1rem; }
.admin-book-meta p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============ Bulk upload page ============ */
.bulk-apply {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(0,0,0,0.015);
}
.bulk-apply label.small {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.upload-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
.upload-row {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.upload-row.status-uploading { border-color: var(--accent); }
.upload-row.status-done { border-color: #76a070; background: rgba(118, 160, 112, 0.08); }
.upload-row.status-error { border-color: var(--danger, #c75050); background: rgba(199, 80, 80, 0.06); }

.upload-thumb {
  width: 88px;
  height: 88px;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: #f0eae0;
}
.upload-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.upload-fields { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.upload-name {
  font-size: 0.85rem;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-field-row { display: flex; gap: 8px; flex-wrap: wrap; }
.upload-field-row input[type="date"] { width: 150px; }
.upload-field-row input[type="text"] { flex: 1; min-width: 140px; }
.upload-status {
  font-size: 0.82rem;
  color: var(--ink-soft);
  min-height: 1em;
}
.upload-row.status-done .upload-status { color: #4f7a48; }
.upload-row.status-error .upload-status { color: var(--danger, #c75050); }

.upload-remove {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.9rem;
}
.upload-remove:hover { background: rgba(0,0,0,0.04); color: var(--ink); }

@media (max-width: 720px) {
  .upload-row {
    grid-template-columns: 64px 1fr auto;
    gap: 10px;
    padding: 8px;
  }
  .upload-thumb { width: 64px; height: 64px; }
  .upload-field-row input[type="date"] { width: 130px; }
  .upload-field-row input[type="text"] { width: 100%; flex: 1 0 100%; }
}

/* ============ Photo edit modal (shared by admin) ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(20, 14, 10, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  animation: modal-fade 0.18s ease-out;
}
@keyframes modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  padding: 22px;
  max-width: 560px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
.modal-card h3 { margin: 0 0 12px; font-size: 1.2rem; }
.modal-body {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 16px;
  align-items: start;
}
.modal-thumb {
  width: 140px;
  height: 140px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #f0eae0;
}
.modal-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.modal-fields .field { margin-bottom: 12px; }
.modal-fields .field:last-child { margin-bottom: 0; }
.modal-fields .small { font-size: 0.75rem; margin-top: 4px; }

@media (max-width: 560px) {
  .modal-body { grid-template-columns: 1fr; }
  .modal-thumb { width: 100%; height: 200px; }
}

/* Edit affordances on approved photo tiles and book builder slots */
.photo-card.editable { position: relative; }
.photo-edit-btn {
  position: absolute;
  top: 6px; right: 6px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  z-index: 2;
}
.photo-card.editable:hover .photo-edit-btn,
.photo-card.editable:focus-within .photo-edit-btn { opacity: 1; }
.photo-edit-btn:hover { background: rgba(0, 0, 0, 0.75); }
/* On touch devices hover doesn't apply — keep the button visible. */
@media (hover: none) {
  .photo-edit-btn { opacity: 1; }
}

.slot-edit {
  position: absolute;
  top: 4px;
  right: 32px;            /* sits to the left of .slot-clear */
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.slot-edit:hover { background: rgba(0,0,0,0.75); }

/* ============ Live Photos ============
 *
 * .live-photo wraps an <img> and <video> on top of each other. The video
 * starts at opacity 0 (so the still shows). When playback begins
 * (auto-once on view, or on hover/touch) the parent gets .playing and the
 * video fades in. Both elements use object-fit:cover so the same
 * object-position can be applied to either via inline style — keeping
 * drag-to-reposition behaviour intact for live photos.
 */
.live-photo {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
}
.live-photo img,
.live-photo video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.live-photo video {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  background: transparent;
}
.live-photo.playing video {
  opacity: 1;
}
/* "static" variant — used by the admin so we still surface the LIVE
 * badge without loading the .mov. */
.live-photo.static video { display: none; }

.live-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 2px 7px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  border-radius: 4px;
  z-index: 2;
  pointer-events: none;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  /* Tiny dot indicator to evoke a record/motion light. */
}
.live-badge::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffe17a;
  margin-right: 5px;
  vertical-align: 1px;
  box-shadow: 0 0 4px rgba(255, 225, 122, 0.8);
}
/* Smaller badge variant for compact contexts (library tiles, upload rows,
 * book builder slots). */
.live-badge-tile,
.live-badge-slot {
  top: 4px;
  left: 4px;
  font-size: 0.55rem;
  padding: 1px 5px;
  letter-spacing: 0.08em;
}
.live-badge-tile::before,
.live-badge-slot::before {
  width: 5px;
  height: 5px;
  margin-right: 4px;
}

/* When a photo-card holds a Live Photo, the LIVE badge sits inside the
 * card frame above the image. Make sure card-level border-radius doesn't
 * clip it awkwardly. */
.photo-card.has-live .live-badge,
.library-tile.has-live .live-badge {
  border-radius: 3px;
}
/* The card normally relies on .photo-card img setting the square frame.
 * For a Live Photo the direct child is a .live-photo wrapper, so apply
 * the same 1:1 frame there. */
.photo-card > .live-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  background: var(--surface-alt);
}
.photo-card > .live-photo img,
.photo-card > .live-photo video {
  background: var(--surface-alt);
}

/* Tiny text-button used in the upload list to drop a paired video. */
.linklike {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.linklike:hover { color: var(--ink); }
