/* --- IMPORTATION DES POLICES --- */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@700;900&family=Lora:ital,wght@0,400;0,700;1,400&family=MedievalSharp&family=Fira+Code&display=swap');

/* --- VARIABLES --- */
:root {
    --bg-parchment: #FDF1DC;
    /* Couleur de repli si l'image ne charge pas */
    --color-ink: #1C1C1C;
    --color-red-dnd: #58180D;
    --color-gold: #C9AD6A;
    --font-header: 'Cinzel', serif;
    /* Ou 'MedievalSharp' pour un look plus fantasy */
    --font-body: 'Lora', serif;
    --font-code: 'Fira Code', monospace;

    /* Layout variables needed for sidebar */
    --sidebar-width: 280px;
    --sidebar-bg: #2b0f0a;
    /* Darkened variant of the red for sidebar background */
}

/* --- STYLE GÉNÉRAL --- */
* {
    box-sizing: border-box;
}

body {
    background-color: #1a1a1a;
    /* Background outside the page */
    color: var(--color-ink);
    font-family: var(--font-body);
    font-size: 14px;
    /* Demande utilisateur : max 14px */
    line-height: 1.6;
    /* Plus compact */
    margin: 0;
    padding: 0;
    display: flex;
    min-height: 100vh;
}

/* --- SIDE NAVIGATION --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid rgba(201, 173, 106, 0.3);
    /* Subtle gold border */
    padding: 1rem 0;
    /* Removing horizontal padding from container, handling in links */
    height: 100vh;
    overflow-y: auto;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.5);
    scrollbar-width: thin;
    scrollbar-color: var(--color-gold) var(--sidebar-bg);
}

/* Sidebar Header */
.sidebar h1 {
    font-family: var(--font-header);
    color: var(--color-gold);
    font-size: 1.4rem;
    /* Slightly smaller for elegance */
    margin: 0 0 1rem 0;
    text-align: center;
    border-bottom: 1px solid rgba(201, 173, 106, 0.2);
    padding-bottom: 1rem;
    padding-top: 0.5rem;
    letter-spacing: 1px;
}

.sidebar h1 a {
    transition: color 0.3s ease;
}

.sidebar h1 a:hover {
    color: #fff;
    text-shadow: 0 0 5px var(--color-gold);
}

/* Navigation List */
.nav-links {
    list-style: none;
    padding: 0;
    margin: 0;
    width: 100%;
}

.nav-links li {
    margin: 0;
    width: 100%;
}

/* Base Link Style */
.nav-links a {
    display: flex;
    /* Better alignment */
    align-items: center;
    padding: 6px 20px;
    /* Comfortable touch target but visually compact */
    color: #e6e6e6;
    /* Cleaner off-white than heavy parchment */
    text-decoration: none;
    border-left: 3px solid transparent;
    /* For hover effect */
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
    font-family: var(--font-body);
    line-height: 1.3;
    letter-spacing: 0.3px;
    opacity: 0.9;
}

/* Hover & Active States */
.nav-links a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #fff;
    padding-left: 24px;
    /* Slight movement effect */
    opacity: 1;
}

.nav-links a.active {
    background-color: rgba(201, 173, 106, 0.15);
    /* Low opacity Gold */
    color: var(--color-gold);
    border-left-color: var(--color-gold);
    font-weight: 600;
    opacity: 1;
}

/* Submenu Styling */
.submenu {
    background-color: rgba(0, 0, 0, 0.2);
    /* Darker inset */
    padding: 5px 0;
    margin: 0;
    box-shadow: inset 0 4px 6px rgba(0, 0, 0, 0.1);
}

.submenu li a {
    padding-left: 35px;
    /* Indent sub-items */
    font-size: 0.85rem;
    color: #ccc;
    border-left: 3px solid transparent;
    /* Consistency */
}

.submenu li a:hover {
    padding-left: 38px;
    color: var(--color-gold);
    background-color: rgba(255, 255, 255, 0.03);
}

.submenu li a.active {
    border-left-color: transparent;
    color: var(--color-gold);
    background-color: transparent;
}

/* Group Headers (Classes, Monsters, etc.) */
.nav-group-header {
    font-weight: 700;
    color: #f0e6d2;
    cursor: pointer;
    font-size: 0.95em;
    margin-top: 5px;
}

.nav-group-header:hover {
    color: var(--color-gold);
}


