/* ============================================================================
   STORIKAST, application layout and components.
   Mobile-first, one-handed: everything you press lives in the bottom half.
   ========================================================================== */

/* ---------------------------------------------------------------- shell --- */

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--paper-sunk);
  visibility: hidden;
}
body[data-route="map"] #map { visibility: visible; }

#view {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  background: var(--paper);
}
/* On the map route the view layer is only chrome floating over the map. */
body[data-route="map"] #view {
  background: transparent;
  pointer-events: none;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
body[data-route="map"] #view > * { pointer-events: auto; }

/* ------------------------------------------------------------- tab bar ---- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: stretch;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper-veil);
  backdrop-filter: saturate(1.5) blur(18px);
  -webkit-backdrop-filter: saturate(1.5) blur(18px);
  border-top: 1px solid var(--rule);
}
.tabbar__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tap);
  color: var(--ink-faint);
  text-decoration: none;
  font-size: var(--step--2);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: color var(--dur-1) linear;
}
.tabbar__item svg { width: 22px; height: 22px; }
.tabbar__item[aria-current="page"] { color: var(--accent-lift); }
.tabbar__item:active { opacity: 0.6; }
/* Someday is the one tab the accent never claims. */
.tabbar__item--dream[aria-current="page"] { color: var(--dream); }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 10px;
  background: var(--paper-veil);
  backdrop-filter: saturate(1.5) blur(18px);
  -webkit-backdrop-filter: saturate(1.5) blur(18px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur-2) linear;
}
.topbar--ruled { border-bottom-color: var(--rule); }
.topbar__title {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar__spacer { flex: 1; }

.viewhead {
  padding: 4px var(--gutter) 6px;
}
.viewhead__title {
  font-size: var(--step-4);
  letter-spacing: -0.02em;
}
.viewhead__sub {
  margin-top: 4px;
  font-size: var(--step-0);
  color: var(--ink-soft);
}

.section { padding: 8px var(--gutter) 22px; }
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 10px;
}

/* --------------------------------------------------------- map: search ---- */

.mapchrome {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.searchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 50px;
  padding: 0 8px 0 15px;
  border-radius: var(--r-pill);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-2);
}
.searchbar__icon { width: 19px; height: 19px; color: var(--ink-faint); flex: none; }
.searchbar__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  font-size: 1rem;
  padding: 0;
}
.searchbar__input::placeholder { color: var(--ink-faint); }
.searchbar__input:focus { outline: none; }
.searchbar .iconbtn { flex: none; width: 36px; height: 36px; }

.avatarbtn {
  width: 36px; height: 36px;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-display);
  font-size: var(--step-0);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border: 0;
}

.mapchips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  margin: 0 calc(var(--gutter) * -1);
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}
.mapchips::-webkit-scrollbar { display: none; }

.searchresults {
  max-height: min(52dvh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
}
.result {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--rule);
}
.result:last-child { border-bottom: 0; }
.result:active { background: var(--paper-sunk); }
.result__emoji {
  width: 34px; height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  background: var(--paper-sunk);
  font-size: 17px;
}
.result__name { font-weight: 600; }
.result__meta { font-size: var(--step--1); color: var(--ink-soft); }

/* map floating controls, bottom-right, above the sheet peek */
.mapdock {
  position: absolute;
  right: var(--gutter);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mapdock .iconbtn { width: 42px; height: 42px; box-shadow: var(--shadow-2); }

.maphint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 22px);
  max-width: calc(100% - 2 * var(--gutter));
  text-align: center;
}

/* ------------------------------------------------------------- markers ---- */

