:root {
  --felt: #685641;
  --felt-dark: #4e4032;
  --paper: #fffaf0;
  --ink: #2c2621;
  --purple: #a66bff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: #17100c;
  color: #fff9ef;
  font-family:
    Inter,
    "Noto Sans SC",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
}

/* =========================================================
   PAGE / FELT TEXTURE
   ========================================================= */

.memory-board-page {
  min-height: 100vh;
  padding-top: 112px;
  background:
    radial-gradient(circle at 20% 10%, rgba(176, 119, 255, .08), transparent 26%),
    linear-gradient(180deg, #17110e 0 390px, #30261d 390px);
}

.memory-board-hero {
  width: min(1180px, calc(100% - 42px));
  margin: 0 auto 34px;
  text-align: center;
}



/* Hero entrance */
.memory-board-hero > * {
  animation: top-rise-in var(--dur-l) var(--ease-out) both;
}
.memory-board-hero > :nth-child(2) { animation-delay: calc(1 * var(--stagger)); }
.memory-board-hero > :nth-child(3) { animation-delay: calc(2 * var(--stagger)); }
.memory-board-hero > :nth-child(4) { animation-delay: calc(3 * var(--stagger)); }
.memory-board-hero > :nth-child(5) { animation-delay: calc(4 * var(--stagger)); }

.memory-board-kicker {
  color: #b785ff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .34em;
}

.memory-board-hero h1 {
  margin: 12px 0 9px;
  font-family: "Noto Serif SC", "Songti SC", Georgia, serif;
  font-size: clamp(38px, 5vw, 66px);
  font-weight: 500;
}

.memory-board-hero p {
  max-width: 670px;
  margin: 0 auto;
  color: rgba(248, 238, 226, .56);
  font-size: 13px;
  line-height: 1.8;
}

.memory-board-stats {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 18px;
}

.memory-board-stats strong {
  color: #c69cff;
  font-family: Georgia, serif;
  font-size: 19px;
}

.memory-board-stats span {
  color: rgba(232, 214, 249, .34);
  font-size: 7px;
  letter-spacing: .20em;
}

/* The board is intentionally not grouped or sorted by year. */

/* =========================================================
   FELT CANVAS
   Compact enough for 50+ photos.
   ========================================================= */

.felt-canvas {
  position: relative;
  width: min(1510px, calc(100% - 32px));
  min-height: 720px;
  margin: 0 auto 70px;
  padding: 108px 42px 70px;
  overflow: hidden;
  border: 15px solid #3c2d21;
  border-radius: 9px;
  background:
    radial-gradient(circle at 13px 11px, rgba(255,255,255,.055) 0 1px, transparent 1.6px),
    radial-gradient(circle at 31px 25px, rgba(0,0,0,.055) 0 1px, transparent 1.6px),
    linear-gradient(135deg, rgba(255,255,255,.025), rgba(0,0,0,.03)),
    var(--felt);
  background-size:
    42px 38px,
    51px 47px,
    auto,
    auto;
  box-shadow:
    0 28px 80px rgba(0, 0, 0, .42),
    inset 0 0 70px rgba(18, 10, 5, .20);
}

.felt-canvas::before {
  content: "";
  position: absolute;
  inset: 10px;
  pointer-events: none;
  border: 1px solid rgba(255, 242, 220, .08);
}

.memory-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns:
    repeat(auto-fill, minmax(108px, 1fr));
  grid-auto-flow: dense;
  align-items: start;
  gap: 18px 8px;
}

.memory-photo-card {
  --rotate: 0deg;
  --shift-x: 0px;
  --shift-y: 0px;
  --photo-scale: 1;
  --card-width: 142px;
  --photo-ratio: 4 / 3;
  --memory-z: 1;
  --col-span: 1;

  position: relative;
  grid-column: span var(--col-span);
  justify-self: center;
  width: min(100%, var(--card-width));
  padding: 7px 7px 20px;
  border: 0;
  background: var(--paper);
  box-shadow:
    0 6px 12px rgba(28, 18, 12, .24),
    0 1px 1px rgba(41, 29, 20, .18);
  cursor: zoom-in;
  z-index: var(--memory-z);
  transform:
    translate(var(--shift-x), var(--shift-y))
    rotate(var(--rotate))
    scale(var(--photo-scale));
  transform-origin: 50% 36%;
  transition:
    transform var(--dur-m) var(--ease-out),
    box-shadow var(--dur-m) var(--ease-out),
    z-index 0s;
}

