:root {
    --rl-bg: #070a10;
    --rl-surface: #0d111a;
    --rl-surface-2: #121824;
    --rl-border: rgba(255, 255, 255, 0.07);
    --rl-border-hi: rgba(126, 184, 234, 0.3);
    --rl-text: #f4f7fb;
    --rl-muted: #a3b4cc;
    --rl-brand: #002b66;
    --rl-brand-rgb: 0, 43, 102;
    --rl-accent: #7eb8ea;
    --rl-accent-soft: #a8d4f8;
    --rl-accent-dim: rgba(126, 184, 234, 0.12);
    --rl-accent-rgb: 126, 184, 234;
    --rl-max: 1180px;
    --rl-sidebar: 280px;
    --rl-font: 'IBM Plex Sans Arabic', system-ui, sans-serif;
    --rl-font-en: 'Outfit', system-ui, sans-serif;
    --rl-radius: 12px;
    --rl-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 12px 40px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body.rules-page {
    font-family: var(--rl-font);
    background-color: #040609;
    background-image:
        linear-gradient(118deg, rgba(16, 32, 58, 0.22) 0%, transparent 42%),
        linear-gradient(180deg, #080e18 0%, var(--rl-bg) 50%, #040609 100%);
    color: var(--rl-text);
    line-height: 1.65;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

body.rules-page::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.038;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.78' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    mix-blend-mode: soft-light;
}

.hidden { display: none !important; }

.rules-wrap {
    width: min(var(--rl-max), calc(100% - 2rem));
    margin-inline: auto;
    position: relative;
    z-index: 1;
}

/* ── Top bar ── */
.rules-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid var(--rl-border);
    background: rgba(13, 17, 26, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.rules-topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 60px;
}

.rules-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--rl-text);
}

.rules-brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--rl-border-hi);
    background: var(--rl-surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.rules-brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.rules-brand-mark img:not(.hidden) + .rules-brand-initial { display: none; }

.rules-brand-initial {
    font-family: var(--rl-font-en);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--rl-accent);
}

.rules-brand-text {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    line-height: 1.2;
}

.rules-brand-name {
    font-family: var(--rl-font-en);
    font-weight: 700;
    font-size: 0.98rem;
}

.rules-brand-tag {
    font-size: 0.7rem;
    color: var(--rl-muted);
    font-weight: 500;
}

.rules-topnav {
    display: flex;
    align-items: center;
    gap: 0.15rem;
}

.rules-topnav a {
    color: var(--rl-muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.45rem 0.8rem;
    border-radius: 8px;
    transition: color 0.15s, background 0.15s;
}

.rules-topnav a:hover {
    color: var(--rl-text);
    background: rgba(255, 255, 255, 0.04);
}

.rules-topnav a.is-current {
    color: var(--rl-accent);
    background: var(--rl-accent-dim);
}

/* ── Page head ── */
.rules-page-head {
    padding: 2.25rem 0 1.75rem;
    border-bottom: 1px solid var(--rl-border);
    background: linear-gradient(180deg, rgba(var(--rl-accent-rgb), 0.04) 0%, transparent 100%);
}

.rules-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    color: var(--rl-muted);
    margin-bottom: 1.15rem;
}

.rules-breadcrumb a {
    color: var(--rl-muted);
    text-decoration: none;
}

.rules-breadcrumb a:hover { color: var(--rl-accent); }

.rules-head-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.rules-page-head h1 {
    font-size: clamp(1.75rem, 4vw, 2.25rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.45rem;
}

.rules-lead {
    max-width: 38rem;
    color: var(--rl-muted);
    font-size: 0.92rem;
}

.rules-stats {
    display: flex;
    gap: 0.65rem;
}

.rules-stats div {
    min-width: 100px;
    padding: 0.65rem 0.9rem;
    border-radius: var(--rl-radius);
    border: 1px solid var(--rl-border);
    background: var(--rl-surface);
    text-align: center;
}

.rules-stats dt {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--rl-muted);
    margin-bottom: 0.2rem;
}

.rules-stats dd {
    font-family: var(--rl-font-en);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--rl-accent);
    line-height: 1;
}

