/* ——— the story card (over the map) ——— */
.card-layer { z-index: 20; pointer-events: none !important; transition: opacity .3s; }
.card-layer.is-hidden { opacity: 0; }
.card-layer.is-hidden .story-card {
  pointer-events: none !important; }
.story-card {
  cursor: pointer;
  position: absolute;
  top: 50%;
  right: calc(26px + var(--sar));
  width: min(420px, 37vw);
  padding: 0;
  border-radius: 20px 18px 22px 19px;
  pointer-events: auto;
  transform: translate(calc(100% + 80px), -50%) rotate(5deg);
  transition: transform .6s var(--spring);
  touch-action: none;
}
.card-layer.is-open .story-card { transform: translateY(-50%) rotate(-1.2deg); }
.card-layer.is-out .story-card { transition-duration: .42s; transition-timing-function: cubic-bezier(.5, 0, .9, .5); }

.card-cover-wrap { position: relative; }
.card-cover {
  position: relative;
  aspect-ratio: 16 / 11;
  border-bottom: var(--line) solid var(--ink);
  border-radius: 17px 15px 0 0;
  overflow: hidden;
  background: var(--sky-pale);
}
.card-cover.is-loading { background: repeating-linear-gradient(-45deg, var(--sky-pale) 0 18px, #b9ddf8 18px 36px); }
.card-cover-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-year {
  position: absolute; top: 10px; right: 10px;
  padding: 1px 10px;
  font-family: var(--font-title); font-weight: 700; font-size: 18px;
  color: var(--cream); background: var(--red);
  border: 2.5px solid var(--ink); border-radius: 10px;
}
.card-body { display: grid; gap: 10px; padding: 14px 18px 22px 84px; }
.card-title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 400;
  font-size: clamp(19px, 2vw, 25px);
  line-height: 1.25;
  text-align: center;
  text-wrap: balance;
  min-width: 0;
  overflow-wrap: anywhere;
}
.card-play {
  position: absolute; top: 100%; left: 12px; translate: 0 -50%;
  width: 64px; height: 64px;
  display: grid; place-items: center;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--red);
  box-shadow: var(--flat);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .09s;
  outline: none;
}
.card-play > svg { width: 58%; height: 58%; margin-left: 8%; pointer-events: none; }
.card-close { position: absolute; top: -20px; left: -20px; z-index: 2; }
.card-dad { position: absolute; top: -62px; right: 26px; width: 84px; height: 84px; z-index: 1; animation: peek .9s var(--spring) both .35s; }
.card-dad > svg { width: 100%; height: 100%; }
.card-dad-bubble {
  position: absolute; top: 6px; right: 92px;
  white-space: nowrap; padding: 4px 12px;
  font-size: 15px; font-weight: 700;
  background: var(--white); border: 2.5px solid var(--ink); border-radius: 16px 16px 4px 16px;
  box-shadow: var(--flat);
  animation: pop-in .5s var(--spring) both .9s;
}
@keyframes peek { from { transform: translateY(40px) rotate(8deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop-in { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }

/* portrait: keep the same illustrated card near the bottom of the map */
.card-layer.is-portrait .story-card {
  top: auto;
  right: auto;
  left: 50%;
  bottom: calc(16px + var(--sab));
  width: min(420px, calc(100% - 52px));
  transform: translate(-50%, calc(100% + 60px)) rotate(2deg);
}
.card-layer.is-portrait.is-open .story-card { transform: translateX(-50%) rotate(-.6deg); }
.card-layer.is-portrait .card-dad { top: -64px; }

/* ——— floating stories rail, rising from the stories button ——— */
.menu-layer { z-index: 9; }
.menu-layer > .scrim {background:rgba(42,33,28,.52);}
.menu-panel {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--gap) + var(--sab) + var(--hud) * 1.38 + 18px);
  display: flex; flex-direction: column;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
  transform: translateY(48px) scale(.96);
  transform-origin: bottom right;
  opacity: 0;
  transition: transform .5s var(--spring), opacity .25s;
  pointer-events: none;
}
.menu-layer.is-open .menu-panel { transform: none; opacity: 1; pointer-events: auto; }
.menu-head { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 0 70px; }
.menu-dad { width: 78px; height: 78px; margin-bottom: -10px; transform: rotate(-6deg); }
.ribbon {
  position: relative;
  margin: 0;
  padding: 8px 46px 10px;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: clamp(24px, 3.2vmin, 34px);
  color: var(--ink);
  background: var(--cream);
  border: var(--line) solid var(--ink);
  border-radius: 6px;
  box-shadow: var(--flat);
}
.ribbon::before, .ribbon::after {
  content: ''; position: absolute; top: 12px; width: 34px; height: 100%;
  background: var(--paper-deep); border: var(--line) solid var(--ink); z-index: -1;
}
.ribbon::before { right: -26px; clip-path: polygon(0 0, 100% 0, 72% 50%, 100% 100%, 0 100%); }
.ribbon::after { left: -26px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 28% 50%); }
.ribbon > span { position: relative; }

