:root {
  --bg: #0b0d12;
  --panel: #12161f;
  --panel2: #1a2030;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #3b82f6;
  --gold: #fbbf24;
  --purple: #a855f7;
  --blue: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2744 0%, var(--bg) 55%);
  color: var(--text);
}

#tcgApp {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.tcg-kicker { color: var(--muted); font-size: 0.8rem; letter-spacing: 0.08em; text-transform: uppercase; margin: 0 0 6px; }
.tcg-title { font-size: 1.8rem; margin: 0 0 18px; }
.tcg-hint { color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.tcg-sub { margin: 18px 0 10px; font-size: 1rem; color: var(--muted); }

.tcg-kpi {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.tcg-kpi > div {
  background: var(--panel);
  border: 1px solid #243044;
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.tcg-kpi span { display: block; color: var(--muted); font-size: 0.75rem; margin-bottom: 4px; }
.tcg-kpi strong { font-size: 1.35rem; }

.tcg-actions-col { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.tcg-actions-row { display: flex; flex-wrap: wrap; gap: 10px; }

.tcg-btn {
  border: 1px solid #334155;
  background: var(--panel2);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s, background .15s, border-color .15s;
}
.tcg-btn:hover { border-color: #64748b; transform: translateY(-1px); }
.tcg-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.tcg-btn.primary { background: linear-gradient(135deg, #2563eb, #7c3aed); border-color: transparent; }
.tcg-btn.ghost { background: transparent; }
.tcg-btn.master {
  background: linear-gradient(135deg, #b45309, #a16207 40%, #713f12);
  border-color: #fbbf24;
  color: #fffbeb;
}
.tcg-btn.sm { padding: 8px 12px; font-size: 0.85rem; }

.tcg-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.tcg-section-head h2 { margin: 0; font-size: 1.2rem; }

.tcg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.tcg-card {
  position: relative;
  background: linear-gradient(160deg, #1e293b, #0f172a);
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px 10px 10px;
  min-height: 110px;
  cursor: default;
  transition: transform .15s, box-shadow .15s;
  overflow: hidden;
}
.tcg-card.sm { min-height: 72px; padding: 8px; }
.tcg-card.in-deck { outline: 2px solid var(--accent); }
.tcg-card.common { border-color: #64748b; }
.tcg-card.rare { border-color: var(--blue); box-shadow: 0 0 0 1px rgba(59,130,246,.25); }
.tcg-card.epic { border-color: var(--purple); box-shadow: 0 0 16px rgba(168,85,247,.2); }
.tcg-card.legend { border-color: var(--gold); box-shadow: 0 0 18px rgba(251,191,36,.25); }
.tcg-card.holo {
  background: linear-gradient(135deg, #1e293b 0%, #312e81 40%, #1e293b 100%);
  background-size: 200% 200%;
  animation: holoShift 4s ease infinite;
}
@keyframes holoShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.tcg-card-power {
  position: absolute;
  top: 8px; right: 8px;
  background: #0f172a;
  border: 1px solid #475569;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 2px 7px;
  color: var(--gold);
}
.tcg-card-name { font-weight: 700; font-size: 0.92rem; margin-right: 36px; line-height: 1.25; }
.tcg-card-meta { color: var(--muted); font-size: 0.72rem; margin-top: 6px; }
.tcg-card-team { color: #94a3b8; font-size: 0.7rem; margin-top: 4px; }

.tcg-deck-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 80px;
  padding: 10px;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px dashed #334155;
  margin-bottom: 8px;
}

.tcg-label { display: block; color: var(--muted); font-size: 0.8rem; margin: 12px 0 6px; }
.tcg-input, .tcg-textarea {
  width: 100%;
  background: var(--panel);
  border: 1px solid #334155;
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}
.tcg-textarea { resize: vertical; font-family: ui-monospace, monospace; font-size: 0.8rem; }

/* Battle */
.tcg-battle-score {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 10px;
}
.tcg-battle-score .you, .tcg-battle-score .enemy {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid #243044;
}
.tcg-battle-score strong { font-size: 1.5rem; color: var(--gold); }
.tcg-battle-score .vs { color: var(--muted); font-weight: 700; letter-spacing: 0.1em; }

.tcg-battle-arena {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  min-height: 180px;
  margin-bottom: 18px;
}
.tcg-battle-arena.shake { animation: shake .28s ease; }
.tcg-battle-arena.reveal .tcg-side { animation: slideIn .4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px) scale(.94); }
  to { opacity: 1; transform: none; }
}

.tcg-side { display: flex; justify-content: center; }
.tcg-side .tcg-card { width: 150px; min-height: 130px; cursor: default; }
.tcg-card-back {
  width: 150px;
  min-height: 130px;
  border-radius: 12px;
  background: repeating-linear-gradient(45deg, #1e293b, #1e293b 10px, #0f172a 10px, #0f172a 20px);
  border: 2px solid #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--muted);
}

.tcg-clash {
  font-weight: 900;
  font-size: 1.1rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-align: center;
  min-width: 64px;
}
.tcg-clash.pop { animation: pop .45s ease; }
.tcg-clash.win { color: var(--green); }
.tcg-clash.lose { color: var(--red); }
@keyframes pop {
  0% { transform: scale(.5); opacity: 0; }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); opacity: 1; }
}

.tcg-battle-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }

.tcg-round-log { display: flex; justify-content: center; gap: 8px; }
.tcg-pip {
  width: 12px; height: 12px; border-radius: 50%;
  background: #334155;
}
.tcg-pip.win { background: var(--green); }
.tcg-pip.lose { background: var(--red); }
.tcg-pip.draw { background: var(--gold); }
.tcg-pip.pending { background: #334155; }

.tcg-result { text-align: center; padding: 24px 12px; }
.tcg-result-badge {
  font-size: 2rem; font-weight: 900; margin-bottom: 8px;
}
.tcg-result.win .tcg-result-badge { color: var(--green); }
.tcg-result.lose .tcg-result-badge { color: var(--red); }
.tcg-result.draw .tcg-result-badge { color: var(--gold); }
.tcg-result-score { font-size: 1.6rem; margin-bottom: 18px; color: var(--muted); }
.tcg-result-rounds { text-align: left; max-width: 420px; margin: 0 auto 20px; }
.tcg-result-row {
  display: grid;
  grid-template-columns: 32px 1fr auto 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #1e293b;
  font-size: 0.85rem;
}
.tcg-result-row.win { color: #86efac; }
.tcg-result-row.lose { color: #fca5a5; }

@media (max-width: 560px) {
  .tcg-battle-arena { grid-template-columns: 1fr; }
  .tcg-clash { order: -1; }
}

/* Modo Mestre — ban */
.tcg-card.banned {
  outline: 2px solid var(--red);
  opacity: 0.55;
  position: relative;
}
.tcg-card.banned::after {
  content: "BAN";
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #fecaca;
  background: #7f1d1d;
  padding: 2px 6px;
  border-radius: 4px;
}
.tcg-ban-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 56px;
  padding: 10px;
  margin: 12px 0 8px;
  background: var(--panel);
  border: 1px dashed #7f1d1d;
  border-radius: var(--radius);
  align-items: center;
}
.tcg-ban-bar .tcg-card.sm {
  cursor: pointer;
  position: relative;
}
.tcg-ban-x {
  position: absolute;
  top: 4px;
  right: 6px;
  color: #fecaca;
  font-weight: 800;
  font-size: 0.85rem;
}
.tcg-master-setup .tcg-input,
.tcg-master-ban .tcg-input {
  width: 100%;
  max-width: 420px;
}

/* Arte / fotos das cartas */
.tcg-art {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: #0f172a;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tcg-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.tcg-art.sm {
  aspect-ratio: 1;
  max-height: 64px;
  margin-bottom: 4px;
}
.tcg-art-fallback {
  background: linear-gradient(145deg, #1e293b, #0f172a);
  color: var(--muted);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
}
.tcg-card .tcg-art { pointer-events: none; }
.tcg-card.sm .tcg-art { max-height: 56px; }
.tcg-side .tcg-card .tcg-art { max-height: 110px; }


.tcg-room-code {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-align: center;
  padding: 16px;
  margin: 8px 0 12px;
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  color: var(--gold);
  user-select: all;
}

/* ===== Combate V2 ===== */
.tcg-battle-v2 { padding-bottom: 24px; }
.tcg-battle-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.tcg-who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}
.tcg-who.enemy { flex-direction: row-reverse; }
.tcg-who-name { font-weight: 700; color: var(--text); max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tcg-bench { display: flex; gap: 5px; }
.tcg-bench-pip {
  width: 10px; height: 10px; border-radius: 50%;
  background: #334155; border: 1px solid #475569;
}
.tcg-bench-pip.on { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.tcg-bench-pip.dead { background: #7f1d1d; opacity: 0.5; }

.tcg-arena-v2 {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.tcg-fighter {
  background: var(--panel);
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 10px;
  text-align: center;
  position: relative;
}
.tcg-fighter.active { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(59,130,246,.35); }
.tcg-fighter.dead { opacity: 0.4; filter: grayscale(0.6); }
.tcg-fighter .tcg-art { max-height: 120px; margin-bottom: 6px; }
.tcg-fighter .tcg-card-name { font-size: 0.9rem; font-weight: 700; margin: 4px 0; }
.tcg-fighter .tcg-card-power {
  position: absolute; top: 8px; left: 8px;
  background: #0f172a; border-radius: 8px; padding: 2px 6px;
  font-weight: 800; font-size: 0.8rem; border: 1px solid #334155;
}
.tcg-fighter-empty { padding: 40px 8px; color: var(--muted); }

.tcg-hp {
  position: relative;
  height: 16px;
  background: #1e293b;
  border-radius: 8px;
  overflow: hidden;
  margin: 6px 0 4px;
  border: 1px solid #334155;
}
.tcg-hp-fill { height: 100%; transition: width .35s ease; }
.tcg-hp-fill.ok { background: linear-gradient(90deg, #16a34a, #22c55e); }
.tcg-hp-fill.mid { background: linear-gradient(90deg, #ca8a04, #eab308); }
.tcg-hp-fill.low { background: linear-gradient(90deg, #b91c1c, #ef4444); }
.tcg-hp span {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 700; color: #fff;
  text-shadow: 0 1px 2px #000;
}

.tcg-vs-col { text-align: center; min-width: 72px; }
.tcg-vs-label { font-weight: 900; color: var(--muted); letter-spacing: 0.1em; }
.tcg-last-moves { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.tcg-last-moves .mv { font-size: 0.75rem; color: var(--muted); }
.tcg-last-moves .mv-res { font-weight: 900; font-size: 0.9rem; }
.tcg-last-moves .mv-res.player { color: var(--green); }
.tcg-last-moves .mv-res.enemy { color: var(--red); }
.tcg-last-moves .mv-res.tie { color: var(--gold); }
.tcg-battle-msg { font-size: 0.75rem; color: var(--muted); margin: 8px 0 0; line-height: 1.35; max-width: 140px; }

.tcg-moves { margin: 8px 0 12px; }
.tcg-moves.disabled { opacity: 0.55; pointer-events: none; }
.tcg-move-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}
.tcg-move {
  border: 1px solid #334155;
  background: var(--panel2);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 8px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 72px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.tcg-move .ico { font-size: 1.5rem; }
.tcg-move.atk:active, .tcg-move.atk:hover { border-color: #ef4444; background: #3f1d1d; }
.tcg-move.def:active, .tcg-move.def:hover { border-color: #3b82f6; background: #1e3a5f; }
.tcg-move.esq:active, .tcg-move.esq:hover { border-color: #a855f7; background: #3b1d5a; }
.tcg-hint.center { text-align: center; }
.tcg-hint.tiny { font-size: 0.75rem; }

@media (max-width: 560px) {
  #tcgApp { padding: 12px 10px 40px; }
  .tcg-arena-v2 {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .tcg-vs-col { order: 0; }
  .tcg-fighter.player { order: 1; }
  .tcg-fighter.enemy { order: -1; }
  .tcg-fighter .tcg-art { max-height: 100px; }
  .tcg-move { min-height: 68px; padding: 12px 6px; }
  .tcg-title { font-size: 1.45rem; }
  .tcg-room-code { font-size: 1.8rem; letter-spacing: 0.14em; }
  .tcg-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

@media (min-width: 561px) {
  .tcg-fighter .tcg-art { max-height: 140px; }
}

/* Progress / season */
.tcg-progress-chip {
  display: inline-block;
  background: var(--panel);
  border: 1px solid #334155;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 12px;
}
.tcg-progress-chip .rk { color: var(--gold); font-weight: 800; }

/* Energy */
.tcg-energy { display: flex; gap: 3px; }
.tcg-energy .en {
  width: 8px; height: 8px; border-radius: 2px;
  background: #1e293b; border: 1px solid #334155;
}
.tcg-energy .en.on { background: #38bdf8; border-color: #7dd3fc; box-shadow: 0 0 4px #38bdf8; }

/* Hit flash */
.tcg-fighter.hit { animation: hitFlash .35s ease; }
@keyframes hitFlash {
  0% { filter: brightness(2); transform: scale(1.03); }
  100% { filter: none; transform: none; }
}
.tcg-arena-v2.shake { animation: shake .28s ease; }

/* Order badge */
.tcg-ord-badge {
  position: absolute; top: 6px; right: 6px;
  background: var(--accent); color: #fff;
  font-size: 0.7rem; font-weight: 800;
  padding: 2px 6px; border-radius: 6px; z-index: 2;
}
.tcg-card { position: relative; }

/* Smart ban highlight */
.tcg-card.smart-ban { box-shadow: 0 0 0 2px var(--gold); }

/* Sticky moves mobile */
.tcg-moves-sticky {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent, var(--bg) 20%);
  padding: 8px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
}

/* Chat */
.tcg-chat {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid #243044;
  border-radius: var(--radius);
  padding: 10px;
}
.tcg-chat-log {
  max-height: 120px;
  overflow-y: auto;
  font-size: 0.85rem;
  margin-bottom: 8px;
  line-height: 1.4;
}
.tcg-chat-row { display: flex; gap: 8px; }
.tcg-chat-row .tcg-input { flex: 1; }

/* Room list */
.tcg-room-list { display: flex; flex-direction: column; gap: 8px; }
.tcg-room-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid #243044;
  border-radius: 12px;
  padding: 10px 12px;
}

/* Safe area body */
body {
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* Frame rarity accents */
.tcg-fighter.rarity-legend { border-color: #fbbf24; }
.tcg-fighter.rarity-epic { border-color: #a855f7; }
.tcg-fighter.holo { box-shadow: 0 0 12px rgba(168, 85, 247, 0.25); }

.tcg-move-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 10px 0;
}
@media (min-width: 520px) {
  .tcg-move-grid { grid-template-columns: repeat(3, 1fr); }
}
.tcg-move {
  border: 1px solid #334155;
  background: var(--panel2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 8px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 64px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  text-align: center;
}
.tcg-move .ico { font-size: 1.25rem; }
.tcg-move .lab { font-size: 0.78rem; line-height: 1.2; }
.tcg-move .cost { font-size: 0.7rem; color: #7dd3fc; font-weight: 600; }
.tcg-move.atk:hover, .tcg-move.atk:active { border-color: #ef4444; background: #3f1d1d; }
.tcg-move.def:hover, .tcg-move.def:active { border-color: #3b82f6; background: #1e3a5f; }
.tcg-move.esq:hover, .tcg-move.esq:active { border-color: #a855f7; background: #3b1d5a; }
.tcg-move.special { border-color: #fbbf24; background: linear-gradient(160deg, #3b2a0a, #1a1520); }
.tcg-move.special .cost { color: #fbbf24; }
.tcg-move.skip { border-color: #22c55e; border-style: dashed; }
.tcg-move:disabled { opacity: 0.35; cursor: not-allowed; }
.buff { font-size: 0.85rem; }

.tcg-swap-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 8px;
}
.tcg-swap-btn {
  border: 1px dashed #475569;
  background: var(--panel);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.tcg-swap-btn:not(:disabled):hover { border-color: var(--accent); color: var(--text); }
.tcg-swap-btn:disabled { opacity: 0.35; }
.tcg-swap-btn.dead { text-decoration: line-through; }
