/* ── Reset & base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Mesa de madeira — fundo geral e chrome de combate (header/HUD/ações,
     grade tática) continuam escuros pra não perder legibilidade, só
     mudam de azulado pra tom de madeira. */
  --bg:        #201509;
  --panel:     #3A2A1A;
  --panel2:    #2B1F12;
  /* Papel envelhecido — cards/tiles/listas/botões (a "ficha" em cima da
     mesa). Texto sobre essas superfícies usa --ink/--ink-dim, não
     --text/--text-dim (que são pro texto direto sobre a madeira). */
  --paper:     #E9DAB0;
  --paper2:    #D7C48C;
  --ink:       #2E2011;
  --ink-dim:   #6B5738;
  --gold:      #C9A227;
  --gold-dim:  #8A6A2A;
  --red:       #C84B31;
  --green:     #3D7A4A;
  --green-lit: #5DBF6A;
  --purple:    #6B4FA0;
  --purple-lit:#9B7FD0;
  --blue:      #2E5FA0;
  --text:      #D4C89A;
  --text-dim:  #A08860;
  --border:    #4A3520;
  --cell-w:    72px;
  --cell-h:    80px;
  --font-px:   'Press Start 2P', monospace;
  --font-log:  'VT323', monospace;
}

html, body {
  height: 100%;
  /* Veios de madeira: costuras de táboa espaçadas (não uma grade
     apertada) + alguns "nós" de madeira via radial-gradient borrado,
     sobre um degradê marrom — sem depender de imagem externa. */
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.14) 0px, rgba(0,0,0,0.14) 1.5px, transparent 1.5px, transparent 110px),
    radial-gradient(ellipse 180px 60px at 15% 20%, rgba(0,0,0,0.12), transparent 70%),
    radial-gradient(ellipse 220px 70px at 80% 65%, rgba(0,0,0,0.10), transparent 70%),
    radial-gradient(ellipse 160px 50px at 55% 90%, rgba(0,0,0,0.10), transparent 70%),
    linear-gradient(160deg, #2E2213, #1A1108 70%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-px);
  font-size: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-overflow-scrolling: touch;
}

/* ── Layout principal ──────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 420px;
  margin: 0 auto;
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────────── */
#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px 6px;
  border-bottom: 2px solid var(--border);
  background: var(--panel2);
  flex-shrink: 0;
}
#dungeon-name {
  font-size: 7px;
  color: var(--gold);
  letter-spacing: 1px;
  text-transform: uppercase;
}
#room-info {
  font-size: 6px;
  color: var(--text-dim);
}
#turn-counter {
  font-size: 6px;
  color: var(--purple-lit);
}

/* ── Batalha ───────────────────────────────────────────────────── */
#battle {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 6px 8px;
  gap: 4px;
}

/* ── Rótulos das grades ────────────────────────────────────────── */
.grid-label {
  font-size: 6px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 3px;
}
.grid-label.enemy { color: var(--red); }
.grid-label.player { color: var(--green-lit); }

