* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #111;
  color: #eee;
  font-family: Georgia, serif;
  min-height: 100vh;
}

/* ── Password Gate ── */
#gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.gate-box {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 300px;
}

.gate-box h1 {
  font-size: 2rem;
  letter-spacing: 0.1em;
  font-weight: normal;
}

.gate-box input {
  padding: 10px 14px;
  font-size: 1rem;
  background: #222;
  border: 1px solid #444;
  color: #eee;
  border-radius: 4px;
  text-align: center;
}

.gate-box button {
  padding: 10px;
  font-size: 1rem;
  background: #eee;
  color: #111;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.gate-box button:hover { background: #ccc; }

#error-msg {
  color: #e55;
  font-size: 0.9rem;
}

/* ── Header ── */
header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 20px 12px;
  border-bottom: 1px solid #222;
  gap: 10px;
}

.album-header-top {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.album-header-top .back {
  position: absolute;
  left: 0;
}

header h1 {
  font-size: 1.4rem;
  letter-spacing: 0.1em;
  font-weight: normal;
  text-align: center;
}

header nav {
  display: flex;
  align-items: center;
  gap: 0;
  white-space: nowrap;
}

header nav a,
header .back {
  color: #aaa;
  text-decoration: none;
  font-size: 0.9rem;
  font-family: sans-serif;
}

header nav a:hover,
header .back:hover { color: #eee; }

/* ── Album Grid (homepage) ── */
.album-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
}

.album-card {
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: #222;
}

.album-cover {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  transition: transform 0.3s ease;
}

.album-card:hover .album-cover { transform: scale(1.03); }

.album-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 10px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.album-name {
  font-size: 0.95rem;
  letter-spacing: 0.05em;
}

.album-count {
  font-size: 0.75rem;
  color: #aaa;
  font-family: sans-serif;
}

/* ── Photo Grid (album view) ── */
.grid {
  display: flex;
  gap: 4px;
  padding: 4px;
  align-items: flex-start;
}

.masonry-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.grid img {
  width: 100%;
  display: block;
  cursor: pointer;
  transition: opacity 0.2s;
}

.grid img:hover { opacity: 0.85; }

/* ── Comment Drawer ── */
#comment-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
}

#comment-overlay.active { display: block; }

#comment-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1c1c1e;
  border-radius: 16px 16px 0 0;
  z-index: 201;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

#comment-drawer.active { transform: translateY(0); }

.comment-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #2c2c2e;
}

.comment-drawer-header img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
}

.comment-drawer-close {
  background: none;
  border: none;
  color: #888;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
}

#comment-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.comment-loading, .comment-empty {
  color: #666;
  font-size: 0.85rem;
  text-align: center;
  padding: 24px 0;
}

.comment-item { margin-bottom: 14px; }

.comment-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.comment-author {
  font-size: 0.82rem;
  font-weight: 600;
  color: #eee;
}

.comment-time {
  font-size: 0.72rem;
  color: #555;
}

.comment-text {
  font-size: 0.88rem;
  color: #bbb;
  margin: 0;
  line-height: 1.4;
}

.comment-input-area {
  padding: 12px 16px 32px;
  border-top: 1px solid #2c2c2e;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.comment-input-area input {
  background: #2c2c2e;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  color: #eee;
  font-size: 0.9rem;
  width: 100%;
  box-sizing: border-box;
}

.comment-input-row {
  display: flex;
  gap: 8px;
}

.comment-input-row input { flex: 1; }

#comment-post-btn {
  background: #007AFF;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#comment-post-btn:disabled { opacity: 0.5; }

/* ── Lightbox ── */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.lb-img-wrap {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lb-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  display: block;
}

.lb-close {
  position: fixed;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #eee;
  font-size: 1.6rem;
  cursor: pointer;
  z-index: 101;
  line-height: 1;
}

.lb-prev, .lb-next {
  background: none;
  border: none;
  color: #eee;
  font-size: 3rem;
  cursor: pointer;
  padding: 0 16px;
  line-height: 1;
  user-select: none;
}

