*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', sans-serif;
  background: #060b11;
  color: #e8f5e9;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.game-hp-orange { background: #3d1a00; }
body.game-hp-red    { background: #3a0a0a; }
body.game-hp-black  { background: #0a0a0a; }

#app {
  width: 100%;
  max-width: 1000px;
  padding: 0.5rem;
  padding-left:  max(0.5rem, env(safe-area-inset-left));
  padding-right: max(0.5rem, env(safe-area-inset-right));
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}

/* ── Screens ── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; align-items: center; gap: .75rem; }
.hidden { display: none !important; }

/* ── Shared inputs / buttons ── */
input[type="text"],
input[type="password"] {
  padding: .65rem 1rem; font-size: 1rem;
  border-radius: 8px; border: none;
  background: #1a0a0e; color: #e8f5e9;
  outline: 2px solid transparent;
  transition: outline .15s;
}
input[type="text"]:focus,
input[type="password"]:focus { outline-color: #c9920e; }

button {
  padding: .6rem 1.4rem; font-size: .9rem;
  border: none; border-radius: 8px;
  background: #c9920e; color: #111;
  cursor: pointer; font-weight: bold;
  transition: transform .1s, background .15s;
}
button:hover    { background: #a87a0b; transform: translateY(-1px); }
button:disabled { background: #444; color: #777; cursor: not-allowed; transform: none; }
.btn-sm { padding: .3rem .8rem; font-size: .8rem; }

/* ── Action buttons (roll / draw / pass) ── */
.btn-action {
  font-size: 1.5rem; padding: 1.1rem 2.8rem;
  border-radius: 16px; letter-spacing: .02em;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
#btn-draw-only { background: transparent; }
#btn-roll-target { background: transparent; }
#btn-draw-card { background: #2980b9; color: #fff; }
#btn-draw-card:hover { background: #2471a3; }
#btn-roll-mult { background: transparent; }
.pass-btn {
  display: flex; flex-direction: column; align-items: center; gap: .6rem;
  cursor: pointer; user-select: none; padding: .5rem 1.5rem;
  background: transparent; border: none;
}
.pass-arrows {
  display: flex; gap: 6px; align-items: center;
}
.pass-arrow {
  width: 0; height: 0;
  border-top: 22px solid transparent;
  border-bottom: 22px solid transparent;
  border-left: 30px solid rgba(200,200,200,.45);
  transition: border-left-color .2s;
}
.pass-btn:hover .pass-arrow { border-left-color: rgba(255,255,255,.85); }
.pass-btn:hover .pass-arrow:nth-child(1) { transition-delay: 0s; }
.pass-btn:hover .pass-arrow:nth-child(2) { transition-delay: .05s; }
.pass-btn:hover .pass-arrow:nth-child(3) { transition-delay: .1s; }
.pass-btn:active .pass-arrows { transform: translateX(4px); transition: transform .1s; }
.pass-btn-label {
  font-size: 1rem; font-weight: bold; color: #aaa;
  letter-spacing: .06em; text-transform: uppercase; text-align: center;
}
.pass-btn:hover .pass-btn-label { color: #fff; }

/* ── Menu screen ── */
#logo { width: min(480px, 90vw); height: auto;}
#name-form { display: flex; gap: .5rem; }
#name-form input { width: 220px; }

/* Room panels (create + join side by side) */
#room-actions { width: 100%; display: flex; flex-direction: column; gap: 1rem; }
.room-panels { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; width: 100%; }
.room-panel {
  background: rgba(255,255,255,.06); border-radius: 12px;
  padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .55rem;
}
.room-panel-title { font-size: .85rem; font-weight: bold; color: #c9920e; }
.room-panel input { width: 100%; }
.toggle-label {
  display: flex; align-items: center; gap: .5rem;
  font-size: .85rem; color: #ccc; cursor: pointer;
}
.toggle-label input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: #c9920e; }

/* Public rooms section */
#public-rooms-section {
  width: 100%;
  background: rgba(255,255,255,.04); border-radius: 12px;
  padding: .75rem 1rem;
}
.public-rooms-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .9rem; font-weight: bold; color: #c9920e; margin-bottom: .5rem;
}
#rooms-list { display: flex; flex-direction: column; gap: .35rem; }
.rooms-empty { font-size: .82rem; color: #666; text-align: center; padding: .5rem; }
.room-row {
  display: flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.07); border-radius: 8px;
  padding: .4rem .75rem;
}
.room-row-name  { flex: 1; font-size: .9rem; font-weight: bold; }
.room-row-meta  { font-size: .75rem; color: #aaa; }
.room-row-status-playing { color: #e74c3c; font-size: .7rem; font-weight: bold; }
.room-row-status-waiting { color: #2ecc71; font-size: .7rem; font-weight: bold; }
.btn-join-room  { padding: .3rem .9rem; font-size: .8rem; }

/* ── Waiting screen ── */
#screen-waiting { width: 100%; }
.waiting-header {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  padding: .6rem; background: rgba(255,255,255,.06); border-radius: 10px;
}
.waiting-room-name { font-size: 1.3rem; font-weight: bold; color: #c9920e; }
.waiting-room-meta {
  display: flex; align-items: center; gap: .4rem;
  font-size: .85rem; color: #aaa;
}
.room-code-label { color: #888; }
.room-code-badge {
  font-family: monospace; font-size: 1rem; font-weight: bold;
  color: #fff; background: rgba(244,196,48,.2);
  padding: 2px 8px; border-radius: 6px; letter-spacing: 2px;
}
.lobby-title {
  font-size: .9rem; font-weight: bold; color: #c9920e; width: 100%; text-align: left;
}
.lobby-hint  { font-size: .75rem; color: #666; }
#lobby-player-list { list-style: none; width: 100%; display: flex; flex-direction: column; gap: .3rem; }
#lobby-player-list li {
  background: rgba(255,255,255,.08); border-radius: 6px;
  padding: .35rem .75rem; font-size: .9rem;
  display: flex; align-items: center; gap: .5rem;
}
.host-badge {
  font-size: .65rem; background: #c9920e; color: #111;
  border-radius: 8px; padding: 1px 6px; font-weight: bold;
}
#lobby-actions { display: flex; flex-direction: column; align-items: center; gap: .4rem; }
#lobby-wait-msg { font-size: .85rem; color: #888; }

/* ── Game screen ── */
#screen-game { width: 100%; gap: .5rem; }
#game-top-bar { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.btn-mute  { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.2); font-size: 1rem; }
.btn-mute:hover  { background: rgba(255,255,255,.2); }
.btn-voice { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.2); font-size: .85rem; }
.btn-voice:hover { background: rgba(255,255,255,.2); }
.btn-voice.vc-active { background: #27ae60; border-color: #2ecc71; color: #fff; }
.btn-voice.vc-active:hover { background: #2ecc71; }

#opponents-row { width: 100%; display: flex; gap: .5rem; flex-wrap: wrap; }
#opponents-row .player-panel { flex: 1 1 200px; }
.player-panel.eliminated { opacity: .35; }

/* ── Voice chat indicators ── */
.vc-mic-badge {
  font-size: .75rem;
  margin-left: .25rem;
  opacity: .8;
  transition: opacity .15s;
}
.vc-mic-badge.hidden { display: none; }
@keyframes vcPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(46,204,113,.6); }
  50%      { box-shadow: 0 0 0 6px rgba(46,204,113,0); }
}
.player-panel.vc-speaking { animation: vcPulse .6s ease-in-out infinite; border-color: #2ecc71 !important; }
#panel-me.vc-speaking     { animation: vcPulse .6s ease-in-out infinite; }

.player-panel {
  width: 100%;
  background: rgba(255,255,255,.06); border-radius: 10px;
  padding: .5rem .9rem; display: flex; flex-direction: column; gap: .35rem;
}
.panel-row { display: flex; justify-content: space-between; align-items: center; }
.pname { font-size: 1rem; font-weight: bold; color: #c9920e; }
.pname.active-turn { color: #2ecc71; }
.cards-badge { font-size: 1rem; color: #ccc; font-weight: 600; }

/* ── HP display (opponents) ── */
.hp-wrap {
  display: flex; align-items: center; gap: .4rem;
}
.hp-bar { display: none; }
.hp-text {
  font-size: 1.4rem; font-weight: bold; color: #27ae60;
  line-height: 1;
}
.hp-text.mid { color: #e67e22; }
.hp-text.low { color: #e74c3c; }

/* ── HP display (own player) ── */
.my-hp-section {
  display: flex; flex-direction: column; align-items: center; gap: .4rem;
  width: 100%;
}
.hp-heart-wrap {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .2rem 0;
}
.hp-heart-val {
  font-size: 3.2rem; font-weight: bold; color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,.9);
  user-select: none; line-height: 1;
}
.hp-heart-icon {
  font-size: 4.2rem; color: #fff; line-height: 1;
  user-select: none; display: inline-block;
}
.hp-own-bar-wrap {
  width: 90%; height: 8px;
  background: rgba(255,255,255,.15); border-radius: 4px; overflow: hidden;
}
.hp-own-bar {
  height: 100%; width: 100%; border-radius: 4px;
  background: #27ae60;
  transition: width .5s ease, background .6s ease;
}
/* Heartbeat animations — speed increases as HP drops */
.hp-heart-icon.beat-slow   { animation: heartbeat 1.6s ease-in-out infinite; }
.hp-heart-icon.beat-medium { animation: heartbeat 1.0s ease-in-out infinite; }
.hp-heart-icon.beat-fast   { animation: heartbeat 0.55s ease-in-out infinite; }
.hp-heart-icon.beat-danger { animation: heartbeat 0.3s ease-in-out infinite; }
@keyframes heartbeat {
  0%   { transform: scale(1); }
  20%  { transform: scale(1.25); }
  35%  { transform: scale(1); }
  50%  { transform: scale(1.15); }
  65%  { transform: scale(1); }
  100% { transform: scale(1); }
}

.status-row { display: flex; gap: .35rem; flex-wrap: wrap; min-height: 20px; }
.stag { font-size: .7rem; padding: 2px 7px; border-radius: 10px; font-weight: bold; }
.stag-redir { background: #6a1b9a; color: #fff; }

.turn-badge { font-size: .8rem; padding: 3px 10px; border-radius: 10px; background: rgba(255,255,255,.1); color: #aaa; }
.turn-badge.my-turn { background: #c9920e; color: #111; animation: pulse 1.2s infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(244,196,48,.5); }
  50%      { box-shadow: 0 0 0 6px rgba(244,196,48,0); }
}

/* Battle zone */
#battle-zone {
  width: 100%; display: grid;
  grid-template-columns: 100px 1fr 200px;
  gap: .75rem; align-items: start;
}
#piles { display: flex; flex-direction: column; gap: .5rem; }
.pile { background: rgba(255,255,255,.07); border-radius: 8px; padding: .4rem .6rem; text-align: center; }
.pile-label { font-size: .65rem; color: #888; text-transform: uppercase; margin-bottom: 2px; }
.pile-count { font-size: 1.4rem; font-weight: bold; color: #c9920e; }

#phase-center { display: flex; flex-direction: column; align-items: center; gap: .5rem; width: 100%; overflow: hidden; }
#phase-banner {
  display: flex; align-items: center; gap: .4rem;
  background: rgba(0,0,0,.4); border-radius: 8px;
  padding: .4rem 1rem; font-weight: bold; font-size: .95rem;
}
#target-display {
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  background: rgba(0,0,0,.35); border-radius: 10px; padding: .5rem 1.2rem;
  border: 1px solid rgba(201,146,14,.25);
}
#target-display .target-label { font-size: .7rem; color: #888; text-transform: uppercase; letter-spacing: .08em; }
#target-die-result { font-size: 1.6rem; font-weight: bold; color: #1ac8d4; text-align: center; line-height: 1.2; }
#target-names { font-size: 1.6rem; font-weight: bold; color: #c9920e; text-align: center; line-height: 1.2; }

#dice-row { display: flex; gap: .5rem; justify-content: center; }
.die-box { background: rgba(255,255,255,.07); border-radius: 8px; padding: .4rem .6rem; text-align: center; min-width: 70px; }
.die-label { font-size: .6rem; color: #888; text-transform: uppercase; margin-bottom: 2px; }
.die-face { font-size: 1.3rem; font-weight: bold; color: #c9920e; min-height: 1.6rem; display: flex; align-items: center; justify-content: center; }
@keyframes dieRoll {
  0%   { transform: scale(1.6) rotate(-25deg); opacity: 0.15; }
  45%  { transform: scale(1.15) rotate(12deg); opacity: 0.75; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
.die-face.rolling { animation: dieRoll 0.55s ease-out; }

#target-selector p { font-size: .85rem; color: #ccc; margin-bottom: .4rem; }
#target-options { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.target-btn {
  background: rgba(255,255,255,.1); color: #fff;
  border: 2px solid #c9920e; border-radius: 12px;
  padding: .9rem 2rem; font-size: 1.25rem;
  cursor: pointer; transition: background .15s;
}
.target-btn:hover { background: rgba(244,196,48,.2); }


#hand-area { width: 100%; display: flex; flex-direction: column; align-items: center; gap: .5rem; padding-bottom: .5rem; }
#hand {
  display: flex; gap: .4rem; flex-wrap: nowrap;
  width: 100%; overflow-x: auto; overflow-y: visible;
  justify-content: flex-start; padding: 1.5rem .75rem 1rem;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
#hand::-webkit-scrollbar { display: none; }

/* ── Cards ── */
.card {
  position: relative;
  width: 100px; height: 140px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-weight: bold; box-shadow: 2px 3px 8px rgba(0,0,0,.5);
  transition: transform .15s, box-shadow .15s;
  user-select: none; cursor: pointer; border: 2px solid transparent; padding: 5px; text-align: center;
}
.card:hover         { transform: translateY(-14px) scale(1.04); box-shadow: 4px 10px 16px rgba(0,0,0,.6); }
.card.locked        { opacity: .45; cursor: not-allowed; transform: none !important; box-shadow: 2px 3px 8px rgba(0,0,0,.5); }
.card.combo-only    { opacity: .6; cursor: default; border-style: dashed; transform: none !important; }
.card.combo-only::after {
  content: 'COMBO'; position: absolute; bottom: 3px;
  font-size: .5rem; letter-spacing: 1px; background: rgba(0,0,0,.5);
  border-radius: 3px; padding: 1px 4px; color: #c9920e;
}

.card-icon  { font-size: 1.9rem; line-height: 1; }
.card-value { font-size: 1.5rem; }
.card-label { font-size: .72rem; color: rgba(255,255,255,.85); line-height: 1.2; }

.card.attack  { background: linear-gradient(160deg,#7b1c1c,#c0392b); color:#fff; border-color:#e74c3c; }
.card.heal    { background: linear-gradient(160deg,#145214,#27ae60); color:#fff; border-color:#2ecc71; }
.card.defense { background: linear-gradient(160deg,#0d3b6e,#1565c0); color:#fff; border-color:#3498db; }
.card.special { background: linear-gradient(160deg,#4a148c,#8e24aa); color:#fff; border-color:#ab47bc; }

.card-placeholder {
  width: 100px; height: 140px; border: 2px dashed rgba(255,255,255,.2); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,.3); font-size: 1.2rem;
}

/* ── Turn timer ── */
#turn-timer-wrap { display: flex; justify-content: center; align-items: center; }
#turn-timer-bar  { display: none; }
#turn-timer-text { font-size: 3rem; font-weight: bold; color: #27ae60; line-height: 1; transition: color .4s; }

/* ── Elimination overlay ── */
#elim-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.82);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000; pointer-events: none;
  display: none;
}
#elim-overlay.visible { display: flex; animation: elimFade 3.5s ease-in-out forwards; }
#elim-panel {
  background: #130508; border: 3px solid #c0392b; border-radius: 20px;
  padding: 2.5rem 3.5rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
  box-shadow: 0 0 60px rgba(192,57,43,.5);
}
#elim-icon  { font-size: 5rem; line-height: 1; }
#elim-name  { font-size: 2rem; font-weight: bold; color: #fff; letter-spacing: 0.03em; }
#elim-title { font-size: 1.1rem; font-weight: bold; color: #e74c3c; text-transform: uppercase; letter-spacing: 0.08em; }
#elim-sub   { font-size: 1rem; color: #bbb; margin-top: 0.25rem; }
#elim-sub span { color: #e74c3c; font-weight: bold; }
@keyframes elimFade {
  0%   { opacity: 0; transform: scale(0.8); }
  10%  { opacity: 1; transform: scale(1.05); }
  20%  { opacity: 1; transform: scale(1); }
  75%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.95); }
}

/* ── Winner overlay ── */
#winner-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.88);
  display: none; align-items: center; justify-content: center;
  z-index: 9500;
}
#winner-overlay.visible { display: flex; animation: winnerFade 7.5s ease-in-out forwards; }
#winner-panel {
  background: linear-gradient(160deg, #1a1200, #2a1f00);
  border: 3px solid #f1c40f; border-radius: 24px;
  padding: 2.5rem 3.5rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.8rem;
  box-shadow: 0 0 80px rgba(241,196,15,.35);
}
#winner-icon { font-size: 5rem; line-height: 1; animation: trophyBounce 0.6s ease-out 0.3s both; }
#winner-name { font-size: 2.4rem; font-weight: bold; color: #f1c40f; letter-spacing: 0.03em; }
#winner-sub  { font-size: 1.05rem; color: #ccc; }
#winner-countdown { font-size: 0.9rem; color: #888; margin-top: 0.5rem; }
@keyframes winnerFade {
  0%   { opacity: 0; transform: scale(0.8); }
  8%   { opacity: 1; transform: scale(1.04); }
  15%  { opacity: 1; transform: scale(1); }
  80%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.95); }
}
@keyframes trophyBounce {
  0%   { transform: scale(0) rotate(-15deg); }
  60%  { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* ── Turn change overlay ── */
#turn-change-overlay {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.88);
  color: #fff; padding: 18px 40px; border-radius: 14px;
  font-size: 1.5rem; font-weight: bold; z-index: 10000;
  pointer-events: none; text-align: center;
  border: 2px solid rgba(244,196,48,.5);
  display: none;
}
#turn-change-overlay.visible {
  display: block;
  animation: turnFadeInOut 2.5s ease-in-out forwards;
}
#turn-change-name { color: #c9920e; }
@keyframes turnFadeInOut {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
  12%  { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
}

/* ── Dado multiplicador — botón interactivo 3D ── */
.die-btn-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 1.4rem;
  cursor: pointer; padding: 0.75rem 1rem;
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.die-btn-scene {
  width: 90px; height: 90px;
  perspective: 300px;
}
.die-btn-cube {
  width: 90px; height: 90px;
  position: relative;
  transform-style: preserve-3d;
  animation: die-btn-float 2.8s ease-in-out infinite;
  transition: transform 0.25s ease;
}
.die-btn-wrap:hover .die-btn-cube {
  animation: none;
  transform: rotateX(-20deg) rotateY(50deg) scale(1.1);
}
.die-btn-wrap.clicked .die-btn-cube {
  animation: die-btn-click 0.4s ease-in forwards !important;
}
.die-btn-face {
  position: absolute;
  width: 90px; height: 90px;
  border: 2.5px solid #c9920e;
  border-radius: 14px;
  background: #1a0a10;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: bold; color: #c9920e;
  backface-visibility: hidden;
  box-shadow: inset 0 0 18px rgba(200,146,14,.25);
  text-shadow: 0 0 14px rgba(200,146,14,.65);
}
/* face positions — half-size = 45px */
.die-btn-cube .face-front  { transform: rotateY(0deg)    translateZ(45px); }
.die-btn-cube .face-back   { transform: rotateY(180deg)  translateZ(45px); }
.die-btn-cube .face-right  { transform: rotateY(90deg)   translateZ(45px); }
.die-btn-cube .face-left   { transform: rotateY(-90deg)  translateZ(45px); }
.die-btn-cube .face-top    { transform: rotateX(90deg)   translateZ(45px); }
.die-btn-cube .face-bottom { transform: rotateX(-90deg)  translateZ(45px); }
/* attack — rojo */
#btn-roll-mult.die-attack .die-btn-face {
  border-color: #e74c3c; color: #e74c3c;
  box-shadow: inset 0 0 18px rgba(231,76,60,.25);
  text-shadow: 0 0 14px rgba(231,76,60,.65);
}
/* heal — verde */
#btn-roll-mult.die-heal .die-btn-face {
  border-color: #2ecc71; color: #2ecc71;
  box-shadow: inset 0 0 18px rgba(46,204,113,.25);
  text-shadow: 0 0 14px rgba(46,204,113,.65);
}
.die-btn-label {
  font-size: 1.3rem; font-weight: bold; color: #c9920e;
  letter-spacing: 0.08em; text-transform: uppercase;
  text-align: center; width: 100%;
}
#btn-roll-mult.die-attack .die-btn-label { color: #e74c3c; }
#btn-roll-mult.die-heal   .die-btn-label { color: #2ecc71; }
/* dado objetivo — celeste */
.die-btn-wrap.die-target .die-btn-face {
  border-color: #1ac8d4; color: #1ac8d4;
  box-shadow: inset 0 0 18px rgba(26,200,212,.25);
  text-shadow: 0 0 14px rgba(26,200,212,.65);
  font-size: 2rem;
}
.die-btn-wrap.die-target .die-btn-label { color: #1ac8d4; }
@keyframes die-btn-float {
  0%, 100% { transform: rotateX(-20deg) rotateY(20deg) translateY(0px); }
  50%       { transform: rotateX(-20deg) rotateY(20deg) translateY(-8px); }
}
@keyframes die-btn-click {
  0%   { transform: rotateX(-20deg) rotateY(20deg) scale(1);    opacity: 1; }
  40%  { transform: rotateX(160deg) rotateY(220deg) scale(1.2); opacity: 1; }
  100% { transform: rotateX(360deg) rotateY(480deg) scale(0.3); opacity: 0; }
}

/* ── Deck button ── */
.deck-btn {
  display: flex; flex-direction: column; align-items: center; gap: .7rem;
  cursor: pointer; user-select: none; padding: .5rem 1.5rem;
  background: transparent; border: none;
}
.deck-stack {
  position: relative; width: 72px; height: 96px;
}
.deck-card {
  position: absolute;
  width: 72px; height: 96px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,.35);
  background: linear-gradient(145deg, #2c3e6b, #1a2540);
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
}
.deck-card-3 { transform: rotate(-6deg) translate(-5px, 4px); }
.deck-card-2 { transform: rotate(-2deg) translate(-2px, 2px); }
.deck-card-1 { transform: rotate(0deg);
  background: linear-gradient(145deg, #3a5090, #233066);
  border-color: rgba(255,255,255,.55);
}
.deck-btn-label {
  font-size: 1rem; font-weight: bold; color: #c9d6ff;
  letter-spacing: .06em; text-transform: uppercase; text-align: center;
}
.deck-btn:hover .deck-card-1 { transform: rotate(0deg) translateY(-6px); transition: transform .2s; }
.deck-btn:active .deck-stack { transform: scale(.94); transition: transform .1s; }
#btn-draw-only .deck-card-3 { background: linear-gradient(145deg, #a02020, #6b1010); border-color: rgba(255,100,100,.6); }
#btn-draw-only .deck-card-2 { background: linear-gradient(145deg, #1a8a3a, #0f5522); border-color: rgba(80,220,120,.6); }
#btn-draw-only .deck-card-1 { background: linear-gradient(145deg, #1a8aaa, #0f4d66); border-color: rgba(80,210,255,.6); }
#btn-draw-only .deck-btn-label { color: #88ccff; }
#btn-draw-card .deck-card-1 { border-color: rgba(80,170,255,.7); background: linear-gradient(145deg, #1a5a9e, #0f2e5c); }
#btn-draw-card .deck-btn-label { color: #88ccff; }

/* ── Die roll overlay ── */
#die-roll-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center; z-index: 150;
}
#die-roll-panel {
  background: #130508; border: 3px solid #c9920e; border-radius: 20px;
  padding: 2.5rem 4rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
  box-shadow: 0 0 40px rgba(200,146,14,.3);
  transition: border-color .2s, box-shadow .2s;
}
#die-roll-panel.die-attack  { border-color: #e74c3c; box-shadow: 0 0 40px rgba(231,76,60,.4); }
#die-roll-panel.die-defense { border-color: #3498db; box-shadow: 0 0 40px rgba(52,152,219,.4); }
#die-roll-panel.die-heal    { border-color: #2ecc71; box-shadow: 0 0 40px rgba(46,204,113,.4); }
#die-roll-label { font-size: .9rem; color: #aaa; font-weight: bold; text-transform: uppercase; letter-spacing: 2px; }
#die-roll-context { font-size: 1.05rem; font-weight: bold; color: #ddd; letter-spacing: .03em; }
#die-roll-panel.die-attack  #die-roll-context { color: #f1948a; }
#die-roll-panel.die-defense #die-roll-context { color: #7fb3d3; }
#die-roll-panel.die-heal    #die-roll-context { color: #82e0aa; }
#die-roll-face  { font-size: 7rem; font-weight: bold; color: #c9920e; line-height: 1; text-shadow: 0 0 40px rgba(200,146,14,.8); }
#die-roll-panel.die-attack  #die-roll-face { color: #e74c3c; text-shadow: 0 0 40px rgba(231,76,60,.8); }
#die-roll-panel.die-defense #die-roll-face { color: #3498db; text-shadow: 0 0 40px rgba(52,152,219,.8); }
#die-roll-panel.die-heal    #die-roll-face { color: #2ecc71; text-shadow: 0 0 40px rgba(46,204,113,.8); }
#die-roll-result { font-size: 2.2rem; font-weight: bold; color: #ccc; min-height: 1.5rem; }
#die-roll-panel.die-attack  #die-roll-result { color: #e74c3c; }
#die-roll-panel.die-defense #die-roll-result { color: #3498db; }
#die-roll-panel.die-heal    #die-roll-result { color: #2ecc71; }
@keyframes dieResultIn {
  0%   { opacity: 0; transform: scale(0.6); }
  60%  { opacity: 1; transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}
#die-roll-panel.result-in #die-roll-face,
#die-roll-panel.result-in #die-roll-result { animation: dieResultIn 0.45s cubic-bezier(.25,.46,.45,.94) both; }
#die-roll-panel.result-in #die-roll-result { animation-delay: 0.12s; }

/* ── Combo overlay ── */
#combo-overlay, #defense-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#combo-panel, #defense-panel {
  background: #130508; border-radius: 14px; padding: 1.5rem;
  max-width: 480px; width: 90%;
  display: flex; flex-direction: column; align-items: center; gap: .75rem; text-align: center;
}
#combo-panel   { border: 2px solid #c9920e; }
#defense-panel { border: 2px solid #3498db; }
#combo-panel h3   { font-size: 1.3rem; color: #c9920e; }
#defense-panel h3 { font-size: 1.4rem; color: #e74c3c; }
#combo-cards-display { display: flex; gap: .75rem; align-items: center; justify-content: center; }
.combo-plus { font-size: 1.5rem; color: #c9920e; font-weight: bold; }
#combo-desc, #def-info { font-size: .9rem; color: #ccc; }
.def-hint { font-size: .8rem; color: #888; }
#combo-actions, #def-actions { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center; }
#def-cards { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
#btn-combo-yes    { background: #27ae60; color: #fff; }
#btn-combo-yes:hover { background: #219653; }
#btn-combo-no     { background: #2980b9; color: #fff; }
#btn-combo-no:hover  { background: #1f6fa0; }
#btn-combo-cancel { background: #555; color: #ccc; }
#btn-def-none     { background: #c0392b; color: #fff; }
#btn-def-none:hover { background: #a93226; }
#def-redirect-section { display: flex; flex-direction: column; align-items: center; gap: .5rem; width: 100%; }
#def-redirect-targets { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
#btn-def-redirect-back { background: rgba(255,255,255,.15); color: #ccc; }

.btn-leave { background: rgba(231,76,60,.25); color: #e74c3c; border: 1px solid #e74c3c; }
.btn-leave:hover { background: rgba(231,76,60,.45); }

/* ── End screen ── */
#screen-end h2 { font-size: 2.5rem; color: #c9920e; }
#screen-end p  { font-size: 1.2rem; color: #ccc; }
#btn-back-menu { background: rgba(255,255,255,.15); color: #ccc; }
#btn-back-menu:hover { background: rgba(255,255,255,.25); }

/* ── Reactions ── */
#reaction-bar {
  display: flex; gap: .35rem; justify-content: center; align-items: center;
  background: rgba(255,255,255,.05); border-radius: 20px;
  padding: .25rem .5rem;
}

/* ── Spectator panel (eliminated players) ── */
#spectator-panel {
  width: 100%; display: flex; flex-direction: column; align-items: center;
  gap: .7rem; padding: .8rem .5rem .5rem;
  border-top: 1px solid rgba(255,255,255,.1);
}
#spectator-title {
  font-size: 1rem; color: #aaa; letter-spacing: .04em; text-align: center;
}
#spectator-turn {
  font-size: 1.15rem; font-weight: bold; color: #f1c40f; text-align: center;
  min-height: 1.4em;
}
#spectator-players {
  width: 100%; display: flex; flex-direction: column; gap: .5rem;
}
.spec-player-row {
  display: flex; align-items: center; gap: .6rem;
  background: rgba(255,255,255,.05); border-radius: 10px;
  padding: .45rem .7rem;
}
.spec-player-name {
  flex: 1; font-size: 1rem; font-weight: 600; color: #ecf0f1;
}
.spec-player-name.active-turn { color: #f1c40f; }
.spec-hp-text { font-size: .9rem; color: #bbb; margin-left: auto; white-space: nowrap; }
.spec-hp-bar-wrap { flex: 1; height: 6px; background: rgba(255,255,255,.12); border-radius: 3px; overflow: hidden; max-width: 120px; }
.spec-hp-bar { height: 100%; border-radius: 3px; background: #27ae60; transition: width .4s; }
.spec-hp-bar.low { background: #c0392b; }
.spec-hp-bar.mid { background: #d35400; }
#spectator-reaction-bar {
  display: flex; gap: .35rem; justify-content: center; align-items: center;
  background: rgba(255,255,255,.05); border-radius: 20px;
  padding: .25rem .5rem;
}

/* When spectating: hide normal player panel and hand */
#screen-game.spectating #panel-me { display: none; }
#screen-game.spectating #hand-area { display: none; }
#screen-game.spectating #hand { display: none; }
.reaction-btn {
  background: transparent; border: none;
  font-size: 2rem; padding: .2rem .4rem; border-radius: 8px;
  cursor: pointer; line-height: 1;
  transition: transform .12s, background .12s;
}
.reaction-btn:hover  { background: rgba(255,255,255,.12); transform: scale(1.25); }
.reaction-btn:active { transform: scale(.9); }
.reaction-btn:disabled { opacity: .35; }

.win-badge {
  font-size: 0.75rem; font-weight: bold; color: #f1c40f;
  vertical-align: middle; margin-left: 3px; white-space: nowrap;
}

.reaction-display {
  font-size: 2.2rem; min-width: 2rem; text-align: center; line-height: 1;
  display: inline-block;
  opacity: 0; transform: scale(.4) translateY(4px);
  transition: opacity .18s, transform .18s;
}
.reaction-display.active {
  opacity: 1; transform: scale(1) translateY(0);
  animation: reactionPop .28s ease-out;
}
@keyframes reactionPop {
  0%   { transform: scale(.3) translateY(6px); opacity: 0; }
  60%  { transform: scale(1.35) translateY(-2px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {

  /* Global */
  body { align-items: flex-start; }
  #app { padding: .25rem; }
  button { touch-action: manipulation; }

  /* Menu */
  #screen-menu h1 { font-size: 2rem; }
  #name-form { flex-direction: column; width: 100%; }
  #name-form input { width: 100%; }
  .room-panels { grid-template-columns: 1fr; }

  /* Waiting */
  #screen-waiting { gap: .5rem; }

  /* Game screen — battle zone becomes single column */
  #screen-game { gap: .35rem; }
  .card:hover { transform: none; box-shadow: 2px 3px 8px rgba(0,0,0,.5); }

  #battle-zone {
    grid-template-columns: 1fr;
    gap: .4rem;
  }

  /* Piles (deck + discard): horizontal strip, order 2 */
  #piles {
    order: 2;
    flex-direction: row;
    justify-content: center;
    gap: .75rem;
  }
  .pile { min-width: 64px; }
  .pile-count { font-size: 1.1rem; }

  /* Phase center: order 1 — most important, stays on top */
  #phase-center { order: 1; }
  #phase-banner { font-size: .85rem; padding: .35rem .75rem; }

  /* Opponents row: compact panels, horizontal scroll if many */
  #opponents-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: .25rem;
    scrollbar-width: none;
    gap: .35rem;
  }
  #opponents-row::-webkit-scrollbar { display: none; }
  #opponents-row .player-panel { flex: 0 0 150px; }

  /* My panel: more compact */
  #panel-me { padding: .4rem .7rem; }
  .pname { font-size: .9rem; }
  .hp-text { font-size: 1.2rem; }
  .hp-heart-val { font-size: 2.4rem; }
  .hp-heart-icon { font-size: 3.2rem; }

  #hand { gap: .35rem; padding: .25rem .5rem .75rem; }

  /* Cards: slightly smaller on mobile */
  .card, .card-placeholder {
    width: 82px;
    height: 116px;
    flex-shrink: 0;
  }
  .card-icon  { font-size: 1.5rem; }
  .card-value { font-size: 1.2rem; }
  .card-label { font-size: .6rem; }

  /* Discard card */
  #discard-card .card,
  #discard-card .card-placeholder { width: 50px; height: 72px; }

  /* Turn timer */
  #turn-timer-wrap { padding: .2rem .5rem; }

  /* Dice row: smaller */
  .die-box { min-width: 58px; padding: .3rem .4rem; }
  .die-face { font-size: 1.1rem; }

  /* Die roll overlay */
  #die-roll-panel { padding: 1.5rem 2rem; }
  #die-roll-face  { font-size: 6rem; }
  #die-roll-result { font-size: 1.6rem; }

  /* Combo & defense overlays */
  #combo-panel, #defense-panel {
    width: 96%;
    padding: 1rem;
    max-height: 88vh;
    overflow-y: auto;
  }
  #combo-panel h3   { font-size: 1.1rem; }
  #defense-panel h3 { font-size: 1.2rem; }

  /* Elim / turn-change overlays */
  #elim-panel { padding: 1.5rem 2rem; }
  #elim-icon  { font-size: 3.5rem; }
  #elim-name  { font-size: 1.5rem; }
  #elim-title { font-size: 0.95rem; }
  #turn-change-overlay { font-size: 1.2rem; padding: 14px 24px; }

  /* Target & action buttons: full width on small screens */
  #target-options, #combo-actions, #def-actions { flex-direction: column; align-items: stretch; }
  .target-btn { text-align: center; }
  #def-redirect-targets { flex-direction: column; align-items: stretch; }
  .btn-action { width: 100%; font-size: 1.15rem; padding: .9rem 1rem; }

  /* End screen */
  #screen-end h2 { font-size: 1.8rem; }
  #screen-end p  { font-size: 1rem; }
}
