/* =========================================
   1. GRUNDLAGEN (THEMES & VARIABLEN)
   ========================================= */
:root {
    /* --- DARK MODE (STANDARD) --- */
    --bg-primary: #000000;
    --bg-secondary: #121212;
    --text-primary: #f0f0f0;
    --text-secondary: #a0a0a0;
    --accent-primary: #3b82f6;
    --accent-secondary: #f59e0b;
    --border-color: #2d2d2d;
    --bg-table-header: #1f1f1f;
    --bg-table-cell: #121212;
    --bg-module-row: rgba(59, 130, 246, 0.1);
    --text-module-row: var(--accent-primary);
    
    /* WICHTIG: VARIABLEN FÜR DAS MENÜ (TOC) */
    --toc-width-collapsed: 4rem;
    --toc-width-expanded: 20rem;
}

body.light-mode {
    /* --- LIGHT MODE (SHOJI PAPIER) --- */
    --bg-primary: #fbf9f1;
    --bg-secondary: #f0ebe0;
    
    /* Textur */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.06'/%3E%3C/svg%3E");

    /* Farben */
    --text-primary: #231810;
    --text-secondary: #5d4037;
    --border-color: #3e2723;
    --accent-primary: #1a237e;
    --accent-secondary: #bf360c;
    
    /* Tabellen */
    --bg-table-header: #e6e0d4;
    --bg-table-cell: #fbf9f1;
    --bg-module-row: rgba(26, 35, 126, 0.08);
    --text-module-row: var(--accent-primary);
}

/* =========================================
   2. LAYOUT & BASIS
   ========================================= */
body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary); /* Hier greift Dark Mode! */
    color: var(--text-secondary);
    line-height: 1.7;
    font-size: clamp(1.0rem, 2.3vw, 1.125rem);
    padding-top: 4rem;
    -webkit-font-smoothing: antialiased;
}

.page-container { display: none; }
.page-container.active { 
    display: block; 
    animation: softFade 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

h1, h2, h3, h4, h5 {
    font-family: 'Inter', sans-serif;
    color: var(--text-primary);
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
    margin-bottom: 1.5rem;
    margin-top: 3rem;
    scroll-margin-top: 5rem;
    line-height: 1.3;
}

/* Schriftgrößen */
h1 { font-size: clamp(2.5rem, 6vw, 3rem); border-bottom: none; }
h2 { font-size: clamp(2rem, 5vw, 2.5rem); }
h3 { font-size: clamp(1.5rem, 4vw, 2rem); }
h4 { font-size: clamp(1.2rem, 3vw, 1.5rem); }
h5 { font-size: clamp(1.1rem, 3vw, 1.25rem); }

.rule-number { color: var(--accent-secondary); font-weight: 600; margin-right: 0.75rem; }

/* Links */
a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px dotted rgba(59, 130, 246, 0.5);
    transition: color 0.2s, border-color 0.2s;
}
body.light-mode a { border-bottom-color: rgba(26, 35, 126, 0.3); }
a:hover { color: var(--text-primary); border-bottom-color: var(--text-primary); }

/* =========================================
   3. NAVIGATION & TOC (REPARATUR!)
   ========================================= */
/* Der Container für das Menü */
#toc-container { 
    width: var(--toc-width-collapsed); 
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1); /* Die Animation */
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
}

/* Wenn ausgeklappt */
#toc-container.is-expanded { 
    width: var(--toc-width-expanded); 
}

/* Der vertikale Text (nur wenn eingeklappt sichtbar) */
#toc-container:not(.is-expanded) #toc-title {
    writing-mode: vertical-rl;
    text-align: center;
    opacity: 1 !important;
    margin: 0;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%) rotate(180deg);
    white-space: nowrap;
    font-size: 1.5rem;
    color: var(--text-primary);
    cursor: pointer;
}

/* Der Pin-Button (Muss sichtbar sein!) */
#toc-container button {
    background-color: var(--bg-table-header);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}
#toc-container button:hover {
    background-color: var(--accent-primary);
    color: white;
}

#app-wrapper { transition: padding-left 0.3s ease-in-out; }

/* Navbar Oben */
#top-nav {
    position: fixed; top: 0; left: 0; right: 0; height: 4rem;
    background-color: rgba(17, 17, 17, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    display: flex; align-items: center; justify-content: space-between; padding: 0 1rem;
    transition: transform 0.3s ease-in-out;
}
body.light-mode #top-nav { background-color: rgba(251, 249, 241, 0.9); }
#top-nav.top-nav--hidden { transform: translateY(-100%); }

.nav-link {
    display: flex; align-items: center; height: 100%; padding: 0 1.25rem;
    font-family: 'Lora', serif; font-size: 1.1rem; color: var(--text-secondary);
    border-bottom: 2px solid transparent; transition: all 0.3s ease;
}
.nav-link.active { color: var(--accent-secondary); border-bottom-color: var(--accent-secondary); }

.toc-link.active { background-color: var(--accent-primary) !important; color: white !important; }
.toc-link.active .rule-number { color: white !important; }

/* =========================================
   4. ELEMENTE (CARDS, TABELLEN)
   ========================================= */
