:root {
  --wood-dark: #2b1a0f;
  --wood-mid: #4a2f1a;
  --wood-light: #6b4527;
  --stone: #3a3a3a;
  --stone-light: #5a5a5a;
  --torch-glow: #e8a13a;
  --blood: #7a1414;
  --parchment: #e8d9b5;
  --rune-blue: #4a90d9;
  --danger: #b03030;
  --success: #3a8f4a;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

html, body {
  width: 100%;
  min-height: 100%;
  background: radial-gradient(ellipse at center, #1a1008 0%, #0d0805 100%);
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
  color: var(--parchment);
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 12px;
}

/* Container central: imita o tamanho compacto do overlay original,
   mas centralizado e com teto de largura pra nao esticar num monitor
   grande (era o motivo do tabuleiro ficar gigante). */
#app-shell {
  width: 100%;
  max-width: 500px;
  background: radial-gradient(ellipse at center, var(--wood-mid) 0%, var(--wood-dark) 100%);
  border: 2px solid var(--wood-light);
  border-radius: 6px;
  overflow: hidden;
}
/* A tela de partida e mais larga (tabuleiro + log lado a lado), entao
   ela sozinha estica o app-shell alem do limite padrao das outras telas. */
#app-shell:has(#screen-match:not(.hidden)) {
  max-width: 820px;
}

/* Pisca a borda quando e o turno do jogador (notificacao discreta) */
body.your-turn {
  animation: turn-glow 1.6s ease-in-out infinite;
}
@keyframes turn-glow {
  0%, 100% { border-color: var(--wood-light); }
  50% { border-color: var(--torch-glow); }
}

#titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 28px;
  padding: 0 8px;
  background: var(--wood-dark);
  border-bottom: 1px solid var(--wood-light);
  -webkit-app-region: drag;
}
.titlebar-text {
  font-size: 12px;
  letter-spacing: 0.5px;
  color: var(--torch-glow);
}
.titlebar-buttons { display: flex; gap: 4px; -webkit-app-region: no-drag; }
.titlebar-buttons button {
  width: 20px; height: 20px;
  background: transparent;
  border: none;
  color: var(--parchment);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.titlebar-buttons button:hover { color: var(--torch-glow); }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  overflow-y: auto;
}
.hidden { display: none !important; }

.rune-title {
  text-align: center;
  font-size: 20px;
  color: var(--torch-glow);
  text-shadow: 0 0 6px rgba(232, 161, 58, 0.6);
  margin-bottom: 6px;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: var(--parchment);
  gap: 3px;
}
input {
  padding: 6px 8px;
  background: var(--stone);
  border: 1px solid var(--wood-light);
  border-radius: 4px;
  color: var(--parchment);
  font-size: 13px;
}
input:focus { outline: 1px solid var(--torch-glow); }

button {
  cursor: pointer;
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.3px;
}
.btn-primary {
  background: linear-gradient(180deg, var(--torch-glow), #b5741f);
  color: #2b1a0f;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary {
  background: var(--stone-light);
  color: var(--parchment);
}
.btn-secondary:hover { filter: brightness(1.15); }
.btn-warning {
  background: var(--danger);
  color: var(--parchment);
}

.login-buttons { display: flex; gap: 8px; }
.login-buttons button { flex: 1; }
.error-text { color: var(--danger); font-size: 12px; min-height: 14px; }

.player-info { font-size: 12px; text-align: center; color: var(--parchment); }
.status-text { font-size: 12px; text-align: center; color: var(--torch-glow); min-height: 16px; }

.turn-banner {
  text-align: center;
  font-size: 13px;
  padding: 6px;
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
  color: var(--torch-glow);
}

.turn-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 6px;
  border: 2px solid var(--wood-light);
  background: rgba(0,0,0,0.25);
  transition: border-color 0.3s ease, background 0.3s ease;
}
.turn-indicator.mine {
  border-color: var(--success);
  background: rgba(58, 143, 74, 0.18);
}
.turn-indicator.theirs {
  border-color: var(--danger);
  background: rgba(176, 48, 48, 0.15);
}
.turn-indicator-label {
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.3px;
}
.turn-timer {
  font-size: 20px;
  font-weight: bold;
  min-width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
  border: 2px solid var(--torch-glow);
  color: var(--torch-glow);
}
.turn-timer.urgent {
  color: var(--danger);
  border-color: var(--danger);
  animation: timer-pulse 0.6s ease-in-out infinite;
}
@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.match-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.match-board-col {
  flex: 0 0 auto;
  width: 520px; /* board anterior (~416px uteis) + uns 25% */
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.board {
  position: relative; /* ancora os projeteis/impactos da animacao de ataque */
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 2px;
  aspect-ratio: 1 / 1;
  width: 100%;
  background: var(--stone);
  border: 2px solid var(--wood-dark);
  border-radius: 4px;
  padding: 4px;
}

.attack-projectile {
  position: absolute;
  font-size: 22px;
  transform: translate(-50%, -50%);
  transition: left 0.48s cubic-bezier(0.3, 0, 0.7, 1), top 0.48s cubic-bezier(0.3, 0, 0.7, 1);
  z-index: 30;
  pointer-events: none;
}
.attack-impact {
  position: absolute;
  font-size: 28px;
  transform: translate(-50%, -50%) scale(0.5);
  z-index: 31;
  pointer-events: none;
  animation: impact-pop 0.45s ease-out forwards;
}
@keyframes impact-pop {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4); }
  40% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}