/* ── Grade ─────────────────────────────────────────────────────── */
.grid-wrapper {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.grid-row {
  display: flex;
  gap: 3px;
  justify-content: center;
}

.row-tag {
  font-size: 5px;
  color: var(--text-dim);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  display: flex;
  align-items: center;
  margin-right: 2px;
  letter-spacing: 1px;
}

/* ── Célula da grade ───────────────────────────────────────────── */
.cell {
  width: var(--cell-w);
  height: var(--cell-h);
  background: var(--panel);
  border: 2px dotted var(--border);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: default;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
}

/* Célula com inimigo vivo — clicável */
.cell.has-occupant.enemy-side {
  cursor: pointer;
  border-color: var(--red);
  border-style: solid;
}
.cell.has-occupant.enemy-side:hover,
.cell.has-occupant.enemy-side:focus {
  background: #2A0A08;
  border-color: #FF6B4A;
  outline: none;
}

/* Célula selecionada (alvo ativo) */
.cell.selected {
  background: #2A1008;
  border-color: var(--gold) !important;
  border-style: solid !important;
  animation: pulse-border 0.8s ease-in-out infinite;
}
@keyframes pulse-border {
  0%, 100% { border-color: var(--gold); }
  50%       { border-color: #A08040; }
}

/* Célula do jogador */
.cell.has-occupant.player-side {
  border-color: var(--green);
  border-style: solid;
}

/* Célula vazia */
.cell.empty {
  opacity: 0.3;
}

/* ── Conteúdo da célula ────────────────────────────────────────── */
.cell-emoji {
  font-size: 24px;
  line-height: 1;
  margin-bottom: 2px;
  filter: drop-shadow(0 0 3px rgba(0,0,0,0.8));
}

.cell-name {
  font-size: 5px;
  color: var(--text);
  text-align: center;
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}

/* HP bar dentro da célula */
.cell-hp-bar {
  width: 60px;
  height: 4px;
  background: #1A0808;
  border-radius: 1px;
  margin-top: 3px;
  overflow: hidden;
  border: 1px solid #2A1010;
}
.cell-hp-fill {
  height: 100%;
  border-radius: 1px;
  transition: width 0.3s ease;
}
.cell-hp-fill.high   { background: var(--green-lit); }
.cell-hp-fill.mid    { background: #B8A030; }
.cell-hp-fill.low    { background: var(--red); }

/* Indicador de terreno */
.cell-terrain {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 10px;
  line-height: 1;
}

/* Status effects */
.cell-status {
  position: absolute;
  bottom: 2px;
  left: 3px;
  font-size: 8px;
  line-height: 1;
}

/* ── Animações 4B ──────────────────────────────────────────────── */

/* Flash de dano — inimigo atingido */
@keyframes flash-damage {
  0%   { background: rgba(200, 75, 49, 0.85); }
  60%  { background: rgba(200, 75, 49, 0.4); }
  100% { background: var(--panel); }
}
.anim-damage {
  animation: flash-damage 0.35s ease-out forwards !important;
}

/* Flash de dano crítico — mais intenso, borda dourada */
@keyframes flash-crit {
  0%   { background: rgba(232,201,122,0.9); box-shadow: 0 0 8px rgba(232,201,122,0.8); }
  50%  { background: rgba(200,75,49,0.6);   box-shadow: 0 0 4px rgba(200,75,49,0.5); }
  100% { background: var(--panel);           box-shadow: none; }
}
.anim-crit {
  animation: flash-crit 0.45s ease-out forwards !important;
}

/* Flash de morte — escurece e some */
@keyframes flash-death {
  0%   { background: rgba(80,20,10,0.95); opacity: 1; }
  100% { background: rgba(20,5,5,0.5);    opacity: 0.4; }
}
.anim-death {
  animation: flash-death 0.5s ease-out forwards !important;
  pointer-events: none;
}

/* Flash de cura — verde pulsante */
@keyframes flash-heal {
  0%   { background: rgba(61,122,74,0.8); box-shadow: 0 0 6px rgba(93,191,106,0.6); }
  60%  { background: rgba(61,122,74,0.3); }
  100% { background: var(--panel); box-shadow: none; }
}
.anim-heal {
  animation: flash-heal 0.4s ease-out forwards !important;
}

/* Flash de terreno — laranja/roxo dependendo do tipo */
@keyframes flash-terrain {
  0%   { background: rgba(232,160,32,0.7); }
  100% { background: var(--panel); }
}
.anim-terrain {
  animation: flash-terrain 0.4s ease-out forwards !important;
}

/* Shake do HUD do jogador quando é atingido */
@keyframes shake-player {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-5px); }
  40%  { transform: translateX(5px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(3px); }
  100% { transform: translateX(0); }
}
.anim-shake {
  animation: shake-player 0.35s ease-out forwards !important;
}

/* Pulso de conjuração — célula do jogador ao lançar skill de área
   (várias células atingidas de uma vez, sem "carta viajando") */
@keyframes flash-cast {
  0%   { box-shadow: 0 0 0 rgba(232,201,122,0); }
  40%  { box-shadow: 0 0 10px 2px rgba(232,201,122,0.85); }
  100% { box-shadow: 0 0 0 rgba(232,201,122,0); }
}
.anim-cast {
  animation: flash-cast 0.35s ease-out forwards !important;
}

/* Centelha de impacto — colisão do ataque na célula alvo */
.impact-burst {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,220,120,0.9) 0%, rgba(255,120,60,0.55) 45%, transparent 75%);
  pointer-events: none;
  z-index: 40;
  animation: impact-pop 0.4s ease-out forwards;
}
@keyframes impact-pop {
  0%   { opacity: 0;   transform: scale(0.3); }
  35%  { opacity: 1;   transform: scale(1.1); }
  100% { opacity: 0;   transform: scale(1.6); }
}

