/* --- Base and Theming --- */
:root {
    --main-bg-color: #000000;
    --text-color: #33ff33; /* Default green */
    --accent-color: #FFFF00; /* Yellow for prompts, highlights */
    --link-bg-color: rgba(51, 255, 51, 0.1);
    --link-hover-bg-color: rgba(51, 255, 51, 0.3);
    --scanline-color: rgba(51, 255, 51, 0.08);
    --border-color: var(--text-color);
    --overlay-bg-color: rgba(0, 0, 0, 0.9);
    --notification-bg-color: rgba(0, 0, 0, 0.95);
    --glow-amount: 2px; /* Subtle glow */
    --blur-amount: 0.4px; /* Subtle blur */
    --flicker-opacity: 0.05;
    --char-delay-ms: 15; /* Controls typing speed (inverse of chars/sec) */
}

body.amber-mode {
    --text-color: #ffb000;
    --accent-color: #FFD700; /* Gold for amber */
    --link-bg-color: rgba(255, 176, 0, 0.1);
    --link-hover-bg-color: rgba(255, 176, 0, 0.3);
    --scanline-color: rgba(255, 176, 0, 0.08);
}

/* --- General Layout & CRT Effects --- */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevent body scrollbars */
}

/* Screen reader only class */
.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;
}

/* Focus styles for accessibility */
*:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Skip link for keyboard navigation */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--main-bg-color);
    color: var(--text-color);
    padding: 8px;
    text-decoration: none;
    border: 1px solid var(--border-color);
    z-index: 1000;
}

.skip-link:focus {
    top: 6px;
}

body {
    background-color: var(--main-bg-color);
    font-family: 'VT323', 'Courier New', Courier, monospace; /* Retro font first */
    color: var(--text-color);
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Apply base text effects globally */
body, input, button, select, textarea, a {
    color: var(--text-color);
    text-shadow: 0 0 var(--glow-amount) var(--text-color);
    filter: blur(var(--blur-amount));
    font-size: 18px; /* Base font size */
    line-height: 1.5; /* Generous line height for readability */
}

/* Load the font */
@font-face {
  font-family: 'VT323';
  src: url('https://fonts.gstatic.com/s/vt323/v17/pxiKyp0ihIEF2isQFJXGdg.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap; /* Ensures text is visible while font loads */
}


/* CRT screen effect overlay */
#crt-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background:
        linear-gradient(var(--scanline-color) 50%, transparent 50%);
    background-size: 100% 3px; /* Thicker scanlines */
    pointer-events: none; z-index: 10;
    opacity: 0.6;
}

/* Vignette effect */
#vignette {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    box-shadow: 0 0 200px rgba(0, 0, 0, 0.85) inset;
    pointer-events: none; z-index: 5;
}

/* Screen flicker effect */
#flicker {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.03); /* Use white for more contrast */
    opacity: 0; pointer-events: none; z-index: 4;
    animation: flicker 0.12s infinite alternate; /* Simpler flicker */
}

@keyframes flicker {
    from { opacity: 0; }
    to { opacity: var(--flicker-opacity); }
}

/* --- Main Container & Content Area --- */
.container {
    width: 95%;
    max-width: 900px; /* Slightly wider */
    margin: 0 auto;
    padding: 5px 15px;
    position: relative; z-index: 1;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    height: 100vh; /* Full viewport height */
    box-sizing: border-box;
}

/* --- Navigation --- */
nav {
    border-bottom: 1px solid var(--border-color);
    padding: 8px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Prevent nav from shrinking */
    margin-bottom: 8px;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 10px;
}
.nav-links { display: flex; flex-wrap: wrap; gap: 15px; }
.nav-links a { padding: 3px 5px; text-transform: uppercase; font-size: 16px; letter-spacing: 1px; }
.controls { display: flex; gap: 15px; align-items: center; }
.toggle-container { display: flex; align-items: center; gap: 8px; }
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 20px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #222; border: 1px solid var(--border-color); transition: .4s; border-radius: 20px; }
.toggle-slider:before { position: absolute; content: ""; height: 12px; width: 12px; left: 3px; bottom: 3px; background-color: var(--text-color); transition: .4s; border-radius: 50%; }
input:checked + .toggle-slider:before { transform: translateX(24px); }
.toggle-label { font-size: 14px; text-transform: uppercase; }

