:root {
  color-scheme: light;
  --ink: #203040;
  --muted: #65778a;
  --line: #d8e3ef;
  --blue: #4d96ff;
  --green: #5fd18c;
  --red: #f95f62;
  --paper: #ffffff;
  --tile-min: 112px;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef5fb;
  color: var(--ink);
  overflow-x: hidden;
}

button {
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  min-height: 100dvh;
}

.home {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.home-head {
  padding: calc(clamp(18px, 4vw, 44px) + env(safe-area-inset-top)) clamp(18px, 4vw, 44px) clamp(18px, 4vw, 44px);
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.home-head h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 54px);
  line-height: 1;
}

.home-head p {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 750;
  font-size: clamp(16px, 2vw, 20px);
}

.adult-guide {
  max-width: 920px;
  display: grid;
  gap: 5px;
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fbff;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.adult-guide strong {
  color: var(--ink);
  font-size: 15px;
}

.category-list {
  display: grid;
  gap: clamp(18px, 4vw, 34px);
  padding: clamp(16px, 4vw, 44px);
}

.category-section {
  display: grid;
  gap: 12px;
}

.difficulty-head {
  display: grid;
  gap: 6px;
}

.difficulty-head h2 {
  margin: 0;
  font-size: clamp(20px, 3vw, 30px);
  line-height: 1;
}

.difficulty-head p {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
}

.difficulty-easy .difficulty-head h2 { color: #238653; }
.difficulty-medium .difficulty-head h2 { color: #316ecb; }
.difficulty-hard .difficulty-head h2 { color: #b55319; }

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: clamp(10px, 2vw, 18px);
}

.game-card {
  min-height: clamp(250px, 31vw, 320px);
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(31, 47, 67, .12);
  text-align: left;
  transition: transform .18s ease, box-shadow .18s ease;
}

.game-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 24px 56px rgba(31, 47, 67, .16);
}

.game-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
}

.game-card span {
  padding: 0 4px 4px;
  font-weight: 900;
  font-size: 24px;
  overflow-wrap: anywhere;
}

.game-card small {
  width: max-content;
  max-width: 100%;
  margin: 0 4px 2px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef5fb;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.play {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.play-top {
  display: grid;
  grid-template-columns: auto minmax(0, 92px) auto;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--line);
}

.play-top img {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: 14px;
  box-shadow: 0 10px 22px rgba(31, 47, 67, .14);
}

.icon-button {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
}

.icon-button.next {
  background: var(--blue);
}

.icon-button svg {
  width: 27px;
  height: 27px;
}

.play-main {
  display: grid;
  padding: clamp(14px, 3vw, 28px);
  align-items: center;
}

.choice-layout,
.match-layout {
  display: grid;
  gap: clamp(12px, 2.4vw, 20px);
  align-content: center;
}

.scene-panel {
  width: min(100%, clamp(220px, 34vh, 360px));
  justify-self: center;
  margin: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 18px 42px rgba(31, 47, 67, .13);
}

.scene-panel img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  background: #f7fbff;
  animation: scene-breathe 8s ease-in-out infinite;
}

.parent-hint {
  width: min(100%, 820px);
  justify-self: center;
  margin-top: -4px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .82);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.3;
}

.big-prompt {
  width: min(210px, 48vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  justify-self: center;
  border-radius: 50%;
  background: #fff;
  border: 4px solid #ffe2a0;
  box-shadow: 0 18px 36px rgba(31, 47, 67, .12);
  animation: breathe 2.4s ease-in-out infinite;
}

.big-prompt svg {
  width: 78%;
  height: 78%;
}

.choice-row,
.target-row,
.tray,
.reward-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--tile-min), 1fr));
  gap: clamp(8px, 1.8vw, 14px);
}

.sequence-layout .target-row {
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
}

.target,
.toy-card,
.reward {
  min-height: 128px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fff;
  border: 3px solid var(--line);
  box-shadow: 0 14px 28px rgba(31, 47, 67, .1);
  user-select: none;
  touch-action: none;
}

