:root {
  --ink: #214c3c;
  --muted: #667a6e;
  --paper: #fffdf7;
  --cream: #fff7e5;
  --line: #e8ddc6;
  --green: #2e7d62;
  --green-dark: #1f5f49;
  --mint: #dff1df;
  --gold: #f1b64d;
  --orange: #e97a45;
  --blue: #74b8bf;
  --shadow: 0 18px 45px rgba(59, 76, 57, .13);
}

* { box-sizing: border-box; }

html { background: #f7f0df; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 9% 4%, rgba(255, 216, 123, .24), transparent 22rem),
    radial-gradient(circle at 92% 13%, rgba(92, 171, 151, .18), transparent 24rem),
    #f7f0df;
  font-family: "Trebuchet MS", Arial, sans-serif;
  overflow-x: hidden;
}

button, a { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible { outline: 4px solid rgba(241, 182, 77, .55); outline-offset: 3px; }
img { display: block; max-width: 100%; }

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto 52px;
}

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.game-brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.game-brand > span:last-child { display: grid; gap: 1px; }
.game-brand strong { font-size: clamp(18px, 2vw, 24px); line-height: 1.05; }
.game-brand small { color: var(--muted); font-weight: 700; }

.game-icon {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 18px;
  background: #dcefe4;
  box-shadow: inset 0 0 0 2px rgba(46, 125, 98, .15), 0 9px 20px rgba(40, 88, 68, .13);
}
.game-icon svg { width: 34px; fill: none; stroke: var(--green-dark); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.age-pill { flex: 0 0 auto; padding: 9px 15px; border-radius: 999px; color: #6a4d18; background: #ffe4a8; font-weight: 900; }

.screen { display: none; }
.screen.is-active { display: block; animation: appear .24s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(8px); } }

.home-screen {
  grid-template-columns: minmax(0, 1fr) minmax(360px, .92fr);
  gap: 26px;
  align-items: center;
  padding: clamp(24px, 4vw, 48px);
  border: 1px solid var(--line);
  border-radius: 34px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.home-screen.is-active { display: grid; }
.hero-copy h1 { max-width: 650px; margin: 8px 0 14px; font-size: clamp(38px, 5vw, 64px); line-height: .98; letter-spacing: -.04em; }
.hero-copy > p:not(.eyebrow) { max-width: 610px; margin: 0 0 23px; color: #536c60; font-size: clamp(17px, 2vw, 20px); line-height: 1.52; }
.eyebrow { margin: 0; color: var(--orange); font-size: 13px; font-weight: 1000; letter-spacing: .12em; }

.primary-button, .secondary-button, .route-button, .next-button, .hint-button {
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 1000;
  transition: transform .16s ease, box-shadow .16s ease, opacity .16s ease;
}
.primary-button, .route-button, .next-button { padding: 14px 20px; color: white; background: var(--green); box-shadow: 0 10px 20px rgba(35, 112, 83, .22); }
.primary-button:hover, .route-button:hover, .next-button:hover, .secondary-button:hover, .hint-button:hover { transform: translateY(-2px); }
.primary-button span, .next-button span { margin-left: 8px; }
.primary-button:disabled, .route-button:disabled, .next-button:disabled, .hint-button:disabled { cursor: default; opacity: .48; transform: none; box-shadow: none; }
.secondary-button { padding: 14px 20px; border: 2px solid #b9d7c8; background: #eff8f1; }

.hero-scene {
  position: relative;
  min-height: 380px;
  overflow: hidden;
  border: 10px solid #e6c48b;
  border-radius: 30px 30px 24px 24px;
  background: #e7f2dd;
  box-shadow: 0 22px 36px rgba(61, 76, 53, .18), inset 0 0 0 2px rgba(89, 61, 31, .15);
}
.hero-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero-mother, .hero-acorn, .hero-slot { position: absolute; z-index: 2; }
.hero-mother { left: 12%; bottom: 10%; width: 34%; }
.hero-acorn { left: 53%; bottom: 10%; width: 13%; }
.hero-slot { left: 62%; bottom: 14%; width: 23%; border-radius: 42%; filter: grayscale(1); opacity: .22; }
.hero-slot::after { content: ""; position: absolute; inset: -8px; border: 3px dashed rgba(44, 116, 88, .78); border-radius: 38%; }
.hero-piece { position: absolute; z-index: 4; right: 3%; top: 5%; display: grid; width: 27%; place-items: center; padding: 7px; border: 3px solid #efb550; border-radius: 22px; background: rgba(255, 253, 247, .94); transform: rotate(4deg); box-shadow: 0 12px 25px rgba(50, 71, 56, .18); }
.hero-piece img { width: 82%; }
.hero-piece b { margin-top: -3px; color: #9a651f; font-size: 13px; }

.how-strip { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 4px; }
.how-strip article { display: flex; align-items: center; gap: 12px; min-height: 86px; padding: 13px; border-radius: 18px; background: #f6f3e8; }
.how-strip article > b { display: grid; flex: 0 0 40px; width: 40px; height: 40px; place-items: center; border-radius: 14px; color: white; background: var(--green); }
.how-strip article span { display: grid; gap: 3px; }
.how-strip strong { line-height: 1.1; }
.how-strip small { color: var(--muted); line-height: 1.25; }

.routes-screen, .play-screen, .result-screen { padding: clamp(22px, 3.7vw, 42px); border: 1px solid var(--line); border-radius: 32px; background: var(--paper); box-shadow: var(--shadow); }
.section-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.section-title h2, .task-head h2, .result-copy h2 { margin: 5px 0 0; font-size: clamp(30px, 4vw, 48px); line-height: 1.02; letter-spacing: -.03em; }
.section-title > p { margin: 0; color: var(--muted); font-weight: 900; }

.route-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; align-items: stretch; }
.route-card { display: flex; min-width: 0; flex-direction: column; overflow: hidden; border: 1px solid #e4dbc8; border-radius: 25px; background: #fffdfa; }
.route-preview { position: relative; height: 154px; overflow: hidden; background: #dcecdf; }
.route-preview > img:first-child { width: 100%; height: 100%; object-fit: cover; }
.route-preview-piece { position: absolute; bottom: 8%; height: 58%; width: auto; filter: drop-shadow(0 8px 8px rgba(27, 65, 48, .18)); }
.route-preview-piece:nth-of-type(2) { left: 18%; }
.route-preview-piece:nth-of-type(3) { right: 17%; }
.route-copy { display: flex; flex: 1; flex-direction: column; padding: 18px; }
.route-copy h3 { margin: 5px 0 8px; font-size: 25px; }
.route-copy > p:not(.eyebrow) { min-height: 62px; margin: 0 0 15px; color: var(--muted); line-height: 1.35; }
.route-progress, .task-progress { height: 9px; overflow: hidden; border-radius: 99px; background: #ece8dc; }
.route-progress span, .task-progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #4a9b76, #f0b64e); transition: width .3s ease; }
.route-meta { display: flex; justify-content: space-between; margin: 6px 2px 14px; color: var(--muted); font-size: 13px; font-weight: 900; }
.route-button { width: 100%; margin-top: auto; }
.text-button { margin-top: 22px; padding: 8px 0; border: 0; color: var(--green-dark); background: none; cursor: pointer; font-weight: 900; }

.task-head { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; align-items: center; gap: 15px; }
.task-head h2 { font-size: clamp(27px, 3.5vw, 40px); }
.round-button { display: grid; width: 46px; height: 46px; place-items: center; border: 0; border-radius: 50%; color: var(--green-dark); background: #e7f2ea; cursor: pointer; font-size: 25px; font-weight: 1000; }
.counter { padding: 9px 13px; border-radius: 999px; background: #f2eadb; font-weight: 1000; }
.task-progress { margin: 17px 0 22px; }
.play-layout { display: grid; grid-template-columns: minmax(0, 1.34fr) minmax(330px, .76fr); gap: 20px; align-items: start; }
.scene-card, .tray-card { border: 1px solid #e5dcc9; border-radius: 25px; background: #fffdf9; }
.scene-card { padding: 14px; }
.scene-stage { position: relative; overflow: hidden; aspect-ratio: 3 / 2; border-radius: 19px; background: #e5efe1; isolation: isolate; }
.scene-background { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; object-fit: cover; }
.scene-piece { position: absolute; z-index: var(--z, 3); height: auto; filter: drop-shadow(0 5px 5px rgba(33, 63, 50, .13)); transition: opacity .2s ease, transform .2s ease, filter .2s ease; }
.scene-piece.is-flipped { transform: scaleX(-1); }
.scene-piece.is-slot { opacity: .16; filter: grayscale(1) contrast(.5) brightness(.72); }
.scene-piece.is-current { opacity: .24; filter: grayscale(1) contrast(.45) sepia(.28) brightness(.75); animation: breathe 1.45s ease-in-out infinite; }
.scene-piece.is-current::after { content: ""; }
.slot-ring { position: absolute; z-index: 8; border: 3px dashed var(--gold); border-radius: 30%; background: rgba(255, 249, 222, .12); box-shadow: 0 0 0 5px rgba(255, 250, 230, .42), 0 0 25px rgba(238, 168, 51, .42); pointer-events: none; animation: ring 1.3s ease-in-out infinite; }
.scene-stage.is-hinted .slot-ring { border-color: var(--orange); box-shadow: 0 0 0 6px rgba(255, 247, 215, .6), 0 0 30px rgba(233, 122, 69, .5); }
@keyframes breathe { 50% { opacity: .35; } }
@keyframes ring { 50% { transform: scale(1.035); } }
.scene-story { min-height: 26px; margin: 12px 4px 1px; color: var(--muted); text-align: center; font-weight: 800; }

.tray-card { padding: 20px; }
.tray-card h3 { margin: 6px 0 15px; font-size: 25px; }
.piece-tray { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.piece-option { position: relative; display: grid; min-width: 0; min-height: 116px; place-items: center; padding: 10px 8px 25px; border: 2px solid #e4dbc9; border-radius: 17px; background: #fff; cursor: pointer; transition: transform .15s ease, border-color .15s ease, background .15s ease, opacity .15s ease; }
.piece-option:hover { transform: translateY(-2px); border-color: #8bc1a6; }
.piece-option img { max-width: 92%; max-height: 76px; object-fit: contain; filter: drop-shadow(0 5px 5px rgba(33, 63, 50, .12)); }
.piece-option img.is-flipped { transform: scaleX(-1); }
.piece-option small { position: absolute; right: 7px; bottom: 5px; left: 7px; overflow: hidden; color: #5e7267; font-size: 11px; font-weight: 900; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.piece-option.is-wrong { border-color: #e8b29b; background: #fff2ec; opacity: .48; }
.piece-option.is-hint { border-color: var(--gold); background: #fff8d9; box-shadow: 0 0 0 4px rgba(241, 182, 77, .2); }
.piece-option.is-placed { border-color: #acd5b9; background: #edf8ef; opacity: .67; }
.piece-option.is-placed::after { content: "✓"; position: absolute; top: 6px; right: 7px; display: grid; width: 24px; height: 24px; place-items: center; border-radius: 50%; color: white; background: var(--green); font-weight: 1000; }

.feedback { display: grid; gap: 3px; min-height: 72px; margin-top: 14px; padding: 13px 14px; border-radius: 15px; color: #596e63; background: #f4f1e8; line-height: 1.28; }
.feedback b { color: var(--ink); }
.feedback.is-warn { color: #81522f; background: #fff0e7; }
.feedback.is-warn b { color: #954a25; }
.feedback.is-hint { color: #6f5a24; background: #fff7d5; }
.feedback.is-success { color: #31654c; background: #e9f7ed; }
.task-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 13px; }
.hint-button { display: inline-flex; align-items: center; gap: 7px; padding: 12px 14px; border: 2px solid #edd69e; background: #fff7dc; }
.hint-button svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.next-button { margin-left: auto; }

.result-screen.is-active { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, .8fr); gap: 30px; align-items: center; }
.result-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; padding: 11px; border-radius: 25px; background: #e8e1d2; transform: rotate(-1deg); }
.result-scene { position: relative; overflow: hidden; aspect-ratio: 3 / 2; border: 4px solid white; border-radius: 14px; background: #dcebdc; }
.result-scene > img:first-child { width: 100%; height: 100%; object-fit: cover; }
.result-scene .mini-piece { position: absolute; z-index: var(--z, 3); height: auto; }
.result-copy > p:not(.eyebrow) { color: var(--muted); font-size: 18px; line-height: 1.5; }
.result-facts { display: flex; gap: 10px; margin: 18px 0; }
.result-facts span { padding: 10px 13px; border-radius: 13px; background: #f2eadb; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; }

@media (max-width: 1024px) {
  .home-screen { grid-template-columns: minmax(0, 1fr) minmax(320px, .85fr); }
  .hero-scene { min-height: 330px; }
  .play-layout { grid-template-columns: minmax(0, 1.18fr) minmax(310px, .82fr); }
  .piece-option { min-height: 105px; }
}

@media (max-width: 860px) {
  .home-screen.is-active, .result-screen.is-active { grid-template-columns: 1fr; }
  .hero-scene { min-height: 420px; }
  .play-layout { grid-template-columns: 1fr; }
  .piece-tray { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .piece-option { min-height: 100px; }
  .piece-option img { max-height: 58px; }
}

@media (max-width: 760px) {
  .app { width: min(1120px, calc(100% - 20px)); margin-top: 16px; }
  .game-head { align-items: flex-start; }
  .game-brand small { display: none; }
  .game-icon { width: 48px; height: 48px; border-radius: 15px; }
  .home-screen, .routes-screen, .play-screen, .result-screen { padding: 19px; border-radius: 25px; }
  .hero-copy h1 { font-size: clamp(36px, 11vw, 52px); }
  .hero-scene { min-height: 350px; }
  .how-strip { grid-template-columns: 1fr; }
  .how-strip article { min-height: 72px; }
  .route-grid { grid-template-columns: 1fr; }
  .route-card { display: grid; grid-template-columns: 170px minmax(0, 1fr); }
  .route-preview { height: 100%; min-height: 250px; }
  .route-copy > p:not(.eyebrow) { min-height: 0; }
  .section-title { align-items: flex-start; flex-direction: column; }
  .piece-tray { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .app { width: min(1120px, calc(100% - 14px)); }
  .game-head { gap: 8px; }
  .game-brand { gap: 8px; }
  .game-brand strong { font-size: 17px; }
  .age-pill { padding: 8px 10px; font-size: 13px; }
  .home-screen, .routes-screen, .play-screen, .result-screen { padding: 14px; border-radius: 21px; }
  .hero-scene { min-height: 270px; border-width: 7px; border-radius: 22px; }
  .route-card { display: flex; }
  .route-preview { height: 150px; min-height: 0; }
  .task-head { grid-template-columns: 42px minmax(0, 1fr) auto; gap: 9px; }
  .round-button { width: 40px; height: 40px; }
  .task-head h2 { font-size: 25px; }
  .counter { padding: 7px 9px; font-size: 13px; }
  .scene-card { padding: 8px; border-radius: 19px; }
  .scene-stage { border-radius: 14px; }
  .scene-story { min-height: 42px; font-size: 14px; }
  .tray-card { padding: 13px; border-radius: 19px; }
  .tray-card h3 { font-size: 21px; }
  .piece-tray { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .piece-option { min-height: 88px; padding: 7px 5px 22px; border-radius: 14px; }
  .piece-option img { max-height: 54px; }
  .piece-option small { font-size: 10px; }
  .task-actions { align-items: stretch; flex-direction: column; }
  .hint-button, .next-button { justify-content: center; width: 100%; margin: 0; }
  .result-gallery { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
