/* manipulation: rolar e pinçar continuam, mas o toque duplo não vira zoom (arena e cartas usam none) */
* { box-sizing: border-box; margin: 0; padding: 0; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: #1b2440;
  color: #fff;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  height: 100%;
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #2a3558;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

/* ---------- Topo ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: linear-gradient(#34406a, #26304f);
  border-bottom: 2px solid #151c33;
}

.crowns { display: flex; gap: 2px; font-size: 20px; min-width: 80px; }
.crowns.me { justify-content: flex-end; }
.crowns span { filter: grayscale(1) brightness(0.45); }
.crowns span.on { filter: none; }
.crowns.enemy span.on { filter: hue-rotate(-40deg) saturate(1.4); }

#timer-box { text-align: center; }
#timer { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
#timer-label { font-size: 11px; opacity: 0.7; text-transform: uppercase; letter-spacing: 1px; }
#timer-box.double #timer-label { color: #f8d030; opacity: 1; }
#timer-box.overtime #timer { color: #ff6b6b; }

/* ---------- Arena ---------- */
#arena-wrap { position: relative; flex: 1; min-height: 0; }
#arena { display: block; touch-action: none; }

#banner {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) scale(0.8);
  padding: 10px 22px;
  border-radius: 14px;
  background: rgba(20, 24, 45, 0.85);
  border: 2px solid #f8d030;
  font-size: 20px;
  font-weight: 800;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- Cartas ---------- */
#bottombar {
  padding: 8px 10px 10px;
  background: linear-gradient(#26304f, #1a223d);
  border-top: 2px solid #151c33;
}

#cards-row { display: flex; align-items: flex-end; gap: 8px; max-width: 62vh; margin: 0 auto; }

#next-wrap { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; opacity: 0.85; }

#hand { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

.card {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--type) 85%, #fff), color-mix(in srgb, var(--type) 70%, #000));
  border: 3px solid #e9edf7;
  box-shadow: 0 3px 0 #0d1226;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.12s;
  touch-action: none;
}
.card img {
  position: absolute;
  inset: 4% 4% 18% 4%;
  width: 92%;
  height: 78%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
}
.card .name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  padding: 2px 0;
  background: rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .cost {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #e9a6ff, #a03ad6);
  border: 2px solid #fff;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 1px 1px #000;
}
.card .lock {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  background: rgba(10, 12, 25, 0.55);
  pointer-events: none;
}
.card.selected { transform: translateY(-10px); border-color: #f8d030; box-shadow: 0 0 0 3px #f8d030, 0 8px 0 #0d1226; }
.card.shake { animation: shake 0.3s; }
/* Sem energia: a carta treme e pisca em vermelho */
.card.denied { animation: shake 0.3s, denied 0.45s; }
@keyframes denied { 0%, 60% { box-shadow: 0 0 0 3px #ff4040, 0 0 14px #ff4040; filter: brightness(1.15) saturate(1.3); } }
/* Carta que acabou de ficar disponível dá um pulinho */
.card.ready { animation: card-ready 0.35s ease-out; }
@keyframes card-ready { 40% { transform: translateY(-6px) scale(1.06); } }
.card.mini { width: 44px; border-width: 2px; }
.card.mini .name, .card.mini .cost { display: none; }

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ---------- Energia ---------- */
#energy {
  position: relative;
  max-width: 62vh;
  margin: 8px auto 0;
  height: 22px;
  border-radius: 11px;
  background: #0f1430;
  border: 2px solid #0a0d1f;
  overflow: hidden;
}
#energy-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 50%;
  background: linear-gradient(#e9a6ff, #a03ad6);
  transition: width 0.1s linear;
}
/* Barra cheia brilha; na energia dupla, um brilho corre pela barra */
#energy.full { box-shadow: 0 0 10px #e9a6ff, 0 0 18px rgba(200, 90, 255, 0.6); animation: energy-full 1.1s ease-in-out infinite; }
@keyframes energy-full { 50% { box-shadow: 0 0 4px #e9a6ff; } }
#energy.double #energy-fill { background: linear-gradient(90deg, transparent 0, rgba(255, 255, 255, 0.45) 50%, transparent 100%) -60px 0 / 60px 100% no-repeat, linear-gradient(#ffd0ff, #c040ff); animation: energy-shine 1.2s linear infinite; }
@keyframes energy-shine { to { background-position: calc(100% + 60px) 0, 0 0; } }
#energy-ticks {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0, transparent calc(10% - 2px), rgba(10, 13, 31, 0.8) calc(10% - 2px), rgba(10, 13, 31, 0.8) 10%);
}
#energy-num {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 800;
  font-size: 14px;
  text-shadow: 0 1px 2px #000;
}

/* ---------- Telas ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(12, 16, 34, 0.82);
  backdrop-filter: blur(3px);
  z-index: 10;
}
.overlay.hidden { display: none; }

.panel {
  width: 100%;
  max-width: 400px;
  padding: 24px 20px;
  border-radius: 18px;
  background: linear-gradient(#34406a, #222b4a);
  border: 3px solid #4d5d94;
  text-align: center;
}
.panel h1 { font-size: 40px; font-weight: 900; letter-spacing: 1px; color: #f8d030; text-shadow: 0 3px 0 #3b5bdb, 0 5px 8px rgba(0, 0, 0, 0.5); }
.panel h1 span { color: #fff; }
.panel h2 { font-size: 14px; margin: 18px 0 8px; opacity: 0.8; text-transform: uppercase; letter-spacing: 1px; }
.panel .sub { margin-top: 8px; font-size: 14px; opacity: 0.85; }

.btn-row { display: flex; gap: 8px; justify-content: center; }
button {
  flex: 1;
  padding: 12px 10px;
  border: none;
  border-radius: 10px;
  background: #4d5d94;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 #2b355c;
}
button:active { transform: translateY(2px); box-shadow: 0 1px 0 #2b355c; }
button.primary { background: #f0b400; color: #1b2440; box-shadow: 0 3px 0 #a07800; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.wide { width: 100%; margin-top: 12px; }

details { margin-top: 16px; text-align: left; font-size: 13px; }
summary { cursor: pointer; font-weight: 700; text-align: center; opacity: 0.85; }
details ul { margin: 10px 0 0 18px; display: grid; gap: 6px; opacity: 0.9; }

#end-crowns { font-size: 34px; margin: 14px 0 18px; }
/* Coroas entram uma de cada vez; na vitória, título pulsando e confete */
#end-crowns .crown { display: inline-block; animation: crown-pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) backwards; }
@keyframes crown-pop { from { transform: scale(0) rotate(-40deg); opacity: 0; } }
#end.win #end-title { animation: win-title 1.4s ease-in-out infinite; color: #ffd84a; text-shadow: 0 0 12px rgba(255, 216, 74, 0.6); }
@keyframes win-title { 50% { transform: scale(1.06); } }
.confetti { position: absolute; top: -12px; width: 8px; height: 12px; border-radius: 2px; pointer-events: none; animation: confetti-fall linear forwards; }
@keyframes confetti-fall { to { transform: translateY(105vh) rotate(720deg); } }
#end-crowns .vs { font-size: 18px; opacity: 0.7; margin: 0 10px; }

/* ---------- Multiplayer ---------- */
.join-row { display: flex; gap: 8px; margin-top: 8px; }
.join-row input {
  flex: 2;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid #4d5d94;
  background: #161d36;
  color: #fff;
  font: inherit;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  user-select: text;
  -webkit-user-select: text;
}
.join-row input::placeholder { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: 0.6; }
.join-row button { flex: 1; }
.error { min-height: 1.2em; margin-top: 8px; font-size: 13px; color: #ff8a8a; }

#lobby-code {
  margin: 14px 0 6px;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 4px;
  color: #f8d030;
  font-variant-numeric: tabular-nums;
  user-select: text;
  -webkit-user-select: text;
}
#lobby-status { margin-bottom: 18px; }
#lobby-status.waiting::after { content: ''; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- Editor de deck ---------- */
#btn-deck { margin-top: 10px; }
#menu-deck-avg { font-weight: 400; opacity: 0.75; font-size: 13px; }

.deck-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 520px;
  padding: 14px 12px;
  gap: 10px;
}
.deck-head { display: flex; align-items: center; gap: 10px; }
.deck-head h2 { flex: 1; text-align: left; }
button.icon { flex: 0 0 auto; padding: 6px 10px; }
.deck-head h2 { margin: 0; font-size: 18px; opacity: 1; }
#deck-avg { font-size: 13px; opacity: 0.85; }

#deck-slots { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.slot {
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  border: 2px dashed #4d5d94;
  background: rgba(0, 0, 0, 0.2);
}

