/* =========================================
   CUSTOM SCROLLBARS (Dark Theme)
   ========================================= */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-color); }
::-webkit-scrollbar-thumb { background: #333; border-radius: 5px; border: 2px solid var(--bg-color); }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* =========================================
   CORE VARIABLES & TYPOGRAPHY
   ========================================= */
:root { 
    --bg-color: #0a0a0c; 
    --panel-bg: #16161a; 
    --text-main: #e0e0e0; 
    --text-dim: #888; 
    --accent-gold: #d4af37; 
    --accent-red: #c93b3b; 
    --accent-blue: #4a90e2; 
    --border-color: #333; 
}

body { 
    margin: 0; padding: 0; 
    background-color: var(--bg-color); color: var(--text-main); 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    display: flex; height: 100vh; overflow: hidden; 
}

h1, h2, h3, h4 { margin: 0 0 10px 0; font-weight: normal; }
p { line-height: 1.5; color: var(--text-dim); }

/* =========================================
   LAYOUT STRUCTURE & NAVIGATION
   ========================================= */
#sidebar { 
    width: 340px; background-color: var(--panel-bg); 
    border-right: 1px solid var(--border-color); 
    padding: 20px; display: flex; flex-direction: column; 
    gap: 15px; overflow-y: auto; z-index: 10;
}

#main-area { 
    flex-grow: 1; display: flex; flex-direction: column; position: relative; 
}

.top-nav { 
    display: flex; background: var(--panel-bg); border-bottom: 1px solid var(--border-color); 
}

.nav-tab { 
    padding: 15px 30px; cursor: pointer; font-weight: bold; 
    text-transform: uppercase; color: var(--text-dim); 
    border-bottom: 3px solid transparent; transition: all 0.2s; 
}

.nav-tab:hover { color: var(--text-main); }
.nav-tab.active { color: var(--accent-gold); border-bottom-color: var(--accent-gold); }

/* =========================================
   VIEW PANELS
   ========================================= */
#view-container { 
    flex-grow: 1; overflow-y: auto; scroll-behavior: smooth; 
    position: relative; width: 100%;
}

.view-panel { 
    display: none; animation: fadeIn 0.3s; height: 100%; box-sizing: border-box;
}

#view-loom, #view-guide {
    padding: 40px; overflow-y: auto; max-width: 1200px; margin: 0 auto;
}

.active-view { display: block; }

/* =========================================
   SIDEBAR UI (Stats & Radar)
   ========================================= */
.loom-header { 
    text-align: center; padding-bottom: 15px; border-bottom: 1px solid var(--border-color); 
}

.loom-header h1 { 
    color: var(--accent-gold); letter-spacing: 2px; 
    text-transform: uppercase; font-size: 1.5em; margin-bottom: 5px;
}

.nudge-count { font-size: 1.2em; font-weight: bold; color: var(--accent-blue); }

