:root {
  --bg-app: #121212;
  --bg-panel: #1e1e1e;
  --text-main: #e0e0e0;
  --text-muted: #a0a0a0;
  --accent: #d4af37;
  --border: #333;
  --font-main: "Segoe UI", system-ui, sans-serif;
  --font-header: "Georgia", serif;
  --color-danger: #e62e2e; /* Rojo D&D */
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
}

/* =========================================
   BOTÓN DE DONACIONES (KO-FI)
   ========================================= */
#kofi-button {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(30, 30, 30, 0.8);
    backdrop-filter: blur(4px);
    border: 1px solid var(--accent);
    padding: 8px 15px;
    border-radius: 50px;
    text-decoration: none;
    color: var(--accent);
    font-weight: bold;
    font-size: 0.85rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    transition: transform 0.2s, background 0.2s;
}

#kofi-button:hover {
    background: rgba(42, 42, 42, 0.9);
    transform: scale(1.05);
}

.kofi-icon {
    font-size: 1.2rem;
    display: inline-block;
    animation: kofi-bob 2s ease-in-out infinite;
}

@keyframes kofi-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* Ocultar en móviles muy pequeños si estorba */
@media (max-width: 480px) {
    #kofi-button .kofi-text { display: none; }
    #kofi-button { padding: 8px; }
}

#app {
  display: flex; /* Cambiamos Grid por Flex para mejor control de rebote */
  width: 100vw;
  height: 100vh;
  overflow: hidden; /* Cortafuegos global */
}

#sheet-preview {
  flex: 1; /* Ocupa todo el espacio sobrante */
  background-color: #2c2c2c;
  overflow-y: auto;
  display: flex;
  flex-direction: column; /* Poner páginas una debajo de otra */
  align-items: center; /* Centrar horizontalmente */
  padding: 2rem;
  min-width: 0; /* CRÍTICO: Permite que flex encoja este panel si es necesario */
}

/* =========================================
   PANEL DERECHO: CONSTRUCTOR (WIZARD)
   ========================================= */

/* RESET DE ESTRUCTURA DEL PANEL DERECHO */
#builder-controls {
  display: flex;
  flex-direction: column;
  width: 400px; /* Ancho Base */
  max-width: 100vw; /* Tope absoluto en móviles */
  height: 100vh;
  background: #1e1e1e;
  border-left: 1px solid #333;
  overflow: hidden; /* El padre NUNCA tiene scroll */
  flex-shrink: 0; /* No encogerse */
}

/* Encabezado fijo */
#builder-controls header {
  padding: 10px;
  border-bottom: 1px solid #333;
}

/* Área de contenido desplazable */
#builder-content {
  flex: 1; /* Ocupar altura restante */
  width: 100%; /* Ancho exacto del padre */
  overflow-y: auto; /* Scroll vertical permitido */
  overflow-x: hidden; /* Scroll horizontal PROHIBIDO */
  position: relative;
  padding: 0; /* Padding lo manejan los hijos */
}

/* Corrección especial para la Grid de Navegación */
#builder-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  width: 100%;
  margin-bottom: 0.5rem;
}

#builder-nav button {
  width: 100%;
  min-width: 0; /* Permite al botón encogerse si el texto es largo */
  font-size: 0.8rem;
  padding: 8px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 4px;
  background-color: #2a2a2a;
  border: 1px solid #444;
  cursor: pointer;
  color: var(--text-muted);
  font-family: var(--font-main);
  transition: all 0.2s ease;
}

#builder-nav button:hover {
  background-color: #333;
  color: var(--text-main);
}

#builder-nav button.active {
  background-color: var(--color-danger);
  color: white;
  border-color: var(--color-danger);
  font-weight: bold;
}

/* Pestañas */
.builder-tab {
  padding: 15px;
  width: 100%;
  display: none;
  box-sizing: border-box;
}
.builder-tab.active {
  display: block;
}

/* --- REGLA CORTAFUEGOS --- */
/* Esto obliga a Inputs, Tablas, Grids y Textos a rendirse ante el ancho del padre */
.builder-tab * {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* Inputs y Elementos de Formulario - Preservando estilos generales */
.builder-tab input,
.builder-tab select,
.builder-tab textarea,
.builder-tab button {
  width: 100%;
  margin-bottom: 10px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-header);
  color: var(--accent);
  margin-bottom: 0.5rem;
}

/* Header Layout */
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.header-top h1 {
  font-size: 1.2rem; /* Mucho más pequeño */
  margin: 0;
  color: var(--accent);
}

/* Language Selector */
.lang-selector select {
  background-color: var(--bg-panel);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-family: var(--font-main);
  cursor: pointer;
  outline: none;
}

