/* ==========================================================================
   Memories: Polaroids and On this day.
   ========================================================================== */

/* ==========================================================================
   Memories: Polaroids
   ========================================================================== */

/* Replaced in Phase 4 by the month-grouped grid below. */

/* ==========================================================================
   On this day (Memories)
   ========================================================================== */

#on-this-day-host:empty { display: none; }
#on-this-day-host { padding: 0 var(--gutter) 1.6rem; }
.on-this-day {
  display: flex; align-items: center; gap: 1rem; width: 100%; text-align: left;
  padding: 0.75rem;
  background: var(--card); border: 1px solid var(--rule); box-shadow: var(--shadow-paper);
  transition: transform var(--med) var(--ease), box-shadow var(--med) var(--ease);
}
.on-this-day:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.on-this-day__photo {
  width: 84px; height: 84px; flex-shrink: 0;
  background-size: cover; background-position: center;
  border: 5px solid var(--polaroid); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transform: rotate(-3deg);
}
.on-this-day__body { display: flex; flex-direction: column; min-width: 0; }
.on-this-day__label { font-family: var(--mono); font-size: 0.72rem; color: var(--wax-text); }
.on-this-day__title { font-family: var(--serif); font-size: 1.5rem; line-height: 1.1; margin-top: 0.15rem; }
.on-this-day__text { font-size: 0.88rem; color: var(--ink-soft); margin-top: 0.2rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.on-this-day--text { padding: 1rem 1.15rem; border-left: 3px solid var(--wax-text); }

@keyframes lock-out { to { opacity: 0; transform: scale(1.03); } }
@keyframes heartbeat { 0%, 60%, 100% { transform: scale(1); } 12% { transform: scale(1.16); } 24% { transform: scale(1); } 36% { transform: scale(1.1); } }

/* While typing on a phone, hide the tab bar so the chat gets the room,
   the way native messaging apps do. */
body.is-typing .bottom-nav { display: none; }
body.is-typing .view-root { padding-bottom: 0; }
body.is-typing .chat-view { height: 100vh; height: var(--keyboard-free, 100dvh); }
body.is-typing .chat-input { padding-bottom: max(0.55rem, env(safe-area-inset-bottom)); }

/* ==========================================================================
   Phase 4: Memories
   Photos first: month by month, a wide feature then pairs, clean captions
   underneath. Opening one lays it on a dark table as a Polaroid.
   ========================================================================== */

.memories-grid { padding: 0.25rem var(--gutter) calc(var(--nav-height) + 6rem); }

.mem-month { margin-bottom: 1.75rem; }
.mem-month__label {
  position: sticky; top: 0; z-index: 3;
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 0 calc(-1 * var(--gutter)) 0.35rem; padding: 0.7rem var(--gutter) 0.5rem;
  background: var(--paper);
  font-family: var(--sans); font-size: var(--text-cap); font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-faint); line-height: 1.2;
}
.mem-month__count { letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }

.mem-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.1rem 10px; }
.mem-card {
  display: flex; flex-direction: column; min-width: 0; text-align: left;
  animation: rise var(--page) var(--ease-out) both;
  transition: transform var(--press) var(--ease);
}
.mem-card:active { transform: scale(0.98); }
.mem-card--wide { grid-column: 1 / -1; }
.mem-card__photo {
  display: block; width: 100%; aspect-ratio: 4 / 5;
  border-radius: var(--r-md);
  background-size: cover; background-position: center;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  transition: box-shadow var(--fast) var(--ease), filter var(--fast) var(--ease);
}
.mem-card--wide .mem-card__photo { aspect-ratio: 16 / 10; }
.mem-card__title {
  margin-top: 0.5rem;
  font-size: var(--text-callout); font-weight: 600; line-height: 1.25; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mem-card__meta { margin-top: 1px; font-size: 0.75rem; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (hover: hover) {
  .mem-card:hover .mem-card__photo { box-shadow: var(--shadow-lift); filter: brightness(1.03); }
}

/* On this day: the photo itself, with the words set on it */
#on-this-day-host { padding: 0 var(--gutter) 1.5rem; }
.on-this-day:not(.on-this-day--text) {
  position: relative; isolation: isolate; overflow: hidden;
  align-items: flex-end; min-height: 150px; padding: 1rem 1.1rem;
  border: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-paper);
  color: #fff;
}
.on-this-day:not(.on-this-day--text) .on-this-day__photo {
  position: absolute; inset: 0; z-index: -1; width: auto; height: auto;
  border: 0; transform: none; box-shadow: inset 0 -110px 70px -30px rgba(20, 10, 8, 0.65);
}
.on-this-day:not(.on-this-day--text) .on-this-day__label { font-family: var(--sans); font-size: var(--text-cap); font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: rgba(255, 255, 255, 0.85); }
.on-this-day:not(.on-this-day--text) .on-this-day__title { color: #fff; }
.on-this-day:not(.on-this-day--text) .on-this-day__text { color: rgba(255, 255, 255, 0.85); -webkit-line-clamp: 1; }
.on-this-day--text { border: 0; border-radius: var(--r-lg); }

/* The viewer: a dark table, the memory as a Polaroid */
.modal__panel.modal__panel--memory {
  position: fixed; inset: 0; width: 100%; max-width: none; height: 100%; max-height: none;
  padding: 0; border-radius: 0; overflow: hidden;
  background: rgba(18, 13, 11, var(--viewer-fade, 1)); color: #f3eadf;
  animation: fade 320ms var(--ease);
}
.modal--closing .modal__panel.modal__panel--memory { animation: fade-out 220ms var(--ease) forwards; }

/* The flying photo (see the photo flight in memories.js). */
.viewer-ghost { position: fixed; z-index: 120; pointer-events: none; background-size: cover; background-position: center; background-color: var(--paper-deep); }
.modal__panel--memory .modal__close {
  top: max(14px, calc(env(safe-area-inset-top) + 8px)); right: max(14px, env(safe-area-inset-right));
  width: 40px; height: 40px; background: rgba(255, 255, 255, 0.1); color: #fff;
}
.viewer {
  position: relative; height: 100%;
  display: flex; flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.viewer__top { height: 40px; flex: none; display: flex; align-items: center; justify-content: center; }
.viewer__count { font-size: var(--text-foot); color: #a8988b; font-variant-numeric: tabular-nums; }
.viewer .viewer__stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0; }
.viewer__polaroid {
  display: block; width: min(100%, 420px, calc(100dvh - 300px));
  padding: 14px 14px 0; border-radius: 3px;
  background: #fffdf7; color: #3a2a24; text-align: left;
  transform: rotate(-1.5deg);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.8);
  transition: transform 300ms var(--ease-sheet);
}
.viewer__polaroid--dragging { transition: none; }
.viewer__polaroid--from-right { animation: viewer-in-right 320ms var(--ease-sheet); }
.viewer__polaroid--from-left { animation: viewer-in-left 320ms var(--ease-sheet); }
@keyframes viewer-in-right { from { opacity: 0; transform: translateX(48px) rotate(1deg); } }
@keyframes viewer-in-left { from { opacity: 0; transform: translateX(-48px) rotate(-3deg); } }
.viewer__polaroid .viewer__image {
  display: block; width: 100%; height: auto; aspect-ratio: 1;
  border-radius: 1px; background-size: cover; background-position: center;
}
.viewer__hand {
  display: block; padding: 14px 4px 18px;
  font-family: var(--hand); font-size: 1.1rem; line-height: 1.5; color: #3a2a24;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.viewer--full .viewer__polaroid { width: 100%; padding: 0; background: transparent; box-shadow: none; transform: none; }
.viewer--full .viewer__polaroid .viewer__image { aspect-ratio: auto; height: calc(100dvh - 220px); background-size: contain; background-repeat: no-repeat; }
.viewer--full .viewer__hand { display: none; }
.viewer .viewer__nav { background: rgba(255, 255, 255, 0.1); color: #fff; }
@media (hover: none) { .viewer .viewer__nav { display: none; } }
.viewer .viewer__body { flex: none; width: 100%; max-width: 520px; margin: 0 auto; padding: 18px 4px 0; color: #f3eadf; }
.viewer .viewer__caption { margin: 0; font-family: var(--serif); font-size: 1.4rem; line-height: 1.3; color: #f3eadf; }
.viewer .viewer__date { margin-top: 6px; font-family: var(--sans); font-size: var(--text-foot); color: #a8988b; }
.viewer__actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.viewer__action {
  width: var(--tap); height: var(--tap); border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.08); color: #f3eadf;
  transition: background var(--fast) var(--ease), transform var(--press) var(--ease);
}
.viewer__action:active { transform: scale(0.92); }
.viewer__action .icon { width: 20px; height: 20px; }
@media (hover: hover) { .viewer__action:hover { background: rgba(255, 255, 255, 0.16); } }

/* Desktop: three columns; a feature spans two, which makes it the same
   height as a portrait photo beside it, so rows line up. */
@media (min-width: 980px) {
  .mem-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-flow: row dense; gap: 1.5rem 14px; }
  .mem-card--wide { grid-column: span 2; }
  /* A month with a single memory: let it run the full width, cinema-style */
  .mem-card--wide:only-child { grid-column: 1 / -1; }
  .mem-card--wide:only-child .mem-card__photo { aspect-ratio: 21 / 9; }
  #on-this-day-host .on-this-day:not(.on-this-day--text) { min-height: 180px; }
}
