@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

:root {
    --dos-green: #ffffff;
    --dos-bg: #000000;
    --dos-highlight: #333333;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    background-color: var(--dos-bg);
    color: var(--dos-green);
    font-family: 'VT323', monospace;
    font-size: 22px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* CRT Scanline Effect */
body::after {
    content: " ";
    display: block;
    position: fixed;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
                linear-gradient(90deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.04));
    z-index: 999;
    background-size: 100% 4px, 6px 100%;
    pointer-events: none;
}

/* --- PACMAN LOADER --- */
#loader-screen {
    display: flex;
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background-color: var(--dos-bg);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-text {
    margin-bottom: 20px;
    animation: blink 1s step-end infinite;
}

.pacman-container {
    position: relative;
    width: 100%;
    max-width: 300px;
    height: 40px;
    overflow: hidden;
    border: 2px solid var(--dos-green);
    padding: 5px;
}

.dots {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    height: 6px;
    background-image: radial-gradient(var(--dos-green) 40%, transparent 40%);
    background-size: 30px 30px;
    background-position: center;
}

.pacman {
    position: absolute;
    top: 5px;
    left: -40px;
    width: 0; height: 0;
    border-right: 20px solid transparent;
    border-top: 20px solid yellow;
    border-left: 20px solid yellow;
    border-bottom: 20px solid yellow;
    border-radius: 50%;
    animation: movePacman 3.5s linear forwards, chomp 0.4s infinite;
    z-index: 1;
}

.pacman::after {
    content: '';
    position: absolute;
    top: -20px;
    left: -300px;
    width: 300px;
    height: 40px;
    background-color: var(--dos-bg);
    z-index: -1;
}

@keyframes chomp {
    0%, 100% { border-right-color: transparent; }
    50%       { border-right-color: yellow; }
}

@keyframes movePacman {
    0%   { left: -40px; }
    100% { left: 320px; }
}

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

/* --- MAIN INTERFACE --- */
.dos-interface {
    display: none;
    width: 95vw;
    height: 95vh;
    grid-template-columns: 300px 1fr;
    grid-template-rows: auto 1fr auto;
    gap: 10px;
    padding: 10px;
    box-sizing: border-box;
    z-index: 10;
}

/* JS adds this class on boot — CSS then controls the grid per breakpoint */
.dos-interface.is-visible {
    display: grid;
    overflow: hidden; /* prevent any panel from escaping the grid boundary */
}

.panel {
    border: 6px double var(--dos-green);
    padding: 40px 15px 15px 15px;
    position: relative;
    background-color: var(--dos-bg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.header-panel,
.footer-panel {
    padding: 5px 15px;
    flex-direction: row;
}

.header-panel {
    grid-column: 1 / -1;
    justify-content: space-between;
    align-items: center;
}

.footer-panel {
    grid-column: 1 / -1;
    justify-content: space-between;
}

.sidebar-panel { grid-column: 1 / 2; }

.main-panel {
    grid-column: 2 / 3;
    /* Let grid row control height — overflow-y:auto on .panel handles scroll */
    align-self: stretch;
}

.panel-title {
    position: absolute;
    top: -14px;
    left: 15px;
    background-color: var(--dos-bg);
    padding: 0 10px;
    font-size: 20px;
    z-index: 5;
}

.sidebar-title {
    text-decoration: underline;
    margin-bottom: 10px;
}

.nav-item {
    cursor: pointer;
    padding: 5px;
    display: block;
    transition: background 0.1s;
}

.nav-item:hover {
    background-color: var(--dos-highlight);
    color: #fff;
}

/* --- TERMINAL STYLES --- */
#terminal-content {
    display: block;
    width: 100%;
}

#terminal-output {
    word-break: break-word;
    overflow-wrap: break-word;
}

.cursor {
    display: inline-block;
    width: 12px;
    height: 24px;
    background-color: var(--dos-green);
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
}

#command-line {
    display: none;
    margin-top: 10px;
    align-items: center;
    width: 100%;
    position: relative;
}

.prompt { margin-right: 10px; }

#cmd-display {
    display: flex;
    align-items: center;
    font-family: 'VT323', monospace;
    font-size: 22px;
    color: var(--dos-green);
    white-space: pre;
}

#cmd-cursor {
    display: inline-block;
    width: 12px;
    height: 24px;
    background-color: var(--dos-green);
    animation: blink 1s step-end infinite;
    margin-left: 2px;
}

#cmd-input {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0;
    color: transparent;
    border: none;
    background: transparent;
    font-family: 'VT323', monospace;
    font-size: 22px;
    outline: none;
    cursor: text;
    letter-spacing: normal;
}

/* Position context for pixel-reveal canvas */
.output-line {
    white-space: pre-wrap;
    margin-bottom: 5px;
    word-wrap: break-word;
    position: relative;
}

/* --- HYPERLINKS & IMAGES --- */
a.retro-link {
    color: var(--dos-green);
    text-decoration: underline;
    cursor: pointer;
}

