/* Drag-to-place puzzle interaction styles */
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain; }
body { padding-bottom: env(safe-area-inset-bottom); }
body.is-dragging-puzzle { user-select: none; -webkit-user-select: none; touch-action: none; }
button { -webkit-tap-highlight-color: transparent; }
.game-buttons button, .photo-card button, .upload-button { min-height: 48px; }
.play-area.game-only { grid-template-columns: 1fr; width: min(760px, calc(100% - 40px)); }
.play-area.game-only .game-panel { width: 100%; }
.play-area.upload-only { grid-template-columns: 1fr; width: min(600px, calc(100% - 40px)); }
.play-area.upload-only .upload-panel { border-right: 0; }
.header-actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.change-photo-button, .move-count { width: auto; height: 54px; min-height: 54px; min-width: 74px; box-sizing: border-box; border: 2px solid var(--ink); border-radius: 15px; box-shadow: 3px 3px 0 var(--ink); }
.change-photo-button { display: grid; place-items: center; padding: 0 14px; background: #fff2bd; font-size: 12px; font-weight: 900; cursor: pointer; }
.move-count { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 10px; background: #e8dcff; text-align: center; }
.move-count b { display: block; font-size: 20px; line-height: 1; }
.move-count small { display: block; margin-top: 4px; font-size: 9px; line-height: 1; }
.change-photo-button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.celebration { position: fixed; top: calc(env(safe-area-inset-top) + 14px); left: 50%; inset-inline-end: auto; bottom: auto; z-index: 10000; display: flex; grid-template-columns: none; align-items: center; gap: 6px; max-width: calc(100vw - 24px); padding: 11px 16px; border: 2px solid var(--ink); border-radius: 16px; background: #fff; box-shadow: 5px 5px 0 var(--pink); white-space: nowrap; pointer-events: none; transform: translateX(-50%); animation: toast-in .3s ease; }
.celebration strong { font-size: 16px; color: var(--pink); }
.celebration span { font-size: 15px; color: var(--yellow); text-shadow: 1px 1px 0 var(--ink); }
.celebration small { display: inline; margin-left: 2px; font-size: 12px; color: #59667b; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -18px) scale(.92); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
.puzzle-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0 !important;
  column-gap: 0 !important;
  row-gap: 0 !important;
  padding: 0;
  background: var(--purple);
  border: 8px solid var(--purple);
  border-radius: 20px;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  box-shadow: 0 0 0 3px var(--ink);
}

.board-slot {
  position: relative;
  display: grid;
  place-items: center;
  background: #f4efff;
  border: 2px dashed #b7a8da;
  border-radius: 6px;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  transition: background .15s, transform .15s;
}

.board-slot > span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  color: #9d8cc5;
  font-weight: 900;
  font-size: 13px;
}

.board-slot img { width: 100%; height: 100%; min-width: 0; min-height: 0; display: block; object-fit: cover; }
.board-slot.is-filled { border: 0 !important; outline: 0 !important; border-radius: 0 !important; margin: 0 !important; }
.board-slot.is-filled img { width: calc(100% + 2px); height: calc(100% + 2px); margin: -1px; max-width: none; }
.board-slot.is-hovered { background: #fff4b8; transform: scale(.95); outline: 5px solid var(--yellow); outline-offset: -5px; }
.board-slot.just-placed { animation: snap-in .3s ease; }
.tray-label { text-align: center; margin: 18px 0 10px; color: #72798b; font-size: 12px; font-weight: 900; }

.tile-tray {
  min-height: 112px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 9px;
  align-content: center;
  padding: 12px;
  background: #eaf8fb;
  border: 2px dashed #75b8c7;
  border-radius: 16px;
}

.tray-tile, .floating-tile {
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  aspect-ratio: 1;
  box-shadow: 3px 3px 0 var(--ink);
  touch-action: none;
  cursor: grab;
}

.tray-tile img, .floating-tile img { width: 100%; height: 100%; display: block; object-fit: cover; pointer-events: none; }
.tray-tile { position: relative; }
.tile-number { position: absolute; top: 5px; left: 5px; display: grid; place-items: center; width: 22px; height: 22px; border: 2px solid var(--ink); border-radius: 50%; background: var(--yellow); font-size: 11px; font-weight: 900; pointer-events: none; }
.tray-tile:active { cursor: grabbing; }
.tray-tile.is-dragging { opacity: .22; }
.tray-tile.is-wrong { animation: nope .4s ease; }
.floating-tile { position: fixed; z-index: 9999; pointer-events: none; opacity: .94; transform: rotate(4deg) scale(1.08); box-shadow: 10px 12px 20px #2530474d; }
.picture-hint { z-index: 20; }

@keyframes snap-in { 0% { transform: scale(.6) rotate(-8deg); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes nope { 20% { transform: translateX(-7px) rotate(-4deg); } 40% { transform: translateX(7px) rotate(4deg); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }

@media (max-width: 1024px) {
  .topbar, .hero, .play-area, footer { width: min(760px, calc(100% - 40px)); }
  .play-area { grid-template-columns: 1fr; box-shadow: 7px 7px 0 var(--ink); }
  .upload-panel { min-height: auto; border-right: 0; border-bottom: 3px solid var(--ink); }
  .photo-card { max-width: 340px; margin: 22px auto 4px; }
  .upload-button { min-height: 330px; }
  .game-content { width: min(100%, 620px); margin: 0 auto; }
  .game-header { width: min(100%, 620px); margin-left: auto; margin-right: auto; }
}

@media (orientation: landscape) and (max-height: 700px) and (max-width: 1024px) {
  .hero { padding-top: 30px; padding-bottom: 58px; }
  .hero h1 { font-size: 52px; }
  .upload-button { min-height: 250px; }
  .photo-card { max-width: 280px; }
}

@media (max-width: 600px) {
  .topbar, .hero, .play-area, footer { width: calc(100% - 22px); }
  .topbar { padding-top: env(safe-area-inset-top); min-height: calc(56px + env(safe-area-inset-top)); }
  .brand { font-size: 17px; }
  .brand-mark { width: 27px; height: 27px; }
  .hero { padding: 18px 0 42px; }
  .eyebrow { padding: 6px 12px; font-size: 10px; box-shadow: 2px 2px 0 var(--ink); }
  .hero h1 { margin: 12px auto 10px; font-size: clamp(36px, 10.8vw, 48px); line-height: 1.03; }
  .hero h1 span { text-shadow: 2px 2px 0 #fff, 3px 3px 0 var(--ink); }
  .hero p { font-size: 12px; line-height: 1.55; padding: 0 12px; }
  .doodles { display: none; }
  .play-area { margin-top: -18px; margin-bottom: 42px; border-radius: 21px; }
  .upload-panel, .game-panel { padding: 14px 12px; }
  .upload-button { min-height: 230px; }
  .sun-icon { width: 68px; height: 68px; font-size: 38px; margin-bottom: 8px; box-shadow: 4px 4px 0 var(--ink); }
  .upload-button strong { font-size: 21px; }
  .game-header h2 { font-size: 20px; }
  .move-count { min-width: 64px; }
  .play-area.game-only { width: calc(100% - 26px); }
  .play-area.upload-only { width: calc(100% - 26px); }
  .header-actions { gap: 7px; }
  .change-photo-button { padding: 7px 10px; }
  .change-photo-button, .move-count { height: 48px; min-height: 48px; border-radius: 13px; }
  .puzzle-board { gap: 0; border-width: 6px; border-radius: 15px; }
  .tile-number { width: 24px; height: 24px; top: 4px; left: 4px; font-size: 12px; }
  .grownup-tip { width: calc(100% - 26px); padding: 20px; }
  footer { padding-bottom: env(safe-area-inset-bottom); }

  body.has-game .hero { display: none; }
  body.has-game .topbar { min-height: calc(50px + env(safe-area-inset-top)); }
  body.has-game .play-area { margin-top: 10px; }
  body.has-game .game-panel { padding: 12px; }
  body.has-game .game-header { margin-bottom: 10px; }
  body.has-game .game-header h2 { font-size: 17px; margin-top: 4px; }
  body.has-game .panel-label { font-size: 9px; }
  body.has-game .puzzle-wrap { width: min(100%, 350px, calc(100dvh - 410px)); min-width: 230px; margin: 0 auto; }
  body.has-game .tray-label { margin: 10px 0 6px; }
  body.has-game .tile-tray { grid-template-columns: repeat(4, 1fr); gap: 7px; padding: 7px; min-height: 0; }
  body.has-game .tile-number { width: 28px; height: 28px; font-size: 14px; }
  body.has-game .game-buttons { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
  body.has-game .game-buttons button { min-height: 44px; padding: 10px 8px; }
}

@media (max-width: 480px) {
  .puzzle-board { gap: 0; border-width: 6px; }
  .tile-tray { grid-template-columns: repeat(5, 1fr); gap: 6px; padding: 8px; min-height: 92px; }
  .tray-tile { border-width: 1.5px; border-radius: 7px; box-shadow: 2px 2px 0 var(--ink); }
}

@media (max-width: 420px) {
  .tile-tray { grid-template-columns: repeat(3, 1fr); gap: 9px; }
  .tray-tile { min-width: 64px; }
  .game-buttons { grid-template-columns: 1fr; }
  body.has-game .tile-tray { grid-template-columns: repeat(4, 1fr); gap: 7px; }
  body.has-game .tray-tile { min-width: 0; }
  body.has-game .game-buttons { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) and (max-height: 720px) {
  body:not(.has-game) .hero p { display: none; }
  body:not(.has-game) .hero { padding-bottom: 34px; }
  body.has-game .puzzle-wrap { width: min(100%, 320px, calc(100dvh - 420px)); }
  body.has-game .change-photo-button { height: 44px; min-height: 44px; }
  body.has-game .move-count { height: 44px; min-height: 44px; padding: 3px 7px; }
  body.has-game .move-count b { font-size: 19px; }
}

/* iPad and desktop: board on the left, pieces and controls on the right. */
@media (min-width: 768px) {
  .play-area.upload-only { width: min(760px, calc(100% - 40px)); margin-bottom: 48px; }
  .play-area.upload-only .upload-panel { min-height: 0; padding: 22px 24px 24px; border-right: 0; border-bottom: 0; }
  .play-area.upload-only .upload-button { min-height: 280px; }
  body.has-game main { min-height: 100dvh; }
  body.has-game .hero,
  body.has-game .grownup-tip,
  body.has-game footer,
  body.has-game .cloud { display: none; }
  body.has-game .topbar { min-height: 62px; width: min(1120px, calc(100% - 40px)); }
  .play-area.game-only { width: min(1120px, calc(100% - 40px)); }
  body.has-game .play-area.game-only { margin: 14px auto 0; }
  .play-area.game-only .game-panel { padding: 18px 22px 20px; }
  .play-area.game-only .game-header { width: 100%; max-width: none; margin-bottom: 14px; }
  .play-area.game-only .game-content {
    width: 100%;
    max-width: none;
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(240px, .75fr);
    grid-template-areas:
      "board label"
      "board tray"
      "board buttons";
    column-gap: 28px;
    align-items: start;
  }
  .play-area.game-only .puzzle-wrap { grid-area: board; width: min(100%, 600px, calc(100dvh - 215px)); min-width: 0; margin: 0; justify-self: center; }
  .play-area.game-only .tray-label { grid-area: label; margin: 2px 0 12px; text-align: left; }
  .play-area.game-only .tile-tray { grid-area: tray; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 10px; }
  .play-area.game-only .game-buttons { grid-area: buttons; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
}

@media (min-width: 768px) and (max-height: 700px) {
  .play-area.upload-only .upload-button { min-height: 230px; }
  body.has-game .topbar { min-height: 54px; }
  body.has-game .play-area.game-only { margin-top: 10px; }
  .play-area.game-only .game-panel { padding: 14px 18px 16px; }
  .play-area.game-only .game-header { margin-bottom: 10px; }
  .play-area.game-only .puzzle-wrap { width: min(100%, 520px, calc(100dvh - 195px)); }
  .play-area.game-only .tile-tray { grid-template-columns: repeat(5, 1fr); gap: 7px; padding: 8px; }
  .play-area.game-only .game-buttons { margin-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .board-slot, .tray-tile, .floating-tile { transition: none; animation: none; }
}

/* 轻快动效：不改变拼图尺寸与拖动定位 */
.brand-mark i { animation: kid-mark-bob 2.8s ease-in-out infinite; }
.brand-mark i:nth-child(2) { animation-delay: -.45s; }
.brand-mark i:nth-child(3) { animation-delay: -.9s; }
.brand-mark i:nth-child(4) { animation-delay: -1.35s; }
.hero .eyebrow { animation: kid-enter .55s ease-out both; }
.hero h1 { animation: kid-enter .65s .08s ease-out both; }
.hero p { animation: kid-enter .65s .16s ease-out both; }
.play-area { animation: kid-card-in .7s .18s cubic-bezier(.2,.8,.2,1) both; }
.doodles b { animation: kid-float 2.7s ease-in-out infinite; }
.doodles b:nth-child(2) { animation-delay: -.9s; }
.doodles b:nth-child(3) { animation-delay: -1.6s; }
.sun-icon { animation: kid-sun 3.2s ease-in-out infinite; }
.upload-button, .change-photo-button, .game-buttons button, .mode-switch a { transition: transform .16s ease, box-shadow .16s ease, filter .16s ease; }
.upload-button:hover, .change-photo-button:hover, .game-buttons button:hover, .mode-switch a:hover { filter: brightness(1.03); transform: translateY(-2px); }
.upload-button:active, .change-photo-button:active, .game-buttons button:active, .mode-switch a:active { transform: translate(2px, 2px) scale(.98); box-shadow: 1px 1px 0 var(--ink); }
.empty-grid i { animation: kid-soft-pulse 2.4s ease-in-out infinite; }
.empty-grid i:nth-child(2n) { animation-delay: -.7s; }
.empty-grid i:nth-child(3n) { animation-delay: -1.4s; }

@keyframes kid-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes kid-card-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes kid-float {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-9px) rotate(5deg); }
}
@keyframes kid-mark-bob {
  0%, 70%, 100% { transform: translateY(0); }
  82% { transform: translateY(-3px); }
}
@keyframes kid-sun {
  0%, 100% { transform: rotate(-4deg) scale(1); }
  50% { transform: rotate(5deg) scale(1.05); }
}
@keyframes kid-soft-pulse {
  0%, 100% { opacity: .72; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .brand-mark i, .hero .eyebrow, .hero h1, .hero p, .play-area, .doodles b, .sun-icon, .empty-grid i {
    animation: none !important;
  }
  .upload-button, .change-photo-button, .game-buttons button, .mode-switch a {
    transition: none !important;
  }
}
