/* Keep the approved art registration intact. The mobile viewport crops only
   the cover's outer edges while bringing the logo, guide and tiles closer. */
body[data-screen="home"] .game-header {
  position: sticky;
  top: var(--safe-top, env(safe-area-inset-top));
  z-index: 7;
  display: flex;
  height: 76px;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 0;
}
body[data-screen="home"] .brand {
  display: none;
}
body[data-screen="home"] .player-supplies {
  flex: 1;
  width: auto;
  margin: 0;
  gap: 12px;
}
body[data-screen="home"] .coin-pill {
  order: -1;
  flex-shrink: 0;
}
body[data-screen="home"] .inventory-summary {
  margin-left: auto;
}
.home-hero {
  padding: 0 0 18px;
  transition:
    background-color 380ms ease,
    box-shadow 380ms ease;
}
.home-cover-slot {
  /* Anchor before morphing, so native scrolling cannot move the animation's
     origin behind the HUD. The empty reservation must not block theme taps. */
  position: sticky;
  top: calc(76px + var(--safe-top, env(safe-area-inset-top)));
  z-index: 6;
  pointer-events: none;
  overflow-anchor: none;
}
.home-cover-slot .home-hero {
  pointer-events: auto;
}
.home-hero.is-docked {
  position: fixed;
  top: calc(76px + var(--safe-top, env(safe-area-inset-top)));
  left: max(32px, calc((100vw - 1116px) / 2));
  right: max(32px, calc((100vw - 1116px) / 2));
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 16px 12px;
  background: #fff7e5;
  border-radius: 0 0 20px 20px;
  box-shadow: 0 6px 14px #8c623329;
}
.is-docked .home-art-window {
  flex: 0 0 260px;
  width: 260px;
  height: 136.5px;
}
.is-docked .home-entry {
  flex: 1;
  padding: 0;
  margin: 0;
}
body.home-docked .game-header {
  background: #fff8e9;
}
body[data-screen="home"] .theme-card {
  scroll-margin-top: calc(var(--home-dock-bottom, 0px) + 12px);
}
.home-art-window,
.home-key-art,
.home-action,
.home-dock-paper {
  transform-origin: 0 0;
}
.home-hero.is-dock-morphing {
  position: relative;
  z-index: 6;
}
.home-hero.is-docked.is-dock-morphing {
  position: fixed;
}
.home-dock-paper {
  position: absolute;
  z-index: -1;
  pointer-events: none;
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.home-hero:has(.home-dock-paper)::before {
  visibility: hidden;
}
@media (prefers-reduced-motion: reduce) {
  .home-hero {
    transition: none;
  }
}
.home-entry {
  justify-content: center;
  padding: 16px 0 0;
}
.home-action {
  flex: 0 1 460px;
  width: 100%;
  transform-origin: 50% 50%;
}
.home-action .primary {
  position: relative;
  isolation: isolate;
  --blue: #0a81ae;
  --blue-top: #1689b5;
  --blue-deep: #087298;
  --blue-edge: #086084;
  --blue-base: #06485f;
  min-height: 60px;
  font-size: 20px;
  border-bottom-color: #227fa299;
  box-shadow:
    inset 0 0 0 2px #a2e4eb88,
    inset 0 3px 0 #c7f4ef44,
    inset 0 -2px 3px #27487933,
    0 3px 4px #17496966,
    0 10px 14px -5px #18456744;
}
.scroll-shockwave {
  position: absolute;
  inset: 4px;
  z-index: -1;
  border: 1px solid #a5e7f0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
}
.home-action .hero-details {
  margin-top: 12px !important;
  opacity: var(--home-details-opacity, 1);
  /* Scroll controls the fade directly; a timed transition would lag behind
     the cards and keep this copy readable over their illustrations. */
  transition: none;
}
.has-scrolled-details .hero-details,
.is-dock-morphing .hero-details {
  opacity: 0;
  visibility: hidden;
}
.is-docked .hero-details {
  height: 0;
  margin-top: 0 !important;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
}
.is-docked .home-action .primary {
  box-shadow:
    inset 0 0 0 2px #a2e4eb88,
    inset 0 4px 0 #c7f4ef44,
    inset 0 -2px 3px #27487933,
    0 3px 4px #17496966,
    0 14px 20px -6px #18456740,
    0 23px 24px -12px #18456740;
}
@media (prefers-reduced-motion: reduce) {
  .home-action .hero-details {
    transition: none;
  }
}

@media (min-width: 761px) {
  body:not(.playing) .app {
    padding-bottom: 100px;
  }
  body:not(.playing) .bottom-nav {
    position: fixed;
    left: 50%;
    bottom: calc(16px + var(--safe-bottom, env(safe-area-inset-bottom)));
    transform: translateX(-50%);
    width: min(
      550px,
      calc(
        100% - max(32px, var(--safe-left, env(safe-area-inset-left))) -
          max(32px, var(--safe-right, env(safe-area-inset-right)))
      )
    );
    z-index: 10;
    margin: 0;
    box-shadow: 0 8px 30px #29324718;
  }
}

@media (max-width: 760px) {
  .home-cover-slot {
    top: calc(64px + var(--safe-top, env(safe-area-inset-top)));
  }
  /* Keep native scrolling, but do not spend mobile cover width on desktop bars. */
  html {
    scrollbar-width: none;
  }
  html::-webkit-scrollbar {
    display: none;
  }
  body:not(.playing) .app {
    /* Keep the device inset on body; reserve navigation space in the page. */
    padding-bottom: 90px;
  }
  body[data-screen="home"] .app {
    --home-left: max(16px, var(--safe-left, env(safe-area-inset-left)));
    --home-right: max(16px, var(--safe-right, env(safe-area-inset-right)));
    padding-inline: var(--home-left) var(--home-right);
  }
  body[data-screen="home"] .game-header {
    position: sticky;
    z-index: 7;
    height: 64px;
    gap: 8px;
    padding-block: 6px;
  }
  body[data-screen="home"] .top-actions {
    display: flex;
    flex-shrink: 0;
  }
  body[data-screen="home"] #fullscreen {
    display: none;
  }
  body[data-screen="home"] .player-supplies {
    gap: 8px;
  }
  body[data-screen="home"] .coin-pill {
    padding-inline: 12px;
    font-size: 14px;
  }
  body[data-screen="home"] .inventory-summary {
    gap: 8px;
    padding: 4px 9px;
  }
  body[data-screen="home"] .inventory-items {
    gap: 8px;
  }
  .home-art-window {
    width: calc(100% + var(--home-left) + var(--home-right));
    margin-left: calc(-1 * var(--home-left));
    aspect-ratio: 1200 / 770;
    overflow: clip;
  }
  .home-art-window .home-key-art {
    width: 122.2222%;
    max-width: none;
    margin: 0;
    left: -9%;
    border-radius: 0;
  }
  /* Scale both dimensions together and anchor the guide to the cover's base.
     Her books stay visible and the star's wink remains unobstructed. */
  .home-art-window .home-art-guide {
    left: 53%;
    top: 12.97%;
    width: 35.46%;
    height: 87.03%;
  }
  .home-entry {
    position: relative;
    z-index: 6;
    padding: 0;
    margin-top: -12px;
  }
  .home-action {
    flex: auto;
    max-width: none;
  }
  .home-action .hero-details {
    gap: 12px;
    font-size: 10px;
    margin-top: 12px !important;
  }
  .is-docked .home-action .hero-details {
    margin-top: 0 !important;
  }
  .home-hero {
    position: relative;
    isolation: isolate;
    padding-bottom: 14px;
  }
  /* One continuous paper illustration behind the HUD, cutouts and play action.
     Extending only the backdrop preserves the approved foreground registration. */
  .home-hero::before {
    content: "";
    position: absolute;
    z-index: -1;
    pointer-events: none;
    left: calc(-1 * var(--home-left));
    right: calc(-1 * var(--home-right));
    top: calc(-64px - var(--safe-top, env(safe-area-inset-top)));
    bottom: 0;
    background: url("../assets/home/paper-clean-pastel-v2.webp") center / 100%
      100% no-repeat;
    /* Fade the bottom and feather its corners beside the CTA. The upper
       paper stays full bleed; only the lower sides blend into the page. */
    mask-image:
      linear-gradient(
        #000 calc(100% - 144px),
        #000b calc(100% - 110px),
        #0005 calc(100% - 66px),
        transparent calc(100% - 18px)
      ),
      linear-gradient(#000 calc(100% - 200px), transparent calc(100% - 128px)),
      linear-gradient(
        90deg,
        transparent,
        #000 60px,
        #000 calc(100% - 60px),
        transparent
      );
    mask-composite: intersect, add;
  }
  .home-art-window .home-art-paper {
    visibility: hidden;
  }
  body.home-docked .game-header {
    background: none;
  }
  body[data-screen="home"] .game-header::after {
    content: "";
    position: absolute;
    inset: auto 0 0;
    height: 1px;
    pointer-events: none;
    opacity: 0;
    background: linear-gradient(
      90deg,
      #c49b4700,
      #c49b4780 12%,
      #ddbd74 50%,
      #c49b4780 88%,
      #c49b4700
    );
    box-shadow: 0 1px 0 #fff7dc80;
    transition: opacity 180ms ease;
  }
  body.home-docked .game-header::after {
    opacity: 1;
  }
  @media (prefers-reduced-motion: reduce) {
    body[data-screen="home"] .game-header::after {
      transition: none;
    }
  }
  .home-hero.is-docked {
    top: calc(64px + var(--safe-top, env(safe-area-inset-top)));
    left: var(--home-left);
    right: var(--home-right);
    display: block;
    padding: 0 0 28px;
    background: none;
    border-radius: 0;
    box-shadow: none;
  }
  .home-hero.is-docked::before {
    /* Finish the paper behind the button, rather than drawing a hard stripe
       across the theme illustrations. Only the button casts a shadow. */
    bottom: -16px;
    background-image:
      linear-gradient(
        transparent calc(100% - 88px),
        var(--paper) calc(100% - 48px)
      ),
      url("../assets/home/paper-clean-pastel-v2.webp");
    /* Keep a quiet paper gap below play before cards reappear. Feather its
       lower edge and corners so the extra breathing room has no hard seam. */
    mask-image:
      linear-gradient(
        #000 calc(100% - 24px),
        #000c calc(100% - 16px),
        #0005 calc(100% - 8px),
        transparent
      ),
      linear-gradient(#000 calc(100% - 40px), transparent calc(100% - 16px)),
      linear-gradient(
        90deg,
        transparent,
        #000 60px,
        #000 calc(100% - 60px),
        transparent
      );
    border: 0;
    box-shadow: none;
  }
  .is-docked .home-art-window {
    width: calc(100% + var(--home-left) + var(--home-right));
    height: clamp(108px, 38vw, 170px);
    margin-left: calc(-1 * var(--home-left));
    aspect-ratio: auto;
    mask-image: linear-gradient(#000 calc(100% - 8px), transparent);
  }
  .is-docked .home-art-window .home-key-art {
    width: 100%;
    left: 0;
  }
  .is-docked .home-art-slogan {
    opacity: 0;
    visibility: hidden;
  }
  .is-dock-morphing .home-art-slogan {
    visibility: visible;
  }
  .is-docked .home-entry {
    margin-top: -8px;
  }
  .home-themes .theme-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .home-themes .theme-card {
    padding: 15px;
    border-radius: 20px;
  }
  .home-themes .theme-card .theme-symbol {
    float: none;
    width: 40px;
    height: 40px;
    margin: 0 0 10px;
    border-radius: 13px;
  }
  .home-themes .theme-card h3 {
    font-family: var(--body);
    font-weight: 900;
    font-size: 18px;
    line-height: 1.2;
  }
  .home-themes .theme-card p {
    margin: 6px 0 14px;
    font-size: 11px;
  }
  body:not(.playing) .bottom-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    max-width: none;
    margin: 0;
    gap: 4px;
    padding: 8px max(8px, var(--safe-right, env(safe-area-inset-right)))
      calc(8px + var(--safe-bottom, env(safe-area-inset-bottom)))
      max(8px, var(--safe-left, env(safe-area-inset-left)));
    border: 0;
    border-top: 3px solid #fff5bd;
    border-radius: 28px 28px 0 0;
    background: #f7d65c;
    box-shadow:
      0 -3px 0 #b99538,
      0 -8px 24px #725c2320;
  }
  body:not(.playing) .bottom-nav button {
    flex-direction: column;
    gap: 5px;
    min-width: 0;
    min-height: 64px;
    padding: 6px 2px;
    border: 2px solid #fff5b6;
    border-radius: 18px;
    background: #ffe78b;
    color: #334461;
    font-size: 11px;
    box-shadow: 0 2px 0 #d3ac42;
  }
  body:not(.playing) .bottom-nav button.active {
    background: #087eaa;
    border-color: #55c3e2;
    color: #fff;
    box-shadow: 0 2px 0 #057da4;
  }
  body:not(.playing) .bottom-nav .icon {
    width: 25px;
    height: 25px;
  }
}
@media (max-height: 600px) {
  .is-docked .home-art-window {
    height: 90px;
  }
  .is-docked .home-art-window .home-key-art {
    width: 171.43px;
    left: 50%;
    transform: translateX(-50%);
  }
}
@media (max-height: 450px) {
  .is-docked .home-art-window,
  .is-docked .hero-details {
    display: none;
  }
  .home-hero.is-docked {
    padding-top: 4px;
  }
  .is-docked .home-entry {
    margin-top: 0;
  }
}
@media (max-width: 350px) {
  body[data-screen="home"] .inventory-caption {
    display: none;
  }
  body[data-screen="home"] .coin-pill {
    padding-inline: 8px;
    font-size: 12px;
  }
  .home-themes .theme-card {
    padding: 12px;
  }
  .home-themes .theme-card h3 {
    font-size: 16px;
  }
}
