/* Element Reading — LANDER (Agent A). Extends tokens.css + base.css; never edits them.
   Premium slot-machine lobby: deep lacquer, gold rims, tasteful glow. Mobile-first. */

/* ============================================================
   ZERO HORIZONTAL OVERFLOW / BLEED
   ------------------------------------------------------------
   base.css sets `body { overflow-x: hidden }`, but that does NOT clip
   position:fixed descendants — and the shared FX (.fx-spark sparkle burst,
   .fx-ghost fly-to-tray clone) are fixed + transform-offset, so a tile tapped
   in the right column paints its gold sparks past the right screen edge
   ("elements go outside the screen slightly"). `overflow-x: clip` on the root
   DOES clip fixed-position paint and — unlike `hidden` — creates no scroll
   container, so the sticky tray keeps working. Guarantees scrollWidth === clientWidth
   at 360 / 390 / 430 and no off-canvas bleed.
   ============================================================ */
html { overflow-x: clip; }
body { overflow-x: clip; }

/* ============================================================
   SPLASH  (covers preload; fades + scales away on Enter)
   ============================================================ */
.splash {
  position: fixed;
  inset: 0;
  z-index: 70;                       /* above mute-btn(60), below fx-ghost(80)/silk-wipe(100) */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  padding: calc(20px + env(safe-area-inset-top)) 22px calc(18px + env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse 90% 55% at 50% 30%, rgba(122,19,19,.34), transparent 70%),
    radial-gradient(ellipse 120% 70% at 50% 8%, rgba(20,11,8,.30), rgba(20,11,8,.92) 72%),
    var(--ink-950);
  text-align: center;
  transition: opacity .55s ease, transform .55s cubic-bezier(.4,0,.2,1);
}
.splash.is-leaving {
  opacity: 0;
  transform: scale(1.08);
  pointer-events: none;
}
.splash__inner {
  position: relative;
  z-index: 2;
  margin: auto 0;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/* decorative hanzi, subtly placed in the corners */
.splash__hanzi {
  position: absolute;
  z-index: 1;
  font-size: clamp(72px, 26vw, 132px);
  line-height: 1;
  color: var(--lacquer-600);
  opacity: .14;
  pointer-events: none;
  user-select: none;
}
.splash__hanzi--a { top: 6%;  left: 4%; }
.splash__hanzi--b { top: 10%; right: 5%; color: var(--gold-700); }
.splash__hanzi--c { bottom: 16%; left: 6%; color: var(--jade-600); }
.splash__hanzi--d { bottom: 11%; right: 5%; }

.splash__logo {
  width: 140px;
  height: 140px;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 26px rgba(245,197,66,.5)) drop-shadow(0 8px 20px rgba(0,0,0,.6));
  animation: splashLogo 9s ease-in-out infinite;
}
@keyframes splashLogo {
  0%, 100% { transform: rotate(-4deg) scale(1);    filter: drop-shadow(0 0 22px rgba(245,197,66,.4)) drop-shadow(0 8px 20px rgba(0,0,0,.6)); }
  50%      { transform: rotate(4deg)  scale(1.04); filter: drop-shadow(0 0 34px rgba(245,197,66,.62)) drop-shadow(0 8px 20px rgba(0,0,0,.6)); }
}

.splash__kicker {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--gold-400);
  margin-bottom: 12px;
  text-shadow: 0 0 14px rgba(245,197,66,.4);
}
.splash__title {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(34px, 11vw, 56px);
  line-height: 1.05;
  margin-bottom: 16px;
}
.splash__sub {
  font-size: 16px;
  line-height: 1.62;
  color: rgba(255,246,229,.86);
  max-width: 30ch;
  margin: 0 auto 30px;
}
.splash__enter {
  font-size: 19px;
  padding: 16px 38px;
  min-height: 58px;
}
/* small reassurance line directly under the Enter button */
.splash__enter-sub {
  margin-top: 11px;
  font-family: var(--font-display);
  font-size: 12.5px;
  letter-spacing: .16em;
  color: rgba(245,197,66,.78);
  text-shadow: 0 0 12px rgba(245,197,66,.3);
}
.splash__legal {
  margin-top: 20px;
  font-size: 11.5px;
  letter-spacing: .04em;
}
.splash__foot {
  position: relative;
  z-index: 2;
  padding-top: 14px;
  line-height: 1.9;
}

/* ============================================================
   GAME SCREEN
   ============================================================ */