/* Cards keep their collage transform: animate with the individual translate/scale props. */
.memory-photo-card[data-enter] {
  animation: memoryCardIn var(--dur-l) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * var(--stagger));
}

@keyframes memoryCardIn {
  from { opacity: 0; translate: 0 14px; scale: .92; }
}

.memory-photo-card:active { scale: .97; }

.memory-grid .top-skeleton {
  min-height: 118px;
  border-radius: 3px;
  background: linear-gradient(100deg,
    rgba(255, 250, 240, .05) 30%,
    rgba(255, 250, 240, .16) 50%,
    rgba(255, 250, 240, .05) 70%);
  background-size: 200% 100%;
}

.memory-grid .top-state {
  color: rgba(255, 243, 227, .66);
}

.memory-grid .top-state-title { color: rgba(255, 243, 227, .92); }

.memory-grid .top-state-retry {
  border-color: rgba(255, 243, 227, .4);
  background: rgba(255, 243, 227, .1);
  color: #fff3e3;
}

.memory-photo-card:nth-child(4n + 1)::before {
  content: "";
  position: absolute;
  z-index: 4;
  left: 50%;
  top: -9px;
  width: 38px;
  height: 16px;
  transform: translateX(-50%) rotate(-2deg);
  background: rgba(239, 220, 180, .72);
  box-shadow: 0 1px 3px rgba(0,0,0,.09);
}

.memory-photo-card:nth-child(4n + 2)::before,
.memory-photo-card:nth-child(4n + 3)::before,
.memory-photo-card:nth-child(4n + 4)::before {
  content: "";
  position: absolute;
  z-index: 4;
  left: 50%;
  top: -6px;
  width: 9px;
  height: 9px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: #8f5d50;
  box-shadow:
    inset 0 1px 2px rgba(255,255,255,.28),
    0 2px 3px rgba(0,0,0,.24);
}

.memory-photo-card img {
  width: 100%;
  aspect-ratio: var(--photo-ratio);
  display: block;
  object-fit: contain;
  object-position: center center;
  background: #eee9e2;
}

.memory-photo-card:focus-visible {
  z-index: 12;
  transform:
    translate(var(--shift-x), calc(var(--shift-y) - 9px))
    rotate(0deg)
    scale(calc(var(--photo-scale) * 1.12));
  box-shadow:
    0 18px 32px rgba(31, 18, 11, .34),
    0 0 0 2px rgba(195, 148, 255, .22);
  outline: none;
}

@media (hover: hover) {
  .memory-photo-card:hover {
    z-index: 12;
    transform:
      translate(var(--shift-x), calc(var(--shift-y) - 9px))
      rotate(0deg)
      scale(calc(var(--photo-scale) * 1.12));
    box-shadow:
      0 18px 32px rgba(31, 18, 11, .34),
      0 0 0 2px rgba(195, 148, 255, .22);
  }
}

.memory-photo-caption {
  display: block;
  margin-top: 8px;
  overflow: hidden;
  color: rgba(46, 36, 29, .72);
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: 9px;
  line-height: 1.25;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* hover sticky-note */
.memory-hover-note {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: calc(100% + 12px);
  width: 168px;
  padding: 11px 12px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px) rotate(-2deg);
  background: #f5eaa8;
  box-shadow: 0 8px 18px rgba(35, 23, 12, .23);
  color: #55472e;
  text-align: left;
  transition:
    opacity var(--dur-s) var(--ease-out),
    transform var(--dur-s) var(--ease-out);
}

.memory-photo-card:focus-visible .memory-hover-note {
  opacity: 1;
  transform: translate(-50%, 0) rotate(-2deg);
}

@media (hover: hover) {
  .memory-photo-card:hover .memory-hover-note {
    opacity: 1;
    transform: translate(-50%, 0) rotate(-2deg);
  }
}

.memory-hover-note strong {
  display: block;
  margin-bottom: 5px;
  font-size: 10px;
}

.memory-hover-note span,
.memory-hover-note small {
  display: block;
  font-size: 8px;
  line-height: 1.5;
}