/* Número de dano flutuante sobre a célula */
.dmg-float {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-px);
  font-size: 8px;
  font-weight: bold;
  pointer-events: none;
  z-index: 50;
  white-space: nowrap;
  animation: float-up 0.7s ease-out forwards;
}
.dmg-float.dmg   { color: #FF8060; text-shadow: 0 0 4px rgba(200,75,49,0.8); }
.dmg-float.crit  { color: var(--gold); font-size: 10px; text-shadow: 0 0 6px rgba(232,201,122,0.9); }
.dmg-float.heal  { color: var(--green-lit); text-shadow: 0 0 4px rgba(93,191,106,0.7); }
.dmg-float.miss  { color: var(--text-dim); font-size: 7px; }

@keyframes float-up {
  0%   { opacity: 1;   transform: translateX(-50%) translateY(0); }
  70%  { opacity: 0.9; transform: translateX(-50%) translateY(-20px); }
  100% { opacity: 0;   transform: translateX(-50%) translateY(-28px); }
}

/* ── Separador de batalha ──────────────────────────────────────── */
#vs-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  flex-shrink: 0;
}
.vs-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
#vs-text {
  font-size: 7px;
  color: var(--gold-dim);
  letter-spacing: 3px;
}

/* ── Painel do jogador (HP) ────────────────────────────────────── */
#player-hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 2px;
  flex-shrink: 0;
}
#player-hud-emoji { font-size: 18px; }
#player-hud-info { flex: 1; }
#player-hud-name {
  font-size: 6px;
  color: var(--gold);
  margin-bottom: 3px;
}
#player-hp-bar {
  width: 100%;
  height: 6px;
  background: #1A0808;
  border-radius: 1px;
  overflow: hidden;
  border: 1px solid #2A1010;
}
#player-hp-fill {
  height: 100%;
  border-radius: 1px;
  transition: width 0.3s ease;
}
#player-hp-text {
  font-size: 5px;
  color: var(--text-dim);
  margin-top: 2px;
  font-family: var(--font-log);
  font-size: 12px;
}

/* ── Ações ─────────────────────────────────────────────────────── */
#actions {
  flex-shrink: 0;
  padding: 6px 8px;
  background: var(--panel2);
  border-top: 2px solid var(--border);
}

#action-hint {
  font-size: 6px;
  color: var(--text-dim);
  margin-bottom: 6px;
  min-height: 10px;
  text-align: center;
}

#action-buttons {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font-family: var(--font-px);
  font-size: 6px;
  padding: 6px 8px;
  border: 2px solid;
  border-radius: 2px;
  cursor: pointer;
  letter-spacing: 0.5px;
  line-height: 1;
  transition: opacity 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); opacity: 0.85; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Botões viram "carimbos de papel" — fundo de pergaminho, cor da tinta
   combinando com a borda, em vez de chips escuros neon. */
.btn-attack {
  background: var(--paper);
  border-color: var(--red);
  color: #7A2318;
}
.btn-skill {
  background: var(--paper);
  border-color: var(--purple);
  color: #4A2F78;
}
.btn-item {
  background: var(--paper);
  border-color: var(--green);
  color: #1F4A28;
}
.btn-advance {
  background: var(--paper);
  border-color: var(--gold);
  color: #6B4A1A;
  width: 100%;
}
.btn-abandon {
  background: transparent;
  border-color: var(--text-dim);
  color: var(--text-dim);
  font-size: 5px;
}

