/* ------------------------------------------------ */
/* --- Betting Rules Page Styling (betting-rules.css) --- */
/* ------------------------------------------------ */

/* FIX: Robust scroll offset using scroll-margin-top on targets */
/* This works better than scroll-padding-top in some mobile contexts */
.rule-section,
.rules-intro {
    scroll-margin-top: 160px;
    /* Desktop offset */
}

/* Define vars based on expected layout */
:root {
    --sticky-offset-desktop: 50px;
    --sticky-offset-mobile: 0px;

    --color-primary: #1a472a;
    --color-secondary: #f6bc3f;
    --color-secondary-dark: #B5882A;
    --color-white: #ffffff;
    --color-text-dark: #333333;
    --color-text-white: #dcd086;
}

.page-content {
    background-color: #f4f4f4;
    padding: 2.5rem 0;
}

.page-content .container {
    max-width: 95%;
}

/* === 1. Layout & Sidebar (Desktop) === */

.rules-layout {
    display: flex;
    gap: 2.5rem;
    align-items: flex-start;
}

.rules-sidebar {
    position: sticky;
    top: calc(var(--sticky-offset-desktop) + 80px);
    width: 280px;
    background-color: var(--color-white);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
    z-index: 40;
}

/* Scrollbar styling for sidebar */
.rules-sidebar::-webkit-scrollbar {
    width: 6px;
}

.rules-sidebar::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 4px;
}

