/* =====================================================================
   TABLA PERIÓDICA INTERACTIVA - v13
   Autor: Ricardo Cañabate García-Villalba
   ===================================================================== */

:root {
    /* Dimensiones de la tabla */
    --table-col: 60px;
    --table-row: 80px;
    --table-gap: 2px;
    --label-size: 22px;      /* Tamaño de la franja de etiquetas grupo/período */

    /* Banco de elementos */
    --bank-cols: 9;
    --bank-item-width: 58px;
    --bank-item-height: 64px;
    --bank-gap: 6px;
    --bank-padding: 10px;

    /* Paleta */
    --bg-dark: #0b1f3a;
    --panel-dark: #10294d;
    --panel-dark-2: #16345f;
    --text-light: #ffffff;
    --text-soft: #dbe7ff;
    --text-muted: rgba(255, 255, 255, 0.55);
    --border-dark: rgba(255, 255, 255, 0.18);
    --accent-win: #4ade80;
    --accent-hint: #fbbf24;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Space Grotesk', system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 12px;
    background-color: var(--bg-dark);
    color: var(--text-light);
}

h1, h2, p { text-align: center; }

/* ---------------------------------------------------------------------
   COLORES DE TEXTO GLOBALES
   --------------------------------------------------------------------- */
.periodic-table-container > h1,
.periodic-table-container > p,
#sidebar-right,
#sidebar-right h2,
#bank-filter,
#bank-filter label,
.leyenda-item,
.acciones button { color: var(--text-light); }

/* Título principal con identidad de marca (fuente Orbitron + degradado dorado-azul) */
#main-title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    letter-spacing: -0.5px;
    background: linear-gradient(110deg, #ffffff 0%, #fcd34d 55%, #93c5fd 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 36px rgba(251, 191, 36, 0.18);
}

.element,
.element .simbolo,
.element .nombre-elemento,
.element .atomic-weight,
.element .atomic-number,
.element .valencias,
.element.colocado,
.element.colocado .simbolo,
.element.colocado .nombre-elemento,
.element.colocado .atomic-weight,
.element.colocado .atomic-number,
.element.colocado .valencias { color: #000; }

#modal-content,
#modal-weight,
#modal-number,
#modal-symbol,
#modal-name,
#modal-valences,
#modal-content a,
#modal-content p,
#modal-close { color: #000 !important; }

#modal-content a {
    text-decoration: underline;
    font-weight: 600;
}

.autoria {
    font-size: .8em;
    text-align: right;
    color: #355075;
}

/* ---------------------------------------------------------------------
   LAYOUT PRINCIPAL
   --------------------------------------------------------------------- */
#juego-container {
    display: flex;
    width: 95%;
    max-width: 2200px;
    gap: 15px;
    align-items: flex-start;
}

.periodic-table-container {
    /* Ancho = tabla + franja de etiquetas de período */
    width: calc(var(--label-size) + 4px + (18 * var(--table-col)) + (17 * var(--table-gap)));
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ---------------------------------------------------------------------
   TABLA CON ETIQUETAS DE GRUPO Y PERÍODO
   Los números de grupo se pintan como ::before sobre el primer slot de
   cada columna (ver .slot.group-head más abajo). Así cada número queda
   pegado a la columna correspondiente, independientemente de dónde
   empiece la columna (período 1, 2 o 4).
   --------------------------------------------------------------------- */
.table-grid-wrapper {
    display: grid;
    grid-template-columns: var(--label-size) auto;
    gap: 4px;
    margin-bottom: 10px;
    /* Espacio arriba para las DOS etiquetas (IUPAC + CAS) que "sobresalen" */
    padding-top: calc(var(--label-size) * 2);
}

.period-labels {
    display: grid;
    grid-template-rows: repeat(7, var(--table-row));
    gap: var(--table-gap);
}

.period-labels span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-muted);
}

