/* ============================================================
   Elin · Festa e Abetares — keepsake photo album
   Warm cream paper · terracotta · muted gold · ink brown
   ============================================================ */

:root {
  --bg:          #FBF4E8;
  --bg-deep:    #F3E9D2;
  --paper:      #FFFCF5;
  --ink:        #2B1A10;
  --ink-soft:   #6B533F;
  --accent:     #B6402B;
  --accent-deep:#8A2F1F;
  --gold:       #C9963C;
  --leaf:       #5A7548;
  --shadow-warm: 18 14 10;

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-script:  "Caveat", "Brush Script MT", cursive;
  --font-body:    "Nunito", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --gap-xs: 6px;
  --gap-sm: 10px;
  --gap-md: 16px;
  --gap-lg: 28px;
  --gap-xl: 48px;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

/* ===== Reset / base ===== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 15% 0%,   rgba(201,150,60,0.10), transparent 55%),
    radial-gradient(ellipse at 100% 10%, rgba(182,64,43, 0.07), transparent 50%),
    radial-gradient(ellipse at 50% 100%, rgba(90,117,72, 0.06), transparent 60%);
  background-attachment: fixed;
  overflow-x: hidden;
  padding:
    calc(var(--safe-top) + 8px)
    calc(var(--safe-right) + 18px)
    calc(var(--safe-bottom) + 8px)
    calc(var(--safe-left) + 18px);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (min-width: 720px) {
  body {
    padding-left:  calc(var(--safe-left) + 40px);
    padding-right: calc(var(--safe-right) + 40px);
  }
}

img { max-width: 100%; display: block; }
picture { display: block; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }

::selection {
  background: rgba(182, 64, 43, 0.22);
  color: var(--ink);
}

/* ===== Paper grain overlay ===== */

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.92' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.16 0 0 0 0 0.10 0 0 0 0 0.06 0 0 0 0.16 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ===== Decorative corners ===== */

.corner {
  position: absolute;
  width: clamp(70px, 14vw, 130px);
  height: clamp(70px, 14vw, 130px);
  color: var(--gold);
  opacity: 0.6;
  pointer-events: none;
  z-index: 2;
  animation: cornerFade 1.4s ease-out 0.3s both;
}
.corner--tl { top: calc(var(--safe-top) + 4px); left: calc(var(--safe-left) - 8px); }
.corner--tr { top: calc(var(--safe-top) + 4px); right: calc(var(--safe-right) - 8px); transform: scaleX(-1); animation-name: cornerFadeR; }

@keyframes cornerFade  { from { opacity: 0; transform: translateY(-12px) scale(0.92); }            to { opacity: 0.6; transform: none; } }
@keyframes cornerFadeR { from { opacity: 0; transform: translateY(-12px) scale(0.92) scaleX(-1); } to { opacity: 0.6; transform: scaleX(-1); } }

/* ===== Hero ===== */

.hero {
  position: relative;
  z-index: 3;
  text-align: center;
  padding: clamp(28px, 9vw, 70px) 6px clamp(20px, 6vw, 44px);
  max-width: 760px;
  margin: 0 auto;
}

.hero__monogram {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: -1;
  opacity: 0.07;
  font-family: var(--font-display);
  font-weight: 700;
  font-style: italic;
  font-size: clamp(150px, 38vw, 320px);
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.05em;
  user-select: none;
}

.hero__name {
  font-family: var(--font-script);
  font-weight: 700;
  color: var(--accent);
  font-size: clamp(36px, 8vw, 58px);
  line-height: 1;
  margin: 0 0 4px;
  letter-spacing: 0.01em;
  transform: rotate(-3deg);
  display: inline-block;
  animation: heroFadeUp 0.9s cubic-bezier(.2,.7,.2,1) 0.15s both;
}

.hero__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-style: italic;
  font-variation-settings: "opsz" 144, "SOFT" 80;
  font-size: clamp(38px, 11vw, 82px);
  line-height: 1.04;
  color: var(--ink);
  margin: 6px 0 4px;
  letter-spacing: -0.012em;
  position: relative;
  display: inline-block;
  animation: heroFadeUp 0.9s cubic-bezier(.2,.7,.2,1) 0.3s both;
}

