:root {
  --farm-visible-width: 100vw;
  --farm-visible-height: 100dvh;
  --farm-visible-top: 0px;
  --farm-visible-left: 0px;
  --farm-stage-scale: 1;
  --farm-stage-rendered-width: min(100vw, 177.7778dvh);
  --farm-stage-rendered-height: min(100dvh, 56.25vw);
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
  color: #fff;
  background: #071c29;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #071c29;
}

body.farm-phases-page {
  min-height: 100dvh;
  touch-action: none;
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 5px solid #fff;
  outline-offset: 3px;
}

.farm-phases-page > .active-child-bar { display: none !important; }

.game-shell {
  position: fixed;
  z-index: 1;
  left: var(--farm-visible-left);
  top: var(--farm-visible-top);
  width: var(--farm-visible-width);
  height: var(--farm-visible-height);
  display: grid;
  place-items: center;
  overflow: hidden;
  overflow: clip;
  isolation: isolate;
  user-select: none;
  background: #1598e7;
}

.farm-backdrop {
  position: absolute;
  z-index: -1;
  inset: -14px;
  background: linear-gradient(rgba(10, 44, 56, .18), rgba(10, 44, 56, .18)), url("assets/backgrounds/background_fazenda.png") center / cover no-repeat;
  filter: blur(5px) brightness(.82) saturate(.9);
  transform: scale(1.035);
  pointer-events: none;
}

.farm-stage-frame {
  position: relative;
  width: var(--farm-stage-rendered-width);
  height: var(--farm-stage-rendered-height);
  flex: 0 0 auto;
  overflow: visible;
}

.farm-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1280px;
  height: 720px;
  overflow: hidden;
  transform: scale(var(--farm-stage-scale));
  transform-origin: left top;
  background: #1598e7;
  box-shadow: 0 0 30px rgba(2, 24, 33, .34);
}

.farm-scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
}

.hidden { display: none !important; }

.ui-button {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  touch-action: manipulation;
  transition: transform .1s ease, filter .1s ease;
}

.ui-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.ui-button:active {
  transform: scale(.91);
  filter: brightness(1.08);
}

.top-back {
  position: absolute;
  z-index: 40;
  left: 14px;
  top: 7px;
  width: 84px;
  height: 84px;
}

.wood-sign {
  position: absolute;
  z-index: 20;
  left: 397px;
  top: 9px;
  width: 486px;
  height: 62px;
  display: grid;
  place-items: center;
  padding: 0 24px;
  border: 5px solid #9a4d13;
  border-radius: 20px;
  background: repeating-linear-gradient(90deg, rgba(121, 63, 16, .13) 0 2px, transparent 2px 74px), linear-gradient(#f9c14c, #eda029);
  box-shadow: inset 0 5px 0 rgba(255,255,255,.38), inset 0 -5px 0 rgba(124,61,17,.18), 0 7px 14px rgba(48,41,24,.28);
  color: #fff8e8;
  text-align: center;
  font-size: 32px;
  font-weight: 1000;
  letter-spacing: -.02em;
  line-height: 1;
  text-shadow: -2px -2px 0 #5b260d, 2px -2px 0 #5b260d, -2px 2px 0 #5b260d, 2px 2px 0 #5b260d, 0 4px 0 #783616;
}

.top-controls {
  position: absolute;
  z-index: 40;
  right: 14px;
  top: 7px;
  height: 84px;
  display: flex;
  gap: 3px;
}

.top-controls .ui-button {
  width: 84px;
  height: 84px;
}

.language-button span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-top: 4px;
  color: #fff;
  font-size: 18px;
  font-weight: 1000;
  text-shadow: 0 2px 0 #6b2b0c, 0 0 3px #6b2b0c;
}

.menu-heading {
  position: absolute;
  left: 300px;
  right: 300px;
  top: 86px;
  margin: 0;
  color: #4b220d;
  text-align: center;
  font-size: 31px;
  font-weight: 1000;
  line-height: 1;
  text-shadow: 0 2px 0 #fff;
}

