/* ---------- Base ---------- */
:root {
  --room-dark: #0d0d10;
  --room-mid: #1a1a1f;
  --paper: #fdfbf6;
  --paper-edge: #eae4d6;
  --ink: #2b2118;
  --ink-soft: #6b5f52;
  --accent: #d98a3d;
  --shadow-color: rgba(0, 0, 0, 0.6);
  --glow: rgba(255, 226, 170, 0.16);
  --glow-strong: rgba(255, 226, 170, 0.28);
  --radius: 3px;
  --font-serif: "Fraunces", Georgia, serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden;
}

button, a, .photo-card, .grid-card, .stack {
  touch-action: manipulation;
}

body {
  background-color: var(--room-dark);
  background-image:
    radial-gradient(ellipse 900px 600px at 50% -10%, rgba(255, 226, 170, 0.05), transparent 70%),
    radial-gradient(ellipse 1200px 800px at 50% 100%, rgba(0, 0, 0, 0.5), transparent 70%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--paper);
  font-family: var(--font-sans);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.subtle {
  color: rgba(255, 246, 230, 0.65);
  font-size: 0.95rem;
  margin: 0.15rem 0 0;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: calc(1.1rem + env(safe-area-inset-top)) max(2rem, env(safe-area-inset-right)) 1.1rem max(2rem, env(safe-area-inset-left));
  background: linear-gradient(to bottom, rgba(6,6,8,0.65), rgba(6,6,8,0));
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(2px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
  color: #fdf3e2;
  letter-spacing: 0.01em;
}

.brand-mark {
  display: inline-block;
  transform: rotate(20deg);
  color: var(--accent);
}

.crumbs {
  font-size: 0.9rem;
  color: rgba(255,246,230,0.6);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.crumbs a:hover { color: #fdf3e2; }

/* ---------- App / views ---------- */
.app {
  padding: 0 max(2rem, env(safe-area-inset-right)) calc(4rem + env(safe-area-inset-bottom)) max(2rem, env(safe-area-inset-left));
  max-width: 1400px;
  margin: 0 auto;
}

.view { animation: view-fade 0.35s ease both; }
@keyframes view-fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.home-heading h1,
.album-title h1 {
  font-family: var(--font-serif);
  font-size: 2.6rem;
  font-weight: 500;
  margin: 0.4rem 0 0;
  color: #fdf3e2;
  text-shadow: 0 2px 10px rgba(0,0,0,0.35);
}

/* ---------- Home: stacks ---------- */
.stacks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 3rem 2.5rem;
  margin-top: 2.5rem;
}

.stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
  perspective: 800px;
}

.stack-photos {
  position: relative;
  width: 168px;
  height: 168px;
  transition: transform 0.35s ease;
}

.stack:hover .stack-photos,
.stack:focus-visible .stack-photos {
  transform: translateY(-6px);
}

.stack-photos .card {
  position: absolute;
  inset: 0;
  background: var(--paper);
  border-radius: var(--radius);
  padding: 8px 8px 20px;
  box-shadow: 0 8px 18px var(--shadow-color), 0 0 26px var(--glow);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}

.stack-photos .card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #d8d0c0;
}

/* fan the under-photos out slightly, top photo (last child) stays centered */
.stack-photos .card:nth-child(1) { transform: rotate(-9deg) translate(-8px, 3px); z-index: 1; }
.stack-photos .card:nth-child(2) { transform: rotate(7deg) translate(7px, 1px); z-index: 2; }
.stack-photos .card:nth-child(3) { transform: rotate(-2deg) translate(0, -2px); z-index: 3; }

.stack:hover .stack-photos .card:nth-child(1) { transform: rotate(-16deg) translate(-20px, 10px); }
.stack:hover .stack-photos .card:nth-child(2) { transform: rotate(13deg) translate(18px, 8px); }
.stack:hover .stack-photos .card:nth-child(3) { transform: rotate(-3deg) translate(0, -6px) scale(1.02); }

.stack-label h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.15rem;
  margin: 0;
  color: #fdf3e2;
}

.stack-label p {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: rgba(255,246,230,0.55);
}

/* ---------- Album toolbar ---------- */
.album-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1.5rem;
}

.album-controls {
  display: flex;
  gap: 0.4rem;
  background: rgba(0,0,0,0.25);
  padding: 0.3rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.08);
}

.toggle-btn {
  border: none;
  background: transparent;
  color: rgba(255,246,230,0.7);
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.2s ease, color 0.2s ease;
}

.toggle-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #241505;
}

/* ---------- Light table surface ---------- */
.table-surface {
  position: relative;
  margin-top: 2rem;
  min-height: 70vh;
  border-radius: 10px;
  background: radial-gradient(ellipse at center, rgba(255,226,170,0.035), var(--room-dark) 75%);
  box-shadow: inset 0 0 120px rgba(0,0,0,0.75), inset 0 0 2px rgba(255,255,255,0.04);
  overflow: hidden;
  padding: 2rem;
}

.scatter {
  position: relative;
  width: 100%;
  min-height: 66vh;
}

.photo-card {
  position: absolute;
  background: var(--paper);
  padding: 10px 10px 34px;
  border-radius: 2px;
  box-shadow: 0 10px 24px var(--shadow-color), 0 2px 4px rgba(0,0,0,0.5), 0 0 32px var(--glow);
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, z-index 0s;
  will-change: transform;
  opacity: 0;
}