.periodic-table {
    display: grid;
    grid-template-columns: repeat(18, var(--table-col));
    grid-template-rows: repeat(7, var(--table-row));
    gap: var(--table-gap);
}

/* Números de grupo encima del primer slot de cada columna.
   ::before -> nomenclatura IUPAC (1-18)
   ::after  -> nomenclatura CAS  (IA, IIA, IIIB...)            */
.slot.group-head {
    position: relative;
}

.slot.group-head::before,
.slot.group-head::after {
    position: absolute;
    left: 0;
    right: 0;
    text-align: center;
    pointer-events: none;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.slot.group-head::before {
    content: attr(data-group);
    bottom: calc(100% + 22px);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.slot.group-head::after {
    content: attr(data-cas);
    bottom: calc(100% + 4px);
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.38);
    font-style: italic;
}

/* ---------------------------------------------------------------------
   LANTÁNIDOS Y ACTÍNIDOS (fila separada debajo)
   --------------------------------------------------------------------- */
.lanthanides-actinides-container {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: calc(var(--label-size) + 4px + (18 * var(--table-col)) + (17 * var(--table-gap)));
    margin-top: 15px;
}

.la-row-wrapper {
    display: grid;
    grid-template-columns: var(--label-size) auto;
    gap: 4px;
    align-items: center;
}

.la-period-label {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--table-row);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-muted);
}

.lanthanides-row,
.actinides-row {
    display: grid;
    grid-template-columns: repeat(15, var(--table-col));
    grid-template-rows: var(--table-row);
    gap: var(--table-gap);
    /* Desplazamiento para alinear con las columnas 3-17 de la tabla principal */
    margin-left: calc((3 * var(--table-col)) + (3 * var(--table-gap)));
}

/* ---------------------------------------------------------------------
   SLOTS
   --------------------------------------------------------------------- */
.slot {
    background-color: rgba(255, 255, 255, 0.08);
    border: 1px dashed rgba(255, 255, 255, 0.26);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2px;
    text-align: center;
    border-radius: 12px;
    width: 100%;
    height: 100%;
    transition: background-color 0.15s, border-color 0.15s;
}

.slot.drag-over {
    background-color: rgba(74, 222, 128, 0.2);
    border-color: var(--accent-win);
    border-style: solid;
}

.slot.drag-wrong {
    animation: shake 0.35s ease;
    background-color: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
}

/* ---------------------------------------------------------------------
   ELEMENTOS
   --------------------------------------------------------------------- */
.element {
    width: 58px;
    height: 64px;
    border: 1px solid #666;
    border-radius: 6px;
    padding: 4px 3px;
    cursor: grab;
    user-select: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2px;
    font-size: 10px;
    overflow: hidden;
}

.element .atomic-weight,
.element .atomic-number,
.element .valencias { display: none; }

.element .simbolo {
    font-size: 2em;
    font-weight: 700;
    line-height: 1;
    margin: 0;
}

.element .nombre-elemento {
    font-size: 0.84em;
    font-weight: 700;
    text-align: center;
    line-height: 1.05;
    display: block;
    white-space: normal;
    word-break: break-word;
    min-height: 22px;
}

.dragging {
    opacity: 0.5;
    transform: scale(1.05);
}

.element.colocado {
    width: 100%;
    height: 100%;
    padding: 6px 4px 4px;
    border: 1px solid rgba(0, 0, 0, 0.14);
    border-radius: 8px;
    cursor: pointer;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto auto;
    align-items: start;
    justify-items: center;
    font-size: 10px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
    transition: background-color 0.22s ease, color 0.22s ease,
                border-color 0.22s ease, transform 0.16s ease;
}

.element.colocado:hover {
    transform: translateY(-1px);
}

.element.colocado .simbolo {
    display: block;
    grid-column: 1 / 3;
    grid-row: 2;
    font-size: 2.05em;
    font-weight: 700;
    line-height: 1;
    margin: 2px 0;
}

