:root {
  --ink: #183f35;
  --muted: #60746c;
  --paper: #fffdf7;
  --cream: #f6efdf;
  --green: #438565;
  --green-dark: #27634c;
  --coral: #c8644c;
  --gold: #e6b752;
  --line: #dce5dc;
  color-scheme: light;
  font-family: Inter, ui-rounded, "Trebuchet MS", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { background: #eee5d2; }
body {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,.85), transparent 27rem),
    linear-gradient(180deg, #f5eddd 0, #ebe0ca 100%);
  overflow-x: hidden;
}
button { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 4px solid rgba(230,183,82,.68); outline-offset: 3px; }

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

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 74px;
  padding: 12px 18px;
  border: 1px solid rgba(42,97,74,.14);
  border-radius: 24px;
  background: rgba(255,253,247,.92);
  box-shadow: 0 14px 34px rgba(68,51,27,.09);
}
.game-brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.game-brand > span:last-child { display: grid; gap: 2px; min-width: 0; }
.game-brand strong { font-size: clamp(17px, 2vw, 22px); line-height: 1.08; }
.game-brand small { color: var(--muted); font-size: 13px; }
.game-icon {
  display: grid;
  place-items: center;
  width: 49px;
  height: 49px;
  flex: 0 0 49px;
  border-radius: 16px;
  color: #fffaf0;
  background: linear-gradient(145deg, #d87556, #a84e43);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.28), 0 8px 16px rgba(143,67,56,.22);
}
.game-icon svg { width: 38px; height: 38px; fill: rgba(255,244,221,.18); stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.age-pill {
  flex: 0 0 auto;
  padding: 9px 13px;
  border-radius: 999px;
  color: #66481d;
  background: #f7df9e;
  font-weight: 900;
  font-size: 13px;
}

.screen { display: none; }
.screen.is-active { display: grid; }
.home-screen {
  grid-template-columns: minmax(0, 1.02fr) minmax(420px, .98fr);
  align-items: center;
  gap: 30px;
  margin-top: 22px;
  padding: 40px;
  border-radius: 34px;
  background: var(--paper);
  box-shadow: 0 22px 52px rgba(67,52,29,.11);
}
.hero-copy { align-self: center; }
.eyebrow { margin: 0 0 8px; color: #b15a45; font-size: 12px; font-weight: 1000; letter-spacing: .1em; }
h1, h2, h3, p { overflow-wrap: break-word; }
h1 { margin: 0; max-width: 570px; font-size: clamp(35px, 5vw, 58px); line-height: .98; letter-spacing: -.045em; }
.hero-copy > p:not(.eyebrow) { max-width: 590px; margin: 20px 0 0; color: var(--muted); font-size: 18px; line-height: 1.55; }
.hero-facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 22px 0; }
.hero-facts span, .result-facts span { padding: 8px 12px; border-radius: 999px; background: #eef3e9; color: #35624e; font-size: 13px; font-weight: 900; }
.primary-button, .secondary-button, .route-button, .hide-button, .hint-button, .next-button {
  min-height: 50px;
  border: 0;
  border-radius: 16px;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 1000;
  transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}
.primary-button, .hide-button, .route-button, .next-button { color: white; background: linear-gradient(145deg, var(--green), var(--green-dark)); box-shadow: 0 9px 18px rgba(39,99,76,.2); }
.primary-button:hover, .hide-button:hover, .route-button:hover, .next-button:hover, .secondary-button:hover, .hint-button:hover { transform: translateY(-2px); filter: saturate(1.05); }
.primary-button { min-width: 210px; }
.primary-button span, .route-button span, .next-button span { margin-left: 9px; }

.hero-theater { min-width: 0; }
.hero-theater .felt-theater { aspect-ratio: 1.35; }
.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-width: 0; padding: 13px; border-radius: 18px; background: #f4efe3; }
.how-strip article > b { display: grid; place-items: center; width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%; background: #fff; color: #a95843; box-shadow: 0 4px 10px rgba(64,48,23,.1); }
.how-strip article span { display: grid; gap: 2px; min-width: 0; }
.how-strip strong { font-size: 14px; }
.how-strip small { color: var(--muted); font-size: 12px; line-height: 1.35; }

.felt-theater {
  position: relative;
  width: 100%;
  min-height: 260px;
  overflow: hidden;
  border: 10px solid #7a4932;
  border-bottom-width: 18px;
  border-radius: 24px 24px 16px 16px;
  background: #d9bd86;
  box-shadow: inset 0 0 0 3px #ab7952, 0 18px 28px rgba(77,48,28,.2);
  isolation: isolate;
}
.scene-backdrop { position: absolute; inset: 0; z-index: -2; background-image: linear-gradient(rgba(255,241,204,.14), rgba(78,65,35,.24)), var(--scene-bg); background-position: center; background-size: cover; }
.felt-theater::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 14%; z-index: -1; background: linear-gradient(#c29258, #91613e); border-top: 3px solid rgba(91,52,34,.3); }
.stage-valance { position: absolute; z-index: 4; left: -2%; right: -2%; top: -1px; height: 23%; background: #b95749; border-bottom: 4px dashed rgba(255,224,177,.68); border-radius: 0 0 50% 50% / 0 0 28% 28%; filter: drop-shadow(0 5px 3px rgba(67,38,30,.2)); }
.stage-valance::after { content: ""; position: absolute; left: 8%; right: 8%; bottom: 16%; height: 7px; border-top: 3px dashed rgba(255,223,168,.7); }
.side-curtain { position: absolute; z-index: 3; top: 9%; bottom: 0; width: 23%; background: repeating-linear-gradient(88deg, #276a68 0 12px, #3b7f78 12px 24px, #245f5f 24px 34px); border-inline-end: 4px dashed rgba(255,225,177,.62); box-shadow: 5px 0 12px rgba(38,37,26,.18); }
.side-curtain--left { left: -9%; border-radius: 0 0 76% 0; transform: skewX(5deg); }
.side-curtain--right { right: -9%; border-radius: 0 0 0 76%; transform: skewX(-5deg); border-inline-end: 0; border-inline-start: 4px dashed rgba(255,225,177,.62); box-shadow: -5px 0 12px rgba(38,37,26,.18); }
.stage-friends { position: absolute; z-index: 1; left: 11%; right: 11%; bottom: 7%; height: 72%; display: flex; justify-content: center; align-items: flex-end; gap: clamp(0px, 1.2vw, 12px); }
.stage-friend { position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; width: min(22%, 120px); height: 100%; transform-origin: bottom center; animation: friend-arrives .35s ease both; }
.stage-friend img { display: block; flex: 1 1 0; width: 100%; min-height: 0; object-fit: contain; object-position: center bottom; filter: drop-shadow(0 7px 5px rgba(56,42,24,.25)); }
.stage-friend.is-mirrored img { transform: scaleX(-1); }
.stage-friend b { width: 100%; max-width: 120px; padding: 4px 5px; margin-top: 2px; border-radius: 12px; color: #153d34; background: rgba(255,252,238,.94); box-shadow: 0 3px 8px rgba(57,43,25,.13); font-size: clamp(11px, 1.25vw, 15px); line-height: 1.1; text-align: center; overflow-wrap: anywhere; white-space: normal; }
.stage-friend.is-returned { animation: friend-return .65s ease both; }
.stage-friend.is-returned::before { content: "✓"; position: absolute; z-index: 2; right: 3%; bottom: clamp(76px, 10vw, 110px); display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: white; background: #4a9469; box-shadow: 0 4px 10px rgba(32,87,57,.28); font-weight: 1000; }
.closed-curtain { position: absolute; z-index: 8; inset: 7% 0 0; display: grid; grid-template-columns: 1fr 1fr; animation: curtain-close .36s ease both; }
.closed-curtain i { background: repeating-linear-gradient(88deg, #276a68 0 17px, #3e837b 17px 32px, #225d5c 32px 43px); border-top: 5px solid #174b4c; }
.closed-curtain i:first-child { border-right: 3px dashed rgba(255,223,168,.7); }
.closed-curtain i:last-child { border-left: 3px dashed rgba(255,223,168,.7); }
.closed-curtain b { position: absolute; left: 50%; top: 47%; width: 46px; height: 46px; display: grid; place-items: center; translate: -50% -50%; border: 4px solid #f4d49a; border-radius: 50%; color: #f4d49a; background: #b95749; box-shadow: 0 5px 12px rgba(41,36,28,.3); }
@keyframes friend-arrives { from { opacity: 0; transform: translateY(8px); } }
@keyframes friend-return { 0% { opacity: 0; transform: scale(.68) translateY(20px); } 65% { transform: scale(1.06); } }
@keyframes curtain-close { from { transform: scaleX(.18); opacity: .65; } to { transform: scaleX(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }

.routes-screen { margin-top: 22px; padding: 32px; border-radius: 32px; background: var(--paper); box-shadow: 0 20px 46px rgba(67,52,29,.1); }
.section-title, .task-head { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.section-title h2, .task-head h2, .result-copy h2 { margin: 0; font-size: clamp(27px, 4vw, 42px); letter-spacing: -.035em; line-height: 1.05; }
.section-title > p { margin: 0; padding: 9px 12px; border-radius: 999px; background: #f0ece2; color: var(--muted); font-size: 13px; font-weight: 900; }
.route-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 24px 0 18px; align-items: stretch; }
.route-card { display: flex; flex-direction: column; min-width: 0; overflow: hidden; border: 1px solid color-mix(in srgb, var(--route-accent), white 65%); border-radius: 23px; background: var(--route-soft); }
.route-preview { position: relative; height: 172px; padding: 12px; background: rgba(255,255,255,.5); }
.route-preview .felt-theater { min-height: 0; height: 100%; border-width: 6px; border-bottom-width: 10px; border-radius: 15px; }
.route-preview .stage-friend b { display: none; }
.route-preview .stage-valance { height: 25%; }
.route-count { position: absolute; z-index: 10; right: 19px; top: 19px; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: white; background: var(--route-accent); box-shadow: 0 5px 10px rgba(47,43,29,.2); font-weight: 1000; }
.route-copy { display: flex; flex: 1; flex-direction: column; padding: 17px; }
.route-copy h3 { margin: 0 0 8px; font-size: 22px; }
.route-copy > p:not(.eyebrow) { min-height: 92px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.route-progress { height: 9px; margin-top: auto; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.85); box-shadow: inset 0 1px 2px rgba(43,59,49,.12); }
.route-progress span { display: block; height: 100%; border-radius: inherit; background: var(--route-accent); }
.route-meta { display: flex; justify-content: space-between; margin: 6px 2px 12px; color: var(--muted); font-size: 12px; font-weight: 900; }
.route-button { width: 100%; background: var(--route-accent); box-shadow: none; }
.text-button { justify-self: start; border: 0; padding: 8px 2px; color: var(--green-dark); background: transparent; cursor: pointer; font-weight: 900; }

.play-screen { margin-top: 22px; padding: 28px; border-radius: 32px; background: var(--paper); box-shadow: 0 20px 46px rgba(67,52,29,.1); }
.task-head > div { flex: 1; min-width: 0; }
.round-button { display: grid; place-items: center; width: 48px; height: 48px; flex: 0 0 48px; border: 1px solid var(--line); border-radius: 15px; color: var(--ink); background: white; cursor: pointer; font-size: 24px; font-weight: 900; }
.counter { flex: 0 0 auto; padding: 9px 12px; border-radius: 999px; background: #eee8db; color: var(--muted); font-weight: 1000; }
.task-progress { height: 7px; margin: 18px 0 22px; overflow: hidden; border-radius: 99px; background: #ebe7dc; }
.task-progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #d26c52, #e6b752); transition: width .3s ease; }
.memory-board { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(290px, .75fr); gap: 18px; align-items: start; }
.theater-card { min-width: 0; padding: 16px; border: 1px solid #e0d7c6; border-radius: 24px; background: #f5eddd; }
.theater-scene .felt-theater { aspect-ratio: 1.55; min-height: 300px; }
.scene-note { margin: 12px 4px 0; color: var(--muted); font-size: 14px; line-height: 1.4; text-align: center; }
.guide-card { display: grid; min-height: 100%; padding: 20px; border: 1px solid var(--line); border-radius: 24px; background: #fff; }
.guide-card h3 { margin: 0; font-size: 25px; line-height: 1.08; }
.round-progress { display: flex; gap: 8px; margin: 16px 0; }
.round-dot { display: grid; place-items: center; width: 38px; height: 38px; border: 2px solid #d7dfd7; border-radius: 50%; color: #75857e; background: #f5f7f3; font-weight: 1000; }
.round-dot.is-current { border-color: #d28a4f; box-shadow: 0 0 0 5px rgba(210,138,79,.14); color: #a55b2c; }
.round-dot.is-correct { border-color: #4e946c; color: white; background: #4e946c; }
.feedback { display: grid; gap: 5px; min-height: 104px; align-content: center; padding: 14px; border-left: 5px solid #91a69c; border-radius: 15px; background: #f1f5f1; }
.feedback b { font-size: 16px; }
.feedback span { color: var(--muted); font-size: 14px; line-height: 1.4; }
.feedback.is-error { border-color: #d77962; background: #fff0ec; }
.feedback.is-success { border-color: #4c936b; background: #e8f5eb; }
.feedback.is-hint { border-color: #d5a53f; background: #fff6dc; }
.task-actions { display: grid; gap: 10px; margin-top: 16px; align-self: end; }
.hint-button { display: flex; justify-content: center; align-items: center; gap: 8px; color: #6b4c18; background: #fae4a8; }
.hint-button svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.next-button { background: linear-gradient(145deg, #4d8b67, #2a694f); }
[hidden] { display: none !important; }

.candidate-panel { grid-column: 1 / -1; padding: 18px; border: 1px solid #ded9cd; border-radius: 23px; background: #f7f3e9; }
.candidate-panel > header { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 14px; }
.candidate-panel h3 { margin: 0; font-size: 24px; }
.candidate-panel header small { color: var(--muted); font-weight: 900; }
.candidate-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.candidate-grid[data-count="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.candidate-grid[data-count="5"] { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.candidate-grid[data-count="6"] { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.candidate-card { position: relative; display: grid; grid-template-rows: 112px auto; justify-items: center; min-width: 0; min-height: 162px; padding: 9px 7px 11px; border: 3px solid transparent; border-radius: 18px; color: var(--ink); background: #fff; box-shadow: 0 6px 14px rgba(64,50,28,.1); cursor: pointer; transition: transform .17s ease, border-color .17s ease, box-shadow .17s ease; }
.candidate-card:hover:not(:disabled) { z-index: 1; transform: translateY(-3px); border-color: #d0a24d; box-shadow: 0 10px 20px rgba(64,50,28,.14); }
.candidate-card img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 5px 4px rgba(52,42,25,.18)); }
.candidate-card b { align-self: center; font-size: clamp(13px, 1.45vw, 17px); line-height: 1.12; text-align: center; }
.candidate-card.is-wrong { border-color: #d66f5b; background: #fff0ec; animation: soft-shake .34s ease; }
.candidate-card.is-hint { border-color: #d9a83d; background: #fff6dc; box-shadow: 0 0 0 5px rgba(217,168,61,.14); }
.candidate-card.is-correct { border-color: #4c936b; background: #e8f5eb; box-shadow: 0 0 0 5px rgba(76,147,107,.14); }
.candidate-card:disabled { cursor: default; opacity: .78; }
@keyframes soft-shake { 33% { transform: translateX(-4px); } 66% { transform: translateX(4px); } }

.result-screen { grid-template-columns: minmax(360px, 1fr) minmax(320px, .9fr); gap: 30px; align-items: center; margin-top: 22px; padding: 38px; border-radius: 32px; background: var(--paper); box-shadow: 0 20px 46px rgba(67,52,29,.1); }
.result-theater { min-width: 0; }
.result-theater .felt-theater { aspect-ratio: 1.45; }
.result-copy > p:not(.eyebrow) { color: var(--muted); font-size: 17px; line-height: 1.55; }
.result-facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.secondary-button { color: var(--green-dark); border: 2px solid #b8d1c2; background: #eff7f1; }

@media (max-width: 1000px) {
  .home-screen { grid-template-columns: 1fr 420px; padding: 30px; }
  .hero-copy > p:not(.eyebrow) { font-size: 16px; }
  .route-grid { gap: 12px; }
  .route-copy { padding: 14px; }
  .route-copy > p:not(.eyebrow) { min-height: 108px; font-size: 13px; }
  .route-button { padding-inline: 10px; font-size: 14px; }
  .memory-board { grid-template-columns: minmax(0, 1.35fr) minmax(270px, .65fr); }
  .candidate-card { grid-template-rows: 94px auto; min-height: 145px; }
}

@media (max-width: 820px) {
  .home-screen { grid-template-columns: 1fr; }
  .hero-copy { text-align: center; }
  .hero-copy h1, .hero-copy > p:not(.eyebrow) { margin-inline: auto; }
  .hero-facts { justify-content: center; }
  .hero-theater { width: min(520px, 100%); margin: 0 auto; }
  .how-strip { grid-template-columns: 1fr; }
  .route-grid { grid-template-columns: 1fr; }
  .route-card { display: grid; grid-template-columns: minmax(240px, .8fr) minmax(0, 1.2fr); }
  .route-preview { height: auto; min-height: 230px; }
  .route-copy > p:not(.eyebrow) { min-height: 0; margin-bottom: 18px; }
  .memory-board { grid-template-columns: 1fr; }
  .guide-card { min-height: 0; }
  .candidate-grid, .candidate-grid[data-count="6"], .candidate-grid[data-count="5"], .candidate-grid[data-count="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .candidate-card { grid-template-rows: 100px auto; min-height: 150px; }
  .result-screen { grid-template-columns: 1fr; }
  .result-theater { width: min(560px, 100%); margin: 0 auto; }
}

@media (max-width: 600px) {
  .app { width: min(100% - 20px, 1120px); margin-top: 10px; }
  .game-head { min-height: 66px; padding: 9px 11px; border-radius: 19px; }
  .game-icon { width: 43px; height: 43px; flex-basis: 43px; border-radius: 13px; }
  .game-icon svg { width: 33px; height: 33px; }
  .game-brand small { display: none; }
  .age-pill { padding: 7px 9px; font-size: 12px; }
  .home-screen, .routes-screen, .play-screen, .result-screen { margin-top: 12px; padding: 20px 14px; border-radius: 24px; }
  h1 { font-size: clamp(34px, 12vw, 47px); }
  .hero-copy > p:not(.eyebrow) { font-size: 15px; }
  .primary-button { width: 100%; }
  .felt-theater { min-height: 220px; border-width: 7px; border-bottom-width: 13px; }
  .stage-friends { left: 8%; right: 8%; }
  .stage-friend { width: min(25%, 110px); }
  .stage-friend b { font-size: 11px; padding-inline: 2px; }
  .route-card { display: flex; }
  .route-preview { min-height: 190px; }
  .route-copy > p:not(.eyebrow) { margin-bottom: 15px; }
  .section-title { align-items: flex-start; flex-direction: column; }
  .section-title > p { align-self: stretch; text-align: center; }
  .task-head { gap: 10px; }
  .round-button { width: 42px; height: 42px; flex-basis: 42px; }
  .counter { padding: 7px 9px; font-size: 12px; }
  .theater-card { padding: 9px; }
  .theater-scene .felt-theater { min-height: 230px; aspect-ratio: auto; }
  .theater-scene .felt-theater[data-count="6"],
  .theater-scene .felt-theater[data-count="7"],
  .result-theater .felt-theater[data-count="6"],
  .result-theater .felt-theater[data-count="7"] { min-height: 420px; }
  .felt-theater[data-count="6"] .stage-friends,
  .felt-theater[data-count="7"] .stage-friends { left: 14%; right: 14%; height: 76%; flex-wrap: wrap; align-content: flex-end; gap: 0 3px; }
  .felt-theater[data-count="6"] .stage-friend,
  .felt-theater[data-count="7"] .stage-friend { width: auto; height: 33.333%; flex: 0 0 calc(33.333% - 3px); }
  .felt-theater[data-count="6"] .stage-friend.is-returned::before,
  .felt-theater[data-count="7"] .stage-friend.is-returned::before { top: 10%; right: 0; bottom: auto; }
  .candidate-panel { padding: 13px 9px; }
  .candidate-panel > header { align-items: flex-start; flex-direction: column; gap: 5px; }
  .candidate-grid, .candidate-grid[data-count="6"], .candidate-grid[data-count="5"], .candidate-grid[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .candidate-card { grid-template-rows: 106px auto; min-height: 156px; }
  .candidate-card b { font-size: 15px; }
  .result-actions { display: grid; }
}

@media (max-width: 390px) {
  .game-brand strong { font-size: 15px; }
  .home-screen, .routes-screen, .play-screen, .result-screen { padding-inline: 12px; }
  .hero-facts span { padding-inline: 9px; font-size: 12px; }
  .felt-theater { min-height: 205px; }
  .stage-friend { width: 28%; }
  .stage-friend b { font-size: 10px; line-height: 1.05; }
  .guide-card { padding: 16px 13px; }
}