.menu-scroll { width: 100%; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; scrollbar-width: none; }
.menu-scroll::-webkit-scrollbar { display: none; }
.menu-shelf {
  display: flex;
  gap: clamp(18px, 2.4vw, 30px);
  padding: 16px calc(var(--gap) + var(--sar) + 12px) 18px calc(var(--gap) + var(--sal) + 12px);
  width: max-content;
  min-width: 100%;
  justify-content: flex-start;
}
.menu-card {
  position: relative;
  flex: none;
  display: flex;
  flex-direction: column;
  width: clamp(190px, calc((100vw - 240px) / 4), 272px);
  padding: 0 0 14px;
  border: var(--line) solid var(--ink);
  border-radius: 20px 18px 22px 19px;
  background-color: var(--cream);
  background-image: var(--grain);
  box-shadow: var(--flat-big);
  rotate: var(--tilt, 0deg);
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .1s;
  outline: none;
}
.menu-cover-wrap { position: relative; flex: none; }
.menu-cover { position: relative; aspect-ratio: 16 / 11; overflow: hidden; border-bottom: var(--line) solid var(--ink); border-radius: 17px 15px 0 0; background: var(--sky-pale); }
.menu-cover.is-loading { background: repeating-linear-gradient(-45deg, var(--sky-pale) 0 16px, #b9ddf8 16px 32px); }
.menu-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.menu-year {
  position: absolute; top: 10px; right: 10px;
  padding: 1px 10px;
  font-family: var(--font-title); font-weight: 700; font-size: 18px;
  color: var(--ink); background: var(--white);
  border: 2.5px solid var(--ink); border-radius: 10px;
}
.menu-card-title { padding: 12px 18px 0; font-family: var(--font-title); font-weight: 400; font-size: clamp(17px, 1.7vw, 21px); line-height: 1.25; text-wrap: balance; }
.menu-story { padding-bottom: 18px; }
.menu-story .menu-card-title { padding-inline-end: 64px; min-height: 2.5em; display: flex; align-items: center; }
.menu-card-play {
  position: absolute; top: 100%; left: 12px; translate: 0 -50%;
  width: 64px; height: 64px; display: grid; place-items: center;
  background: var(--red); border: 3px solid var(--ink); border-radius: 50%;
  box-shadow: var(--flat);
}
.menu-card-play > svg { width: 58%; height: 58%; margin-left: 8%; }
.menu-panel.entering .menu-card { animation: card-in .55s var(--spring) backwards; }
.menu-panel.entering .menu-card:nth-child(2) { animation-delay: .07s; }
.menu-panel.entering .menu-card:nth-child(3) { animation-delay: .14s; }
.menu-panel.entering .menu-card:nth-child(4) { animation-delay: .21s; }
.menu-panel.entering .menu-card:nth-child(5) { animation-delay: .28s; }
@keyframes card-in { from { transform: translateY(40px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }

.menu-teaser { background-color: var(--paper-deep); width: clamp(170px, calc((100vw - 240px) / 4.6), 236px); align-self: flex-end; }
.menu-story { width: clamp(220px, calc((100vw - 200px) / 3.6), 320px); }
.teaser-art { aspect-ratio: 16 / 11; display: grid; place-items: center; padding: 10px; border-bottom: var(--line) dashed rgba(42, 33, 28, .45); }
.teaser-art > svg { width: 78%; height: 100%; }
.menu-teaser .teaser-art > svg { animation: float 4s ease-in-out infinite; }
.menu-teaser:nth-child(odd) .teaser-art > svg { animation-delay: -2s; }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(-6px) rotate(1.5deg); } }
.teaser-title { color: var(--ink-soft); }
.teaser-lock {
  position: absolute; top: 16px; left: -12px;
  padding: 2px 14px;
  font-family: var(--font-title); font-weight: 700; font-size: 16px;
  color: var(--ink); background: var(--magic);
  border: 2.5px solid var(--ink); border-radius: 4px;
  rotate: -12deg;
  box-shadow: var(--flat);
}
.menu-teaser.jiggle { animation: jiggle .55s ease; }
@keyframes jiggle {
  0%, 100% { transform: none; }
  20% { transform: rotate(-5deg) scale(1.04); }
  40% { transform: rotate(4deg) scale(1.05); }
  60% { transform: rotate(-3deg); }
  80% { transform: rotate(1.5deg); }
}
.teaser-bubble {
  position: absolute; bottom: calc(100% - 8px); left: 50%;
  translate: -50% 0;
  white-space: nowrap; padding: 6px 14px;
  font-size: 16px; font-weight: 700;
  background: var(--white); border: 2.5px solid var(--ink); border-radius: 18px;
  box-shadow: var(--flat);
  opacity: 0; pointer-events: none;
}
.teaser-bubble.show { animation: bubble 2.2s ease both; }
@keyframes bubble {
  0% { opacity: 0; transform: translateY(10px) scale(.7); }
  12%, 82% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-6px); }
}

