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

:root {
  --accent:        #004AFF;
  --accent-hover:  #003acc;
  --bg:            #f2f2f2;
  --bg-panel:      #ffffff;
  --text:          #111827;
  --muted:         #6b7280;
  --border:        #e5e7eb;
  --attack:        #E81717;
  --attack-dark:   #b80f0f;
  --heal:          #21DB37;
  --heal-dark:     #18a829;
  --defense:       #004AFF;
  --defense-dark:  #003acc;
  --special:       #7c3aed;
  --special-dark:  #5b21b6;
  --special-light: #a78bfa;
  --winner:        #f59e0b;
  --target:        #0ea5e9;
}

body {
  font-family: 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}
body.game-hp-orange { background: #fff3e0; }
body.game-hp-red    { background: #fde8e8; }
body.game-hp-black  { background: #f0f0f0; }

#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; }

/* ── Inputs / buttons ── */
input[type="text"],
input[type="password"] {
  padding: .65rem 1rem; font-size: 1rem;
  border-radius: 8px; border: 2px solid var(--border);
  background: var(--bg-panel); color: var(--text);
  outline: none; transition: border-color .15s;
}
input[type="text"]:focus,
input[type="password"]:focus { border-color: var(--accent); }

button {
  padding: .6rem 1.4rem; font-size: .9rem;
  border: none; border-radius: 8px;
  background: var(--accent); color: #fff;
  cursor: pointer; font-weight: bold;
  transition: transform .1s, background .15s;
}
button:disabled { background: #d1d5db; color: #9ca3af; cursor: not-allowed; transform: none; }
.btn-sm { padding: .3rem .8rem; font-size: .8rem; }

/* ── Action buttons ── */
.btn-action { font-size: 1.5rem; padding: 1.1rem 2.8rem; border-radius: 16px; letter-spacing: .02em; }
#btn-draw-only   { background: transparent; }
#btn-roll-target { background: transparent; }
#btn-draw-card       { background: var(--accent); border-radius: 16px; }
#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 #585858;
  transition: border-left-color .2s;
}
.pass-btn:active .pass-arrows { transform: translateX(4px); transition: transform .1s; }
.pass-btn-label { font-size: 1rem; font-weight: bold; color: #2b2b2b; letter-spacing: .06em; text-transform: uppercase; text-align: center; }

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

#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: var(--bg-panel); border-radius: 12px; border: 2px solid var(--border);
  padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .55rem;
}
.room-panel-title { font-size: .85rem; font-weight: bold; color: var(--accent); }
.room-panel input { width: 100%; }
.toggle-label { display: flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--muted); cursor: pointer; }
.toggle-label input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }

#public-rooms-section {
  width: 100%; background: var(--bg-panel); border-radius: 12px; border: 2px solid var(--border); padding: .75rem 1rem;
}
.public-rooms-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: .9rem; font-weight: bold; color: var(--accent); margin-bottom: .5rem;
}
#rooms-list { display: flex; flex-direction: column; gap: .35rem; }
.rooms-empty { font-size: .82rem; color: #9ca3af; text-align: center; padding: .5rem; }
.room-row {
  display: flex; align-items: center; gap: .5rem;
  background: var(--bg); border-radius: 8px; border: 1px solid var(--border); padding: .4rem .75rem;
}
.room-row-name  { flex: 1; font-size: .9rem; font-weight: bold; color: var(--text); }
.room-row-meta  { font-size: .75rem; color: var(--muted); }
.room-row-status-playing { color: var(--attack); font-size: .7rem; font-weight: bold; }
.room-row-status-waiting { color: var(--heal-dark); font-size: .7rem; font-weight: bold; }
.btn-join-room  { padding: .3rem .9rem; font-size: .8rem; }

/* ── Waiting ── */
#screen-waiting { width: 100%; }
.waiting-header {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: .3rem;
  padding: .6rem; background: var(--bg-panel); border-radius: 10px; border: 2px solid var(--border);
}
.waiting-room-name { font-size: 1.3rem; font-weight: bold; color: var(--accent); }
.waiting-room-meta { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }
.room-code-label { color: #9ca3af; }
.room-code-badge {
  font-family: monospace; font-size: 1rem; font-weight: bold;
  color: var(--accent); background: rgba(0,74,255,.08);
  padding: 2px 8px; border-radius: 6px; letter-spacing: 2px;
}
.lobby-title { font-size: .9rem; font-weight: bold; color: var(--accent); width: 100%; text-align: left; }
.lobby-hint  { font-size: .75rem; color: #9ca3af; }
#lobby-player-list { list-style: none; width: 100%; display: flex; flex-direction: column; gap: .3rem; }
#lobby-player-list li {
  background: var(--bg); border-radius: 6px; border: 1px solid var(--border);
  padding: .35rem .75rem; font-size: .9rem; color: var(--text);
  display: flex; align-items: center; gap: .5rem;
}
.host-badge { font-size: .65rem; background: var(--accent); color: #fff; 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: var(--muted); }

/* ── Game ── */
#screen-game { width: 100%; gap: .5rem; }
#game-top-bar { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.btn-mute  { background: var(--bg-panel); color: var(--text); border: 2px solid var(--border); font-size: 1rem; }
.btn-voice { background: var(--bg-panel); color: var(--text); border: 2px solid var(--border); font-size: .85rem; }
.btn-voice.vc-active { background: var(--heal-dark); border-color: var(--heal); color: #fff; }

#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 ── */
.vc-mic-badge { font-size: .75rem; margin-left: .25rem; opacity: .8; transition: opacity .15s; }
.vc-mic-badge.hidden { display: none; }
.player-panel.vc-speaking { outline: 2px solid var(--heal); border-color: var(--heal) !important; }
#panel-me.vc-speaking     { outline: 2px solid var(--heal); }

.player-panel {
  width: 100%; background: var(--bg-panel); border-radius: 10px; border: 2px solid var(--border);
  padding: .5rem .9rem; display: flex; flex-direction: column; gap: .35rem;
}
.panel-row { display: flex; justify-content: space-between; align-items: center; gap: .3rem; }
.pname { font-size: 1rem; font-weight: bold; color: var(--accent); flex: 1; }
.pname.active-turn { color: var(--heal-dark); }
.cards-badge { font-size: 1rem; color: var(--muted); font-weight: 600; }

.turn-order-num {
  font-size: .72rem; font-weight: bold; color: #fff; background: #9ca3af; border-radius: 50%;
  width: 1.25rem; height: 1.25rem; display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; line-height: 1;
}
.next-target-badge { font-size: .85rem; flex-shrink: 0; animation: pulseTarget 1.2s ease-in-out infinite; }
.player-panel.next-target { border: 2px solid var(--attack); }
@keyframes pulseTarget {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .6; transform: scale(1.15); }
}

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

/* ── HP own ── */
.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: var(--text); user-select: none; line-height: 1; }
.hp-heart-icon { font-size: 4.2rem; color: var(--attack); line-height: 1; user-select: none; display: inline-block; }
.hp-own-bar-wrap { width: 90%; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.hp-own-bar { height: 100%; width: 100%; border-radius: 4px; background: var(--heal-dark); transition: width .5s ease, background .6s ease; }

.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: var(--special); color: #fff; }
.stag-draw  { background: var(--defense); color: #fff; }

.turn-badge { font-size: .8rem; padding: 3px 10px; border-radius: 10px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.turn-badge.my-turn { background: var(--accent); color: #fff; border-color: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse {
  0%,100% { outline: 0px solid transparent; }
  50%      { outline: 4px solid rgba(0,74,255,.2); outline-offset: 1px; }
}

/* ── Battle zone ── */
#battle-zone  { width: 100%; }
#die-def-box  { display: none !important; }

#phase-center { display: flex; flex-direction: column; align-items: center; gap: .5rem; width: 100%; overflow: hidden; }

#phase-top-row {
  display: flex; flex-direction: row; align-items: stretch; gap: .5rem; width: 100%;
}
#piles {
  display: flex; flex-direction: column; justify-content: center; gap: .3rem; flex-shrink: 0;
}
.pile { background: var(--bg-panel); border-radius: 8px; border: 2px solid var(--border); padding: .4rem .8rem; text-align: center; }
.pile-label { font-size: .65rem; color: #9ca3af; text-transform: uppercase; margin-bottom: 2px; }
.pile-count { font-size: 1.4rem; font-weight: bold; color: var(--accent); }

#phase-banner {
  flex: 1; display: flex; align-items: center; gap: .4rem;
  background: var(--bg-panel); border-radius: 8px; border: 2px solid var(--border);
  padding: .4rem 1rem; font-weight: bold; font-size: .95rem; color: var(--text);
}
#target-display {
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  background: var(--bg-panel); border-radius: 10px; padding: .5rem 1.2rem;
  border: 2px solid rgba(0,74,255,.2);
}
#target-display .target-label { font-size: .7rem; color: #9ca3af; text-transform: uppercase; letter-spacing: .08em; }
#target-die-result { font-size: 1.6rem; font-weight: bold; color: var(--target); text-align: center; line-height: 1.2; }
#target-names      { font-size: 1.6rem; font-weight: bold; color: var(--accent); text-align: center; line-height: 1.2; }

#dice-row { display: flex; gap: .5rem; justify-content: center; }
.die-box  { background: var(--bg-panel); border-radius: 8px; border: 2px solid var(--border); padding: .4rem .6rem; text-align: center; min-width: 70px; }
.die-label { font-size: .6rem; color: #9ca3af; text-transform: uppercase; margin-bottom: 2px; }
.die-face  { font-size: 1.3rem; font-weight: bold; color: var(--accent); 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: var(--muted); margin-bottom: .4rem; }
#target-options { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.target-btn {
  background: var(--bg-panel); color: var(--text);
  border: 2px solid var(--accent); border-radius: 12px;
  padding: .9rem 2rem; font-size: 1.25rem;
  cursor: pointer; transition: background .15s;
}

#hand-area { width: 100%; display: flex; flex-direction: row; align-items: center; justify-content: center; gap: .75rem; padding-bottom: .5rem; }
#hand {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: .4rem; width: 100%; padding: .5rem;
}

/* ── Cards ── */
.card {
  position: relative;
  width: 80px; height: 112px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-weight: bold; transition: transform .15s;
  user-select: none; cursor: pointer; border: 3px solid transparent; padding: 5px; text-align: center;
}
#hand .card { width: 100%; height: auto; aspect-ratio: 5/7; }
.card.locked     { opacity: .45; cursor: not-allowed; transform: none !important; }
.card.combo-only { opacity: .75; 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,.2);
  border-radius: 3px; padding: 1px 4px; color: #fff;
}
.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,.88); line-height: 1.2; }

