:root {
    --bg-color: #1e1e1e;
    /* Slightly adjusted for a classic dark theme feel */
    --section-bg: #2a2a2a;
    --section-bg-open: #3c3c3c;
    --text-color: #d4d4d4;
    --header-color: #569cd6;
    --link-color: #9cdcfe;
    --border-color: #444;
    --focus-ring-color: #007acc;
    --code-bg: #1a1a1a;
    --tag-easy-bg: #38761d;
    --tag-moderate-bg: #e6cc38;
    --tag-advanced-bg: #a7690d;
    --tag-complex-bg: #cc0000;
}

/* --- 1. Global & Typographic Refinements --- */
html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.7;
    margin: 0;
    padding: 1rem;
    background-color: var(--bg-color);
    color: var(--text-color);
    text-wrap: pretty;
    /* Progressive enhancement for better text wrapping */
}

main {
    max-width: 900px;
    margin: 2rem auto;
}

/* --- Enhanced, Fluid Headlines --- */
h1,
h2,
h3,
h4 {
    color: var(--header-color);
    font-weight: 600;
    line-height: 1.2;
    /* Adjust line-height for larger text */
    text-wrap: balance;
    /* A nice touch for multi-line headlines */
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
    border-image: linear-gradient(to right, var(--header-color), var(--border-color)) 1;
}

/* clamp(MIN, PREFERRED, MAX) MIN: Smallest font size on mobile. PREFERRED: A calculation based on viewport width (vw)
   for fluid scaling. MAX: Largest font size on desktop. */
h1 {
    font-size: clamp(2rem, 1.5rem + 2.5vw, 3.5rem);
}

h2 {
    font-size: clamp(1.75rem, 1.25rem + 2vw, 2.75rem);
}

h3 {
    font-size: clamp(1.5rem, 1.1rem + 1.5vw, 2.25rem);
}

h4 {
    font-size: clamp(1.25rem, 1rem + 1vw, 1.75rem);
}

