:root {
  --bg-main: #0b0f17;
  --bg-panel: #131a26;
  --bg-card: #1b2434;
  --border: #2c384e;
  --text-main: #e6edf3;
  --text-muted: #8b949e;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --blue: #3b82f6;
  --green: #10b981;
  --red: #ef4444;
  --purple: #a855f7;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Aviso si se usa en vertical en móvil */
.rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 23, 0.97);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}

@media screen and (max-width: 768px) and (orientation: portrait) {
  .rotate-overlay {
    display: flex;
  }
}

.rotate-box {
  max-width: 320px;
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: 16px;
  padding: 24px;
}

.rotate-icon {
  font-size: 42px;
  margin-bottom: 10px;
}

/* Barra superior */
.topbar {
  height: 46px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-hex {
  font-size: 22px;
  color: var(--accent);
}

.brand h1 {
  font-size: 14px;
  line-height: 1.1;
}

.badge {
  font-size: 11px;
  color: var(--accent);
}

.hearts-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.commander-pill, .turn-pill, .gold-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
}

.turn-pill {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Botones */
.btn {
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary { background: var(--accent); color: #111; }
.btn-secondary { background: var(--blue); }
.btn-warning { background: var(--green); color: #081c15; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-main); }
.btn-small { padding: 4px 7px; font-size: 11px; }

/* Layout Principal Horizontal */
.arena-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 230px 1fr 265px;
  gap: 8px;
  padding: 8px;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.card-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.box-header h3 {
  font-size: 12px;
  font-weight: 700;
}

.hint {
  font-size: 10px;
  color: var(--text-muted);
}

/* Emblemas */
.crest-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.crest-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 2px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.crest-icon { font-size: 14px; }
.crest-label { font-size: 9px; color: var(--text-muted); }
.crest-item strong { font-size: 13px; color: var(--accent); }

/* Sinergias */
.synergies-box {
  flex: 1;
}

.synergies-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-right: 2px;
}

.synergy-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 7px;
  font-size: 11px;
}

.synergy-row.active {
  border-color: var(--accent);
  background: rgba(245, 158, 11, 0.12);
}

.synergy-top {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.synergy-desc {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Centro: Tablero Hexagonal + Dados */
.center-stage {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.board-wrapper {
  flex: 1;
  background: radial-gradient(circle at center, #162033 0%, #0b0f17 100%);
  border: 1px solid var(--border);
  border-radius: 10px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

#hex-board {
  width: 100%;
  height: 100%;
}

.board-hint {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(19, 26, 38, 0.9);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  color: #cbd5e1;
  white-space: nowrap;
  pointer-events: none;
}

/* Estilos SVG Hexágonos */
.hex-cell {
  cursor: pointer;
  transition: fill 0.15s ease, stroke 0.15s ease;
}

.hex-cell.void {
  fill: rgba(255, 255, 255, 0.02);
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1;
}

.hex-cell.player-tile {
  fill: rgba(59, 130, 246, 0.22);
  stroke: #3b82f6;
  stroke-width: 1.5;
}

.hex-cell.enemy-tile {
  fill: rgba(239, 68, 68, 0.22);
  stroke: #ef4444;
  stroke-width: 1.5;
}

.hex-cell.neutral-tile {
  fill: rgba(148, 163, 184, 0.16);
  stroke: #64748b;
  stroke-width: 1.5;
}

.hex-cell.highlight-summon {
  fill: rgba(245, 158, 11, 0.35);
  stroke: #fbbf24;
  stroke-width: 2.2;
}

.hex-cell.highlight-move {
  fill: rgba(16, 185, 129, 0.35);
  stroke: #34d399;
  stroke-width: 2.2;
}

.hex-cell.highlight-attack {
  fill: rgba(239, 68, 68, 0.48);
  stroke: #f87171;
  stroke-width: 2.5;
}

.hex-cell.selected {
  stroke: #ffffff;
  stroke-width: 2.8;
}

/* Bandeja de Dados */
.dice-tray {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  flex-shrink: 0;
}

.dice-tray-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  margin-bottom: 5px;
}

.dice-buttons {
  display: flex;
  gap: 6px;
}

.dice-hand {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.die-card {
  min-width: 118px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 5px 7px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, transform 0.1s;
}

.die-card.selected {
  border-color: var(--accent);
  background: rgba(245, 158, 11, 0.14);
  transform: translateY(-2px);
}

.die-card.summon-ready {
  border-color: var(--green);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.3);
}

.die-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
}

.die-traits {
  font-size: 9px;
  color: var(--accent);
  margin: 2px 0;
}

.die-faces {
  font-size: 10px;
  color: var(--text-muted);
}

/* Columna Derecha */
.inspector-box {
  flex: 1.1;
}

.unit-inspector {
  font-size: 11px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.unit-inspector.empty {
  color: var(--text-muted);
  justify-content: center;
  text-align: center;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  text-align: center;
}

.stat-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px;
}

.stat-pill span {
  display: block;
  font-size: 9px;
  color: var(--text-muted);
}

.equip-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.equip-slot {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 4px;
  text-align: center;
  font-size: 10px;
}

.equip-slot.filled {
  border-style: solid;
  border-color: var(--purple);
}

.spells-box {
  flex: 0.95;
}

.spells-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.spell-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-size: 10px;
}

.log-box {
  flex: 0.8;
}

.battle-log {
  overflow-y: auto;
  font-size: 10px;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Modales */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 12px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(820px, 95vw);
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  padding: 14px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.grimorio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  overflow-y: auto;
}

.grimorio-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.grimorio-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px;
  font-size: 11px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.shop-box {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.result-modal {
  max-width: 420px;
  text-align: center;
  gap: 10px;
}

.result-loot {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
}

.small-muted {
  font-size: 11px;
  color: var(--text-muted);
}

/* Ajustes para móviles horizontales de baja altura */
@media screen and (max-height: 450px) {
  .topbar { height: 38px; }
  .arena-layout { grid-template-columns: 205px 1fr 240px; padding: 4px; gap: 5px; }
  .card-box { padding: 5px; }
  .die-card { min-width: 105px; padding: 4px 6px; }
}