.pin {
  position: relative;
  width: 40px; height: 48px;
  transform-origin: 50% 100%;
  animation: pin-drop var(--dur-3) var(--ease-out) both;
}
@keyframes pin-drop {
  from { transform: translateY(-10px) scale(0.7); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.pin__bubble {
  position: absolute;
  inset: 0 0 8px 0;
  border-radius: 50% 50% 50% 50% / 52% 52% 48% 48%;
  background: var(--paper-raised);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-1);
  display: grid;
  place-items: center;
  font-size: 19px;
  line-height: 1;
}
.pin__bubble::after {                  /* the tail */
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 10px; height: 10px;
  transform: translateX(-50%) rotate(45deg);
  background: var(--accent);
  border-radius: 0 0 3px 0;
}
.pin--saved .pin__bubble { background: var(--accent); }
.pin--saved .pin__heart {
  position: absolute;
  right: -3px; top: -3px;
  width: 16px; height: 16px;
  color: var(--accent);
  filter: drop-shadow(0 0 0 var(--paper-raised));
}
.pin--dim { opacity: 0.28; filter: grayscale(0.7); }
.pin--active { z-index: 500; }
.pin--active .pin__bubble { transform: scale(1.14); box-shadow: var(--shadow-2); }
.pin__count {
  position: absolute;
  right: -4px; bottom: 4px;
  min-width: 17px; height: 17px;
  padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* a temporary pin she has just dropped, before naming it */
.pin--draft .pin__bubble {
  border-style: dashed;
  background: var(--accent-wash);
}

/* ---------------------------------------------------------- dream pins ----
   A SOMEDAY is not a memory, and it must never be mistakable for one. Same
   silhouette so it belongs to the family, then everything that says "this
   happened" is taken away: the fill goes translucent, the outline goes dashed
   and dream-coloured, there is no visit count, and the whole pin floats a
   little above its own shadow instead of standing in the ground. */

.pin--dream .pin__bubble {
  background: var(--paper-veil);
  border: 2px dashed var(--dream);
  color: var(--dream);
  box-shadow: 0 0 0 5px var(--dream-wash), var(--shadow-1);
}
.pin--dream .pin__bubble::after { background: var(--dream); }
.pin--dream {
  animation:
    pin-drop var(--dur-3) var(--ease-out) both,
    dream-float 5.4s var(--dur-3) ease-in-out infinite;
}
.pin--dream::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1px;
  width: 15px; height: 4px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(20, 14, 8, 0.20);
  filter: blur(1.5px);
  animation: dream-shadow 5.4s var(--dur-3) ease-in-out infinite;
}
.pin__spark {
  position: absolute;
  right: -3px; top: -4px;
  width: 15px; height: 15px;
  color: var(--dream-lift);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}
@keyframes dream-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}
@keyframes dream-shadow {
  0%, 100% { opacity: 0.55; transform: translateX(-50%) scaleX(1); }
  50%      { opacity: 0.3; transform: translateX(-50%) scaleX(0.78); }
}
@media (prefers-reduced-motion: reduce) {
  .pin--dream, .pin--dream::after { animation: none; }
}

/* ------------------------------------------------------- leaflet chrome --- */

.leaflet-container {
  font-family: var(--font-ui);
  background: var(--paper-sunk);
}
.leaflet-control-attribution {
  background: var(--paper-veil) !important;
  color: var(--ink-faint) !important;
  font-size: 9.5px !important;
  line-height: 1.5;
  padding: 1px 6px !important;
  border-radius: var(--r-pill) 0 0 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.leaflet-control-attribution a { color: var(--ink-soft) !important; text-decoration: none; }
.leaflet-bottom.leaflet-right {
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.leaflet-control-zoom { display: none; }        /* pinch is the gesture on a phone */
[data-theme="dark"] .leaflet-tile-pane { filter: none; }

/* --------------------------------------------------------- bottom sheet --- */

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper-raised);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-3);
  border-top: 1px solid var(--rule);
  transform: translateY(100%);
  transition: transform var(--dur-3) var(--ease);
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--tabbar-h));
}
.sheet--open { transform: translateY(0); }
.sheet--dragging { transition: none; }
.sheet__grip {
  flex: none;
  padding: 9px 0 5px;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
}
.sheet__grip::before {
  content: "";
  width: 40px; height: 4px;
  border-radius: var(--r-pill);
  background: var(--rule-heavy);
}
.sheet__body { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.placecard {
  display: flex;
  flex-direction: column;
  padding: 4px var(--gutter) 18px;
}
.placecard__row { display: flex; align-items: flex-start; gap: 14px; }
.placecard__cover {
  width: 74px; height: 74px;
  flex: none;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--photo-bed);
  display: grid;
  place-items: center;
  font-size: 30px;
}
.placecard__cover img { width: 100%; height: 100%; object-fit: cover; }
.placecard__main { flex: 1; min-width: 0; }
.placecard__name {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 600;
  line-height: 1.2;
}
.placecard__meta { margin-top: 3px; font-size: var(--step--1); color: var(--ink-soft); }
.placecard__actions { display: flex; gap: 9px; margin-top: 14px; }
.placecard__actions .btn { flex: 1; }

