:root {
  color-scheme: light;
  --paper: #fffaf0;
  --cream: #fff3d8;
  --ink: #174f45;
  --muted: #667d72;
  --coral: #ef715c;
  --coral-dark: #cc4f42;
  --teal: #2f9682;
  --gold: #e7b44f;
  --line: #dbcda8;
  --shadow: 0 18px 45px rgba(75, 62, 29, .14);
}

* { box-sizing: border-box; }

html { background: #f7edda; }

body {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", Arial, sans-serif;
  background:
    radial-gradient(circle at 10px 10px, rgba(43, 121, 99, .06) 1.5px, transparent 1.6px) 0 0 / 25px 25px,
    linear-gradient(180deg, #fff9eb 0, #f7eddc 100%);
  overflow-x: hidden;
}

button, a { font: inherit; }
button { color: inherit; }

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

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

.game-brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.game-brand strong, .game-brand small { display: block; }
.game-brand strong { font-size: clamp(1.05rem, 2vw, 1.4rem); }
.game-brand small { margin-top: 2px; color: var(--muted); font-size: .86rem; }

.game-icon {
  display: grid;
  flex: 0 0 56px;
  width: 56px;
  height: 56px;
  place-items: center;
  border: 2px solid #d8c38c;
  border-radius: 18px;
  background: #fff5ce;
  box-shadow: 0 7px 0 #ead9ad;
}

.game-icon svg { width: 38px; fill: none; stroke: var(--teal); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

.age-pill, .counter {
  flex: 0 0 auto;
  padding: 11px 18px;
  border: 2px solid #dfd2b0;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  font-weight: 900;
  box-shadow: 0 5px 0 rgba(214, 198, 158, .5);
}

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

.home-screen {
  display: none;
  grid-template-columns: minmax(0, .94fr) minmax(390px, 1.06fr);
  gap: 28px;
  align-items: center;
  padding: clamp(26px, 5vw, 58px);
  border: 2px solid var(--line);
  border-radius: 36px;
  background: rgba(255, 250, 238, .94);
  box-shadow: var(--shadow), inset 0 0 0 7px rgba(255,255,255,.38);
}

.home-screen.is-active { display: grid; }

.hero-copy h1, .section-title h2, .task-head h2, .result-copy h2, .choices-card h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.04;
  letter-spacing: -.025em;
}

.hero-copy h1 { max-width: 590px; font-size: clamp(2.35rem, 5vw, 4.65rem); }
.hero-copy > p:not(.eyebrow) { max-width: 560px; margin: 22px 0 28px; color: var(--muted); font-size: 1.08rem; line-height: 1.6; }

.eyebrow {
  margin: 0 0 12px;
  color: #9a6144;
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .18em;
}

.primary-button, .secondary-button, .next-button, .hint-button, .text-button, .round-button {
  min-height: 52px;
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 900;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.primary-button, .next-button {
  padding: 0 24px;
  color: #fff;
  background: var(--coral);
  box-shadow: 0 7px 0 var(--coral-dark);
}
.primary-button:hover, .next-button:hover { transform: translateY(-2px); box-shadow: 0 9px 0 var(--coral-dark); }
.primary-button:active, .next-button:active { transform: translateY(4px); box-shadow: 0 3px 0 var(--coral-dark); }

.secondary-button, .hint-button {
  padding: 0 20px;
  border: 2px solid var(--teal);
  color: var(--ink);
  background: #fffdf7;
}
.secondary-button:hover, .hint-button:hover { background: #e6f5ef; transform: translateY(-2px); }
.hint-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.hint-button svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hint-button:disabled { cursor: default; opacity: .5; transform: none; }

button:focus-visible, a:focus-visible { outline: 4px solid rgba(48, 151, 130, .3); outline-offset: 4px; }

.hero-workshop {
  position: relative;
  min-height: 430px;
  padding: 26px 84px 26px 10px;
}

.hero-board {
  position: relative;
  width: min(100%, 410px);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border: 12px solid #d5a967;
  border-radius: 30px;
  background: linear-gradient(145deg, #dff0df, #f8dfb4);
  box-shadow: 0 20px 35px rgba(82, 58, 24, .2), inset 0 0 0 5px #f4d89e;
}

.hero-half { position: absolute; inset: 7%; overflow: hidden; clip-path: polygon(0 0, 50% 0, 50% 100%, 0 100%); }
.hero-half img { width: 100%; height: 100%; object-fit: contain; }
.hero-seam { position: absolute; z-index: 3; top: 10%; bottom: 10%; left: 50%; border-left: 4px dashed rgba(115, 87, 47, .55); }
.hero-target { position: absolute; right: 22%; top: 45%; z-index: 2; display: grid; width: 64px; height: 64px; place-items: center; border: 3px dashed #c7a871; border-radius: 19px; color: #aa8052; background: rgba(255,255,255,.48); font: 700 2.1rem Georgia, serif; }
.hero-piece { position: absolute; z-index: 5; right: 0; bottom: 70px; width: 155px; transform: rotate(4deg); }
.hero-piece > span { display: block; aspect-ratio: 1; overflow: hidden; border: 7px solid #fff8dc; border-radius: 25px; background: #d9eee5; box-shadow: 0 16px 30px rgba(55, 71, 53, .24); clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%); }
.hero-piece img { width: 100%; height: 100%; object-fit: contain; }
.hero-piece b { display: block; width: max-content; margin: -4px auto 0; padding: 7px 13px; border-radius: 999px; color: #fff; background: var(--teal); font-size: .78rem; transform: rotate(-4deg); }

.how-strip {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 8px;
  padding-top: 24px;
  border-top: 2px dashed #deceaa;
}
.how-strip article { display: flex; gap: 11px; align-items: center; min-width: 0; }
.how-strip article > b { display: grid; flex: 0 0 38px; width: 38px; height: 38px; place-items: center; border-radius: 13px; color: #fff; background: var(--teal); }
.how-strip strong, .how-strip small { display: block; }
.how-strip small { margin-top: 3px; color: var(--muted); line-height: 1.3; }

.routes-screen, .play-screen, .result-screen {
  padding: clamp(24px, 4vw, 46px);
  border: 2px solid var(--line);
  border-radius: 34px;
  background: rgba(255, 250, 238, .95);
  box-shadow: var(--shadow);
}

.section-title, .task-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.section-title h2 { font-size: clamp(2.2rem, 4.2vw, 3.7rem); }
.section-title > p { color: var(--muted); font-weight: 800; }

.route-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin: 28px 0 22px; }
.route-card { display: flex; min-width: 0; flex-direction: column; overflow: hidden; border: 2px solid #ddcfaa; border-radius: 27px; background: #fffdf7; box-shadow: 0 11px 0 #eadfca; }
.route-preview { position: relative; aspect-ratio: 16 / 10; overflow: hidden; background: linear-gradient(145deg, #dcefe4, #f6dca7); }
.route-preview img { position: absolute; inset: 7%; width: 86%; height: 86%; object-fit: contain; }
.route-preview::after { content: ""; position: absolute; pointer-events: none; }
.route-preview--vertical::after { top: 9%; bottom: 9%; left: 50%; border-left: 4px dashed rgba(112,79,42,.55); }
.route-preview--horizontal::after { left: 9%; right: 9%; top: 50%; border-top: 4px dashed rgba(112,79,42,.55); }
.route-preview--diagonal::after { width: 120%; left: -10%; top: 50%; border-top: 4px dashed rgba(112,79,42,.55); transform: rotate(-34deg); }
.route-copy { display: flex; flex: 1; flex-direction: column; padding: 22px; }
.route-copy h3 { margin: 0 0 10px; font: 700 1.65rem/1.05 Georgia, serif; }
.route-copy > p:not(.eyebrow) { min-height: 75px; margin: 0 0 18px; color: var(--muted); line-height: 1.48; }
.route-progress { height: 10px; margin-top: auto; overflow: hidden; border-radius: 999px; background: #eee5d4; }
.route-progress span { display: block; height: 100%; border-radius: inherit; background: var(--teal); }
.route-meta { display: flex; justify-content: space-between; gap: 10px; margin: 9px 0 15px; color: var(--muted); font-size: .82rem; font-weight: 800; }
.route-button { width: 100%; min-height: 50px; border: 0; border-radius: 15px; color: #fff; background: var(--ink); cursor: pointer; font-weight: 900; }
.route-button:hover { background: var(--teal); }
.text-button { display: block; padding: 0 18px; margin: 0 auto; border: 0; background: transparent; }
.text-button:hover { color: var(--teal); }

.task-head { justify-content: flex-start; }
.task-head > div { min-width: 0; }
.task-head h2 { font-size: clamp(2rem, 4vw, 3.3rem); }
.task-head .counter { margin-left: auto; }
.round-button { flex: 0 0 54px; width: 54px; padding: 0; border: 2px solid #d9cba5; border-radius: 50%; background: #fffdf7; font-size: 1.5rem; }
.round-button:hover { background: #e7f4ee; transform: translateX(-2px); }
.task-progress { height: 11px; margin: 24px 0; overflow: hidden; border-radius: 999px; background: #e9e1d0; }
.task-progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), #69b88b); transition: width .3s ease; }

.play-layout { display: grid; grid-template-columns: minmax(0, 1.16fr) minmax(340px, .84fr); gap: 24px; align-items: stretch; }
.assembly-card, .choices-card { border: 2px solid #d9cca8; border-radius: 28px; background: #fffdf7; box-shadow: 0 10px 0 #e8ddc7; }
.assembly-card { padding: 22px; }
.assembly-stage { position: relative; width: min(100%, 590px); aspect-ratio: 1; margin: 0 auto; overflow: hidden; border: 10px solid #d4ad72; border-radius: 30px; background: linear-gradient(145deg, #dcefe5, #f8deae); box-shadow: inset 0 0 0 5px rgba(255,255,255,.48); }
.assembly-stage::before { content: ""; position: absolute; inset: 5%; border: 2px dashed rgba(106, 88, 51, .32); border-radius: 22px; }
.assembly-object, .target-shade { position: absolute; inset: 7%; width: 86%; height: 86%; }
.assembly-object { object-fit: contain; transition: clip-path .38s ease, opacity .25s ease, transform .38s ease; }
.assembly-stage.split-vertical .assembly-object { clip-path: polygon(0 0, 50% 0, 50% 100%, 0 100%); }
.assembly-stage.split-horizontal .assembly-object { clip-path: polygon(0 0, 100% 0, 100% 50%, 0 50%); }
.assembly-stage.split-diagonal .assembly-object { clip-path: polygon(0 0, 100% 0, 0 100%); }
.assembly-stage.is-solved .assembly-object { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); transform: scale(1.02); }
.target-shade { display: grid; place-items: center; color: rgba(119, 87, 44, .68); background: rgba(255,255,255,.44); }
.target-shade::after { content: "?"; display: grid; width: 64px; height: 64px; place-items: center; border: 3px dashed currentColor; border-radius: 19px; font: 700 2rem Georgia, serif; }
.split-vertical .target-shade { clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%); }
.split-horizontal .target-shade { clip-path: polygon(0 50%, 100% 50%, 100% 100%, 0 100%); }
.split-diagonal .target-shade { clip-path: polygon(100% 0, 100% 100%, 0 100%); }
.assembly-stage.is-solved .target-shade { opacity: 0; }
.seam-line { position: absolute; z-index: 4; pointer-events: none; transition: opacity .25s ease; }
.split-vertical .seam-line { top: 9%; bottom: 9%; left: 50%; border-left: 4px dashed #b29058; }
.split-horizontal .seam-line { left: 9%; right: 9%; top: 50%; border-top: 4px dashed #b29058; }
.split-diagonal .seam-line { width: 125%; left: -12%; top: 50%; border-top: 4px dashed #b29058; transform: rotate(-45deg); }
.assembly-stage.is-solved .seam-line { opacity: .24; }
.assembly-stage.is-hinted { box-shadow: inset 0 0 0 7px rgba(231, 180, 79, .75), 0 0 0 7px rgba(231, 180, 79, .24); }
.seam-caption { margin: 14px 0 0; color: var(--muted); text-align: center; font-weight: 800; }

.choices-card { display: flex; flex-direction: column; padding: clamp(20px, 3vw, 30px); }
.choices-card h3 { font-size: clamp(2rem, 3.5vw, 3rem); }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 20px 0; }
.choice-grid[data-count="3"] .piece-option:last-child { grid-column: 1 / -1; width: calc(50% - 6px); justify-self: center; }
.piece-option { position: relative; min-width: 0; min-height: 132px; padding: 8px; border: 3px solid #dbcda8; border-radius: 20px; background: #f8f2e4; cursor: pointer; box-shadow: 0 6px 0 #e5d8bc; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.piece-option:hover { transform: translateY(-3px); border-color: var(--teal); }
.piece-option:disabled { cursor: default; }
.piece-option.is-wrong { opacity: .47; border-color: #d48a78; box-shadow: none; transform: none; }
.piece-option.is-hint { border-color: var(--gold); background: #fff5c9; box-shadow: 0 0 0 5px rgba(231,180,79,.22), 0 6px 0 #d8b45f; }
.piece-option.is-correct { border-color: #45a878; background: #e9f7ee; box-shadow: 0 0 0 5px rgba(69,168,120,.18), 0 6px 0 #a4d1b6; }
.piece-number { position: absolute; z-index: 4; left: 8px; bottom: 8px; display: grid; width: 29px; height: 29px; place-items: center; border-radius: 10px; color: #fff; background: var(--ink); font-size: .82rem; font-weight: 900; }
.piece-view { position: absolute; inset: 7px; overflow: hidden; border-radius: 14px; background: linear-gradient(145deg, #e2efe4, #f6dfbd); }
.piece-view img { position: absolute; inset: 5%; width: 90%; height: 90%; object-fit: contain; }
.piece-view.split-vertical img { clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%); }
.piece-view.split-horizontal img { clip-path: polygon(0 50%, 100% 50%, 100% 100%, 0 100%); }
.piece-view.split-diagonal img { clip-path: polygon(100% 0, 100% 100%, 0 100%); }

.feedback { min-height: 88px; margin-top: auto; padding: 15px 17px; border: 2px solid #dfd3b6; border-radius: 18px; background: #f8f3e7; }
.feedback b, .feedback span { display: block; }
.feedback span { margin-top: 4px; color: var(--muted); line-height: 1.4; }
.feedback.is-warn { border-color: #e6a38e; background: #fff0e8; }
.feedback.is-hint { border-color: #e5c568; background: #fff8d6; }
.feedback.is-success { border-color: #86c2a0; background: #eaf7ef; }
.task-actions { display: flex; gap: 10px; margin-top: 14px; }
.task-actions > button { flex: 1 1 0; }

.result-screen.is-active { display: grid; grid-template-columns: minmax(0, 1fr) minmax(350px, .9fr); gap: clamp(28px, 5vw, 60px); align-items: center; }
.result-gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 16px; border-radius: 28px; background: #dcefe6; }
.result-toy { display: grid; aspect-ratio: 1; place-items: center; overflow: hidden; border: 4px solid #fffaf0; border-radius: 20px; background: linear-gradient(145deg, #f9dfb2, #e4f1e8); box-shadow: 0 7px 12px rgba(72,78,49,.12); }
.result-toy img { width: 88%; height: 88%; object-fit: contain; }
.result-copy h2 { font-size: clamp(2.55rem, 5vw, 4.5rem); }
.result-copy > p:not(.eyebrow) { margin: 20px 0; color: var(--muted); font-size: 1.08rem; line-height: 1.55; }
.result-facts { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0 24px; }
.result-facts span { padding: 11px 15px; border: 2px solid #c8dbce; border-radius: 14px; background: #eff8f2; }
.result-facts b { font-size: 1.35rem; }
.result-actions { display: flex; flex-wrap: wrap; gap: 12px; }

@media (max-width: 960px) {
  .home-screen { grid-template-columns: 1fr; }
  .hero-copy { text-align: center; }
  .hero-copy > p:not(.eyebrow) { margin-left: auto; margin-right: auto; }
  .hero-workshop { width: min(100%, 620px); margin: 0 auto; }
  .play-layout { grid-template-columns: 1fr; }
  .assembly-stage { max-width: 550px; }
  .choice-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .choice-grid[data-count="3"] .piece-option:last-child { grid-column: auto; width: auto; }
  .piece-option { min-height: 142px; }
}

@media (max-width: 900px) {
  .route-grid { grid-template-columns: 1fr; }
  .route-card { display: grid; grid-template-columns: minmax(220px, .8fr) minmax(0, 1.2fr); }
  .route-preview { min-height: 270px; aspect-ratio: auto; }
  .route-copy > p:not(.eyebrow) { min-height: 0; }
}

@media (max-width: 720px) {
  .app { width: min(100% - 18px, 1120px); padding-top: 14px; }
  .game-head { margin-bottom: 14px; }
  .game-icon { flex-basis: 46px; width: 46px; height: 46px; border-radius: 15px; }
  .game-icon svg { width: 32px; }
  .age-pill { padding: 9px 12px; font-size: .82rem; }
  .home-screen, .routes-screen, .play-screen, .result-screen { padding: 20px; border-radius: 26px; }
  .hero-workshop { min-height: 350px; padding-right: 54px; }
  .hero-board { max-width: 330px; border-width: 9px; }
  .hero-piece { right: 0; bottom: 44px; width: 120px; }
  .how-strip { grid-template-columns: 1fr; }
  .section-title { display: block; text-align: center; }
  .route-card { display: flex; }
  .route-preview { min-height: 0; aspect-ratio: 16 / 9; }
  .task-head { display: grid; grid-template-columns: 50px minmax(0, 1fr) auto; }
  .counter { padding: 9px 11px; }
  .assembly-card { padding: 12px; }
  .assembly-stage { border-width: 7px; border-radius: 23px; }
  .choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .piece-option { min-height: 130px; }
  .result-screen.is-active { grid-template-columns: 1fr; }
  .result-copy { text-align: center; }
  .result-facts, .result-actions { justify-content: center; }
}

@media (max-width: 440px) {
  .game-brand small { display: none; }
  .game-brand strong { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .home-screen, .routes-screen, .play-screen, .result-screen { padding: 16px; }
  .hero-copy h1 { font-size: 2.45rem; }
  .hero-workshop { min-height: 300px; padding: 10px 38px 18px 0; }
  .hero-board { max-width: 280px; }
  .hero-piece { width: 104px; bottom: 35px; }
  .hero-target { width: 48px; height: 48px; font-size: 1.5rem; }
  .task-head h2 { font-size: 2rem; }
  .task-head .eyebrow { letter-spacing: .1em; }
  .choices-card { padding: 18px 14px; }
  .choice-grid { gap: 9px; }
  .piece-option { min-height: 116px; padding: 5px; border-radius: 17px; }
  .choice-grid[data-count="5"] { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .choice-grid[data-count="5"] .piece-option { grid-column: span 2; min-height: 98px; }
  .choice-grid[data-count="5"] .piece-option:nth-child(4) { grid-column: 2 / span 2; }
  .choice-grid[data-count="5"] .piece-option:nth-child(5) { grid-column: 4 / span 2; }
  .piece-number { width: 25px; height: 25px; }
  .task-actions { flex-direction: column; }
  .result-actions { flex-direction: column; }
}

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