:root {
  --ink: #1d1612;
  --cream: #f1e4c4;
  --paper: #f4e8cc;
  --jade: #2f8a6b;
  --cobalt: #2b56a6;
  --terracotta: #c4553a;
  --mustard: #e3b93f;
  --pink: #e27d98;
  --display: 'Lilita One', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  --hand: 'Gochi Hand', 'Comic Sans MS', 'Chalkboard SE', cursive;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #16325e; color: var(--ink); font-family: var(--display); }
body.jolt { animation: jolt 0.22s ease-out; }
@keyframes jolt {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-5px, 4px) rotate(-0.3deg); }
  45% { transform: translate(4px, -3px) rotate(0.2deg); }
  70% { transform: translate(-2px, 1px); }
  100% { transform: none; }
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

.card {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px 18px 12px 16px;
  box-shadow: 4px 5px 0 var(--ink);
}
.card.small { padding: 6px 12px; font-size: 16px; }

button { font: inherit; color: inherit; cursor: pointer; }

.btn {
  font-family: var(--display);
  font-size: 20px;
  padding: 10px 22px;
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 12px 16px 12px 14px;
  box-shadow: 3px 4px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translate(-1px, -2px) rotate(-1deg); box-shadow: 4px 6px 0 var(--ink); }
.btn:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--mustard); }
.btn small { display: block; font-family: var(--hand); font-size: 14px; margin-top: -2px; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px 16px; pointer-events: none; z-index: 5;
}
#hud > * { pointer-events: auto; }
#hud .right { display: flex; gap: 10px; align-items: flex-start; }
#score { display: flex; align-items: stretch; overflow: hidden; padding: 0; }
#score .team { display: flex; flex-direction: column; align-items: center; padding: 6px 16px 4px; min-width: 96px; }
#score .team span { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; }
#score .team b { font-size: 34px; line-height: 1; font-weight: normal; }
#score .us { background: var(--jade); color: var(--cream); border-right: 3px solid var(--ink); }
#score .them { background: var(--terracotta); color: var(--cream); border-right: 3px solid var(--ink); }
#score .target { display: grid; place-items: center; padding: 0 12px; font-family: var(--hand); font-size: 18px; }
#score b.bump { animation: bump 0.4s; }
@keyframes bump { 40% { transform: scale(1.35) rotate(-6deg); } }
.icon { width: 44px; height: 44px; font-size: 24px; display: grid; place-items: center; padding: 0; }
#ends { font-size: 15px; }
#ends b { font-size: 20px; font-weight: normal; }

/* ---------- hand ---------- */
#handbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 0 16px 14px; pointer-events: none;
}
#handbar > * { pointer-events: auto; }
#turn[data-seat="0"] { background: var(--mustard); animation: nudge 1.4s infinite; }
#turn small { display: block; font-family: var(--hand); font-size: 14px; text-align: center; }
@keyframes nudge { 50% { transform: rotate(-2deg) scale(1.04); } }
#hand { display: flex; gap: 6px; min-height: 60px; justify-content: center; flex-wrap: nowrap; }
.tile {
  padding: 0; border: 0; background: none; border-radius: 10px;
  filter: drop-shadow(3px 4px 0 rgba(29, 22, 18, 0.85));
  transition: transform 0.14s cubic-bezier(.3, 1.6, .5, 1), filter 0.14s, opacity 0.2s;
  animation: dealIn 0.35s backwards; animation-delay: calc(var(--i) * 40ms);
}
.tile canvas { display: block; }
.tile.playable { transform: translateY(-10px); }
.tile.playable:hover { transform: translateY(-22px) rotate(-3deg); }
.tile.selected { transform: translateY(-30px) scale(1.08) !important; filter: drop-shadow(0 0 0 var(--ink)) drop-shadow(4px 8px 0 var(--mustard)); }
.tile.dead { opacity: 0.55; filter: grayscale(0.4) drop-shadow(2px 3px 0 rgba(29, 22, 18, 0.6)); }
.tile:disabled { cursor: default; }
@keyframes dealIn { from { transform: translateY(80px) rotate(12deg); opacity: 0; } }
#passBtn { order: -1; font-size: 26px; animation: nudge 1s infinite; }