.memory-hover-note small {
  margin-top: 4px;
  color: rgba(67, 53, 34, .65);
}

.memory-loading,
.memory-empty {
  grid-column: 1 / -1;
  padding: 80px 20px;
  color: rgba(255, 243, 227, .58);
  text-align: center;
}

/* =========================================================
   LIGHTBOX
   ========================================================= */

.memory-modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* TopUI.dialog drives data-state; the closed lightbox is not rendered. */
.memory-modal:not([data-state="open"]):not([data-state="closing"]) {
  display: none;
}

.memory-modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(4, 4, 8, .80);
  backdrop-filter: blur(9px);
  cursor: zoom-out;
}

.memory-modal-card {
  position: relative;
  z-index: 2;
  width: min(1050px, 94vw);
  max-height: 88dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(270px, .7fr);
  overflow: hidden;
  border: 1px solid rgba(207, 174, 246, .22);
  border-radius: 22px;
  background: #0d0d16;
  box-shadow: 0 35px 100px rgba(0, 0, 0, .55);
}

.memory-modal-photo {
  position: relative;
  min-height: min(72vh, 720px);
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #050509;
  touch-action: pan-y;
}

/* Slow image: a small spinner appears only if loading takes a moment. */
.memory-modal-photo.is-loading::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 2px solid rgba(218, 193, 249, .22);
  border-top-color: #cfa9ff;
  border-radius: 50%;
  pointer-events: none;
  animation:
    top-fade-in var(--dur-m) var(--ease-out) 300ms both,
    memorySpin .8s linear infinite;
}

@keyframes memorySpin {
  to { rotate: 360deg; }
}

.memory-modal-photo.is-error::before {
  content: "这张照片暂时没能加载";
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  color: rgba(243, 236, 249, .55);
  font-size: 12px;
  animation: top-fade-in var(--dur-m) var(--ease-out) both;
}

.memory-modal-photo img {
  width: 100%;
  height: 100%;
  max-height: 78dvh;
  display: block;
  object-fit: contain;
}

.memory-modal-copy {
  padding: 46px 34px 32px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 70% 0, rgba(155, 91, 244, .10), transparent 35%),
    #10101b;
}

.memory-modal-meta {
  color: #b98aff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .15em;
  line-height: 1.6;
}

.memory-modal-copy h2 {
  margin: 13px 0 12px;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 27px;
  font-weight: 500;
}

.memory-modal-copy p {
  margin: 0;
  color: rgba(243, 236, 249, .62);
  font-size: 13px;
  line-height: 1.85;
}

.memory-modal-copy .memory-modal-note {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(207, 174, 246, .14);
  color: rgba(243, 236, 249, .5);
  font-size: 12px;
}

.memory-modal-close,
.memory-modal-nav {
  position: absolute;
  z-index: 5;
  display: grid;
  place-items: center;
  border: 1px solid rgba(218, 193, 249, .22);
  background: rgba(7, 7, 13, .72);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition:
    scale var(--dur-s) var(--ease-out),
    background-color var(--dur-s) var(--ease-out);
}

.memory-modal-close:active,
.memory-modal-nav:active { scale: .94; }

@media (hover: hover) {
  .memory-modal-close:hover,
  .memory-modal-nav:hover {
    scale: 1.06;
    background: rgba(40, 24, 64, .85);
  }
}

.memory-modal-close {
  right: 16px;
  top: 16px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 22px;
}

.memory-modal-nav {
  top: 50%;
  width: 42px;
  height: 58px;
  transform: translateY(-50%);
  border-radius: 13px;
  font-size: 31px;
}

.memory-modal-prev {
  left: 15px;
}

.memory-modal-next {
  left: calc(65% - 57px);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 900px) {
  .felt-canvas {
    padding: 92px 25px 55px;
    border-width: 11px;
  }

  .memory-grid {
    grid-template-columns:
      repeat(auto-fill, minmax(96px, 1fr));
    gap: 25px 17px;
  }

  .memory-photo-card {
    max-width: 124px;
  }

  .memory-modal-card {
    grid-template-columns: 1fr;
    max-height: 91dvh;
    overflow-y: auto;
  }

  .memory-modal-photo {
    min-height: 52vh;
  }

  .memory-modal-copy {
    padding: 25px 24px 30px;
  }

  .memory-modal-next {
    left: auto;
    right: 15px;
  }
}