/* --- Text & Link Styles --- */
p, h1, h2, h3, h4, h5, h6, li, pre, code, strong, span, div#game-text > div, div#game-text > p, .stat-item, .inventory-item {
    margin: 0.6em 0;
    white-space: pre-wrap; /* Preserve whitespace and wrap */
    word-wrap: break-word; /* Break long words */
}
 h1, h2, h3 { text-transform: uppercase; letter-spacing: 2px; }
 h1 { font-size: 28px; margin-top: 1em; text-align: center; }
 h2 { font-size: 22px; border-bottom: 1px solid var(--border-color); padding-bottom: 6px; margin: 1.2em 0 0.8em; }
 h3 { font-size: 20px; margin: 1em 0 0.6em; }

a, .action-link {
    text-decoration: none;
    background-color: var(--link-bg-color);
    padding: 1px 4px;
    border-radius: 2px;
    cursor: pointer;
    border-bottom: 1px dotted transparent; /* Subtle underline effect on hover */
    transition: background-color 0.2s, border-bottom-color 0.2s;
}
a:hover, a:focus, .action-link:hover, .action-link:focus {
    background-color: var(--link-hover-bg-color);
    outline: none;
    border-bottom: 1px dotted var(--text-color);
}

/* Specific text colors */
.location-name { color: #AAAAFF; text-shadow: 0 0 3px #AAAAFF; font-weight: bold; }
.item-name { color: #90EE90; text-shadow: 0 0 3px #90EE90; }
.item-location { color: #CCCCCC; font-style: italic; } /* Location of an item */
.person-name { color: #FFC0CB; text-shadow: 0 0 3px #FFC0CB; }
.exit-name { color: #FFA500; text-shadow: 0 0 3px #FFA500; text-transform: uppercase; }
.event-title { color: var(--accent-color); font-weight: bold; }
.event-choice-prompt { color: #ADD8E6; } /* Light blue */
.echo-command { color: #888888; } /* Dim echoed command */
.error-message { color: #FF6347; } /* Tomato red for errors */
.success-message { color: #90EE90; } /* Light green for success */
.milestone-message { color: #AFEEEE; } /* Pale turquoise for milestones */
.info-label { color: #CCCCCC; font-weight: bold; } /* Light gray for info labels */
.action-hint { color: #FFCC99; font-style: italic; } /* Hint about possible actions */
.inline-code {
     background-color: var(--link-bg-color);
     padding: 1px 5px;
     font-family: inherit; /* Use VT323 */
     font-size: 0.95em;
     border-radius: 2px;
}


/* --- Boot & Intro Screens --- */
.boot-screen, .intro-screen {
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    height: 100vh; width: 100%; position: fixed; top: 0; left: 0;
    background-color: var(--main-bg-color);
    z-index: 100; transition: opacity 1s ease-out;
    text-align: center; padding: 20px; box-sizing: border-box;
}
.boot-text { font-size: 18px; max-width: 90%; }
.boot-text p { animation: pulse 1.8s infinite ease-in-out; opacity: 0.7; margin: 0.5em 0;}
.boot-text p:nth-child(1) { animation-delay: 0s; }
.boot-text p:nth-child(2) { animation-delay: 0.3s; }
.boot-text p:nth-child(3) { animation-delay: 0.6s; }
.boot-text p:nth-child(4) { animation-delay: 0.9s; }
.boot-text p:nth-child(5) { animation-delay: 1.2s; }

@keyframes pulse { 0%, 100% { opacity: 0.7; } 50% { opacity: 1; } }

.intro-screen { opacity: 0; display: none; z-index: 110; } /* Start hidden */
.intro-logo { font-size: 36px; margin-bottom: 15px; line-height: 1.3; }
.ascii-art { font-family: monospace; white-space: pre; line-height: 1.1; margin: 15px 0; text-align: center; font-size: 10px; opacity: 0.8; }
.intro-text { font-size: 16px; max-width: 85%; margin-bottom: 30px; }
.intro-text p { margin: 0.8em 0; }
.start-button {
    background-color: transparent; color: var(--text-color); border: 2px solid var(--border-color);
    padding: 10px 25px; font-size: 18px; cursor: pointer;
    font-family: inherit; /* Use VT323 */
    text-transform: uppercase; letter-spacing: 3px;
    transition: all 0.3s ease;
    /* Filter/shadow applied by body defaults */
}
.start-button:hover {
    background-color: var(--link-hover-bg-color);
    transform: scale(1.03);
    box-shadow: 0 0 10px var(--text-color); /* Add glow on hover */
}

/* --- Content Area & Scrolling --- */
#content {
    position: relative; /* For cursor positioning */
    flex-grow: 1; /* Takes remaining vertical space */
    overflow-y: auto; /* Enables scrolling *only* for the content */
    padding-bottom: 20px; /* More space below command prompt */
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth; /* Smooth scrolling */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS devices */
    overscroll-behavior: contain; /* Prevent page scroll when reaching boundary */
}
/* Scrollbar styling (Webkit) */
#content::-webkit-scrollbar { width: 8px; }
#content::-webkit-scrollbar-track { background: #111; border-left: 1px solid var(--border-color); }
#content::-webkit-scrollbar-thumb { background: var(--text-color); border-radius: 4px; }
#content::-webkit-scrollbar-thumb:hover { background: var(--accent-color); }

#game-text {
    flex-grow: 1; /* Allow text area to expand */
    position: relative; /* Needed for absolute cursor */
    padding-bottom: 25px; /* Extra space for cursor/MORE prompt */
}

/* --- Cursor & MORE Prompt --- */
.cursor {
    display: inline-block;
    width: 10px;
    height: 1.2em; /* Match line height */
    background: var(--text-color);
    animation: blink 1s step-end infinite;
    position: absolute;
    z-index: 2; pointer-events: none;
    box-shadow: 0 0 5px var(--text-color); /* Cursor glow */
    vertical-align: baseline; /* Align better with text */
    opacity: 0; /* Start hidden until positioned */
}

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.more-prompt {
    color: var(--accent-color);
    font-weight: bold;
    text-align: center;
    padding: 8px 0;
    margin-top: 10px;
    animation: pulse 1.5s infinite ease-in-out;
    cursor: pointer; /* Indicate clickable */
    display: block; /* Ensure it takes full width */
}

/* --- Command Prompt & Input --- */
#input-line {
     display: flex;
     align-items: baseline; /* Align prompt symbol with input text */
     margin-top: 10px; /* Space above input */
     position: relative; /* For potential future additions */
     flex-shrink: 0; /* Prevent shrinking */
     padding: 5px 0; /* Add some padding */
}

.prompt-symbol {
    color: var(--accent-color); /* Use accent color */
    margin-right: 10px;
    font-weight: bold;
    user-select: none; /* Prevent selecting the '>' */
}

#command-input {
    background-color: transparent;
    border: none;
    color: var(--text-color); /* Inherited */
    font-family: inherit; /* Use VT323 */
    font-size: inherit; /* Use base font size */
    width: 100%;
    padding: 2px 5px;
    outline: none;
    flex-grow: 1;
    height: 1.5em; /* Match line height */
     caret-color: var(--text-color); /* Make caret visible */
     /* Filter/shadow applied by body defaults */
}
 #command-input::placeholder {
    color: var(--text-color);
    opacity: 0.5;
 }


/* --- Game Specific Styles --- */
.game-title { font-size: 36px; text-align: center; margin-bottom: 30px; letter-spacing: 4px; }
.room-description { margin-bottom: 20px; }

/* Game actions (contextual buttons) */
.game-actions {
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px; /* Reduced gap */
    border-top: 1px dashed var(--border-color);
    padding-top: 10px;
    flex-shrink: 0;
    min-height: 30px; /* Ensure it takes some space even when empty */
}

/* Action buttons and links */
.action-btn, .cmd-btn {
    background-color: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 4px 10px; /* Slightly smaller */
    cursor: pointer;
    font-family: inherit; /* Use VT323 */
    font-size: 14px; /* Smaller font for buttons */
    margin: 2px;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.2s ease;
    /* Filter/shadow applied by body defaults */
}
.action-btn:hover, .cmd-btn:hover, .action-btn:focus, .cmd-btn:focus {
    background-color: var(--link-hover-bg-color);
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
    box-shadow: 0 0 8px var(--text-color); /* Glow on hover */
}
/* Style for event choice buttons */
.event-choice { border-style: dashed; }

/* Improved keyboard navigation */
.action-btn:focus-visible, .cmd-btn:focus-visible, a:focus-visible, .action-link:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    background-color: var(--link-hover-bg-color);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --glow-amount: 0px;
        --blur-amount: 0px;
        --flicker-opacity: 0;
    }
    
    body, input, button, select, textarea, a {
        filter: none;
        text-shadow: none;
    }
    
    #crt-overlay, #vignette, #flicker {
        display: none;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .cursor {
        animation: none;
        opacity: 1;
    }
    
    #flicker {
        animation: none;
        opacity: 0;
    }
    
    .boot-text p {
        animation: none;
        opacity: 1;
    }
}


/* --- Overlays (Help, Stats, Credits) --- */
.overlay-content {
    display: none; /* Hidden by default */
    padding: 20px 25px;
    border: 1px solid var(--border-color);
    margin: 0 auto; /* Centered */
    background-color: var(--overlay-bg-color);
    max-height: 80vh; /* Limit height */
    overflow-y: auto; /* Scroll within overlay */
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 85%; max-width: 700px;
    z-index: 200;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}
 /* Scrollbar styling for overlays */
.overlay-content::-webkit-scrollbar { width: 6px; }
.overlay-content::-webkit-scrollbar-track { background: #222; }
.overlay-content::-webkit-scrollbar-thumb { background: var(--text-color); }

.overlay-content h2 { margin-top: 0; color: var(--accent-color); }
.overlay-content ul { list-style: none; padding-left: 0; }
.overlay-content li { margin-bottom: 8px; }
.overlay-content li code { /* Use inline-code class defined earlier */
     background-color: var(--link-bg-color);
     padding: 1px 5px;
     font-family: inherit;
     font-size: 0.95em;
     border-radius: 2px;
}
.overlay-content .cmd-btn { margin-top: 20px; float: right; }

/* Stats specific */
#stats-display { margin-bottom: 30px; } /* Space before close button */
.stat-item {
    display: flex; justify-content: space-between;
    border-bottom: 1px dotted var(--border-color);
    padding: 6px 0; font-size: 16px;
    margin: 0; /* Override default p/div margin */
}
.stat-name { font-weight: normal; margin-right: 15px; flex-shrink: 0;}
.stat-value { text-align: right; font-weight: bold; }
#stats-display hr { border: none; border-top: 1px dashed var(--border-color); margin: 15px 0; }
 #stats-display h3 { font-size: 18px; margin-top: 20px; margin-bottom: 10px; color: var(--accent-color); border-bottom: none; }
 .inventory-item.milestone-message { /* Style for milestones in stats overlay */
    font-size: 14px;
    margin: 4px 0 4px 10px;
 }


/* Credits specific */
.credits-content { text-align: center; }
.credits-content p { margin: 1em 0; }

/* --- Notifications --- */
.notification {
    position: fixed;
    bottom: 20px; /* Position at bottom */
    left: 50%;
    transform: translateX(-50%); /* Center horizontally */
    background-color: var(--notification-bg-color);
    border: 1px solid var(--border-color);
    padding: 8px 15px;
    border-radius: 4px;
    color: var(--text-color);
    z-index: 1000;
    animation: fadeInOut 4s ease-in-out forwards;
    font-size: 14px;
    max-width: 80%;
    text-align: center;
     box-shadow: 0 0 10px rgba(0,0,0,0.7);
     /* Filter/shadow applied by body defaults */
}
@keyframes fadeInOut {
     0% { opacity: 0; transform: translate(-50%, 20px); } /* Start below */
     10% { opacity: 1; transform: translate(-50%, 0); }
     80% { opacity: 1; transform: translate(-50%, 0); }
     100% { opacity: 0; transform: translate(-50%, 20px); } /* Fade out downwards */
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    body, input, button, select, textarea, a { font-size: 16px; } /* Slightly smaller base font */
    .container { width: 100%; padding: 5px 8px; height: 100vh; } /* Full width, less padding */
    nav { padding: 5px 0; margin-bottom: 5px; }
     .nav-links { gap: 10px; justify-content: center;}
     .nav-links a { font-size: 14px;}
    .controls { margin-top: 8px; justify-content: center; }
    .intro-logo { font-size: 26px; }
    .intro-text { font-size: 14px; max-width: 95%; }
    .ascii-art { font-size: 8px; line-height: 1.0; }
    .start-button { padding: 8px 18px; font-size: 16px; letter-spacing: 2px; }
    h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
    .action-btn, .cmd-btn { font-size: 12px; padding: 3px 8px; }
    #input-line { margin-top: 8px; }
    .overlay-content { width: 90%; max-height: 75vh; padding: 15px 20px;}
     .stat-item { font-size: 14px; }
     .notification { width: 90%; bottom: 10px; }
     #crt-overlay { background-size: 100% 2px; } /* Thinner scanlines on mobile */
}
 @media (max-width: 480px) {
      nav { flex-direction: column; align-items: center; }
      .nav-links { margin-bottom: 10px; }
 }
