/* ------------------------------------------------------------------ */
/*  Bookshelf — light warm-grey shell, off-white panel, fanned stacks  */
/* ------------------------------------------------------------------ */

:root {
  --bg: #dcdbd7;
  --panel: #f1f0ee;
  --card-top: #e8e7e4;
  --card-mid: #e0dfdb;
  --card-bot: #d5d4d0;
  --text: #555450;
  --text-strong: #3a3936;
  --text-muted: #a8acad;
  --white: #ffffff;
  --shadow-card: 0 1px 1px rgba(40, 35, 25, 0.04), 0 6px 16px rgba(40, 35, 25, 0.05);
  --shadow-photo: 0 6px 16px rgba(40, 30, 20, 0.22), 0 1px 3px rgba(40, 30, 20, 0.12);
  --radius-panel: 52px;
  --radius-card: 24px;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-hand: "Gochi Hand", "Patrick Hand", cursive;
  --page-pad: clamp(20px, 5vw, 72px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { min-height: 100vh; }

.page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: var(--page-pad);
}

.panel {
  width: 100%;
  max-width: 1120px;
  background: var(--panel);
  border-radius: var(--radius-panel);
  padding: 28px 36px 48px;
  position: relative;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  margin-bottom: 10px;
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  line-height: 0;
  margin-left: 4px;
}

.logo img {
  width: 42px;
  height: 24px;
  display: block;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-new {
  appearance: none;
  border: 0;
  background: #fff;
  color: #9aa0a2;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(40, 35, 25, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.03);
  transition: box-shadow 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.btn-new:hover {
  color: #6d7274;
  box-shadow: 0 2px 8px rgba(40, 35, 25, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.btn-new:focus-visible {
  outline: 2px solid #c9a56b;
  outline-offset: 2px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: block;
  background:
    linear-gradient(180deg, #c5cdd0 0%, #d5d4cf 42%, #e8c48a 72%, #e0a15a 100%);
  background-size: cover;
  background-position: center;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8), 0 1px 3px rgba(40, 35, 25, 0.15);
  flex-shrink: 0;
}

/* ---------- heading + centered shelf ---------- */
/* Grid is ~62% of the panel and centered. Heading shares the same left edge.
   Logo / New album stay on the full-width topbar at the panel corners. */

.shelf {
  width: 66%;
  margin: 8px auto 0;
}

.page-title {
  margin: 8px 0 18px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 17px;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.2;
}

.shelf .status { margin: 0 0 18px; }

/* ---------- grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-card);
  background: linear-gradient(180deg, var(--card-top) 0%, var(--card-mid) 48%, var(--card-bot) 100%);
  aspect-ratio: 1.15 / 1;
  cursor: pointer;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  text-decoration: none;
  box-shadow: var(--shadow-card);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  width: 100%;
}

.card:focus-visible {
  outline: 2px solid #c9a56b;
  outline-offset: 3px;
}

.card:hover,
.card.is-hovered {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(40, 35, 25, 0.1);
}

.card-title {
  position: relative;
  z-index: 2;
  margin: 0;
  padding: 14px 16px 0;
  font-family: var(--font-hand);
  font-weight: 400;
  font-size: clamp(18px, 1.45vw, 22px);
  letter-spacing: 0.01em;
  color: var(--text-strong);
  line-height: 1.15;
  text-align: left;
  pointer-events: none;
}

/* ---------- fanned photo stack ---------- */

.stack {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 55%;
  aspect-ratio: 1 / 1;
  transform: translateX(-50%);
  z-index: 1;
  pointer-events: none;
}

.photo {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #cfcce8;
  border: 4px solid #fff;
  box-shadow: var(--shadow-photo);
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #d5d3cf;
}


.play-mini {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28%;
  aspect-ratio: 1;
  max-width: 42px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 12px rgba(30, 25, 20, 0.25);
  pointer-events: none;
}
.play-mini::after {
  content: "";
  position: absolute;
  left: 54%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-style: solid;
  border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent #3a3936;
}
.photo .play-mini { display: block; }
.photo.is-empty {
  background: linear-gradient(160deg, #e4e2de, #d0cec9);
  border-color: rgba(255, 255, 255, 0.9);
}

.photo-left {
  z-index: 1;
  transform: translate(-18%, 6%) rotate(-8deg) scale(0.88);
}

.photo-right {
  z-index: 1;
  transform: translate(18%, 6%) rotate(8deg) scale(0.88);
}

.photo-front {
  z-index: 3;
  transform: translate(0, 2%) rotate(0.3deg) scale(1);
  box-shadow: 0 8px 18px rgba(40, 30, 20, 0.24), 0 2px 4px rgba(40, 30, 20, 0.12);
}

.card:hover .photo-left,
.card.is-hovered .photo-left {
  transform: translate(-26%, 2%) rotate(-13deg) scale(0.9);
}

.card:hover .photo-right,
.card.is-hovered .photo-right {
  transform: translate(26%, 2%) rotate(13deg) scale(0.9);
}

.card:hover .photo-front,
.card.is-hovered .photo-front {
  transform: translate(0, -2%) rotate(0deg) scale(1.05);
}

/* fewer than 3 photos: keep remaining ones centered-ish */
.stack[data-count="1"] .photo-front { transform: translate(0, 4%) rotate(0); }
.stack[data-count="2"] .photo-left { transform: translate(-20%, 10%) rotate(-8deg) scale(0.9); }
.stack[data-count="2"] .photo-front { transform: translate(12%, 4%) rotate(3deg); }

.card-error .card-title { color: #8a5a4a; }
.card-msg {
  position: relative;
  z-index: 2;
  margin: 6px 16px 0;
  font-size: 12px;
  color: #8a7f76;
  line-height: 1.35;
  text-align: left;
}

/* ---------- skeleton ---------- */

.card.skeleton {
  cursor: default;
  pointer-events: none;
}

.card.skeleton .card-title,
.card.skeleton .photo {
  background: linear-gradient(90deg, #e0dfdb 0%, #ecebe8 50%, #e0dfdb 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border: 0;
  box-shadow: none;
  color: transparent;
}

.card.skeleton .photo { border: 4px solid rgba(255,255,255,0.7); }
.card.skeleton .card-title {
  width: 48%;
  height: 22px;
  margin: 26px auto 0;
  border-radius: 10px;
  padding: 0;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ---------- status / errors ---------- */

.status {
  margin: 0 18px 20px;
  padding: 16px 18px;
  border-radius: 16px;
  background: #e8e4dc;
  color: var(--text-strong);
  font-size: 14px;
  line-height: 1.55;
}

.status a { color: #6b5a2e; }
.status code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; white-space: nowrap; }
.status[hidden] { display: none; }
.status.is-error { background: #efe4dc; }
.status.is-info { background: #e6e7e4; }

/* ---------- lightbox gallery ---------- */

.lightbox[hidden] { display: none; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(55, 53, 48, 0.38);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.lightbox-sheet {
  position: relative;
  z-index: 1;
  width: min(1080px, 100%);
  max-height: calc(100vh - 48px);
  background: var(--panel);
  border-radius: 36px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(30, 25, 20, 0.22);
  overflow: hidden;
}

.lightbox-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 12px;
  flex-shrink: 0;
}

.lightbox-title {
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 400;
  font-size: 30px;
  color: var(--text-strong);
}

.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-drive {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  background: #fff;
  color: #6d7274;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(40, 35, 25, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.03);
}

.btn-drive:hover { color: var(--text-strong); }

.btn-close,
.viewer-close,
.viewer-nav {
  appearance: none;
  border: 0;
  background: #fff;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(40, 35, 25, 0.08);
}

.btn-close:hover,
.viewer-close:hover,
.viewer-nav:hover { background: #f7f6f3; }

.lightbox-body {
  padding: 8px 24px 28px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.lb-item {
  appearance: none;
  border: 0;
  padding: 0;
  background: #e6e5e2;
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
  box-shadow: 0 1px 3px rgba(40, 35, 25, 0.08);
}

.lb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
}

.lb-item:hover img { transform: scale(1.04); }

.lb-empty, .lb-error {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text);
  padding: 32px 12px;
  font-size: 14px;
}

/* ---------- full viewer ---------- */

.viewer[hidden] { display: none; }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(30, 28, 24, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 72px;
}

.viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  font-size: 28px;
  background: rgba(255, 255, 255, 0.92);
}

.viewer-nav.prev { left: 16px; }
.viewer-nav.next { right: 16px; }

.viewer-caption {
  position: absolute;
  bottom: 14px;
  left: 0;
  right: 0;
  text-align: center;
  color: #eceae6;
  font-size: 13px;
  margin: 0;
}

body.lb-open { overflow: hidden; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .shelf { width: 88%; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: 22px 22px 36px; border-radius: 36px; }
  .card-title { font-size: 20px; }
}

@media (max-width: 600px) {
  :root { --page-pad: 12px; --radius-panel: 28px; --radius-card: 22px; }
  .page { padding: 12px; }
  .panel { padding: 16px 14px 28px; }
  .shelf { width: 100%; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .page-title { margin: 10px 0 14px; font-size: 16px; }
  .card { aspect-ratio: 1.15 / 1; }
  .lightbox { padding: 8px; }
  .lightbox-sheet { border-radius: 20px; max-height: calc(100vh - 16px); }
  .lightbox-body { grid-template-columns: repeat(2, 1fr); padding: 8px 14px 20px; }
  .viewer { padding: 56px 12px 40px; }
  .viewer-nav.prev { left: 6px; }
  .viewer-nav.next { right: 6px; }
}

@media (min-width: 901px) and (max-width: 1100px) {
  .panel { padding: 24px 28px 40px; }
}


/* ---------- album page ---------- */

.album-head {
  display: flex;
  align-items: center;
  gap: 14px 18px;
  flex-wrap: wrap;
  margin: 8px 8px 24px;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  background: #fff;
  color: #6d7274;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(40, 35, 25, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.03);
  flex-shrink: 0;
}
.btn-back:hover { color: var(--text-strong); }
.btn-back span { font-size: 15px; line-height: 1; }

.album-title {
  margin: 0;
  flex: 1 1 auto;
  font-family: var(--font-hand);
  font-weight: 400;
  font-size: clamp(28px, 3vw, 36px);
  color: var(--text-strong);
  line-height: 1.1;
  min-width: 0;
}

.album-head .btn-drive { flex-shrink: 0; }

.subgrid { margin: 0 0 28px; }
.subgrid-label {
  margin: 0 8px 12px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
}
.grid-nested { }
.card-nested { aspect-ratio: 1.15 / 1; }
.card-nested .card-title { font-size: clamp(16px, 1.4vw, 20px); }

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

.media-tile {
  appearance: none;
  border: 0;
  padding: 0;
  background: #e6e5e2;
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
  position: relative;
  box-shadow: 0 1px 3px rgba(40, 35, 25, 0.08);
}
.media-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
}
.media-tile:hover img { transform: scale(1.04); }
.media-tile:focus-visible {
  outline: 2px solid #c9a56b;
  outline-offset: 3px;
}

.play-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(30, 25, 20, 0.28);
  pointer-events: none;
}
.play-badge::after {
  content: "";
  position: absolute;
  left: 54%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-style: solid;
  border-width: 10px 0 10px 16px;
  border-color: transparent transparent transparent #3a3936;
}

.duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(30, 28, 24, 0.78);
  color: #f4f2ee;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 3px 7px;
  border-radius: 6px;
  pointer-events: none;
}

.media-skel {
  aspect-ratio: 1;
  border-radius: 16px;
  background: linear-gradient(90deg, #e0dfdb 0%, #ecebe8 50%, #e0dfdb 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

/* ---------- video modal ---------- */

.video-modal[hidden] { display: none; }
.video-modal {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.video-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 28, 24, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.video-sheet {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  background: var(--panel);
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 28px 70px rgba(20, 16, 12, 0.4);
  display: flex;
  flex-direction: column;
}
.video-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px 20px;
}
.video-title {
  margin: 0;
  font-family: var(--font-hand);
  font-size: 24px;
  font-weight: 400;
  color: var(--text-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-stage {
  position: relative;
  width: 100%;
  background: #111;
  aspect-ratio: 16 / 10;
}
.video-stage iframe,
.video-stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #111;
}

@media (max-width: 900px) {
  .media-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .media-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .album-head { margin: 4px 0 18px; }
  .album-title { font-size: 26px; flex-basis: 100%; order: 3; }
  .video-modal { padding: 8px; }
  .video-sheet { border-radius: 18px; }
  .video-stage { aspect-ratio: 16 / 11; }
  .play-badge { width: 46px; height: 46px; }
}