.hero__rule {
  display: block;
  width: clamp(180px, 60%, 360px);
  height: 12px;
  margin: 4px auto 0;
  color: var(--accent);
  opacity: 0;
  animation: ruleDraw 1.1s ease-out 0.85s forwards;
}

@keyframes ruleDraw { from { opacity: 0; } to { opacity: 1; } }
.hero__rule path {
  stroke-dasharray: 280;
  stroke-dashoffset: 280;
  animation: dash 1.1s ease-out 0.85s forwards;
}
@keyframes dash { to { stroke-dashoffset: 0; } }

.hero__caption {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: clamp(11px, 2.6vw, 14px);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
  margin: clamp(18px, 4vw, 26px) 0 0;
  animation: heroFadeUp 0.9s cubic-bezier(.2,.7,.2,1) 0.55s both;
}

@keyframes heroFadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* ===== Grid (masonry via CSS columns) ===== */

.grid {
  position: relative;
  z-index: 3;
  column-count: 1;
  column-gap: 14px;
  max-width: 1280px;
  margin: clamp(14px, 4vw, 28px) auto clamp(36px, 8vw, 64px);
  padding: 0 2px;
}

@media (min-width: 520px)  { .grid { column-count: 2; column-gap: 16px; } }
@media (min-width: 880px)  { .grid { column-count: 3; column-gap: 18px; } }
@media (min-width: 1200px) { .grid { column-count: 4; column-gap: 20px; } }

/* ===== Photo card ===== */

.card {
  --tilt: 0deg;
  display: block;
  width: 100%;
  margin: 0 0 14px;
  padding: 6px;
  background: var(--paper);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  break-inside: avoid;
  cursor: zoom-in;
  outline-offset: 4px;
  transform: rotate(var(--tilt));
  transition:
    transform 360ms cubic-bezier(.2,.7,.2,1),
    box-shadow 360ms ease,
    filter 360ms ease;
  box-shadow:
    0 1px 0 rgba(255, 252, 245, 0.9) inset,
    0 1px 2px rgba(var(--shadow-warm) / 0.10),
    0 8px 22px -10px rgba(var(--shadow-warm) / 0.22);
  opacity: 0;
  animation: cardIn 0.7s cubic-bezier(.2,.7,.2,1) var(--delay, 0ms) both;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@media (min-width: 520px)  { .card { margin-bottom: 16px; } }
@media (min-width: 880px)  { .card { margin-bottom: 18px; } }
@media (min-width: 1200px) { .card { margin-bottom: 20px; } }

@keyframes cardIn {
  from { opacity: 0; transform: rotate(var(--tilt)) translateY(18px) scale(0.985); }
  to   { opacity: 1; transform: rotate(var(--tilt)); }
}

.card__media {
  --ar: 4 / 3;
  display: block;
  position: relative;
  aspect-ratio: var(--ar);
  border-radius: 6px;
  overflow: hidden;
  background-color: var(--bg-deep);
  background-image: var(--lqip, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  /* LQIP smoothing — the raw 24x16 jpeg looks better with a hint of blur */
  isolation: isolate;
}

/* Subtle gradient over LQIP to hide block edges if any */
.card__media::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,252,245,0.05), rgba(0,0,0,0.04));
  pointer-events: none;
  transition: opacity 360ms ease;
  z-index: 1;
}
.card.loaded .card__media::after { opacity: 0; }

.card picture { width: 100%; height: 100%; }

.card img {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: transparent;
  opacity: 0;
  transition: opacity 380ms ease;
}
.card.loaded img { opacity: 1; }

.card:hover {
  transform: rotate(0deg) translateY(-3px);
  box-shadow:
    0 1px 0 rgba(255, 252, 245, 0.95) inset,
    0 2px 4px rgba(var(--shadow-warm) / 0.12),
    0 18px 36px -14px rgba(var(--shadow-warm) / 0.32);
}
.card:hover img { transform: scale(1.018); filter: saturate(1.05) brightness(1.01); }
.card:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 5px; }
.card:active { transform: rotate(var(--tilt)) scale(0.985); transition-duration: 120ms; }