.lang-selector select:focus {
  border-color: var(--accent);
}

/* Selector Layout (Master-Detail) */
.selector-layout {
  display: flex;
  flex-direction: column; /* Cambiar de row a column */
  gap: 15px;
  width: 100%;
}

.option-list,
.option-details {
  width: 100% !important; /* Forzar que cada parte ocupe todo el ancho */
  max-width: 100%;
}

/* Option List (Left Column) */
.option-list {
  max-height: 200px; /* Limitar altura para que no empuje todo muy abajo */
  overflow-y: auto;
  border: 1px solid var(--border);
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.option-btn {
  background-color: var(--bg-panel);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  font-family: var(--font-main);
  transition: all 0.2s ease;
}

.option-btn:hover {
  background-color: #333;
  border-color: var(--text-muted);
}

.option-btn.selected {
  background-color: var(--color-danger);
  color: white;
  border-color: var(--color-danger);
  font-weight: bold;
}

/* Option Details (Right Column) */
.option-details {
  background-color: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.25rem;
  animation: fadeIn 0.3s ease;
}

.option-details h3 {
  margin-top: 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.option-details ul {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.option-details li {
  margin-bottom: 0.5rem;
}

.placeholder-text {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  margin-top: 2rem;
}

.actions {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  text-align: right;
}

.btn-select {
  background-color: var(--accent);
  color: #121212;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
  font-family: var(--font-main);
  transition: background 0.2s;
}

.btn-select:hover {
  background-color: #f0c040;
}

.btn-select.confirmed {
  background-color: #28a745;
  color: white;
  cursor: default;
}

/* Responsive */
@media (max-width: 768px) {
  .selector-layout {
    grid-template-columns: 1fr;
  }

  .option-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 4px;
  }
}

/* --- UI Limpia: Etiquetas de Rasgos --- */
.traits-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 1rem;
}

.trait-badge {
  background-color: #333;
  color: var(--text-main);
  border: 1px solid var(--accent);
  padding: 4px 10px;
  border-radius: 12px; /* Forma de píldora */
  font-size: 0.85rem;
  cursor: help; /* Indica que hay info extra */
  transition: background 0.2s;
}

.trait-badge:hover {
  background-color: var(--accent);
  color: #121212;
}

/* Ocultar descripción larga en el selector para limpieza */
.desc-text.hidden-in-selector {
  display: none;
}

/* --- Stats Selector (Fixed & Compact) --- */

/* Botones de la lista lateral */
.option-list button {
  background-color: #2a2a2a;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  transition: all 0.2s ease;
}

.option-list button:hover {
  background-color: #333;
  color: var(--text-main);
  border-left-color: var(--accent);
}

.option-list button.selected {
  background-color: #28a745; /* VERDE */
  color: white;
  border-color: #28a745;
  font-weight: bold;
  border-left: 3px solid #1e7e34;
}

/* Stats Table Layout */
.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 5px;
  overflow-x: hidden;
  max-width: 600px;
  margin: 0 auto;
}

.stat-row {
  display: grid !important;
  /* Nombre | Control | Total | Mod */
  grid-template-columns: 80px 1fr 50px 50px !important;
  align-items: center;
  gap: 10px !important;
  padding: 8px 10px !important;
  background-color: #252525;
  border-radius: 6px;
  border: 1px solid #333;
}

.stat-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-control {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 100%;
}

/* Point Buy Buttons */
.stat-control button {
  width: 28px !important;
  height: 28px !important;
  font-size: 1rem !important;
  padding: 0;
  border-radius: 4px;
  border: 1px solid #444;
  background: #333;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-control button:hover:not(:disabled) {
  background: var(--accent);
  color: #121212;
  border-color: var(--accent);
}

.stat-control button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: #444;
  color: #666;
}

.stat-control span {
  font-size: 1.1rem !important;
  width: 25px !important;
  text-align: center;
  font-weight: bold;
}

/* Inputs & Selects */
.stat-input-manual {
  width: 100% !important;
  max-width: 80px !important;
  height: 32px;
  font-size: 1.1rem;
  text-align: center;
  margin: 0 auto;
  display: block;
  background-color: #333;
  color: white;
  border: 1px solid #555;
  border-radius: 4px;
}

.stat-select-standard {
  width: 100% !important;
  height: 32px;
  font-size: 0.95rem;
  background-color: #333;
  color: white;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 0 5px;
}