/* ── Submenu de skills ─────────────────────────────────────────── */
#skill-menu {
  display: none;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}
#skill-menu.visible { display: flex; }

.btn-skill-item {
  background: var(--paper);
  border-color: var(--purple);
  color: #4A2F78;
  font-family: var(--font-px);
  font-size: 5px;
  padding: 5px 7px;
  border: 2px solid;
  border-radius: 2px;
  cursor: pointer;
}

/* ── Toast de log ──────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
  pointer-events: none;
  z-index: 100;
  max-width: 340px;
  width: 90%;
}

.toast {
  font-family: var(--font-log);
  font-size: 16px;
  padding: 6px 12px;
  border-radius: 2px;
  border-left: 3px solid;
  background: rgba(13,13,13,0.95);
  animation: toast-in 0.2s ease, toast-out 0.3s ease 2s forwards;
  line-height: 1.3;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}
.toast.attack  { border-color: var(--red);       color: #FF9070; }
.toast.skill   { border-color: var(--purple-lit); color: var(--purple-lit); }
.toast.enemy   { border-color: #666;             color: #AAA; }
.toast.heal    { border-color: var(--green-lit);  color: var(--green-lit); }
.toast.terrain { border-color: #E8A020;           color: #E8A020; }
.toast.system  { border-color: var(--gold);       color: var(--gold); }
.toast.death   { border-color: var(--text-dim);   color: var(--text-dim); }

/* ── Overlay de estado (carregando / game over / vitória) ──────── */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
}
#overlay.visible { display: flex; }
#overlay-emoji { font-size: 48px; }
#overlay-title { font-size: 12px; color: var(--gold); line-height: 1.8; }
#overlay-sub   { font-size: 7px;  color: var(--text-dim); line-height: 2; }
#overlay-btn   {
  font-family: var(--font-px);
  font-size: 8px;
  padding: 10px 20px;
  background: var(--paper);
  border: 2px solid var(--gold);
  color: var(--ink);
  border-radius: 2px;
  cursor: pointer;
  margin-top: 8px;
}

