/* ==========================================================================
   VTT D&D 5e - MASTER STYLESHEET
   Paleta de Colores:
   - Fondo Principal: #0a0a1a
   - Paneles: #1a1a2e
   - Elementos/Tarjetas: #16213e
   - Acento Dorado: #c9a84c
   - Dorado Claro: #f0d060
   - Peligro/Daño: #e74c3c
   - Curación/Éxito: #2ecc71
   ========================================================================== */

:root {
  --bg-main: #0a0a1a;
  --bg-panel: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f172a;
  --gold-primary: #c9a84c;
  --gold-light: #f0d060;
  --gold-dark: #8c7128;
  --red-damage: #e74c3c;
  --green-heal: #2ecc71;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --border-subtle: rgba(201, 168, 76, 0.25);
  --border-gold: rgba(201, 168, 76, 0.6);
  --shadow-gold: 0 0 15px rgba(201, 168, 76, 0.2);
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.5);
  --nav-height-pc: 56px;
  --nav-height-mobile: 48px;
  --font-title: 'Cinzel', serif;
  --font-body: 'Roboto', sans-serif;
}

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

body {
  font-family: var(--font-body);
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  display: flex;
  flex-direction: column;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 0.95rem;
}

input:focus, select:focus, textarea:focus, button:focus {
  outline: none;
}

.gold-text {
  color: var(--gold-light);
  text-shadow: 0 0 8px rgba(240, 208, 96, 0.3);
}

.red-text {
  color: var(--red-damage);
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none !important;
}

/* BARRA SUPERIOR FIJA */
.top-navbar {
  height: var(--nav-height-pc);
  background: linear-gradient(180deg, #16213e 0%, #1a1a2e 100%);
  border-bottom: 2px solid var(--gold-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
  flex-shrink: 0;
}

.nav-left, .nav-center, .nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-title {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 1px;
  color: #ffffff;
}

.btn-nav {
  background: rgba(201, 168, 76, 0.1);
  border: 1px solid var(--border-subtle);
  color: var(--gold-light);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-nav:hover {
  background: var(--gold-primary);
  color: #000;
  box-shadow: var(--shadow-gold);
}

.code-badge {
  background: var(--bg-input);
  border: 1px dashed var(--gold-primary);
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--gold-light);
  font-family: monospace;
  cursor: pointer;
}

.role-badge {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-main);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.role-badge.dm {
  border-color: var(--gold-light);
  background: rgba(201, 168, 76, 0.2);
  color: var(--gold-light);
  font-weight: bold;
}

.scene-badge {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.save-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.save-status.saving {
  color: var(--gold-light);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

/* PANTALLAS PRINCIPALES */
.screen-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  width: 100%;
}

/* PANTALLA DE INICIO */
#screen-start {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 40px 20px;
  overflow-y: auto;
  background: radial-gradient(circle at center, #1a1a2e 0%, #0a0a1a 100%);
}

.hero-header {
  text-align: center;
  margin-bottom: 30px;
}

.hero-header h1 {
  font-family: var(--font-title);
  font-size: 2.8rem;
  margin-bottom: 10px;
  letter-spacing: 2px;
}

.hero-header .subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
}

.start-actions {
  display: flex;
  gap: 16px;
  margin-bottom: 40px;
  flex-wrap: wrap;
  justify-content: center;
}

.saved-games-section {
  width: 100%;
  max-width: 900px;
}

.saved-games-section h2 {
  font-family: var(--font-title);
  font-size: 1.5rem;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.game-card:hover {
  transform: translateY(-3px);
  border-color: var(--gold-primary);
  box-shadow: var(--shadow-gold);
}

.game-card .card-title {
  font-family: var(--font-title);
  font-size: 1.2rem;
  color: var(--gold-light);
}

.game-card .card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.game-card .card-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* PANTALLA PRINCIPAL VTT: ESTRUCTURA DE 3 COLUMNAS */

/* PANEL IZQUIERDO: HERRAMIENTAS DM */
.dm-tools-panel {
  width: 72px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 6px;
  gap: 12px;
  z-index: 100;
  flex-shrink: 0;
}

.dm-tools-panel .panel-header {
  font-size: 0.7rem;
  text-align: center;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--text-muted);
}

.tools-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.tool-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: 8px;
  width: 56px;
  height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-size: 0.7rem;
  transition: all 0.2s ease;
}

.tool-btn i {
  font-size: 1.2rem;
}

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

.tool-btn.active {
  background: var(--gold-primary);
  color: #000;
  border-color: var(--gold-light);
  box-shadow: var(--shadow-gold);
  font-weight: bold;
}

.tool-options {
  background: var(--bg-card);
  border: 1px solid var(--gold-primary);
  border-radius: 8px;
  padding: 10px;
  position: absolute;
  left: 80px;
  top: 60px;
  z-index: 200;
  box-shadow: var(--shadow-card);
  min-width: 200px;
}

.tool-sub-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-sub-options label {
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ÁREA CENTRAL: CANVAS */
.canvas-wrapper {
  flex: 1;
  position: relative;
  background-color: #05050f;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vtt-canvas-container {
  width: 100%;
  height: 100%;
  position: relative;
  touch-action: none;
}

#vtt-canvas {
  display: block;
  cursor: default;
}

/* Controles de Zoom Flotantes */
.canvas-controls {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(26, 26, 46, 0.85);
  border: 1px solid var(--border-subtle);
  padding: 6px 12px;
  border-radius: 30px;
  backdrop-filter: blur(8px);
  z-index: 90;
}

.btn-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--gold-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-circle:hover {
  background: var(--gold-primary);
  color: #000;
}

.zoom-level {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 45px;
  text-align: center;
}

/* Tooltip de Medición */
.measure-tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.85);
  color: var(--gold-light);
  border: 1px solid var(--gold-primary);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: bold;
  pointer-events: none;
  z-index: 150;
  box-shadow: var(--shadow-gold);
}