.card.attack  { background: var(--attack);  color: #fff; border-color: var(--attack-dark); }
.card.heal    { background: var(--heal);    color: #063b0e; border-color: var(--heal-dark); }
.card.heal .card-label { color: rgba(0,0,0,.55); }
.card.defense { background: var(--defense); color: #fff; border-color: var(--defense-dark); }
.card.special { background: var(--special); color: #fff; border-color: var(--special-dark); }

.card-placeholder {
  width: 80px; height: 112px; border: 2px dashed #d1d5db; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; color: #d1d5db; font-size: 1.2rem;
}
#hand .card-placeholder { width: 100%; height: auto; aspect-ratio: 5/7; }

/* ── 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: var(--heal-dark); line-height: 1; transition: color .4s; }

/* ── Elimination overlay ── */
#elim-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  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: var(--bg-panel); border: 4px solid var(--attack-dark); border-radius: 20px;
  padding: 2.5rem 3.5rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}
#elim-icon  { font-size: 5rem; line-height: 1; }
#elim-name  { font-size: 2rem; font-weight: bold; color: var(--text); letter-spacing: 0.03em; }
#elim-title { font-size: 1.1rem; font-weight: bold; color: var(--attack); text-transform: uppercase; letter-spacing: 0.08em; }
#elim-sub   { font-size: 1rem; color: var(--muted); margin-top: 0.25rem; }
#elim-sub span { color: var(--attack); 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,.7);
  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: var(--bg-panel); border: 4px solid var(--winner); border-radius: 24px;
  padding: 2.5rem 3.5rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.8rem;
}
#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: var(--winner); letter-spacing: 0.03em; }
#winner-sub       { font-size: 1.05rem; color: var(--muted); }
#winner-countdown { font-size: 0.9rem; color: #9ca3af; 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); }
}

/* ── Player order overlay ── */
#player-order-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center; z-index: 9400;
}
#player-order-overlay.hidden { display: none; }
#player-order-panel {
  background: var(--bg-panel); border: 3px solid var(--heal-dark); border-radius: 20px;
  padding: 2rem 3rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
  animation: orderSlideIn 0.4s cubic-bezier(.22,1,.36,1) both;
}
@keyframes orderSlideIn {
  from { opacity: 0; transform: scale(0.82) translateY(30px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
#player-order-icon  { font-size: 3.5rem; line-height: 1; }
#player-order-title { font-size: 1.5rem; font-weight: bold; color: var(--heal-dark); margin: 0; letter-spacing: 0.03em; }
#player-order-list  { list-style: none; padding: 0; margin: 0.25rem 0 0; display: flex; flex-direction: column; gap: 0.4rem; width: 100%; }
#player-order-list li {
  display: flex; align-items: center; gap: 0.65rem;
  font-size: 1.05rem; padding: 0.35rem 0.75rem;
  background: var(--bg); border-radius: 8px; border: 1px solid var(--border); color: var(--text);
}
#player-order-list li .order-num  { font-size: 0.85rem; color: #9ca3af; min-width: 1.4rem; text-align: right; }
#player-order-list li .order-name { color: var(--text); flex: 1; text-align: left; }
#player-order-list li.order-first { background: rgba(33,219,55,.1); border-color: rgba(24,168,41,.35); }
#player-order-list li .order-me   { font-size: 0.78rem; color: var(--heal-dark); font-weight: bold; }
#player-order-countdown { font-size: 0.88rem; color: #9ca3af; margin-top: 0.25rem; }

/* ── Turn change overlay ── */
#turn-change-overlay {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(17, 24, 39, 0.93); color: #f1f5f9; 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 #f59e0b; display: none;
  box-shadow: 0 0 24px rgba(245,158,11,.35);
}
#turn-change-overlay.visible { display: block; animation: turnFadeInOut 2.5s ease-in-out forwards; }
#turn-change-name { color: #fbbf24; }
@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 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.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 var(--accent); border-radius: 14px; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: bold; color: var(--accent); backface-visibility: hidden;
}
.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); }

