:root {
    --h: 4rem;
    --navH: 2.5rem;
    --footerH: 2.25rem;
    
    /* Page Dimensions for Portrait Look */
    --pageW: 800px;
    --pageH: 80vh; 
    --sidebarW: 16rem;
    --contentPadding: 15px;
    --mainContentW: calc(var(--pageW) - var(--sidebarW) - 0.75rem - 0.75rem - var(--contentPadding) * 2);

    --bg-base: #333842;
    --bg-module: #4c535e;
    --bg-content: #ffffff;
    --bg-accent-blue: #a2c4e8;
    --blue-title-v2: #0a1c36;
    --text-main: #ffffff;
    
    --border-light: #7d8594;
    --border-dark: #1e2126;
    --border-mid: #606875;
    
    --rounding: 0px;
}

/* Base and Layout Reset */
body {
    font-family: 'Tahoma', 'Verdana', 'Arial', sans-serif;
    color: var(--text-main);
    font-size: 14px;
    background-color: var(--bg-base);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    overflow-x: hidden;
    display: flex; /* Use flex to control overall layout */
    flex-direction: column;
    align-items: center; /* Center everything horizontally */
}

/* --- Header & Nav (Full Width) --- */
#header {
    width: 100%;
    height: var(--h);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-module);
    border-top: 2px solid var(--border-light);
    border-left: 2px solid var(--border-light);
    border-right: 2px solid var(--border-dark);
    border-bottom: 2px solid var(--border-dark);
    box-sizing: border-box;
    font-size: 1.2em;
    font-weight: bold;
    flex-shrink: 0;
}

#nav {
    width: 100%;
    height: var(--navH);
    display: flex;
    align-items: center;
    padding: 0.5rem;
    box-sizing: border-box;
    background-color: var(--bg-base);
    flex-shrink: 0;
}
#nav a {
    padding: 0.5rem 1rem;
    cursor: pointer;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    text-decoration: none;
    background: var(--bg-module);
    color: var(--text-main);
    border-top: 1px solid var(--border-dark);
    border-left: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}
#nav a:hover { background: var(--bg-accent-blue); color: #000; }
#nav a:active { border-top: 1px solid var(--border-light); border-left: 1px solid var(--border-light); border-right: 1px solid var(--border-dark); border-bottom: 1px solid var(--border-dark); }


/* --- Page Wrapper (The Portrait Container) --- */
#pageWrapper {
    /* Set fixed portrait dimensions and center it */
    width: var(--pageW);
    height: var(--pageH);
    margin: 0.75rem 0; /* Vertical margin to separate from header/footer */
    position: relative; /* Anchor for the external nav buttons */
}

/* --- Main Content Area (Within Wrapper) --- */
#main {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%; /* Take full height of the wrapper */
    padding: 0.5rem;
    box-sizing: border-box;
    background-color: var(--bg-base);
}

/* Sidebar Styling */
#sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebarW);
    height: 100%;
}
/* ... (Sidebar component styles remain the same for profileBox, avatar, status, badges) ... */
#profileBox {
    background-color: var(--bg-module);
    border-top: 2px solid var(--border-light);
    border-left: 2px solid var(--border-light);
    border-right: 2px solid var(--border-dark);
    border-bottom: 2px solid var(--border-dark);
    padding: 0.75rem;
    flex-shrink: 0;
    margin-bottom: 0.75rem;
    box-sizing: border-box;
}
#profileTop {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    height: 60px;
}
#avatar {
    width: 50%;
    background-color: #374151;
    border: 1px solid #4a5568;
}
#status {
    width: 50%;
    background-color: #374151;
    border: 1px solid #4a5568;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    padding: 0 5px;
}
#status span { color: #fde047; }
#profileLinks a {
    display: block;
    text-align: center;
    text-decoration: none;
    background: var(--bg-module);
    color: var(--text-main);
    border-top: 1px solid var(--border-dark);
    border-left: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-dark);
    padding: 0.5rem;
    font-weight: bold;
}
#profileLinks a:hover { background: var(--bg-accent-blue); color: #000; }
#badges {
    flex-grow: 1;
    background-color: var(--bg-module);
    border-top: 2px solid var(--border-light);
    border-left: 2px solid var(--border-light);
    border-right: 2px solid var(--border-dark);
    border-bottom: 2px solid var(--border-dark);
    padding: 0.75rem;
    overflow-y: auto;
}
#badges p {
    font-weight: bold;
    border-bottom: 1px solid #4a5568;
    padding-bottom: 0.25rem;
    margin-bottom: 0.5rem;
    margin-top: 0;
}
/* End Sidebar Styling */

