:root {
  --bg-deep: #0b0914;
  --bg-castle: #151126;
  --bg-card: rgba(26, 21, 43, 0.88);
  --bg-parchment: #f5ebd6;
  --bg-parchment-dark: #e6d3ad;
  --text-parchment: #2c1e14;
  --gold-light: #ffe28a;
  --gold: #d4af37;
  --gold-dark: #99731c;
  --crimson: #8b1e24;
  --crimson-bright: #d9383a;
  --emerald: #1b6344;
  --emerald-bright: #2ecc71;
  --sapphire: #1c3f7c;
  --sapphire-bright: #4aa3df;
  --amethyst: #6c3483;
  --text-light: #f8f1e5;
  --text-muted: #bfb3d1;
  --border-gold: 2px solid rgba(212, 175, 55, 0.55);
  --shadow-magic: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 20px rgba(212, 175, 55, 0.18);
  --radius-lg: 18px;
  --radius-md: 12px;
}

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

body {
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-deep);
  background-image:
    radial-gradient(circle at 20% 15%, rgba(108, 52, 131, 0.28) 0%, transparent 45%),
    radial-gradient(circle at 80% 20%, rgba(212, 175, 55, 0.16) 0%, transparent 40%),
    radial-gradient(circle at 50% 85%, rgba(28, 63, 124, 0.3) 0%, transparent 50%),
    linear-gradient(180deg, #090712 0%, #161129 60%, #0d0a18 100%);
  color: var(--text-light);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Fondo de estrellas y velas flotantes */
.magic-sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.star-particle {
  position: absolute;
  border-radius: 50%;
  background: #fff6d6;
  box-shadow: 0 0 8px #ffd700;
  animation: twinkle var(--dur, 4s) ease-in-out infinite alternate;
  opacity: 0.5;
}

@keyframes twinkle {
  0% { opacity: 0.2; transform: scale(0.8) translateY(0); }
  100% { opacity: 0.9; transform: scale(1.25) translateY(-8px); }
}

.floating-candle {
  position: absolute;
  width: 8px;
  height: 28px;
  background: linear-gradient(180deg, #fffdf7 0%, #e5d2b0 100%);
  border-radius: 3px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  animation: floatCandle var(--dur, 5s) ease-in-out infinite alternate;
  opacity: 0.75;
}

.floating-candle::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 12px;
  background: radial-gradient(circle, #fff 10%, #ffae00 60%, transparent 100%);
  border-radius: 50% 50% 35% 35%;
  filter: drop-shadow(0 0 8px #ffae00);
  animation: flicker 0.8s infinite alternate;
}

@keyframes floatCandle {
  0% { transform: translateY(0px); }
  100% { transform: translateY(-16px); }
}

@keyframes flicker {
  0% { transform: translateX(-50%) scale(0.92) rotate(-2deg); }
  100% { transform: translateX(-50%) scale(1.08) rotate(2deg); }
}

/* Tipografía mágica */
h1, h2, h3, .magic-title {
  font-family: 'Cinzel Decorative', 'Cinzel', Georgia, serif;
  letter-spacing: 0.03em;
}

/* Cabecera */
.app-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: rgba(12, 9, 23, 0.85);
  border-bottom: 2px solid rgba(212, 175, 55, 0.45);
  backdrop-filter: blur(10px);
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  cursor: pointer;
}

.brand-crest {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle, #38235c 0%, #150d2a 100%);
  border: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 0 14px rgba(212, 175, 55, 0.4);
}

.brand-text h1 {
  font-size: 1.35rem;
  background: linear-gradient(90deg, #fff3c4, #d4af37, #fff3c4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 10px rgba(212, 175, 55, 0.25);
}

.brand-text p {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(212, 175, 55, 0.4);
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--gold-light);
}

.btn-icon-top {
  background: rgba(212, 175, 55, 0.14);
  border: 1px solid rgba(212, 175, 55, 0.55);
  color: var(--gold-light);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-icon-top:hover {
  background: rgba(212, 175, 55, 0.28);
  transform: translateY(-1px);
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.35);
}

/* Contenedor Principal */
.main-container {
  position: relative;
  z-index: 5;
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem;
}

.screen {
  display: none;
  animation: fadeIn 0.35s ease;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ZONA INICIAL: HUB DE CONFIGURACIÓN Y AVATAR */
.hub-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 980px) {
  .hub-grid {
    grid-template-columns: 1fr;
  }
}

.magic-card {
  background: var(--bg-card);
  border: var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  box-shadow: var(--shadow-magic);
  backdrop-filter: blur(12px);
  position: relative;
  overflow: hidden;
}

.magic-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid rgba(212, 175, 55, 0.25);
}

.card-header h2 {
  font-size: 1.18rem;
  color: var(--gold-light);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Panel de Avatar en la Zona Inicial */
.avatar-stage-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(108, 52, 131, 0.45), rgba(13, 10, 24, 0.9));
  border: 2px solid rgba(212, 175, 55, 0.5);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1rem;
  position: relative;
}