#btn-roll-mult.die-attack .die-btn-face { border-color: var(--attack); color: var(--attack); background: rgba(232,23,23,.04); }
#btn-roll-mult.die-heal   .die-btn-face { border-color: var(--heal);   color: var(--heal);   background: rgba(33,219,55,.04); }
.die-btn-label { font-size: 1.3rem; font-weight: bold; color: var(--accent); letter-spacing: 0.08em; text-transform: uppercase; text-align: center; width: 100%; }
#btn-roll-mult.die-attack .die-btn-label { color: var(--attack); }
#btn-roll-mult.die-heal   .die-btn-label { color: var(--heal-dark); }

.die-btn-wrap.die-target .die-btn-face  { border-color: var(--target); color: var(--target); background: rgba(14,165,233,.04); font-size: 2rem; }
.die-btn-wrap.die-target .die-btn-label { color: var(--target); }

@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 #d1d5db; background: linear-gradient(145deg, #dbeafe, #eff6ff); }
.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, #bfdbfe, #dbeafe); border-color: #93c5fd; }
.deck-btn-label { font-size: 2rem; font-weight: bold; color: white; letter-spacing: .06em; text-transform: uppercase; text-align: center; }
.deck-btn:active .deck-stack  { transform: scale(.94); transition: transform .1s; }
#btn-draw-only .deck-card-3   { background: linear-gradient(145deg, #fee2e2, #fecaca); border-color: #fca5a5; }
#btn-draw-only .deck-card-2   { background: linear-gradient(145deg, #dcfce7, #bbf7d0); border-color: #86efac; }
#btn-draw-only .deck-card-1   { background: linear-gradient(145deg, #dbeafe, #bfdbfe); border-color: #93c5fd; }
#btn-draw-only .deck-btn-label { color: var(white); }
#btn-draw-card {
  flex-direction: row; gap: 1.2rem; align-items: center; padding: 1rem 1.6rem; width: 100%;
  position: relative; overflow: hidden;
  animation: draw-glow 1.8s ease-in-out infinite;
}
#btn-draw-card::before {
  content: '';
  position: absolute; top: 0; left: 0; width: 45%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  animation: draw-shimmer 3s ease-in-out infinite;
  pointer-events: none; border-radius: 16px;
}
#btn-draw-card .deck-stack    { flex-shrink: 0; animation: draw-float 1.8s ease-in-out infinite; }
#btn-draw-card .deck-card     { border-color: rgba(255,255,255,.4); background: rgba(255,255,255,.15); }
#btn-draw-card .deck-card-1   { border-color: rgba(255,255,255,.8); background: rgba(255,255,255,.28); animation: draw-peek 3.5s ease-in-out infinite; }
#btn-draw-card .deck-btn-text  { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: .2rem; font-size: 1.8rem; font-weight: bold; color: #fff;}
#btn-draw-card .deck-btn-title { font-size: 1.7rem; font-weight: 900; color: #fff; letter-spacing: .01em; line-height: 1.1; }
#btn-draw-card .deck-btn-sub   { font-size: 1rem; color: #fff; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; }