/* Calculation Column (Total + Bonus) */
.stat-calculation {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.stat-total {
  font-size: 1.3rem !important;
  font-weight: bold;
  color: white;
}

.stat-bonus {
  font-size: 0.75rem !important;
  color: #4ff;
  margin-bottom: 2px;
}

/* Modifier Circle */
.stat-mod {
  display: flex;
  justify-content: flex-end;
}

.stat-mod div {
  width: 40px !important;
  height: 40px !important;
  font-size: 1.1rem !important;
  border: 2px solid var(--accent) !important;
  border-radius: 50%;
  background: #2a2a2a;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  font-weight: bold;
  color: var(--accent);
}

/* Other components */
.points-display {
  background-color: var(--bg-panel);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 1rem;
  text-align: center;
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
  border-radius: 4px;
}

.points-display.error {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.mode-selector {
  margin-bottom: 1.5rem;
  text-align: center;
}

.mode-selector select {
  padding: 0.5rem 1rem;
  font-size: 1rem;
  background-color: var(--bg-panel);
  color: var(--text-main);
  border: 1px solid var(--accent);
  border-radius: 4px;
  cursor: pointer;
}

/* --- Shop UI --- */
.shop-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.shop-tab {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-family: var(--font-main);
  font-weight: bold;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.shop-tab:hover {
  color: var(--text-main);
}

.shop-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.shop-search {
  margin-bottom: 1rem;
}

.shop-search input {
  width: 100%;
  padding: 0.75rem;
  background-color: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-main);
  font-family: var(--font-main);
}

.shop-search input:focus {
  border-color: var(--accent);
  outline: none;
}

.item-stats p {
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

/* Shop Redesign */
.shop-content {
  margin-top: 1rem;
}

.shop-section {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background-color: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.shop-section h4 {
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--accent);
}

.shop-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.shop-select {
  width: 100%;
  padding: 0.75rem;
  background-color: #333;
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
}

.shop-select:focus {
  border-color: var(--accent);
  outline: none;
}

.shield-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.item-preview {
  background-color: #252525;
  padding: 1rem;
  border-radius: 4px;
  border: 1px solid #444;
}

/* Wallet */
.wallet-section {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #333;
  padding: 5px 10px;
  border-radius: 4px;
  border: 1px solid #555;
}

.wallet-section label {
  color: var(--accent);
  font-weight: bold;
}

.wallet-section input {
  background: transparent;
  border: none;
  color: white;
  width: 60px;
  text-align: right;
  font-family: var(--font-main);
  font-size: 1rem;
}

.wallet-section input:focus {
  outline: none;
  border-bottom: 1px solid var(--accent);
}

/* Shield Checkbox */
.shield-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: bold;
  color: var(--text-main);
  user-select: none;
}

.shield-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* --- Spells UI (Compact) --- */
.spell-row {
  display: grid;
  grid-template-columns: 40px 1fr 100px 80px 40px; /* Nivel, Nombre, Escuela, Tiempo, Btn */
  align-items: center;
  background: #252525;
  border-bottom: 1px solid #333;
  padding: 8px;
  cursor: pointer;
  transition: background 0.2s;
  gap: 10px;
}
.spell-row:hover {
  background: #333;
}
.spell-row.known {
  border-left: 3px solid var(--accent);
  background: #2f2f2f;
}

.spell-details-panel {
  background: #1a1a1a;
  padding: 15px;
  border-bottom: 1px solid #444;
  display: none; /* Oculto por defecto */
  font-size: 0.9rem;
  color: #ccc;
}
.spell-details-panel.open {
  display: block;
}

.btn-spell-add {
  background: transparent;
  border: 1px solid #555;
  color: #aaa;
  width: 30px;
  height: 30px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-spell-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-spell-add.added {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: white;
}

/* Checkbox Toggle Estilizado */
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.9rem;
}
.toggle-switch input {
  accent-color: var(--accent);
  cursor: pointer;
  width: 16px;
  height: 16px;
}

.btn-icon-add {
  width: 32px !important;
  height: 32px !important;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: bold;
  font-size: 1.2rem;
  background-color: var(--accent);
  color: #121212;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  margin-bottom: 0 !important;
}
.btn-icon-add:hover {
  background-color: #fff;
}
.btn-icon-add:disabled {
  background-color: #555;
  color: #888;
  cursor: not-allowed;
}

/* --- Grimorio Optimizado --- */
.spell-page-columns {
  column-count: 2;
  column-gap: 15px;
  width: 100%;
}
.spell-card-compact {
  break-inside: avoid; /* Evita que se parta a la mitad entre columnas */
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px;
  margin-bottom: 8px;
  background: transparent;
  font-size: 0.8rem;
  color: #444;
}
.spell-meta-compact {
  font-size: 0.7rem;
  color: #666;
  border-bottom: 1px solid #eee;
  margin-bottom: 4px;
  padding-bottom: 2px;
}

/* --- Diseño Página 2 (Grid) --- */
.page-2-grid {
  display: grid;
  grid-template-columns: 1fr 2fr; /* Columna izq estrecha, der ancha */
  gap: 15px;
  align-items: start;
}

@media (max-width: 700px) {
  .page-2-grid {
    grid-template-columns: 1fr;
  } /* Móvil: una columna */
}

.p2-sec.stat-box {
  border: 1px solid #000;
  border-radius: 4px;
  text-align: center;
  padding: 5px;
  background: transparent;
}

.p2-section-box {
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 8px;
  background: transparent;
  margin-bottom: 10px;
  font-size: 0.85rem;
}

.p2-title {
  margin: 0 0 5px 0;
  font-size: 0.8rem;
  font-weight: bold;
  text-transform: uppercase;
  border-bottom: 2px solid var(--accent);
  color: #444;
}

/* Etiqueta para ataques automáticos */
.auto-hit-tag {
  display: inline-block;
  background: #eee;
  color: #444;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 0 4px;
  font-size: 0.75rem;
  font-weight: bold;
}

/* Reseteo agresivo para evitar scroll horizontal */
img,
table,
input,
select,
textarea {
  max-width: 100% !important;
}

#builder-content,
.builder-tab,
.bio-container,
.selector-layout {
  overflow-x: hidden !important;
  max-width: 100vw;
}

/* Forzar que todos los contenedores flexibles internos bajen a la siguiente línea */
.feature-section,
.control-group,
.spell-ui-layout {
  flex-wrap: wrap;
}

/* --- Math Tooltip (Inspector de Números) --- */
[data-math-tooltip] {
    position: relative;
    cursor: help;
}

[data-math-tooltip]:hover::after {
    content: attr(data-math-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #222;
    color: #fff;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    margin-bottom: 8px;
    border: 1px solid #444;
}

[data-math-tooltip]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #222 transparent transparent transparent;
    margin-bottom: -2px;
    z-index: 1000;
}

/* --- Optimización Hoja 1 --- */
.vitals-grid-compact {
  display: grid;
  grid-template-columns: 1fr 1fr; /* 2 Columnas para Salvaciones y Skills */
  gap: 10px;
  margin-bottom: 10px;
}
.skills-list-compact {
  column-count: 2; /* Divide la lista larga de 18 skills en 2 columnas */
  column-gap: 20px;
  font-size: 0.8rem;
}
/* Estilo para los círculos de slots */
.slot-circle {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1px solid #333;
  border-radius: 50%;
  margin-right: 2px;
  background: #fff; /* Blanco para que se pueda pintar */
}

.spell-slots-wrapper {
  display: flex;
  flex-wrap: wrap; /* Clave: Permite que los niveles bajen si no caben */
  gap: 15px;
  align-items: center;
}
.spell-level-group {
  display: flex;
  align-items: center;
  border: 1px solid #ccc;
  padding: 2px 6px;
  border-radius: 10px;
  background: transparent;
}

/* =========================================
   SHEET RENDERER STYLES
   ========================================= */

.sheet-page {
  width: 210mm;
  min-height: 297mm;
  background-color: white;
  padding: 10mm;
  margin-bottom: 30px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  color: #000;
  font-family: var(--font-main);
  position: relative;
  overflow: hidden;
}

/* Marca de Agua Aesthetic - Versión Robusta (Encima de todo pero tenue) */
.sheet-page::before {
  content: "";
  display: block !important;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 170mm; /* Tamaño fijo para que no escale con el alto de la hoja */
  height: 170mm;
  transform: translate(-50%, -50%);
  background-image: url('../marca de agua2.png');
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0.06; /* Muy tenue para no molestar la lectura */
  z-index: 99; /* Por encima de los bloques pero por debajo de la interacción */
  pointer-events: none;
}

/* Asegurar transparencia de los bloques de contenido */
.sheet-header, .sheet-body, .page-2-grid-asym, .combat-box, .hp-box, .stat-block, .p2-section-box {
  position: relative;
  z-index: 1;
}

@media print {
  .sheet-page {
    margin: 0 !important;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .sheet-page::before {
      opacity: 0.08 !important; /* Ajuste para papel */
  }
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  border-bottom: 2px solid #333;
  padding-bottom: 10px;
  margin-bottom: 20px;
}

.header-info {
  width: 70%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.char-name-box h1 {
  font-size: 2.5rem;
  margin: 0;
  line-height: 1.2;
  text-transform: uppercase;
  font-family: var(--font-header);
  color: black; /* Override generic h1 color */
}

.char-name-box label {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: #666;
}

.subclass-badges-container {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
}

.subclass-badge {
  background: #333;
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid var(--accent);
}

.meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.meta-field {
  background: transparent;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.meta-field label {
  display: block;
  font-size: 0.6rem;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 2px;
}

.meta-field span {
  display: block;
  font-weight: bold;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-field span span {
  display: inline;
}

.header-avatar {
  width: 180px;
  height: 180px;
  border: 2px solid #000;
  overflow: hidden;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.char-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.char-avatar-placeholder {
  color: #666;
  text-align: center;
  font-size: 0.8rem;
  padding: 10px;
}

/* Stats Layout */
.main-columns {
  display: flex;
  gap: 20px;
}

.stats-column {
  width: 35%; /* Ancho aumentado para acomodar 2 columnas */
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr; /* Dos columnas */
  gap: 8px;
}

.main-content-column {
  width: 63%; /* Reducido para evitar traslape (35+63+gap = 100%) */
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.stat-block {
  border: 1px solid #000;
  border-radius: 8px;
  padding: 4px; /* Un poco más compacto */
  text-align: center;
  background: transparent;
  position: relative;
  box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
  font-size: 0.8rem;
}

.stat-header {
  font-weight: bold;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 1px;
  margin-bottom: 5px;
}

.stat-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px solid black;
  border-radius: 8px;
  width: 70px;
  margin: 0 auto 5px;
  padding: 5px;
  background: white;
}

.stat-mod {
  font-size: 1.4rem; /* Ajustado */
  font-weight: bold;
  line-height: 1;
  color: black;
  border: none !important;
  background: transparent !important;
  width: auto !important;
  height: auto !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.stat-score {
  font-size: 0.9rem;
  border-top: 1px solid #ccc;
  width: 100%;
  margin-top: 2px;
  padding-top: 2px;
}

.stat-save {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  border-bottom: 1px solid #ddd;
  padding-bottom: 4px;
  margin-bottom: 4px;
}

.skill-list {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
}

.skill-item {
  display: flex;
  font-size: 0.8rem;
  margin-bottom: 2px;
}

.skill-mod {
  width: 25px;
  text-align: center;
  border-bottom: 1px solid #ccc;
  margin-right: 5px;
}

.skill-name {
  color: #444;
}

.skill-name.proficient {
  font-weight: bold;
  color: black;
}
.skill-name.proficient::before {
  content: "● ";
  font-size: 0.6rem;
  vertical-align: middle;
}

/* Bloque de Combate */
.combat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
.combat-box {
  border: 2px solid #333;
  border-radius: 5px;
  padding: 2px 5px;
  text-align: center;
  background: transparent;
}
.combat-val {
  font-size: 1.3rem;
  font-weight: bold;
  line-height: 1;
}
.combat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 1px;
}

.hope-circle {
  width: 10px;
  height: 10px;
  border: 1px solid #000;
  border-radius: 50%;
  background: transparent;
}

.hp-box {
  border: 2px solid #333;
  border-radius: 5px;
  padding: 2px 5px;
  margin-bottom: 10px;
  text-align: center;
  background: transparent;
}

/* Tabla de Ataques */
.attacks-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 15px;
}
.attacks-table th {
  background: #eee;
  text-align: left;
  padding: 4px;
  font-size: 0.8rem;
  border-bottom: 1px solid #000;
}
.attacks-table td {
  border-bottom: 1px solid #ccc;
  padding: 2px 4px;
  font-size: 0.9rem;
}

/* Lista de Rasgos */
.features-list {
  font-size: 0.8rem;
  line-height: 1.2;
}
.feature-item {
  margin-bottom: 3px;
  padding-bottom: 3px;
  border-bottom: 1px dotted #ccc;
}
.feature-item strong {
  font-size: 0.75rem;
}

/* --- FIX: Grid y Alineación de Selectores --- */

/* Contenedor de la cuadrícula */
.skill-grid,
.tool-selector-group {
  display: grid;
  /* Reducimos el mínimo a 110px para garantizar 2 columnas incluso en paneles estrechos */
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px 8px; /* Espaciado: 6px vertical, 8px horizontal */
  width: 100%;
  box-sizing: border-box;
  margin-top: 5px;
}

/* Elemento individual (Label) */
.skill-option {
  display: flex !important;
  align-items: center !important; /* Centrado vertical para checkboxes y texto */
  width: 100%;
  font-size: 0.8rem;
  line-height: 1.2;
  color: #ccc;
  cursor: pointer;
  padding: 4px 0;
  white-space: nowrap !important; /* Evita que el texto de la habilidad se parta en este grid */
}

/* El Checkbox propiamente dicho */
.skill-option input[type="checkbox"] {
  flex: 0 0 auto !important;
  width: 16px !important;
  height: 16px !important;
  margin: 0 8px 0 0 !important;
  cursor: pointer;
}

/* Estilo para skills ya conocidas (deshabilitadas) */
.skill-option[style*="font-style:italic"] {
  opacity: 0.7;
}
/* --- Tooltips de Maestrías --- */
.tooltip-container {
  position: relative;
  border-bottom: 1px dotted #666;
  cursor: help;
}
.tooltip-text {
  visibility: hidden;
  width: 220px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 4px;
  padding: 8px;
  position: absolute;
  z-index: 100;
  bottom: 125%;
  left: 50%;
  margin-left: -110px;
  font-size: 0.75rem;
  font-weight: normal;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}
.tooltip-container:hover .tooltip-text {
  visibility: visible;
}

/* --- Recursos de Clase --- */
.resource-box {
  border: 2px solid #333;
  border-radius: 5px;
  padding: 5px;
  margin-top: 10px;
  background: transparent;
  text-align: center;
}
.resource-val {
  font-size: 1.2rem;
  font-weight: bold;
  display: block;
}
.resource-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #666;
}

/* --- Spellcasting Module --- */
.spell-stats-row {
  display: flex;
  justify-content: space-around;
  margin-bottom: 10px;
  border-bottom: 1px solid #ccc;
  padding-bottom: 5px;
}
.spell-stat-box {
  text-align: center;
}
.spell-stat-val {
  font-size: 1.2rem;
  font-weight: bold;
  display: block;
}
.spell-stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: #666;
}

.spell-level-row {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
  font-size: 0.85rem;
}
.spell-level-label {
  width: 80px;
  font-weight: bold;
  font-size: 0.75rem;
}
.spell-slots-container {
  display: flex;
  gap: 4px;
}
.spell-slot-check {
  width: 12px;
  height: 12px;
  border: 1px solid #333;
  border-radius: 50%;
  display: inline-block;
} /* Círculos vacíos para imprimir */

/* --- FIX: Layout Hoja 1 (Evita traslape) --- */
.sheet-body-compact {
  display: grid;
  grid-template-columns: 1fr 1fr; /* Divide Salvaciones y Habilidades en paralelo */
  gap: 15px;
  margin-bottom: 10px;
  align-items: start;
}
.skills-list-compact {
  column-count: 2; /* Habilidades en 2 columnas internas */
  column-gap: 20px;
  font-size: 0.75rem; /* Texto un poco más pequeño para que quepa todo */
}

/* --- Recursos Visuales (Círculos) --- */
.resource-circles-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3px;
  margin: 4px 0;
}
.res-circle {
  width: 11px;
  height: 11px;
  border: 1px solid #333;
  border-radius: 50%;
}
.res-help {
  font-size: 0.6rem;
  color: #666;
  font-style: italic;
  line-height: 1.1;
}

/* Layout Hoja 1: Sidebar */
.sheet-main-grid {
  display: grid;
  grid-template-columns: 180px 1fr; /* Sidebar fijo 180px */
  gap: 15px;
  align-items: start;
}

/* Hoja 3: Monster Card */
.monster-card {
  border-top: 5px solid #d4af37; /* Borde dorado */
  border-bottom: 2px solid #d4af37;
  background-color: #fdf5e6; /* Color pergamino */
  padding: 8px; /* Reducido de 15px */
  margin-bottom: 0; /* Controlado por grid gap */
  font-family: "Georgia", serif;
  color: #333;
  font-size: 0.85rem; /* Fuente ligeramente más compacta */
  height: 100%; /* Igualar alturas en fila */
}
.monster-header-grid {
  display: grid;
  grid-template-columns: 1fr 120px; /* Columna Izq flexible, Derecha fija para imagen */
  gap: 15px;
  align-items: start;
  border-bottom: 2px solid #8b0000;
  margin-bottom: 10px;
  padding-bottom: 10px;
}
.monster-img-large {
  width: 100%;
  height: 120px;
  background-size: cover;
  background-position: center;
  border: 1px solid #333;
  cursor: pointer;
  background-color: #eee;
}
.monster-stats-grid {
  display: flex;
  justify-content: space-between; /* Space between para aprovechar ancho reducido */
  border-top: 1px solid #d4af37;
  border-bottom: 1px solid #d4af37;
  padding: 3px 0;
  margin: 5px 0;
  font-weight: bold;
  color: #8b0000;
  font-size: 0.75rem; /* Texto más pequeño */
  gap: 2px;
}

/* Atributos Compactos */
.stats-horizontal-container {
  display: flex;
  justify-content: space-between;
  gap: 5px;
  padding: 5px 0;
  border-bottom: 2px solid #333;
  margin-bottom: 10px;
}
.stat-compact-box {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
}
.stat-compact-label {
  font-weight: bold;
  color: #666;
}
.stat-compact-mod {
  border: 2px solid var(--color-danger);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: var(--color-danger);
}

/* Imagen de Compañero */
.companion-img-upload {
  width: 60px;
  height: 60px;
  border: 1px dashed #ccc;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  display: inline-block;
}

/* --- Hoja de Personaje: Mejoras --- */
.spell-slots-flex {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
  border: 1px solid #ccc;
  padding: 4px;
  border-radius: 4px;
}
.page-2-grid-asym {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
  gap: 20px;
  align-items: start;
}

.p2-lore-box {
  font-style: italic;
  font-size: 0.8rem;
  word-break: break-word; /* Forzar rotura de palabras largas */
  overflow-wrap: break-word;
  white-space: pre-wrap; /* Mantener saltos de línea y envolver */
  max-width: 100%;
}
.equip-cols {
  column-count: 2;
  column-gap: 10px;
  font-size: 0.75rem;
}

/* Equipo en 1 sola columna limpia */
.equip-list-simple {
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Bestiary Redesign: Horizontal Mini-Sheets */
.bestiary-horizontal-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.monster-card.horizontal-layout {
    display: flex;
    gap: 20px;
    background-color: #fdf5e6;
    border: 1px solid #d4af37;
    border-left: 8px solid #8b0000;
    padding: 15px;
    min-height: 480px; /* Asegura que 2 quepan bien en A4 */
    page-break-inside: avoid;
    break-inside: avoid;
}

.card-left-col {
    flex: 1.2;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card-right-col {
    flex: 0.8;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card-header-top h2 {
    margin: 0;
    color: #8b0000;
    font-size: 1.6rem;
    border-bottom: 2px solid #8b0000;
}

.type-line {
    font-style: italic;
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 5px;
}

.stats-ribbon {
    display: flex;
    gap: 10px;
}

.stat-bubble {
    background: #8b0000;
    color: white;
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-bubble strong {
    font-size: 0.7rem;
    text-transform: uppercase;
    opacity: 0.9;
}

.attributes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    background: rgba(139,0,0,0.05);
    padding: 8px;
    border-radius: 4px;
}

.attr-box {
    text-align: center;
    border-bottom: 1px solid rgba(139,0,0,0.1);
}

.attr-box label {
    display: block;
    font-size: 0.65rem;
    font-weight: bold;
    color: #8b0000;
}

.traits-section {
    font-size: 0.85rem;
    line-height: 1.3;
    color: #333;
    flex-grow: 1;
}

.actions-section {
    font-size: 0.85rem;
    color: #333;
    border: 1px dashed #d4af37;
    padding: 10px;
    background: rgba(253, 245, 230, 0.5);
    height: 100%;
}

.section-title {
    font-weight: bold;
    text-transform: uppercase;
    color: #8b0000;
    font-size: 0.8rem;
    border-bottom: 1px solid #d4af37;
    margin-bottom: 5px;
}

.monster-img-large {
    width: 100%;
    height: 200px;
    background-size: cover;
    background-position: center;
    border: 2px solid #8b0000;
    border-radius: 4px;
    cursor: pointer;
    background-color: #eee;
}

/* Bestiario: Optimización Real */
.bestiary-header {
  display: grid;
  grid-template-columns: 1fr 150px; /* Columna der fija para imagen (NO REDUCIR) */
  gap: 10px;
  border-bottom: 2px solid #8b0000;
  margin-bottom: 5px;
  padding-bottom: 5px;
  min-height: 150px;
}

.bestiary-header h1 {
  font-size: 1.1rem !important; /* Reducir título para que quepa */
}

.monster-img-square {
  width: 150px;
  height: 150px; /* Cuadrado perfecto (NO REDUCIR) */
  object-fit: cover;
  border: 2px solid #333;
  background-color: #eee;
  cursor: pointer;
  display: block;
  background-size: cover;
  background-position: center;
}

/* Grid de Inicio */
.mode-grid-container { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 10px; }
.mode-card {
    background: #2a2a2a; border: 1px solid #444; padding: 15px; border-radius: 8px; cursor: pointer; text-align: center; transition: all 0.2s;
}
.mode-card:hover { background: #333; }
.mode-card.selected { border-color: var(--accent); background: #3a3a2a; box-shadow: 0 0 10px rgba(212,175,55,0.2); }
.mode-icon { font-size: 1.5rem; margin-bottom: 5px; }

/* Nuevo Selector Rectangular */
.mode-card-rect {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    color: #ccc;
    transition: all 0.2s;
}
.mode-card-rect:hover {
    background: #333;
    color: white;
}
.mode-card-rect.selected {
    background: #333;
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 5px rgba(212,175,55,0.3);
}
.mode-description-box {
    margin-top: 20px;
    padding: 15px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: #1e1e1e;
    color: #ccc;
    text-align: center;
    font-style: italic;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-confirm-mode {
    width: 100%;
    margin-top: 20px;
    padding: 12px;
    background: var(--accent);
    color: #121212;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    font-size: 1rem;
    text-transform: uppercase;
}
.btn-confirm-mode:hover {
    background: #f0c040;
}
.btn-confirm-mode:disabled {
    background: #444;
    color: #888;
    cursor: not-allowed;
}

/* Campos Editables en Hoja */
.manual-editable:hover,
[contenteditable="true"]:hover {
    background-color: rgba(212, 175, 55, 0.05);
    outline: 1px dashed var(--accent);
    cursor: text;
}
.manual-editable:focus,
[contenteditable="true"]:focus {
    background-color: #fff;
    color: #000;
    outline: 2px solid var(--accent);
}

.stat-reminder-badge {
    display: inline-block;
    background-color: rgba(212, 175, 55, 0.2); /* Dorado transparente */
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 0 4px;
    font-size: 0.75rem;
    margin-left: 8px;
    vertical-align: middle;
    cursor: help;
}

/* --- Nuevos Estilos para Edición Amigable --- */
.sheet-numeric-select {
    background: transparent;
    border: none;
    border-bottom: 1px dashed #ccc;
    font-family: inherit;
    font-size: inherit;
    font-weight: bold;
    color: inherit;
    cursor: pointer;
    padding: 0 2px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    text-align: center;
}

.sheet-numeric-select:hover {
    background: rgba(0, 0, 0, 0.05);
    border-bottom-color: var(--accent);
}

.sheet-numeric-select:focus {
    outline: none;
    background: #fff;
    color: #000;
    border-bottom: 2px solid var(--accent);
}


/* =========================================
   RESPONSIVE MOBILE VIEW (TOGGLE)
   ========================================= */

#view-toggle-btn {
    display: none; /* Oculto por defecto en escritorio */
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    padding: 15px 25px;
    background-color: var(--accent);
    color: #121212;
    border: none;
    border-radius: 50px;
    font-weight: bold;
    font-size: 1rem;
    font-family: var(--font-main);
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

#view-toggle-btn:hover {
    background-color: #f0c040;
    transform: scale(1.05);
}

#view-toggle-btn:active {
    transform: scale(0.95);
}

/* Asegurar explícitamente que en escritorio el botón esté oculto */
@media (min-width: 1025px) {
    #view-toggle-btn {
        display: none !important;
    }
}

/* Solo aplicar lógica de toggle en pantallas menores a 1024px (Tablets y Móviles) */
@media (max-width: 1024px) {
    #view-toggle-btn {
        display: flex !important;
    }

    /* MODO EDICIÓN (Por defecto o activo) */
    body.mobile-mode-edit #sheet-preview {
        display: none !important;
    }
    body.mobile-mode-edit #builder-controls {
        display: flex !important;
        width: 100% !important;
        max-width: 100% !important;
        border-left: none;
    }

    /* MODO VISUALIZACIÓN */
    body.mobile-mode-view #builder-controls {
        display: none !important;
    }
    body.mobile-mode-view #sheet-preview {
        display: block !important;
        width: 100% !important;
        padding: 20px 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        background-color: #2c2c2c;
        text-align: center;
    }
    
    /* Ajustar hoja para que se vea como impresión pero escalada */
    body.mobile-mode-view .sheet-page {
        width: 800px !important; /* Ancho fijo en px para consistencia */
        min-width: 800px !important;
        height: auto !important;
        min-height: 1123px !important; /* Alto A4 en px aprox */
        margin: 0 auto 0 auto !important; /* Margen controlado por JS */
        box-shadow: 0 4px 8px rgba(0,0,0,0.5) !important;
        transform-origin: top center;
        /* El escalado se manejará vía JS para compatibilidad total (iOS/Android) */
    }

    /* Prevenir zoom automático en inputs para iOS (tamaño fuente >= 16px) */
    input, select, textarea, .manual-editable {
        font-size: 16px !important;
    }
    input[type="checkbox"] {
        width: 18px !important;
        height: 18px !important;
        margin: 0 4px !important;
    }
}
