:root {
  --paper: #f7f4ec;
  --paper-dot: #dcd7cb;
  --card: #ffffff;
  --card-border: #e6e0d2;
  --ink: #382c24;
  --ink-muted: #8a7e74;
  --lavender-soft: #e7e5fb;
  --lavender: #847ef2;
  --lavender-deep: #6860dc;
  --butter: #fcf2c5;
  --butter-deep: #efd886;
  --tile-edge: #cfd5ea;
  --tile-shadow: rgba(68, 64, 108, 0.16);
  --danger: #f43f5e;
  --font: "PingFang SC", "Hiragino Sans GB", "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(var(--paper-dot) 1.45px, transparent 1.45px);
  background-size: 20px 20px;
}

/* =========================================================
   RICH ANIMATED STAR-PASSBOOK PASTEL SCENE BACKGROUND
========================================================= */
.scene-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
  background:
    radial-gradient(circle at 16% 12%, rgba(254, 243, 199, 0.72), transparent 38%),
    radial-gradient(circle at 86% 16%, rgba(231, 229, 251, 0.78), transparent 40%),
    radial-gradient(circle at 50% 82%, rgba(252, 231, 243, 0.55), transparent 45%);
}

/* Soft rolling pastel meadow hills at bottom */
.bg-hills {
  position: absolute;
  left: -8%;
  right: -8%;
  bottom: -10px;
  height: 36vh;
  width: 116%;
  opacity: 0.72;
}

/* Drifting marshmallow clouds */
.bg-cloud {
  position: absolute;
  opacity: 0.75;
  animation: cloudDrift 28s linear infinite;
}
.bg-cloud.c1 { top: 7%; left: -12%; width: 96px; animation-duration: 34s; }
.bg-cloud.c2 { top: 15%; right: -10%; width: 76px; animation-duration: 42s; animation-direction: reverse; }

@keyframes cloudDrift {
  0% { transform: translateX(-20px); }
  50% { transform: translateX(46px); }
  100% { transform: translateX(-20px); }
}

/* Cute bouncing / squishing meadow tufts & twinkling stars (like video's jumping grass!) */
.bg-hopper {
  position: absolute;
  transform-origin: bottom center;
  animation: cuteHop 1.9s ease-in-out infinite;
}

.bg-hopper.h-slow { animation-duration: 2.4s; animation-delay: -0.7s; }
.bg-hopper.h-fast { animation-duration: 1.65s; animation-delay: -1.1s; }
.bg-hopper.h-mid  { animation-duration: 2.1s; animation-delay: -0.35s; }

@keyframes cuteHop {
  0%, 100% { transform: translateY(0) scaleX(1.06) scaleY(0.92) rotate(-3deg); }
  45%      { transform: translateY(-7px) scaleX(0.94) scaleY(1.1) rotate(4deg); }
  70%      { transform: translateY(0) scaleX(1.04) scaleY(0.95) rotate(-1deg); }
}

.bg-star {
  position: absolute;
  animation: starTwinkle 2.6s ease-in-out infinite;
}
.bg-star.s2 { animation-delay: -1.2s; animation-duration: 3.1s; }
.bg-star.s3 { animation-delay: -0.6s; animation-duration: 2.2s; }

@keyframes starTwinkle {
  0%, 100% { transform: scale(0.85) rotate(0deg); opacity: 0.55; }
  50%      { transform: scale(1.22) rotate(14deg); opacity: 1; }
}

/* =========================================================
   APP SHELL & TOP HUD
========================================================= */
.app-shell {
  position: relative;
  z-index: 2;
  max-width: 446px;
  height: 100dvh;
  margin: 0 auto;
  padding: 10px 14px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 7px;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.94);
  border: 1.5px solid var(--card-border);
  box-shadow: 0 4px 14px rgba(89, 72, 48, 0.08);
  border-radius: 18px;
  padding: 5px 13px 5px 7px;
}

.brand-icon-box {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: var(--butter);
  display: grid;
  place-items: center;
  font-size: 20px;
}

.brand-title {
  font-size: 15.5px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.15;
}

.brand-sub {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-muted);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  height: 38px;
  min-width: 38px;
  padding: 0 11px;
  border-radius: 14px;
  border: 1.5px solid var(--card-border);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 3px 10px rgba(89, 72, 48, 0.07);
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
}

.icon-btn:active { transform: scale(0.93); }

/* Progress Bar */
.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 1.5px solid var(--card-border);
  border-radius: 18px;
  padding: 8px 13px;
  box-shadow: 0 4px 14px rgba(89, 72, 48, 0.06);
  font-size: 12px;
  font-weight: 700;
}

.stage-badge {
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--lavender-soft);
  color: var(--lavender-deep);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.stage-badge.hell {
  background: #ffe4e8;
  color: #e11d48;
}