@media (max-width: 560px) {
  .memory-board-page {
    padding-top: 92px;
  }

  .memory-board-hero {
    width: calc(100% - 28px);
  }

  .memory-board-hero p {
    font-size: 12px;
  }

  .felt-canvas {
    width: calc(100% - 14px);
    padding: 36px 13px 45px;
    border-width: 8px;
  }

  .memory-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px 10px;
  }

  .memory-photo-card {
    grid-column: span 1;
    width: 100%;
    padding: 5px 5px 15px;
    transform:
      translate(calc(var(--shift-x) * .35), calc(var(--shift-y) * .35))
      rotate(var(--rotate))
      scale(.98);
  }

  .memory-photo-caption {
    font-size: 8px;
  }

  .memory-hover-note {
    display: none;
  }

  .memory-modal {
    padding: 10px;
  }

  .memory-modal-card {
    width: 100%;
    border-radius: 17px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition-duration: .01ms !important;
  }
}


/* =========================================================
   CONTROLLED POLAROID COLLAGE
   Real-board look: staggered, lightly overlapping, still readable.
   ========================================================= */

.memory-grid {
  position:
    relative;
  display:
    block;
  min-height:
    520px;
}

.memory-photo-card {
  position:
    absolute;
  grid-column:
    auto;
  width:
    var(--card-width);
  max-width:
    none;
  margin:
    0;
  transform:
    rotate(var(--rotate))
    scale(var(--photo-scale));
  transform-origin:
    50%
    42%;
}

.memory-photo-card img {
  aspect-ratio:
    4
    /
    3;
  object-fit:
    contain;
}

.memory-photo-card:focus-visible {
  transform:
    translateY(-8px)
    rotate(0deg)
    scale(
      calc(
        var(--photo-scale)
        *
        1.08
      )
    );
}

/* hover lift only where hover exists: no sticky lift after a tap */
@media (hover: hover) {
  .memory-photo-card:hover {
    transform:
      translateY(-8px)
      rotate(0deg)
      scale(
        calc(
          var(--photo-scale)
          *
          1.08
        )
      );
  }
}

@media (max-width: 900px) {
  .memory-grid {
    display:
      block;
    grid-template-columns:
      none;
    gap:
      0;
  }

  .memory-photo-card {
    width:
      var(--card-width);
    max-width:
      none;
  }
}

@media (max-width: 560px) {
  .felt-canvas {
    padding:
      32px
      11px
      38px;
  }

  .memory-grid {
    display:
      block;
    grid-template-columns:
      none;
    gap:
      0;
    min-height:
      420px;
  }

  .memory-photo-card {
    width:
      var(--card-width);
    padding:
      5px
      5px
      15px;
    transform:
      rotate(var(--rotate))
      scale(var(--photo-scale));
  }

  .memory-photo-card:focus-visible {
    transform:
      translateY(-5px)
      rotate(0deg)
      scale(
        calc(
          var(--photo-scale)
          *
          1.045
        )
      );
  }

  /* hover lift only where hover exists: no sticky lift after a tap */
  @media (hover: hover) {
    .memory-photo-card:hover {
        transform:
          translateY(-5px)
          rotate(0deg)
          scale(
            calc(
              var(--photo-scale)
              *
              1.045
            )
          );
    }
  }
}


/* =========================================================
   FREEFORM MEMORY BOARD
   Deliberately irregular: varied size/angle/position with limited overlap.
   ========================================================= */

.memory-grid {
  overflow:
    visible;
}

.memory-photo-card {
  will-change:
    transform;
}

@media (max-width: 560px) {
  .memory-photo-card {
    max-width:
      none;
  }

  .memory-photo-caption {
    margin-top:
      6px;
    font-size:
      7px;
  }
}


/* Loading skeletons: the board is absolutely positioned once cards exist,
   so lay the placeholders out as a plain grid while aria-busy. */
.memory-grid[aria-busy="true"] {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 18px 12px;
  min-height: 0;
}

.memory-grid .top-state {
  min-height: 260px;
}

/* "查看原图" under the photo text (TopUI.originalLink) */
.memory-modal-copy .top-original-link { margin-top: 12px; }