/* ── Dashboard shell ── */
.rules-dashboard {
    display: grid;
    grid-template-columns: var(--rl-sidebar) 1fr;
    gap: 0;
    margin: 1.75rem 0 3rem;
    border: 1px solid var(--rl-border);
    border-radius: 16px;
    overflow: hidden;
    background: var(--rl-surface);
    box-shadow: var(--rl-shadow);
    min-height: min(72vh, 720px);
}

.rules-sidebar {
    display: flex;
    flex-direction: column;
    border-inline-end: 1px solid var(--rl-border);
    background: var(--rl-surface-2);
}

.rules-sidebar-head {
    padding: 1rem;
    border-bottom: 1px solid var(--rl-border);
}

.rules-sidebar-title {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--rl-muted);
    margin-bottom: 0.65rem;
}

.rules-search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--rl-border);
    border-radius: 8px;
    background: var(--rl-surface);
    transition: border-color 0.15s;
}

.rules-search:focus-within { border-color: var(--rl-border-hi); }

.rules-search svg {
    display: block;
    width: 16px;
    height: 16px;
    flex: none;
    color: var(--rl-muted);
}

.rules-search input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    color: var(--rl-text);
    font-family: inherit;
    font-size: 0.84rem;
    outline: none;
}

.rules-search input::placeholder { color: #5a6474; }

.rules-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.rules-nav::-webkit-scrollbar { width: 5px; }
.rules-nav::-webkit-scrollbar-thumb {
    background: rgba(var(--rl-accent-rgb), 0.2);
    border-radius: 999px;
}

.rules-nav-btn {
    display: grid;
    grid-template-columns: 1.75rem 1fr auto;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.6rem 0.65rem;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--rl-muted);
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 500;
    text-align: right;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    line-height: 1.4;
}

.rules-nav-btn:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--rl-text);
}

.rules-nav-btn.is-active {
    background: var(--rl-accent-dim);
    border-color: rgba(var(--rl-accent-rgb), 0.2);
    color: var(--rl-text);
}

.rules-nav-index {
    font-family: var(--rl-font-en);
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--rl-muted);
    opacity: 0.7;
}

.rules-nav-btn.is-active .rules-nav-index { color: var(--rl-accent); opacity: 1; }

.rules-nav-label { min-width: 0; }

.rules-nav-count {
    font-family: var(--rl-font-en);
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.12rem 0.4rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--rl-muted);
}

.rules-nav-btn.is-active .rules-nav-count {
    background: rgba(var(--rl-accent-rgb), 0.15);
    color: var(--rl-accent);
}

/* ── Main panel ── */
.rules-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--rl-surface);
}

.rules-doc {
    flex: 1;
    padding: 1.75rem 1.85rem;
    animation: rules-fade 0.22s ease;
}

@keyframes rules-fade {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.rules-doc-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--rl-border);
}

.rules-doc-head-main h2 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
}

.rules-doc-meta {
    font-family: var(--rl-font-en);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    color: var(--rl-muted);
    text-transform: uppercase;
}

.rules-doc-badge {
    flex-shrink: 0;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-family: var(--rl-font-en);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--rl-accent);
    background: var(--rl-accent-dim);
    border: 1px solid rgba(var(--rl-accent-rgb), 0.18);
    white-space: nowrap;
}

.rules-doc-intro {
    color: var(--rl-muted);
    font-size: 0.9rem;
    margin-bottom: 1.35rem;
    max-width: 52rem;
    padding: 0.75rem 0.9rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
    border-inline-start: 2px solid rgba(var(--rl-accent-rgb), 0.35);
}

.rules-def-grid {
    display: grid;
    gap: 0.65rem;
    margin-bottom: 1.35rem;
}

@media (min-width: 640px) {
    .rules-def-grid { grid-template-columns: repeat(2, 1fr); }
}

.rules-def {
    padding: 0.85rem 0.95rem;
    border-radius: 10px;
    border: 1px solid var(--rl-border);
    background: rgba(255, 255, 255, 0.02);
}

.rules-def h3 {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--rl-accent);
    margin-bottom: 0.35rem;
}

