body {
    background-color: #f4f7f9;
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    margin: 20px 0;
    padding: 5px;
    box-sizing: border-box;
}

.container {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-direction: column;
    width: 100%;
    max-width: 715px;
    min-width: 300px;
}

.top {
    display: flex;
    flex-direction: row;
    gap: 5px;
    width: 100%;
}

.bottom {
    display: flex;
    flex-direction: column;
    text-align: center;
    gap: 10px;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.box {
    display: flex;
    flex-direction: row;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

button {
    background-color: #fff;
    border: 1px solid #bbb;
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-weight: 400;
    font-size: 11px;
    white-space: nowrap;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

button:hover {
    background-color: #d0d0d0;
}

.image-container {
    flex: 2;
    max-width: 480px;
    min-width: 250px;
    background-color: white;
    border: 2px solid #999;
    padding: 5px;
    border-radius: 6px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    align-self: flex-start;
}

.portada {
    display: block;
    width: 100%;
    height: auto;
}

button.activo {
    background-color: #333;
    border-color: #333;
    color: #fff;
}

/* Grilla de rangos 13x13 */
:root {
    --c-r: #fd002b;
    --c-y: #fae099;
    --c-g: #a7d878;
    --c-b: #aadbe5;
    --c-vacia: #f2f3f5;
}

.grilla {
    container-type: inline-size;
    display: grid;
    grid-template-columns: repeat(13, 1fr);
    gap: 2px;
    width: 100%;
}

.celda {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--c-vacia);
    background-origin: border-box;
    border: 1px solid #e3e5e8;
    border-radius: 2px;
    color: #556;
    font-size: clamp(6px, 2.4cqi, 13px);
    letter-spacing: -0.02em;
    min-width: 0;
    overflow: hidden;
}

.celda.jugada {
    color: #111;
    font-weight: 600;
    border-color: transparent;
}

.leyenda {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 14px;
    padding-top: 6px;
    border-top: 1px solid #ddd;
    font-size: 11px;
    font-weight: 700;
    color: #222;
}

.leyenda span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.leyenda i {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

/* Páginas de texto: mismo cuadrado que la grilla de rangos.
   Las medidas en cqi escalan con el ancho del visor para que todo entre sin scroll. */
.image-container {
    container-type: inline-size;
}

.texto {
    aspect-ratio: 1;
    width: 100%;
    box-sizing: border-box;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 2.5cqi;
    font-size: 3.4cqi;
    line-height: 1.3;
    color: #222;
}

.texto h3 {
    margin: 0 0 1.5cqi;
    font-size: 3.8cqi;
    text-align: center;
}

.texto ul {
    margin: 0;
    padding-left: 4.5cqi;
}

.texto li {
    margin-bottom: 1cqi;
}

.nota {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px solid #999;
    border-radius: 4px;
    padding: 2.5cqi 3.5cqi;
}

.nota.amarilla { background: #fbe3a4; }
.nota.verde { background: #c6e3a6; }
.nota.azul { background: #bcd8f2; justify-content: space-evenly; }

.sizings {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4cqi;
}

.sizings .columna {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.sizings table,
.perfiles,
.hud {
    border-collapse: collapse;
    width: 100%;
}

.sizings table { table-layout: fixed; }

.sizings td {
    padding: 0.9cqi 1cqi;
    border: 1px solid #fff;
    background: #8de08a;
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
}

.sizings td + td {
    background: #1f3b4d;
    color: #fff;
    white-space: normal;
}

.perfiles th,
.perfiles td {
    padding: 0.4cqi 1cqi;
    text-align: left;
    white-space: nowrap;
}

.dot {
    display: inline-block;
    width: 2.6cqi;
    height: 2.6cqi;
    border-radius: 50%;
    margin-right: 1.2cqi;
}

.hud-claves {
    font-weight: 600;
}

.hud-claves li {
    margin-bottom: 0;
}

.hud {
    flex: 1;
    background: #2b2b2b;
    color: #eee;
    font-family: Georgia, 'Times New Roman', serif;
}

.hud td {
    padding: 0 1.2cqi;
    white-space: nowrap;
}

.hud tr.sep td {
    padding-top: 2.5cqi;
}

.right-sidebar {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.badge {
    font-size: 9px;
    background-color: #f3b7b7;
    padding: 3px;
    border-radius: 5px;
    text-align: center;
    color: #222;
    font-weight: 600;
}

.set {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    justify-content: center;
}

.tags button {
    margin: 1px;
    font-size: 10px;
    padding: 1px 6px;
}

.error {
    display: none;
}

/* Celular */
@media (max-width: 600px) {
    body {
        margin: 0;
        padding: 0 8px 16px;
    }

    .container {
        min-width: 0;
        gap: 12px;
        align-items: stretch;
    }

    /* Los hijos de .top pasan a ser hijos directos de .container,
       así el visor puede quedar fijo arriba mientras se recorren todos los botones. */
    .top {
        display: contents;
    }

    .image-container {
        order: -1;
        width: 100%;
        max-width: none;
        min-width: 0;
        box-sizing: border-box;
        border-width: 1px;
        border-radius: 0 0 8px 8px;
        padding: 6px;
    }

    .image-container.fijo {
        position: sticky;
        top: 0;
        z-index: 5;
    }

    .celda {
        font-size: clamp(7px, 2.9cqi, 13px);
        letter-spacing: -0.04em;
        border-radius: 1px;
    }

    .grilla {
        gap: 1px;
    }

    .leyenda {
        font-size: 10px;
        gap: 3px 10px;
        padding-top: 5px;
    }

    .leyenda i {
        width: 10px;
        height: 10px;
    }

    /* Grupos de botones: título arriba y botones en filas que llenan el ancho */
    .sidebar,
    .right-sidebar,
    .bottom {
        gap: 10px;
    }

    .set {
        flex-direction: row;
        flex-wrap: wrap;
        align-content: flex-start;
        gap: 4px;
    }

    .set > .badge {
        flex-basis: 100%;
    }

    .tags,
    .box .set > div {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        flex-basis: 100%;
    }

    .box {
        flex-wrap: nowrap;
        gap: 10px;
    }

    .box .set {
        flex: 1;
    }

    .badge {
        font-size: 10px;
        padding: 4px;
    }

    button,
    .tags button {
        flex: 1 0 auto;
        min-height: 36px;
        margin: 0;
        padding: 4px 8px;
        font-size: 13px;
        border-radius: 6px;
    }
}

@media (hover: none) {
    button:hover {
        background-color: #fff;
    }

    button.activo:hover {
        background-color: #333;
    }
}