.progress-track {
  flex: 1;
  height: 10px;
  background: var(--lavender-soft);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #a6a1f8, #7b74ee);
  border-radius: 99px;
  transition: width 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-pct {
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 800;
}

/* =========================================================
   PLAYABLE 3D STACKED BOARD
========================================================= */
.board-stage {
  position: relative;
  flex: 1;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.board-inner {
  position: relative;
  width: 344px;
  height: 360px;
  transform-origin: center center;
}

.board-inner.swoop-in {
  animation: boardSwoopIn 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes boardSwoopIn {
  from { transform: translateX(120px) scale(0.92); opacity: 0; }
  to   { opacity: 1; }
}

/* Crisp Porcelain-White 3D Tile (NO inner background color!) */
.tile {
  position: absolute;
  width: 49px;
  height: 55px;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8f9ff 100%);
  border: 1.5px solid #dde2f2;
  box-shadow:
    inset 0 2px 0 #ffffff,
    0 5px 0 var(--tile-edge),
    0 9px 16px var(--tile-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  cursor: pointer;
  transition: transform 0.12s cubic-bezier(0.22, 1, 0.36, 1), filter 0.16s ease;
  touch-action: manipulation;
}

.tile-inner {
  width: 100%;
  height: 100%;
  border-radius: 11px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-emoji {
  font-size: 32px;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(45, 42, 72, 0.18));
}

.tile:not(.blocked):hover {
  transform: translateY(-3px) scale(1.05);
}

.tile:not(.blocked):active {
  transform: translateY(2px) scale(0.95);
}

.tile.blocked {
  filter: brightness(0.74) saturate(0.42);
  cursor: not-allowed;
}

.tile.blocked::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: rgba(92, 84, 114, 0.24);
  pointer-events: none;
}

.tile.shake {
  animation: tileShake 0.24s ease;
}

@keyframes tileShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Flying Tile Ghost (Fast Zip from Board into Dock Slot!) */
.flying-tile {
  position: fixed;
  z-index: 95;
  pointer-events: none;
  transform-origin: top left;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8f9ff 100%);
  border: 1.5px solid #dde2f2;
  box-shadow:
    0 6px 0 var(--tile-edge),
    0 16px 28px rgba(68, 64, 108, 0.24);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  will-change: transform, left, top, width, height;
}

/* Pop-out Holding Shelf */
.shelf-area {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.shelf-area .tile {
  position: relative;
  width: 44px;
  height: 48px;
  border-radius: 13px;
  box-shadow: 0 3px 0 var(--tile-edge), 0 6px 12px var(--tile-shadow);
}

.shelf-area .tile-emoji { font-size: 26px; }

/* =========================================================
   SCULPTED BOUTIQUE 3D PASSBOOK / FENCE 7-SLOT DOCK FRAME
========================================================= */
.tray-wrap {
  position: relative;
  margin: 8px 6px 4px;
  padding: 9px 10px 13px;
  border-radius: 22px;
  background: linear-gradient(180deg, #fffdf6 0%, #f7ebd0 52%, #ebd7ac 100%);
  border: 2px solid #d7be8a;
  box-shadow:
    inset 0 2.5px 0 rgba(255, 255, 255, 0.95),
    0 6px 0 #cfb379,
    0 12px 24px rgba(102, 78, 42, 0.2);
  transition: box-shadow 0.2s, border-color 0.2s;
}

/* Left & Right Cute Sculpted Corner Posts with Golden Star Caps */
.tray-post {
  position: absolute;
  top: -11px;
  width: 18px;
  height: calc(100% + 14px);
  border-radius: 9px;
  background: linear-gradient(90deg, #fff8e2 0%, #f1da9e 58%, #d7b875 100%);
  border: 2px solid #cca864;
  box-shadow: 0 4px 10px rgba(102, 78, 42, 0.16);
  display: flex;
  justify-content: center;
  padding-top: 3px;
  font-size: 9px;
  color: #b5842c;
  pointer-events: none;
  z-index: 3;
}
.tray-post.left { left: -7px; }
.tray-post.right { right: -7px; }

/* Decorative Bottom Fence Clasp Rails (echoes classic fence charm in pastel luxury) */
.tray-rail-studs {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 3px;
  height: 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.tray-rail-studs span {
  width: 12px;
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(180deg, #ffffff 0%, #dcc38c 100%);
  border: 1px solid #c5a669;
}

.tray-wrap.danger {
  border-color: #fb7185;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.9),
    0 6px 0 #e11d48,
    0 0 0 5px rgba(244, 63, 94, 0.22);
}

/* Deep Cozy Lavender-Velvet Inner Tray Cavity */
.tray-slots {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  background: linear-gradient(180deg, #dcd7f8 0%, #ebe8fc 100%);
  border: 1.5px solid #cbc4f2;
  border-radius: 15px;
  padding: 6px 6px;
  box-shadow: inset 0 3px 8px rgba(96, 86, 170, 0.2);
}

.tray-slot {
  aspect-ratio: 48 / 54;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.56);
  border: 1.5px dashed rgba(132, 126, 242, 0.34);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.tray-tile {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f8f9ff 100%);
  border: 1.5px solid #dde2f2;
  box-shadow: 0 3px 0 var(--tile-edge), 0 4px 8px rgba(68, 64, 108, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1px;
  transition: transform 0.15s ease;
}

.tray-tile.hidden-in-flight {
  opacity: 0;
}

.tray-tile.just-landed {
  animation: squishLand 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes squishLand {
  0%   { transform: scale(1.16, 0.88); }
  55%  { transform: scale(0.95, 1.06); }
  100% { transform: scale(1, 1); }
}

.tray-tile .tile-emoji { font-size: 26px; }

.tray-tile.matching {
  animation: popClear 0.26s ease forwards;
}

@keyframes popClear {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.28); filter: brightness(1.25); }
  100% { transform: scale(0); opacity: 0; }
}

/* =========================================================
   EXPLODING SPARKLE PARTICLES ON 3-MATCH CLEAR!
========================================================= */
.sparkle-particle {
  position: fixed;
  pointer-events: none;
  z-index: 120;
  font-size: 14px;
  line-height: 1;
  will-change: transform, opacity;
}

/* =========================================================
   3 SQUISHY PASTEL LIFELINE BUTTONS
========================================================= */
.lifelines {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.life-btn {
  position: relative;
  padding: 10px 8px;
  border-radius: 16px;
  border: 1.5px solid #d5d0f8;
  background: linear-gradient(180deg, #ffffff 0%, #efedfd 100%);
  box-shadow: 0 4px 0 #cfcaf4, 0 7px 14px rgba(107, 100, 223, 0.14);
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: transform 0.08s ease;
}

.life-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #cfcaf4;
}

.life-btn:disabled {
  background: #f1efe9;
  border-color: #e4e1d8;
  box-shadow: 0 2px 0 #e4e1d8;
  color: #b4aba2;
  cursor: not-allowed;
}

.life-count {
  position: absolute;
  top: -7px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 99px;
  background: linear-gradient(180deg, #9892f7 0%, #766ee8 100%);
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(107, 100, 223, 0.35);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

/* Footer */
.footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  padding: 2px 4px 0;
}

.sponsor-pill {
  background: rgba(255, 255, 255, 0.88);
  border: 1.5px solid var(--card-border);
  border-radius: 99px;
  padding: 3px 11px;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.sponsor-pill:hover { color: var(--ink); }

/* Floating Combo Pop */
.combo-pop {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  background: linear-gradient(180deg, #9690f7 0%, #746ce7 100%);
  color: #ffffff;
  border: 2.5px solid #ffffff;
  box-shadow: 0 8px 24px rgba(107, 100, 223, 0.38);
  padding: 6px 18px;
  border-radius: 99px;
  font-size: 16px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  z-index: 60;
  transition: all 0.24s ease;
}

.combo-pop.show {
  opacity: 1;
  transform: translate(-50%, -88%) scale(1.06);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(56, 44, 36, 0.42);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
}

.modal-overlay.hidden { display: none; }

.modal-card {
  width: 100%;
  max-width: 375px;
  background: #ffffff;
  border: 1.5px solid var(--card-border);
  box-shadow: 0 24px 60px rgba(56, 44, 36, 0.22);
  border-radius: 26px;
  padding: 24px 20px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: popIn 0.22s ease;
}

@keyframes popIn {
  from { transform: scale(0.93); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-emoji { font-size: 48px; line-height: 1; }
.modal-title { font-size: 20px; font-weight: 800; color: var(--ink); }
.modal-desc { font-size: 13.5px; color: var(--ink-muted); line-height: 1.55; }

.share-preview {
  background: #f7f6fb;
  border: 1.5px solid #e6e4fa;
  border-radius: 16px;
  padding: 12px;
  text-align: left;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--ink);
}

.modal-btn {
  width: 100%;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1.5px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.08s ease;
}

.modal-btn:active { transform: scale(0.97); }
.modal-btn-x { background: #1e1b24; color: #ffffff; }
.modal-btn-primary { background: linear-gradient(180deg, #958ff6 0%, #7c75ee 100%); color: #ffffff; box-shadow: 0 6px 16px rgba(124, 117, 238, 0.3); }
.modal-btn-ghost { background: #f6f4ee; color: var(--ink); border-color: var(--card-border); }

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: var(--ink);
  color: #fffdf8;
  padding: 8px 18px;
  border-radius: 99px;
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(56, 44, 36, 0.25);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  transition: all 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Gentle Autoplay Fallback Pill (only appears if browser blocks autoplay) */
.bgm-hint {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 253, 248, 0.96);
  color: #5e549e;
  border: 1.5px solid #d4cef8;
  box-shadow: 0 8px 20px rgba(124, 117, 238, 0.18);
  padding: 6px 14px;
  border-radius: 99px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  z-index: 80;
  animation: bgmPillFloat 1.8s ease-in-out infinite;
}

.bgm-hint.hidden {
  display: none;
}

@keyframes bgmPillFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-3px); }
}