/* Journal Content Box */
#content {
    flex-grow: 1;
    margin-left: 0.75rem;
    background-color: var(--bg-content);
    border-top: 2px solid var(--border-light);
    border-left: 2px solid var(--border-light);
    border-right: 2px solid var(--border-dark);
    border-bottom: 2px solid var(--border-dark);
    padding: var(--contentPadding);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    color: #000;
    
    /* Crucial: Set up for absolute positioning of journal entries */
    position: relative; 
    box-sizing: border-box;
}

#logContainer {
    flex-grow: 1;
    overflow: hidden;
    height: 100%;
    /* Crucial for ensuring entries fill the space */
    position: absolute; 
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: var(--contentPadding); /* Apply padding to content here */
    box-sizing: border-box;
}

/* Entry Visibility Logic (CSS :target) */
.logEntry {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    overflow-y: auto;
    background-color: var(--bg-content);
    /* Entries must fill logContainer, which has the padding */
    padding: 0; 
    box-sizing: border-box;
}

/* FIX: Removes default visibility. Only visible if targeted by a hash. */
.logEntry:target {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

/* Content Styling */
.entryHeader {
    border-bottom: 1px dashed #606875;
    margin-bottom: 15px;
    padding-bottom: 5px;
}
.entryHeader h2 {
    margin: 0 0 5px 0;
    font-size: 1.5em;
    color: var(--blue-title-v2);
}
.entryHeader time {
    display: block;
    font-size: 0.9em;
    color: #606875;
}
.entryBody p {
    line-height: 1.6;
    margin-bottom: 10px;
    text-align: justify;
}

/* --- External Navigation Controls (The button fix) --- */
#externalNav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: calc(100% + 150px); /* Extend past the wrapper width */
    left: -75px; /* Center the extended width */
    display: flex;
    justify-content: space-between;
    pointer-events: none; /* Allows clicks to pass through this container */
    z-index: 50; 
}

.navBtn {
    text-decoration: none;
    font-size: 1.5em;
    font-weight: bold;
    padding: 0.75rem 1rem;
    background: var(--bg-module);
    color: var(--text-main);
    border-top: 1px solid var(--border-dark);
    border-left: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    pointer-events: auto; /* Buttons themselves are clickable */
}

/* Hide the arrow that points toward the sidebar */
.navBtn.prevBtn {
    visibility: hidden; 
}
.navBtn.nextBtn {
    margin-right: -75px; /* Adjust based on externalNav width calculation */
}
/* Revert visibility and position for the visible button */
.navBtn.nextBtn {
    margin-right: 0;
}

.navBtn:hover { background: var(--bg-accent-blue); color: #000; }
.navBtn:active { border-top: 1px solid var(--border-light); border-left: 1px solid var(--border-light); border-right: 1px solid var(--border-dark); border-bottom: 1px solid var(--border-dark); }

/* --- Footer --- */
#footer {
    width: 100%;
    height: var(--footerH);
    display: flex;
    align-items: center;
    padding: 0.25rem;
    background-color: var(--bg-module);
    border-top: 2px solid var(--border-light);
    border-left: 2px solid var(--border-light);
    border-right: 2px solid var(--border-dark);
    border-bottom: 2px solid var(--border-dark);
    flex-shrink: 0;
    margin-top: auto; /* Push footer to the bottom */
}

#statusBox {
    background-color: #c0c0c0;
    color: #000;
    padding: 2px 6px;
    border-top: 2px solid var(--border-dark);
    border-left: 2px solid var(--border-dark);
    border-right: 2px solid var(--border-light);
    border-bottom: 2px solid var(--border-light);
    height: calc(var(--footerH) - 8px);
    display: flex;
    align-items: center;
    margin-left: 0.5rem;
    margin-right: 1rem;
    flex-shrink: 0;
    font-size: 0.75rem;
}
#statusBox span span {
    color: #b91c1c;
    font-weight: bold;
}

#marquee {
    flex-grow: 1;
    overflow: hidden;
    height: 100%;
    display: flex;
    align-items: center;
}

#rotatingText {
    font-size: 0.75rem;
    font-style: italic;
    color: #d1d5db;
    display: inline-block;
    animation: continuousScroll 20s linear infinite;
    white-space: nowrap;
    padding-left: 100%;
}

@keyframes continuousScroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}