/* --------------------------------------------------------------- heart ---- */

.heartstage {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 64px;
  flex: none;
}

.heart {
  display: inline-grid;
  place-items: center;
  width: 42px; height: 42px;
  border-radius: var(--r-pill);
  border: 1px solid var(--rule-heavy);
  background: var(--paper-raised);
  color: var(--ink-faint);
  flex: none;
  transition: transform var(--dur-1) var(--ease-out), color var(--dur-1) linear,
              border-color var(--dur-1) linear;
}
.heart svg { width: 21px; height: 21px; }
.heart[aria-pressed="true"] { color: var(--accent); border-color: var(--accent-line); }
.heart[aria-pressed="true"] svg { fill: currentColor; }
.heart:active { transform: scale(0.88); }
.heart--pop { animation: heart-pop 460ms var(--ease-out); }
@keyframes heart-pop {
  0%   { transform: scale(1); }
  32%  { transform: scale(1.32); }
  62%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}

.heartstage--celebrating .heart {
  opacity: 0;
  transform: scale(0.72);
}
.heart-celebration {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  pointer-events: none;
  animation: stori-heart-pop 820ms var(--ease-out) both;
}
.heart-celebration img {
  width: 64px;
  height: 64px;
  filter: drop-shadow(0 6px 8px rgba(76, 46, 38, 0.18));
}
@keyframes stori-heart-pop {
  0%   { opacity: 0; transform: translateY(5px) scale(0.38); }
  36%  { opacity: 1; transform: translateY(-1px) scale(1.08); }
  68%  { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-3px) scale(0.92); }
}

@media (prefers-reduced-motion: reduce) {
  .heart-celebration { animation: none; opacity: 1; transform: none; }
}

/* --------------------------------------------------------------- cards ---- */

.card {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.card + .card { margin-top: 14px; }
.card__pad { padding: 15px var(--gutter); }

.cover {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  background: var(--photo-bed);
  overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover--tall { aspect-ratio: 4 / 5; }
.cover__veil {
  position: absolute;
  inset: auto 0 0 0;
  padding: 44px 18px 16px;
  background: linear-gradient(to top, rgba(18, 14, 10, 0.72), transparent);
  color: #FFF8EE;
}
.cover__veil h1, .cover__veil h2 { color: inherit; }
.cover__veil .meta { color: rgba(255, 248, 238, 0.82); }
.cover--empty {
  display: grid;
  place-items: center;
  color: var(--ink-faint);
  font-size: 40px;
}

/* place chapter hero */
.chapterhero { position: relative; }
.chapterhero .cover { aspect-ratio: 1 / 1; max-height: 46dvh; }
.chapterhero__back {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 10px);
  left: var(--gutter);
  z-index: 3;
}
.chapterhero__tools {
  position: absolute;
  top: env(safe-area-inset-top);
  right: var(--gutter);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 9px;
}

.titleblock { padding: 16px var(--gutter) 4px; }
.titleblock__name {
  display: flex;
  align-items: center;
  gap: 10px;
}
.titleblock__emoji {
  font-size: 30px;
  line-height: 1;
  width: 46px; height: 46px;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: var(--paper-sunk);
  border: 1px dashed var(--rule-heavy);
  flex: none;
}
.titleblock h1 { flex: 1; min-width: 0; }

/* An inline-editable field: looks like text until she touches it. */
.editable {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px dashed transparent;
  background: none;
  padding: 2px 0;
  font-family: var(--font-display);
  font-size: var(--step-3);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink);
  border-radius: 0;
  -webkit-appearance: none;
}
.editable:hover { border-bottom-color: var(--rule-heavy); }
.editable:focus {
  outline: none;
  border-bottom-color: var(--accent);
}
.editable--sm { font-size: var(--step-2); }
.editable--ui { font-family: var(--font-ui); font-size: var(--step-1); font-weight: 600; }

.pinnote {
  margin: 14px var(--gutter) 0;
  padding: 13px 15px;
  border-left: 3px solid var(--accent-line);
  background: var(--accent-wash);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  font-family: var(--font-display);
  font-size: var(--step-1);
  line-height: 1.45;
}
.pinnote .eyebrow { display: block; margin-bottom: 5px; }