.stat-row { 
    display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.85em; 
}
.stat-value { font-family: monospace; font-size: 1.1em; transition: color 0.3s; }
.pop-value { color: #b8e986; font-weight: bold; font-size: 1.2em; }

.stat-bar-container { 
    width: 100%; height: 4px; background: #222; 
    border-radius: 2px; overflow: hidden; margin-bottom: 18px; position: relative;
}

.stat-bar { height: 100%; background: var(--text-dim); transition: width 0.5s; }

.bar-tech { background: #4a90e2; } 
.bar-eco { background: #f5a623; } 
.bar-cul { background: #b8e986; } 
.bar-phil { background: #bd10e0; } 
.bar-suffering { background: var(--accent-red); }

.chart-container {
    position: relative; height: 300px; width: 100%; 
    margin-top: auto; padding-bottom: 20px; flex-shrink: 0; 
}

/* =========================================
   MANDATE DISPLAY (SIDEBAR)
   ========================================= */
.mandate-display {
    padding: 15px;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.1) 0%, rgba(10, 10, 12, 1) 100%);
    border: 1px solid var(--accent-gold); border-radius: 6px;
    margin-bottom: 15px; box-shadow: 0 0 15px rgba(212, 175, 55, 0.05);
    text-align: center; animation: pulseBorderGold 3s infinite;
}

.mandate-label {
    font-size: 0.7em; text-transform: uppercase; letter-spacing: 2px;
    color: var(--accent-gold); margin-bottom: 5px; opacity: 0.8;
}

.mandate-boon {
    font-size: 0.95em; font-weight: bold; color: #fff;
    letter-spacing: 0.5px; text-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
}

/* =========================================
   THE SEEDING STAGE
   ========================================= */
.seeding-stage-container {
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: flex-start; 
    padding: 30px; 
    background: radial-gradient(circle at center, #0f0f15 0%, #050508 100%);
    position: relative; 
    overflow-y: auto;
    
    /* NEW: Forces padding to remain inside the 100% height bounds */
    box-sizing: border-box; 
    width: 100%; 
}

.seeding-grid {
    display: grid; 
    grid-template-columns: repeat(4, 200px); 
    gap: 25px; 
    /* NEW: Tightened up the vertical margins (was 40px 0) */
    margin: 15px 0 30px 0; 
}

.pillar-bucket {
    background: rgba(255, 255, 255, 0.02); border: 1px solid #333;
    border-radius: 8px; height: 280px; /* Reduced from 380px */
    position: relative; overflow: hidden; display: flex; flex-direction: column;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.pillar-bucket:hover {
    border-color: var(--accent-gold); background: rgba(212, 175, 55, 0.04);
    transform: translateY(-5px);
}

.pillar-fill {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: linear-gradient(to top, rgba(212, 175, 55, 0.2), transparent);
    z-index: 1; pointer-events: none; transition: height 0.8s ease-out;
}

.pillar-content {
    position: relative; z-index: 2; padding: 25px 15px; 
    height: 100%; display: flex; flex-direction: column; align-items: center;
}

.pillar-icon { 
    font-size: 2.8em; margin-bottom: 15px; filter: drop-shadow(0 0 10px rgba(255,255,255,0.1));
}

.investment-controls {
    display: flex; justify-content: center; align-items: center; 
    gap: 12px; margin: 15px 0;
}

.btn-seed {
    background: #111; border: 1px solid #444; color: var(--accent-gold);
    width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
    font-size: 1.2em; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.btn-seed:hover { border-color: var(--accent-gold); background: #1a1a1a; transform: scale(1.1); }

.total-marker {
    font-family: 'Cinzel', serif; font-size: 0.65em; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 1.5px; margin-top: 10px;
}

/* =========================================
   THEATER STAGE (MICRO PHASE)
   ========================================= */
#theater-stage {
    flex: 1; /* This is crucial so it stretches! */
    display: flex;
    flex-direction: column;
}

/* --- THE DEVIL'S BARGAIN CARDS --- */
.devil-bargain-card {
    background: #0a0a0c;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 20px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    display: flex;
    flex-direction: column;
    /* Optional: subtle inner glow so it doesn't look totally flat */
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5); 
}

/* Hover effect to make the blind choice feel tactile */
.devil-bargain-card:hover {
    border-color: #666 !important; /* Slightly brightens on hover */
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.8);
}

/* Selected state (if you want to enforce the styling via class instead of inline JS) */
.devil-bargain-card.selected {
    border-color: var(--accent-blue) !important;
    background: rgba(74, 144, 226, 0.05) !important;
    box-shadow: 0 0 20px rgba(74, 144, 226, 0.15) !important;
}

.stage-card {
    background-color: var(--panel-bg); border: 2px solid var(--border-color);
    border-radius: 8px; padding: 40px 30px; width: 100%; max-width: 600px; 
    box-shadow: 0 10px 40px rgba(0,0,0,0.6); display: flex; flex-direction: column;
    transition: all 0.3s; margin: 0 auto; flex-shrink: 0; 
}

.stage-card.at-risk {
    border-color: var(--accent-red) !important;
    box-shadow: 0 0 25px rgba(201, 59, 59, 0.3);
    animation: pulseBorderRed 2s infinite;
}

.critical-label {
    background: var(--accent-red); color: white; font-size: 0.7em; 
    font-weight: bold; padding: 2px 8px; border-radius: 3px; 
    letter-spacing: 1px; margin-bottom: 10px; display: inline-block; align-self: center;
}

.lineage-name { font-size: 0.8em; color: var(--accent-gold); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 5px; }
.npc-name { font-size: 1.2em; font-weight: bold; margin-bottom: 5px; }
.npc-role { font-size: 0.9em; color: var(--text-dim); margin-bottom: 15px; font-style: italic; }

.npc-thought { 
    font-size: 1.15em; line-height: 1.5; flex-grow: 1; 
    margin: 30px 0; padding-left: 15px; 
    border-left: 3px solid var(--accent-gold); 
    color: #fff; font-style: italic; font-weight: 500;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5); 
}

.card-actions {
    margin-top: 30px; padding-top: 25px; border-top: 1px solid #333;
    display: flex; flex-direction: column; gap: 15px;
}

.action-row { display: flex; justify-content: center; gap: 10px; width: 100%; }

/* Buttons */
.btn-primary { 
    background: var(--accent-blue); color: #000; border: none; padding: 12px 10px; 
    border-radius: 4px; font-weight: bold; cursor: pointer; text-transform: uppercase; 
    flex-grow: 1; transition: all 0.2s; font-size: 0.85em;
}
.btn-primary:hover { transform: scale(1.05); background: #5ba1f3; }
.btn-primary:disabled { background: #333; color: #555; cursor: not-allowed; transform: none; }

.btn-secondary { 
    background: transparent; color: var(--text-dim); border: 1px solid #444; 
    padding: 12px 10px; border-radius: 4px; font-weight: bold; cursor: pointer; 
    text-transform: uppercase; flex-grow: 1; transition: all 0.2s; font-size: 0.85em;
}
.btn-secondary:hover { border-color: var(--accent-red); color: var(--accent-red); }

/* =========================================
   TOOL CARDS (Sidebar Sidebar)
   ========================================= */
.mini-tool-card {
    position: relative; background: #0a0a0c; border: 1px solid #222; 
    border-radius: 6px; padding: 16px; transition: all 0.2s; 
    display: flex; flex-direction: column;
}

.mini-tool-card.explorable { border-color: #444; opacity: 1; cursor: pointer; }
.mini-tool-card.explorable:hover { border-color: var(--accent-gold); }

.mini-tool-card.highlighted {
    border-color: var(--accent-blue); opacity: 1; cursor: pointer;
    background: rgba(74, 144, 226, 0.05);
}
.mini-tool-card.highlighted:hover {
    transform: translateX(-4px); box-shadow: -4px 4px 15px rgba(74, 144, 226, 0.15);
    background: rgba(74, 144, 226, 0.1);
}

.mini-tool-card.selected {
    border-color: #fff; box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1); transform: translateX(-4px);
}
.mini-tool-card.selected::before {
    content: '✓'; position: absolute; top: 10px; right: 15px; color: #fff; font-weight: bold;
}

.tool-desc-hidden { display: none; }
.tool-desc-visible { 
    display: block; margin-top: 10px; font-size: 0.85em; 
    color: var(--text-main); line-height: 1.4; border-top: 1px solid #333; 
    padding-top: 10px; animation: fadeIn 0.2s ease-out;
}

.nudge-details-area {
    max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out, margin 0.3s;
    font-size: 0.85em; color: var(--text-dim); border-top: 1px solid rgba(255,255,255,0.1);
}

.mini-tool-card.selected .nudge-details-area {
    max-height: 300px; margin-top: 15px; padding-top: 15px; 
    display: flex; flex-direction: column; gap: 10px; 
}

/* =========================================
   THE DOCKED FATES SIDEBAR
   ========================================= */
#theater-dock {
    width: 280px;
    min-width: 280px;
    background: #070709;
    border-left: 1px solid #222;
    padding: 25px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow-y: auto;
    /* Ensure it doesn't span 100% width anymore */
    height: 100%; 
}

.dock-card {
    position: relative; 
    min-width: 120px; 
    background: #0a0a0c; 
    border: 1px solid #333; 
    border-radius: 6px; 
    padding: 6px 10px; /* Slightly tighter internal padding */
    font-size: 0.75em; 
    opacity: 0.8; 
    flex-shrink: 0; 
    border-top: 3px solid #333;
    cursor: pointer; 
    overflow: hidden; 
    transition: all 0.2s;
}

.dock-card:hover { opacity: 1; transform: translateY(-3px); border-color: var(--accent-blue); }
.dock-card.nudge { border-top-color: var(--accent-blue); }
.dock-card.silence { border-top-color: var(--accent-red); }

.undo-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(201, 59, 59, 0.9); color: #fff; display: flex; 
    align-items: center; justify-content: center; font-weight: bold; 
    text-transform: uppercase; letter-spacing: 1px; opacity: 0; transition: opacity 0.2s;
}
.dock-card:hover .undo-overlay { opacity: 1; }

/* =========================================
   DEPRIVATION & MITIGATION
   ========================================= */
.deprivation-container {
    margin: 15px 0; padding: 12px; background: rgba(0, 0, 0, 0.3);
    border-radius: 4px; border: 1px solid #333;
}

.progress-label-row {
    display: flex; justify-content: space-between; font-size: 0.75em;
    text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; color: var(--text-dim);
}

.progress-track {
    width: 100%; height: 6px; background: #1a1a1a;
    border-radius: 3px; position: relative; overflow: hidden;
}

.progress-fill-comprehension {
    height: 100%; background: var(--accent-blue); position: absolute;
    left: 0; top: 0; z-index: 2; transition: width 0.4s ease;
}

.progress-marker-world {
    height: 100%; background: rgba(212, 175, 55, 0.3); position: absolute;
    left: 0; top: 0; z-index: 1; transition: width 0.4s ease;
}

.obsolete-warning {
    color: var(--accent-red); font-weight: bold; font-size: 0.7em;
    margin-top: 8px; text-align: center; animation: pulseText 2s infinite;
}

.shield-bar-bg {
    width: 100%; height: 8px; background: #222; 
    border-radius: 4px; margin: 10px 0; overflow: hidden; position: relative;
}

.stat-bar-ghost {
    height: 100%; background: rgba(201, 59, 59, 0.5);
    position: absolute; top: 0; z-index: 1; transition: width 0.2s ease;
}

/* =========================================
   MACRO PHASE: FLOATING ERA CARD
   ========================================= */
.floating-era-card {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); 
    width: 500px; max-height: 80vh; background: var(--panel-bg);
    border: 1px solid var(--accent-gold); border-radius: 12px; padding: 40px; 
    box-shadow: 0 0 100px rgba(0,0,0,0.9), 0 0 20px rgba(212, 175, 55, 0.2);
    z-index: 200; display: flex; flex-direction: column; 
    box-sizing: border-box; overflow-y: auto;          
}

/* =========================================
   THE ARCHIVE LOOM
   ========================================= */
#loom-wrapper { 
    position: relative; width: 100%; height: 530px; overflow-x: auto; overflow-y: hidden;
    border: 1px solid #333; border-radius: 8px; box-shadow: inset 0 0 50px rgba(0,0,0,0.8); 
    background-color: #050508;
    background-image: 
        radial-gradient(circle at center, rgba(30, 30, 40, 0.4) 0%, #050508 100%),
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 100% 100%, 40px 40px, 40px 40px;
}

#loom-svg { position: absolute; top: 0; left: 0; min-width: 100%; min-height: 100%; pointer-events: none; z-index: 1; }

#loom-content { 
    position: relative; z-index: 2; display: grid; 
    grid-template-columns: 200px repeat(10, 100px); 
    grid-template-rows: repeat(4, 80px); gap: 40px 60px; padding: 40px; width: max-content; 
}

.branch-label {
    position: sticky; left: 0; z-index: 10; display: flex; align-items: center; 
    font-weight: bold; font-size: 0.8em; color: var(--text-main); 
    text-transform: uppercase; letter-spacing: 2px; padding-right: 20px;
    background: linear-gradient(90deg, #050508 85%, transparent 100%);
}
.branch-label span { color: var(--accent-gold); margin-right: 10px; font-size: 1.5em; }

.tree-node-icon { 
    width: 60px; height: 60px; background: var(--panel-bg); border: 2px solid #444; 
    border-radius: 50%; display: flex; align-items: center; justify-content: center; 
    position: relative; transition: all 0.3s; z-index: 2; font-size: 1.5em; cursor: help; margin: auto;
}
.tree-node-icon:hover { transform: scale(1.1); }
.tree-node-icon.unlocked { border-color: var(--accent-gold); box-shadow: 0 0 20px rgba(212,175,55,0.4); background: rgba(212,175,55,0.1); color: var(--accent-gold); }
.tree-node-icon.available { border-color: var(--accent-blue); opacity: 0.9; color: var(--accent-blue); box-shadow: 0 0 15px rgba(74,144,226,0.2);}
.tree-node-icon.hidden { border-color: #222; opacity: 0.2; color: #333; user-select: none; pointer-events: none; }

.branch-tech { grid-row: 1; }
.branch-economy { grid-row: 2; }
.branch-culture { grid-row: 3; }
.branch-philosophy { grid-row: 4; }

.node-tooltip { 
    position: fixed; background: rgba(15, 15, 20, 0.95); border: 1px solid var(--accent-gold); 
    padding: 20px; border-radius: 6px; width: 280px; display: none; z-index: 100; 
    pointer-events: none; box-shadow: 0 10px 30px rgba(0,0,0,0.8); backdrop-filter: blur(5px); color: var(--text-main); 
}
.tooltip-title { color: var(--accent-gold); font-weight: bold; font-size: 1.2em; border-bottom: 1px solid #333; padding-bottom: 8px; margin-bottom: 10px; display: flex; justify-content: space-between;}
.tooltip-desc { font-size: 0.9em; line-height: 1.4; color: var(--text-dim); margin-bottom: 15px; }
.tooltip-stats { font-family: monospace; font-size: 0.85em; display: flex; flex-direction: column; gap: 5px; }

/* =========================================
   THE TEMPORAL LEDGER (Full-Screen Report)
   ========================================= */
.ledger-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: #050508; z-index: 200; padding: 60px; overflow-y: auto;
    display: flex; flex-direction: column; align-items: center; animation: fadeIn 0.8s ease-in;
}

.ledger-header {
    text-align: center; border-bottom: 2px solid var(--accent-gold);
    width: 100%; max-width: 900px; padding-bottom: 20px; margin-bottom: 40px;
}

.ledger-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 40px;
    width: 100%; max-width: 900px; margin-bottom: 50px;
}

.ledger-section h3 {
    color: var(--accent-gold); font-size: 0.8em; text-transform: uppercase;
    letter-spacing: 2px; border-bottom: 1px solid #333; padding-bottom: 8px; margin-bottom: 15px;
}

.ledger-item { font-size: 0.95em; line-height: 1.5; margin-bottom: 12px; color: var(--text-dim); }
.ledger-item strong { color: var(--text-main); }
.ledger-footer { text-align: center; width: 100%; max-width: 900px; padding-top: 30px; border-top: 1px solid #333; }

/* =========================================
   NOTIFICATIONS & GUIDES
   ========================================= */
#toast-container {
    position: fixed; bottom: 30px; right: 30px; z-index: 1000;
    display: flex; flex-direction: column; gap: 15px; pointer-events: none;
}
.toast {
    background: var(--panel-bg); color: var(--text-main);
    padding: 15px 25px; border-radius: 6px; border-left: 4px solid var(--accent-red);
    box-shadow: 0 10px 30px rgba(0,0,0,0.8); font-weight: bold;
    animation: toastSlideIn 0.3s ease-out forwards, toastFadeOut 0.5s ease-in 3s forwards;
}
.toast.success { border-left-color: var(--accent-gold); }

.guide-section { background: var(--panel-bg); border: 1px solid #333; border-radius: 8px; padding: 25px; margin-bottom: 20px; }
.guide-section h3 { color: var(--accent-blue); border-bottom: 1px solid #333; padding-bottom: 10px; margin-bottom: 15px;}
.resolution-text {
    font-size: 1.1em; color: var(--text-dim); line-height: 1.5;
    margin-top: 20px; padding: 20px; background: #0a0a0c;
    border-left: 4px solid var(--accent-gold); border-radius: 4px;
}

/* =========================================
   BOOT SCREEN
   ========================================= */
.boot-screen {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: #050508; z-index: 9999; display: flex; align-items: center; 
    justify-content: center; transition: opacity 1s ease-out;
}
.boot-content {
    max-width: 700px; text-align: center; padding: 40px; 
    background: rgba(20, 20, 25, 0.5); border: 1px solid #333; 
    border-radius: 8px; box-shadow: 0 0 50px rgba(0,0,0,0.8);
}
.boot-content p { font-size: 1.1em; line-height: 1.6; margin-bottom: 20px; color: #ccc; }

/* =========================================
   ANIMATIONS
   ========================================= */
@keyframes fadeIn { 
    from { opacity: 0; transform: translateY(5px); } 
    to { opacity: 1; transform: translateY(0); } 
}
@keyframes fadeInCenter {
    from { opacity: 0; transform: translate(-50%, -45%); }
    to { opacity: 1; transform: translate(-50%, -50%); }
}
@keyframes toastSlideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastFadeOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }
@keyframes pulseText { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

/* Dedicated border pulse animations */
@keyframes pulseBorderRed {
    0% { border-color: #500; }
    50% { border-color: var(--accent-red); }
    100% { border-color: #500; }
}

@keyframes pulseBorderGold {
    0%, 100% { border-color: rgba(212, 175, 55, 0.3); }
    50% { border-color: var(--accent-gold); box-shadow: 0 0 20px rgba(212, 175, 55, 0.15); }
}