@keyframes draw-glow {
  0%, 100% { box-shadow: 0 2px 10px rgba(0,74,255,.3); }
  50%       { box-shadow: 0 6px 32px rgba(0,74,255,.7), 0 0 0 4px rgba(0,74,255,.18); }
}
@keyframes draw-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-7px); }
}
@keyframes draw-peek {
  0%,  50%, 100% { transform: rotate(0deg) translateY(0); }
  65%             { transform: rotate(-9deg) translateY(-12px); }
  82%             { transform: rotate(3deg) translateY(-5px); }
}
@keyframes draw-shimmer {
  0%        { transform: translateX(-120%) skewX(-15deg); }
  55%, 100% { transform: translateX(280%) skewX(-15deg); }
}

/* ── Die roll overlay ── */
#die-roll-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 150;
}
#die-roll-panel {
  background: var(--bg-panel); border: 4px solid var(--accent); border-radius: 20px;
  padding: 2.5rem 4rem; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 1rem; transition: border-color .2s;
  max-width: min(500px, 92vw); width: 100%;
}
#die-roll-panel.die-attack  { border-color: var(--attack); }
#die-roll-panel.die-defense { border-color: var(--defense); }
#die-roll-panel.die-heal    { border-color: var(--heal-dark); }
#die-roll-label   { font-size: .9rem; color: #9ca3af; font-weight: bold; text-transform: uppercase; letter-spacing: 2px; }
#die-roll-context { font-size: 1.05rem; font-weight: bold; color: var(--text); letter-spacing: .03em; }
#die-roll-panel.die-attack  #die-roll-context { color: var(--attack); }
#die-roll-panel.die-defense #die-roll-context { color: var(--defense); }
#die-roll-panel.die-heal    #die-roll-context { color: var(--heal-dark); }
#die-roll-face { font-size: 7rem; font-weight: bold; color: var(--accent); line-height: 1.1; word-break: break-word; }
#die-roll-panel.die-attack  #die-roll-face { color: var(--attack); }
#die-roll-panel.die-defense #die-roll-face { color: var(--defense); }
#die-roll-panel.die-heal    #die-roll-face { color: var(--heal-dark); }
#die-roll-result { font-size: 2.2rem; font-weight: bold; color: var(--text); min-height: 1.5rem; }
#die-roll-panel.die-attack  #die-roll-result { color: var(--attack); }
#die-roll-panel.die-defense #die-roll-result { color: var(--defense); }
#die-roll-panel.die-heal    #die-roll-result { color: var(--heal-dark); }
@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 / Defense overlay ── */
#combo-overlay, #defense-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#combo-panel, #defense-panel {
  background: var(--bg-panel); 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: 3px solid var(--accent); }