.element.colocado .nombre-elemento {
    display: block;
    grid-column: 1 / 3;
    grid-row: 3;
    font-size: 1em;
    line-height: 1.05;
    text-align: center;
    margin: 0;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: auto;
}

.element.colocado .atomic-weight {
    display: block;
    grid-column: 1 / 2;
    grid-row: 1;
    justify-self: start;
    align-self: start;
    font-size: 1em;
    font-weight: 600;
    line-height: 1;
}

.element.colocado .atomic-number {
    display: block;
    grid-column: 2 / 3;
    grid-row: 1;
    justify-self: end;
    align-self: start;
    font-size: 1em;
    font-weight: 600;
    line-height: 1;
}

.element.colocado .valencias {
    display: block;
    grid-column: 1 / 3;
    grid-row: 4;
    font-size: 1em;
    line-height: 1.05;
    text-align: center;
    opacity: 0.85;
    margin-top: 2px;
}

/* Animación de flotación en el banco */
@keyframes flotarElemento {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

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

#element-bank .element {
    animation: flotarElemento 3s ease-in-out infinite;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.element.colocado {
    animation: none !important;
}

/* ---------------------------------------------------------------------
   COLORES DE FAMILIAS
   --------------------------------------------------------------------- */
.alcalinos          { background-color: #f0f8ff; }
.alcalinoterreos    { background-color: #e6e6fa; }
.transicion         { background-color: #ffffc2; }
.posttransicionales { background-color: #ecec88; }
.metaloides         { background-color: #9ff26d; }
.no-metales         { background-color: #afeeee; }
.gases-nobles       { background-color: #e0ffff; }
.lantanidos         { background-color: #ffe4c4; }
.actinidos          { background-color: #ffcda1; }

/* ---------------------------------------------------------------------
   SIDEBAR DERECHO
   --------------------------------------------------------------------- */
#sidebar-right {
    padding-left: 3vh;
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    /* Que el sidebar no sobrepase el alto del viewport - así el banco
       puede calcular su altura disponible y hacer scroll internamente */
    max-height: calc(100vh - 40px);
    position: sticky;
    top: 20px;
}

.acciones {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.acciones button {
    padding: 6px 12px;
    font-size: 0.9rem;
    line-height: 1.2;
    cursor: pointer;
    background-color: var(--panel-dark-2);
    color: var(--text-light);
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    transition: filter 0.15s, background-color 0.15s;
}

.acciones button:hover { filter: brightness(1.15); }

#btn-resolver {
    background-color: var(--accent-hint);
    color: #0b1f3a;
    font-weight: 600;
    border-color: transparent;
}

/* Botón de pista (NUEVO v14.1) */
#btn-pista {
    background-color: #7c3aed;
    color: #fff;
    font-weight: 600;
    border-color: transparent;
}
#btn-pista:hover { background-color: #8b5cf6; }
#btn-pista:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(0.5);
}

/* ---------------------------------------------------------------------
   SELECTOR DE DIFICULTAD (v14.1) - Versión compacta con <select>
   --------------------------------------------------------------------- */
#difficulty-panel {
    padding: 8px 10px;
    background: var(--panel-dark-2);
    border: 1px solid var(--border-dark);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.panel-label {
    font-size: 0.66rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}

#difficulty-select {
    width: 100%;
    padding: 6px 8px;
    font-size: 0.85rem;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-light);
    border: 1px solid var(--border-dark);
    border-radius: 5px;
    cursor: pointer;
    outline: none;
}
#difficulty-select:focus {
    border-color: var(--accent-win);
}
#difficulty-select option {
    background: var(--panel-dark);
    color: var(--text-light);
}

/* ---------------------------------------------------------------------
   SLOTS OCULTOS según dificultad (v14.1)
   --------------------------------------------------------------------- */
.slot.disabled-slot {
    opacity: 0.15;
    border-style: dotted;
    background: transparent;
    pointer-events: none;
}

.la-row-wrapper.hidden-row {
    display: none;
}

/* ---------------------------------------------------------------------
   BÚSQUEDA EN EL BANCO (v14.1)
   --------------------------------------------------------------------- */
#bank-search-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
}

#bank-search {
    width: 100%;
    min-width: 0;
    padding: 7px 32px 7px 12px;
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--panel-dark-2);
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    color: var(--text-light);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

#bank-search::placeholder { color: var(--text-muted); }

#bank-search:focus {
    border-color: var(--accent-win);
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.15);
}