.rules-sidebar h3 {
    color: var(--color-primary);
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
    border-bottom: 2px solid #eee;
    padding-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Close button is hidden on desktop */
.rules-sidebar .close-toc {
    display: none;
}

.rules-toc {
    max-height: 70vh;
    overflow-y: auto;
}

.rules-toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.rules-toc li {
    border-bottom: 1px dashed #eee;
}

.rules-toc li:last-child {
    border-bottom: none;
}

.rules-toc a {
    display: block;
    padding: 0.5rem 0.25rem;
    text-decoration: none;
    color: var(--color-text-dark);
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.rules-toc a:hover {
    color: var(--color-secondary-dark);
    font-weight: 600;
}

.rules-toc a.active {
    color: var(--color-primary);
    font-weight: 700;
    background-color: #f9f9f9;
    border-left: 3px solid var(--color-secondary);
    padding-left: 0.75rem;
}

.rules-content {
    flex: 1;
    min-width: 0;
}

/* === 2. General Provisions Styling === */

.rules-intro {
    background-color: var(--color-white);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 2.5rem;
    border-left: 6px solid var(--color-primary);
}

.rules-intro h2 {
    color: var(--color-primary);
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    border-bottom: 3px solid var(--color-secondary-dark);
    padding-bottom: 0.5rem;
}

.rules-intro p {
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.rules-intro ol {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: item;
}

/* Custom list styling for General Provisions */
.rules-intro ol li {
    font-size: 0.95rem;
    line-height: 1.8;
    margin-bottom: 1.5rem;
    padding-left: 40px;
    position: relative;
    color: var(--color-text-dark);
}

.rules-intro ol li::before {
    content: counter(item) ". ";
    counter-increment: item;
    position: absolute;
    left: 0;
    top: 0;
    width: 28px;
    height: 28px;
    background-color: var(--color-primary);
    color: #fff;
    border-radius: 50%;
    text-align: center;
    line-height: 28px;
    font-weight: 700;
    font-size: 0.85rem;
}


/* --- TOC Toggle Button (Hidden on Desktop) --- */
.mobile-toc-toggle {
    display: none;
}


/* === 3. Individual Rule Sections (Rule Cards) === */

.rule-section {
    background-color: var(--color-white);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 2.5rem;
}

.rule-header {
    border-bottom: 1px solid #eee;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

.rule-title {
    color: var(--color-primary);
    font-size: 1.5rem;
    font-weight: 700;
}

.rule-number {
    background-color: var(--color-secondary);
    color: var(--color-primary);
    padding: 4px 10px;
    border-radius: 4px;
    margin-right: 10px;
    font-size: 1.2rem;
    display: inline-block;
}

.rule-info-grid {
    display: flex;
    gap: 2rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    padding-left: 0;
    list-style: none;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 1rem;
}

.rule-info-item {
    font-size: 0.9rem;
    color: #555;
    font-weight: 500;
}

.rule-info-label {
    font-weight: 700;
    color: var(--color-secondary-dark);
    margin-right: 5px;
}

.rule-info-value {
    color: var(--color-primary);
    font-weight: 700;
}

/* Nested Rule List Styling */
.rule-body ol,
.rule-body ul {
    padding-left: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.7;
    margin-bottom: 1rem;
}

.rule-body ol li,
.rule-body ul li {
    margin-bottom: 0.75rem;
    color: var(--color-text-dark);
}

.rule-body ol li>ol,
.rule-body ol li>ul {
    margin-top: 0.75rem;
}

/* === 4. Sticky Search Bar & Icons === */

.sticky-search-wrapper {
    position: sticky;
    top: var(--sticky-offset-desktop);
    background-color: #f4f4f4;
    z-index: 100;
    padding: 1rem 0;
    margin-bottom: 1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.rules-search-bar {
    position: relative;
    padding: 0 0.5rem;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 0 !important;
}

#ruleSearchInput {
    width: 100%;
    padding: 1rem 1.5rem;
    padding-right: 6.5rem;
    font-size: 1rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: border-color 0.3s;
}

#ruleSearchInput:focus {
    border-color: var(--color-secondary-dark);
    outline: none;
}

/* Search and Clear Icons Positioning */
.rules-search-bar .search-icon,
.rules-search-bar .clear-search-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1rem;
}

.rules-search-bar .search-icon {
    right: 2rem;
    color: #999;
    pointer-events: none;
}

.rules-search-bar .clear-search-btn {
    right: 4.5rem;
    cursor: pointer;
    color: #666;
    transition: color 0.2s;
    z-index: 10;
}

.rules-search-bar .clear-search-btn:hover {
    color: #cc0000;
}

/* --- Search Feedback Box Styling --- */
.search-feedback {
    margin: 10px 0.5rem 0 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.search-feedback.success {
    background-color: #e6ffed;
    color: #0c712f;
    border: 1px solid #b3e6c6;
}

.search-feedback.failure {
    background-color: #ffe6e6;
    color: #cc0000;
    border: 1px solid #ffb3b3;
}


/* === 5. Floating Back to Top Button === */
.back-to-top-btn {
    display: none;
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 999;
    background-color: var(--color-secondary);
    color: var(--color-primary);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    text-decoration: none;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: background-color 0.3s, transform 0.2s;
    cursor: pointer;
}

.back-to-top-btn:hover {
    background-color: var(--color-secondary-dark);
    color: var(--color-white);
    transform: translateY(-3px);
}

/* === 6. Mobile Responsive Adjustments (Max Width 991px) === */

@media (max-width: 991px) {

    /* CRITICAL FIX: scroll-margin-top ensures browser scrolls to correct position 
       relative to the sticky header height.
       Header + Search Bar + TOC Toggle ~= 150px
    */
    .rule-section,
    .rules-intro {
        scroll-margin-top: 150px;
    }

    /* --- General Layout --- */
    .rules-layout {
        flex-direction: column;
        gap: 1.5rem;
    }

    .rules-content {
        padding: 0 0.5rem;
        width: 100%;
    }

    /* --- Sticky Search (Sticks to Absolute Top on Mobile) --- */
    .sticky-search-wrapper {
        top: 0;
        padding: 0.75rem 0;
        margin-bottom: 0;
    }

    .rules-search-bar {
        max-width: 100%;
        padding: 0 1rem;
    }

    #ruleSearchInput {
        padding: 0.75rem 1rem;
        padding-right: 5rem;
    }

    .rules-search-bar .search-icon {
        right: 1.5rem;
    }

    .rules-search-bar .clear-search-btn {
        right: 3.5rem;
    }

    .search-feedback {
        margin: 10px 1rem 0 1rem;
    }

    /* --- TOC Sidebar (Mobile Overlay) --- */
    .rules-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        max-height: 100vh;
        padding: 2rem 1.5rem;
        border-radius: 0;
        z-index: 1100;
        transform: translateX(-100%);
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.5);
        overflow-y: auto;
        opacity: 0;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    .rules-sidebar.is-open {
        transform: translateX(0);
        opacity: 1;
    }

    /* Close TOC Button Styling (Mobile Only) */
    .rules-sidebar .close-toc {
        display: flex;
        color: var(--color-text-dark);
        font-size: 2rem;
        line-height: 1;
        cursor: pointer;
        position: absolute;
        top: 15px;
        right: 15px;
        background: #f0f0f0;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
    }

    /* --- TOC Toggle Button (Visible on Mobile) --- */
    .mobile-toc-toggle {
        display: block;
        position: sticky;
        /* Sticks right below the sticky search wrapper. */
        top: 76px;
        z-index: 90;
        width: 100%;
        text-align: center;
        background-color: var(--color-primary);
        color: var(--color-white);
        padding: 0.75rem;
        margin-bottom: 1.5rem;
        border-radius: 6px;
        text-decoration: none;
        font-weight: 600;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
        cursor: pointer;
    }

    .mobile-toc-toggle i {
        margin-right: 8px;
    }

    /* --- Back to Top Button Mobile --- */
    .back-to-top-btn {
        bottom: 20px;
        right: 20px;
        width: 40px;
        height: 40px;
        font-size: 1rem;
        z-index: 1200;
    }

    /* General Provision Mobile Adjustments */
    .rules-intro {
        padding: 1.5rem;
    }

    .rule-section {
        padding: 1.5rem;
    }

    .rule-info-grid {
        gap: 1rem;
        flex-direction: column;
    }
}

/* Small Mobile (Phones) */
@media (max-width: 576px) {
    .sticky-search-wrapper {
        padding: 0.5rem 0;
    }

    .mobile-toc-toggle {
        top: 65px;
    }
}

/* === 5. Floating Back to Top Button (Base Styles) === */
.back-to-top-btn {
    display: none;
    /* Hidden by default, toggled by JS */
    position: fixed;
    z-index: 999;
    background-color: var(--color-secondary);
    color: var(--color-primary);
    text-decoration: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: background-color 0.3s, transform 0.2s;
    cursor: pointer;
    font-weight: 700;
}

.back-to-top-btn:hover {
    background-color: var(--color-secondary-dark);
    color: var(--color-white);
    transform: translateY(-3px);
}

/* Desktop Specific Styles (Bottom Right Circle) */
.back-to-top-btn.desktop-only {
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.3rem;
}

/* Mobile Specific Styles (Bottom Center Pill) */
.back-to-top-btn.mobile-only {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    /* Center horizontally */
    width: auto;
    height: 40px;
    padding: 0 1.5rem;
    border-radius: 20px;
    /* Pill shape */
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    z-index: 999;
}

.back-to-top-btn.mobile-only i {
    margin-right: 5px;
}

/* Hide Mobile Button on Desktop */
@media (min-width: 992px) {
    .back-to-top-btn.mobile-only {
        display: none !important;
    }
}

/* Hide Desktop Button on Mobile */
@media (max-width: 991px) {
    .back-to-top-btn.desktop-only {
        display: none !important;
    }

    /* Ensure hover effect (transform) accounts for centering */
    .back-to-top-btn.mobile-only:hover {
        transform: translateX(-50%) translateY(-3px);
    }
}