/* PANEL DERECHO: PESTAÑAS MULTIFUNCIÓN */
.right-panel {
  width: 360px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
}

.tabs-nav {
  display: flex;
  background: #121224;
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 12px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  min-width: 64px;
  transition: all 0.2s ease;
  border-bottom: 2px solid transparent;
}

.tab-btn i {
  font-size: 1.1rem;
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  color: var(--gold-light);
  border-bottom-color: var(--gold-light);
  background: rgba(201, 168, 76, 0.08);
  font-weight: bold;
}

.tab-content-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-pane {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.tab-pane.active {
  opacity: 1;
  pointer-events: auto;
}

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

.pane-header h3 {
  font-family: var(--font-title);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-box {
  margin-bottom: 12px;
}

.search-box input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 6px;
}

/* LISTA DE FICHAS */
.fichas-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ficha-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ficha-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ficha-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold-primary);
}

.ficha-info {
  flex: 1;
}

.ficha-name {
  font-weight: bold;
  font-size: 1rem;
  color: var(--gold-light);
}

.ficha-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hp-bar-outer {
  width: 100%;
  height: 10px;
  background: rgba(0,0,0,0.5);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
  margin-top: 4px;
}

.hp-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, #e74c3c 0%, #2ecc71 100%);
  width: 100%;
  transition: width 0.3s ease;
}

.ficha-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-start;
  margin-top: 8px;
  width: 100%;
}

.ficha-actions .btn {
  font-size: 0.78rem;
  padding: 5px 9px;
  height: 28px;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
  border-radius: 4px;
}

/* LANZADOR DE DADOS */
.dice-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: bold;
  letter-spacing: 0.5px;
}

.formula-input-group {
  display: flex;
  gap: 8px;
}

.formula-input-group input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-gold);
  color: #fff;
  padding: 10px 12px;
  border-radius: 6px;
  font-family: monospace;
  font-size: 1rem;
}

.quick-dice-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.btn-quick-die {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--gold-light);
  padding: 10px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.2s ease;
  min-height: 48px;
}

.btn-quick-die:hover {
  background: var(--gold-primary);
  color: #000;
}

.classification-grid, .d20-mode-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-classif, .btn-mode {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  flex: 1;
  min-width: 90px;
  text-align: center;
}

.btn-classif.active, .btn-mode.active {
  background: var(--gold-primary);
  color: #000;
  border-color: var(--gold-light);
  font-weight: bold;
}

#dice-token-select {
  width: 100%;
  background-color: var(--bg-input, #131722);
  border: 1px solid var(--border-subtle, rgba(201, 168, 76, 0.35));
  color: #f8fafc;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  margin-top: 4px;
  margin-bottom: 12px;
  cursor: pointer;
  display: block;
}

#dice-token-select:focus {
  outline: none;
  border-color: var(--gold-primary);
  box-shadow: 0 0 0 2px rgba(201, 168, 76, 0.3);
}

#dice-token-select option, .form-select option, select option {
  background-color: #1e1b2e !important;
  color: #f1f5f9 !important;
  padding: 6px 10px;
}

.chat-token-badge {
  color: #38bdf8;
  font-weight: 600;
  margin-left: 2px;
}

.quick-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  background: var(--bg-input);
  padding: 8px;
  border-radius: 6px;
  max-height: 120px;
  overflow-y: auto;
}