/* -------------------------------------------------------------- visits ---- */

.visit {
  border-top: 1px solid var(--rule);
  padding: 20px 0 6px;
}
.visit__head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 0 var(--gutter);
}
.visit__date {
  flex: none;
  width: 52px;
  text-align: center;
  font-family: var(--font-display);
  line-height: 1;
}
.visit__date b { display: block; font-size: var(--step-3); font-weight: 600; }
.visit__date span { font-size: var(--step--2); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.visit__title { flex: 1; min-width: 0; }
.visit__meta { font-size: var(--step--1); color: var(--ink-soft); margin-top: 2px; }

/* horizontal photo strip inside a place chapter */
.strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 12px var(--gutter);
  scroll-snap-type: x proximity;
}
.strip::-webkit-scrollbar { display: none; }
.strip__item {
  flex: none;
  height: 132px;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--photo-bed);
  scroll-snap-align: start;
  position: relative;
}
.strip__item img { height: 100%; width: auto; max-width: none; object-fit: cover; }
.strip__more {
  flex: none;
  width: 92px; height: 132px;
  border-radius: var(--r-md);
  background: var(--paper-sunk);
  display: grid;
  place-items: center;
  text-align: center;
  font-size: var(--step--1);
  color: var(--ink-soft);
  font-weight: 600;
}

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

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 0 4px;
}
.grid--roomy { gap: 8px; padding: 0 var(--gutter); }
.grid--four { grid-template-columns: repeat(4, 1fr); }

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--photo-bed);
  overflow: hidden;
  border-radius: 4px;
  touch-action: manipulation;
}
.grid--roomy .tile { border-radius: var(--r-sm); }
.tile img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform var(--dur-2) var(--ease-out), opacity var(--dur-2) linear;
}
.tile--loading img { opacity: 0; }
.tile:active img { transform: scale(1.04); }
.tile__badge {
  position: absolute;
  top: 5px; right: 5px;
  width: 18px; height: 18px;
  color: #FFF6E9;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}
.tile__badge--fav { fill: currentColor; }
.tile--hidden { opacity: 0.42; }
.tile--hidden::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, transparent 0 7px, var(--scrim) 7px 8px);
}
.tile--dragging { opacity: 0.4; }
.tile--drop-target { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile--lifted {
  z-index: 5;
  transform: scale(1.06);
  box-shadow: var(--shadow-2);
  transition: none;
}

.grid--reorder .tile { cursor: grab; }
.reorderhint {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px var(--gutter) 0;
  font-size: var(--step--1);
  color: var(--ink-faint);
}

.hiddenreveal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 2 * var(--gutter));
  margin: 12px var(--gutter) 0;
  min-height: var(--tap);
  border-radius: var(--r-md);
  border: 1px dashed var(--rule-heavy);
  color: var(--ink-soft);
  font-size: var(--step--1);
  font-weight: 600;
}

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

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #0B0908;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transition: opacity var(--dur-2) linear;
}
.lightbox--open { opacity: 1; }
.lightbox__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  color: #F6EEE2;
}
.lightbox__bar .iconbtn {
  background: rgba(255, 255, 255, 0.10);
  border-color: transparent;
  color: inherit;
  box-shadow: none;
}
.lightbox__caption { flex: 1; min-width: 0; text-align: center; line-height: 1.25; }
.lightbox__caption b { display: block; font-family: var(--font-display); font-size: var(--step-0); font-weight: 600; }
.lightbox__caption span { font-size: var(--step--1); opacity: 0.7; }
.lightbox__stage {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.lightbox__stage::-webkit-scrollbar { display: none; }
.lightbox__slide {
  flex: none;
  width: 100%;
  height: 100%;
  scroll-snap-align: center;
  display: grid;
  place-items: center;
  padding: 6px;
}
.lightbox__slide img {
  max-width: 100%;
  max-height: 100%;
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 3px;
}
.lightbox__foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 14px);
  color: #F6EEE2;
}
.lightbox__foot .btn {
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.18);
  color: inherit;
}
.lightbox__foot .btn[aria-pressed="true"] { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.lightbox__dots {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 2px 0 0;
}
.lightbox__dots i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
}
.lightbox__dots i.on { background: #F6EEE2; }

/* ------------------------------------------------------------- entries ---- */

.entries { padding: 0 var(--gutter); }
.entry {
  padding: 15px 0;
  border-bottom: 1px solid var(--rule);
}
.entry:last-child { border-bottom: 0; }
.entry__body {
  font-family: var(--font-display);
  font-size: var(--step-1);
  line-height: 1.58;
  color: var(--ink);
  white-space: normal;
  overflow-wrap: anywhere;
}
.entry__body em { font-style: italic; }
.entry__body strong { font-weight: 700; }
.entry__sig {
  margin-top: 9px;
  font-size: var(--step--1);
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 8px;
}
.entry__sig .iconbtn { width: 30px; height: 30px; }
.entry__sig b { font-weight: 600; color: var(--ink-soft); }

.composer {
  margin: 12px 0 4px;
  border: 1px solid var(--rule-heavy);
  border-radius: var(--r-lg);
  background: var(--paper-raised);
  overflow: hidden;
  transition: border-color var(--dur-2) linear;
}
.composer:focus-within { border-color: var(--accent-line); }
.composer__area {
  display: block;
  width: 100%;
  min-height: 96px;
  padding: 14px 15px 6px;
  border: 0;
  background: none;
  resize: none;
  font-family: var(--font-display);
  font-size: 1.0625rem;      /* ≥16px: no zoom-on-focus in iOS Safari */
  line-height: 1.55;
}
.composer__area:focus { outline: none; }
.composer__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px 10px 15px;
  font-size: var(--step--1);
  color: var(--ink-faint);
}
.composer__status[data-state="saving"] { color: var(--ink-soft); }
.composer__status[data-state="saved"] { color: var(--accent-lift); }
.composer__status[data-state="error"] { color: #C0392B; font-weight: 600; }
.composer__hint { font-size: var(--step--2); }

/* -------------------------------------------------------------- upload ---- */

.dropzone {
  position: relative;
  border-radius: var(--r-lg);
}
.dropzone--over::after {
  content: "Drop photos here";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  border: 2px dashed var(--accent);
  background: var(--accent-wash);
  color: var(--accent-deep);
  font-weight: 650;
  pointer-events: none;
  z-index: 4;
}
.uploadrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--gutter) 4px;
}
.uploadrow__bar {
  flex: 1;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--paper-sunk);
  overflow: hidden;
}
.uploadrow__bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width var(--dur-2) linear;
}

