:root {
  --bg: #fbfaf6;
  --paper: #ffffff;
  --ink: #1f2a37;
  --ink-soft: #4a5568;
  --whitewash: #f3eee3;
  --aegean: #1e5b8a;
  --aegean-deep: #163f63;
  --sky: #6ba9d4;
  --sand: #e8dfc7;
  --gold: #b8946a;
  --shadow: 0 30px 60px -28px rgba(22, 63, 99, 0.32);
  --radius: 14px;
  --serif: "Cormorant Garamond", "Garamond", "EB Garamond", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% -10%, rgba(107, 169, 212, 0.18), transparent 55%),
    radial-gradient(circle at 110% 20%, rgba(232, 223, 199, 0.45), transparent 55%),
    var(--bg);
}

a { color: var(--aegean); text-decoration: none; }
a:hover { color: var(--aegean-deep); text-decoration: underline; }

/* Navigation */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 32px;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.nav-brand {
  font-family: var(--serif);
  font-size: 18px;
  font-style: italic;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--aegean-deep);
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}
.nav-sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  margin-top: 2px;
}

.nav-links { display: flex; gap: 28px; }
.nav-links a {
  color: var(--ink-soft);
  font-weight: 500;
}
.nav-links a:hover { color: var(--aegean-deep); text-decoration: none; }
.nav-links a.is-active { color: var(--aegean-deep); }

/* Cover */
.cover {
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 24px 56px;
  text-align: center;
}

.home-body {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.home-body .nav {
  flex-shrink: 0;
  padding: 14px 32px;
}
.home-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 16px 12px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}
.home-main .book-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px;
}
.home-main .book-stage {
  flex: 1;
  min-height: 0;
  height: auto;
}

.masthead {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 12px;
  text-align: center;
}

.masthead-names {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--aegean-deep);
}

.masthead-amp {
  font-style: italic;
  color: var(--gold);
  margin: 0 6px;
}

.masthead-meta {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
  margin: 6px 0 0;
  letter-spacing: 0.02em;
}

.cover-eyebrow {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--aegean);
  margin-bottom: 24px;
}

.cover-names {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(56px, 12vw, 130px);
  line-height: 0.95;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--aegean-deep);
}

.cover-amp {
  display: block;
  font-style: italic;
  font-size: 0.55em;
  color: var(--gold);
  margin: 12px 0;
}

.cover-meta {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(20px, 3vw, 28px);
  color: var(--ink-soft);
  margin: 36px 0 0;
}

.cover-divider {
  width: 60px;
  height: 1px;
  background: var(--gold);
  margin: 28px auto;
  border: none;
}

.cover-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 56px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 28px;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 200ms ease, background 200ms ease;
}

.btn-primary {
  background: var(--aegean);
  color: white;
  box-shadow: 0 12px 24px -12px rgba(30, 91, 138, 0.7);
}
.btn-primary:hover { background: var(--aegean-deep); transform: translateY(-1px); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--aegean-deep);
  border-color: rgba(30, 91, 138, 0.3);
}
.btn-ghost:hover { background: rgba(30, 91, 138, 0.06); border-color: var(--aegean); text-decoration: none; }

/* Page wrapper */
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 96px;
}

.page-header {
  text-align: center;
  margin: 16px 0 40px;
}

.page-title {
  font-family: var(--serif);
  font-size: clamp(36px, 6vw, 60px);
  font-weight: 400;
  color: var(--aegean-deep);
  margin: 0;
}

.page-subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(16px, 2vw, 20px);
  color: var(--ink-soft);
  margin: 8px 0 0;
}

/* Book reader */
.book-shell {
  background: linear-gradient(180deg, #f7f3eb, #ece4d2);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.book-stage {
  position: relative;
  background: var(--whitewash);
  border-radius: 8px;
  overflow: hidden;
  height: var(--book-stage-height, 70vh);
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-flip {
  position: relative;
  margin: 0 auto;
  max-width: 100%;
  perspective: 2400px;
  perspective-origin: 50% 50%;
  overflow: hidden;
}

.flip-page {
  position: absolute;
  inset: 0;
  background: white;
  box-shadow: 0 14px 40px -20px rgba(22, 63, 99, 0.45);
  overflow: hidden;
}
.flip-page img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

.flip-page-underlay {
  z-index: 1;
}
.flip-page-current {
  z-index: 2;
}

.flip-page-flipper {
  position: absolute;
  inset: 0;
  z-index: 3;
  transform-style: preserve-3d;
  transition: transform var(--flip-ms, 720ms) cubic-bezier(0.45, 0.05, 0.35, 1);
  pointer-events: none;
}
.flip-next .flip-page-flipper,
.flip-next.flip-page-flipper { transform-origin: left center; }
.flip-prev .flip-page-flipper,
.flip-prev.flip-page-flipper { transform-origin: right center; }
.flip-page-flipper.flip-next { transform-origin: left center; }
.flip-page-flipper.flip-prev { transform-origin: right center; }
.flip-page-flipper.flip-next.is-flipping { transform: rotateY(-180deg); }
.flip-page-flipper.flip-prev.is-flipping { transform: rotateY(180deg); }

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: white;
  overflow: hidden;
}
.flip-face img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}
.flip-face-front { transform: rotateY(0deg); }
.flip-face-back { transform: rotateY(180deg); }