#defense-panel { border: 3px solid var(--attack); }
#combo-panel h3   { font-size: 1.3rem; color: var(--accent); }
#defense-panel h3 { font-size: 1.4rem; color: var(--attack); }
#combo-cards-display { display: flex; gap: .75rem; align-items: center; justify-content: center; }
.combo-plus { font-size: 1.5rem; color: var(--accent); font-weight: bold; }
#def-info  { font-size: .9rem; color: var(--muted); }
.def-hint  { font-size: .8rem; color: #9ca3af; }

#combo-options { display: flex; flex-direction: column; gap: .45rem; width: 100%; margin-bottom: .3rem; }
.combo-option-btn {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: .5rem .85rem; border-radius: 8px; border: 2px solid var(--border);
  background: var(--bg); cursor: pointer; text-align: left; width: 100%;
  transition: background .15s, border-color .15s;
}
.combo-option-btn.direct { border-color: rgba(0,74,255,.25); }
.combo-opt-label { font-weight: bold; font-size: .9rem; color: var(--text); }
.combo-opt-desc  { font-size: .78rem; color: #9ca3af; margin-top: .1rem; }

#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-cancel { background: var(--bg); color: var(--muted); border: 2px solid var(--border); }
#btn-def-none       { background: var(--attack); color: #fff; }
#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: var(--bg); color: var(--muted); border: 2px solid var(--border); }

.btn-leave { background: rgba(232,23,23,.07); color: var(--attack); border: 2px solid var(--attack); }

/* ── End screen ── */
#screen-end h2 { font-size: 2.5rem; color: var(--accent); }
#screen-end p  { font-size: 1.2rem; color: var(--muted); }
#btn-back-menu { background: var(--bg); color: var(--text); border: 2px solid var(--border); }

/* ── Reactions ── */
#reaction-bar {
  display: flex; gap: .35rem; justify-content: center; align-items: center;
  background: var(--bg-panel); border-radius: 20px; border: 1px solid var(--border); padding: .25rem .5rem;
}

/* ── Spectator ── */
#spectator-panel {
  width: 100%; display: flex; flex-direction: column; align-items: center;
  gap: .7rem; padding: .8rem .5rem .5rem; border-top: 2px solid var(--border);
}
#spectator-title { font-size: 1rem; color: var(--muted); letter-spacing: .04em; text-align: center; }
#spectator-turn  { font-size: 1.15rem; font-weight: bold; color: var(--winner); 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: var(--bg-panel); border-radius: 10px; border: 1px solid var(--border); padding: .45rem .7rem;
}
.spec-player-name { flex: 1; font-size: 1rem; font-weight: 600; color: var(--text); }
.spec-player-name.active-turn { color: var(--winner); }
.spec-hp-text { font-size: .9rem; color: var(--muted); margin-left: auto; white-space: nowrap; }
.spec-hp-bar-wrap { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; max-width: 120px; }
.spec-hp-bar { height: 100%; border-radius: 3px; background: var(--heal-dark); transition: width .4s; }
.spec-hp-bar.low { background: var(--attack); }
.spec-hp-bar.mid { background: #f97316; }
#spectator-reaction-bar {
  display: flex; gap: .35rem; justify-content: center; align-items: center;
  background: var(--bg-panel); border-radius: 20px; border: 1px solid var(--border); padding: .25rem .5rem;
}