a.retro-link:hover {
    background-color: var(--dos-green);
    color: var(--dos-bg);
    text-decoration: none;
}

img.retro-img {
    max-width: 100%;
    height: auto;
    border: 2px dashed var(--dos-green);
    display: block;
    position: relative; /* canvas overlay aligns to image */
    margin: 10px 0;
    filter: grayscale(100%) contrast(1.2) brightness(1.05);
}

/* --- LIGHTBOX --- */
#retro-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9000;
    align-items: center;
    justify-content: center;
}

#retro-lightbox.lb-open {
    display: flex;
}

#lb-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    cursor: pointer;
}

#lb-frame {
    position: relative;
    z-index: 9001;
    border: 6px double var(--dos-green);
    background: var(--dos-bg);
    display: flex;
    flex-direction: column;
    max-width: 90vw;
    max-height: 90vh;
    width: auto;
}

#lb-titlebar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 10px;
    border-bottom: 2px solid var(--dos-green);
    background: var(--dos-green);
    color: var(--dos-bg);
    font-family: 'VT323', monospace;
    font-size: 18px;
    user-select: none;
}

#lb-close {
    cursor: pointer;
    padding: 0 4px;
}

#lb-close:hover {
    background: var(--dos-bg);
    color: var(--dos-green);
}

#lb-img-wrap {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 0;
}

#lb-img {
    display: block;
    max-width: 85vw;
    max-height: 75vh;
    width: auto;
    height: auto;
    object-fit: contain;
    filter: grayscale(80%) contrast(1.15);
    transition: opacity 0.15s ease;
    border: none;
    margin: 0;
}

/* scanlines over lightbox image */
#lb-scanlines {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0,0,0,0) 0px, rgba(0,0,0,0) 2px,
        rgba(0,0,0,0.18) 2px, rgba(0,0,0,0.18) 4px
    );
    pointer-events: none;
}

#lb-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    border-top: 2px solid var(--dos-green);
    font-family: 'VT323', monospace;
    font-size: 18px;
    user-select: none;
}

#lb-prev, #lb-next {
    cursor: pointer;
    padding: 2px 6px;
}

#lb-prev:hover, #lb-next:hover {
    background: var(--dos-green);
    color: var(--dos-bg);
}

#lb-counter {
    color: var(--dos-green);
    opacity: 0.7;
    font-size: 16px;
}

@media (max-width: 768px) {
    #lb-frame {
        max-width: 98vw;
        max-height: 95vh;
    }
    #lb-img {
        max-width: 95vw;
        max-height: 78vh;
    }
    #lb-nav {
        font-size: 20px;
        padding: 8px 10px;
    }
    #lb-prev, #lb-next {
        padding: 4px 10px;
    }
}

/* --- GALLERY GRID --- */
.retro-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
    margin: 10px 0;
}

/* Wrapper div around each gallery img — fixed size, canvas stays inside */
.retro-gallery-img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    margin: 0;
    cursor: pointer;
    display: block;
    transition: filter 0.2s;
    position: relative;
}

.retro-gallery-img:hover {
    filter: grayscale(0%) contrast(1.2) brightness(1.1) !important;
}

@media (max-width: 768px) {
    .retro-gallery {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 5px;
    }
    .retro-gallery-img {
        height: 90px;
    }
}
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin: 8px 0;
}

.retro-flex img.retro-img {
    width: 260px;
    min-width: 260px;
    flex-shrink: 0;
}

/* --- MOBILE --- */
@media (max-width: 768px) {

    /* Let the page scroll naturally on mobile */
    body, html {
        overflow: auto;
        height: auto;
        align-items: flex-start;
        min-height: 100%;
    }

    .dos-interface.is-visible {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr auto;
        width: 100vw;
        height: auto;
        min-height: 100dvh;
        padding: 4px;
        gap: 5px;
    }

    .header-panel {
        flex-wrap: wrap;
        gap: 4px;
        font-size: 16px;
    }

    .sidebar-panel {
        grid-column: 1 / -1;
        max-height: 200px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .main-panel {
        grid-column: 1 / -1;
        /* grow with content, don't clip */
        overflow-y: visible;
        height: auto;
        min-height: 50vh;
    }

    .footer-panel {
        flex-direction: column;
        text-align: center;
        gap: 4px;
    }

    /* Stack retro-flex project layout vertically on mobile */
    .retro-flex {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .retro-flex img.retro-img {
        width: 100% !important;
        min-width: unset !important;
        max-width: 100% !important;
    }

    /* Command line input bar — sticky at bottom on mobile */
    #command-line {
        position: sticky;
        bottom: 0;
        background-color: var(--dos-bg);
        padding: 6px 0;
        z-index: 50;
    }

    /* Larger tap targets in sidebar on mobile */
    .nav-item {
        padding: 10px 5px;
        font-size: 20px;
    }
}