.house-ribbon {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.btn-random-hat {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(212, 175, 55, 0.22);
  border: 1px solid var(--gold);
  color: var(--gold-light);
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s;
}

.btn-random-hat:hover {
  background: var(--gold);
  color: #1a1204;
}

.avatar-svg-container {
  width: 210px;
  height: 225px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.6));
  animation: wizardFloat 3.5s ease-in-out infinite alternate;
}

@keyframes wizardFloat {
  0% { transform: translateY(0px); }
  100% { transform: translateY(-6px); }
}

.wizard-name-input-wrap {
  width: 100%;
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

.wizard-name-input {
  width: 100%;
  background: rgba(11, 9, 20, 0.8);
  border: 1px solid rgba(212, 175, 55, 0.55);
  color: var(--gold-light);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.05rem;
  text-align: center;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  outline: none;
}

.wizard-name-input:focus {
  border-color: var(--gold-light);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.35);
}

/* Pestañas del Creador de Avatar */
.avatar-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.avatar-tab-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(212, 175, 55, 0.25);
  color: var(--text-muted);
  padding: 0.42rem 0.3rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s;
  font-family: inherit;
}

.avatar-tab-btn.active {
  background: rgba(212, 175, 55, 0.22);
  border-color: var(--gold);
  color: var(--gold-light);
}

.avatar-options-panel {
  min-height: 155px;
}

.option-group-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
  font-weight: 800;
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.swatch-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  color: var(--text-light);
  border-radius: 8px;
  padding: 0.45rem 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.18s;
  font-family: inherit;
  text-align: center;
}

.swatch-btn:hover {
  border-color: rgba(212, 175, 55, 0.6);
  transform: translateY(-1px);
}

.swatch-btn.selected {
  background: rgba(212, 175, 55, 0.24);
  border-color: var(--gold-light);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
  color: var(--gold-light);
}

.color-dots-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.color-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: transform 0.15s;
}

.color-dot.selected {
  transform: scale(1.18);
  border-color: #fff;
  box-shadow: 0 0 10px var(--gold);
}

/* CONFIGURACIÓN DE OPERACIONES Y CURSOS */
.config-section {
  margin-bottom: 1.25rem;
}

.config-section-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--gold-light);
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.config-section-title span.hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Tarjetas de Operaciones (+, -, ×, ÷) */
.ops-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

@media (max-width: 650px) {
  .ops-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.op-card {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.65rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  position: relative;
}

.op-card:hover {
  transform: translateY(-2px);
  border-color: rgba(212, 175, 55, 0.55);
}

.op-card.selected {
  background: linear-gradient(145deg, rgba(212, 175, 55, 0.24), rgba(108, 52, 131, 0.35));
  border-color: var(--gold-light);
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.3);
}

.op-check-badge {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
}

.op-card.selected .op-check-badge {
  background: var(--emerald-bright);
  color: #082917;
  font-weight: 900;
}

.op-symbol {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.1;
  margin-bottom: 0.25rem;
  color: var(--gold-light);
}

.op-name {
  font-weight: 800;
  font-size: 0.92rem;
}

.op-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Selector de Curso / Nivel de Primaria */
.grades-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
}

@media (max-width: 720px) {
  .grades-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.grade-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 0.6rem 0.4rem;
  color: var(--text-light);
  cursor: pointer;
  text-align: center;
  transition: all 0.18s;
  font-family: inherit;
}

.grade-btn:hover {
  border-color: var(--gold);
}

.grade-btn.selected {
  background: rgba(212, 175, 55, 0.25);
  border-color: var(--gold-light);
  color: var(--gold-light);
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.25);
}

.grade-num {
  font-size: 1.05rem;
  font-weight: 900;
  display: block;
}

.grade-rank {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
}

.grade-btn.selected .grade-rank {
  color: #fff2c2;
}