.phase-grid {
  position: absolute;
  left: 154px;
  right: 154px;
  top: 136px;
  bottom: 38px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 22px 26px;
}

.phase-card {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: 46% 54%;
  align-items: stretch;
  overflow: hidden;
  border: 7px solid #fff3d3;
  border-radius: 24px;
  background: linear-gradient(#fffef7, #ffe8b8);
  box-shadow: 0 8px 0 #cf8422, 0 14px 18px rgba(63,48,24,.25);
  color: #4b210e;
  touch-action: manipulation;
  transition: transform .12s ease, filter .12s ease;
}

.phase-card:hover { filter: saturate(1.05); }
.phase-card:active { transform: scale(.975); }

.phase-preview {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: linear-gradient(#65c8ff, #b8ef9b);
}

.phase-preview img { position: absolute; pointer-events: none; }

.preview-cover {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-animal {
  left: 12%;
  bottom: -3%;
  width: 62%;
  height: 76%;
  object-fit: contain;
  filter: drop-shadow(0 5px 5px rgba(57,38,13,.28));
}

.food-preview { background: linear-gradient(#7ed0ff, #d2f3a7); }
.food-animal { left: 5%; bottom: -4%; width: 50%; height: 66%; }

.phase-copy {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 34px 22px 24px;
  text-align: center;
}

.phase-number {
  position: absolute;
  left: 15px;
  top: 14px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f5b822;
  color: #7a320c;
  font-size: 20px;
  font-weight: 1000;
  box-shadow: 0 3px 0 #a85a12;
}

.phase-copy strong {
  font-size: 29px;
  font-weight: 1000;
  line-height: 1.04;
}

.phase-copy small {
  margin-top: 12px;
  color: #7d4b2a;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.15;
}

.sound-preview { background: linear-gradient(145deg, #69ccff, #c9f2a0); }

.preview-sound-icon {
  left: 30%;
  top: 9%;
  width: 40%;
  height: 40%;
  object-fit: contain;
  filter: drop-shadow(0 4px 4px rgba(73,42,11,.25));
}

.sound-animal {
  bottom: -5%;
  width: 43%;
  height: 57%;
  object-fit: contain;
}

.sound-animal-left { left: 5%; }
.sound-animal-right { left: auto; right: 4%; }

.challenge-card .phase-copy { background: linear-gradient(#fff5bd, #ffd76f); }
.challenge-preview { background: linear-gradient(145deg, #84ddff, #8ad56e); }

.challenge-home,
.challenge-food {
  width: 61%;
  height: 66%;
  object-fit: cover;
  border: 4px solid #fff4d3;
  border-radius: 12px;
  box-shadow: 0 5px 8px rgba(54,39,18,.28);
}

.challenge-home { left: 2%; top: 5%; transform: rotate(-7deg); }
.challenge-food { right: 2%; bottom: 4%; transform: rotate(7deg); }

.challenge-animal {
  z-index: 3;
  left: 32%;
  bottom: -6%;
  width: 40%;
  height: 67%;
  object-fit: contain;
  filter: drop-shadow(0 5px 5px rgba(49,32,12,.38));
}

.challenge-star {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 43%;
  transform: translate(-50%, -50%);
  color: #ffd62e;
  font-size: 72px;
  text-shadow: 0 4px 0 #9f5b0d, 0 0 7px white;
}

.animal-stage {
  position: absolute;
  left: 54px;
  top: 108px;
  width: 230px;
  height: 173px;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
}

.animal-stage:active { cursor: grabbing; }

.animal-halo {
  width: 74%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,245,136,.95), rgba(255,205,61,.48) 56%, transparent 74%);
  filter: drop-shadow(0 0 11px rgba(255,224,68,.9));
}

.animal-stage > img {
  position: absolute;
  max-width: 98%;
  max-height: 110%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 7px 5px rgba(70,48,20,.3));
}

.animal-stage.dragging > img { transform: scale(1.06) rotate(-2deg); }
.animal-stage.sound-mode { cursor: pointer; }
.animal-stage.sound-mode .animal-halo {
  width: 86%;
  background: radial-gradient(circle, rgba(255,245,136,.98), rgba(124,213,59,.52) 58%, transparent 75%);
}

.animal-stage .sound-stage-icon {
  width: 82%;
  height: 82%;
  max-width: none;
  max-height: none;
  filter: drop-shadow(0 8px 6px rgba(58,38,11,.3));
}

.instruction-card {
  position: absolute;
  left: 307px;
  top: 104px;
  width: 730px;
  height: 102px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border: 6px solid #fff3d3;
  border-radius: 22px;
  background: linear-gradient(#fffdf7, #ffe6ac);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.8), 0 5px 0 #d89b3a, 0 9px 14px rgba(61,78,65,.2);
  color: #4b210e;
}

.repeat-button {
  flex: 0 0 82px;
  width: 82px;
  height: 82px;
}

.instruction-copy {
  min-width: 0;
  flex: 1;
  text-align: center;
}

.instruction-copy p {
  margin: 0;
  font-size: 30px;
  font-weight: 1000;
  line-height: 1;
}

.instruction-copy small {
  display: block;
  margin-top: 7px;
  color: #7c4a2a;
  font-size: 15px;
  font-weight: 900;
}

.progress-pill {
  position: absolute;
  right: 54px;
  top: 116px;
  width: 160px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 5px solid #ffe4a7;
  border-radius: 20px;
  background: linear-gradient(#fff9e9, #f9c968);
  box-shadow: 0 5px 0 #ae6118, 0 9px 12px rgba(77,54,24,.22);
  color: #592110;
  font-size: 29px;
  font-weight: 1000;
}

.progress-pill span { color: #ffb600; text-shadow: 0 3px 0 #b66500; }

.options-grid {
  position: absolute;
  left: 205px;
  right: 205px;
  top: 248px;
  height: 360px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 32px;
}

.option-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 7px solid #fff2d3;
  border-radius: 22px;
  background: #cbeeff;
  box-shadow: 0 8px 0 #d49130, 0 13px 18px rgba(61,72,57,.25);
  touch-action: manipulation;
  transition: transform .14s ease, filter .14s ease, border-color .14s ease, box-shadow .14s ease;
}

.option-card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
}

.option-card:active,
.option-card.drag-over {
  transform: scale(.97);
  filter: saturate(1.08);
}

.option-card.correct {
  border-color: #ffe34c;
  box-shadow: 0 0 0 6px rgba(255,217,40,.55), 0 0 23px 8px rgba(255,240,91,.9), 0 8px 0 #cf8b19;
  animation: correct-pop .55s ease both;
}

.option-card.wrong { border-color: #ff6b5c; animation: wrong-shake .45s ease; }
.option-card.disabled { pointer-events: none; }

.options-grid.animal-options {
  left: 230px;
  right: 230px;
}

.option-card.animal-option { background: linear-gradient(#d9f3ff, #b9eca8); }
.option-card.animal-option img {
  object-fit: contain;
  padding: 16px;
  filter: drop-shadow(0 7px 5px rgba(56,42,19,.2));
}

.progress-track {
  position: absolute;
  left: 397px;
  bottom: 15px;
  width: 486px;
  height: 39px;
  overflow: hidden;
  border: 5px solid #fff0d1;
  border-radius: 22px;
  background: #f6dfb2;
  box-shadow: 0 4px 0 #bd731f;
}

.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, #8a2bd0, #c84dea);
  transition: width .35s ease;
}

.progress-dots {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 14px;
}

.progress-dot {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(143,83,25,.3);
  border-radius: 50%;
  background: #e7c690;
}

.progress-dot.done {
  border-color: #f3970c;
  background: #ffd22a;
  box-shadow: 0 0 7px rgba(255,216,45,.9);
}

.challenge-phase .wood-sign { background: repeating-linear-gradient(90deg, rgba(121,63,16,.13) 0 2px, transparent 2px 76px), linear-gradient(#ffd74f, #f3a623); }
.challenge-phase .progress-track { left: 345px; width: 590px; }
.challenge-phase .progress-dot { width: 12px; height: 12px; }

.feedback {
  position: absolute;
  z-index: 100;
  left: 50%;
  top: 52%;
  min-width: 260px;
  transform: translate(-50%, -50%) scale(.7);
  opacity: 0;
  pointer-events: none;
  padding: 16px 28px;
  border: 6px solid #fff4c9;
  border-radius: 22px;
  color: #fff;
  text-align: center;
  font-size: 40px;
  font-weight: 1000;
  text-shadow: 0 3px 0 rgba(73,30,6,.28);
  box-shadow: 0 8px 0 rgba(102,50,12,.32), 0 18px 28px rgba(39,49,44,.28);
}

.feedback.show { animation: feedback-in .9s ease both; }
.feedback.correct-feedback { background: linear-gradient(#80df4e, #29a93a); }
.feedback.wrong-feedback { background: linear-gradient(#ff8e73, #e04234); }

.game-overlay {
  position: absolute;
  z-index: 120;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(12,34,52,.55);
  backdrop-filter: blur(4px);
}

.overlay-card {
  width: 510px;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 28px;
  border: 7px solid #ffd76b;
  border-radius: 26px;
  background: linear-gradient(#c45cf0, #8f2bd6);
  box-shadow: inset 0 4px 0 rgba(255,255,255,.32), 0 12px 26px rgba(31,15,41,.3);
  color: #fff8f0;
  text-align: center;
}

.overlay-icon { width: 92px; height: 92px; object-fit: contain; }

.overlay-card h2 {
  margin: 8px 0 20px;
  color: #fff8f0;
  font-size: 43px;
  line-height: 1;
  text-shadow: 0 3px 0 #4d146f, 0 0 3px rgba(54,13,78,.6);
}

.overlay-card p {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 900;
  line-height: 1.15;
}

.primary-button,
.secondary-button {
  min-height: 54px;
  border: 4px solid #f1b61b;
  border-radius: 28px;
  padding: 10px 26px;
  font-weight: 1000;
  touch-action: manipulation;
}

.primary-button {
  color: #6a26a7;
  background: linear-gradient(#ffd94d, #f7b915);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.5), 0 5px 0 rgba(163,86,17,.8);
  font-size: 23px;
}

.secondary-button {
  color: #6d3513;
  background: linear-gradient(#fff5d3, #f2cf7b);
  font-size: 20px;
}

.pause-actions,
.finish-actions {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.action-with-icon {
  min-width: 190px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.action-with-icon img { width: 36px; height: 36px; object-fit: contain; }
.pause-card.menu-pause #restartButton { display: none; }

.finish-card {
  width: 570px;
  min-height: 420px;
  max-height: 620px;
}

.stars {
  color: #ffd648;
  font-size: 48px;
  line-height: 1;
  text-shadow: 0 4px 0 rgba(130,74,12,.34);
}

.finish-card h2 { margin: 10px 0; }
.finish-actions { flex-direction: column; gap: 10px; }
.finish-actions button { width: 390px; }

.drag-ghost {
  position: fixed;
  z-index: 9999999;
  width: calc(190px * var(--farm-stage-scale));
  max-width: 26vw;
  height: auto;
  transform: translate(-50%, -50%) scale(1.05);
  filter: drop-shadow(0 10px 8px rgba(48,31,9,.38));
  pointer-events: none;
}

@keyframes correct-pop {
  0% { transform: scale(.95); }
  45% { transform: scale(1.035); }
  100% { transform: scale(1.01); }
}

@keyframes wrong-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(5px); }
}

@keyframes feedback-in {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.65); }
  15%, 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(.86); }
}

@media (hover: none) {
  .phase-card:hover { filter: none; }
}

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