:root {
  --ink: #214b43;
  --muted: #667b75;
  --paper: #fffdf7;
  --cream: #f6eddb;
  --line: #dfd3b8;
  --green: #47936e;
  --green-dark: #2d6f56;
  --coral: #df735d;
  --route-color: #ad7241;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background: #ece8d6;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 0; overflow-x: clip; }
body {
  min-height: 100%;
  background:
    radial-gradient(circle at 13% 9%, rgba(255,255,255,.8), transparent 28rem),
    linear-gradient(145deg, #e5eed8 0, #f4ead6 48%, #e7ead7 100%);
}
button, a { font: inherit; }
button { color: inherit; }
img { display: block; max-width: 100%; }

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 24px auto 34px;
  background: rgba(255,253,247,.94);
  border: 1px solid rgba(205,190,155,.72);
  border-radius: 34px;
  box-shadow: 0 24px 60px rgba(70, 76, 54, .15);
  overflow: hidden;
}

.game-bar {
  min-height: 86px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.62);
}
.game-brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
  border-radius: 18px;
  padding: 4px 8px 4px 4px;
  transition: background .18s ease, transform .18s ease;
}
.game-brand:hover { background: #eef5e7; transform: translateY(-1px); }
.game-brand:focus-visible { outline: 4px solid rgba(71,147,110,.3); outline-offset: 3px; }
.game-brand > span:last-child { display: grid; gap: 2px; min-width: 0; }
.game-brand strong { font-size: clamp(18px, 2.3vw, 25px); line-height: 1.05; }
.game-brand small { color: var(--muted); font-size: 13px; }
.game-icon {
  flex: 0 0 54px;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 17px;
  background: #e9d5ae;
  box-shadow: inset 0 -4px 0 rgba(121,81,47,.14);
}
.game-icon svg { width: 44px; height: 44px; fill: #bd7942; stroke: #674a31; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.age-pill, .counter {
  flex: 0 0 auto;
  padding: 10px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: white;
  font-weight: 800;
}

main { min-width: 0; }
.screen { display: none; }
.screen.is-active { display: block; }
.eyebrow { margin: 0 0 8px; color: var(--route-color); font-size: 12px; font-weight: 900; letter-spacing: .12em; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1, h2, h3 { margin-top: 0; }

.home-screen {
  position: relative;
  grid-template-columns: minmax(0, 1.02fr) minmax(380px, .98fr);
  gap: 22px 34px;
  padding: 52px 48px 36px;
  background:
    linear-gradient(110deg, rgba(242,236,215,.98) 0 50%, rgba(228,241,217,.88) 50% 100%);
}
.home-screen.is-active { display: grid; }
.hero-copy { align-self: center; min-width: 0; padding-bottom: 4px; }
.hero-copy h1 { max-width: 620px; margin-bottom: 18px; font-size: clamp(38px, 5.2vw, 66px); line-height: .98; letter-spacing: -.04em; }
.hero-copy > p:not(.eyebrow) { max-width: 600px; margin: 0; color: var(--muted); font-size: clamp(18px, 2.05vw, 23px); line-height: 1.45; }
.hero-facts { display: flex; flex-wrap: wrap; gap: 9px; margin: 24px 0; }
.hero-facts span, .result-facts span {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.82);
  font-weight: 800;
}
.primary-button, .secondary-button, .route-button, .hint-button, .next-button {
  min-height: 54px;
  border: 0;
  border-radius: 17px;
  padding: 13px 24px;
  cursor: pointer;
  font-weight: 900;
  transition: transform .17s ease, box-shadow .17s ease, background .17s ease;
}
.primary-button, .route-button, .next-button { color: white; background: var(--green); box-shadow: 0 8px 0 #2f7658; }
.primary-button:hover, .route-button:hover, .next-button:hover { background: var(--green-dark); transform: translateY(-2px); }
.primary-button:active, .route-button:active, .next-button:active { transform: translateY(4px); box-shadow: 0 4px 0 #2f7658; }
.primary-button:focus-visible, .secondary-button:focus-visible, button:focus-visible { outline: 4px solid rgba(71,147,110,.3); outline-offset: 3px; }

.hero-scene {
  position: relative;
  min-height: 390px;
  align-self: center;
  border: 1px solid #d8cda9;
  border-radius: 36px;
  overflow: hidden;
  background:
    radial-gradient(circle at 70% 20%, #fffbdc 0 8%, transparent 9%),
    linear-gradient(#d8eacb 0 45%, #eee3be 45% 100%);
  box-shadow: inset 0 -12px 20px rgba(106,83,47,.08);
}
.hero-lane {
  position: absolute;
  left: 7%; right: 7%; top: 42%; height: 34%;
  border: 9px solid #708c5a;
  border-left: 0;
  border-radius: 0 26px 26px 0;
  background: #f7edcf;
  box-shadow: 0 7px 0 rgba(83,78,49,.12), inset 0 0 18px rgba(140,105,47,.09);
}
.hero-helper { position: absolute; left: -10px; bottom: 2%; width: 32%; transform: scaleX(-1); filter: drop-shadow(0 6px 5px rgba(44,48,30,.18)); }
.hero-treat { position: absolute; left: 34%; bottom: 15%; width: 20%; max-height: 66%; object-fit: contain; filter: drop-shadow(0 5px 4px rgba(44,48,30,.2)); }
.hero-stop { position: absolute; left: 60%; top: 0; bottom: 0; width: 12px; background: #708c5a; box-shadow: inset 2px 0 0 rgba(255,255,255,.22); }
.hero-animal { position: absolute; right: -3%; bottom: 0; width: 28%; transform: scaleX(-1); filter: drop-shadow(0 6px 5px rgba(44,48,30,.18)); }
.hero-corner { position: absolute; left: 19%; top: 14%; width: 38%; height: 30%; border: 9px solid #708c5a; border-bottom: 0; border-radius: 24px 24px 0 0; opacity: .78; }

.how-strip {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
  position: relative;
  z-index: 2;
}
.how-strip article {
  min-width: 0;
  min-height: 122px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255,253,247,.97);
}
.how-strip article > b { flex: 0 0 54px; height: 54px; display: grid; place-items: center; border-radius: 17px; color: white; background: var(--coral); font-size: 24px; }
.how-strip article span { min-width: 0; display: grid; gap: 4px; }
.how-strip strong { font-size: 17px; }
.how-strip small { color: var(--muted); font-size: 14px; line-height: 1.35; }

.routes-screen, .play-screen, .result-screen { padding: 38px 42px 44px; }
.section-title, .task-head { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.section-title h2, .task-head h2 { margin-bottom: 0; font-size: clamp(28px, 4vw, 44px); line-height: 1.06; }
.section-title > p { flex: 0 0 auto; color: var(--muted); font-weight: 800; }
.route-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 28px; align-items: stretch; }
.route-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 25px;
  background: white;
  box-shadow: 0 12px 28px rgba(72,66,47,.09);
}
.route-art {
  position: relative;
  height: 166px;
  overflow: hidden;
  border-radius: 18px;
  background-position: center;
  background-size: cover;
}
.route-art::after { content: ""; position: absolute; inset: auto 0 0; height: 48%; background: linear-gradient(transparent, rgba(37,54,38,.18)); }
.route-art .route-treat { position: absolute; left: 10%; bottom: 13%; z-index: 1; width: 28%; height: 44%; object-fit: contain; filter: drop-shadow(0 4px 3px rgba(0,0,0,.18)); }
.route-art .route-animal { position: absolute; right: 4%; bottom: 5%; z-index: 1; width: 40%; height: 72%; object-fit: contain; filter: drop-shadow(0 4px 3px rgba(0,0,0,.18)); }
.route-art .is-flipped { transform: scaleX(-1); }
.route-art .mini-wall { position: absolute; left: 47%; bottom: 0; z-index: 2; width: 8px; height: 72%; border-radius: 7px 7px 0 0; background: #6b8555; box-shadow: inset 2px 0 rgba(255,255,255,.25); }
.route-number { margin: 17px 0 7px; color: var(--route-color); font-weight: 900; font-size: 12px; letter-spacing: .09em; }
.route-card h3 { min-height: 50px; margin-bottom: 8px; font-size: 22px; line-height: 1.12; }
.route-card > p:not(.route-number) { min-height: 62px; margin: 0; color: var(--muted); line-height: 1.38; }
.route-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: auto; padding-top: 16px; color: var(--muted); font-size: 13px; font-weight: 800; }
.route-progress { height: 8px; margin: 9px 0 16px; overflow: hidden; border-radius: 99px; background: #e8e4d7; }
.route-progress i { display: block; width: var(--progress); height: 100%; border-radius: inherit; background: var(--route-color); }
.route-button { width: 100%; display: flex; justify-content: space-between; align-items: center; background: var(--route-color); box-shadow: 0 7px 0 color-mix(in srgb, var(--route-color), #333 24%); }
.back-link { margin-top: 26px; border: 0; background: transparent; cursor: pointer; color: var(--green-dark); font-weight: 900; }

.task-head { justify-content: flex-start; }
.task-head > div { min-width: 0; flex: 1; }
.round-button { flex: 0 0 48px; width: 48px; height: 48px; border: 1px solid var(--line); border-radius: 50%; background: white; cursor: pointer; font-size: 23px; font-weight: 900; }
.route-progress-line { height: 8px; margin: 19px 0 20px; overflow: hidden; border-radius: 99px; background: #e7e4d7; }
.route-progress-line i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--route-color); transition: width .25s ease; }
.mission-strip {
  display: grid;
  grid-template-columns: 78px minmax(0,1fr) 88px;
  align-items: center;
  gap: 17px;
  min-height: 112px;
  padding: 14px 20px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #f8f3e7;
}
.mission-strip > img { width: 78px; height: 78px; object-fit: contain; }
.mission-strip > img:last-child { width: 88px; height: 88px; transform: scaleX(-1); }
.mission-strip h3 { margin: 0 0 5px; font-size: 23px; }
.mission-strip p:last-child { margin: 0; color: var(--muted); }
.play-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 18px; margin-top: 18px; align-items: start; }
.map-card, .control-panel { border: 1px solid var(--line); border-radius: 25px; background: white; }
.map-card { min-width: 0; padding: 14px; }
.maze-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1.42 / 1;
  min-height: 430px;
  overflow: hidden;
  border: 8px solid #617953;
  border-radius: 19px;
  background-color: #ecdfb8;
  background-image:
    linear-gradient(rgba(255,255,255,.2), rgba(255,255,255,.2)),
    var(--board-bg);
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.38), inset 0 0 24px rgba(65,69,39,.16);
}
.maze-board::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(to right, transparent 0 calc((100% / var(--size)) - 1px), rgba(62,82,52,.18) calc((100% / var(--size)) - 1px) calc(100% / var(--size))),
    repeating-linear-gradient(to bottom, transparent 0 calc((100% / var(--size)) - 1px), rgba(62,82,52,.18) calc((100% / var(--size)) - 1px) calc(100% / var(--size)));
  background-color: rgba(255,249,222,.58);
}
.maze-wall { position: absolute; z-index: 3; border-radius: 8px; background: #5f7a50; box-shadow: inset 2px 2px 0 rgba(255,255,255,.22), 0 2px 4px rgba(48,50,31,.16); }
.maze-wall.is-v { left: calc(var(--edge) * 100% / var(--size) - 4px); top: calc(var(--cell) * 100% / var(--size) + 2px); width: 8px; height: calc(100% / var(--size) - 4px); }
.maze-wall.is-h { left: calc(var(--cell) * 100% / var(--size) + 2px); top: calc(var(--edge) * 100% / var(--size) - 4px); width: calc(100% / var(--size) - 4px); height: 8px; }
.maze-treat, .maze-animal {
  position: absolute;
  z-index: 5;
  left: calc((var(--x) + .5) * 100% / var(--size));
  top: calc((var(--y) + .5) * 100% / var(--size));
  object-fit: contain;
  filter: drop-shadow(0 5px 4px rgba(46,45,28,.25));
  transition: left .3s ease, top .3s ease, transform .3s ease;
}
.maze-treat { width: calc(72% / var(--size)); height: calc(72% / var(--size)); transform: translate(-68%, -38%); }
.maze-treat.is-moving { animation: treat-bob .34s ease; }
.maze-animal { z-index: 4; width: calc(112% / var(--size)); height: calc(112% / var(--size)); transform: translate(-25%, -66%) scaleX(-1); }
.goal-pad { position: absolute; z-index: 2; left: calc(var(--x) * 100% / var(--size) + 5px); top: calc(var(--y) * 100% / var(--size) + 5px); width: calc(100% / var(--size) - 10px); height: calc(100% / var(--size) - 10px); border: 3px dashed rgba(67,126,91,.75); border-radius: 18px; background: rgba(224,246,217,.62); }
.start-marker { position: absolute; z-index: 2; left: calc(var(--x) * 100% / var(--size) + 8px); top: calc(var(--y) * 100% / var(--size) + 8px); width: calc(100% / var(--size) - 16px); height: calc(100% / var(--size) - 16px); border-radius: 50%; background: rgba(255,247,209,.6); border: 2px solid rgba(151,106,55,.5); }
.map-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 15px; padding: 13px 2px 1px; color: var(--muted); font-size: 13px; font-weight: 800; }
.map-legend span { display: inline-flex; align-items: center; gap: 7px; }
.map-legend i { width: 18px; height: 18px; display: inline-block; }
.legend-treat { border-radius: 50%; background: #c98648; }
.legend-wall { width: 8px !important; border-radius: 4px; background: #5f7a50; }
.legend-goal { border: 2px dashed #4d9169; border-radius: 6px; background: #e1f1d9; }
@keyframes treat-bob { 45% { transform: translate(-68%, -45%) rotate(-5deg); } }

.control-panel { padding: 19px; }
.control-copy h3 { margin-bottom: 8px; font-size: 24px; }
.control-copy > p:last-child { margin: 0; color: var(--muted); line-height: 1.42; }
.direction-pad { width: 224px; margin: 19px auto; display: grid; grid-template-columns: repeat(3, 68px); grid-template-rows: repeat(2, 68px); gap: 8px; }
.direction-pad button { display: grid; place-items: center; border: 1px solid #bfd0b9; border-radius: 19px; background: #edf5e7; cursor: pointer; box-shadow: 0 5px 0 #b5c8ae; }
.direction-pad button:hover { background: #dcecd5; transform: translateY(-1px); }
.direction-pad button:active { transform: translateY(3px); box-shadow: 0 2px 0 #b5c8ae; }
.direction-pad button:disabled { opacity: .45; cursor: default; }
.direction-pad button[data-direction="U"] { grid-column: 2; }
.direction-pad button[data-direction="L"] { grid-column: 1; grid-row: 2; }
.direction-pad button[data-direction="D"] { grid-column: 2; grid-row: 2; }
.direction-pad button[data-direction="R"] { grid-column: 3; grid-row: 2; }
.direction-pad svg { width: 39px; height: 39px; fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.feedback { min-height: 82px; display: grid; align-content: center; gap: 4px; padding: 13px 15px; border-radius: 17px; background: #f3f1e8; border: 1px solid #e2ded1; }
.feedback b { font-size: 16px; }
.feedback span { color: var(--muted); font-size: 14px; line-height: 1.35; }
.feedback[data-tone="good"] { background: #e3f2df; border-color: #b8d7af; }
.feedback[data-tone="soft"] { background: #fff0e4; border-color: #f1c4a6; }
.feedback[data-tone="success"] { background: #dcefe4; border-color: #9fcbb0; }
.small-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.small-actions button { min-height: 43px; padding: 7px; border: 1px solid var(--line); border-radius: 13px; background: white; cursor: pointer; font-size: 13px; font-weight: 800; }
.small-actions button:disabled { opacity: .45; cursor: default; }
.control-actions { margin-top: 12px; }
.hint-button { width: 100%; color: var(--green-dark); border: 2px solid #91bea2; background: #eef8ef; }
.next-button { width: 100%; }
.task-tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 14px; }
.task-tabs button { min-height: 42px; border: 1px solid var(--line); border-radius: 12px; background: white; cursor: pointer; font-weight: 800; }
.task-tabs button.is-current { color: white; border-color: var(--route-color); background: var(--route-color); }
.task-tabs button.is-done:not(.is-current) { color: var(--green-dark); background: #e4f1df; }

.result-screen.is-active { display: grid; grid-template-columns: minmax(340px, .95fr) minmax(0, 1.05fr); gap: 38px; align-items: center; min-height: 560px; }
.result-scene { position: relative; min-height: 390px; overflow: hidden; border: 1px solid var(--line); border-radius: 30px; background: linear-gradient(#dfeecd 0 54%, #eee3bd 54%); }
.result-track { position: absolute; left: 7%; right: 7%; bottom: 24%; height: 30%; border: 9px solid #637d50; border-radius: 24px; background: #f5ebca; }
.result-treat { position: absolute; z-index: 2; left: 43%; bottom: 26%; width: 24%; height: 27%; object-fit: contain; filter: drop-shadow(0 5px 4px rgba(0,0,0,.2)); }
.result-animal { position: absolute; z-index: 2; right: 2%; bottom: 17%; width: 34%; height: 48%; object-fit: contain; transform: scaleX(-1); filter: drop-shadow(0 5px 4px rgba(0,0,0,.2)); }
.result-helper { position: absolute; z-index: 2; left: 2%; bottom: 17%; width: 35%; transform: scaleX(-1); filter: drop-shadow(0 5px 4px rgba(0,0,0,.2)); }
.result-copy h2 { margin-bottom: 15px; font-size: clamp(34px, 5vw, 57px); line-height: 1; }
.result-copy > p:not(.eyebrow) { color: var(--muted); font-size: 19px; line-height: 1.5; }
.result-facts { display: flex; flex-wrap: wrap; gap: 9px; margin: 20px 0 25px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 13px; align-items: center; }
.secondary-button { color: var(--green-dark); border: 2px solid #92bca3; background: white; }

@media (max-width: 900px) {
  .home-screen { grid-template-columns: 1fr; padding: 38px 30px 30px; background: linear-gradient(#f2ecd7, #e8f0d9); }
  .hero-copy { text-align: center; }
  .hero-copy > p:not(.eyebrow), .hero-copy h1 { margin-left: auto; margin-right: auto; }
  .hero-facts { justify-content: center; }
  .hero-scene { width: min(600px, 100%); min-height: 340px; margin: 0 auto; }
  .how-strip { margin-top: 0; }
  .route-grid { gap: 11px; }
  .route-card { padding: 11px; }
  .route-art { height: 138px; }
  .route-card h3 { font-size: 19px; }
  .play-layout { grid-template-columns: 1fr; }
  .control-panel { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 14px 20px; align-items: start; }
  .direction-pad { grid-row: span 3; grid-column: 2; margin: 0 auto; }
  .feedback, .small-actions, .control-actions { grid-column: 1; }
  .result-screen.is-active { grid-template-columns: 1fr; }
  .result-scene { min-height: 330px; }
}

@media (max-width: 720px) {
  .app { width: min(1120px, calc(100% - 16px)); margin: 8px auto 20px; border-radius: 24px; }
  .game-bar { min-height: 76px; padding: 10px 13px; }
  .game-icon { flex-basis: 46px; width: 46px; height: 46px; border-radius: 14px; }
  .game-icon svg { width: 37px; height: 37px; }
  .game-brand small { display: none; }
  .age-pill { padding: 8px 10px; font-size: 13px; }
  .home-screen { padding: 30px 16px 20px; }
  .hero-copy h1 { font-size: clamp(35px, 10vw, 52px); }
  .hero-scene { min-height: 280px; border-radius: 26px; }
  .how-strip { grid-template-columns: 1fr; gap: 9px; }
  .how-strip article { min-height: 94px; }
  .routes-screen, .play-screen, .result-screen { padding: 28px 16px 32px; }
  .section-title { align-items: flex-start; flex-direction: column; }
  .section-title > p { margin: 0; }
  .route-grid { grid-template-columns: 1fr; }
  .route-card h3, .route-card > p:not(.route-number) { min-height: 0; }
  .route-art { height: 190px; }
  .mission-strip { grid-template-columns: 62px minmax(0,1fr) 65px; padding: 12px; gap: 10px; }
  .mission-strip > img, .mission-strip > img:last-child { width: 62px; height: 62px; }
  .mission-strip h3 { font-size: 19px; }
  .maze-board { min-height: 0; aspect-ratio: 1 / 1; border-width: 6px; }
  .control-panel { display: block; }
  .direction-pad { margin: 18px auto; }
  .task-tabs { grid-template-columns: repeat(5, minmax(48px,1fr)); overflow-x: auto; padding: 3px; }
  .result-screen.is-active { min-height: 0; }
  .result-scene { min-height: 285px; }
}

@media (max-width: 430px) {
  .game-brand { gap: 8px; }
  .game-brand strong { font-size: 16px; }
  .age-pill { display: none; }
  .hero-copy > p:not(.eyebrow) { font-size: 17px; }
  .hero-facts span { padding: 8px 10px; font-size: 13px; }
  .primary-button { width: 100%; }
  .hero-scene { min-height: 245px; }
  .how-strip article { padding: 13px; }
  .how-strip article > b { flex-basis: 46px; height: 46px; }
  .task-head { gap: 10px; }
  .task-head h2 { font-size: 25px; }
  .counter { padding: 7px 9px; font-size: 12px; }
  .mission-strip { grid-template-columns: 50px minmax(0,1fr) 50px; }
  .mission-strip > img, .mission-strip > img:last-child { width: 50px; height: 50px; }
  .mission-strip p:last-child { font-size: 14px; }
  .map-card { padding: 8px; }
  .map-legend { gap: 8px; font-size: 11px; }
  .direction-pad { width: 200px; grid-template-columns: repeat(3, 61px); grid-template-rows: repeat(2, 61px); }
  .result-actions { display: grid; }
  .result-actions button { width: 100%; }
}

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