/* Rules page: readable sci-fi layout, scoped to avoid changing other login pages. */
.rules-page {
    position: relative;
    z-index: 1;
    width: calc(100% - 24px);
    max-width: 1180px;
    margin: 28px auto 46px;
    padding: 0;
}

/* In-game popup mode: keep only the rules panel, without the public header/nav. */
.rules-page-popup {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    margin: 0;
    min-height: 0 !important;
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
}

.rules-page-popup .rules-shell {
    box-sizing: border-box;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    width: 100%;
    border-radius: 0;
    box-shadow: none;
    min-height: 0 !important;
    height: 100% !important;
    max-height: 100% !important;
    overflow: hidden !important;
}

.rules-shell {
    overflow: hidden;
    border: 1px solid rgba(78, 203, 255, 0.48);
    border-radius: 12px;
    background: linear-gradient(145deg, rgba(4, 18, 35, 0.96), rgba(2, 9, 20, 0.9));
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(149, 225, 255, 0.13);
}

.rules-header {
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 96px;
    padding: 18px 28px;
    border-bottom: 1px solid rgba(78, 203, 255, 0.35);
    background:
        linear-gradient(105deg, rgba(16, 69, 105, 0.88), rgba(5, 23, 43, 0.82) 62%, rgba(8, 39, 60, 0.9)),
        radial-gradient(circle at 90% 0%, rgba(69, 218, 255, 0.18), transparent 42%);
}

.rules-header-icon {
    display: grid;
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    place-items: center;
    border: 1px solid rgba(255, 213, 84, 0.8);
    border-radius: 50%;
    color: #ffe27b;
    font-size: 26px;
    background: rgba(65, 42, 5, 0.5);
    box-shadow: 0 0 18px rgba(255, 206, 62, 0.26);
}

.rules-kicker {
    display: block;
    margin-bottom: 2px;
    color: #9edfff;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.rules-header h1 {
    margin: 0;
    color: #f2fbff;
    font-size: clamp(1.65rem, 3vw, 2.35rem);
    font-weight: 800;
    letter-spacing: 0.02em;
}

.rules-content {
    padding: 24px;
}

/* In the game popup the iframe is the viewport. Keep the title fixed and
   give the complete rules body its own scroll container. This prevents both
   the missing scrollbar and the second scrollbar on the outer game page. */
.rules-page-popup .rules-header {
    flex: 0 0 auto;
}

.rules-page-popup .rules-content {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #299bd3 rgba(2, 14, 28, .85);
}

/* Popup mode locks the document viewport. Scrolling is enabled only when the
   rules are taller than the available iframe, never on the outer page. */
html.rules-popup-document,
body.rules-popup-document {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: 100% !important;
    margin: 0 !important;
    overflow: hidden !important;
}

body.rules-popup-document > .rules-page-popup {
    height: 100% !important;
    overflow: hidden !important;
}

/* Nel popup l'unico scorrimento deve avvenire dentro il regolamento. */
.rules-page-popup .rules-content::-webkit-scrollbar {
    width: 9px;
}

.rules-page-popup .rules-content::-webkit-scrollbar-track {
    background: rgba(2, 14, 28, .85);
}

.rules-page-popup .rules-content::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #42c8f4, #1471a8);
    border: 1px solid #0a2e4c;
    border-radius: 8px;
}

.rules-content #rules {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.rules-content #rules > li {
    min-width: 0;
    padding: 20px 22px 19px;
    border: 1px solid rgba(74, 161, 211, 0.38);
    border-left: 3px solid rgba(64, 207, 255, 0.78);
    border-radius: 9px;
    background: linear-gradient(145deg, rgba(8, 34, 57, 0.92), rgba(3, 15, 29, 0.86));
    box-shadow: inset 0 1px 0 rgba(153, 224, 255, 0.08), 0 5px 16px rgba(0, 0, 0, 0.2);
}

.rules-content #rules > li:nth-child(3n + 2) {
    border-left-color: rgba(255, 207, 77, 0.85);
}

.rules-content #rules > li:nth-child(3n) {
    border-left-color: rgba(100, 235, 173, 0.82);
}

.rules-content #rules > li h1 {
    display: flex;
    align-items: baseline;
    gap: 9px;
    margin: 0 0 13px;
    color: #8fddff;
    font-size: clamp(1.25rem, 2vw, 1.65rem);
    line-height: 1.2;
    font-weight: 800;
}

.rules-content #rules > li h1::before {
    content: "✦";
    color: #ffdc62;
    font-size: 0.74em;
    text-shadow: 0 0 8px rgba(255, 213, 73, 0.6);
}

.rules-content #rules > li p {
    margin: 0;
    color: #dbeaf7;
    font-size: 0.97rem;
    line-height: 1.68;
    overflow-wrap: anywhere;
}

@media (max-width: 760px) {
    .rules-page {
        width: calc(100% - 16px);
        margin: 14px auto 28px;
    }

    .rules-header {
        min-height: 78px;
        padding: 14px 16px;
        gap: 11px;
    }

    .rules-header-icon {
        flex-basis: 38px;
        width: 38px;
        height: 38px;
        font-size: 21px;
    }

    .rules-content {
        padding: 12px;
    }

    .rules-page-popup .rules-content {
        padding: 12px;
    }

    .rules-content #rules {
        grid-template-columns: 1fr;
        gap: 11px;
    }

    .rules-content #rules > li {
        padding: 15px 16px;
    }

    .rules-content #rules > li h1 {
        margin-bottom: 9px;
        font-size: 1.2rem;
    }

    .rules-content #rules > li p {
        font-size: 0.91rem;
        line-height: 1.58;
    }
}