.deck-filters { display: flex; gap: 6px; }
.deck-filters input, .deck-filters select {
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 2px solid #4d5d94;
  background: #161d36;
  color: #fff;
  font: inherit;
  font-size: 14px;
}
.deck-filters input { flex: 1; user-select: text; -webkit-user-select: text; }

#deck-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  align-content: start;
  align-items: start;
  gap: 6px;
  padding: 4px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  touch-action: pan-y;
}
.card.small .name { font-size: 9px; }
.card.small .cost { width: 18px; height: 18px; font-size: 10px; border-width: 1px; }
.card.small { border-width: 2px; box-shadow: 0 2px 0 #0d1226; }
.card.in-deck { opacity: 0.35; }
.card.focused { border-color: #f8d030; box-shadow: 0 0 0 2px #f8d030; }
.card .dexno { position: absolute; top: 2px; right: 4px; font-size: 9px; opacity: 0.8; text-shadow: 0 1px 1px #000; }

#deck-info {
  min-height: 92px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  text-align: left;
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: center;
}
#deck-info .hint { opacity: 0.7; margin: auto; }
#deck-info img { width: 72px; height: 72px; image-rendering: pixelated; flex-shrink: 0; }
#deck-info .info-body { flex: 1; min-width: 0; }
#deck-info h3 { font-size: 16px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#deck-info .stats { margin: 4px 0; opacity: 0.9; }
#deck-info .desc { opacity: 0.8; }
#deck-info button { flex: 0 0 auto; padding: 10px 12px; }
.type-chip { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 6px; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5); }

/* A página em si nunca rola (só os painéis por dentro). Sem isso, no celular o navegador escondia a barra
   de endereço ao rolar algo e "puxava" a tela para cima, sem ter como voltar. */
body { position: fixed; inset: 0; width: 100%; }

/* Imagens nunca são "arrastáveis": no celular, arrastar começando numa imagem tentava arrastar a imagem
   em vez de rolar a lista (ex.: ofertas da loja). Imagens decorativas também não capturam o toque. */
img { -webkit-user-drag: none; user-drag: none; -webkit-touch-callout: none; }
.offer-art, .offer-art img, .mini-deck img, .rank-row img, .journey-step img, .reward-card img, .profile-card img { pointer-events: none; }

/* ---------- Emotes na partida ---------- */
.emote-btn {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 3;
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  font-size: 22px;
  background: rgba(17, 26, 52, 0.85);
  border: 2px solid #7fb0ff;
  box-shadow: 0 3px 0 #0b1124;
}
.emote-menu {
  position: absolute;
  left: 8px;
  bottom: 62px;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(2, 64px);
  gap: 6px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(17, 26, 52, 0.95);
  border: 2px solid #2f4a8a;
}
.emote-menu button { width: 64px; height: 64px; padding: 4px; border-radius: 12px; background: #fff; box-shadow: 0 3px 0 #9aa6c8; }
.emote-menu img { width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; }

/* ---------- Sair da partida ---------- */
.leave-btn {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 3;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  background: rgba(17, 26, 52, 0.85);
  border: 2px solid #ff8a80;
  box-shadow: 0 3px 0 #0b1124;
}
button.danger { background: linear-gradient(180deg, #e2453c, #b62c25); box-shadow: 0 4px 0 #7a1712; color: #fff; }
#leave .panel { max-width: 380px; }
#leave .sub { margin: 10px 0 16px; }

/* Na partida, no PC: coluna com proporção de celular para o campo encher a tela sem bordas */
/* Só no PC (tela larga): no celular a partida ocupa a largura toda, sem faixas nas laterais */
@media (min-width: 700px) {
  body.in-battle #app { max-width: min(540px, calc((100dvh - 200px) * 0.62)); }
}

/* ---------- Som ---------- */
.sound-btn {
  position: absolute;
  left: 8px;
  top: 58px;
  z-index: 3;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 19px;
  background: rgba(17, 26, 52, 0.85);
  border: 2px solid #8fb4ff;
  box-shadow: 0 3px 0 #0b1124;
}
.sound-form label { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sound-form input[type="range"] { flex: 1; max-width: 180px; accent-color: #ffcb05; }

/* ---------- Arrastar cartas para o deck ---------- */
#deck-grid .card, #deck-slots .card { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#deck-grid .card img, #deck-slots .card img, .drag-ghost img { -webkit-user-drag: none; }
.card.drag-ghost {
  position: fixed;
  z-index: 1000;
  margin: 0;
  pointer-events: none;
  transform: translate(-50%, -55%) scale(1.15) rotate(-4deg);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.55);
  opacity: 0.95;
}
.card.drag-source { opacity: 0.3; }
#deck-slots.drop-zone { outline: 2px dashed #ffcb05; outline-offset: 4px; border-radius: 10px; }
#deck-slots > .drop-target { transform: scale(1.08); box-shadow: 0 0 0 3px #ffcb05; border-radius: 8px; }
body.dragging-card, body.dragging-card * { cursor: grabbing !important; }

/* Construções: pixel art sem suavizar, como os sprites */
img[src*="assets/construcoes/"] { image-rendering: pixelated; object-fit: contain; }

/* Ícones em pixel art no lugar dos emojis (js/icons.js) */
/* !important: outras regras de <img> (cartas, detalhes, listas) não podem esticar o ícone */
img.ico {
  display: inline-block !important;
  width: 1.2em !important;
  height: 1.2em !important;
  min-width: 0 !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: none !important;
  box-shadow: none !important;
  flex: none !important;
  vertical-align: -0.22em;
  image-rendering: pixelated;
  pointer-events: none;
}

/* ---------- Fim da partida chegando (últimos 10 s) ---------- */
#timer-box.final #timer { color: #ff5a5a; animation: timer-pulse 0.5s ease-in-out infinite alternate; }
@keyframes timer-pulse { from { transform: scale(1); } to { transform: scale(1.18); } }
.countdown {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 4;
  pointer-events: none;
  font-family: var(--pixel, sans-serif);
  font-weight: 700;
  font-size: clamp(56px, 22vw, 120px);
  color: #fff;
  -webkit-text-stroke: 4px #b3261e;
  paint-order: stroke fill;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.45);
  opacity: 0;
}
.countdown.pop { animation: countdown-pop 1s ease-out forwards; }
@keyframes countdown-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); }
  18% { opacity: 0.95; transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 0.8; transform: translate(-50%, -50%) scale(0.95); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}
.final-vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  box-shadow: inset 0 0 60px 10px rgba(255, 40, 40, 0.55);
  animation: vignette-pulse 1s ease-in-out infinite;
}
@keyframes vignette-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