/* ── Tela de seleção de dungeon ────────────────────────────────── */
#dungeon-select {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: 20px 16px;
  gap: 12px;
  overflow-y: auto;
}
#dungeon-select h1 {
  font-size: 9px;
  color: var(--gold);
  text-align: center;
  line-height: 2;
  margin-bottom: 8px;
}
.dungeon-card {
  background: var(--paper);
  border: 2px solid var(--border);
  border-radius: 2px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.dungeon-card:hover { border-color: var(--gold); }
.dungeon-card-name {
  font-size: 8px;
  color: #6B4A1A;
  margin-bottom: 6px;
}
.dungeon-card-desc {
  font-family: var(--font-log);
  font-size: 15px;
  color: var(--ink);
  margin-bottom: 8px;
  line-height: 1.4;
}
.dungeon-card-meta {
  font-size: 6px;
  color: var(--ink-dim);
  display: flex;
  gap: 12px;
}
.diff-badge {
  padding: 2px 6px;
  border-radius: 2px;
  font-size: 5px;
}
.diff-facil    { background: #0A2A0A; color: var(--green-lit); border: 1px solid var(--green); }
.diff-normal   { background: #0A1A2A; color: #70A0E0;          border: 1px solid var(--blue); }
.diff-dificil  { background: #2A0A08; color: #FF8060;          border: 1px solid var(--red); }
.diff-epico    { background: #1A0A2A; color: var(--purple-lit); border: 1px solid var(--purple); }

/* ══════════════════════════════════════════════════════════════════════
   Componentes genéricos do Hub e das páginas do sistema geral
   ══════════════════════════════════════════════════════════════════════ */

/* ── Borda Estilizada (Pixel Art) ────────────────────────────────────── */
.page {
  max-width: 420px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px 12px 24px;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

.page-header .back-link {
  font-family: var(--font-px);
  font-size: 9px;
  color: var(--text-dim);
  text-decoration: none;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
}

.page-header h1 {
  font-family: var(--font-px);
  font-size: 10px;
  color: var(--gold);
  letter-spacing: 1px;
}

/* ── Barra de stat genérica (HP/Energia/EXP/etc) ─────────────────────── */
.stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-log);
  font-size: 15px;
  color: var(--ink);
  margin-bottom: 4px;
}
.stat-bar {
  flex: 1;
  height: 10px;
  background: #1A0808;
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.stat-bar-fill {
  height: 100%;
  transition: width 0.3s ease;
}
.stat-bar-fill.hp { background: var(--red); }
.stat-bar-fill.energy { background: var(--blue); }
.stat-bar-fill.exp { background: var(--gold); }

/* ── Card genérico ────────────────────────────────────────────────────── */
.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  margin-bottom: 8px;
  color: var(--ink);
}

/* ── Grade de tiles do hub ────────────────────────────────────────────── */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}

.tile {
  background: var(--paper);
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-decoration: none;
  color: var(--ink);
  min-height: 68px;
  transition: border-color 0.15s, background 0.15s;
}
.tile:active { transform: scale(0.96); }
.tile .tile-emoji { font-size: 22px; }
.tile .tile-label {
  font-family: var(--font-px);
  font-size: 6px;
  text-align: center;
  letter-spacing: 0.5px;
}
.tile.available { border-color: var(--gold-dim); }
.tile.available:hover, .tile.available:active { border-color: var(--gold); }
.tile.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Lista genérica (inventário, missões, ranking, bestiário) ────────── */
.list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 6px;
}
.list-row .row-emoji { font-size: 20px; flex-shrink: 0; }
.list-row .row-main { flex: 1; min-width: 0; }
.list-row .row-title {
  font-family: var(--font-px);
  font-size: 8px;
  color: var(--ink);
}
.list-row .row-sub {
  font-family: var(--font-log);
  font-size: 14px;
  color: var(--ink-dim);
}

/* Variante tocável de .list-row — usa quando o toque revela mais info
   (ex: descrição num toast), em vez de navegar/executar uma ação. */
.list-row.clickable {
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.list-row.clickable:active {
  transform: scale(0.98);
  border-color: var(--gold-dim, var(--border));
}

.empty-state {
  font-family: var(--font-log);
  font-size: 16px;
  color: var(--ink-dim);
  text-align: center;
  padding: 24px 8px;
}

.loading-state {
  font-family: var(--font-log);
  font-size: 16px;
  color: var(--ink-dim);
  text-align: center;
  padding: 24px 8px;
}

/* ══════════════════════════════════════════════════════════════════════
   Componentes genéricos do Hub e das páginas do sistema geral
   ══════════════════════════════════════════════════════════════════════ */

/* ── Borda Estilizada (Pixel Art) ────────────────────────────────────── */
.pixel-box, .card {
  position: relative;
  /* Sobrescreve a borda padrão usando o Dourado do seu tema */
  border: 2px solid var(--gold) !important;
  /* Cria a linha interna dupla usando a cor de fundo do seu painel */
  box-shadow: inset 0 0 0 2px var(--panel), inset 0 0 0 4px var(--gold);
}

/* Cria os 4 quadradinhos nos cantos */
.pixel-box::after, .card::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none; /* Deixa o clique passar para o botão */
  background:
    linear-gradient(var(--gold), var(--gold)) 2px 2px / 4px 4px no-repeat,
    linear-gradient(var(--gold), var(--gold)) calc(100% - 2px) 2px / 4px 4px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 2px calc(100% - 2px) / 4px 4px no-repeat,
    linear-gradient(var(--gold), var(--gold)) calc(100% - 2px) calc(100% - 2px) / 4px 4px no-repeat;
  z-index: 10;
}
/* ────────────────────────────────────────────────────────────────────── */