#bank-search-clear {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-light);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
#bank-search-clear:hover { background: rgba(255, 255, 255, 0.3); }

/* Elemento destacado al buscar o con pista (v14.1) */
.element.search-highlight {
    outline: 2px solid var(--accent-win);
    outline-offset: 2px;
}

.element.search-dimmed {
    opacity: 0.2;
    filter: grayscale(0.6);
}

/* Pista: elemento flasheando en su slot (v14.1) */
@keyframes hintPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.8),
                    0 0 20px 4px rgba(251, 191, 36, 0.6);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(251, 191, 36, 0),
                    0 0 30px 8px rgba(251, 191, 36, 0.9);
    }
}

.slot.hint-showing {
    animation: hintPulse 0.8s ease-in-out infinite;
    border-color: var(--accent-hint) !important;
    border-style: solid !important;
    z-index: 5;
}

.element.hint-preview {
    animation: none !important;
}

/* ---------------------------------------------------------------------
   FILA DE CONTROLES: dificultad + cronómetro lado a lado (v14.1)
   --------------------------------------------------------------------- */
#control-row {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
    gap: 8px;
    margin-bottom: 10px;
}

/* ---------------------------------------------------------------------
   PANEL DE CRONÓMETRO Y MEJOR TIEMPO (v14) - Versión compacta
   --------------------------------------------------------------------- */
#timer-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 8px 10px;
    background: var(--panel-dark-2);
    border: 1px solid var(--border-dark);
    border-radius: 8px;
}

.timer-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

.timer-label {
    font-size: 0.66rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.timer-value {
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-light);
    letter-spacing: 1px;
}

.timer-value.timer-best {
    color: var(--accent-hint);
}

.timer-value.timer-running {
    color: var(--accent-win);
    animation: timerPulse 1s ease-in-out infinite;
}

@keyframes timerPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.timer-block.new-record .timer-value {
    animation: newRecord 0.6s ease;
}

@keyframes newRecord {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.3); color: #fcd34d; }
    100% { transform: scale(1); }
}

/* ---------------------------------------------------------------------
   CANVAS DE CONFETTI (v14)
   --------------------------------------------------------------------- */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 500;
}

/* ---------------------------------------------------------------------
   TOOLBAR DEL BANCO: búsqueda + orden en una fila (v14.1)
   --------------------------------------------------------------------- */
#bank-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

#bank-filter {
    padding: 0;
    border: none;
    margin: 0;
    display: flex;
    gap: 2px;
    background: var(--panel-dark-2);
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    padding: 2px;
    flex-shrink: 0;
}

#bank-filter label {
    position: relative;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 6px 10px;
    border-radius: 4px;
    color: var(--text-muted);
    font-weight: 600;
    transition: background-color 0.15s, color 0.15s;
    user-select: none;
}

#bank-filter label:hover {
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.05);
}

#bank-filter input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

#bank-filter label:has(input:checked) {
    background: var(--accent-win);
    color: #0b1f3a;
}

#bank-header {
    margin-bottom: 6px;
}

#bank-header h2 {
    font-size: 0.95rem;
    margin: 0;
    text-align: left;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

#bank-counter {
    font-size: 0.85rem;
    color: var(--text-light);
    font-weight: 700;
    margin-left: 6px;
    letter-spacing: 0;
    text-transform: none;
}