/* --- MAIN CONTENT AREA --- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    background-color: #111;
    /* Dark framing for the parchment page */
    padding: 40px;
    display: flex;
    justify-content: center;
}

/* --- MISE EN PAGE TYPE "LIVRE" --- */
.container {
    width: 100%;
    /* 
       "Web Best Practice" pour la longueur de ligne : 60-75 caractères.
       env. 40rem à 48rem, ou directement en unité 'ch'.
    */
    max-width: 46rem;
    /* margin: 0 auto; handled by flex in main-content */
    background: white;
    /* Pour simuler la page si le body est sombre */
    background-color: var(--bg-parchment);
    padding: 40px 60px;
    /* Padding réduit pour optimiser l'espace */
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.7);
    min-height: 90vh;

    /* SINGLE COLUMN AS REQUESTED */
    column-count: 1;
    /* column-gap: 1cm; */
    /* column-rule: 2px solid var(--color-gold); */

    position: relative;
}

/* Texture effect overlay using CSS pattern if image is missing */
.container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.6' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E");
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
}

.container>* {
    position: relative;
    z-index: 1;
}

/* Responsive : 1 colonne sur mobile */
@media (max-width: 900px) {
    .container {
        padding: 30px;
        max-width: 100%;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
    }

    .main-content {
        margin-left: 0;
        padding: 0;
        display: block;
    }

    body {
        display: block;
    }
}

/* --- TYPOGRAPHIE --- */
h1,
h2,
h3,
h4 {
    font-family: var(--font-header);
    color: var(--color-red-dnd);
    margin-top: 0;
    font-variant: small-caps;
    /* Petites capitales très D&D */
}

h1 {
    font-size: 2.5rem;
    border-bottom: 3px solid var(--color-gold);
    padding-bottom: 5px;
    margin-bottom: 40px;
    text-align: center;
}

h2 {
    font-size: 1.8rem;
    margin-top: 2rem;
    border-bottom: 1px solid var(--color-gold);
    padding-bottom: 5px;
}

h3 {
    font-size: 1.4rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--color-ink);
    font-weight: 700;

    /* Spell Header Style */
    font-family: var(--font-header);
    color: var(--color-ink);
    border-bottom: 1px solid #d3c4a9;
    padding-bottom: 0px;
    font-variant: small-caps;
}

/* Spell School/Level line (italicized by script) */
p em {
    font-family: var(--font-body);
    color: #444;
    font-style: italic;
    font-size: 0.95em;
}

/* Spell Metadata Labels (bolded by script) */
p strong {
    color: var(--color-red-dnd);
    font-weight: 700;
}

/* Ensure standard paragraphs below headers have small margin if they are metadata */
h3+p {
    margin-top: 0.2rem;
}

/* La lettrine (Drop Cap) - La première lettre du paragraphe en gros */
/* We will need to add class="intro" to the first paragraph in generation or manually */
/* Or use :first-of-type for generic pages? */
/* Let's try to target the first p after h1 */
h1+p::first-letter {
    font-family: var(--font-header);
    font-size: 3.5rem;
    float: left;
    line-height: 0.8;
    margin-right: 0.1em;
    color: var(--color-red-dnd);
}

/* --- COMPOSANTS SPÉCIFIQUES --- */

/* Hero Image */
.hero-image {
    width: 100%;
    max-height: 500px;
    object-fit: cover;
    border: 2px solid var(--color-gold);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    margin-bottom: 2rem;
}

/* Global Responsive Images */
img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1rem 0;
}

/* COMPOSANT : BOÎTE DE DESCRIPTION (Lue par le MJ) */
.dm-box,
blockquote {
    background-color: #E0E5C1;
    /* Vert/Gris pâle */
    padding: 15px;
    border: 1px solid #7D8067;
    margin-bottom: 1.5em;
    font-style: italic;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
    break-inside: avoid;
    font-family: var(--font-body);
}

/* COMPOSANT : BLOC DE STATISTIQUES (Monster Stat Block) */
.stat-block,
.feature-box {
    background-color: #FDF1DC;
    border: 2px solid var(--color-gold);
    border-top: 6px solid var(--color-gold);
    border-bottom: 6px solid var(--color-gold);
    padding: 15px;
    margin: 20px 0;
    font-family: sans-serif;
    font-size: 0.9rem;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    break-inside: avoid;
}