/* CHAT */
.chat-messages-container {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg .sender {
  font-weight: bold;
  font-size: 0.8rem;
}

.chat-msg.dm-msg {
  background: rgba(201, 168, 76, 0.1);
  border-left: 3px solid var(--gold-primary);
  padding: 6px 10px;
  border-radius: 4px;
}

.chat-gif-img {
  max-width: 240px;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 4px;
  border: 1px solid var(--border-subtle);
}

.chat-input-bar {
  display: flex;
  gap: 8px;
}

.chat-input-bar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: #fff;
  padding: 10px 12px;
  border-radius: 6px;
  min-height: 48px;
}

/* HISTORIAL COMPLETO DE DADOS */
.table-responsive {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history-table th, .history-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.history-table th {
  color: var(--gold-light);
  font-family: var(--font-title);
}

.pagination-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  font-size: 0.85rem;
}

/* PANEL DM */
.dm-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dm-section h4 {
  font-family: var(--font-title);
  color: var(--gold-light);
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 4px;
}

.grid-config-form label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.grid-config-form input {
  width: 70px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
}

.scenes-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.scene-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-input);
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  font-size: 0.85rem;
}

.scene-item.active {
  border-color: var(--gold-primary);
  background: rgba(201, 168, 76, 0.15);
  font-weight: bold;
}

/* ==========================================================================
   GALERÍA DE PLANTILLAS DEL DM (SIDEBAR Y MODAL BESTIARIO)
   ========================================================================== */