.game {
  /* .stage already: max-width 520px, centered, flex column, padding */
  gap: 0;
}
.game[hidden] { display: none; }

/* --- Master Shen header: portrait + stacked chat log (ERChat) --- */
.game__head {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 16px;
}
.game__head .shen-pic {
  width: 72px;
  flex: 0 0 auto;
  align-self: flex-end;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.6));
}
/* compact chat column: bubbles stack + persist; internal scroll keeps the
   grid primary; newest bubble auto-scrolls into view (ERChat.scrollLatest). */
.game__chat {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 38vh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 2px 4px 2px 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(245,197,66,.5) transparent;
}
.game__chat::-webkit-scrollbar { width: 5px; }
.game__chat::-webkit-scrollbar-thumb {
  background: rgba(245,197,66,.45);
  border-radius: 999px;
}
/* the mounted .chat-log: tighten gaps + bubble scale for the lander's compact rail */
.game__chat .chat-log { gap: 9px; padding-bottom: 2px; }
.game__chat .chat-b {
  max-width: 100%;
  font-size: 15px;
  line-height: 1.5;
  padding: 11px 14px;
}
.game__chat .chat-b__name { font-size: 10.5px; margin-bottom: 3px; }

/* --- Tray (sticky, above grid) --- */
.tray {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 6px);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background:
    linear-gradient(180deg, rgba(60,33,20,.96), rgba(28,15,10,.97));
  border: 1px solid rgba(245,197,66,.5);
  box-shadow:
    0 8px 22px rgba(0,0,0,.5),
    inset 0 1px 0 rgba(255,233,168,.22),
    inset 0 -10px 18px rgba(0,0,0,.45);
  overflow: hidden;
}
/* slow shimmer sweep across the tray */
.tray::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(100deg, transparent 38%, rgba(255,233,168,.16) 50%, transparent 62%);
  background-size: 260% 100%;
  background-position: 130% 0;
  pointer-events: none;
  animation: trayShimmer 5.5s ease-in-out infinite;
}
@keyframes trayShimmer {
  0%, 72%, 100% { background-position: 130% 0; }
  92%           { background-position: -30% 0; }
}
.tray__slots {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
}
.slot {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 38%, rgba(20,11,8,.5), rgba(20,11,8,.85));
  border: 1px solid rgba(245,197,66,.28);
  box-shadow: inset 0 2px 5px rgba(0,0,0,.55);
}
.slot__mark {
  font-size: 10px;
  color: rgba(245,197,66,.32);
  line-height: 1;
}
.slot.is-filled {
  border-color: rgba(245,197,66,.7);
  background: radial-gradient(circle at 50% 35%, rgba(122,19,19,.55), rgba(20,11,8,.9));
  box-shadow: inset 0 1px 3px rgba(0,0,0,.5), 0 0 8px rgba(245,197,66,.35);
}
.slot.is-filled .slot__mark { display: none; }
.slot__icon {
  width: 86%;
  height: 86%;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.6));
  animation: slotPop .42s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes slotPop {
  0%   { transform: scale(0)   rotate(-25deg); opacity: 0; }
  60%  { transform: scale(1.18) rotate(6deg);  opacity: 1; }
  100% { transform: scale(1)   rotate(0);      opacity: 1; }
}

.tray__meta {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  max-width: 42%;
}
.tray__count {
  padding: 7px 12px;
  font-size: 13.5px;
  white-space: nowrap;
}
.tray__count.is-hidden { display: none; }
.tray__empty {
  font-size: 12px;
  line-height: 1.3;
  text-align: right;
}
.tray__empty.is-hidden { display: none; }