.target:nth-child(1),
.toy-card:nth-child(1) { background: #fff8db; border-color: #eccb61; }
.target:nth-child(2),
.toy-card:nth-child(2) { background: #eff6ff; border-color: #84b8ff; }
.target:nth-child(3),
.toy-card:nth-child(3) { background: #f0fff6; border-color: #77d79e; }

.toy-card {
  animation: floaty 2.4s ease-in-out infinite;
}

.toy-card:nth-child(2n) { animation-delay: -.75s; }
.toy-card:nth-child(3n) { animation-delay: -1.35s; }

.toy-card svg,
.target svg,
.reward svg {
  width: min(104px, 84%);
  height: min(104px, 84%);
  filter: drop-shadow(0 7px 8px rgba(31, 47, 67, .13));
}

.toy-card svg {
  width: min(136px, 92%);
  height: min(136px, 92%);
}

.target {
  min-height: 150px;
  border-style: dashed;
  animation: target-breathe 2.6s ease-in-out infinite;
}

.target.ready {
  transform: scale(1.04);
  border-color: var(--blue);
}

.target.done {
  background: #effaf3;
  border-color: var(--green);
  border-style: solid;
  animation: pop .34s ease-out;
}

.target.miss,
.toy-card.wrong {
  border-color: var(--red);
  animation: shake .32s linear;
}

.toy-card.right {
  border-color: var(--green);
  background: #effaf3;
  animation: pop .34s ease-out;
}

.dragging {
  opacity: .35;
}

.drag-ghost {
  position: fixed;
  z-index: 50;
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 44px rgba(31, 47, 67, .24);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.drag-ghost svg {
  width: 108px;
  height: 108px;
}

.status {
  min-height: 56px;
  display: grid;
  place-items: center;
  padding: 8px;
  background: #fff;
  border-top: 1px solid var(--line);
  color: var(--blue);
  font-size: 30px;
  font-weight: 950;
}

.celebration {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(239, 246, 252, .76);
  backdrop-filter: blur(10px);
}

.celebration-card {
  width: min(560px, 100%);
  display: grid;
  gap: 14px;
  justify-items: center;
  padding: clamp(16px, 4vw, 28px);
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 28px 80px rgba(31, 47, 67, .22);
}

.celebration-card > img {
  width: min(230px, 58vw);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
}

.stars {
  color: #ff9f45;
  font-size: 30px;
  font-weight: 950;
}

.reward {
  min-height: 92px;
  border-radius: 50%;
  animation: floaty 1.8s ease-in-out infinite;
  position: relative;
  overflow: hidden;
}

.reward.popped {
  opacity: .62;
  transform: scale(.82) rotate(8deg);
  animation: none;
}

.mini-burst {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ff9f45;
  font-size: 42px;
  font-weight: 950;
  animation: burst .72s ease-out forwards;
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  top: -24px;
  left: calc((var(--i) + 1) * 3.5%);
  width: 12px;
  height: 20px;
  border-radius: 4px;
  background: hsl(calc(var(--i) * 47), 86%, 64%);
  animation: confetti 1.9s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.08s);
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes target-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.015); }
}

@keyframes pop {
  0% { transform: scale(.75); }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px) rotate(-2deg); }
  55% { transform: translateX(8px) rotate(2deg); }
  80% { transform: translateX(-4px); }
}

@keyframes confetti {
  0% { transform: translateY(-30px) rotate(0deg); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translateY(110vh) rotate(380deg); opacity: .9; }
}

@keyframes scene-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.025); }
}

@keyframes burst {
  0% { transform: scale(.35) rotate(-18deg); opacity: 0; }
  45% { transform: scale(1.25) rotate(8deg); opacity: 1; }
  100% { transform: scale(1.7) rotate(18deg); opacity: 0; }
}