.cell {
  background: linear-gradient(160deg, #4a4a4a, #333);
  border-radius: 2px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.cell.blood { background: linear-gradient(160deg, #5a2020, #3a1010); }
.cell.selectable { outline: 2px solid var(--success); outline-offset: -2px; }
.cell.selected { outline: 2px solid var(--torch-glow); outline-offset: -2px; }

.unit {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  text-align: center;
  color: var(--parchment);
  border: 2px solid var(--wood-dark);
  position: relative;
}
.unit.owner-a { background: transparent; border: 3px solid var(--rune-blue); }
.unit.owner-b { background: transparent; border: 3px solid var(--danger); }
.unit.dead { display: none; }
.unit-icon {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  pointer-events: none;
  transform: rotate(0deg);
  transition: transform 0.2s ease;
}
.unit-icon.unit-icon-flipped {
  transform: rotate(180deg);
}
.unit-label {
  pointer-events: none;
}

.mini-bars {
  position: absolute;
  bottom: -16px;
  left: 5%;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.mini-hp-bar, .mini-stamina-bar {
  position: relative;
  width: 100%;
  height: 7px;
  background: rgba(0,0,0,0.55);
  border-radius: 2px;
  overflow: visible;
  border: 1px solid rgba(0,0,0,0.4);
}
.mini-hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #b03030, #e05050);
  border-radius: 1px;
  transition: width 0.3s ease;
}
.mini-stamina-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--rune-blue), #6fb0e6);
  border-radius: 1px;
  transition: width 0.3s ease;
}
.mini-bar-text {
  position: absolute;
  top: -1px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 6px;
  line-height: 7px;
  color: #fff;
  text-shadow: 0 0 2px #000, 0 0 2px #000;
  pointer-events: none;
}

@keyframes stamina-float {
  0% { transform: translate(-50%, 0); opacity: 1; }
  100% { transform: translate(-50%, -18px); opacity: 0; }
}
.stamina-boost-badge {
  position: absolute;
  top: -26px;
  left: 50%;
  transform: translate(-50%, 0);
  color: #4ade80;
  font-size: 10px;
  font-weight: bold;
  animation: stamina-float 1.1s ease-out forwards;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}

.unit-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  padding: 6px;
  background: rgba(0,0,0,0.25);
  border-radius: 4px;
}
.bar-row { display: flex; align-items: center; gap: 6px; }
.bar-label { width: 44px; font-size: 10px; }
.bar {
  flex: 1;
  height: 8px;
  background: var(--stone);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--wood-dark);
}
.bar-fill { height: 100%; transition: width 0.2s ease; }
.bar-hp .bar-fill { background: linear-gradient(90deg, #b03030, #e05050); }
.bar-stamina .bar-fill { background: linear-gradient(90deg, var(--rune-blue), #6fb0e6); }

input[type="range"] {
  width: 100%;
  margin: 8px 0;
  accent-color: var(--torch-glow);
}
.stamina-value {
  text-align: center;
  font-size: 12px;
  color: var(--torch-glow);
  margin-bottom: 8px;
}
.response-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}
.response-btn {
  background: var(--stone-light);
  color: var(--parchment);
  font-size: 12px;
  padding: 8px 4px;
}
.response-btn:hover { filter: brightness(1.15); }
.response-btn.picked { outline: 2px solid var(--torch-glow); }
.response-btn:disabled { opacity: 0.35; cursor: not-allowed; }
#heal-ally-picker {
  margin-bottom: 8px;
}
#heal-ally-picker select {
  width: 100%;
  padding: 6px;
  background: var(--stone);
  border: 1px solid var(--wood-light);
  border-radius: 4px;
  color: var(--parchment);
}

.wager-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--wood-dark);
  border: 2px solid var(--torch-glow);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  z-index: 50;
  box-shadow: 0 0 20px rgba(0,0,0,0.6);
}
.wager-title { color: var(--torch-glow); font-size: 14px; margin-bottom: 4px; }
.wager-subtitle { font-size: 11px; margin-bottom: 10px; }
.wager-buttons { display: flex; gap: 8px; }
.wager-btn {
  width: 40px; height: 40px;
  font-size: 16px;
  background: linear-gradient(180deg, var(--torch-glow), #b5741f);
  color: #2b1a0f;
  border-radius: 50%;
}
.wager-btn:hover { filter: brightness(1.15); }
.wager-btn.picked { outline: 2px solid var(--parchment); }

.result-toast {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  border: 1px solid var(--wood-light);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 12px;
  z-index: 60;
  max-width: 90%;
  text-align: center;
}

.combat-log {
  flex: 1 1 auto;
  min-width: 220px;
  align-self: stretch;
  height: 560px;
  overflow-y: auto;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--wood-light);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.6;
  display: flex;
  flex-direction: column-reverse; /* mais recente sempre visivel no topo */
}
.combat-log-entry {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.combat-log-entry .log-turn {
  color: var(--torch-glow);
  font-weight: bold;
  margin-right: 4px;
}
.combat-log-entry.log-damage { color: #f0b0b0; }
.combat-log-entry.log-heal { color: #a0e0b0; }
.combat-log-entry.log-dodge { color: #a0c8f0; }
.combat-log-entry.log-move { color: var(--parchment); opacity: 0.7; }
.combat-log-entry.log-death { color: var(--danger); font-weight: bold; }
.combat-log-entry.log-timeout { color: #e08a3c; font-style: italic; }
.combat-log-entry.log-turn-change { color: #8ab0d0; opacity: 0.85; }

/* ============================================================
 * Tela de Exercito (montar esquadrao)
 * ============================================================ */
.squad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.squad-count {
  font-size: 12px;
  color: var(--torch-glow);
}
.roster-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 2px;
}
.roster-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: rgba(0,0,0,0.25);
  border: 2px solid var(--wood-light);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.roster-card.selected {
  border-color: var(--torch-glow);
  background: rgba(232, 161, 58, 0.15);
}
.roster-card.locked {
  cursor: default;
  opacity: 0.75;
}
.roster-icon-wrap {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--stone);
  border: 2px solid var(--wood-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  text-align: center;
}
.roster-icon-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.roster-info {
  flex: 1;
  min-width: 0;
}
.roster-name {
  font-size: 13px;
  font-weight: bold;
  color: var(--parchment);
}
.roster-stats {
  font-size: 10px;
  color: rgba(232, 217, 181, 0.75);
  margin-top: 2px;
}
.roster-action {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.roster-lock-cost {
  font-size: 10px;
  color: var(--torch-glow);
}
.roster-unlock-btn {
  font-size: 10px;
  padding: 4px 8px;
  background: var(--stone-light);
  color: var(--parchment);
}
.roster-selected-badge {
  font-size: 16px;
  color: var(--torch-glow);
}

/* ============================================================
 * Painel de stats de unidade durante a partida (versao expandida)
 * ============================================================ */
.unit-info-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--wood-dark);
}
.unit-info-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.unit-info-stats-row {
  font-size: 10px;
  color: rgba(232, 217, 181, 0.75);
  margin-top: 2px;
}

/* Tela estreita: empilha tabuleiro e log em vez de cortar o layout lado a lado. */
@media (max-width: 860px) {
  #app-shell:has(#screen-match:not(.hidden)) {
    max-width: 520px;
  }
  .match-body {
    flex-direction: column;
  }
  .match-board-col {
    width: 100%;
  }
  .combat-log {
    width: 100%;
    height: 160px;
  }
}