/* ------------------------------------------------------------ timeline ---- */

.yearscrub {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px var(--gutter) 12px;
  scroll-snap-type: x proximity;
}
.yearscrub::-webkit-scrollbar { display: none; }
.yearscrub__y {
  flex: none;
  min-width: 62px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  background: var(--paper-sunk);
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  scroll-snap-align: center;
  transition: background var(--dur-1) linear, color var(--dur-1) linear;
}
.yearscrub__y[aria-current="true"] { background: var(--accent); color: var(--accent-ink); }

.day { padding: 0 0 26px; }
.day__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 var(--gutter) 8px;
  position: sticky;
  top: calc(env(safe-area-inset-top) + 52px);
  z-index: 6;
  background: linear-gradient(to bottom, var(--paper) 70%, transparent);
}
.day__date {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 600;
}
.day__wd { font-size: var(--step--1); color: var(--ink-faint); letter-spacing: 0.04em; }
.day__count { margin-left: auto; }

.dayvisit {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0 0 12px;
}
.dayvisit__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px var(--gutter);
}
.dayvisit__emoji {
  width: 32px; height: 32px;
  flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--paper-sunk);
  font-size: 16px;
}
.dayvisit__name { flex: 1; min-width: 0; font-weight: 650; }
.dayvisit__time { font-size: var(--step--1); color: var(--ink-faint); font-variant-numeric: tabular-nums; }

.loosegroup { padding: 4px 0 10px; }
.loosegroup__label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px var(--gutter);
  color: var(--ink-faint);
  font-size: var(--step--1);
}
.loosegroup__label svg { width: 16px; height: 16px; }

/* ---------------------------------------------------------- on this day --- */

