:root {
  --cream: #fbf1dc;
  --cream2: #f6e3bf;
  --orange: #f8a94a;
  --orange-d: #e5862a;
  --red: #f0562d;
  --wood: #7a3f1d;
  --wood-d: #4d240e;
  --ink: #2d1a0e;
  --grass: #7cb342;
  --grass-d: #4f8a2a;
  --sky: #9fd8f0;
  --gold: #ffcd3c;
  --shadow: 0 6px 18px rgba(40, 20, 5, .35);
  --card-w: 112px;
  --card-h: calc(var(--card-w) * 1.5);
  --board-w: 300px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 0%, #a7d86b 0%, #6fa83a 55%, #4c7f25 100%);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
button { font-family: inherit; cursor: pointer; }
h1, h2, h3, .brand, .btn, .lilita { font-family: 'Lilita One', 'Nunito', sans-serif; font-weight: 400; letter-spacing: .5px; }

/* ---------- pantallas ---------- */
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; }

/* fondo de granja con textura */
#scr-start, #scr-end {
  align-items: center; justify-content: center; overflow-y: auto; padding: 16px;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.18) 0 60px, transparent 61px),
    radial-gradient(circle at 85% 75%, rgba(255,255,255,.12) 0 90px, transparent 91px),
    linear-gradient(180deg, #8fd3ef 0%, #c9ecf7 38%, #8cc152 38.2%, #5d9a2c 100%);
}
.start-box, .end-box {
  background: var(--cream); border-radius: 26px; padding: 22px 28px 18px;
  box-shadow: 0 14px 40px rgba(30, 15, 0, .45), inset 0 0 0 6px var(--orange);
  max-width: 820px; width: 100%; text-align: center; margin: auto;
  animation: popIn .6s cubic-bezier(.2, 1.4, .4, 1);
}
.logo h1 {
  margin: 0; font-size: clamp(40px, 7vw, 74px); line-height: .92; color: #fff;
  text-shadow: 0 4px 0 var(--orange-d), 0 8px 0 var(--wood), 0 12px 18px rgba(0,0,0,.35);
  -webkit-text-stroke: 2px var(--wood-d);
  transform: rotate(-2deg);
}
.logo-small { display: inline-block; background: var(--red); color: #fff; padding: 4px 14px; border-radius: 20px; font-weight: 900; transform: rotate(-3deg); margin-bottom: 6px; }
.tagline { font-weight: 800; margin: 12px 0 6px; }
.step-title { margin: 14px 0 8px; color: var(--wood); font-size: 20px; }
.pick-animal { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.pick-animal button {
  background: #fff; border: 4px solid transparent; border-radius: 18px; padding: 8px 8px 6px; width: 140px;
  box-shadow: var(--shadow); transition: transform .2s, border-color .2s;
}
.pick-animal button img { width: 110px; height: 110px; border-radius: 50%; display: block; margin: 0 auto 4px; }
.pick-animal button b { font-family: 'Lilita One'; font-weight: 400; font-size: 19px; display: block; }
.pick-animal button small { color: #7a5b45; font-weight: 700; }
.pick-animal button:hover { transform: translateY(-6px) rotate(-2deg); }
.pick-animal button.on { border-color: var(--red); transform: translateY(-6px) scale(1.05); }
.pick-animal button.on img { animation: wobble 1s ease-in-out infinite; }
.opts { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--cream2); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; font-weight: 900; font-size: 15px; color: var(--wood); }
.seg button.on { background: var(--orange); color: #fff; box-shadow: 0 3px 0 var(--orange-d); }
.seg button:disabled { opacity: .55; cursor: not-allowed; }
.btn {
  border: 0; border-radius: 16px; padding: 10px 26px; font-size: 22px; color: #fff;
  background: linear-gradient(180deg, #ff7a45, var(--red)); box-shadow: 0 5px 0 #b33a17, var(--shadow);
  transition: transform .12s;
}
.btn.big { font-size: 30px; padding: 12px 40px; margin-top: 18px; }
.btn:hover { transform: translateY(-2px) scale(1.03); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b33a17; }
.btn.ghost { background: var(--cream2); color: var(--wood); box-shadow: 0 5px 0 #c9a77a; }
.start-links { margin-top: 14px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.link { background: none; border: 0; font-weight: 900; color: var(--wood); font-size: 16px; padding: 6px 10px; border-radius: 10px; }
.link:hover { background: var(--cream2); }
.designer { margin: 10px 0 0; font-size: 14px; color: #8a6a4e; }

/* ---------- partida ---------- */
#scr-game {
  display: none; flex-direction: column;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.035) 0 2px, transparent 2px 60px),
    linear-gradient(180deg, #6aa636, #4f8a2a);
}
#scr-game.active { display: grid; grid-template-columns: 1fr var(--board-w); grid-template-rows: 46px 1fr; height: 100vh; }
.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 12px;
  background: linear-gradient(180deg, #8b4a22, var(--wood)); color: #fff; box-shadow: 0 3px 0 var(--wood-d);
  z-index: 5;
}
.brand { font-size: 22px; text-shadow: 0 2px 0 var(--wood-d); white-space: nowrap; }
.goal { background: var(--gold); color: var(--wood-d); font-weight: 900; padding: 3px 12px; border-radius: 12px; font-size: 14px; }
.tools { margin-left: auto; display: flex; gap: 6px; }
.tool { width: 36px; height: 34px; border-radius: 10px; border: 0; background: rgba(255,255,255,.16); font-size: 18px; }
.tool:hover { background: rgba(255,255,255,.3); }

.main-col { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.upper { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 10px; padding: 10px 10px 0; min-height: 0; }
.track-wrap {
  position: relative; border-radius: 22px; overflow: hidden; min-height: 0;
  background: #5e9c2f; box-shadow: inset 0 0 0 5px rgba(255,255,255,.25), var(--shadow);
}
#track { width: 100%; height: 100%; display: block; }
.table-center {
  display: flex; flex-direction: column; gap: 8px; min-height: 0;
  background: rgba(60, 30, 10, .28); border-radius: 18px; padding: 10px;
}
.piles { display: flex; gap: 12px; justify-content: center; }
.pile-col { text-align: center; color: #fff; font-weight: 900; text-shadow: 0 1px 2px #000; }
.pile {
  width: 74px; height: 111px; border-radius: 9px; position: relative;
  background-size: 112%; background-position: center; box-shadow: 0 4px 0 rgba(0,0,0,.25), var(--shadow);
}
.deck { background-image: url(img/dorso.jpg); }
.deck::before, .deck::after { content: ''; position: absolute; inset: 0; border-radius: 9px; background: inherit; z-index: -1; }
.deck::before { transform: translate(3px, 3px); filter: brightness(.7); }
.deck::after { transform: translate(6px, 6px); filter: brightness(.5); }
.deck span { position: absolute; bottom: -6px; right: -8px; background: var(--red); color: #fff; border-radius: 12px; padding: 1px 7px; font-size: 13px; text-shadow: none; }
.discard { background-color: rgba(255,255,255,.15); outline: 3px dashed rgba(255,255,255,.4); outline-offset: -3px; }
.discard.has { outline: 0; }
.turn-banner {
  text-align: center; font-family: 'Lilita One'; font-size: 19px; color: #fff; padding: 6px 8px; border-radius: 12px;
  background: var(--wood); box-shadow: 0 3px 0 var(--wood-d); transition: background .3s;
}
.turn-banner.mine { background: var(--red); box-shadow: 0 3px 0 #a8361a; animation: pulse 1.4s infinite; }
.log {
  list-style: none; margin: 0; padding: 6px 8px; flex: 1; min-height: 60px; overflow-y: auto;
  background: rgba(251, 241, 220, .93); border-radius: 12px; font-size: 13px; font-weight: 700;
}
.log li { padding: 3px 0; border-bottom: 1px dashed #e4cfa8; display: flex; gap: 6px; align-items: flex-start; animation: slideIn .3s; }
.log li img { width: 18px; height: 18px; border-radius: 50%; flex: none; margin-top: 1px; }
.log li.big { color: var(--red); }

/* ---------- mano ---------- */
.hand-area { position: relative; height: calc(var(--card-h) + 56px); }
.hand { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--card-h) + 40px); }
.card {
  position: absolute; width: var(--card-w); height: var(--card-h); border-radius: 10px;
  background-size: 112%; background-position: center; background-color: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,.2), 0 8px 16px rgba(0,0,0,.3);
  transition: transform .22s cubic-bezier(.2, 1.3, .5, 1), box-shadow .2s, filter .2s;
  transform: translateX(var(--x)) translateY(var(--y)) rotate(var(--r));
  left: 50%; bottom: 36px; margin-left: calc(var(--card-w) / -2);
  transform-origin: 50% 120%;
}
.hand .card.playable { cursor: pointer; }
.hand .card.playable:hover, .hand .card.playable.focus {
  transform: translateX(var(--x)) translateY(-58px) rotate(0deg) scale(1.22);
  z-index: 60 !important; box-shadow: 0 0 0 4px var(--gold), 0 18px 30px rgba(0,0,0,.45);
}
.hand .card.dim { filter: grayscale(.7) brightness(.75); }
.hand .card.forced { box-shadow: 0 0 0 4px #4cd964, 0 0 24px #4cd964; animation: zapGlow .5s infinite alternate; }
.hand .card.new { animation: dealIn .5s cubic-bezier(.2, 1.3, .5, 1); }
.card-info {
  position: absolute; left: 50%; bottom: calc(var(--card-h) + 70px); transform: translateX(-50%);
  background: var(--cream); border-radius: 14px; padding: 8px 14px; width: min(420px, 90%);
  box-shadow: var(--shadow), inset 0 0 0 3px var(--orange); text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 70;
}
.card-info.show { opacity: 1; }
.card-info b { font-family: 'Lilita One'; font-weight: 400; font-size: 19px; color: var(--red); display: block; }
.card-info span { font-size: 14px; font-weight: 700; }

/* ---------- tableros de los jugadores ---------- */
.boards { grid-row: 2; grid-column: 2; display: flex; flex-direction: column; gap: 6px; padding: 8px 8px 8px 0; overflow-y: auto; min-height: 0; }
.board {
  position: relative; width: 100%; aspect-ratio: 1100 / 751; border-radius: 14px; flex: none;
  background-size: cover; box-shadow: var(--shadow); transition: box-shadow .3s, transform .3s;
  container-type: inline-size;
}
.board.turn { box-shadow: 0 0 0 4px var(--gold), 0 0 22px var(--gold), var(--shadow); }
.board.me::after {
  content: 'TÚ'; position: absolute; top: -2px; right: 10px; background: var(--red); color: #fff; font-family: 'Lilita One';
  padding: 0 8px; border-radius: 0 0 8px 8px; font-size: 13px;
}
.board.target { cursor: pointer; animation: targetPulse .8s infinite; }
.board.target:hover { transform: scale(1.03); }
.board .name {
  position: absolute; left: 6%; top: 0; font-family: 'Lilita One'; font-size: 4.8cqw; color: var(--wood-d);
  background: var(--orange); padding: 0 8px; border-radius: 0 0 8px 8px; white-space: nowrap;
}
.board .laps-txt { position: absolute; left: 31%; top: 85%; font-family: 'Lilita One'; color: var(--red); font-size: 4.4cqw; white-space: nowrap; }
.tok {
  position: absolute; width: 9%; aspect-ratio: 1; border-radius: 50%; transform: translate(-50%, -50%);
  background-size: cover; box-shadow: 0 0 0 2px #fff, 0 3px 6px rgba(0,0,0,.5);
  transition: left .5s cubic-bezier(.4, 1.4, .5, 1), top .5s cubic-bezier(.4, 1.4, .5, 1);
  z-index: 3;
}
.tok.rec { width: 8.5%; }
.board .extras { position: absolute; left: 6%; right: 6%; top: 49%; height: 13%; display: flex; gap: 4px; align-items: center; }
.mini {
  height: 100%; aspect-ratio: 2 / 3; border-radius: 3px; background-size: 112%; background-position: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.5); position: relative; flex: none; animation: popIn .4s;
}
.mini i { position: absolute; bottom: -4px; right: -6px; background: var(--red); color: #fff; font-style: normal; font-size: 10px; font-weight: 900; border-radius: 8px; padding: 0 4px; }
.board .badge { font-size: 4cqw; }
.amplmini { margin-left: auto; }
.amplmini .tok { width: 42%; box-shadow: 0 0 0 1px #fff, 0 1px 3px rgba(0,0,0,.6); }
.badge { font-size: 12px; font-weight: 900; background: #fff; border-radius: 8px; padding: 1px 5px; box-shadow: 0 1px 3px rgba(0,0,0,.4); white-space: nowrap; animation: popIn .4s; }
.badge.ice { background: #d9f3ff; color: #1b6a96; }
.badge.stamp { background: #ffe0d6; color: #a8361a; }
.handcount { position: absolute; right: 6%; top: 11%; display: flex; align-items: center; gap: 2px; font-weight: 900; font-size: 3.8cqw; color: var(--wood-d); }
.handcount .b { width: 3.8cqw; height: 5.6cqw; border-radius: 2px; background: url(img/dorso.jpg) center/120%; box-shadow: 0 1px 2px rgba(0,0,0,.4); margin-left: -6px; }
.handcount .b.g { background-image: url(img/dorsoverde.jpg); }

/* ---------- efectos ---------- */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 80; overflow: hidden; }
.fx-p { position: absolute; left: 0; top: 0; font-size: 30px; will-change: transform, opacity; }
.flash { position: absolute; inset: 0; animation: flash .5s forwards; }
.spot { position: fixed; inset: 0; pointer-events: none; z-index: 90; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; }
.spot .big-card {
  width: 230px; height: 345px; border-radius: 18px; background-size: 112%; background-position: center;
  box-shadow: 0 0 0 5px #fff, 0 20px 60px rgba(0,0,0,.6);
}
.spot .who {
  font-family: 'Lilita One'; font-size: 26px; color: #fff; background: var(--wood); padding: 6px 20px; border-radius: 16px;
  box-shadow: 0 4px 0 var(--wood-d); text-align: center; max-width: 90vw;
}
.spot.dark { background: rgba(20, 10, 0, .35); transition: background .3s; }
.flyer { position: fixed; z-index: 95; border-radius: 10px; background-size: 112%; background-position: center; box-shadow: var(--shadow); pointer-events: none; }
.shake { animation: shake .5s; }
.bigshake { animation: bigshake .8s; }
.lap-pop {
  position: fixed; z-index: 96; font-family: 'Lilita One'; font-size: 44px; color: #fff; pointer-events: none;
  -webkit-text-stroke: 2px var(--wood-d); text-shadow: 0 4px 0 var(--orange-d);
  animation: lapPop 1.4s forwards;
}
.pick-banner {
  position: fixed; top: 54px; left: 50%; transform: translate(-50%, -200px); opacity: 0; z-index: 85; transition: transform .3s, opacity .3s;
  background: var(--red); color: #fff; padding: 8px 16px; border-radius: 14px; font-weight: 900; font-size: 17px;
  box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center;
}
.pick-banner.show { transform: translate(-50%, 0); opacity: 1; }
.pick-banner button { border: 0; background: #fff; color: var(--red); border-radius: 10px; padding: 4px 10px; font-weight: 900; }

/* ---------- ventana modal ---------- */
.modal { position: fixed; inset: 0; z-index: 120; background: rgba(20, 10, 0, .55); display: none; align-items: center; justify-content: center; padding: 16px; }
.modal.show { display: flex; }
.modal-box {
  background: var(--cream); border-radius: 22px; padding: 20px 24px; max-width: 640px; width: 100%; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 14px 40px rgba(0,0,0,.5), inset 0 0 0 5px var(--orange); animation: popIn .35s cubic-bezier(.2, 1.4, .4, 1);
}
.modal-box h2 { margin: 0 0 8px; color: var(--red); font-size: 30px; text-align: center; }
.modal-box h3 { color: var(--wood); margin: 14px 0 4px; }
.modal-box p, .modal-box li { font-weight: 700; line-height: 1.4; }
.modal-box .row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.modal-box .btn { font-size: 20px; }
.rules-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.rules-cards div { display: flex; gap: 8px; align-items: center; background: #fff; border-radius: 10px; padding: 6px; font-size: 14px; font-weight: 700; }
.rules-cards .mini { height: 60px; }
.credits-big { font-family: 'Lilita One'; font-size: 34px; color: var(--red); text-align: center; margin: 8px 0; }

/* ---------- final ---------- */
#end-title { font-size: clamp(36px, 6vw, 60px); margin: 0; color: var(--red); -webkit-text-stroke: 1px var(--wood-d); }
#end-sub { font-weight: 800; font-size: 18px; margin: 6px 0 0; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 8px; margin: 18px 0 4px; min-height: 260px; }
.podium .step { display: flex; flex-direction: column; align-items: center; width: 140px; }
.podium .step img { width: 110px; height: 110px; border-radius: 50%; box-shadow: 0 0 0 5px #fff, var(--shadow); margin-bottom: -18px; z-index: 1; animation: popIn .6s backwards; }
.podium .step .blk { width: 100%; background: linear-gradient(180deg, #9a5426, var(--wood)); color: #fff; font-family: 'Lilita One'; font-size: 40px; border-radius: 8px 8px 0 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding-top: 18px; }
.podium .step .blk small { font-family: 'Nunito'; font-size: 13px; font-weight: 800; }
.podium .step.p1 .blk { height: 165px; } .podium .step.p2 .blk { height: 135px; } .podium .step.p3 .blk { height: 110px; } .podium .step.p4 .blk { height: 92px; font-size: 30px; }
.podium .step.p1 img { width: 130px; height: 130px; animation: popIn .6s backwards, wobble 1.2s 1s infinite; }
.end-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.end-btns .btn.big { margin-top: 10px; }

/* ---------- animaciones ---------- */
@keyframes popIn { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes wobble { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg) translateY(-3px); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@keyframes slideIn { from { transform: translateX(-20px); opacity: 0; } }
@keyframes dealIn { from { transform: translateX(var(--x)) translateY(-300px) rotate(30deg); opacity: 0; } }
@keyframes zapGlow { to { box-shadow: 0 0 0 4px #b6ff5a, 0 0 40px #4cd964; } }
@keyframes targetPulse { 0%, 100% { box-shadow: 0 0 0 4px var(--red), var(--shadow); } 50% { box-shadow: 0 0 0 8px #ffb199, 0 0 26px var(--red); } }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
@keyframes shake { 0%, 100% { translate: 0 0; } 20% { translate: -8px 2px; } 40% { translate: 7px -2px; } 60% { translate: -5px 1px; } 80% { translate: 4px 0; } }
@keyframes bigshake { 0%, 100% { translate: 0 0; } 10% { translate: -16px 6px; } 25% { translate: 14px -8px; } 40% { translate: -12px 5px; } 55% { translate: 10px -4px; } 70% { translate: -6px 3px; } 85% { translate: 4px -1px; } }
@keyframes lapPop { 0% { transform: translate(-50%, -50%) scale(.2); opacity: 0; } 20% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; } 70% { transform: translate(-50%, -80%) scale(1); opacity: 1; } 100% { transform: translate(-50%, -140%) scale(.9); opacity: 0; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* ---------- pantallas pequeñas ---------- */
@media (max-height: 760px) { :root { --card-w: 92px; } .pile { width: 60px; height: 90px; } }
@media (max-width: 1100px) { :root { --board-w: 250px; } .upper { grid-template-columns: minmax(0, 1fr) 190px; } }
@media (max-width: 820px) {
  body { overflow: auto; }
  :root { --card-w: 78px; }
  #scr-game.active { display: flex; flex-direction: column; height: auto; min-height: 100vh; }
  .topbar { height: 46px; flex: none; gap: 6px; }
  .brand { font-size: 15px; }
  .goal { white-space: nowrap; font-size: 12px; padding: 2px 8px; }
  .tool { width: 30px; }
  .boards { flex-direction: row; overflow-x: auto; padding: 8px; order: 1; }
  .board { width: 230px; }
  .main-col { order: 2; }
  .upper { grid-template-columns: 1fr; }
  .track-wrap { height: 220px; }
  .table-center { flex-direction: row; flex-wrap: wrap; }
  .log { height: 90px; flex-basis: 100%; }
  .turn-banner { flex: 1; align-self: center; }
}
