/**
 * Règlement — Page FantasyLap (refonte)
 */

/* ============================================================
   Layout principal : deux colonnes sur desktop
   ============================================================ */

.page-rules {
    position: relative;
}

/* Barre de progression de lecture */
.read-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--color-gold));
    z-index: 200;
    transition: width 0.1s linear;
    pointer-events: none;
}

.rules-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    max-width: 1200px;
    margin: 0 auto;
}

/* ---- Sidebar TOC — masquée sur mobile ---- */
.rules-sidebar {
    display: none;
}

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

@media (min-width: 1024px) {
    .rules-sidebar {
        display: block;
        width: 260px;
        flex-shrink: 0;
        position: sticky;
        top: 5.5rem;
        max-height: calc(100vh - 7rem);
        overflow-y: auto;
    }
}

/* ---- TOC sidebar ---- */
.rules-toc {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.rules-toc h3 {
    font-family: var(--font-title);
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

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

.toc-list li {
    margin-bottom: 0.1rem;
}

.toc-link {
    display: block;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.82rem;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
    border-left: 3px solid transparent;
    line-height: 1.4;
}

.toc-link:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    text-decoration: none;
}

.toc-link.is-active {
    color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
    border-left-color: var(--accent);
    font-weight: 600;
}

/* Barre de recherche dans la sidebar */
.cards-search-wrap {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.cards-search-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
}

.cards-search {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--text);
    background: var(--bg-dark);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.2s;
}

.cards-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(233, 69, 96, 0.2);
}

.cards-search::placeholder {
    color: var(--text-muted);
}

#cardsSearchEmpty {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
}

/* ---- TOC mobile (details/summary) ---- */
.rules-toc-mobile {
    margin-bottom: 1.5rem;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.rules-toc-mobile summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 1.1rem;
    font-family: var(--font-title);
    font-size: 1.05rem;
    user-select: none;
}

.rules-toc-mobile summary::-webkit-details-marker { display: none; }
.rules-toc-mobile summary::marker { display: none; }

.rules-toc-mobile summary:hover {
    background: rgba(255, 255, 255, 0.04);
}

.toc-chevron {
    width: 18px;
    height: 18px;
    transition: transform 0.2s;
    flex-shrink: 0;
    color: var(--text-muted);
}

.rules-toc-mobile[open] .toc-chevron {
    transform: rotate(180deg);
}

.toc-mobile-body {
    padding: 0 1rem 1rem;
    border-top: 1px solid var(--border);
}

.toc-list-mobile {
    list-style: none;
    padding: 0.5rem 0 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.2rem;
}