.card img { transition: opacity 380ms ease, transform 600ms cubic-bezier(.2,.7,.2,1), filter 360ms ease; }

/* ===== Empty state ===== */

.empty {
  position: relative;
  z-index: 3;
  max-width: 520px;
  margin: clamp(40px, 10vw, 80px) auto;
  padding: clamp(20px, 5vw, 30px);
  text-align: center;
  font-family: var(--font-body);
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px dashed rgba(107, 83, 63, 0.35);
  border-radius: 12px;
}
.empty code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--bg-deep);
  color: var(--accent-deep);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.92em;
}

/* ===== Footer ===== */

.foot {
  position: relative;
  z-index: 3;
  text-align: center;
  padding: clamp(20px, 5vw, 36px) 0 calc(var(--safe-bottom) + 12px);
  font-family: var(--font-script);
  font-weight: 700;
  font-size: clamp(20px, 4vw, 28px);
  color: var(--ink-soft);
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 14px;
}
.foot__heart {
  width: 22px;
  height: 22px;
  color: var(--accent);
  transform: translateY(2px);
  filter: drop-shadow(0 2px 0 rgba(138, 47, 31, 0.18));
  animation: heartBeat 2.4s ease-in-out infinite;
}
.foot__sep {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.5;
}
.foot__meta {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: clamp(11px, 2.2vw, 13px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  transform: translateY(2px);
}

@keyframes heartBeat {
  0%, 100% { transform: translateY(2px) scale(1); }
  10%, 30% { transform: translateY(2px) scale(1.16); }
  20%      { transform: translateY(2px) scale(1.04); }
}

/* ============================================================
   Lightbox
   ============================================================ */

.lbx {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(26, 16, 10, 0);
  backdrop-filter: blur(0);
  -webkit-backdrop-filter: blur(0);
  display: grid;
  grid-template-areas:
    "close close close"
    "prev  stage next "
    ".     counter . ";
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto 1fr auto;
  align-items: center;
  justify-items: center;
  padding:
    calc(var(--safe-top) + 14px)
    calc(var(--safe-right) + 14px)
    calc(var(--safe-bottom) + 18px)
    calc(var(--safe-left) + 14px);
  transition: background 240ms ease, backdrop-filter 240ms ease;
  touch-action: none;
  overflow: hidden;
}
.lbx[hidden] { display: none !important; }

.lbx--open {
  background: rgba(26, 16, 10, 0.55);
  backdrop-filter: blur(10px) saturate(1.05);
  -webkit-backdrop-filter: blur(10px) saturate(1.05);
}

/* ===== Ambient blurred backdrop ===== */
.lbx__backdrop-wrap {
  position: absolute;
  inset: -10%;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.lbx__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(40px) brightness(0.55) saturate(1.2);
  -webkit-filter: blur(40px) brightness(0.55) saturate(1.2);
  opacity: 0;
  transition: opacity 360ms ease;
  transform: scale(1.12);
  will-change: opacity;
}
.lbx--open .lbx__backdrop { opacity: 0.55; }
@media (prefers-reduced-motion: reduce) {
  .lbx__backdrop { display: none; }
}
@supports not (filter: blur(1px)) {
  .lbx__backdrop { display: none; }
}

/* ===== Lightbox controls ===== */

.lbx__close,
.lbx__nav {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: rgba(255, 252, 245, 0.10);
  color: #FFFCF5;
  display: grid;
  place-items: center;
  transition: background 200ms ease, transform 200ms ease, opacity 200ms ease;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.lbx__close { grid-area: close; justify-self: end; }
.lbx__close svg, .lbx__nav svg { width: 22px; height: 22px; }
.lbx__nav--prev { grid-area: prev; }
.lbx__nav--next { grid-area: next; }

.lbx__close:hover,
.lbx__nav:hover { background: rgba(255, 252, 245, 0.20); transform: scale(1.06); }
.lbx__close:active,
.lbx__nav:active { transform: scale(0.94); }
.lbx__close:focus-visible,
.lbx__nav:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* When zoomed, dim the navigation chevrons so they don't compete with content */
.lbx--zoomed .lbx__nav { opacity: 0.35; }

/* ===== Stage + Frame + Image ===== */

.lbx__stage {
  grid-area: stage;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.lbx__frame {
  margin: 0;
  padding: 8px;
  background: var(--paper);
  border-radius: 8px;
  box-shadow:
    0 1px 0 rgba(255, 252, 245, 0.4) inset,
    0 30px 60px -20px rgba(0, 0, 0, 0.6);
  max-width: min(94vw, 1100px);
  max-height: min(78dvh, 1000px);
  display: grid;
  place-items: center;
  transition: opacity 200ms ease, transform 200ms ease;
  overflow: hidden;
}

.lbx__img {
  display: block;
  max-width: 100%;
  max-height: calc(min(78dvh, 1000px) - 16px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 3px;
  background: var(--bg-deep);
  pointer-events: none;
  will-change: transform;
  transform-origin: 0 0;
  transform: translate(0, 0) scale(1);
  user-select: none;
  -webkit-user-drag: none;
}

.lbx__counter {
  grid-area: counter;
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0.16em;
  font-size: 13px;
  color: rgba(255, 252, 245, 0.78);
  padding-top: 10px;
  font-variant-numeric: tabular-nums;
}
.lbx__counter-sep { padding: 0 4px; color: rgba(255, 252, 245, 0.45); }

@media (max-width: 640px) {
  .lbx {
    grid-template-areas:
      "close   close   close"
      "stage   stage   stage"
      "prev    counter next";
  }
  .lbx__close,
  .lbx__nav  { width: 48px; height: 48px; }
  .lbx__frame { max-height: 70dvh; padding: 6px; }
}

/* Open transition for image */
.lbx__frame { opacity: 0; transform: scale(0.96); }
.lbx--open .lbx__frame { opacity: 1; transform: scale(1); }

/* Slide animations between photos */
.lbx__frame.is-out-left  { animation: slideOutLeft  220ms ease forwards; }
.lbx__frame.is-out-right { animation: slideOutRight 220ms ease forwards; }
.lbx__frame.is-in-left   { animation: slideInLeft   260ms cubic-bezier(.2,.7,.2,1) forwards; }
.lbx__frame.is-in-right  { animation: slideInRight  260ms cubic-bezier(.2,.7,.2,1) forwards; }

@keyframes slideOutLeft  { to   { opacity: 0; transform: translateX(-40px) scale(0.96); } }
@keyframes slideOutRight { to   { opacity: 0; transform: translateX( 40px) scale(0.96); } }
@keyframes slideInLeft   { from { opacity: 0; transform: translateX(-40px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes slideInRight  { from { opacity: 0; transform: translateX( 40px) scale(0.96); } to { opacity: 1; transform: none; } }

/* ===== Zoom hint toast ===== */

.lbx__hint {
  position: absolute;
  left: 50%;
  bottom: clamp(56px, 12vw, 80px);
  transform: translateX(-50%) translateY(8px);
  background: rgba(43, 26, 16, 0.78);
  color: #FFFCF5;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.02em;
  pointer-events: auto;
  cursor: pointer;
  opacity: 0;
  transition: opacity 260ms ease, transform 260ms ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 8px 20px -8px rgba(0, 0, 0, 0.4);
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
}
.lbx__hint.is-visible {
  opacity: 0.95;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ============================================================
   Reduced motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .hero__rule path { stroke-dashoffset: 0; }
  .card { opacity: 1; }
  .corner { opacity: 0.5; }
}

/* ============================================================
   Print
   ============================================================ */

@media print {
  body { background: white; padding: 0; }
  .grain, .corner, .foot__heart { display: none; }
  .grid { column-count: 2; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .card__media::after { display: none; }
}