.otd-year { padding-bottom: 8px; }
.otd-year__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 14px var(--gutter) 6px;
}
.otd-year__y {
  font-family: var(--font-display);
  font-size: var(--step-3);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.otd-year__ago { font-size: var(--step--1); color: var(--ink-faint); }

/* --------------------------------------------------------------- saved ---- */

.savedrow {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px var(--gutter);
  border-bottom: 1px solid var(--rule);
}
.savedrow__hit {
  display: flex;
  align-items: center;
  gap: 13px;
  flex: 1;
  min-width: 0;
  text-align: left;
  min-height: var(--tap);
}
.savedrow:active { background: var(--paper-sunk); }
.savedrow > svg { width: 20px; height: 20px; color: var(--ink-faint); flex: none; }
.savedrow__thumb {
  width: 58px; height: 58px;
  flex: none;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--paper-sunk);
  display: grid; place-items: center;
  font-size: 25px;
}
.savedrow__thumb img { width: 100%; height: 100%; object-fit: cover; }
.savedrow__main { flex: 1; min-width: 0; }
.savedrow__name { font-weight: 650; }
.savedrow__meta { font-size: var(--step--1); color: var(--ink-soft); }

/* ------------------------------------------------------------ settings ---- */

.setting {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  padding: 12px var(--gutter);
  border-bottom: 1px solid var(--rule);
}
.setting__main { flex: 1; min-width: 0; }
.setting__label { font-weight: 600; }
.setting__hint { font-size: var(--step--1); color: var(--ink-soft); }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--r-pill);
  background: var(--paper-sunk);
}
.segmented button {
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--ink-soft);
}
.segmented button[aria-pressed="true"] {
  background: var(--paper-raised);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 4px var(--gutter) 18px;
}
.swatch {
  width: 46px; height: 46px;
  border-radius: var(--r-pill);
  position: relative;
  display: grid;
  place-items: center;
  border: 2px solid transparent;
  transition: transform var(--dur-1) var(--ease-out);
}
.swatch i {
  width: 32px; height: 32px;
  border-radius: var(--r-pill);
  background: var(--sw);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch[aria-pressed="true"] { border-color: var(--sw); }
.swatch:active { transform: scale(0.9); }
.swatch__custom {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%; height: 100%;
  border: 0; padding: 0;
  cursor: pointer;
}

.mapstyles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 12px;
  padding: 4px var(--gutter) 18px;
}
.mapstyle {
  border-radius: var(--r-md);
  overflow: hidden;
  border: 2px solid transparent;
  background: var(--paper-sunk);
  text-align: left;
}
.mapstyle[aria-pressed="true"] { border-color: var(--accent); }
.mapstyle__swatch {
  height: 56px;
  background-size: cover;
  background-position: center;
}
.mapstyle__name { padding: 7px 9px; font-size: var(--step--1); font-weight: 600; }

/* ------------------------------------------------------------- someday ----
   Places they have not been. The whole section is written in a second voice:
   dream teal instead of ember, dashed instead of solid, sparkles instead of
   counts, and not one date anywhere. Real history stays real precisely because
   this does not pretend to be it. */

.chip--dream {
  background: var(--dream-wash);
  border-color: var(--dream-line);
  color: var(--dream);
  box-shadow: none;
}
.chip--dream svg { color: var(--dream); }

.dreamhead {
  padding: 4px var(--gutter) 2px;
}
.dreamhead__title {
  font-size: var(--step-4);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dreamhead__title svg { width: 26px; height: 26px; color: var(--dream); flex: none; }
.dreamhead__sub {
  margin-top: 5px;
  font-family: var(--font-display);
  font-size: var(--step-1);
  color: var(--ink-soft);
  max-width: 34ch;
}

.somedaygrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  padding: 14px var(--gutter) 24px;
}

/* the same card, laid on its side and set loose to scroll, for the Saved tab */
.somedayrail {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  padding: 6px var(--gutter) 14px;
}
.somedayrail::-webkit-scrollbar { display: none; }
.somedayrail .somedaycard { flex: none; width: 152px; scroll-snap-align: start; }

.somedaycard {
  display: flex;
  flex-direction: column;
  text-align: left;
  border-radius: var(--r-lg);
  border: 1px dashed var(--dream-line);
  background: var(--paper-raised);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  transition: transform var(--dur-1) var(--ease-out);
}
.somedaycard:active { transform: scale(0.985); }
.somedaycard__art {
  position: relative;
  aspect-ratio: 4 / 5;
  background: var(--photo-bed);
  display: grid;
  place-items: center;
  font-size: 34px;
}
.somedaycard__art img { width: 100%; height: 100%; object-fit: cover; }
/* the haze: a breath of dream colour over the art, so even the photography
   reads as imagined rather than remembered */