#element-bank {
    /* Ocupa todo el alto sobrante del sidebar y hace scroll internamente
       si hay más elementos de los que caben (v14.1) */
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: grid;
    grid-template-columns: repeat(auto-fill, 58px);
    justify-content: center;
    gap: var(--bank-gap);
    padding: var(--bank-padding);
    background-color: var(--panel-dark);
    border: 1px solid var(--border-dark);
    border-radius: 8px;
    align-content: start;
}

/* Scrollbar sutil para el banco */
#element-bank::-webkit-scrollbar { width: 8px; }
#element-bank::-webkit-scrollbar-track { background: transparent; }
#element-bank::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
#element-bank::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

input[type="radio"] { accent-color: #7fb3ff; }

/* ---------------------------------------------------------------------
   LEYENDA
   --------------------------------------------------------------------- */
.leyenda-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    width: 100%;
    justify-content: center;
    align-items: center;
    padding: 14px 0 8px;
    margin-top: 18px;
    border-top: 1px solid var(--border-dark);
}

.leyenda-item {
    display: flex;
    align-items: center;
    white-space: nowrap;
    font-size: 0.95em;
}

.leyenda-color {
    width: 16px;
    height: 16px;
    margin-right: 6px;
    border: 1px solid #333;
    border-radius: 4px;
    flex-shrink: 0;
}

/* ---------------------------------------------------------------------
   MODAL - Tarjeta única compacta con tooltips
   Animaciones: fade + scale al abrir/cerrar, backdrop con blur
   --------------------------------------------------------------------- */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        backdrop-filter: blur(0);
        -webkit-backdrop-filter: blur(0);
    }
    to {
        opacity: 1;
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
    }
}

@keyframes modalPopIn {
    0% {
        opacity: 0;
        transform: scale(0.82) translateY(20px);
        filter: blur(4px);
    }
    60% {
        opacity: 1;
        transform: scale(1.03) translateY(-2px);
        filter: blur(0);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
        filter: blur(0);
    }
}

@keyframes modalFadeOut {
    from {
        opacity: 1;
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
    }
    to {
        opacity: 0;
        backdrop-filter: blur(0);
        -webkit-backdrop-filter: blur(0);
    }
}

@keyframes modalPopOut {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
        filter: blur(0);
    }
    to {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
        filter: blur(3px);
    }
}

#modal {
    display: none;
    position: fixed;
    z-index: 100;
    inset: 0;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    justify-content: center;
    align-items: center;
    padding: 20px;
    animation: modalFadeIn 0.3s ease forwards;
}

#modal.modal-closing {
    animation: modalFadeOut 0.25s ease forwards;
}

#modal.modal-closing #modal-content {
    animation: modalPopOut 0.25s ease forwards;
}

.modal-hidden { display: none !important; }

#modal-content {
    margin: auto;
    width: min(92vw, 500px);
    padding: 30px;
    border-radius: 20px;
    position: relative;
    border: 8px solid #fff;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.55),
                0 0 0 1px rgba(255, 255, 255, 0.1);
    background-color: transparent;
    animation: modalPopIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    transform-origin: center;
}

#modal-close {
    color: #888;
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
}
#modal-close:hover,
#modal-close:focus { color: #000; }

.modal-card {
    position: relative;
    width: 100%;
    height: 440px;
    font-family: Georgia, 'Times New Roman', serif;
    color: #000;
}

/* Esquinas superiores */
.modal-weight {
    position: absolute;
    top: 8px;
    left: 15px;
    font-size: 1.35rem;
    font-weight: 500;
}
.modal-number {
    position: absolute;
    top: 8px;
    right: 15px;
    font-size: 1.35rem;
    font-weight: 600;
}