.dm-gallery-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-gallery-launcher {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 8px;
  background: linear-gradient(135deg, #c9a84c 0%, #a8822d 100%);
  color: #0b0c10;
  border: 1px solid #e6c86e;
  box-shadow: 0 4px 15px rgba(201, 168, 76, 0.25);
  transition: all 0.2s ease;
  cursor: pointer;
  width: 100%;
}

.btn-gallery-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(201, 168, 76, 0.4);
  background: linear-gradient(135deg, #d4b359 0%, #b89136 100%);
}

.btn-gallery-launcher .badge-count {
  background: #0b0c10;
  color: #f59e0b;
  border: 1px solid #c9a84c;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
}

.dm-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.dm-section-header h4 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-count {
  background: rgba(201, 168, 76, 0.2);
  color: var(--gold-light);
  border: 1px solid rgba(201, 168, 76, 0.4);
  font-size: 0.72rem;
  padding: 1px 7px;
  border-radius: 12px;
  font-weight: 600;
}

.gallery-save-box {
  display: flex;
  gap: 6px;
  align-items: center;
  width: 100%;
}

.gallery-save-box select {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
  padding: 6px 8px;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid rgba(201, 168, 76, 0.3);
  border-radius: 6px;
  height: 36px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-save-box .btn {
  flex-shrink: 0;
  white-space: nowrap;
  height: 36px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.gallery-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.gallery-search-wrap,
.catalog-search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.gallery-search-wrap .search-icon,
.catalog-search-box .search-icon {
  position: absolute;
  left: 10px;
  color: var(--gold-primary);
  font-size: 0.85rem;
  pointer-events: none;
}

.gallery-search-wrap input,
.catalog-search-box input {
  width: 100%;
  padding-left: 32px;
  padding-right: 28px;
  background: var(--bg-input);
  border: 1px solid rgba(201, 168, 76, 0.3);
  color: var(--text-main);
  border-radius: 6px;
  font-size: 0.82rem;
  height: 36px;
}

.btn-clear-search {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px;
  font-size: 0.8rem;
}

.btn-clear-search:hover {
  color: #f87171;
}

.gallery-filter-chips,
.catalog-filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.filter-chip,
.catalog-filter-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.filter-chip:hover,
.catalog-filter-btn:hover {
  background: rgba(201, 168, 76, 0.15);
  color: var(--gold-light);
  border-color: rgba(201, 168, 76, 0.4);
}

.filter-chip.active,
.catalog-filter-btn.active {
  background: var(--gold-primary);
  color: #0f172a;
  border-color: var(--gold-light);
  font-weight: bold;
}

/* Contenedor de Tarjetas en Sidebar */
.gallery-cards-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

/* Tarjeta de Plantilla individual */
.template-card {
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.75), rgba(15, 23, 42, 0.9));
  border: 1px solid rgba(201, 168, 76, 0.25);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.template-card:hover {
  border-color: var(--gold-primary);
  box-shadow: 0 6px 18px rgba(201, 168, 76, 0.15);
  transform: translateY(-1px);
}

.template-card-header {
  display: flex;
  gap: 10px;
  align-items: center;
}

.template-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.template-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold-primary);
  background: #0f172a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.template-main-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.template-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.template-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-tag {
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-tag.tag-monster {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-tag.tag-npc {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.badge-tag.tag-player {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.template-stat-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.stat-pill {
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}

.stat-pill.hp { color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.3); }
.stat-pill.ac { color: #38bdf8; border: 1px solid rgba(56, 189, 248, 0.3); }
.stat-pill.spd { color: #a855f7; border: 1px solid rgba(168, 85, 247, 0.3); }

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

.template-card-actions .btn-spawn-template {
  flex: 1;
  font-size: 0.8rem;
  padding: 6px 12px;
  height: 36px;
  min-height: 36px;
  font-weight: 600;
}

.template-card-actions .btn-inspect-template,
.template-card-actions .btn-del-template {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.gallery-empty-state {
  text-align: center;
  padding: 24px 12px;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.gallery-empty-state i {
  font-size: 2.2rem;
  color: rgba(201, 168, 76, 0.4);
}

.gallery-empty-state p {
  font-size: 0.85rem;
  margin: 0;
}

/* ==========================================================================
   MODAL DE CATÁLOGO / BESTIARIO EXPANDIDO (#modal-dm-gallery)
   ========================================================================== */
.modal-gallery-catalog {
  max-width: 1040px;
  width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.header-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title-wrap h3 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-gallery-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  padding: 16px 20px;
}

.catalog-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  background: rgba(15, 23, 42, 0.7);
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid rgba(201, 168, 76, 0.2);
}

.catalog-search-box {
  flex: 1;
  min-width: 220px;
}

.catalog-spawn-multiplier {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--gold-light);
  flex-wrap: wrap;
}

.quantity-input-wrapper {
  display: inline-flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(201, 168, 76, 0.45);
  border-radius: 6px;
  overflow: hidden;
  height: 34px;
}

.btn-qty-step {
  background: rgba(30, 41, 59, 0.9);
  color: #cbd5e1;
  border: none;
  width: 32px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.85rem;
}

.btn-qty-step:hover {
  background: #c9a84c;
  color: #0b0c10;
}

.input-spawn-qty {
  width: 52px !important;
  height: 34px !important;
  text-align: center;
  font-size: 1rem !important;
  font-weight: 700;
  color: #f1c40f !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  margin: 0 !important;
  -moz-appearance: textfield;
}

.input-spawn-qty::-webkit-outer-spin-button,
.input-spawn-qty::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.quick-qty-chips {
  display: flex;
  gap: 4px;
  align-items: center;
}

.btn-quick-qty {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: #94a3b8;
  padding: 5px 9px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-quick-qty:hover {
  border-color: #c9a84c;
  color: #cbd5e1;
}

.btn-quick-qty.active {
  background: rgba(201, 168, 76, 0.25);
  border-color: #c9a84c;
  color: #f1c40f;
  font-weight: 700;
}

.gallery-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
  overflow-y: auto;
  padding-right: 6px;
  max-height: calc(75vh - 120px);
}

.gallery-modal-grid .template-card {
  padding: 14px;
}

.modal-gallery-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.catalog-hint {
  font-size: 0.8rem;
  color: #94a3b8;
}

/* ==========================================================================
   MODAL INSPECTOR DE PLANTILLA (#modal-template-detail)
   ========================================================================== */
.modal-template-inspector {
  max-width: 520px;
  width: 92vw;
}

.template-detail-hero {
  display: flex;
  gap: 16px;
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid rgba(201, 168, 76, 0.2);
}

.template-detail-img {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--gold-primary);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
}

.template-detail-meta h4 {
  margin: 0 0 6px 0;
  font-size: 1.25rem;
  color: #f8fafc;
}

.template-badges-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.template-vital-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.8rem;
}

.vital-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.vital-item.hp strong { color: #ef4444; }
.vital-item.ac strong { color: #38bdf8; }
.vital-item.speed strong { color: #a855f7; }
.vital-item.ini strong { color: var(--gold-light); }

.ability-scores-summary {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 14px 0;
}

.ability-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(201, 168, 76, 0.3);
  border-radius: 6px;
  padding: 6px 2px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ability-box .ab-name {
  font-size: 0.68rem;
  color: #94a3b8;
  font-weight: 600;
}

.ability-box strong {
  font-size: 1rem;
  color: #f8fafc;
}

.ability-box .ab-mod {
  font-size: 0.75rem;
  color: var(--gold-light);
  font-weight: 700;
}

.template-notes-section label {
  font-size: 0.82rem;
  color: var(--gold-primary);
  font-weight: 600;
  display: block;
  margin-bottom: 6px;
}

.template-notes-box {
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(201, 168, 76, 0.3);
  border-radius: 6px;
  padding: 14px;
  font-size: 0.88rem;
  color: #e2e8f0;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.55;
}

/* ÁREA DE TEXTO: NOTAS / RASGOS / HECHIZOS (SIN LÍMITE DE ESPACIO) */
#ficha-notas {
  width: 100%;
  min-height: 190px;
  max-height: 520px;
  resize: vertical;
  background: rgba(13, 13, 30, 0.75);
  border: 1px solid rgba(201, 168, 76, 0.35);
  border-radius: 6px;
  color: #e2e8f0;
  font-family: 'Roboto', sans-serif;
  font-size: 0.9rem;
  line-height: 1.55;
  padding: 12px 14px;
  overflow-y: auto;
  box-sizing: border-box;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#ficha-notas:focus {
  border-color: var(--gold-primary);
  box-shadow: 0 0 10px rgba(201, 168, 76, 0.35);
  outline: none;
}

/* BARRITA DESLIZADORA (SCROLLBAR) TEMÁTICA D&D ELEGANTE */
.custom-scrollbar::-webkit-scrollbar,
#ficha-notas::-webkit-scrollbar,
#enlarged-img-notas::-webkit-scrollbar,
.template-notes-box::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track,
#ficha-notas::-webkit-scrollbar-track,
#enlarged-img-notas::-webkit-scrollbar-track,
.template-notes-box::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.45);
  border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb,
#ficha-notas::-webkit-scrollbar-thumb,
#enlarged-img-notas::-webkit-scrollbar-thumb,
.template-notes-box::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--gold-primary), #8a6d2b);
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.3);
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover,
#ficha-notas::-webkit-scrollbar-thumb:hover,
#enlarged-img-notas::-webkit-scrollbar-thumb:hover,
.template-notes-box::-webkit-scrollbar-thumb:hover {
  background: var(--gold-light);
}

.custom-scrollbar,
#ficha-notas,
#enlarged-img-notas,
.template-notes-box {
  scrollbar-width: thin;
  scrollbar-color: var(--gold-primary) rgba(0, 0, 0, 0.45);
}

/* BOTONES Y BOTONERÍA GENERICA */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  min-height: 44px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
  min-height: 32px;
}

.btn-large {
  padding: 14px 28px;
  font-size: 1.1rem;
  border-radius: 8px;
  min-height: 52px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: #2563eb;
  color: #fff;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-secondary {
  background: #475569;
  color: #fff;
}

.btn-secondary:hover {
  background: #334155;
}

.btn-gold {
  background: linear-gradient(135deg, #c9a84c 0%, #f0d060 100%);
  color: #000;
  font-weight: bold;
}

.btn-gold:hover {
  filter: brightness(1.1);
  box-shadow: var(--shadow-gold);
}

.btn-danger {
  background: var(--red-damage);
  color: #fff;
}

.btn-danger:hover {
  background: #c0392b;
}

.btn-success {
  background: var(--green-heal);
  color: #fff;
}

.btn-success:hover {
  background: #27ae60;
}

/* MODALES */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--gold-primary);
  border-radius: 12px;
  box-shadow: var(--shadow-card), var(--shadow-gold);
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-sm { max-width: 400px; }
.modal-md { max-width: 600px; }
.modal-lg { max-width: 800px; }

.modal-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
}