.somedaycard__art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, var(--dream-wash) 0%, transparent 52%);
  pointer-events: none;
}
.somedaycard__spark {
  position: absolute;
  top: 8px; left: 8px;
  width: 17px; height: 17px;
  color: #FFF8EC;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.45));
  z-index: 1;
}
.somedaycard__body { padding: 10px 12px 13px; }
.somedaycard__name {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 600;
  line-height: 1.22;
}
.somedaycard__where {
  margin-top: 5px;
  font-size: var(--step--2);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--dream);
}
.somedaycard__cap {
  margin-top: 7px;
  font-size: var(--step--1);
  line-height: 1.42;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.somedayrail .somedaycard__cap { -webkit-line-clamp: 2; line-clamp: 2; }

/* ---- the chapter --------------------------------------------------------- */

.chapterhero--dream { border-bottom: 1px dashed var(--dream-line); }
.chapterhero--dream .cover::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to top, var(--dream-wash) 0%, transparent 44%);
}
.chapterhero--dream .cover--empty { color: var(--dream); }

.somedaybadge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px var(--gutter) 0;
}

.somedaywhere {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--gutter) 2px;
}
.somedaywhere > svg { width: 18px; height: 18px; color: var(--dream); flex: none; }
.somedaywhere .editable {
  font-family: var(--font-ui);
  font-size: var(--step-0);
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0;
}
.somedaywhere .btn--sm { flex: none; }

/* her fun little story about a place she has not been */
.somedaycap {
  margin: 16px var(--gutter) 0;
  padding: 13px 15px;
  border-left: 3px solid var(--dream-line);
  background: var(--dream-wash);
  border-radius: 0 var(--r-md) var(--r-md) 0;
}
.somedaycap .eyebrow { display: block; margin-bottom: 6px; }
.editable-note {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  padding: 0;
  resize: none;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: var(--step-1);
  line-height: 1.5;
  color: var(--ink);
  border-bottom: 1px dashed transparent;
}
.editable-note:focus { outline: none; border-bottom-color: var(--dream); }
.editable-note::placeholder { color: var(--ink-faint); }

/* ---- "we said someday" ---------------------------------------------------
   The one place a date is allowed near a someday, because by then it is not a
   someday any more. Dashed dream while it is still a promise; solid ember once
   it is a memory. The colour is the story. */

.saidsomeday {
  margin: 20px var(--gutter) 4px;
  padding: 14px 15px;
  border-radius: var(--r-md);
  border: 1px dashed var(--dream-line);
  background: var(--dream-wash);
}
.saidsomeday--kept {
  border-style: solid;
  border-color: var(--accent-line);
  background: var(--accent-wash);
}
.saidsomeday .eyebrow { display: block; margin-bottom: 6px; }
.saidsomeday__line {
  font-family: var(--font-display);
  font-size: var(--step-1);
  line-height: 1.45;
}
.saidsomeday__link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: var(--r-md);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  text-align: left;
}
.saidsomeday__link svg { width: 19px; height: 19px; flex: none; color: var(--accent); }
.saidsomeday__thumb {
  width: 42px; height: 42px;
  flex: none;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--paper-sunk);
  display: grid; place-items: center;
}
.saidsomeday__thumb img { width: 100%; height: 100%; object-fit: cover; }
.saidsomeday__name { flex: 1; min-width: 0; font-weight: 650; }

/* ---- picking a spot on the map ------------------------------------------- */

.mappick {
  position: relative;
  height: min(46dvh, 320px);
  margin: 0 -4px;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
}
.mappick__map { position: absolute; inset: 0; }
.mappick__cross {
  position: absolute;
  left: 50%; top: 50%;
  z-index: 500;
  transform: translate(-50%, -100%);
  pointer-events: none;
}
.mappick__hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  font-size: var(--step--1);
  color: var(--ink-faint);
}
.mappick__coords { font-variant-numeric: tabular-nums; }