/* Segunda fila: ionización (izda) y electronegatividad (dcha) */
.modal-ionization {
    position: absolute;
    top: 44px;
    left: 15px;
    font-size: 1rem;
}
.modal-electroneg {
    position: absolute;
    top: 44px;
    right: 15px;
    font-size: 1rem;
}

/* Símbolo grande centrado */
.modal-symbol {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -55%);
    font-size: 10rem;
    font-weight: bold;
    line-height: 1;
}

/* Nombre bajo el símbolo */
.modal-name {
    position: absolute;
    bottom: 55px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 1.6rem;
    font-weight: 500;
    font-style: italic;
}

/* Estados de oxidación: lista vertical, a la derecha del símbolo */
.modal-valences {
    position: absolute;
    top: 90px;
    right: 15px;
    bottom: 110px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
    text-align: right;
    font-size: 0.95rem;
    line-height: 1.25;
}
.modal-valences .val-common { font-weight: 700; font-size: 1.05rem; }

/* Configuración electrónica abajo centrada */
.modal-config {
    position: absolute;
    bottom: 15px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.95rem;
    color: #222;
}

#modal-content a {
    display: block;
    margin-top: 10px;
    text-align: center;
    color: #fff;
    text-decoration: underline;
    font-weight: 600;
    font-family: sans-serif;
}

/* Fondo del modal según familia */
#modal-content.alcalinos          { background-color: #f0f8ff; }
#modal-content.alcalinoterreos    { background-color: #e6e6fa; }
#modal-content.transicion         { background-color: #ffffc2; }
#modal-content.posttransicionales { background-color: #ecec88; }
#modal-content.metaloides         { background-color: #9ff26d; }
#modal-content.no-metales         { background-color: #afeeee; }
#modal-content.gases-nobles       { background-color: #e0ffff; }
#modal-content.lantanidos         { background-color: #ffe4c4; }
#modal-content.actinidos          { background-color: #ffcda1; }

/* Tooltips al pasar el ratón */
.modal-weight,
.modal-number,
.modal-ionization,
.modal-electroneg,
.modal-symbol,
.modal-name,
.modal-valences,
.modal-config { cursor: help; }

.modal-weight::after,
.modal-number::after,
.modal-ionization::after,
.modal-electroneg::after,
.modal-symbol::after,
.modal-name::after,
.modal-valences::after,
.modal-config::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.88);
    color: #fff;
    padding: 5px 9px;
    border-radius: 5px;
    font-size: 0.75rem;
    font-family: sans-serif;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 200;
}

.modal-weight:hover::after,
.modal-number:hover::after,
.modal-ionization:hover::after,
.modal-electroneg:hover::after,
.modal-symbol:hover::after,
.modal-name:hover::after,
.modal-valences:hover::after,
.modal-config:hover::after { opacity: 1; }

/* ---------------------------------------------------------------------
   MENSAJE DE VICTORIA
   --------------------------------------------------------------------- */
#victoria-msg {
    display: none;
    margin-top: 15px;
    background: linear-gradient(135deg, var(--accent-win) 0%, #22c55e 100%);
    color: #0b1f3a;
    padding: 16px 18px;
    border-radius: 10px;
    text-align: center;
    font-weight: bold;
    font-size: 1rem;
    box-shadow: 0 8px 24px rgba(74, 222, 128, 0.35),
                inset 0 1px 0 rgba(255, 255, 255, 0.3);
    animation: flotarElemento 2s ease-in-out infinite;
}

#victoria-msg .victoria-time {
    display: block;
    margin-top: 6px;
    font-size: 1.3rem;
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
}

#victoria-msg.visible { display: block; }

/* ---------------------------------------------------------------------
   RESPONSIVE
   Escalado fluido de la tabla según el ancho del viewport y layout en
   columna para tablets/móviles (v14.1)
   --------------------------------------------------------------------- */

/* Pantallas medianas/pequeñas (< 1400px): escalar la tabla con clamp
   para que encaje sin que los elementos pierdan legibilidad */