.stat-block h3,
.feature-box h3 {
    color: var(--color-red-dnd);
    font-family: var(--font-header);
    border-bottom: 2px solid var(--color-red-dnd);
    margin-bottom: 5px;
}

/* TABLEAUX LOOK D&D */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 2rem 0;
    border: 1px solid var(--color-gold);
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-body);
    font-size: 0.8rem;
    background-color: var(--bg-parchment);
    border: none;
    margin: 0;
}

/* Scrollbar styling for tables */
table::-webkit-scrollbar {
    height: 8px;
}

table::-webkit-scrollbar-track {
    background: #2b0f0a;
}

table::-webkit-scrollbar-thumb {
    background: var(--color-gold);
    border-radius: 4px;
}

th {
    background-color: var(--color-red-dnd);
    color: var(--bg-parchment);
    font-family: var(--font-header);
    font-weight: 700;
    font-size: 0.7rem;
    /* Font plus petite pour les entêtes */
    line-height: 1.2;
    padding: 0.5rem 0.5rem;
    /* Padding réduit */
    text-align: left;
    text-transform: uppercase;
    border-bottom: 2px solid var(--color-gold);
}

td {
    padding: 0.4rem 0.5rem;
    /* Padding réduit */
    border-bottom: 1px solid rgba(88, 24, 13, 0.2);
}

tr:nth-child(even) {
    background-color: rgba(88, 24, 13, 0.05);
    /* Very light red tint */
}

/* CODE */
pre {
    background: #111;
    color: #f0f0f0;
    padding: 1rem;
    border-radius: 4px;
    overflow-x: auto;
    font-family: var(--font-code);
}

/* --- MONSTER STAT BLOCK (D&D 5E STYLE) --- */
.monster-stat-block {
    background-color: #fdf1dc;
    border: 1px solid #d4c6a8;
    padding: 1em;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 2em;
    break-inside: avoid;
    font-family: 'Noto Sans', sans-serif;
    font-size: 1em;
    /* Explicit request from user */
    line-height: 1.4;
    color: #1a1a1a;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: block;
    position: relative;
    /* Removed background-image to reduce visual noise and loading issues */
}

.monster-stat-block h3 {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    color: #58180D;
    margin: 0 0 5px 0;
    font-size: 24px;
    border-bottom: none;
    letter-spacing: 1px;
}

.monster-stat-block .type-line {
    font-style: italic;
    color: #333;
    margin-bottom: 0.5em;
    font-size: 0.9em;
}

.monster-tapered-line {
    display: block;
    height: 0.4em;
    height: 2px;
    background: linear-gradient(to right, transparent, #c0392b, transparent);
    margin: 0.5em 0;
}

.monster-stat-block p {
    margin: 0.2em 0;
    font-size: 14px;
    /* Ensure inheritance issues don't shrink it */
}

.monster-stat-block strong {
    font-weight: bold;
    color: #58180D;
}

/* Abilities Grid (For, Dex, Con...) */
.abilities-block {
    display: flex;
    flex-wrap: wrap;
    /* Allow wrapping to prevent overflow */
    justify-content: space-around;
    text-align: center;
    margin: 0.5em 0;
    gap: 5px;
}

.ability-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 1.1em;
    /* Slightly larger than base 14px */
    min-width: 50px;
}

.ability-score strong {
    font-family: var(--font-header);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 1.1em;
    color: #922610;
    /* D&D Red for headers */
    margin-bottom: 0.2em;
}

.ability-score span {
    font-size: 1.2em;
    /* Slightly larger for readability */
    color: #58180D;
}

/* Section Headers (Actions, Traits...) */
.monster-section-title {
    font-family: var(--font-header);
    color: #922610;
    border-bottom: 1px solid #922610;
    font-size: 1.3em;
    margin-top: 1em;
    margin-bottom: 0.5em;
    padding-bottom: 0.2em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-variant: small-caps;
    display: inline-block;
    width: 100%;
}

.monster-action {
    margin-bottom: 8px;
    line-height: 1.5;
}

.monster-action-name {
    font-family: 'Noto Sans', sans-serif;
    font-weight: 700;
    /* Bold */
    font-style: italic;
    /* Start with italic like D&D */
    color: #4a1913;
    margin-right: 5px;
    text-transform: none;
    font-variant: normal;
}