@media (max-width: 680px) {
  :root {
    --tile-min: 82px;
  }

  .home-head {
    padding: calc(12px + env(safe-area-inset-top)) 12px 14px;
  }

  .home-head h1 {
    font-size: 28px;
  }

  .home-head p {
    margin-top: 8px;
    font-size: 14px;
  }

  .adult-guide {
    margin-top: 12px;
    padding: 10px;
    font-size: 12px;
  }

  .adult-guide strong {
    font-size: 13px;
  }

  .category-list {
    gap: 22px;
    padding: 12px;
  }

  .category-section {
    gap: 10px;
  }

  .difficulty-head h2 {
    font-size: 22px;
  }

  .difficulty-head p {
    font-size: 13px;
  }

  .game-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .game-card {
    min-height: 0;
    gap: 7px;
    padding: 8px;
    box-shadow: 0 10px 24px rgba(31, 47, 67, .1);
  }

  .game-card:hover {
    transform: none;
  }

  .game-card img {
    aspect-ratio: 1;
  }

  .game-card span {
    font-size: 16px;
    line-height: 1.1;
  }

  .game-card small {
    margin: 0 2px;
    padding: 4px 6px;
    font-size: 10.5px;
  }

  .play-top {
    grid-template-columns: auto 56px auto;
    gap: 8px;
    padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  }

  .play-top img {
    width: 56px;
    height: 56px;
    border-radius: 8px;
  }

  .icon-button {
    width: 44px;
    height: 44px;
  }

  .icon-button svg {
    width: 23px;
    height: 23px;
  }

  .play-main {
    padding: 10px;
    align-items: start;
  }

  .choice-layout,
  .match-layout {
    gap: 10px;
  }

  .scene-panel img {
    max-height: none;
  }

  .scene-panel {
    width: min(100%, clamp(220px, 32vh, 300px));
  }

  .parent-hint {
    padding: 7px 8px;
    font-size: 11.5px;
  }

  .big-prompt {
    width: min(130px, 34vw);
    border-width: 3px;
  }

  .choice-row,
  .target-row,
  .tray,
  .reward-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .sequence-layout .target-row {
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  }

  .piece-count-5 .choice-row,
  .piece-count-5 .tray {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sequence-layout.target-count-5 .target-row {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .sequence-layout.target-count-5 .target {
    min-height: 82px;
  }

  .sequence-layout.target-count-5 .target svg {
    width: min(64px, 84%);
    height: min(64px, 84%);
  }

  .target,
  .toy-card,
  .reward {
    min-height: 106px;
    border-width: 2px;
  }

  .target {
    min-height: 96px;
  }

  .toy-card svg,
  .target svg,
  .reward svg {
    width: min(82px, 84%);
    height: min(82px, 84%);
  }

  .toy-card svg {
    width: min(112px, 92%);
    height: min(112px, 92%);
  }

  .drag-ghost {
    width: 112px;
    height: 112px;
  }

  .drag-ghost svg {
    width: 92px;
    height: 92px;
  }

  .status {
    min-height: 42px;
    font-size: 24px;
  }

  .celebration {
    padding: 10px;
  }

  .celebration-card {
    gap: 10px;
    padding: 14px;
  }

  .celebration-card > img {
    width: min(150px, 48vw);
  }

  .stars {
    font-size: 26px;
  }

  .reward {
    min-height: 74px;
  }
}

@media (max-width: 380px) {
  .game-card span {
    font-size: 15px;
  }

  .target,
  .toy-card {
    min-height: 98px;
  }

  .toy-card svg {
    width: min(104px, 92%);
    height: min(104px, 92%);
  }
}

@media (min-width: 681px) and (max-width: 1180px) {
  :root {
    --tile-min: 120px;
  }

  .game-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .game-card {
    min-height: 260px;
  }

  .play-main {
    padding: 18px;
  }

  .scene-panel,
  .parent-hint {
    width: min(100%, 760px);
  }

  .scene-panel {
    width: min(100%, 360px);
  }

  .scene-panel img {
    max-height: none;
  }

  .sequence-layout .target-row {
    grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  }
}

@media (orientation: landscape) and (max-height: 900px) {
  .scene-panel {
    width: min(100%, 220px);
  }
}

@media (orientation: landscape) and (max-height: 760px) {
  .play-main {
    padding: 8px 14px;
  }

  .play-top {
    grid-template-columns: auto minmax(0, 58px) auto;
    gap: 8px;
    padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  }

  .play-top img {
    width: 58px;
    height: 58px;
  }

  .scene-panel img {
    max-height: none;
  }

  .scene-panel {
    width: min(100%, 220px);
  }

  .target,
  .toy-card {
    min-height: 112px;
  }

  .target {
    min-height: 106px;
  }

  .toy-card svg {
    width: min(126px, 92%);
    height: min(126px, 92%);
  }

  .status {
    min-height: 40px;
    padding: 4px;
  }
}

@media (hover: none) {
  .game-card:hover {
    transform: none;
  }
}
