:root {
  --sky: #8ADCF3;
  --sky2: #98CFF1;
  --action: #92DF43;
  --action-dark: #4F9F39;
  --warm: #F5B83A;
  --cool: #58D3BF;
  --ink: #503D32;
  --cream: #FFF7DC;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", Arial, sans-serif;
  color: var(--ink);
  background: #203845;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #203845; }
button { font: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
#app { position: relative; width: 100%; height: 100%; max-width: 620px; margin: 0 auto; overflow: hidden; background: var(--sky); isolation: isolate; }
.screen { position: absolute; inset: 0; visibility: hidden; opacity: 0; pointer-events: none; transition: opacity .22s ease; }
.screen.active { visibility: visible; opacity: 1; pointer-events: auto; }

#home-screen { background-position: center; background-size: cover; }
.home-haze { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(138,220,243,.12), rgba(255,247,220,.12) 52%, rgba(80,61,50,.13)); }
.home-panel { position: absolute; top: max(6.2%, calc(env(safe-area-inset-top) + 22px)); left: 6%; right: 6%; bottom: max(5.5%, calc(env(safe-area-inset-bottom) + 18px)); display: flex; flex-direction: column; align-items: center; padding: 5% 6% 3.5%; border: 5px solid white; border-radius: 34px; background: linear-gradient(180deg, rgba(255,247,220,.94), rgba(255,240,224,.91)); box-shadow: 0 13px 0 rgba(80,61,50,.30), inset 0 0 0 3px rgba(245,184,58,.18); }
.eyebrow { display: inline-block; padding: 7px 18px; color: white; border: 3px solid white; border-radius: 999px; background: var(--cool); box-shadow: 0 4px 0 #389587; font-size: clamp(10px, 2.6vw, 14px); font-weight: 1000; letter-spacing: .17em; }
h1 { margin: 13px 0 2px; text-align: center; line-height: .82; letter-spacing: -.06em; filter: drop-shadow(0 5px 0 white); }
h1 span, h1 strong { display: block; }
h1 span { color: var(--ink); font-size: clamp(42px, 12vw, 72px); }
h1 strong { color: #eb7594; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; font-size: clamp(43px, 12.5vw, 76px); }
.home-panel > p { margin: 12px 0 4px; max-width: 360px; text-align: center; font-size: clamp(14px, 3.7vw, 20px); font-weight: 800; }
.hero-stage { position: relative; flex: 1 1 auto; width: 100%; min-height: 200px; display: grid; place-items: center; pointer-events: none; }
.hero-stage::before { content: ""; position: absolute; width: min(64vw, 310px); aspect-ratio: 1; border: 10px solid rgba(255,255,255,.94); border-radius: 50%; background: radial-gradient(circle at 38% 30%, white 0 10%, var(--sky) 11% 58%, var(--sky2) 59%); box-shadow: 0 9px 0 rgba(80,61,50,.22); }
.hero-stage img { position: absolute; z-index: 2; filter: drop-shadow(0 8px 3px rgba(80,61,50,.25)); }
#hero-main { width: min(54vw, 260px); animation: hero-bob 2.4s ease-in-out infinite; }
#hero-left { width: min(24vw, 122px); left: 1%; bottom: 4%; transform: rotate(-7deg); }
#hero-right { width: min(25vw, 126px); right: 0; bottom: 3%; transform: rotate(6deg); }
@keyframes hero-bob { 0%,100% { transform: translateY(5px) rotate(-2deg); } 50% { transform: translateY(-9px) rotate(2deg); } }
.burst { position: absolute; z-index: 3; color: var(--warm); font-style: normal; font-size: clamp(22px, 7vw, 38px); -webkit-text-stroke: 2px white; animation: twinkle 1.4s ease-in-out infinite alternate; }
.burst-a { left: 13%; top: 13%; }.burst-b { right: 10%; top: 10%; animation-delay: -.5s; }.burst-c { right: 8%; bottom: 25%; animation-delay: -.9s; }
@keyframes twinkle { to { transform: rotate(18deg) scale(1.25); } }
.primary-button { width: min(90%, 390px); min-height: 58px; padding: 12px 20px; border: 4px solid white; border-radius: 22px; color: var(--ink); background: linear-gradient(#b6f26a, var(--action)); box-shadow: 0 8px 0 var(--action-dark), 0 12px 18px rgba(80,61,50,.20); font-size: clamp(18px, 5vw, 27px); font-weight: 1000; }
.primary-button:active { transform: translateY(5px); box-shadow: 0 3px 0 var(--action-dark); }
.text-button { border: 0; padding: 14px 18px 7px; color: var(--ink); background: transparent; font-size: clamp(13px, 3.3vw, 17px); font-weight: 900; text-decoration: underline; text-underline-offset: 4px; }
.continue-line { margin-top: auto; color: #7e6b5e; font-size: clamp(11px, 2.8vw, 14px); font-weight: 900; letter-spacing: .1em; }
.continue-line b { color: #e65f84; }
.sound-button { display: grid; place-items: center; border: 4px solid white; color: white; background: var(--ink); box-shadow: 0 6px 0 rgba(80,61,50,.38); }
.sound-button span { position: relative; font-size: 27px; line-height: 1; }
.sound-button.sound-off span { opacity: .38; }
.sound-button.sound-off span::after { content: "×"; position: absolute; left: 2px; top: -5px; color: #ff6c82; font-size: 30px; opacity: 1; }
.home-sound { position: absolute; z-index: 8; top: max(5.5%, calc(env(safe-area-inset-top) + 15px)); right: 4.5%; width: 55px; height: 55px; border-radius: 18px; }

#game-field { position: absolute; inset: 0; overflow: hidden; background-position: center; background-size: cover; }
#game-field::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255,255,255,.18), transparent 52%, rgba(88,211,191,.12)); pointer-events: none; }
.hud { position: absolute; z-index: 30; top: max(5.2%, calc(env(safe-area-inset-top) + 10px)); left: 3%; right: 3%; height: 58px; display: grid; grid-template-columns: 56px 1fr 1.25fr 56px; gap: 7px; }
.round-button { width: 56px; height: 56px; border-radius: 19px; font-size: 27px; }
.hud-pill { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; border: 4px solid white; border-radius: 19px; background: rgba(255,247,220,.95); box-shadow: 0 6px 0 rgba(80,61,50,.24); }
.hud-pill small { color: #806c5e; font-size: clamp(9px, 2.2vw, 12px); font-weight: 900; letter-spacing: .14em; }
.hud-pill strong { color: #e65f84; font-size: clamp(21px, 5.2vw, 28px); line-height: 1; }
.timer-pill strong { color: var(--ink); }
.timer-pill.danger { animation: danger-pulse .55s ease-in-out infinite alternate; }
@keyframes danger-pulse { to { background: #ffd7d2; transform: scale(1.03); } }

.goal-strip { position: absolute; z-index: 25; top: max(13.5%, calc(env(safe-area-inset-top) + 77px)); left: 5%; right: 5%; height: 55px; display: grid; grid-template-columns: 44px auto 1fr auto; align-items: center; gap: 7px; padding: 5px 9px; border: 3px solid white; border-radius: 19px; color: white; background: rgba(80,61,50,.91); box-shadow: 0 5px 0 rgba(80,61,50,.27); }
.goal-pig { width: 42px; height: 42px; display: grid; place-items: center; border: 3px solid white; border-radius: 50%; background: #ffd5d8; overflow: hidden; }
.goal-pig img { width: 48px; max-height: 43px; object-fit: contain; }
.goal-strip small { display: block; font-size: clamp(7px, 1.9vw, 10px); font-weight: 900; letter-spacing: .1em; white-space: nowrap; }
.goal-strip strong { color: var(--warm); font-size: clamp(16px, 4vw, 21px); }
.goal-strip > b { font-size: clamp(8px, 2.2vw, 11px); white-space: nowrap; }
.progress-track { height: 9px; min-width: 30px; border: 2px solid rgba(255,255,255,.72); border-radius: 999px; background: rgba(255,255,255,.25); overflow: hidden; }
.progress-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--action); transition: width .3s ease; }

#pile-board { position: absolute; z-index: 5; top: 22%; left: 4%; right: 4%; height: 46%; overflow: visible; border: 4px solid rgba(255,255,255,.84); border-radius: 30px; background: radial-gradient(circle at 50% 45%, rgba(255,247,220,.85), rgba(255,255,255,.35) 68%); box-shadow: inset 0 0 0 4px rgba(88,211,191,.18), 0 8px 0 rgba(80,61,50,.17); }
#pile-board::before { content: "TOY PILE"; position: absolute; top: 10px; left: 50%; transform: translateX(-50%); color: rgba(80,61,50,.40); font-size: 11px; font-weight: 1000; letter-spacing: .18em; }
.pile-item { position: absolute; width: clamp(58px, 17.2vw, 82px); aspect-ratio: 1; padding: 4px; border: 4px solid white; border-radius: 26%; background: linear-gradient(145deg, #fffefa, #fff0df); box-shadow: 0 5px 0 rgba(80,61,50,.31), 0 7px 10px rgba(80,61,50,.14); transform: translate(-50%, -50%) rotate(var(--rotation)); transition: transform .16s ease, opacity .18s ease, filter .18s ease; cursor: pointer; touch-action: manipulation; }
.pile-item::before { content: ""; position: absolute; left: 10%; right: 25%; top: 8%; height: 14%; border-radius: 999px; background: rgba(255,255,255,.86); pointer-events: none; }
.pile-item img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; filter: drop-shadow(0 2px 1px rgba(80,61,50,.12)); }
.pile-item:active { filter: brightness(.95); }
.pile-item.spawning { animation: tile-spawn .2s cubic-bezier(.2,1.3,.4,1); }
@keyframes tile-spawn { from { transform: translate(-50%, -50%) rotate(var(--rotation)) scale(.45); opacity: 0; } }
.pile-item.picked { pointer-events: none; transform: translate(-50%, -50%) scale(.35) rotate(16deg); opacity: 0; }
.pile-item.hint { animation: hint-pop .65s ease-in-out 2; filter: drop-shadow(0 0 10px var(--warm)); }
@keyframes hint-pop { 50% { transform: translate(-50%, -50%) rotate(var(--rotation)) scale(1.16); } }

.tray-wrap { position: absolute; z-index: 30; top: 70%; left: 4%; right: 4%; height: 12.5%; padding: 22px 8px 8px; border: 4px solid white; border-radius: 22px; background: rgba(80,61,50,.94); box-shadow: 0 7px 0 rgba(80,61,50,.28); }
.tray-label { position: absolute; top: 3px; left: 14px; right: 14px; display: flex; justify-content: space-between; color: white; font-size: clamp(8px, 2vw, 11px); font-weight: 1000; letter-spacing: .12em; }
.tray-label span { color: var(--warm); }
#tray { height: 100%; display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.tray-slot { position: relative; display: grid; place-items: center; min-width: 0; border: 2px dashed rgba(255,255,255,.34); border-radius: 12px; background: rgba(255,255,255,.10); }
.tray-slot.filled { border-style: solid; border-color: white; background: var(--cream); box-shadow: inset 0 -3px 0 rgba(80,61,50,.13); }
.tray-slot img { max-width: 92%; max-height: 92%; object-fit: contain; }
.tray-slot.arriving { animation: tray-pop .32s cubic-bezier(.2,1.5,.4,1); }
@keyframes tray-pop { from { transform: translateY(-22px) scale(.3); opacity: 0; } }
.tray-slot.matching { animation: matching .4s ease forwards; }
@keyframes matching { 45% { transform: translateY(-12px) scale(1.2) rotate(-5deg); filter: brightness(1.2); } 100% { transform: scale(.1); opacity: 0; } }

.tools { position: absolute; z-index: 31; left: 8%; right: 8%; bottom: max(5.7%, calc(env(safe-area-inset-bottom) + 10px)); height: 66px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tool-button { position: relative; display: flex; align-items: center; justify-content: center; flex-direction: column; border: 4px solid white; border-radius: 19px; color: white; background: var(--ink); box-shadow: 0 6px 0 rgba(80,61,50,.35); font-weight: 1000; }
.tool-button.featured { background: #e76c91; }
.tool-button span { color: var(--warm); font-size: 23px; line-height: .75; }
.tool-button b { font-size: clamp(9px, 2.4vw, 13px); letter-spacing: .05em; }
.tool-button em { position: absolute; top: -9px; right: -7px; width: 25px; height: 25px; display: grid; place-items: center; border: 3px solid white; border-radius: 50%; color: var(--ink); background: var(--warm); font-size: 11px; font-style: normal; }
.tool-button:disabled { filter: grayscale(1); opacity: .45; box-shadow: none; }
.tool-button:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 rgba(80,61,50,.35); }

#fx-layer { position: absolute; z-index: 80; inset: 0; pointer-events: none; overflow: hidden; }
.fx-star { position: absolute; color: var(--warm); font-size: 24px; -webkit-text-stroke: 2px white; animation: star-burst .75s ease-out forwards; }
@keyframes star-burst { to { transform: translate(var(--dx), var(--dy)) rotate(220deg) scale(.2); opacity: 0; } }
.fx-label { position: absolute; color: white; font-size: 26px; font-weight: 1000; -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; animation: label-float .8s ease-out forwards; }
@keyframes label-float { to { transform: translateY(-75px) scale(1.15); opacity: 0; } }
.game-shake { animation: shake .34s linear; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }

.overlay { position: absolute; z-index: 100; inset: 0; display: grid; place-items: center; padding: max(7%, env(safe-area-inset-top)) 6% max(7%, env(safe-area-inset-bottom)); background: rgba(51,61,62,.52); backdrop-filter: blur(5px); transition: opacity .2s ease; }
.overlay.hidden { visibility: hidden; opacity: 0; pointer-events: none; }
.modal { position: relative; width: min(100%, 470px); padding: 45px 7% 27px; border: 5px solid white; border-radius: 31px; background: linear-gradient(180deg, #fffbe8, #ffeef0); box-shadow: 0 13px 0 rgba(80,61,50,.42), inset 0 0 0 3px rgba(245,184,58,.17); text-align: center; }
.modal-medal { position: absolute; top: -41px; left: 50%; width: 82px; height: 82px; display: grid; place-items: center; transform: translateX(-50%); border: 6px solid white; border-radius: 50%; color: white; background: var(--warm); box-shadow: 0 8px 0 #a77224; font-size: 39px; font-weight: 1000; }
.modal h2 { margin: 14px 0 7px; color: var(--ink); font-size: clamp(26px, 7vw, 40px); line-height: .95; }
.modal > p { margin: 7px 0 17px; color: #79675c; font-weight: 800; }
.tutorial-demo { position: relative; height: 126px; margin: 8px 0 14px; border: 3px solid rgba(80,61,50,.18); border-radius: 20px; background: linear-gradient(180deg, #dff6fb, #c5eff2); overflow: hidden; }
.demo-tile { position: absolute; left: 12%; top: 12px; width: 78px; height: 78px; padding: 4px; border: 4px solid white; border-radius: 22px; background: var(--cream); box-shadow: 0 5px 0 rgba(80,61,50,.24); animation: demo-move 2.2s ease-in-out infinite; }
.demo-tile img { width: 100%; height: 100%; object-fit: contain; }
@keyframes demo-move { 0%,18% { transform: translate(0,0); } 60%,82% { transform: translate(150px,42px) scale(.72); } 100% { transform: translate(0,0); } }
.demo-arrow { position: absolute; left: 48%; top: 37px; color: var(--ink); font-size: 33px; transform: rotate(-62deg); }
.demo-tray { position: absolute; right: 7%; bottom: 10px; width: 42%; height: 48px; display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; padding: 4px; border: 4px solid white; border-radius: 14px; background: var(--ink); }
.demo-tray i { border: 2px dashed rgba(255,255,255,.45); border-radius: 8px; }
.tutorial-modal ol { margin: 0 0 20px; padding-left: 25px; text-align: left; color: #625247; font-size: clamp(13px, 3.4vw, 17px); font-weight: 700; line-height: 1.5; }
.tutorial-modal li::marker { color: #e65f84; font-weight: 1000; }
.modal .primary-button { width: 100%; }
.result-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 17px 0 22px; }
.result-stats div { padding: 11px 4px; border: 3px solid #efd9c9; border-radius: 15px; background: white; }
.result-stats small { display: block; color: #806c5e; font-size: 9px; font-weight: 900; letter-spacing: .1em; }
.result-stats strong { color: #e65f84; font-size: clamp(21px, 5.8vw, 31px); }
.hidden-action { display: none; }

#landscape-warning { display: none; position: fixed; z-index: 999; inset: 0; align-items: center; justify-content: center; flex-direction: column; gap: 10px; padding: 30px; color: var(--cream); background: var(--ink); text-align: center; }
#landscape-warning div { color: var(--warm); font-size: 67px; }
#landscape-warning b { font-size: 27px; }
#landscape-warning span { opacity: .75; }
@media (orientation: landscape) and (max-height: 620px) { #landscape-warning { display: flex; } }
@media (max-height: 700px) and (orientation: portrait) {
  .home-panel { top: max(5.3%, calc(env(safe-area-inset-top) + 14px)); bottom: max(4.8%, calc(env(safe-area-inset-bottom) + 11px)); padding-top: 3.5%; }
  h1 { margin-top: 8px; }
  .home-panel > p { margin: 7px 0 1px; }
  .hero-stage { min-height: 155px; }
  .primary-button { min-height: 50px; }
  .text-button { padding-top: 10px; }
  .hud { top: max(4.9%, calc(env(safe-area-inset-top) + 7px)); height: 51px; grid-template-columns: 50px 1fr 1.2fr 50px; gap: 5px; }
  .round-button { width: 50px; height: 50px; }
  .goal-strip { top: max(13%, calc(env(safe-area-inset-top) + 64px)); height: 49px; }
  #pile-board { top: 21.5%; height: 45%; }
  .tray-wrap { top: 68%; height: 13%; }
  .tools { height: 58px; bottom: max(4.9%, calc(env(safe-area-inset-bottom) + 6px)); }
  .modal { padding-top: 39px; }
  .tutorial-demo { height: 103px; }
  .demo-tile { width: 66px; height: 66px; }
  .tutorial-modal ol { line-height: 1.35; margin-bottom: 13px; }
}