/* --- MONSTER SEARCH --- */
.monster-search-container {
    padding: 20px;
    text-align: center;
    background-color: var(--bg-parchment);
    border: 1px solid var(--color-gold);
    margin-bottom: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.monster-search-container input {
    width: 100%;
    max-width: 400px;
    padding: 12px;
    font-size: 1.1rem;
    border: 2px solid var(--color-gold);
    border-radius: 4px;
    background-color: #fffaf0;
    font-family: var(--font-body);
    color: var(--color-ink);
    outline: none;
    transition: all 0.3s ease;
}

.monster-search-container input:focus {
    border-color: var(--color-red-dnd);
    box-shadow: 0 0 8px rgba(146, 38, 16, 0.3);
}

/* --- SPELL BLOCK --- */
.spell-block {
    background-color: #FAFAFA;
    /* Very light grey/white */
    border: 1px solid #d3c4a9;
    border: 1px solid #d3c4a9;
    /* Matching spell header underline */
    padding: 10px 15px;
    margin: 15px 0;
    font-size: 0.9em;
    /* Increase legibility while keeping it compact */
    line-height: 1.5;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    break-inside: avoid;
    page-break-inside: avoid;
    width: 100%;
}

.spell-block p {
    margin: 0.3em 0;
    text-align: justify;
    /* Optional: justify text to fill width */
}

.spell-block h3 {
    margin-top: 0;
    font-size: 1.3rem;
    /* Relative to spell block font size? No, rem is root. */
    border-bottom: 2px solid var(--color-gold);
    color: var(--color-red-dnd);
}

.spell-block p {
    margin: 0.5em 0;
}

.spell-block em {
    color: #555;
    font-size: 0.9em;
}

.spell-block strong {
    color: var(--color-red-dnd);
}

/* --- MONSTER STAT BLOCK (D&D 5E Style) --- */


/* Header (Name) */
h3[id] {
    scroll-margin-top: 80px;
    /* Sticky nav offset */
}

/* Responsive Columns for Stat Block */
@media (min-width: 900px) {
    /* Removed column-count for monster-stat-block to fix text wrapping issue */
    /* Only keeping it for specific lists if needed, but user requested full width text */
}

.monster-toc {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.5rem;
    background-color: rgba(253, 241, 220, 0.5);
    border: 1px solid var(--color-gold);
    border-radius: 4px;
    margin-bottom: 2rem;
}

.monster-toc a {
    color: #58180D;
    font-family: var(--font-header);
    font-weight: 700;
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    transition: all 0.2s ease;
    background: transparent;
    border: none;
    box-shadow: none;
}

.monster-toc a:hover {
    color: #fff;
    background-color: #922610;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#backToTop {
    display: none;
    /* Hidden by default */
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--color-red-dnd);
    color: var(--color-gold);
    padding: 10px 15px;
    border-radius: 5px;
    text-decoration: none;
    font-family: var(--font-header);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    opacity: 0.8;
    transition: opacity 0.3s;
    cursor: pointer;
    /* Interaction */
    border: 1px solid var(--color-gold);
    /* Consistent border */
    font-size: 1.2rem;
}

#backToTop:hover {
    opacity: 1;
}

.monster-lore {
    font-family: var(--font-body);
    font-style: italic;
    margin-bottom: 20px;
    padding: 15px;
    /* border-left: 2px solid var(--color-gold); Remove border for cleaner look */
    /* background-color: rgba(255, 255, 255, 0.4); Remove white bg */
    font-size: 1.1rem;
    color: #4a4a4a;
    /* Dark grey for readability */
    line-height: 1.6;
}

@media (max-width: 600px) {
    .monster-toc {
        flex-direction: column;
        align-items: center;
    }
}

/* --- PRINT & PAGE BREAKS --- */
.page-break {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0;
    border-top: 1px dashed #ccc;
    height: 20px;
    color: #888;
    font-size: 0.8rem;
}

.page-break::after {
    content: "";
    display: none;
}

@media print {
    .page-break {
        display: block;
        page-break-before: always;
        break-before: page;
        border: none;
        margin: 0;
        height: 0;
    }

    .page-break::after {
        content: "";
        display: none;
    }

    .no-print {
        display: none !important;
    }

    .sidebar,
    .monster-search-container {
        display: none !important;
    }

    .main-content {
        margin: 0;
        padding: 0;
    }

    .container {
        box-shadow: none;
        max-width: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
    }

    body {
        background-color: white;
    }
}