.lb-prev:hover, .lb-next:hover { color: #fff; }

.lb-actions {
  position: absolute;
  bottom: -44px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 24px;
}

.lb-heart {
  background: none;
  border: none;
  color: #eee;
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.lb-heart:hover { color: #e55; }

.lb-comment-btn {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
}

.lb-comment-btn:hover { color: #fff; }

/* ── Empty message ── */
.empty-msg {
  text-align: center;
  color: #666;
  font-family: sans-serif;
  font-size: 0.95rem;
  padding: 60px 20px;
}

/* ── Admin ── */
body.admin-page {
  background: #f2f2f7;
  color: #1c1c1e;
}

.admin-wrap {
  max-width: 540px;
  margin: 0 auto;
  padding: 32px 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

.admin-wrap h1 {
  font-size: 2rem;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: #1c1c1e;
}

.admin-card {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 2px 10px rgba(0,0,0,0.04);
}

.admin-card h2 {
  font-size: 0.7rem;
  font-weight: 600;
  color: #8e8e93;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.admin-card input[type="text"],
.admin-card input[type="password"],
.admin-card select {
  padding: 13px 14px;
  background: #f2f2f7;
  border: none;
  color: #1c1c1e;
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

.admin-card input[type="text"]:focus,
.admin-card input[type="password"]:focus,
.admin-card select:focus {
  outline: none;
  background: #e8e8ed;
}

.admin-card input[type="file"] {
  color: #636366;
  font-family: inherit;
  font-size: 0.9rem;
}

.admin-card button,
#upload-btn {
  padding: 14px 20px;
  background: #007AFF;
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  align-self: stretch;
  text-align: center;
  transition: opacity 0.15s;
  line-height: 1.2;
}

.admin-card button:hover,
#upload-btn:hover { opacity: 0.85; }

.admin-card button:active,
#upload-btn:active { opacity: 0.7; }

.admin-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.admin-row button {
  align-self: auto;
  flex-shrink: 0;
  padding: 13px 18px;
}

#new-album-fields {
  flex-direction: column;
  gap: 8px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.preview-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
}

.progress-bar {
  height: 4px;
  background: #e5e5ea;
  border-radius: 2px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: #007AFF;
  width: 0%;
  transition: width 0.3s ease;
}

#progress-label {
  font-family: inherit;
  font-size: 0.85rem;
  color: #8e8e93;
  margin-top: 6px;
}

/* ── View Toggle ── */
.view-toggle {
  background: none;
  border: none;
  color: #666;
  font-family: Georgia, serif;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  letter-spacing: 0.05em;
}

.view-toggle.active {
  color: #eee;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.toggle-divider {
  color: #444;
  font-size: 0.8rem;
  margin: 0 6px;
}

.fav-link {
  color: #666;
  text-decoration: none;
  font-size: 1rem;
}

.fav-link:hover { color: #e55; }

body.scrapbook-bg header.light {
  background: #f7f2ea;
  border-bottom-color: #e0d8cc;
}

body.scrapbook-bg header.light h1,
body.scrapbook-bg header.light .back,
body.scrapbook-bg header.light .view-toggle,
body.scrapbook-bg header.light .toggle-divider {
  color: #4a4035;
}

body.scrapbook-bg header.light .view-toggle.active {
  color: #2a1f14;
}

body.scrapbook-bg header.light .fav-link {
  color: #9a8f82;
}

/* ── Book / Scrapbook View ── */
body.scrapbook-bg {
  background: #f7f2ea;
}

.book-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 16px 28px;
  min-height: calc(100vh - 62px);
  background: #f7f2ea;
}

.book-container {
  position: relative;
  width: min(90vw, 680px);
  height: min(58vh, 430px);
  perspective: 1600px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08);
  border-radius: 3px;
}

.book-page {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 8px;
  padding: 16px 20px;
  background: #f7f2ea;
  border-radius: 3px;
  opacity: 0;
  pointer-events: none;
  backface-visibility: hidden;
}

.book-page.active {
  opacity: 1;
  pointer-events: auto;
}

.book-page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(0,0,0,0.1);
  transition: opacity 0.15s;
}

.book-page img:hover { opacity: 0.88; }

/* Page flip animations */
@keyframes flipOutLeft {
  from { transform: rotateY(0deg); opacity: 1; }
  to   { transform: rotateY(-90deg); opacity: 0; }
}
@keyframes flipInRight {
  from { transform: rotateY(90deg); opacity: 0; }
  to   { transform: rotateY(0deg); opacity: 1; }
}
@keyframes flipOutRight {
  from { transform: rotateY(0deg); opacity: 1; }
  to   { transform: rotateY(90deg); opacity: 0; }
}
@keyframes flipInLeft {
  from { transform: rotateY(-90deg); opacity: 0; }
  to   { transform: rotateY(0deg); opacity: 1; }
}

/* Layout classes */
.l-duo   { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.l-2x2   { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.l-3x2   { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.l-solo  { display: flex; align-items: center; justify-content: center; }
.l-solo img { max-width: 60%; max-height: 100%; width: auto; height: auto; }

.l-hero-right { grid-template-columns: 3fr 2fr; grid-template-rows: 1fr 1fr; }
.l-hero-right img:first-child { grid-row: 1 / 3; }

.l-hero-top { grid-template-columns: 1fr 1fr; grid-template-rows: 3fr 2fr; }
.l-hero-top img:first-child { grid-column: 1 / 3; }

.l-mosaic { grid-template-columns: 2fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.l-mosaic img:first-child { grid-row: 1 / 3; }

/* Navigation row */
.book-nav-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.book-prev, .book-next {
  background: none;
  border: none;
  color: #b0a89e;
  font-size: 2rem;
  cursor: pointer;
  padding: 6px 10px;
  line-height: 1;
}

.book-prev:hover, .book-next:hover { color: #4a4035; }

.book-counter {
  font-family: sans-serif;
  font-size: 0.7rem;
  color: #b0a89e;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  min-width: 56px;
  text-align: center;
}

/* ── Manage Photos ── */
.manage-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-top: 4px;
}

.manage-thumb {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  background: #222;
}

.manage-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.manage-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.65);
  border: none;
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.manage-delete:hover { background: #e55; }

.manage-cover {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0,0,0,0.5);
  border: none;
  color: #ccc;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.manage-cover:hover { background: #c8911a; color: #fff; }
.manage-thumb.is-cover .manage-cover { background: #c8911a; color: #fff; }

/* ── Mobile ── */
@media (max-width: 600px) {
  .album-grid {
    grid-template-columns: repeat(2, 1fr);
  }


  .book-container {
    height: min(55vh, 360px);
  }

  .book-page {
    padding: 12px 14px;
    gap: 5px;
  }

  .book-prev, .book-next {
    font-size: 1.6rem;
    padding: 4px 8px;
  }

  .manage-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .lb-prev, .lb-next {
    font-size: 2rem;
    padding: 0 8px;
  }
}