@media (max-width: 700px), (orientation: portrait) {
  .menu-shelf { justify-content: flex-start; }
}

@media (max-height: 520px) {
  .menu-panel { bottom: calc(var(--gap) + var(--sab) + var(--hud) * 1.2 + 8px); }
  .menu-shelf { padding-block: 10px 12px; }
  .menu-story { width: 180px; padding-bottom: 8px; }
  .menu-card-title { padding-top: 6px; font-size: 16px; }
  .menu-story .menu-card-title { padding-inline-end: 48px; }
  .menu-card-play { width: 46px; height: 46px; left: 8px; }
}

/* Paper placeholders share a decoding state across the shelf, preview and player. */
.card-cover,.menu-cover,.ill-frame { background:var(--paper-deep); }
.card-cover.is-loading,.menu-cover.is-loading,.ill-frame.is-loading { background:#e8e1d3; }
.card-cover.is-loading img,.menu-cover.is-loading img,.ill-frame.is-loading .ill-stack { visibility:hidden; }
.card-cover.is-error::after,.menu-cover.is-error::after {
  content:attr(data-error);position:absolute;inset:0;display:grid;place-items:center;
  padding:20px;color:var(--ink-soft);font-size:16px;text-align:center;
}
.card-cover.is-error img,.menu-cover.is-error img { visibility:hidden; }
@keyframes story-shimmer { from {background-position:140% 0} to {background-position:-100% 0} }
.reduce-motion .is-loading::after {animation:none}
@media(prefers-reduced-motion:reduce){.is-loading::after{animation:none!important}}

/* Reserve room for the close button, the full title and the safe areas. */
.story-card {max-height:calc(100dvh - 72px - var(--sat) - var(--sab));display:flex;flex-direction:column;}
.card-cover-wrap {min-height:0;flex:1 1 auto;}
.card-cover {max-height:calc(100dvh - 210px - var(--sat) - var(--sab));}
.card-body {flex-shrink:0;}
@media(max-width:620px){
  .card-layer.is-portrait .story-card {bottom:calc(24px + var(--sab));}
  .card-title {font-size:20px;}
}
@media(max-height:520px) and (orientation:landscape){
  .story-card {width:min(360px,45vw);right:calc(24px + var(--sar));}
  .card-cover {aspect-ratio:2/1;max-height:calc(100dvh - 180px - var(--sat) - var(--sab));}
  .card-body {padding:10px 14px 14px 66px;gap:4px;}
  .card-title {font-size:18px;}
  .card-play {width:48px;height:48px;}
  .card-close {width:44px;height:44px;top:-18px;left:-18px;}
  .menu-story {width:160px;}
  .menu-cover {aspect-ratio:2/1;}
  .menu-panel {bottom:calc(64px + var(--sab));}
}

/* Mobile galleries share a bottom sheet; desktop keeps its illustrated rail. */
.sheet-header,.sheet-search-wrap,.sheet-empty,.sheet-handle {display:none;}
@media (max-width:767px), (pointer:coarse) and (max-width:1024px) and (max-height:540px) {
  .menu-layer > .scrim {background:rgba(42,33,28,.42);}
  .menu-panel {
    bottom:var(--sheet-viewport-bottom,0px);left:0;right:0;box-sizing:border-box;
    --sheet-height:calc(var(--sheet-viewport-height,100dvh) * .75);height:var(--sheet-height);max-height:calc(var(--sheet-viewport-height,100dvh) - env(safe-area-inset-top) - 12px);
    background:var(--sheet-background,#fffdf8);border:2px solid var(--ink);border-bottom:0;
    border-radius:26px 26px 0 0;overflow:clip;
    box-shadow:0 -5px 0 #2a211c18;
    transform:translateY(100%);transform-origin:bottom;
    transition:transform .28s ease,height .28s ease,opacity .2s;
    padding-bottom:env(safe-area-inset-bottom);
  }
  .menu-panel.sheet-expanded {--sheet-height:calc(var(--sheet-viewport-height,100dvh) - env(safe-area-inset-top) - 12px);}
  .menu-layer.is-open .menu-panel.sheet-dragging {height:var(--sheet-drag-height,var(--sheet-height));transform:translateY(var(--sheet-drag,0px));transition:none;}
  .sheet-header {display:flex;flex-direction:column;flex:none;padding:0 16px 6px;background:var(--sheet-background,#fffdf8);border-bottom:1px solid transparent;position:relative;z-index:2;}
  .sheet-header.is-scrolled {border-bottom-color:#ded7ca;}
  .sheet-handle {align-self:center;display:grid;place-items:center;width:80px;height:44px;min-height:44px;padding:6px 0 0;align-items:start;margin-bottom:-16px;position:relative;z-index:3;border:0;background:transparent;box-shadow:none;touch-action:none;cursor:ns-resize;}
  .sheet-handle span {width:42px;height:5px;background:var(--ink-soft);border-radius:8px;opacity:.5;}
  .sheet-heading {touch-action:none;display:flex;align-items:center;justify-content:space-between;gap:12px;}
  .sheet-heading h2 {font-family:var(--font-title);font-size:24px;margin:0;}
  .sheet-close {font-size:30px;width:44px;height:44px;min-width:44px;min-height:44px;padding:0;border:0;box-shadow:none;background:transparent;}
  .sheet-search-wrap {display:block;padding:8px 16px 4px;}
  .sheet-search {box-sizing:border-box;width:100%;min-height:44px;margin-top:0;padding:10px 14px;border:1.5px solid var(--ink-soft);border-radius:14px;background:#fffdf8;font:inherit;font-size:16px;color:var(--ink);}
  .menu-scroll {flex:1;min-height:0;overflow-x:hidden;overflow-y:auto;touch-action:pan-y;overscroll-behavior:contain;scrollbar-width:thin;}
  .menu-shelf {box-sizing:border-box;display:grid;grid-template-columns:minmax(0,1fr);align-items:start;width:100%;min-width:0;gap:14px;padding:8px 16px 24px;}
  .menu-shelf .menu-story {width:100%;min-width:0;rotate:0deg;box-sizing:border-box;padding-bottom:12px;box-shadow:2px 3px 0 #2a211c25;touch-action:pan-y;}
  .menu-panel.entering .menu-card {animation:none;}
  .menu-cover {aspect-ratio:4/3;}
  .menu-story .menu-card-title {font-size:16px;line-height:1.4;padding:10px 10px 0;min-height:2.8em;text-align:start;}
  .public-story-experience[dir="ltr"] .menu-panel .menu-scroll {direction:ltr;}
  .public-story-experience[dir] .menu-panel .menu-story .menu-card-title {padding-inline:10px;text-align:start;justify-content:flex-start;}
  .menu-card-play {width:40px;height:40px;top:auto;left:6px;bottom:8px;translate:none;}
  .sheet-empty {display:block;text-align:center;padding:20px;}
}
@media (prefers-reduced-motion:reduce) {.menu-panel {transition:none;}}
@media (max-height:540px) and (orientation:landscape) and (max-width:767px), (max-height:540px) and (orientation:landscape) and (pointer:coarse) and (max-width:1024px) {
  .menu-cover {aspect-ratio:16/9;}
}

/* Gallery captions sit on the gallery surface; only the illustration is framed. */
.menu-shelf .menu-card.menu-story {
  padding:0;border:0;border-radius:0;background:transparent;box-shadow:none;
}
.menu-shelf .menu-story .menu-cover {
  box-sizing:border-box;border:var(--line) solid var(--ink);
  border-radius:20px 18px 22px 19px;box-shadow:var(--flat-big);
}
.menu-shelf .menu-story .menu-card-title {
  display:block;min-height:0;padding:14px 4px 4px;padding-inline-end:var(--gallery-action-space,70px);text-align:start;color:var(--white);
}
.menu-shelf .menu-story .menu-card-play {
  top:100%;bottom:auto;left:auto;right:auto;inset-inline-end:12px;translate:0 -50%;box-sizing:border-box;width:54px;height:54px;padding:7px;background:var(--sheet-background,#fffdf8);box-shadow:none;z-index:1;
}
.menu-shelf .menu-story .menu-card-play > svg {display:block;min-width:0;min-height:0;width:100%;height:100%;margin:0;object-fit:contain;}
.menu-shelf .menu-story:focus-visible .menu-cover {
  outline:3px solid var(--yellow);outline-offset:3px;
}
.menu-shelf .menu-story.is-pressed {box-shadow:none!important;}
@media (max-width:767px), (pointer:coarse) and (max-width:1024px) and (max-height:540px) {
  .menu-shelf .menu-story .menu-card-title {color:var(--ink);}
  .menu-shelf .menu-story .menu-cover {box-shadow:2px 3px 0 #2a211c25;}
  .menu-shelf .menu-story .menu-card-play {width:48px;height:48px;inset-inline-end:10px;}
  .menu-shelf {row-gap:22px;}
}