#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:active { transform: scale(.9); }
.reaction-btn:disabled { opacity: .35; }

.win-badge { font-size: 0.75rem; font-weight: bold; color: var(--winner); 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) {
  body { align-items: flex-start; }
  #app  { padding: .25rem; }
  button { touch-action: manipulation; }

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

  #screen-waiting { gap: .5rem; }
  #screen-game    { gap: .35rem; }

  #battle-zone { gap: .4rem; }

  #phase-top-row { gap: .35rem; }
  .pile { padding: .3rem .6rem; }
  .pile-count { font-size: 1.1rem; }

  #phase-banner { font-size: .85rem; padding: .35rem .75rem; }

  #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; }

  #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: .35rem; }


  .card-icon  { font-size: 1.5rem; }
  .card-value { font-size: 1.2rem; }
  .card-label { font-size: .6rem; }

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

  #turn-timer-wrap { padding: .2rem .5rem; }
  .die-box { min-width: 58px; padding: .3rem .4rem; }
  .die-face { font-size: 1.1rem; }

  /* Die roll overlay */
  #die-roll-panel   { padding: 1rem 1.4rem; gap: 0.45rem; }
  #die-roll-label   { font-size: 0.7rem; letter-spacing: 1px; }
  #die-roll-face    { font-size: 2.8rem; line-height: 1.2; }
  #die-roll-result  { font-size: 1.2rem; min-height: 1.2rem; }
  #die-roll-context { font-size: 0.85rem; }

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

  /* Elimination overlay */
  #elim-panel { padding: 1rem 1.4rem; }
  #elim-icon  { font-size: 2.8rem; }
  #elim-name  { font-size: 1.3rem; }
  #elim-title { font-size: 0.85rem; }
  #elim-sub   { font-size: 0.85rem; }

  /* Winner overlay */
  #winner-panel     { padding: 1.2rem 1.6rem; max-width: 88vw; }
  #winner-icon      { font-size: 3rem; }
  #winner-name      { font-size: 1.6rem; }
  #winner-sub       { font-size: 0.88rem; }
  #winner-countdown { font-size: 0.8rem; }

  /* Player order overlay */
  #player-order-panel { padding: 1rem 1.2rem; max-width: 88vw; }
  #player-order-icon  { font-size: 2.4rem; }
  #player-order-title { font-size: 1.1rem; }
  #player-order-list li { font-size: 0.85rem; padding: 0.25rem 0.6rem; gap: 0.4rem; }
  #player-order-countdown { font-size: 0.8rem; }

  /* Turn change overlay */
  #turn-change-overlay { font-size: 1.1rem; padding: 12px 20px; border-radius: 10px; }

  #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; }

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