.flip-shadow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.0) 0%, rgba(0, 0, 0, 0.18) 50%, rgba(0, 0, 0, 0.0) 100%);
  opacity: 0;
  transition: opacity calc(var(--flip-ms, 720ms) / 2) ease-in,
              opacity calc(var(--flip-ms, 720ms) / 2) ease-out calc(var(--flip-ms, 720ms) / 2);
  transform: translateZ(1px);
}
.flip-page-flipper.is-flipping .flip-shadow { opacity: 0.5; }

.book-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 18px;
  gap: 12px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-soft);
}

.book-controls-center {
  display: flex;
  align-items: center;
  gap: 14px;
}

.book-page-counter {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  color: var(--aegean-deep);
  min-width: 80px;
  text-align: center;
}

.icon-btn {
  background: white;
  border: 1px solid rgba(30, 91, 138, 0.18);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--aegean-deep);
  transition: all 200ms ease;
}
.icon-btn:hover { background: var(--aegean); color: white; border-color: var(--aegean); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; background: white; color: var(--aegean-deep); }
.icon-btn svg { width: 18px; height: 18px; }

.book-empty {
  text-align: center;
  padding: 72px 32px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
}

.book-loading {
  text-align: center;
  padding: 96px 32px;
  color: var(--aegean-deep);
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
}

/* Photos page */
.photo-actions {
  display: flex;
  justify-content: center;
  margin: 0 0 32px;
}

.upload-box {
  display: block;
  width: 100%;
  background: var(--paper);
  border: 1.5px dashed rgba(30, 91, 138, 0.35);
  border-radius: var(--radius);
  padding: 36px;
  text-align: center;
  margin: 0 0 36px;
  transition: all 200ms ease;
  cursor: pointer;
}
.upload-box.is-drag { border-color: var(--aegean); background: rgba(107, 169, 212, 0.06); }
.upload-box-title {
  font-family: var(--serif);
  font-size: 24px;
  color: var(--aegean-deep);
  margin: 0 0 8px;
}
.upload-box-hint {
  color: var(--ink-soft);
  margin: 0 0 18px;
  font-size: 14px;
}
.upload-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.upload-actions .btn {
  cursor: pointer;
}
.upload-box-footnote {
  max-width: 520px;
  margin: 14px auto 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.5;
}
.upload-box input[type="file"] { display: none; }

.uploader-status {
  margin-top: 18px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-soft);
  min-height: 1.4em;
}
.uploader-status.is-error { color: #b54040; }
.uploader-status.is-ok { color: #2f7a4d; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.gallery-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--whitewash);
  aspect-ratio: 1;
  cursor: pointer;
  transition: transform 200ms ease, box-shadow 200ms ease;
}
.gallery-item:hover { transform: translateY(-2px); box-shadow: 0 16px 32px -16px rgba(22, 63, 99, 0.4); }
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-item .select-check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  border: 1.5px solid rgba(30, 91, 138, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--aegean-deep);
  pointer-events: none;
}
.gallery-item .select-check svg { width: 16px; height: 16px; opacity: 0; }
.gallery.is-selecting .gallery-item .select-check { display: flex; }
.gallery-item.is-selected { box-shadow: 0 0 0 3px var(--aegean) inset, 0 16px 32px -16px rgba(22, 63, 99, 0.5); }
.gallery-item.is-selected .select-check { background: var(--aegean); border-color: var(--aegean); color: white; }
.gallery-item.is-selected .select-check svg { opacity: 1; }

.action-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(251, 250, 246, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 14px 16px;
  margin: 0 0 18px;
  border-radius: 12px;
  border: 1px solid rgba(30, 91, 138, 0.12);
  flex-wrap: wrap;
}
.action-bar-info {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--aegean-deep);
}
.action-bar-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-sm { padding: 9px 16px; font-size: 11px; }
.btn-danger {
  background: #b54040;
  color: white;
  border-color: #b54040;
}
.btn-danger:hover { background: #993434; }

.settings-card {
  background: var(--paper);
  border: 1px solid rgba(30, 91, 138, 0.12);
  border-radius: var(--radius);
  padding: 24px;
  margin: 0 0 28px;
}
.settings-card h3 {
  font-family: var(--serif);
  color: var(--aegean-deep);
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 400;
}
.settings-card p.muted {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 13px;
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.settings-grid label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 500;
  gap: 6px;
}
.settings-grid input[type="number"] {
  font-family: var(--sans);
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid rgba(30, 91, 138, 0.2);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
}
.settings-grid input[type="number"]:focus {
  outline: none;
  border-color: var(--aegean);
}
.settings-stats {
  display: flex;
  gap: 24px;
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
  margin: 0 0 16px;
  flex-wrap: wrap;
}
.settings-stats b {
  font-style: normal;
  font-weight: 500;
  color: var(--aegean-deep);
  margin-right: 4px;
}
.settings-status {
  margin-top: 8px;
  font-size: 13px;
  min-height: 1.2em;
  color: var(--ink-soft);
}
.settings-status.is-ok { color: #2f7a4d; }
.settings-status.is-error { color: #b54040; }

.gallery-empty {
  text-align: center;
  padding: 72px 32px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 36, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox.is-open { display: flex; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.7);
}

.footer {
  text-align: center;
  padding: 32px 24px 48px;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
}

@media (max-width: 720px) {
  .nav { padding: 16px 20px; }
  .nav-links { gap: 18px; font-size: 11px; }
  .nav-brand { font-size: 16px; }
  .cover { padding: 24px 16px 64px; }
  .book-shell { padding: 12px; }
  .book-stage { min-height: 50vh; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
}