.modal-header h3 {
  font-family: var(--font-title);
  color: var(--gold-light);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.modal-close:hover { color: #fff; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  padding: 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-card);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.join-games-list-box {
  max-height: 160px;
  overflow-y: auto;
  background: var(--bg-card, #1a1a2e);
  border: 1px solid var(--border-subtle, rgba(201, 168, 76, 0.25));
  border-radius: 6px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 4px;
}

.join-session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-input, #131722);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.join-session-item:hover {
  background: rgba(201, 168, 76, 0.15);
  border-color: var(--gold-primary);
  transform: translateY(-1px);
}

.join-session-item.selected {
  background: rgba(201, 168, 76, 0.25);
  border-color: var(--gold-primary);
  box-shadow: 0 0 8px rgba(201, 168, 76, 0.35);
}

.join-session-title {
  font-size: 0.88rem;
  font-weight: bold;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

.join-session-code {
  background: rgba(201, 168, 76, 0.2);
  color: var(--gold-light);
  font-weight: bold;
  font-size: 0.8rem;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 1.5px;
  border: 1px solid rgba(201, 168, 76, 0.3);
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.form-control, .form-select {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: #fff;
  padding: 10px;
  border-radius: 6px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.stat-box {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 6px;
  text-align: center;
}

.stat-box label {
  font-size: 0.7rem;
  font-weight: bold;
  color: var(--gold-light);
  display: block;
}

.stat-box input {
  width: 100%;
  text-align: center;
  background: transparent;
  border: none;
  color: #fff;
  font-weight: bold;
  font-size: 1.1rem;
}

.stat-mod-badge {
  display: block;
  margin-top: 3px;
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--gold-light);
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(201, 168, 76, 0.3);
  border-radius: 4px;
  padding: 1px 2px;
  letter-spacing: 0.5px;
  transition: all 0.2s ease;
  user-select: none;
}

.avatar-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold-primary);
  margin: 0 auto;
}

/* GIF GRID */
.gif-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
}

.gif-item {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s ease;
}

.gif-item:hover {
  border-color: var(--gold-primary);
  transform: scale(1.04);
}