.photo-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #d8d0c0;
  pointer-events: none;
}

.photo-card::after {
  content: attr(data-index);
  position: absolute;
  bottom: 8px;
  left: 12px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.photo-card:hover,
.photo-card:focus-visible,
.photo-card:active {
  z-index: 999 !important;
  box-shadow: 0 22px 40px rgba(0,0,0,0.65), 0 0 46px var(--glow-strong);
}

.photo-card:active { transform: scale(0.97) !important; }
.grid-card:active { transform: scale(0.97); }
.stack:active .stack-photos { transform: translateY(-4px) scale(0.98); }
.lb-btn:active, .lb-close:active, .lb-nav:active { transform: scale(0.94); }
.toggle-btn:active { transform: scale(0.96); }

/* fall-in animation, angle set per-card via inline style custom property --r */
.photo-card.fall-in {
  animation: fall-in 0.55s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes fall-in {
  from {
    opacity: 0;
    transform: translateY(-140px) rotate(var(--r, 0deg)) scale(0.85);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(var(--r, 0deg)) scale(1);
  }
}

.photo-card:hover:not(.fall-in-active) {
  transform: translateY(-4px) rotate(0deg) scale(1.03) !important;
}

/* ---------- Grid surface (album alt view) ---------- */
.grid-surface {
  margin-top: 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.4rem;
}

.grid-card {
  background: var(--paper);
  border-radius: 3px;
  padding: 8px 8px 22px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.5), 0 0 20px var(--glow);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.grid-card:hover { transform: translateY(-4px); box-shadow: 0 12px 22px rgba(0,0,0,0.6), 0 0 30px var(--glow-strong); }

.grid-card .thumb-wrap {
  width: 100%;
  aspect-ratio: 4/3;
  overflow: hidden;
  background: #d8d0c0;
}

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

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(6, 6, 8, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: lb-fade 0.25s ease both;
}
@keyframes lb-fade { from { opacity: 0; } to { opacity: 1; } }

.lb-stage {
  max-width: min(92vw, 1100px);
  max-height: 74vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-stage img {
  max-width: 100%;
  max-height: 74vh;
  object-fit: contain;
  border-radius: 2px;
  box-shadow: 0 30px 70px rgba(0,0,0,0.7), 0 0 70px var(--glow-strong);
  background: var(--paper);
  padding: 12px 12px 12px;
}

.lb-close, .lb-nav {
  position: absolute;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fdf3e2;
  border-radius: 999px;
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}
.lb-close:hover, .lb-nav:hover { background: rgba(255,255,255,0.18); }

.lb-close { top: calc(1.5rem + env(safe-area-inset-top)); right: calc(1.5rem + env(safe-area-inset-right)); }
.lb-prev { left: calc(1.5rem + env(safe-area-inset-left)); top: 50%; transform: translateY(-50%); }
.lb-next { right: calc(1.5rem + env(safe-area-inset-right)); top: 50%; transform: translateY(-50%); }

.lb-bar {
  margin-top: 1.5rem;
  margin-bottom: env(safe-area-inset-bottom);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  color: rgba(255,246,230,0.75);
  font-size: 0.9rem;
}

.lb-actions { display: flex; gap: 0.6rem; }

.lb-btn {
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
  color: #fdf3e2;
  padding: 0.55rem 1.2rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.2s ease;
}
.lb-btn:hover { background: rgba(255,255,255,0.14); }
.lb-btn-primary {
  background: var(--accent);
  color: #241505;
  border-color: var(--accent);
}
.lb-btn-primary:hover { background: #e59a4e; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(2rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #fdf3e2;
  color: var(--ink);
  padding: 0.7rem 1.3rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 300;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Empty state ---------- */
.empty-state {
  margin-top: 3rem;
  text-align: center;
  color: rgba(255,246,230,0.7);
  font-family: var(--font-serif);
  font-size: 1.2rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar {
    padding: calc(0.9rem + env(safe-area-inset-top)) max(1.1rem, env(safe-area-inset-right)) 0.9rem max(1.1rem, env(safe-area-inset-left));
  }
  .app {
    padding: 0 max(1.1rem, env(safe-area-inset-right)) calc(3rem + env(safe-area-inset-bottom)) max(1.1rem, env(safe-area-inset-left));
  }
  .home-heading h1, .album-title h1 { font-size: 1.9rem; }
  .stacks { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 1.8rem 1.2rem; }
  .stack-photos { width: 118px; height: 118px; }
  .album-toolbar { gap: 0.8rem; }
  .lb-nav { width: 44px; height: 44px; }
  .lb-prev { left: max(0.6rem, env(safe-area-inset-left)); }
  .lb-next { right: max(0.6rem, env(safe-area-inset-right)); }
  .lb-bar { flex-wrap: wrap; justify-content: center; gap: 0.9rem; }
}

/* ---------- Compact phones (iPhone-width viewports) ---------- */
@media (max-width: 430px) {
  .stacks { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 1.5rem 1rem; }
  .stack-photos { width: 98px; height: 98px; }
  .grid-surface { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.9rem; }
  .table-surface { padding: 1rem; }
}

/* Respect the home indicator / gesture bar on notched iPhones */
@supports (padding: max(0px)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
}

@media (prefers-reduced-motion: reduce) {
  .view, .photo-card.fall-in, .lightbox, .stack-photos, .toast, .toggle-btn,
  .photo-card, .grid-card, .lb-close, .lb-nav, .lb-btn {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