/* Selector de Tablas de Multiplicar */
.tables-selector-box {
  background: rgba(11, 9, 20, 0.55);
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  margin-top: 0.75rem;
}

.tables-quick-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.btn-mini {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(212, 175, 55, 0.35);
  color: var(--text-light);
  border-radius: 6px;
  padding: 0.22rem 0.55rem;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.btn-mini:hover {
  background: rgba(212, 175, 55, 0.25);
  color: var(--gold-light);
}

.tables-chips {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0.4rem;
  margin-top: 0.6rem;
}

@media (max-width: 680px) {
  .tables-chips {
    grid-template-columns: repeat(6, 1fr);
  }
}

.table-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 0.45rem 0.2rem;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.table-chip.selected {
  background: linear-gradient(135deg, #d4af37, #9c7416);
  border-color: #fff3c4;
  color: #161004;
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.4);
}

/* Ajustes adicionales: Modo de respuesta y Monstruo inicial */
.settings-row-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

@media (max-width: 650px) {
  .settings-row-split {
    grid-template-columns: 1fr;
  }
}

.mode-switch {
  display: flex;
  background: rgba(11, 9, 20, 0.6);
  border-radius: 10px;
  padding: 0.25rem;
  border: 1px solid rgba(212, 175, 55, 0.3);
}

.mode-switch-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
  transition: 0.2s;
}

.mode-switch-btn.active {
  background: rgba(212, 175, 55, 0.25);
  color: var(--gold-light);
  border: 1px solid rgba(212, 175, 55, 0.5);
}

/* Previsualización de Monstruos en el Hub */
.monster-preview-strip {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.35rem;
}

.monster-mini-card {
  min-width: 96px;
  background: rgba(11, 9, 20, 0.65);
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 0.45rem;
  text-align: center;
  cursor: pointer;
  transition: 0.2s;
  flex-shrink: 0;
}

.monster-mini-card.selected {
  border-color: var(--gold-light);
  background: rgba(212, 175, 55, 0.18);
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.3);
}

.monster-mini-thumb {
  width: 54px;
  height: 54px;
  margin: 0 auto 0.25rem;
  border-radius: 8px;
  object-fit: cover;
  background: #1b142e;
  border: 1px solid rgba(212, 175, 55, 0.4);
}