/* CAPA OSCURA PARA MÓVILES (OVERLAY) */
.mobile-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 400; /* Por debajo de los paneles (500 y 900) pero encima del canvas */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.mobile-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ADAPTACIÓN MÓVIL (MOBILE-FIRST RESPONSIVE) */
@media (max-width: 900px) {
  .top-navbar {
    height: auto;
    padding: 8px 12px;
    flex-wrap: wrap;
  }

  .nav-center {
    order: 3;
    width: 100%;
    justify-content: space-between;
    margin-top: 6px;
  }

  .mobile-only {
    display: inline-flex !important;
  }
  
  .mobile-only.hidden {
    display: none !important;
  }

  /* --- PANEL IZQUIERDO DM (MÓVIL) --- */
  .dm-tools-panel {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    max-width: 80vw;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 15px rgba(0,0,0,0.8);
    background: var(--bg-panel);
    z-index: 500;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding-bottom: 24px;
  }

  .dm-tools-panel.open {
    transform: translateX(0);
  }

  .tools-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .tool-btn {
    width: 100%;
    height: 60px;
  }

  .tool-options {
    position: static;
    width: 100%;
    margin-top: 12px;
  }

  /* --- PANEL DERECHO PESTAÑAS (MÓVIL) --- */
  .right-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    max-width: 90vw;
    height: 100%;
    border-left: 2px solid var(--gold-primary);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 900;
    display: flex;
    flex-direction: column;
  }

  .right-panel.open {
    transform: translateX(0);
  }

  /* Tab bar: fixed height, no shrink */
  .right-panel .tabs-nav {
    flex-shrink: 0;
  }

  /* Content area fills remaining space */
  .right-panel .tab-content-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0; /* key for flex children with overflow */
  }

  /* Each pane fills the container and scrolls vertically */
  .right-panel .tab-pane {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
  }

  .canvas-wrapper {
    flex: 1;
    height: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Horizontal scroll for dice options on mobile */
  .quick-dice-grid,
  .classification-grid,
  .d20-mode-grid {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    padding-bottom: 8px; /* space for scrollbar */
    gap: 8px;
  }
  
  .quick-dice-grid::-webkit-scrollbar,
  .classification-grid::-webkit-scrollbar,
  .d20-mode-grid::-webkit-scrollbar {
    height: 4px;
  }
  
  .quick-dice-grid::-webkit-scrollbar-thumb,
  .classification-grid::-webkit-scrollbar-thumb,
  .d20-mode-grid::-webkit-scrollbar-thumb {
    background: var(--border-gold);
    border-radius: 4px;
  }

  .btn-quick-die,
  .btn-classif,
  .btn-mode {
    flex: 0 0 auto !important; /* don't shrink, stay their natural width */
    min-width: 70px;
  }

  /* Allow text selection & scrolling inside panels on mobile */
  .right-panel *,
  .dm-tools-panel * {
    touch-action: auto;
  }

  /* Keep canvas touch-action blocked (for panning/drawing) */
  .vtt-canvas-container {
    touch-action: none;
  }
}

/* Post-Roll Target Selector */
.post-roll-target-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  text-align: left;
}

.post-roll-target-btn:hover {
  border-color: var(--gold-primary);
  background: rgba(201, 168, 76, 0.1);
  box-shadow: var(--shadow-gold);
  transform: translateY(-1px);
}

.post-roll-target-name {
  font-weight: 600;
  font-size: 0.95em;
}

.post-roll-target-hp {
  font-size: 0.8em;
  color: var(--text-muted);
  white-space: nowrap;
}

.post-roll-hp-bar {
  width: 60px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}

.post-roll-hp-fill {
  height: 100%;
  background: var(--green-heal);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* FICHA OCULTA (DM) */
.ficha-card.ficha-oculta {
  opacity: 0.7;
  border: 1px dashed #777;
  background: rgba(20, 20, 20, 0.6);
}

/* MULTI-SELECT BADGE & BUTTON */
#btn-multi-select-mode.active {
  background: var(--gold-primary);
  color: #000;
  box-shadow: 0 0 12px rgba(201, 168, 76, 0.8);
  border-color: #fff;
}

.multi-select-badge {
  background: var(--gold-primary);
  color: #000;
  font-weight: bold;
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}

/* ==========================================================================
   BANNER DE RECONEXIÓN Y RESILIENCIA ANTE CAÍDAS
   ========================================================================== */
.reconnect-banner {
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  background: linear-gradient(90deg, #b91c1c, #9a3412);
  color: #ffffff;
  padding: 8px 16px;
  z-index: 9999;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
  border-bottom: 1px solid rgba(254, 202, 202, 0.3);
  animation: slideDown 0.3s ease-out;
}

.reconnect-banner.hidden {
  display: none !important;
}

.reconnect-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
  font-weight: 500;
}