/* ---------- markers ---------- */
#markers { position: fixed; inset: 0; pointer-events: none; z-index: 7; }
.marker {
  position: absolute; left: 0; top: 0; width: 64px; height: 64px; pointer-events: auto;
  border-radius: 50%; border: 3px solid var(--ink); background: var(--mustard);
  box-shadow: 3px 4px 0 var(--ink); display: grid; place-items: center; line-height: 1;
  animation: pulse 0.8s infinite alternate;
}
.marker span { font-family: var(--hand); font-size: 13px; }
.marker b { font-size: 24px; font-weight: normal; margin-top: -10px; }
@keyframes pulse { to { box-shadow: 3px 4px 0 var(--ink), 0 0 0 8px rgba(227, 185, 63, 0.35); } }

/* ---------- speech bubbles ---------- */
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
.bubble {
  position: absolute; left: 0; top: 0; max-width: min(340px, 70vw);
  background: #fffaf0; border: 3px solid var(--ink); border-radius: 22px 26px 22px 18px;
  padding: 10px 14px 9px; box-shadow: 4px 5px 0 var(--ink);
}
.bubble::after {
  content: ''; position: absolute; bottom: -16px; left: 50%; width: 22px; height: 18px;
  background: #fffaf0; border-right: 3px solid var(--ink); border-bottom: 3px solid var(--ink);
  transform: skewX(35deg) rotate(20deg); border-bottom-right-radius: 6px;
}
.bubble.seat3::after { left: 22%; }
.bubble.seat1::after { left: 72%; }
.bubble.pop { animation: pop 0.25s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes pop { from { scale: 0.4; opacity: 0; } }
.bubble .es { font-family: var(--display); font-size: 19px; line-height: 1.15; }
.bubble .en { font-family: var(--hand); font-size: 16px; color: #5b4a3a; margin-top: 3px; }
.bubble.seat1 { background: #eaf5ee; }
.bubble.seat2 { background: #fdeee6; }

/* ---------- fx ---------- */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.onoma {
  position: absolute; transform: translate(-50%, -50%) rotate(var(--rot));
  font-family: var(--display); font-size: 58px; color: var(--mustard);
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 4px 5px 0 var(--ink); white-space: nowrap;
  animation: onoma 0.9s ease-out forwards;
}
.onoma.big { font-size: clamp(56px, 11vw, 130px); color: var(--pink); animation-duration: 2.2s; }
@keyframes onoma {
  0% { scale: 0.2; opacity: 0; }
  12% { scale: 1.25; opacity: 1; }
  25% { scale: 1; }
  75% { opacity: 1; }
  100% { scale: 1.1; opacity: 0; translate: 0 -30px; }
}
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 4; background: #fff6d8; opacity: 0; }
#flash.go { animation: flash 0.18s ease-out; }
@keyframes flash { 0% { opacity: var(--a); } 100% { opacity: 0; } }

/* ---------- settings ---------- */
.panel { position: fixed; top: 76px; right: 16px; z-index: 20; padding: 14px 18px; width: min(300px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 8px; font-size: 17px; }
.panel h3 { margin: 0 0 4px; font-weight: normal; font-size: 24px; }
.panel label { display: flex; align-items: center; gap: 8px; }
.panel label.slider { flex-direction: column; align-items: stretch; gap: 2px; }
.panel input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--jade); }
.panel input[type="range"] { accent-color: var(--terracotta); }

/* ---------- overlay ---------- */
#overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(22, 50, 94, 0.45); backdrop-filter: blur(2px); }
#overlayBox { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px 26px; text-align: center; animation: pop 0.3s cubic-bezier(.3, 1.6, .5, 1); }
#overlayBox h1.title { font-size: clamp(56px, 12vw, 96px); margin: 0; line-height: 0.95; font-weight: normal; color: var(--terracotta); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 5px 6px 0 var(--ink); transform: rotate(-3deg); }
#overlayBox h2 { font-size: 44px; margin: 0 0 4px; font-weight: normal; color: var(--jade); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 3px 4px 0 var(--ink); }
#overlayBox .tag { font-family: var(--hand); font-size: 22px; margin: 8px 0 12px; }
#overlayBox .blurb { font-family: system-ui, sans-serif; font-size: 16px; line-height: 1.45; margin: 10px auto; max-width: 440px; }
#overlayBox .warn { font-family: var(--hand); font-size: 18px; margin: 6px 0 4px; }
#overlayBox .who { font-family: var(--hand); font-size: 22px; margin: 4px 0; }
#overlayBox .gain { font-size: 28px; margin: 4px 0 12px; }
#overlayBox .buttons { display: flex; gap: 12px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.rules { text-align: left; font-family: system-ui, sans-serif; font-size: 15px; line-height: 1.45; padding-left: 20px; }
.hands { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.hands .row { display: grid; grid-template-columns: 80px 1fr 40px; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 10px; border: 2px solid var(--ink); }
.hands .row.us { background: rgba(47, 138, 107, 0.18); }
.hands .row.them { background: rgba(196, 85, 58, 0.18); }
.hands .nm { text-align: left; }
.hands .tiles { display: flex; gap: 3px; flex-wrap: wrap; }
.hands .pts { font-size: 22px; }
.scoreline { display: flex; justify-content: center; gap: 22px; font-size: 20px; margin-top: 8px; }
.scoreline b { font-size: 30px; font-weight: normal; }
.scoreline.big b { font-size: 48px; }
.scoreline .tgt { font-family: var(--hand); align-self: center; }

@media (max-width: 640px) {
  #score .team { min-width: 70px; padding: 4px 10px; }
  #score .team b { font-size: 26px; }
  #ends { display: none; }
  #hand { gap: 3px; }
  .bubble .es { font-size: 16px; }
  .bubble .en { font-size: 14px; }
  .onoma { font-size: 40px; }
}

/* ---------- record, banner, collection, celebration ---------- */
#score { flex-wrap: wrap; max-width: 330px; }
#score .record { flex-basis: 100%; border-top: 3px solid var(--ink); padding: 3px 10px; font-size: 14px; display: flex; gap: 6px; align-items: baseline; justify-content: center; background: var(--cream); }
#score .record span { font-family: var(--hand); font-size: 15px; margin-right: 4px; }
#score .record b { font-weight: normal; font-size: 18px; }

#banner {
  position: fixed; top: 16px; left: 50%; z-index: 7; transform: translateX(-50%);
  padding: 8px 18px; text-align: center; max-width: min(560px, calc(100vw - 32px)); pointer-events: none;
}
#banner.show { animation: bannerIn 0.45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bannerIn { from { transform: translate(-50%, -60px) rotate(-3deg); opacity: 0; } }
#banner .big { display: block; font-size: 26px; line-height: 1.1; }
#banner .small { display: block; font-family: var(--hand); font-size: 17px; color: #5b4a3a; }

.flying-tile { position: fixed; z-index: 11; pointer-events: none; filter: drop-shadow(3px 4px 0 rgba(29, 22, 18, 0.8)); }
.pip-pop {
  position: fixed; z-index: 11; pointer-events: none; transform: translate(-50%, -50%);
  font-family: var(--display); font-size: 26px; color: var(--mustard); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  animation: pipPop 0.9s ease-out forwards;
}
@keyframes pipPop { 0% { scale: 0.3; opacity: 0; } 20% { scale: 1.3; opacity: 1; } 100% { translate: 0 -40px; opacity: 0; } }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 29; overflow: hidden; }
#confetti i {
  position: absolute; top: -40px; width: 12px; height: 18px; border: 2px solid var(--ink); border-radius: 2px;
  animation-name: fall; animation-timing-function: linear; animation-fill-mode: forwards;
}
#confetti i.leaf { width: 22px; height: 10px; border-radius: 100% 0; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }

#overlayBox .explain { font-family: system-ui, sans-serif; font-size: 14px; color: #5b4a3a; margin: 2px auto 8px; max-width: 460px; }
.hands .row { grid-template-columns: 70px 1fr 34px 54px; }
.hands .row em { font-style: normal; font-family: var(--hand); font-size: 16px; padding: 0 6px; border-radius: 8px; border: 2px solid var(--ink); }
.hands .row em.pays { background: var(--terracotta); color: var(--cream); }
.hands .row em.keeps { background: var(--mustard); }
.hands .row.paying .pts { color: var(--terracotta); }

.stamp {
  display: inline-block; font-size: 22px; padding: 4px 16px; border: 4px solid currentColor; border-radius: 12px;
  transform: rotate(-8deg); margin-bottom: 6px; animation: stamp 0.5s cubic-bezier(.3, 1.8, .5, 1);
}
.stamp.win { color: var(--jade); }
.stamp.lose { color: var(--terracotta); }
@keyframes stamp { from { scale: 3; opacity: 0; } }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0 6px; }
.stats .stat { border: 3px solid var(--ink); border-radius: 12px; padding: 6px 4px; background: var(--cream); }
.stats .stat b { display: block; font-size: 26px; font-weight: normal; }
.stats .stat span { font-family: var(--hand); font-size: 15px; }
.record-line { font-family: var(--hand); font-size: 18px; margin: 6px 0 0; }
.record-line b { font-family: var(--display); font-weight: normal; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------- shake the table ---------- */
#shakeWrap { position: fixed; right: 16px; bottom: 16px; z-index: 7; }
#shakeBtn { background: var(--pink); font-size: 18px; transform: rotate(2deg); }
#shakeBtn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; background: var(--cream); }
#shakeBtn:not(:disabled):hover { animation: wobble 0.35s infinite; }
@keyframes wobble { 25% { transform: rotate(-4deg) translateX(-2px); } 75% { transform: rotate(4deg) translateX(2px); } }
body.shaking { animation: bigShake 0.9s ease-out; }
@keyframes bigShake {
  10% { transform: translate(-14px, 6px) rotate(-0.8deg); } 20% { transform: translate(12px, -8px) rotate(0.7deg); }
  30% { transform: translate(-10px, 5px) rotate(-0.5deg); } 45% { transform: translate(8px, -3px); }
  60% { transform: translate(-5px, 2px); } 80% { transform: translate(2px, -1px); } 100% { transform: none; }
}
@media (max-width: 640px) { #shakeWrap { bottom: auto; top: 110px; } #shakeBtn { font-size: 15px; padding: 6px 12px; } }

/* ---------- vecinos ---------- */
.cast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.cast-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 6px 10px;
  background: var(--cream); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 3px 4px 0 var(--ink);
  font-family: var(--display); position: relative; transition: transform 0.1s;
}
.cast-card canvas { width: 96px; height: 96px; }
.cast-card b { font-size: 20px; font-weight: normal; }
.cast-card .tag { font-family: var(--hand); font-size: 14px; line-height: 1.1; }
.cast-card .tag.en { font-family: system-ui, sans-serif; font-size: 11px; color: #5b4a3a; }
.cast-card .vs { font-size: 13px; margin-top: 3px; background: var(--mustard); border: 2px solid var(--ink); border-radius: 8px; padding: 0 6px; }
.cast-card.picked { background: var(--mustard); transform: rotate(-2deg) translateY(-3px); }
.cast-card.picked::after { content: '✓'; position: absolute; top: 6px; right: 10px; font-size: 22px; }
.cast-card.locked { opacity: 0.6; cursor: not-allowed; }
.cast-card.locked canvas { filter: brightness(0) opacity(0.35); }
.cast-card .lock { font-size: 20px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.unlock-face canvas { width: 140px; height: 140px; display: block; margin: 6px auto; }