.monster-mini-name {
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.monster-mini-hearts {
  font-size: 0.68rem;
  color: #ff6b81;
  font-weight: 800;
}

/* Botón Principal de Empezar Aventura */
.btn-start-duel {
  width: 100%;
  margin-top: 0.5rem;
  padding: 1rem 1.5rem;
  border-radius: 14px;
  border: 2px solid #fff3c4;
  background: linear-gradient(135deg, #d4af37 0%, #b5851b 50%, #8b1e24 100%);
  color: #fff;
  font-family: 'Cinzel Decorative', serif;
  font-size: 1.25rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(212, 175, 55, 0.4);
  transition: all 0.22s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.btn-start-duel:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 12px 30px rgba(212, 175, 55, 0.6);
}

/* ==========================================
   PANTALLA DE COMBATE / DUELO ARITMÉTICO 2D
   ========================================== */
.battle-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.active-filters-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.filter-tag {
  background: rgba(212, 175, 55, 0.16);
  border: 1px solid rgba(212, 175, 55, 0.4);
  color: var(--gold-light);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

/* ESCENARIO 2D: MAGO VS MONSTRUO */
.arena-stage {
  position: relative;
  background:
    radial-gradient(circle at 50% 30%, rgba(108, 52, 131, 0.38), transparent 65%),
    linear-gradient(180deg, rgba(19, 14, 36, 0.92) 0%, rgba(33, 23, 54, 0.95) 72%, rgba(22, 17, 32, 0.98) 100%);
  border: 2px solid rgba(212, 175, 55, 0.65);
  border-radius: var(--radius-lg);
  padding: 1.2rem 1.5rem 1.4rem;
  box-shadow: var(--shadow-magic);
  display: grid;
  grid-template-columns: 1fr 120px 1fr;
  align-items: center;
  gap: 0.5rem;
  min-height: 295px;
  overflow: hidden;
  margin-bottom: 1.15rem;
}

@media (max-width: 780px) {
  .arena-stage {
    grid-template-columns: 1fr 60px 1fr;
    padding: 0.9rem;
    min-height: 250px;
  }
}

/* Suelo de piedra del castillo */
.arena-stage::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 36px;
  background: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 0px,
    rgba(255, 255, 255, 0.03) 60px,
    rgba(0, 0, 0, 0.25) 60px,
    rgba(0, 0, 0, 0.25) 64px
  ), linear-gradient(180deg, rgba(212, 175, 55, 0.15), rgba(10, 8, 18, 0.95));
  border-top: 1px solid rgba(212, 175, 55, 0.35);
  z-index: 1;
}

.combatant-col {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.combatant-hud {
  background: rgba(11, 9, 20, 0.85);
  border: 1.5px solid rgba(212, 175, 55, 0.5);
  border-radius: 12px;
  padding: 0.5rem 0.9rem;
  width: 100%;
  max-width: 310px;
  margin-bottom: 0.65rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.hud-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.combatant-name {
  font-family: 'Cinzel', serif;
  font-weight: 800;
  font-size: 1rem;
  color: var(--gold-light);
}

.combatant-subtitle {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 700;
}

/* Barra de Corazones / Vidas del Monstruo */
.monster-hearts-row {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.heart-icon {
  font-size: 1.35rem;
  transition: all 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3);
  filter: drop-shadow(0 0 6px rgba(255, 59, 92, 0.65));
}

.heart-icon.lost {
  filter: grayscale(1) opacity(0.28);
  transform: scale(0.78);
}

.heart-icon.just-lost {
  animation: heartShatter 0.6s ease forwards;
}

@keyframes heartShatter {
  0% { transform: scale(1.5); filter: brightness(2); }
  50% { transform: scale(1.2) translateY(-10px) rotate(15deg); opacity: 0.7; }
  100% { transform: scale(0.75); filter: grayscale(1) opacity(0.25); }
}

.hp-bar-track {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.hp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff4757, #ff6b81);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 10px rgba(255, 71, 87, 0.7);
}

/* Sprite del Mago y del Monstruo en la Arena */
.battle-wizard-sprite {
  width: 165px;
  height: 175px;
  transition: transform 0.25s ease;
  position: relative;
}

.battle-wizard-sprite.cast-anim {
  animation: wizardCast 0.65s ease;
}

@keyframes wizardCast {
  0% { transform: translateX(0) scale(1); }
  35% { transform: translateX(22px) scale(1.08) rotate(3deg); filter: drop-shadow(0 0 18px #ffd700); }
  100% { transform: translateX(0) scale(1); }
}

.monster-stage-box {
  position: relative;
  width: 175px;
  height: 175px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.monster-artwork-frame {
  width: 168px;
  height: 168px;
  border-radius: 20px;
  border: 3px solid var(--gold);
  background: radial-gradient(circle, #2a1b4e 0%, #100b1c 100%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.75), 0 0 22px rgba(212, 175, 55, 0.28);
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: monsterIdle 3s ease-in-out infinite alternate;
}

.monster-artwork-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.monster-fallback-svg {
  width: 100%;
  height: 100%;
}

@keyframes monsterIdle {
  0% { transform: translateY(0px) scale(1); }
  100% { transform: translateY(-7px) scale(1.03); }
}

.monster-artwork-frame.hit-anim {
  animation: monsterHit 0.55s ease !important;
}

@keyframes monsterHit {
  0% { transform: translateX(0); filter: brightness(1); }
  20% { transform: translateX(14px) rotate(6deg) scale(0.92); filter: brightness(2.5) drop-shadow(0 0 20px #ff4757); }
  45% { transform: translateX(-12px) rotate(-5deg); }
  70% { transform: translateX(8px) rotate(3deg); }
  100% { transform: translateX(0); filter: brightness(1); }
}

.monster-artwork-frame.defeat-anim {
  animation: monsterDefeat 0.85s ease forwards !important;
}

@keyframes monsterDefeat {
  0% { transform: scale(1) rotate(0deg); opacity: 1; filter: brightness(2); }
  50% { transform: scale(1.18) rotate(8deg); filter: brightness(3) hue-rotate(90deg); }
  100% { transform: scale(0.1) rotate(-25deg); opacity: 0; }
}

/* Centro de la Arena: Rayo de Hechizo y Textos Flotantes */
.arena-center-fx {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.vs-medallion {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle, #38235c, #140c24);
  border: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cinzel Decorative', serif;
  font-weight: 900;
  color: var(--gold-light);
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.45);
}

.spell-beam {
  position: absolute;
  top: 52%;
  left: -90px;
  right: -90px;
  height: 14px;
  background: linear-gradient(90deg, #fff, #ffd700, #ff6b81, #a55eea);
  border-radius: 999px;
  box-shadow: 0 0 24px #ffd700, 0 0 40px #ff4757;
  opacity: 0;
  pointer-events: none;
  transform: scaleX(0);
  transform-origin: left center;
}

.spell-beam.fire {
  animation: shootBeam 0.55s ease-out forwards;
}

@keyframes shootBeam {
  0% { opacity: 1; transform: scaleX(0.05); }
  50% { opacity: 1; transform: scaleX(1); }
  100% { opacity: 0; transform: scaleX(1.05); }
}

.floating-combat-text {
  position: absolute;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-weight: 900;
  font-size: 1.15rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
}

.floating-combat-text.show-hit {
  background: rgba(46, 204, 113, 0.95);
  color: #052612;
  border: 2px solid #fff;
  box-shadow: 0 6px 20px rgba(46, 204, 113, 0.5);
  animation: floatUpBanner 1.2s ease forwards;
}

.floating-combat-text.show-miss {
  background: rgba(231, 76, 60, 0.95);
  color: #fff;
  border: 2px solid #ffd2cc;
  box-shadow: 0 6px 20px rgba(231, 76, 60, 0.5);
  animation: floatUpBanner 1.3s ease forwards;
}

@keyframes floatUpBanner {
  0% { opacity: 0; transform: translate(-50%, 15px) scale(0.8); }
  20% { opacity: 1; transform: translate(-50%, 0px) scale(1.05); }
  80% { opacity: 1; transform: translate(-50%, -8px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -22px) scale(0.95); }
}

/* ==========================================
   PERGAMINO DE LA OPERACIÓN MATEMÁTICA
   ========================================== */
.spellbook-card {
  background: linear-gradient(180deg, var(--bg-parchment) 0%, var(--bg-parchment-dark) 100%);
  color: var(--text-parchment);
  border: 4px solid var(--gold);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.5rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.65), inset 0 0 30px rgba(153, 115, 28, 0.25);
  max-width: 820px;
  margin: 0 auto;
  position: relative;
}

.spellbook-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-weight: 800;
  color: #69491a;
  font-size: 0.9rem;
}

.question-display {
  background: rgba(255, 255, 255, 0.72);
  border: 2px dashed rgba(153, 115, 28, 0.55);
  border-radius: 16px;
  padding: 1.1rem 1.5rem;
  text-align: center;
  margin-bottom: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.math-expression {
  font-size: 3.1rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #1f1308;
  line-height: 1.1;
}

@media (max-width: 600px) {
  .math-expression {
    font-size: 2.35rem;
  }
}

.math-answer-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 95px;
  height: 68px;
  padding: 0 0.75rem;
  border-radius: 12px;
  background: #fff;
  border: 3px solid var(--gold-dark);
  color: var(--crimson);
  font-size: 2.6rem;
  font-weight: 900;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.12);
}

/* Botones de Opción Múltiple (4 Hechizos) */
.choices-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
}

@media (max-width: 680px) {
  .choices-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.choice-spell-btn {
  background: linear-gradient(180deg, #2b1d47 0%, #19112b 100%);
  border: 2.5px solid var(--gold);
  border-radius: 14px;
  padding: 1rem 0.6rem;
  color: var(--gold-light);
  font-size: 1.9rem;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: inherit;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.choice-spell-btn span.spell-incantation {
  font-size: 0.72rem;
  font-family: 'Cinzel', serif;
  color: var(--text-muted);
  font-weight: 700;
}

.choice-spell-btn:hover {
  transform: translateY(-3px) scale(1.02);
  background: linear-gradient(180deg, #3f2b68 0%, #24173e 100%);
  border-color: #fff3c4;
  box-shadow: 0 10px 20px rgba(108, 52, 131, 0.45);
}

.choice-spell-btn.correct-flash {
  background: linear-gradient(180deg, #2ecc71, #1b7943) !important;
  border-color: #fff !important;
  color: #fff !important;
  transform: scale(1.05);
}

.choice-spell-btn.wrong-flash {
  background: linear-gradient(180deg, #e74c3c, #962d22) !important;
  border-color: #ffd2cc !important;
  color: #fff !important;
  animation: shakeWrong 0.4s ease;
}

@keyframes shakeWrong {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* Teclado Numérico Mágico */
.keypad-container {
  max-width: 460px;
  margin: 0 auto;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
}

@media (max-width: 560px) {
  .keypad-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.key-btn {
  background: #2b1d47;
  border: 2px solid var(--gold);
  color: var(--gold-light);
  border-radius: 10px;
  padding: 0.7rem 0.3rem;
  font-size: 1.4rem;
  font-weight: 900;
  cursor: pointer;
  font-family: inherit;
  transition: 0.15s;
}

.key-btn:hover {
  background: #3d2865;
  transform: translateY(-2px);
}

.key-btn.key-cast {
  grid-column: span 2;
  background: linear-gradient(135deg, #1b6344, #2ecc71);
  color: #fff;
  border-color: #fff;
  font-size: 1.15rem;
}

.key-btn.key-clear {
  background: #78281f;
  color: #ffd2cc;
}

/* Modal de Victoria / Bestiario */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 5, 14, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.25s ease;
}

.modal-box {
  background: linear-gradient(180deg, #1f1735 0%, #120d21 100%);
  border: 3px solid var(--gold);
  border-radius: 22px;
  padding: 1.75rem;
  max-width: 680px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(212, 175, 55, 0.3);
}

.victory-monster-badge {
  width: 130px;
  height: 130px;
  margin: 0.75rem auto;
  border-radius: 20px;
  border: 3px solid var(--gold-light);
  overflow: hidden;
  box-shadow: 0 0 25px rgba(212, 175, 55, 0.5);
}

.victory-monster-badge img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bestiary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
  text-align: left;
}

.bestiary-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1.5px solid rgba(212, 175, 55, 0.4);
  border-radius: 14px;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.bestiary-item.locked {
  opacity: 0.55;
  filter: grayscale(0.75);
}

.bestiary-thumb {
  width: 100%;
  height: 130px;
  border-radius: 10px;
  object-fit: cover;
  background: #120d20;
  border: 1px solid rgba(212, 175, 55, 0.35);
}

/* ==========================================
   MODO RED Y MULTIJUGADOR EN TIEMPO REAL
   ========================================== */
.network-banner-box {
  background: linear-gradient(135deg, rgba(28, 63, 124, 0.45), rgba(108, 52, 131, 0.45));
  border: 2px solid rgba(118, 181, 255, 0.55);
  border-radius: var(--radius-md);
  padding: 0.95rem 1.1rem;
  margin-bottom: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.network-actions-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.room-code-input {
  width: 115px;
  background: rgba(11, 9, 20, 0.85);
  border: 2px solid #76b5ff;
  color: #fff;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 1.05rem;
  text-transform: uppercase;
  text-align: center;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  letter-spacing: 0.12em;
  outline: none;
}

.btn-net-action {
  background: linear-gradient(135deg, #1b3b73, #2980b9);
  border: 1.5px solid #a8d0ff;
  color: #fff;
  padding: 0.52rem 0.95rem;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.86rem;
  cursor: pointer;
  font-family: inherit;
  transition: 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-net-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 14px rgba(118, 181, 255, 0.5);
}

.btn-net-action.gold {
  background: linear-gradient(135deg, #b5851b, #d4af37);
  border-color: #fff3c4;
  color: #1a1103;
}

/* Barra de Jugadores Conectados en la Sala durante el Duelo */
.party-raid-bar {
  background: rgba(15, 23, 46, 0.88);
  border: 1.5px solid rgba(118, 181, 255, 0.55);
  border-radius: 14px;
  padding: 0.65rem 1rem;
  margin-bottom: 0.9rem;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.party-raid-bar.active {
  display: flex;
}

.party-room-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  color: #a8d0ff;
  font-size: 0.92rem;
}

.party-code-pill {
  background: #ffd700;
  color: #161004;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  padding: 0.2rem 0.65rem;
  border-radius: 8px;
  letter-spacing: 0.1em;
  font-size: 1rem;
}

.party-players-list {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.party-player-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 999px;
  padding: 0.2rem 0.65rem 0.2rem 0.25rem;
  font-size: 0.8rem;
  font-weight: 800;
}

.party-mini-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #1b132e;
  overflow: hidden;
  border: 1px solid var(--gold);
  flex-shrink: 0;
}

.url-copy-box {
  background: rgba(0, 0, 0, 0.45);
  border: 1px dashed rgba(212, 175, 55, 0.6);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  margin: 0.5rem 0;
  font-family: monospace;
  font-size: 1rem;
  color: var(--gold-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  word-break: break-all;
}