a {
    color: var(--link-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: white;
    text-decoration: underline;
}

/* Enhanced focus state for accessibility */
:is(a, button, summary, input, select):focus-visible {
    outline: 2px solid var(--focus-ring-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* --- 2. Code Blocks and Inline Code --- */
/* Inline code */
:not(pre)>code {
    background-color: var(--code-bg);
    color: #ce9178;
    /* A common color for literals in dark themes */
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.875em;
    border: 1px solid var(--border-color);
}

/* Code blocks */
pre {
    background-color: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    /* Allow horizontal scrolling for long lines */
    font-size: 0.9em;
    line-height: 1.5;
}

pre code {
    background-color: transparent;
    padding: 0;
    border: none;
}

/* --- 3. Styled Form Elements (for Filters & Inputs) --- */
input[type="text"],
input[type="search"],
select {
    background-color: var(--code-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    /* Make inputs responsive by default */
    box-sizing: border-box;
    /* Include padding and border in the element's total width */
}

input[type="text"]:focus,
input[type="search"]:focus,
select:focus {
    border-color: var(--focus-ring-color);
    box-shadow: 0 0 0 2px rgba(0, 122, 204, 0.3);
    outline: none;
}

/* Custom dropdown arrow to match dark theme */
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml, %3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23d4d4d4' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1em;
}

/* --- 4. Enhanced Table Styles (Base for DataTables) --- */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
}

th,
td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

thead th {
    background-color: var(--section-bg);
    color: var(--header-color);
    font-weight: 600;
    border-bottom-width: 2px;
}

tbody tr:nth-child(odd) {
    background-color: var(--section-bg);
}

tbody tr:hover {
    background-color: var(--section-bg-open);
}

/* --- 5. Blockquotes & Details Refinements --- */
blockquote {
    margin: 1.5rem 0;
    padding: 0.5rem 1.5rem;
    border-left: 4px solid var(--header-color);
    background-color: var(--section-bg);
    color: #ccc;
    font-style: italic;
}

blockquote p {
    margin: 0;
}

/* --- Faction Grid & Cards (Your original styles with minor polish) --- */
.faction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    list-style: none;
    padding: 0;
}

.faction-icon {
    height: 1.2em;
    margin-right: 0.25em;
    vertical-align: middle;
    border-radius: 8px
}

.faction-card {
    display: block;
    background-color: var(--section-bg);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

.faction-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    border-color: var(--link-color);
    text-decoration: none;
}

.faction-card h3 {
    margin-top: 0;
    color: var(--header-color);
    border: none;
}

/* --- Accordion-Style Details List --- */
.faction-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.faction-card-details {
    background-color: var(--section-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.faction-card-details[open] {
    background-color: var(--section-bg-open);
}

.faction-card-details summary {
    cursor: pointer;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    list-style: none;
}

.faction-card-details summary::-webkit-details-marker {
    display: none;
}

.faction-card-details h3 {
    margin: 0;
    border: none;
    padding: 0;
}

.faction-complexity {
    font-size: 0.8em;
    font-weight: bold;
    padding: 0.25em 0.75em;
    border-radius: 1em;
    text-transform: uppercase;
    color: #fff;
}

.faction-complexity[data-complexity*="straightforward"] {
    background-color: var(--tag-easy-bg);
}

.faction-complexity[data-complexity*="moderate"] {
    background-color: var(--tag-moderate-bg);
    color: #1a1a1a;
}

.faction-complexity[data-complexity*="advanced"] {
    background-color: var(--tag-advanced-bg);
}

.faction-complexity[data-complexity*="complex"] {
    background-color: var(--tag-complex-bg);
}

.faction-card-details summary::after {
    content: '+';
    font-size: 1.5em;
    font-weight: 300;
    line-height: 1;
    color: var(--link-color);
    margin-left: 1rem;
    transition: transform 0.2s ease-in-out;
}

.faction-card-details[open]>summary::after {
    content: '\2212';
    /* Unicode minus sign */
    transform: rotate(180deg);
}

.faction-card-details .faction-content {
    padding: 0 1.5rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* --- Styles for Individual Faction Pages --- */
.faction-detail .pitch {
    background-color: var(--section-bg-open);
    padding: 1rem 1.5rem;
    border-left: 4px solid var(--link-color);
    border-radius: 5px;
    margin: 2rem 0;
    font-style: italic;
}

.faction-sheet-display-image {
    width: 100%;
    /* Adjust this to your desired display size */
    max-width: 400px;
    height: auto;
    /* Important: Maintains aspect ratio */
    display: block;
    /* Helps with layout */
    border: 1px solid #ddd;
    /* Optional: Adds a border */
    border-radius: 4px;
    /* Optional: Rounds corners */
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
    /* Optional: Adds a subtle shadow */
    transition: transform 0.2s ease-in-out;
    /* Optional: Smooth hover effect */
}

.faction-sheet-display-image:hover {
    transform: scale(1.05);
    /* Optional: Slightly enlarge on hover */
    cursor: pointer;
    /* Indicates it's clickable */
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.back-link {
    display: inline-block;
    margin-top: 2rem;
    font-weight: bold;
}

/* --- 6. Thematic Scrollbar (Progressive Enhancement) --- */
::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    background: var(--code-bg);
}

::-webkit-scrollbar-thumb {
    background-color: #555;
    border-radius: 10px;
    border: 3px solid var(--code-bg);
}

::-webkit-scrollbar-thumb:hover {
    background-color: #777;
}

/* --- 7. Site Header & Navigation --- */
.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.site-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    text-decoration: none;
}

.site-title:hover {
    color: white;
    text-decoration: none;
}

/* Base styles for the navigation list */
.site-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    gap: 1.5rem;
    /* Spacing between top-level items */
}

.site-nav li {
    position: relative;
    /* For dropdown positioning */
}

.site-nav a {
    display: block;
    padding: 0.5rem 0;
    font-weight: 500;
    color: var(--text-color);
    transition: color 0.2s ease;
}

.site-nav a:hover,
.site-nav li.active>a {
    /* Style for hover and the active page */
    color: var(--link-color);
    text-decoration: none;
}

/* --- Dropdown Menu Styles --- */
.site-nav ul ul {
    display: none;
    /* Hide dropdowns by default */
    position: absolute;
    top: 100%;
    right: 0;
    background-color: var(--section-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem;
    min-width: 200px;
    z-index: 100;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.site-nav li:hover>ul {
    display: block;
    /* Show dropdown on hover */
}

.site-nav ul ul li {
    width: 100%;
}

.site-nav ul ul a {
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

/* --- Mobile Navigation ("Hamburger" Menu) --- */
.nav-toggle {
    display: none;
    /* Hidden on desktop */
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
}

.nav-toggle .icon-bar {
    display: block;
    width: 25px;
    height: 3px;
    background-color: var(--text-color);
    margin: 5px 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Media query for mobile screens */
@media(max-width: 768px) {
    .site-nav {
        position: absolute;
        top: 75px;
        /* Adjust based on your header height */
        right: 0;
        background-color: var(--section-bg);
        width: 100%;
        max-width: 300px;
        transform: translateX(100%);
        transition: transform 0.3s ease-in-out;
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.2);
        border-left: 1px solid var(--border-color);
        border-bottom: 1px solid var(--border-color);
        border-bottom-left-radius: 8px;
    }

    /* When the menu is open */
    .site-nav[data-visible="true"] {
        transform: translateX(0);
    }

    .site-nav ul {
        flex-direction: column;
        gap: 0;
        padding: 1rem;
    }

    /* On mobile, dropdowns are always visible within the main list */
    .site-nav ul ul {
        display: block;
        position: static;
        background: none;
        border: none;
        box-shadow: none;
        padding-left: 1rem;
        /* Indent sub-menu items */
        min-width: auto;
    }

    .nav-toggle {
        display: block;
        /* Show the hamburger icon */
    }

    /* Animate hamburger to an 'X' */
    .nav-toggle[aria-expanded="true"] .icon-bar:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }

    .nav-toggle[aria-expanded="true"] .icon-bar:nth-child(2) {
        opacity: 0;
    }

    .nav-toggle[aria-expanded="true"] .icon-bar:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
    }

    /* --- 9. Living Rules Reference Page --- */
    .toc-link {
        display: block;
        padding: 0.75rem 1rem;
        background-color: var(--section-bg);
        border: 1px solid var(--border-color);
        border-radius: 6px;
        text-decoration: none;
        transition: background-color 0.2s ease, transform 0.2s ease;
    }

    .toc-link:hover {
        background-color: var(--section-bg-open);
        transform: translateY(-2px);
        text-decoration: none;
    }

    .glossary-entry {
        scroll-margin-top: 2rem;
        /* Adds space above when jumping from the ToC */
    }

    .glossary-entry h2 {
        border-image: linear-gradient(to right, var(--link-color), var(--border-color)) 1;
    }

    .entry-description {
        background-color: var(--code-bg);
        border-left: 4px solid var(--border-color);
        padding: 0.1rem 1.5rem;
        margin-bottom: 1.5rem;
    }

    .rule {
        padding: 0.5rem 0;
    }

    .rule-number {
        display: inline-block;
        background-color: var(--section-bg);
        padding: 0.1em 0.5em;
        margin-right: 0.75em;
        border: 1px solid var(--border-color);
        border-radius: 4px;
        font-size: 0.9em;
        color: var(--link-color);
    }

    .sub-rule-list,
    .sub-step-list {
        margin-top: 0.75rem;
        padding-left: 3rem;
        color: #bbb;
    }

    .sub-section {
        margin-top: 2rem;
        padding: 1.5rem;
        background-color: var(--section-bg);
        border-radius: 8px;
    }

    .sub-section h3 {
        margin-top: 0;
        border: none;
        padding-bottom: 0.75rem;
        border-bottom: 2px solid var(--border-color);
    }

    .steps-list {
        padding-left: 1.5rem;
    }

    .steps-list li {
        margin-bottom: 1rem;
    }

    .related-topics {
        margin-top: 2rem;
        padding-top: 1rem;
        border-top: 1px dashed var(--border-color);
        font-size: 0.9em;
        color: #aaa;
    }

    .sr-only {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

/* --- Subtitle Styling --- */
.subtitle {
  font-size: clamp(1.1rem, 1rem + 0.5vw, 1.3rem); /* Fluid size, slightly larger than body text */
  font-style: italic;
  font-weight: 400; /* Normal font weight */
  color: var(--text-color);
  opacity: 0.85; /* Muted color to sit below the main header */
  line-height: 1.4;
  text-align: left;
  margin-top: -0.75rem; /* Pulls the subtitle closer to the H2 above it */
  margin-bottom: 2rem; /* Adds space before the body content below it */
  max-width: 85%; /* Slightly narrower for a classic subtitle look */
  text-wrap: pretty;
}

/* --- Quick Reference Page Styles --- */

.grid-column {
    /* This class is used within .details-grid to create columns */
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.icon-text {
    /* Styles the [Icon: ...] placeholders */
    background-color: var(--code-bg);
    color: #ce9178;
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-size: 0.8em;
    font-style: normal;
    font-family: monospace;
    border: 1px solid var(--border-color);
}

/* --- 10. FAQ Page Styles --- */

.faq-category {
    margin-bottom: 3rem;
}

.faq-item {
    background-color: var(--section-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1rem;
    transition: background-color 0.2s ease;
}

/* Style for when the details element is open */
.faq-item[open] {
    background-color: var(--section-bg-open);
}

.faq-item[open] summary {
    border-bottom: 1px solid var(--border-color);
}

.faq-item summary {
    cursor: pointer;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    list-style: none; /* Hide the default triangle marker */
}

/* Hide the default marker in WebKit browsers */
.faq-item summary::-webkit-details-marker {
    display: none;
}

/* Custom open/close icon */
.faq-icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-left: 1rem;
    flex-shrink: 0;
    transition: transform 0.2s ease-in-out;
}
.faq-icon::before {
    content: '+';
    font-size: 1.5em;
    font-weight: 300;
    line-height: 0.8;
    color: var(--link-color);
}

.faq-item[open] .faq-icon {
    transform: rotate(45deg);
}

.faq-answer {
    padding: 0.5rem 1.5rem 1.5rem;
    color: var(--text-color);
    opacity: 0.9;
    line-height: 1.7;
}

.faq-answer p:first-child {
    margin-top: 0;
}