.rules-def p {
    font-size: 0.84rem;
    color: var(--rl-muted);
    line-height: 1.6;
}

.rules-section {
    margin-bottom: 1.75rem;
}

.rules-section:last-child { margin-bottom: 0; }

.rules-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
}

.rules-section h3 {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--rl-text);
}

.rules-section-count {
    font-family: var(--rl-font-en);
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--rl-muted);
}

.rules-list {
    list-style: none;
    counter-reset: rule-num;
    border: 1px solid var(--rl-border);
    border-radius: 10px;
    overflow: hidden;
}

.rules-list li {
    counter-increment: rule-num;
    display: grid;
    grid-template-columns: 2.75rem 1fr;
    gap: 0.85rem;
    align-items: start;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--rl-border);
    font-size: 0.88rem;
    line-height: 1.65;
    background: rgba(255, 255, 255, 0.015);
    transition: background 0.12s;
}

.rules-list li:last-child { border-bottom: none; }

.rules-list li:hover { background: rgba(var(--rl-accent-rgb), 0.03); }

.rules-list li::before {
    content: counter(rule-num, decimal-leading-zero);
    font-family: var(--rl-font-en);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--rl-accent);
    padding-top: 0.15rem;
    opacity: 0.75;
}

.rules-note {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    margin-top: 1.35rem;
    padding: 0.8rem 0.95rem;
    border-radius: 8px;
    border: 1px solid rgba(var(--rl-accent-rgb), 0.15);
    background: var(--rl-accent-dim);
    font-size: 0.82rem;
    color: var(--rl-muted);
    line-height: 1.55;
}

.rules-note::before {
    content: '!';
    flex-shrink: 0;
    width: 1.15rem;
    height: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(var(--rl-accent-rgb), 0.2);
    color: var(--rl-accent);
    font-family: var(--rl-font-en);
    font-size: 0.65rem;
    font-weight: 700;
}

.rules-empty {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--rl-muted);
}

.rules-empty strong {
    display: block;
    color: var(--rl-text);
    margin-bottom: 0.35rem;
}

/* ── Pager ── */
.rules-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--rl-border);
    background: var(--rl-surface-2);
}

.rules-pager-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--rl-border);
    border-radius: 8px;
    background: var(--rl-surface);
    color: var(--rl-text);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.12s, background 0.12s;
}

.rules-pager-btn:hover:not(:disabled) {
    border-color: var(--rl-border-hi);
    background: rgba(var(--rl-accent-rgb), 0.06);
}

.rules-pager-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.rules-pager-btn svg {
    display: block;
    width: 14px;
    height: 14px;
    flex: none;
}

.rules-pager-center {
    font-size: 0.78rem;
    color: var(--rl-muted);
    text-align: center;
}

.rules-pager-center strong {
    color: var(--rl-accent);
    font-family: var(--rl-font-en);
}

/* ── Footer ── */
.rules-footer {
    border-top: 1px solid var(--rl-border);
    padding: 1.25rem 0;
    margin-top: auto;
}

.rules-footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.82rem;
    color: var(--rl-muted);
}

.rules-footer-links {
    display: flex;
    gap: 1rem;
}

.rules-footer-links a {
    color: var(--rl-muted);
    text-decoration: none;
}

.rules-footer-links a:hover { color: var(--rl-accent); }

/* ── Mobile ── */
@media (max-width: 860px) {
    .rules-dashboard {
        grid-template-columns: 1fr;
        min-height: 0;
    }

    .rules-sidebar {
        border-inline-end: none;
        border-bottom: 1px solid var(--rl-border);
    }

    .rules-nav {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 0.35rem;
    }

    .rules-nav-btn {
        flex: 0 0 auto;
        min-width: 168px;
        grid-template-columns: 1.5rem 1fr auto;
    }

    .rules-doc { padding: 1.25rem 1rem; }

    .rules-doc-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .rules-stats { width: 100%; }
    .rules-stats div { flex: 1; }

    .rules-pager {
        flex-wrap: wrap;
        justify-content: center;
    }

    .rules-pager-center { order: -1; width: 100%; margin-bottom: 0.25rem; }
}