.reconnect-icon {
  font-size: 1.1rem;
  color: #fef08a;
  animation: pulse 1.5s infinite;
}

#reconnect-msg {
  flex: 1;
}

/* ==========================================================================
   GESTOR DE BACKUPS Y SNAPSHOTS (PANEL DM)
   ========================================================================== */
.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.8rem;
  transition: background 0.2s;
}

.backup-item:hover {
  background: rgba(201, 168, 76, 0.1);
}

.backup-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-right: 8px;
}

.backup-name {
  font-weight: bold;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.backup-date {
  font-size: 0.7rem;
  color: #94a3b8;
}

.btn-restore-snapshot {
  padding: 3px 7px !important;
  font-size: 0.72rem !important;
  white-space: nowrap;
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: rgba(18, 18, 32, 0.95);
  color: #f8fafc;
  border: 1px solid rgba(201, 168, 76, 0.5);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 250px;
  max-width: 380px;
  animation: toastSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.3s, transform 0.3s;
}

.toast.success {
  border-color: #22c55e;
}

.toast.warning {
  border-color: #f59e0b;
}

.toast.error {
  border-color: #ef4444;
}

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

@keyframes slideDown {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.1); }
}

/* ==========================================================================
   ADAPTACIÓN MÓVIL PARA LA GALERÍA DE PLANTILLAS Y MODALES
   ========================================================================== */
@media (max-width: 900px) {
  #btn-quick-gallery {
    display: inline-flex !important;
  }

  .modal-gallery-catalog {
    width: 96vw !important;
    max-width: 96vw !important;
    height: 94vh !important;
    max-height: 94vh !important;
    margin: 0 auto;
  }

  .modal-gallery-body {
    padding: 10px !important;
    gap: 10px !important;
  }

  .catalog-toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 8px !important;
  }

  .catalog-search-box {
    width: 100% !important;
    min-width: 0 !important;
  }

  .catalog-filters {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    padding-bottom: 4px !important;
    -webkit-overflow-scrolling: touch;
  }

  .catalog-filter-btn {
    flex-shrink: 0 !important;
    padding: 6px 12px !important;
    font-size: 0.8rem !important;
  }

  .catalog-spawn-multiplier {
    justify-content: space-between !important;
    width: 100% !important;
  }

  .gallery-modal-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    max-height: calc(82vh - 180px) !important;
  }

  .template-card {
    padding: 12px !important;
  }

  .template-card-actions .btn-spawn-template {
    height: 44px !important;
    min-height: 44px !important;
    font-size: 0.9rem !important;
  }

  .template-card-actions .btn-inspect-template,
  .template-card-actions .btn-del-template {
    width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    font-size: 1rem !important;
  }

  .modal-template-inspector {
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: 92vh !important;
  }

  .template-detail-hero {
    flex-direction: column !important;
    text-align: center !important;
  }

  .template-vital-stats {
    justify-content: center !important;
  }

  .template-badges-row {
    justify-content: center !important;
  }

  .ability-scores-summary {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
  }
}

/* OVERLAY DE CARGA INMEDIATA AL ENTRAR A SESIÓN */
.vtt-loading-overlay {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(17, 24, 39, 0.94) 0%, rgba(10, 10, 26, 0.98) 100%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 100;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: all;
}

.vtt-loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.vtt-loading-spinner {
  width: 52px;
  height: 52px;
  border: 4px solid rgba(201, 168, 76, 0.2);
  border-top-color: #c9a84c;
  border-right-color: #f1c40f;
  border-radius: 50%;
  animation: vttSpin 0.75s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
}

@keyframes vttSpin {
  to {
    transform: rotate(360deg);
  }
}

.vtt-loading-text {
  font-family: var(--font-title, 'Cinzel', serif);
  font-size: 1.3rem;
  font-weight: 700;
  color: #c9a84c;
  letter-spacing: 1.5px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}

.vtt-loading-subtext {
  font-size: 0.88rem;
  color: #94a3b8;
  letter-spacing: 0.5px;
}

/* ==========================================================================
   COMBAT TRACKER & INICIATIVA (D&D 5e)
   ========================================================================== */

.icon-swords {
  display: inline-block;
  vertical-align: middle;
  color: var(--gold-light);
  filter: drop-shadow(0 0 4px rgba(240, 208, 96, 0.45));
  transition: transform 0.2s ease, filter 0.2s ease;
}

button:hover .icon-swords {
  transform: scale(1.15) rotate(4deg);
  filter: drop-shadow(0 0 8px rgba(240, 208, 96, 0.8));
}

.combat-tracker-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  width: max-content;
  min-width: 320px;
  max-width: min(880px, 92vw);
  background: rgba(16, 22, 44, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-gold);
  border-radius: 12px;
  padding: 8px 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 15px rgba(201, 168, 76, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: all;
  transition: all 0.3s ease;
  animation: slideDownFade 0.3s ease-out;
}