@media (min-width: 768px) {
    .toc-list-mobile {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .rules-toc-mobile {
        display: none;
    }
}

/* Search inside mobile TOC */
.toc-mobile-search-wrap {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

/* ============================================================
   Hero section — chiffres clés
   ============================================================ */

.rules-header {
    margin-bottom: 1.75rem;
}

.rules-header h1 {
    margin-bottom: 1rem;
    font-size: clamp(1.65rem, 5vw, 2rem);
}

.hero-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

@media (min-width: 600px) {
    .hero-stats {
        grid-template-columns: repeat(4, 1fr);
    }
}

.hero-stat {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 0.75rem;
    text-align: center;
    transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.hero-stat:hover {
    border-color: rgba(233, 69, 96, 0.5);
    transform: translateY(-3px);
    box-shadow: 0 6px 24px rgba(233, 69, 96, 0.15);
}

.hero-stat-icon {
    display: block;
    width: 28px;
    height: 28px;
    margin: 0 auto 0.5rem;
    color: var(--accent);
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.hero-stat-value {
    display: block;
    font-family: var(--font-title);
    font-size: 1.5rem;
    color: var(--color-gold);
    line-height: 1;
    margin-bottom: 0.4rem;
}

.hero-stat-label {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.3;
}

/* ============================================================
   Quick Ref / Cheat Sheet
   ============================================================ */

.quick-ref {
    background: linear-gradient(135deg, rgba(233, 69, 96, 0.07), rgba(255, 213, 79, 0.04));
    border: 2px solid rgba(233, 69, 96, 0.3);
    border-radius: var(--radius-lg);
    margin-bottom: 2rem;
    overflow: hidden;
}

.quick-ref > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.9rem 1.25rem;
    font-family: var(--font-title);
    font-size: 1.05rem;
    color: var(--color-gold);
    user-select: none;
    transition: background 0.15s;
}

.quick-ref > summary::-webkit-details-marker { display: none; }
.quick-ref > summary::marker { display: none; }

.quick-ref > summary:hover {
    background: rgba(255, 213, 79, 0.05);
}

.quick-ref-content {
    padding: 0 1.25rem 1.25rem;
}

.quick-ref-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.5rem;
}

@media (min-width: 600px) {
    .quick-ref-list {
        grid-template-columns: repeat(2, 1fr);
    }
}

.quick-ref-item {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.65rem 0.85rem;
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.quick-ref-icon {
    font-size: 1.2rem;
    line-height: 1.25;
    flex-shrink: 0;
}

.quick-ref-item strong {
    display: block;
    color: var(--text);
    font-size: 0.875rem;
    margin-bottom: 0.1rem;
}

.quick-ref-item span {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.4;
}

/* ============================================================
   Sections
   ============================================================ */

.rules-content section {
    margin-bottom: 3rem;
    scroll-margin-top: 5.5rem;
}

.rules-content section h2 {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-title);
    font-size: clamp(1.2rem, 3vw, 1.5rem);
    color: var(--accent);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.25rem;
}

.section-num {
    font-family: var(--font-body);
    font-size: 0.75em;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.08);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.rules-content section h3 {
    font-family: var(--font-title);
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-gold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 1.75rem 0 0.6rem;
}

.rules-content section h3:first-child {
    margin-top: 0;
}

.rules-content section h4 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    margin: 1rem 0 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ============================================================
   Tableaux barème — heatmap
   ============================================================ */

.rules-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0 1.5rem;
    font-size: 0.88rem;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.rules-table th {
    background: rgba(233, 69, 96, 0.18);
    padding: 0.55rem 0.85rem;
    text-align: left;
    font-weight: 700;
    border-bottom: 2px solid var(--border);
    color: var(--text);
    white-space: nowrap;
}

.rules-table td {
    padding: 0.4rem 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    vertical-align: middle;
}

.rules-table tr:last-child td {
    border-bottom: none;
}

.rules-table tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

.rules-table tr:hover td {
    background: rgba(255, 255, 255, 0.05);
}

.col-effect {
    min-width: 220px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Colonnes points heatmap — course principale */
.pts-cell {
    font-weight: 700;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.pts-cell[data-pts="25"] { color: #ff4757; }
.pts-cell[data-pts="18"] { color: #ff6370; }
.pts-cell[data-pts="15"] { color: #ff8533; }
.pts-cell[data-pts="12"] { color: #ffa502; }
.pts-cell[data-pts="10"] { color: #ffb347; }
.pts-cell[data-pts="8"]  { color: #ffce54; }
.pts-cell[data-pts="6"]  { color: #d4e600; }
.pts-cell[data-pts="4"]  { color: #a8e063; }
.pts-cell[data-pts="2"]  { color: #7efb98; }
.pts-cell[data-pts="1"]  { color: var(--text-muted); }

/* Qualifications (max 10) */
.pts-cell[data-pts="q10"] { color: #ff4757; }
.pts-cell[data-pts="q9"]  { color: #ff7043; }
.pts-cell[data-pts="q8"]  { color: #ff8533; }
.pts-cell[data-pts="q7"]  { color: #ffa502; }
.pts-cell[data-pts="q6"]  { color: #ffb347; }
.pts-cell[data-pts="q5"]  { color: #ffce54; }
.pts-cell[data-pts="q4"]  { color: #d4e600; }
.pts-cell[data-pts="q3"]  { color: #a8e063; }
.pts-cell[data-pts="q2"]  { color: #7efb98; }
.pts-cell[data-pts="q1"]  { color: var(--text-muted); }

/* Sprint (max 15) */
.pts-cell[data-pts="s15"] { color: #ff4757; }
.pts-cell[data-pts="s12"] { color: #ff6370; }
.pts-cell[data-pts="s10"] { color: #ff8533; }
.pts-cell[data-pts="s8"]  { color: #ffa502; }
.pts-cell[data-pts="s6"]  { color: #ffb347; }
.pts-cell[data-pts="s4"]  { color: #ffce54; }
.pts-cell[data-pts="s2"]  { color: #a8e063; }
.pts-cell[data-pts="s1"]  { color: var(--text-muted); }

/* ============================================================
   Cards managers / jokers / bonus
   ============================================================ */

/* Groupes accordéon par rareté */
.cards-group {
    border-radius: var(--radius-lg);
    border: 2px solid var(--border);
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.cards-group > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    background: var(--bg-card);
    font-family: var(--font-title);
    font-size: 0.95rem;
    user-select: none;
    border-bottom: 2px solid transparent;
    transition: background 0.15s;
    flex-wrap: wrap;
}

.cards-group > summary::-webkit-details-marker { display: none; }
.cards-group > summary::marker { display: none; }

.cards-group > summary:hover {
    background: var(--bg-card-mid);
}

.cards-group[open] > summary {
    border-bottom-color: var(--border);
}

.cards-group-count {
    font-family: var(--font-body);
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: auto;
}

.cards-group-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.cards-group[open] .cards-group-chevron {
    transform: rotate(180deg);
}

/* Bordures latérales colorées par rareté */
.cards-group[data-rarity="legendary"] > summary { border-left: 4px solid var(--color-gold); }
.cards-group[data-rarity="epic"]      > summary { border-left: 4px solid #9b59b6; }
.cards-group[data-rarity="rare"]      > summary { border-left: 4px solid #3d86c8; }
.cards-group[data-rarity="common"]    > summary { border-left: 4px solid #6b7280; }

.cards-group-body {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

/* ---- Card block individuelle ---- */
.card-block {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: var(--radius);
    padding: 0.8rem 0.9rem;
    transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.card-block:hover {
    transform: translateX(3px);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.3);
}

.card-block[data-rarity="legendary"] { border-left-color: var(--color-gold); }
.card-block[data-rarity="legendary"]:hover { border-color: var(--color-gold); }

.card-block[data-rarity="epic"] { border-left-color: #9b59b6; }
.card-block[data-rarity="epic"]:hover { border-color: #9b59b6; }

.card-block[data-rarity="rare"] { border-left-color: #3d86c8; }
.card-block[data-rarity="rare"]:hover { border-color: #3d86c8; }

.card-block[data-rarity="common"] { border-left-color: #6b7280; }

.card-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
    flex-wrap: wrap;
}

.card-block-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.card-block-name {
    font-weight: 700;
    color: var(--text);
    font-size: 0.92rem;
    white-space: nowrap;
}

.card-block-cost {
    font-family: var(--font-title);
    font-size: 0.95rem;
    color: var(--color-gold);
    background: rgba(255, 213, 79, 0.1);
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    flex-shrink: 0;
    white-space: nowrap;
}

.card-block-badges {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
}

.card-block-effect {
    color: var(--text-muted);
    font-size: 0.845rem;
    line-height: 1.55;
    margin: 0;
}

/* Badges rareté */
.rarity-badge {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.rarity-legendary {
    background: rgba(255, 213, 79, 0.15);
    color: var(--color-gold);
    border: 1px solid rgba(255, 213, 79, 0.3);
}

.rarity-epic {
    background: rgba(155, 89, 182, 0.15);
    color: #c39bd3;
    border: 1px solid rgba(155, 89, 182, 0.35);
}

.rarity-rare {
    background: rgba(61, 134, 200, 0.15);
    color: #7ab4e0;
    border: 1px solid rgba(61, 134, 200, 0.35);
}

.rarity-common {
    background: rgba(107, 114, 128, 0.15);
    color: #9ca3af;
    border: 1px solid rgba(107, 114, 128, 0.3);
}

/* Badges phase */
.phase-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.15rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 4px;
    white-space: nowrap;
    cursor: default;
}

.phase-badge-a {
    background: rgba(233, 69, 96, 0.18);
    color: var(--accent);
    border: 1px solid rgba(233, 69, 96, 0.3);
}

.phase-badge-b {
    background: rgba(61, 90, 128, 0.3);
    color: #7ab4e0;
    border: 1px solid rgba(61, 90, 128, 0.45);
}

.phase-badge-d {
    background: rgba(45, 106, 79, 0.3);
    color: #6bc96b;
    border: 1px solid rgba(45, 106, 79, 0.45);
}

/* Barre de recherche dans les sections (mobile — cachée sur desktop) */
.section-search-wrap {
    margin-bottom: 1.25rem;
}

@media (min-width: 1024px) {
    #mobileSearchSection {
        display: none;
    }
}

/* ============================================================
   Graphique SVG — Malus gros budget
   ============================================================ */

.malus-chart-wrap {
    position: relative;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    margin: 0.75rem 0 1.5rem;
    overflow-x: auto;
    height: 400px;
}

.malus-chart-svg {
    display: block;
    width: 100%;
    min-width: 400px;
    height: auto;
}

.malus-chart-canvas {
    display: block;
    width: 100%;
    min-width: 400px;
    height: 100%;
}

.malus-chart-caption {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.6rem;
    font-style: italic;
}

.malus-chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 0.6rem;
}

.malus-legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.malus-legend-color {
    width: 14px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.malus-legend-safe   { background: rgba(107, 207, 107, 0.5); }
.malus-legend-light  { background: rgba(255, 165, 0, 0.5); }
.malus-legend-heavy  { background: rgba(233, 69, 96, 0.5); }

/* Tooltip graphique */
#malusTooltip {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    background: var(--bg-dark);
    color: var(--text);
    border: 2px solid var(--color-gold);
    border-radius: var(--radius);
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 600;
    pointer-events: none;
    white-space: nowrap;
    z-index: 5;
    transition: opacity 0.15s;
}

/* ============================================================
   Lexique
   ============================================================ */

.lexicon {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

@media (min-width: 600px) {
    .lexicon {
        grid-template-columns: repeat(2, 1fr);
    }
}

.lexicon-item {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    border-left: 3px solid var(--accent);
}

.lexicon-item dt {
    font-weight: 700;
    color: var(--text);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.lexicon-item dd {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin: 0;
    line-height: 1.5;
}

/* ============================================================
   Notes, exemples, formules
   ============================================================ */

.note {
    background: rgba(233, 69, 96, 0.07);
    border-left: 4px solid var(--accent);
    padding: 0.75rem 1rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    margin: 1rem 0;
}

.note strong {
    color: var(--accent);
}

.tip {
    background: rgba(107, 201, 107, 0.07);
    border-left: 4px solid var(--color-success);
    padding: 0.75rem 1rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    margin: 1rem 0;
}

.example {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.855rem;
    padding: 0.5rem 0.85rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius);
    margin: 0.5rem 0;
    display: block;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.formula {
    display: block;
    font-family: var(--font-body);
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin: 0.5rem 0;
}

.inline-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    font-size: 0.78em;
    font-weight: 700;
    white-space: nowrap;
}

/* ============================================================
   Bouton retour en haut
   ============================================================ */

.scroll-top-btn {
    position: fixed;
    bottom: 2rem;
    right: 1.5rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    border: none;
    border-bottom: 4px solid var(--accent-dark);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1.3rem;
    font-family: var(--font-body);
    line-height: 1;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    z-index: 150;
    box-shadow: var(--shadow);
}

.scroll-top-btn.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.scroll-top-btn:hover {
    filter: brightness(1.15);
}

.scroll-top-btn:active {
    transform: translateY(2px);
    border-bottom-width: 2px;
}

/* ============================================================
   Styles d'impression
   ============================================================ */

@media print {
    .site-nav,
    .rules-sidebar,
    .rules-toc-mobile,
    .read-progress-bar,
    .scroll-top-btn {
        display: none !important;
    }

    .rules-layout {
        display: block;
    }

    .rules-content {
        max-width: 100%;
    }

    .card-block,
    .cards-group,
    .rules-table {
        break-inside: avoid;
    }

    .malus-chart-wrap {
        break-inside: avoid;
        overflow: visible;
    }

    body {
        background: white !important;
        color: black !important;
    }

    a { color: inherit; }
}