blockquote {
    background-color: var(--bg-secondary);
    border-left: 4px solid var(--accent-primary);
    padding: 1.5rem;
    margin: 2rem 0;
    font-style: italic;
    border-radius: 0 8px 8px 0;
}

.info-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem 2rem;
    margin-top: 2rem;
}

/* Shoji-Rahmen im Light Mode (außer für dunkle Karten) */
body.light-mode .info-card:not(.bg-gray-900):not(.bg-gray-800) {
    border: 3px solid var(--border-color);
    box-shadow: 4px 4px 0px rgba(62, 39, 35, 0.1);
    background-color: #fdfcf8;
    border-radius: 4px;
}

/* NOTFALL-REGEL: Dunkle Boxen müssen immer dunkel bleiben (Update Log, etc.) */
.info-card.bg-gray-900, .info-card.bg-gray-800 {
    background-color: #1f2937 !important;
    border: 1px solid #374151 !important;
    box-shadow: none !important;
    color: #ffffff !important;
}
.info-card.bg-gray-900 *, .info-card.bg-gray-800 * {
    color: #ffffff !important;
    --text-primary: #ffffff !important;
    --text-secondary: #d1d5db !important;
    border-bottom-color: rgba(255, 255, 255, 0.3) !important;
}

/* Tabellen */
.table-responsive-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin: 2.5rem 0;
}
table { width: 100%; border-collapse: collapse; margin: 0; }
th, td { border-bottom: 1px solid var(--border-color); padding: 1rem; text-align: left; }
th { background-color: var(--bg-table-header); color: var(--text-primary); font-weight: 600; }
td { background-color: var(--bg-table-cell); }

/* Trennlinien */
.section-divider {
    height: 1px; background-color: var(--border-color); border: 0; margin: 5rem 0; text-align: center;
}
body.light-mode .section-divider { height: 2px; opacity: 0.7; }
.section-divider::after {
    content: '⚔️'; display: inline-block; position: relative; top: -1.1rem;
    font-size: 1.5rem; padding: 0 1rem; background: var(--bg-primary); color: var(--text-secondary);
}

/* Formulare */
.form-input, .form-textarea {
    background-color: var(--bg-secondary); border: 1px solid var(--border-color);
    color: var(--text-primary); width: 100%; border-radius: 8px; padding: 0.75rem 1rem;
}
.form-button {
    background-color: var(--accent-secondary); color: #111; font-weight: bold;
    padding: 0.75rem 1.5rem; border-radius: 8px; border: none; cursor: pointer;
}

/* Back to Top */
#back-to-top {
    position: fixed; bottom: 2rem; right: 2rem;
    background-color: rgba(26, 26, 26, 0.7); color: var(--text-primary);
    border: 1px solid var(--border-color); border-radius: 50%; width: 3rem; height: 3rem;
    display: none; align-items: center; justify-content: center; cursor: pointer; z-index: 50;
}
body.light-mode #back-to-top { background-color: rgba(255, 255, 255, 0.7); color: #000; }

#theme-toggle { color: var(--text-primary); }
.theme-icon { width: 1.5rem; height: 1.5rem; }

/* =========================================
   5. MOBILE & LAYOUTS
   ========================================= */
@media (max-width: 1024px) {
    #back-to-top { bottom: 5rem; }
    .rules-layout { flex-direction: column; gap: 0; }
    .context-column { width: 100%; margin-top: 1.5rem; }
    .context-card { position: static; border-left: 1px solid var(--border-color); }
    #mobile-sticky-header {
        position: fixed; top: 4rem; left: 0; right: 0;
        background-color: rgba(26, 26, 26, 0.9);
        color: var(--text-primary); padding: 0.5rem 1rem; text-align: center; z-index: 40;
        border-bottom: 1px solid var(--border-color); font-family: 'Lora', serif;
        transition: transform 0.3s ease; transform: translateY(-100%);
    }
    body.light-mode #mobile-sticky-header { background-color: rgba(255, 255, 255, 0.9); }
    #mobile-sticky-header.visible { transform: translateY(0); }
    #bottom-nav {
        position: fixed; bottom: 0; left: 0; right: 0; height: 3.5rem;
        background-color: rgba(17, 17, 17, 0.8); border-top: 1px solid var(--border-color);
        z-index: 50; display: flex; justify-content: flex-start; align-items: center; overflow-x: auto;
    }
    body.light-mode #bottom-nav { background-color: rgba(248, 249, 250, 0.8); }
    #mobile-toc-panel { z-index: 110; overscroll-behavior: contain; padding-bottom: 6rem; }
}

.rules-layout { display: flex; flex-direction: row; gap: 2rem; }
.rules-column { flex: 1; min-width: 0; }
.context-column { width: 320px; flex-shrink: 0; }
.context-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--accent-secondary);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    position: sticky; top: 5rem;
}
.context-card h5 {
    border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; margin-bottom: 1rem; font-size: 1.1rem;
}

/* Tooltips */
.tooltip { position: relative; border-bottom: 1px dotted var(--accent-primary); cursor: help; }
.tooltip:hover:before { visibility: visible; opacity: 1; }

.js-hidden { display: none !important; }

/* Animationen */
@keyframes softFade {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
p, li { transition: color 0.3s ease; }
p:hover, li:hover { color: var(--text-primary); cursor: default; }