@keyframes slideDownFade {
  from {
    opacity: 0;
    transform: translate(-50%, -15px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.combat-tracker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.combat-round-badge {
  background: rgba(201, 168, 76, 0.15);
  border: 1px solid var(--gold-primary);
  padding: 3px 10px;
  border-radius: 20px;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--gold-light);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.combat-turn-info {
  font-size: 0.88rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.combat-turn-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.combat-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.btn-circle-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--gold-light);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.btn-circle-sm:hover {
  background: var(--gold-primary);
  color: #000;
  border-color: var(--gold-light);
  box-shadow: 0 0 10px rgba(240, 208, 96, 0.3);
}

.btn-danger-sm:hover {
  background: var(--red-damage) !important;
  color: #fff !important;
  border-color: #ff7675 !important;
  box-shadow: 0 0 10px rgba(231, 76, 60, 0.4) !important;
}

#btn-player-end-turn {
  animation: turnButtonGlow 1.5s infinite alternate;
  font-weight: bold;
}

@keyframes turnButtonGlow {
  0% {
    box-shadow: 0 0 5px rgba(201, 168, 76, 0.4);
  }
  100% {
    box-shadow: 0 0 18px rgba(240, 208, 96, 0.85);
  }
}

.combat-track-list {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 6px 2px;
  scroll-behavior: smooth;
}

.combat-track-list::-webkit-scrollbar {
  height: 4px;
}
.combat-track-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
}
.combat-track-list::-webkit-scrollbar-thumb {
  background: rgba(201, 168, 76, 0.4);
  border-radius: 4px;
}
.combat-track-list::-webkit-scrollbar-thumb:hover {
  background: var(--gold-primary);
}

.combat-participant-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 5px;
  background: rgba(26, 33, 62, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.22s ease;
  user-select: none;
}

.combat-participant-card:hover {
  background: rgba(35, 45, 85, 0.8);
  border-color: rgba(201, 168, 76, 0.4);
}

.combat-participant-card.active {
  background: linear-gradient(135deg, rgba(201, 168, 76, 0.28) 0%, rgba(26, 33, 62, 0.95) 100%);
  border-color: var(--gold-light);
  box-shadow: 0 0 14px rgba(240, 208, 96, 0.45);
  transform: scale(1.05);
}

.combat-card-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-subtle);
  background: #0d0d22;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.85rem;
  color: var(--gold-light);
  flex-shrink: 0;
}

.combat-participant-card.active .combat-card-avatar {
  border-color: var(--gold-light);
  box-shadow: 0 0 8px rgba(240, 208, 96, 0.6);
}

.combat-card-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.combat-card-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  max-width: 90px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.combat-participant-card.active .combat-card-name {
  color: var(--gold-light);
}

.combat-card-ini {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: monospace;
}

.combat-card-dead {
  opacity: 0.45;
  filter: grayscale(80%);
}

/* MODAL PREPARACIÓN COMBATE */
.modal-combat-setup {
  max-width: 650px;
  width: 95%;
}

.combat-setup-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.combat-setup-table-wrap {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.5);
}

.combat-setup-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.combat-setup-table th {
  background: var(--bg-card);
  padding: 10px 12px;
  color: var(--gold-light);
  font-family: var(--font-title);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 2;
}

.combat-setup-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  vertical-align: middle;
}

.combat-setup-table tr:hover td {
  background: rgba(201, 168, 76, 0.06);
}

.combat-setup-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border-subtle);
  background: #0d0d22;
  display: block;
  margin: 0 auto;
}

.combat-setup-ini-input {
  width: 65px;
  padding: 4px 8px;
  text-align: center;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--gold-light);
  font-weight: bold;
  margin: 0 auto;
  display: block;
}

.combat-setup-ini-input:focus {
  border-color: var(--gold-primary);
  box-shadow: 0 0 6px rgba(201, 168, 76, 0.4);
}

/* RESPONSIVE COMBAT TRACKER (MÓVIL) */
@media (max-width: 768px) {
  .combat-tracker-bar {
    top: 6px;
    min-width: unset;
    width: 96vw;
    padding: 6px 8px;
    gap: 6px;
  }

  .combat-round-badge {
    font-size: 0.8rem;
    padding: 2px 8px;
  }

  .combat-turn-info {
    font-size: 0.8rem;
    max-width: 140px;
  }

  .btn-circle-sm {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
  }

  #btn-player-end-turn {
    font-size: 0.75rem;
    padding: 4px 8px;
  }

  .combat-card-avatar {
    width: 26px;
    height: 26px;
  }

  .combat-card-name {
    max-width: 65px;
    font-size: 0.75rem;
  }
}

