/* ========================================
   VARIABLES
   ======================================== */
:root {
    --primary: #00ff41;
    --primary-dim: #00cc33;
    --bg-dark: #0a0e0a;
    --bg-medium: #0f140f;
    --text-main: #00ff41;
    --text-dim: #00cc3388;
    --glow: 0 0 10px #00ff41, 0 0 20px #00ff4144;
}

/* ========================================
   RESET & BASE
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'VT323', monospace;
    background: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ========================================
   CRT EFFECTS
   ======================================== */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 255, 65, 0.03),
        rgba(0, 255, 65, 0.03) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 9999;
    animation: flicker 0.15s infinite;
}

@keyframes flicker {
    0% { opacity: 0.97; }
    50% { opacity: 1; }
    100% { opacity: 0.97; }
}

body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, transparent 0%, rgba(0, 0, 0, 0.3) 100%);
    pointer-events: none;
    z-index: 9998;
}

/* ========================================
   BOOT SCREEN
   ======================================== */
.boot-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.boot-content {
    max-width: 800px;
    padding: 2rem;
}

#bootText {
    font-size: 1.2rem;
    line-height: 1.6;
    color: var(--text-main);
    text-shadow: var(--glow);
    white-space: pre-wrap;
}

#bootProgress {
    margin-top: 2rem;
    height: 4px;
    background: var(--bg-medium);
    border: 1px solid var(--primary);
    position: relative;
    overflow: hidden;
}

#bootProgress::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--primary);
    box-shadow: var(--glow);
    animation: loading 2s ease-in-out;
}

@keyframes loading {
    0% { width: 0%; }
    100% { width: 100%; }
}

/* ========================================
   TERMINAL - DOS DOUBLE BORDER
   ======================================== */
.terminal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 95vw;
    height: 95vh;
    background: var(--bg-dark);
    
    /* DOS-style double border using box-shadow */
    border: 3px solid var(--primary);
    box-shadow: 
        /* Inner border */
        inset 0 0 0 1px var(--bg-dark),
        inset 0 0 0 4px var(--primary),
        inset 0 0 0 5px var(--bg-dark),
        /* Outer glow */
        0 0 20px rgba(0, 255, 65, 0.3),
        0 0 40px rgba(0, 255, 65, 0.1);
    
    display: flex;
    flex-direction: column;
    opacity: 0;
    animation: fadeIn 0.5s ease-out forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

/* ========================================
   TERMINAL HEADER
   ======================================== */
.terminal-header {
    padding: 1rem 1.5rem;
    border-bottom: 2px double var(--primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-medium);
}

.header-logo {
    height: 40px;
    width: 60px; /* 3:2 ratio - 60px:40px */
    object-fit: contain;
    opacity: 0.9;
}

.terminal-title {
    font-size: 1.5rem;
    letter-spacing: 0.2em;
    text-shadow: var(--glow);
}

.system-status {
    font-size: 1rem;
    color: var(--primary);
    animation: pulse 2s infinite;
}

.admin-btn {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    font-size: 1.2rem;
    width: 32px;
    height: 32px;
    cursor: pointer;
    margin-right: 1rem;
    transition: all 0.2s;
    font-family: 'VT323', monospace;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.admin-btn:hover {
    background: var(--primary);
    color: var(--bg-dark);
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.5);
}

/* Admin Modal */
.admin-modal {
    display: none;
    position: fixed;
    z-index: 10001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
}

.admin-modal-content {
    background: var(--bg-dark);
    border: 2px double var(--primary);
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--glow);
}

.admin-modal-content h2 {
    font-size: 1.8rem;
    text-align: center;
    margin-bottom: 2rem;
    text-shadow: var(--glow);
}

.admin-menu-buttons {
    display: flex;
    flex-direction: column;
}

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

/* ========================================
   TERMINAL BODY
   ======================================== */
.terminal-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ========================================
   LORE BROWSER
   ======================================== */