@media (max-width: 1500px) {
    :root {
        --table-col: clamp(32px, 3.4vw, 60px);
        --table-row: clamp(42px, 4.6vw, 80px);
        --table-gap: 2px;
        --label-size: clamp(16px, 1.6vw, 22px);
    }

    .element .simbolo { font-size: clamp(1rem, 1.5vw, 2em); }
    .element .nombre-elemento {
        font-size: clamp(0.5rem, 0.7vw, 0.84em);
        min-height: auto;
    }
}

/* Tablet en horizontal o portátil pequeño: reducir padding sidebar */
@media (max-width: 1200px) {
    #juego-container {
        gap: 10px;
    }
    #sidebar-right {
        padding-left: 10px;
        width: 280px;
        flex: 0 0 280px;
    }
    .timer-value { font-size: 1rem; }
}

/* Tablet en vertical / pantallas estrechas: layout en columna
   (tabla arriba, sidebar completo debajo) */
@media (max-width: 900px) {
    body { margin: 8px; }

    #juego-container {
        flex-direction: column;
        width: 100%;
        align-items: center;
    }

    .periodic-table-container {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;  /* scroll horizontal si la tabla no cabe */
    }

    #sidebar-right {
        width: 100%;
        max-width: 700px;
        flex: 0 0 auto;
        padding-left: 0;
        position: static;
        max-height: none;
    }

    #element-bank {
        max-height: 50vh;
    }
}

/* Móvil: la tabla es diminuta pero completa. El usuario puede
   hacer pinch-zoom si quiere ver detalles */
@media (max-width: 600px) {
    :root {
        --table-col: clamp(18px, 4.5vw, 32px);
        --table-row: clamp(22px, 5.5vw, 42px);
        --table-gap: 1px;
        --label-size: 14px;
    }

    body { margin: 6px; font-size: 14px; }

    h1 { font-size: 1.1rem; margin: 10px 0 4px; }
    .title-block p, .periodic-table-container > p { font-size: 0.8rem; }

    .element .simbolo { font-size: clamp(0.6rem, 2vw, 1rem); }
    .element .nombre-elemento { display: none; }  /* sin nombre en móvil, solo símbolo */

    .element.colocado .nombre-elemento { display: block; font-size: 0.55rem; }
    .element.colocado .atomic-weight,
    .element.colocado .atomic-number,
    .element.colocado .valencias { font-size: 0.55rem; }

    .acciones button { padding: 5px 8px; font-size: 0.8rem; }
    .acciones { gap: 4px; }

    #control-row { grid-template-columns: 1fr; gap: 6px; }

    .leyenda-container { gap: 6px 10px; padding: 10px 6px; }
    .leyenda-item { font-size: 0.75em; }

    /* Modal ocupa casi toda la pantalla en móvil */
    #modal-content {
        width: 95vw;
        padding: 20px 15px;
    }
    .modal-symbol { font-size: 6rem; }
    .modal-card { height: 360px; }
}

/* Breakpoints hacia arriba (pantallas grandes) */
@media (min-width: 1400px) and (min-height: 900px) {
    :root {
        --table-col: 66px;
        --table-row: 88px;
        --table-gap: 3px;
        --label-size: 24px;
    }
}

/* Full HD clásico (1920×1080): versión ligeramente mayor sin pasarse de alto.
   Contando que el navegador resta ~100px de barras, apuntamos a ~980px de viewport */
@media (min-width: 1700px) and (min-height: 1000px) {
    :root {
        --table-col: 70px;
        --table-row: 80px;
        --table-gap: 3px;
        --label-size: 24px;
    }
}

/* Pantallas realmente grandes (QHD, 4K, monitores verticales) */
@media (min-width: 2000px), (min-height: 1300px) {
    :root {
        --table-col: 82px;
        --table-row: 112px;
        --table-gap: 4px;
        --label-size: 30px;
    }
}