/* --- Grid of 40 tiles --- */
.grid {
  display: grid;
  /* minmax(0,1fr): plain 1fr keeps an implied auto (min-content) minimum, so a long
     nowrap label can widen its column past the viewport on iOS font metrics */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  transition: opacity .5s ease;
}
@media (min-width: 431px) {
  .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
.grid.is-dimmed {
  opacity: .6;
  pointer-events: none;
}

.tile {
  position: relative;
  min-width: 0; /* lets the label ellipsis engage instead of widening the grid track */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 5px 7px;
  min-height: 0;
  aspect-ratio: 1 / 1.16;
  border: 0;
  border-radius: var(--radius);
  background:
    radial-gradient(ellipse 80% 55% at 50% 18%, rgba(122,19,19,.45), transparent 60%),
    linear-gradient(180deg, #3a1d12 0%, #240f0a 70%, #1a0a07 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,233,168,.16),
    inset 0 0 0 1px rgba(245,197,66,.42),
    0 4px 12px rgba(0,0,0,.5);
  color: var(--cream);
  -webkit-tap-highlight-color: transparent;
  will-change: transform, opacity;
  /* idle float baseline; per-tile delay set inline in JS */
  animation: tileFloat 3.4s ease-in-out infinite alternate;
  transition: transform .34s cubic-bezier(.4,0,.2,1), opacity .34s ease, box-shadow .2s ease;
}
@keyframes tileFloat {
  from { transform: translateY(-3px); }
  to   { transform: translateY(3px); }
}
.tile:active {
  box-shadow:
    inset 0 1px 0 rgba(255,233,168,.2),
    inset 0 0 0 1px rgba(245,197,66,.85),
    0 0 16px rgba(245,197,66,.45);
}
.tile__icon {
  width: 72%;
  max-width: 70px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,.55));
}
.tile__label {
  font-size: 11px;
  line-height: 1.1;
  font-weight: 700;
  color: rgba(255,246,229,.92);
  letter-spacing: .01em;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
/* collected: scale + fade out before removal (grid auto-reflows) */
.tile.is-collected {
  transform: scale(0) translateY(0);
  opacity: 0;
  animation: none;
  pointer-events: none;
}

.grid__hint {
  text-align: center;
  margin-top: 14px;
  font-size: 12.5px;
  letter-spacing: .02em;
}

/* ============================================================
   STICKY CTA  (appears at 7 picks; never covers last grid row —
   .game gets bottom padding from JS when shown)
   ============================================================ */
.cta-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(20,11,8,0), rgba(20,11,8,.82) 32%, rgba(20,11,8,.97));
  pointer-events: none;                /* container ignores; button catches */
  transform: translateY(120%);
  opacity: 0;
  transition: transform .45s cubic-bezier(.34,1.3,.64,1), opacity .4s ease;
}
.cta-bar.is-shown {
  transform: translateY(0);
  opacity: 1;
}
.cta-btn {
  pointer-events: auto;
  width: 100%;
  max-width: 488px;
  font-size: 17px;
  letter-spacing: .02em;
}
/* extra glow once the pattern is complete (12 picks) */
.cta-bar.is-urgent .cta-btn {
  animation: ctaUrgent 1.4s ease-in-out infinite;
}
@keyframes ctaUrgent {
  0%, 100% { box-shadow: 0 6px 18px rgba(0,0,0,.5), 0 0 0 0 rgba(245,197,66,.6), inset 0 2px 2px rgba(255,255,255,.55); transform: scale(1); }
  50%      { box-shadow: 0 8px 26px rgba(0,0,0,.55), 0 0 34px 10px rgba(245,197,66,.5), inset 0 2px 2px rgba(255,255,255,.55); transform: scale(1.02); }
}

/* ============================================================
   AUDIO ATTENTION CUE
   ------------------------------------------------------------
   After the game reveals, if sound is on, the mute button pulses
   twice so seekers notice audio exists. (.mute-btn lives in base.css.)
   ============================================================ */
.mute-btn.mute-pulse {
  animation: mutePulse 1s ease-in-out 2;
}
@keyframes mutePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(245,197,66,0);
    transform: scale(1);
  }
  45% {
    box-shadow: 0 0 18px 5px rgba(245,197,66,.6), 0 0 0 2px rgba(245,197,66,.5) inset;
    transform: scale(1.14);
  }
}

/* ============================================================
   REDUCED MOTION  (base.css neutralises animations globally;
   these keep the static states clean / legible)
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .splash__logo { animation: none; }
  .tile { animation: none; transform: none; }
  .splash.is-leaving { transform: none; }
  .cta-bar { transition: opacity .2s ease; transform: none; }
  .cta-bar:not(.is-shown) { display: none; }
}

/* narrow phones: tighten so 4 cols + labels never clip at 360px */
@media (max-width: 374px) {
  .grid { gap: 8px; }
  .tile { padding: 7px 4px 6px; }
  .tile__label { font-size: 10.5px; }
  .tray__slots { gap: 4px; }
  .game__head { gap: 8px; }
  .game__head .shen-pic { width: 64px; }
  .game__chat .chat-b { font-size: 14.5px; padding: 10px 13px; }
}
