/* Brincadeiras "extra" (v4). Cada atividade ocupa 100% da .activity-shell e se ajusta ao
   espaço com container queries (cqw/cqh), sem rolagem: 375×667, 667×375, 768×1024, 1024×768. */

/* Defesa: em telas estreitas uma regra antiga de v2.css (".progress-track { flex: 1 }")
   faz a barra de progresso do app engolir a altura da atividade. */
.game-stage > .progress-track { flex: none; }

.extra-act {
  --x-ink: #294639; --x-gold: #e3a72f; --x-gold-soft: #fff1c9; --x-paper: #fffdf4; --x-ok: #5c8a45;
  position: relative; width: 100%; height: 100%; min-height: 0; overflow: hidden; padding: 9px;
  container: extra / size;
  color: var(--x-ink); font-family: var(--font, "Avenir Next", "Trebuchet MS", system-ui, sans-serif);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.extra-act * { box-sizing: border-box; }
.extra-act button { font: inherit; color: inherit; margin: 0; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.extra-act button:disabled { cursor: default; }
.extra-act button:focus-visible, .extra-act [tabindex]:focus-visible { outline: 4px solid #d68d22; outline-offset: 3px; }
.extra-act svg { display: block; width: 100%; height: 100%; }
.extra-act img { -webkit-user-drag: none; }

@keyframes x-pulse { 0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgb(244 191 78 / 0%); } 50% { transform: scale(1.04); box-shadow: 0 0 0 6px rgb(244 191 78 / 55%); } }
@keyframes x-call { 0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgb(244 191 78 / 0%); } 50% { transform: scale(1.1); box-shadow: 0 0 0 9px rgb(244 191 78 / 75%); } }
@keyframes x-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(4px); } }
@keyframes x-pop { 0% { transform: scale(.7); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes x-hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-14%); } }
@keyframes x-blink { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* ------------------------------------------------------------------ */
/* 1. Monte a arca                                                     */
/* ------------------------------------------------------------------ */
.xp-layout {
  --g: 8px; --t: 6px;
  --s: min(calc((100cqh - var(--g) - 2 * var(--t) - 10px) / 4), calc((100cqw - 2 * var(--t) - var(--g) - 80px) / 3), 150px);
  height: 100%; display: grid; justify-content: center; align-content: center; gap: var(--g);
  grid-template-columns: calc(3 * var(--s) + 2 * var(--t)) auto;
  grid-template-areas: "board ref" "tray .";
}
.xp-pic { position: absolute; inset: 0; background-image: var(--puzzle-img); background-size: 300% 200%; background-position: var(--px) var(--py); background-repeat: no-repeat; pointer-events: none; }
.xp-board {
  grid-area: board; position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr));
  width: calc(3 * var(--s) + 2 * var(--t)); height: calc(2 * var(--s) + var(--t));
  border-radius: 16px; overflow: hidden; background: #e7eed9; box-shadow: 0 0 0 3px #c7d9b0, 0 5px 0 3px #d7e2c6;
}
.xp-slot { position: relative; min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 0; background: transparent; overflow: hidden; }
.xp-slot::after { content: ""; position: absolute; inset: 0; border: 2px dashed rgb(255 255 255 / 85%); pointer-events: none; }
.xp-ghost { opacity: .32; filter: saturate(.4); transition: opacity .2s ease, filter .2s ease; }
.xp-board.is-waiting .xp-slot:not(.is-filled)::after { border-color: #e9b54b; border-width: 3px; }
.xp-slot.is-filled::after { border: 0; }
.xp-slot.is-filled .xp-ghost { opacity: 1; filter: none; animation: x-pop .4s ease-out; }
.xp-slot.is-hint:not(.is-filled) { z-index: 1; animation: x-pulse 1.2s ease-in-out infinite; box-shadow: inset 0 0 0 4px var(--x-gold); }
.xp-slot.is-nope::after { border: 4px solid #e08a6b; }
.xp-ref { grid-area: ref; align-self: start; margin: 0; width: min(calc(1.5 * var(--s)), calc(100cqw - 3 * var(--s) - 2 * var(--t) - var(--g))); }
.xp-ref img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 12px; border: 3px solid #fff; box-shadow: 0 3px 10px rgb(41 70 57 / 22%); }
.xp-tray { grid-area: tray; display: grid; grid-template-columns: repeat(3, var(--s)); grid-template-rows: repeat(2, var(--s)); gap: var(--t); }
.xp-piece {
  position: relative; width: var(--s); height: var(--s); padding: 0; overflow: hidden;
  border: 3px solid #fff; border-radius: 12px; background: #fbf7e9;
  box-shadow: 0 4px 0 #d9cfb2, 0 4px 10px rgb(41 70 57 / 14%);
  transition: transform .12s ease, box-shadow .12s ease;
}
.xp-piece.is-selected { z-index: 2; border-color: var(--x-gold); transform: translateY(-5px) scale(1.04); box-shadow: 0 0 0 4px rgb(244 191 78 / 70%), 0 9px 14px rgb(41 70 57 / 25%); }
.xp-piece.is-used { visibility: hidden; }
.xp-tray.is-calling .xp-piece:not(.is-used) { animation: x-call .6s ease-in-out 3; }
.xp-piece.is-shaking { animation: x-shake .5s ease; }
.xp-flyer { position: absolute; z-index: 6; pointer-events: none; overflow: hidden; border-radius: 10px; box-shadow: 0 10px 20px rgb(0 0 0 / 25%); }
.extra-complete .xp-board { animation: x-pop .5s ease-out; box-shadow: 0 0 0 4px #8fb46b, 0 6px 0 4px #c9dbb0; }
.extra-complete .xp-slot::after { border: 0; }
.extra-complete .xp-tray { visibility: hidden; }

/* Celular deitado / tablet deitado: tabuleiro à esquerda, peças à direita. */
@container extra (min-aspect-ratio: 13 / 10) {
  .xp-layout {
    --s: min(calc((100cqh - var(--t) - 12px) / 2), calc((100cqw - 4 * var(--t) - 2 * var(--g)) / 6), 150px);
    grid-template-columns: auto auto; grid-template-areas: "board tray"; align-items: center; column-gap: calc(var(--g) * 2);
  }
  .xp-ref { display: none; }
}
@container extra (min-aspect-ratio: 13 / 10) and (min-height: 330px) {
  .xp-layout {
    --s: min(calc((100cqh - var(--t) - var(--g) - 120px) / 2), calc((100cqw - 4 * var(--t) - 2 * var(--g)) / 6), 150px);
    grid-template-rows: auto auto; grid-template-areas: "board ref" "board tray"; row-gap: var(--g);
  }
  .xp-board { align-self: center; }
  .xp-ref { display: block; justify-self: center; align-self: end; width: auto; height: min(150px, calc(100cqh - 2 * var(--s) - var(--t) - var(--g) - 4px)); }
  .xp-ref img { width: auto; height: 100%; }
}
/* Sem espaço para a figura pequena: o fantasma no tabuleiro basta. */
@container extra (max-width: 300px) and (max-aspect-ratio: 13 / 10) {
  .xp-layout { --s: min(calc((100cqh - var(--g) - 2 * var(--t) - 10px) / 4), calc((100cqw - 2 * var(--t)) / 3), 150px); grid-template-columns: auto; grid-template-areas: "board" "tray"; }
  .xp-ref { display: none; }
}

/* ------------------------------------------------------------------ */
/* 2. Cuide das ovelhinhas                                             */
/* ------------------------------------------------------------------ */
.xc-layout { height: 100%; max-width: 860px; margin: 0 auto; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 10px; }
.xc-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; height: clamp(84px, 26cqh, 150px); }
.xc-tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0; min-height: 64px;
  padding: 6px; border: 3px solid #dce5cd; border-bottom-width: 6px; border-radius: 20px; background: var(--x-paper);
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
}
.xc-tool-art { flex: 1 1 auto; min-height: 0; width: 100%; display: block; }
.xc-tool-name { flex: none; font-size: 17px; font-weight: 800; line-height: 1.15; }
.xc-tool.is-selected { border-color: var(--x-gold); background: var(--x-gold-soft); transform: translateY(-3px); box-shadow: 0 0 0 4px rgb(244 191 78 / 55%); }
.xc-want-tool .xc-tool { animation: x-pulse 1.3s ease-in-out infinite; }
.xc-tool:disabled { opacity: .55; }
.xc-flock { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; min-height: 0; }
.xc-sheep {
  position: relative; display: grid; grid-template-rows: minmax(0, .85fr) minmax(0, 1.15fr) auto; justify-items: center; align-items: center; gap: 6px;
  min-width: 0; min-height: 64px; padding: 8px 6px; border: 3px solid #d5e2c5; border-bottom-width: 6px; border-radius: 22px; background: #eef5e3;
  transition: background .15s ease, border-color .15s ease;
}
.xc-sheep.is-selected { border-color: var(--x-gold); background: var(--x-gold-soft); box-shadow: 0 0 0 4px rgb(244 191 78 / 55%); }
.xc-sheep.is-done { background: #e2efd2; border-color: #aec68e; }
.xc-sheep.is-shaking { animation: x-shake .5s ease; }
.xc-sheep.is-happy .xc-body { animation: x-hop .45s ease-out; }
.xc-bubble {
  position: relative; display: block; height: 100%; max-height: 150px; max-width: 100%; aspect-ratio: 1.15; padding: 9%;
  background: #fff; border: 3px solid #e2dcc0; border-radius: 50% / 46%; color: var(--x-ok);
}
.xc-bubble::after { content: ""; position: absolute; left: 50%; bottom: -9px; width: 14px; height: 14px; background: #fff; border-right: 3px solid #e2dcc0; border-bottom: 3px solid #e2dcc0; transform: translateX(-50%) rotate(45deg); }
.xc-want-sheep .xc-sheep:not(.is-done) .xc-bubble { animation: x-pulse 1.3s ease-in-out infinite; }
.xc-bubble.is-calling { animation: x-call .5s ease-in-out 3 !important; border-color: var(--x-gold); }
.xc-bubble.is-new { animation: x-pop .45s ease-out; }
.xc-body { display: block; width: 100%; height: 100%; max-height: 230px; min-height: 0; }
.xc-dots { display: flex; gap: 6px; }
.xc-dots i { width: 13px; height: 13px; border-radius: 50%; background: #d5dfc6; border: 2px solid #aebe96; }
.xc-dots i.is-done { background: var(--x-ok); border-color: #47703a; }

/* Pouca altura (celular deitado): ferramentas numa faixa baixa, balão ao lado da ovelha. */
@container extra (max-height: 260px) {
  .xc-layout { gap: 6px; }
  .xc-tools { height: 64px; gap: 8px; }
  .xc-tool { flex-direction: row; gap: 6px; padding: 3px 8px; border-bottom-width: 5px; border-radius: 16px; }
  .xc-tool-art { flex: 0 0 auto; width: 46px; height: 46px; }
  .xc-sheep { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); grid-template-rows: minmax(0, 1fr) auto; column-gap: 8px; row-gap: 2px; padding: 4px 6px; border-bottom-width: 5px; border-radius: 18px; }
  .xc-bubble { grid-row: 1 / span 2; width: 100%; height: auto; max-height: 100%; aspect-ratio: 1.1; }
  .xc-bubble::after { left: auto; right: -9px; top: 50%; bottom: auto; transform: translateY(-50%) rotate(-45deg); }
  .xc-body, .xc-dots { grid-column: 2; }
  .xc-dots i { width: 11px; height: 11px; }
}
/* Largo e com altura para três botões: ferramentas numa coluna à esquerda. */
@container extra (min-aspect-ratio: 2 / 1) and (min-height: 205px) {
  .xc-layout { max-width: 980px; grid-template-rows: minmax(0, 1fr); grid-template-columns: clamp(120px, 19cqw, 180px) minmax(0, 1fr); gap: 12px; }
  .xc-tools { height: auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(3, minmax(64px, 1fr)); }
}

/* ------------------------------------------------------------------ */
/* 3. Conte os cestos                                                  */
/* ------------------------------------------------------------------ */
.xb-layout { height: 100%; display: grid; place-items: center; }
.xb-baskets {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 8px;
  width: 100%; height: 100%; max-width: 760px; max-height: 620px;
}
.xb-basket {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 64px; padding: 0; container-type: size;
  border: 3px solid #e6e0c6; border-bottom-width: 6px; border-radius: 18px; background: var(--x-paper);
  transition: background .2s ease, border-color .2s ease;
}
.xb-art { position: relative; display: block; width: min(92cqw, 84cqh, 150px); height: min(92cqw, 84cqh, 150px); }
.xb-wicker { position: absolute; inset: 0; display: block; }
.xb-bread { position: absolute; display: block; width: 46%; height: 32%; opacity: 0; transform: translateY(-140%) scale(.8); transition: transform .38s cubic-bezier(.3, 1.4, .5, 1), opacity .15s ease; }
.xb-bread-a { left: 8%; top: 24%; }
.xb-bread-b { left: 46%; top: 23%; transition-delay: .08s; }
.xb-bread-c { left: 27%; top: 13%; transition-delay: .16s; }
.xb-num { position: absolute; top: 3px; left: 7px; font-size: 16px; font-weight: 800; line-height: 1; color: #4f7a3d; opacity: 0; }
.xb-basket.is-counted { background: #eef5e2; border-color: #b9d09c; }
.xb-basket.is-counted .xb-bread { opacity: 1; transform: none; }
.xb-basket.is-counted .xb-num { opacity: 1; }
.xb-basket.is-next { z-index: 1; border-color: var(--x-gold); background: #fff4d2; animation: x-pulse 1.3s ease-in-out infinite; }
.xb-basket.is-calling { animation: x-call .5s ease-in-out 3; border-width: 4px; border-bottom-width: 7px; }
.extra-complete .xb-basket { animation: x-pop .45s ease-out; }

@container extra (min-aspect-ratio: 8 / 5) {
  .xb-baskets { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); max-width: 900px; max-height: 360px; }
}
@container extra (max-height: 260px) {
  .xb-baskets { gap: 6px; }
  .xb-basket { border-radius: 14px; border-bottom-width: 5px; }
}

/* ------------------------------------------------------------------ */
/* 4. Até a hospedaria                                                 */
/* ------------------------------------------------------------------ */
.xs-layout {
  --a: clamp(72px, min(22cqw, 16cqh), 108px);
  --m: min(100cqw, calc(100cqh - var(--a) - 10px), 620px);
  height: 100%; display: grid; justify-content: center; justify-items: center; align-content: center; gap: 10px;
}
.xs-map { position: relative; width: var(--m); height: var(--m); border-radius: 18px; overflow: hidden; background: #cfe0a8; box-shadow: inset 0 0 0 4px #b3ca8a; outline: none; }
.xs-cells { position: absolute; inset: 4px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); grid-template-rows: repeat(5, minmax(0, 1fr)); }
.xs-cell { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; }
.xs-road { background: #f3e2b5; box-shadow: inset 0 0 0 1px #e8d29c; cursor: pointer; }
.xs-bush { padding: 6%; }
.xs-bush.is-shaking svg { animation: x-shake .5s ease; }
.xs-steps { display: block; width: 66%; height: 66%; opacity: 0; transition: opacity .2s ease; }
.xs-cell.is-next { background: #ffe7a1; box-shadow: inset 0 0 0 3px #e7b443; }
.xs-cell.is-next .xs-steps { opacity: 1; animation: x-blink 1.2s ease-in-out infinite; }
.xs-goal { background: #e6efcf; }
.xs-inn { display: block; width: 100%; height: 100%; padding: 4%; }
.xs-traveler {
  position: absolute; z-index: 3; pointer-events: none;
  left: calc(4px + var(--x, 0) * (100% - 8px) / 5); top: calc(4px + var(--y, 0) * (100% - 8px) / 5);
  width: calc((100% - 8px) / 5); height: calc((100% - 8px) / 5); padding: 3%;
  display: grid; place-items: center; filter: drop-shadow(0 3px 2px rgb(60 40 20 / 35%));
  transition: left .15s ease, top .15s ease;
}
.xs-traveler .sprite-art, .xs-traveler img { width: 100%; height: 100%; object-fit: contain; }
.xs-traveler:not(.is-fallback) { scale: 1.3; padding: 0; }
.xs-fallback {
  display: block; width: 100%; height: 100%; border-radius: 50%; border: 3px solid #fff; background-color: #f3e2b5;
  background-size: 256% auto; background-position: 19% 14%; background-repeat: no-repeat; box-shadow: 0 0 0 2px #c48a3a;
}
.xs-traveler.is-bump-left { animation: x-bump-left .4s ease; }
.xs-traveler.is-bump-right { animation: x-bump-right .4s ease; }
.xs-traveler.is-bump-up { animation: x-bump-up .4s ease; }
.xs-traveler.is-bump-down { animation: x-bump-down .4s ease; }
@keyframes x-bump-left { 40% { transform: translateX(-18%); } }
@keyframes x-bump-right { 40% { transform: translateX(18%); } }
@keyframes x-bump-up { 40% { transform: translateY(-18%); } }
@keyframes x-bump-down { 40% { transform: translateY(18%); } }
.xs-arrived .xs-traveler { animation: x-hop .5s ease-out 2; }
.xs-arrows { display: grid; grid-template-columns: repeat(4, var(--a)); grid-auto-rows: var(--a); gap: 8px; }
.xs-arrow {
  width: var(--a); height: var(--a); padding: 14%; min-width: 0;
  border: 3px solid #c8d8b0; border-bottom-width: 6px; border-radius: 22px; background: #fff8e2;
  transition: transform .1s ease, background .15s ease;
}
.extra-act .xs-arrow { color: #4d8a3c; }
.xs-arrow:active:not(:disabled) { transform: translateY(2px); }
.xs-arrow.is-hint { border-color: var(--x-gold); background: var(--x-gold-soft); animation: x-pulse 1.1s ease-in-out infinite; }
.xs-arrow:disabled { opacity: .45; }

/* Deitado: mapa à esquerda, setas em "T" à direita. */
@container extra (min-aspect-ratio: 5 / 4) {
  .xs-layout {
    --a: clamp(72px, min(calc((100cqh - 10px) / 2), 16cqw), 120px);
    --m: min(100cqh, calc(100cqw - 3 * var(--a) - 40px), 620px);
    grid-template-columns: auto auto; align-items: center; column-gap: 20px;
  }
  .xs-arrows { grid-template-columns: repeat(3, var(--a)); grid-template-rows: repeat(2, var(--a)); }
  .xs-arrow-up { grid-column: 2; grid-row: 1; }
  .xs-arrow-left { grid-column: 1; grid-row: 2; }
  .xs-arrow-down { grid-column: 2; grid-row: 2; }
  .xs-arrow-right { grid-column: 3; grid-row: 2; }
}

/* Movimento reduzido: sem animações; os destaques continuam visíveis (borda e cor). */
@media (prefers-reduced-motion: reduce) {
  .extra-act *, .extra-act *::before, .extra-act *::after { animation: none !important; transition: none !important; }
  .xb-basket.is-next, .xp-slot.is-hint, .xs-arrow.is-hint { outline: 4px solid var(--x-gold); outline-offset: 2px; }
  .xb-basket.is-calling, .xc-bubble.is-calling, .xp-tray.is-calling .xp-piece:not(.is-used) { outline: 5px solid #e08a3b; outline-offset: 2px; }
}