@media (min-width: 720px) {
  .somedaygrid { grid-template-columns: repeat(3, 1fr); }
}

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal__scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  transition: opacity var(--dur-2) linear;
}
.modal--open .modal__scrim { opacity: 1; }
.modal__panel {
  position: relative;
  width: min(520px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--paper-raised);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-3);
  padding: 20px var(--gutter) calc(env(safe-area-inset-bottom) + 20px);
  transform: translateY(14px);
  opacity: 0;
  transition: transform var(--dur-2) var(--ease), opacity var(--dur-2) linear;
}
.modal--open .modal__panel { transform: none; opacity: 1; }
.modal__title {
  font-family: var(--font-display);
  font-size: var(--step-2);
  font-weight: 600;
  margin-bottom: 4px;
}
.modal__sub { color: var(--ink-soft); font-size: var(--step--1); margin-bottom: 16px; }
.modal__actions { display: flex; gap: 10px; margin-top: 18px; }
.modal__actions .btn { flex: 1; }
@media (min-width: 620px) {
  .modal { align-items: center; }
  .modal__panel { border-radius: var(--r-xl); padding-bottom: 20px; }
}

.emojigrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 6px;
  max-height: 42dvh;
  overflow-y: auto;
  padding: 2px;
}
.emojigrid button {
  aspect-ratio: 1;
  min-height: 44px;
  border-radius: var(--r-sm);
  font-size: 23px;
  background: var(--paper-sunk);
}
.emojigrid button[aria-pressed="true"] { outline: 2px solid var(--accent); }

/* --------------------------------------------------------------- toast ---- */

#toast-root {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 var(--gutter);
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 11px 16px;
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--paper);
  font-size: var(--step--1);
  font-weight: 550;
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: toast-in var(--dur-2) var(--ease-out) both;
}
.toast--leaving { animation: toast-out var(--dur-2) var(--ease-out) both; }
.toast button {
  color: var(--accent-lift);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  min-height: 22px;
}
@keyframes toast-in {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateY(8px); opacity: 0; }
}

/* --------------------------------------------------------- wider screens -- */

@media (min-width: 720px) {
  :root { --gutter: 26px; }

  #view > .sheet-inline,
  .pagewrap {
    max-width: 780px;
    margin: 0 auto;
  }
  .grid { grid-template-columns: repeat(4, 1fr); }
  .grid--four { grid-template-columns: repeat(6, 1fr); }
  .chapterhero .cover { aspect-ratio: 16 / 9; }
  .mapchrome { max-width: 460px; }
  .searchresults { max-height: min(60dvh, 520px); }

  .tabbar {
    right: auto;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100dvh;
    width: 92px;
    grid-template-columns: 1fr;
    grid-auto-rows: 76px;
    align-content: center;
    gap: 6px;
    border-top: 0;
    border-right: 1px solid var(--rule);
    padding-bottom: 0;
  }
  body { padding-left: 92px; }
  #map { left: 92px; }
  .leaflet-bottom.leaflet-right { bottom: 0; }
  .sheet { left: 92px; max-width: 460px; padding-bottom: env(safe-area-inset-bottom); }
  .mapdock { bottom: 42px; }
  .maphint { bottom: 30px; }
  #toast-root { left: 92px; bottom: 24px; }
}

@media (min-width: 720px) and (pointer: fine) {
  .result:hover, .savedrow:hover { background: var(--paper-sunk); }
  .tile:hover img { transform: scale(1.03); }
}

/* ------------------------------------------------------------- details ---- */

/* Leaflet gives div icons a white box by default; ours replaces the class, and
   this makes sure of it. */
.pin-wrap { background: none; border: 0; }

/* While a tile is under the finger it must not be its own drop target. */
.tile--lifted { pointer-events: none; }
/* In reorder mode the grid owns vertical gestures; the page stops scrolling. */
.grid--reorder .tile { touch-action: none; }
.tile--broken { display: grid; place-items: center; }

/* The map chrome floats: only its actual controls should swallow taps, never
   the empty space between them (that space is map). */
.mapchrome, .maphint { pointer-events: none; }
.mapchrome > *, .maphint > * { pointer-events: auto; }

.searchbar__input::-webkit-search-decoration,
.searchbar__input::-webkit-search-cancel-button,
.searchbar__input::-webkit-search-results-button {
  -webkit-appearance: none;
  appearance: none;
}

.uploads:empty { display: none; }