.lore-browser {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.lore-controls {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 2px double var(--primary);
    margin: 0;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    background: var(--bg-dark);
    z-index: 100;
}

.btn {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--text-main);
    padding: 0.5rem 1.5rem;
    font-family: 'VT323', monospace;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.btn:hover,
.btn.active {
    background: var(--primary);
    color: var(--bg-dark);
    box-shadow: var(--glow);
    text-shadow: none;
}

.search-input {
    flex: 1;
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    font-family: 'VT323', monospace;
    font-size: 1.2rem;
    min-width: 200px;
}

.search-input::placeholder {
    color: var(--text-dim);
}

.search-input:focus {
    outline: none;
    box-shadow: var(--glow);
}

.nav-dropdown {
    background: var(--bg-dark);
    border: 2px solid var(--primary);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    font-family: 'VT323', monospace;
    font-size: 1.2rem;
    cursor: pointer;
    min-width: 250px;
    accent-color: var(--primary);
}

.nav-dropdown:focus {
    outline: none;
    box-shadow: var(--glow);
}

.nav-dropdown option {
    background: var(--bg-dark);
    color: var(--text-main);
    padding: 0.5rem;
}

select.nav-dropdown option:hover,
select.nav-dropdown option:checked,
select.nav-dropdown option:focus,
select.nav-dropdown option[selected] {
    background: var(--primary) !important;
    color: var(--bg-dark) !important;
    background-color: #00ff41 !important;
}

@-moz-document url-prefix() {
    .nav-dropdown option:checked {
        background: linear-gradient(#00ff41, #00ff41);
        background-color: #00ff41 !important;
        color: #0a0e0a !important;
    }
}

.nav-dropdown::-webkit-scrollbar {
    width: 8px;
}

.nav-dropdown::-webkit-scrollbar-track {
    background: var(--bg-medium);
}

.nav-dropdown::-webkit-scrollbar-thumb {
    background: var(--primary);
    box-shadow: 0 0 5px var(--primary);
}

/* ========================================
   LORE CONTENT
   ======================================== */
.lore-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) var(--bg-medium);
}

.lore-content::-webkit-scrollbar {
    width: 8px;
}

.lore-content::-webkit-scrollbar-track {
    background: var(--bg-medium);
}

.lore-content::-webkit-scrollbar-thumb {
    background: var(--primary);
    box-shadow: 0 0 5px var(--primary);
}

/* Lore Entry Cards */
.lore-entry {
    border: 2px double var(--primary);
    padding: 1.5rem;
    margin-bottom: 1rem;
    background: rgba(0, 255, 65, 0.02);
    transition: all 0.2s;
}

.lore-entry.clickable {
    cursor: pointer;
}

.lore-entry.clickable:hover {
    background: rgba(0, 255, 65, 0.05);
    box-shadow: inset 0 0 10px rgba(0, 255, 65, 0.2);
}

.lore-entry.intro-entry {
    font-size: 1.1rem;
    line-height: 1.9;
}

.lore-entry.intro-entry h2 {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 2rem;
    text-shadow: var(--glow);
}

.lore-entry.intro-entry p {
    margin-bottom: 1.5rem;
    text-indent: 2rem;
}

.lore-entry.intro-entry em {
    color: var(--primary);
    font-style: italic;
}

.lore-entry h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    text-shadow: var(--glow);
}

.lore-entry .meta {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* Fixed: Better text formatting with proper line breaks */
.lore-entry .excerpt {
    line-height: 1.8;
    color: var(--text-main);
    white-space: pre-wrap; /* Preserve line breaks and spaces */
    word-wrap: break-word; /* Wrap long words */
}

.lore-entry .excerpt p {
    margin-bottom: 1.2rem;
}

/* Keyword Tags */
.keyword-tags {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--primary);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.keyword-tag {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 0.3rem 0.8rem;
    font-family: 'VT323', monospace;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.keyword-tag:hover {
    background: var(--primary);
    color: var(--bg-dark);
    box-shadow: 0 0 10px rgba(0, 255, 65, 0.5);
}

.keyword-tag.active {
    background: var(--primary);
    color: var(--bg-dark);
}

/* Loading State */
.loading {
    text-align: center;
    padding: 2rem;
    font-size: 1.5rem;
    color: var(--text-dim);
    animation: pulse 1.5s infinite;
}

/* Error State */
.error {
    text-align: center;
    padding: 2rem;
    font-size: 1.5rem;
    color: #ff4444;
    border: 2px double #ff4444;
    margin: 1rem;
}

/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg-dark);
    border: 2px solid var(--primary);
    color: var(--primary);
    padding: 0.75rem 1.5rem;
    font-family: 'VT323', monospace;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 1000;
    box-shadow: var(--glow);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background: var(--primary);
    color: var(--bg-dark);
}

.back-to-top:active {
    transform: scale(0.95);
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 768px) {
    .terminal {
        width: 100vw;
        height: 100vh;
        border: none;
        box-shadow: none;
    }

    .terminal-title {
        font-size: 1.2rem;
    }

    .lore-controls {
        flex-wrap: wrap;
    }

    .btn {
        font-size: 1rem;
        padding: 0.4rem 1rem;
    }

    .search-input {
        width: 100%;
        font-size: 1rem;
    }

    .keyword-tag {
        font-size: 0.9rem;
        padding: 0.25rem 0.6rem;
    }
}

/* ========================================
   UTILITY
   ======================================== */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}
