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

/* Reset and base styles */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background: #121010;
    font-family: 'VT323', monospace;
    font-size: 20px;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    color: #33ff33;
}

/* CRT container */
#crt {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    background: #1a1a1a;
    overflow: hidden;
}

/* Scanlines effect */
#crt::before {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    z-index: 2;
    pointer-events: none;
    animation: scanlines 8s linear infinite;
    will-change: background-position; /* GPU acceleration */
}

/* Moving scanlines animation */
@keyframes scanlines {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 0 10px;
    }
}

/* Terminal screen */
.terminal {
    position: absolute;
    top: 3%;
    left: 3%;
    width: 94%;
    height: 94%;
    background: #000000;
    border-radius: 30px / 25px; /* Subtle CRT curvature */
    padding: 40px;
    overflow: hidden;
    box-shadow:
        inset 0 0 100px rgba(0, 0, 0, 0.8),
        0 0 40px rgba(51, 255, 51, 0.5);
    transform: perspective(1000px) rotateX(0.5deg); /* Slight CRT depth */
}

/* Screen content container */
.screen {
    height: calc(100% - 50px); /* Leave space for progress bar */
    overflow: hidden; /* Disable scrolling */
    position: relative;
    z-index: 5;
}

/* Terminal content container */
.terminal-content {
    display: none; /* Initially hidden during boot */
    height: 100%; /* Full height of screen */
    overflow-y: auto; /* Enable vertical scrolling */
    overflow-x: hidden; /* No horizontal scrolling */
    padding: 20px;
    font-family: 'VT323', monospace;
    font-size: 18px;
    line-height: 1.4;
    color: #33ff33;
    text-shadow:
        0 0 1px #33ff33,
        0 0 2px rgba(51, 255, 51, 0.5),
        0 0 4px rgba(51, 255, 51, 0.2); /* Enhanced phosphor glow */
    white-space: pre-wrap;
    word-wrap: break-word;
    transition: opacity 0.2s ease-in-out;
}

/* Show content after boot */
.booted .terminal-content {
    display: block;
}

/* Progress bar container at bottom */
.progress-bar-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: #000000;
    border-top: 2px solid #33ff33;
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 10;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: rgba(51, 255, 51, 0.2);
    border-radius: 4px;
    overflow: hidden;
    margin-right: 15px;
}

.progress-fill {
    height: 100%;
    background: #33ff33;
    width: 0%;
    transition: width 0.2s ease-out;
    box-shadow: 0 0 10px #33ff33;
}

.progress-text {
    font-family: 'VT323', monospace;
    font-size: 16px;
    color: #33ff33;
    text-shadow: 0 0 5px #33ff33;
    min-width: 40px;
    text-align: right;
}

/* Screen reflection effect */
.terminal::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.03) 0%,
        rgba(255, 255, 255, 0.01) 30%,
        transparent 50%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 6;
    border-radius: inherit;
}

/* Vignette effect */
.terminal::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(
        ellipse at center,
        transparent 0%,
        transparent 65%,
        rgba(0, 0, 0, 0.7) 100%
    );
    pointer-events: none;
    z-index: 4;
}

/* Flicker effect */
.flicker {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: rgba(18, 16, 16, 0.2);
    opacity: 0;
    z-index: 3;
    pointer-events: none;
    animation: flicker 0.15s infinite;
    will-change: opacity; /* GPU acceleration */
    transform: translateZ(0); /* Force GPU layer */
}

@keyframes flicker {
    0% { opacity: 0.18; }
    10% { opacity: 0.15; }
    20% { opacity: 0.19; }
    30% { opacity: 0.16; }
    40% { opacity: 0.18; }
    50% { opacity: 0.15; }
    60% { opacity: 0.17; }
    70% { opacity: 0.16; }
    80% { opacity: 0.18; }
    90% { opacity: 0.15; }
    100% { opacity: 0.18; }
}

/* Subtle glow effect without blur */
@keyframes textShadow {
    0%, 100% {
        text-shadow: 0 0 2px #33ff33;
    }
}

/* Power on effect */
@keyframes turn-on {
    0% {
        transform: scale(1, 0.8) translate(0, 0);
        filter: brightness(30);
        opacity: 1;
    }
    5% {
        transform: scale(1, 0.6) translate(0, 0);
        filter: brightness(30);
        opacity: 1;
    }
    10% {
        transform: scale(1.3, 0.6) translate(0, 0);
        filter: brightness(30);
        opacity: 1;
    }
    15% {
        transform: scale(1, 1) translate(0, 0);
        filter: brightness(1);
        opacity: 1;
    }
}

.terminal {
    animation: turn-on 0.5s linear;
}

/* Typography with CRT effects */
h1, h2, h3 {
    color: #33ff33;
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: 20px;
    animation: textShadow 1.6s infinite;
}

h1 {
    font-size: 48px;
    text-align: center;
}

h2 {
    font-size: 36px;
}

h3 {
    font-size: 28px;
}

p, pre, li {
    color: #33ff33;
    text-shadow: 0 0 1px #33ff33; /* Minimal shadow for clarity */
    line-height: 1.6;
}

pre {
    font-size: 18px;
    line-height: 1.4;
    white-space: pre-wrap; /* Enable word wrapping */
    word-wrap: break-word; /* Break long words */
    overflow-wrap: break-word; /* Modern word breaking */
    overflow-x: hidden; /* No horizontal scroll */
    animation: textShadow 1.6s infinite;
    background: transparent;
    border: none;
    padding: 0;
    margin: 15px 0;
    max-width: 100%;
}

code {
    color: #66ff66;
    background: rgba(0, 255, 0, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'VT323', monospace;
}

a {
    color: #66ff66;
    text-decoration: none;
    animation: textShadow 1.6s infinite;
}

a:hover {
    color: #99ff99;
    text-decoration: underline;
}

/* Terminal prompt styling */
.command {
    color: #33ff33;
}

.output {
    color: #66ff66;
}

.comment {
    color: #228822;
    font-style: italic;
}

/* theAdversary tactical log entries - intercepted C2 traffic */
.adversary-log {
    color: #ff6633;
    font-size: 0.9em;
    opacity: 0.85;
    letter-spacing: 0.5px;
}

.error {
    color: #ff3333;
    animation: textShadow 1.6s infinite;
}

/* Cursor blink */
.cursor {
    display: inline-block;
    width: 10px;
    height: 20px;
    background-color: #33ff33;
    animation: blink 1s step-start infinite;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* Boot sequence */
.boot-sequence {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; /* Full height */
    background-color: transparent;
    color: #33ff33;
    font-family: 'VT323', monospace;
    padding: 40px;
    overflow-y: auto;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.boot-text {
    max-width: 800px;
    width: 100%;
}

.boot-line {
    margin-bottom: 5px;
    font-size: 20px;
    opacity: 0;
    animation: typeIn 0.1s ease-out forwards;
}

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

/* Typewriter effect styles */
.typewriter {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid #33ff33;
    animation: typing 0.5s steps(40, end), blink-caret 1s step-end infinite;
}

.typewriter.line-complete {
    border-right: none;
    white-space: pre-wrap;
}

@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blink-caret {
    from, to { border-color: transparent; }
    50% { border-color: #33ff33; }
}

/* Chapter sections */
.chapter {
    margin-bottom: 60px;
    padding-bottom: 20px;
}

.chapter:last-child {
    margin-bottom: 100px; /* Extra space at the end for comfortable reading */
}

/* Scrollbar styling for terminal content */
.terminal-content::-webkit-scrollbar {
    width: 12px;
}

.terminal-content::-webkit-scrollbar-track {
    background: #0a0a0a;
    border-radius: 10px;
}

.terminal-content::-webkit-scrollbar-thumb {
    background: #33ff33;
    border-radius: 10px;
    box-shadow: 0 0 10px #33ff33;
}

.terminal-content::-webkit-scrollbar-thumb:hover {
    background: #66ff66;
}

/* Chapter navigation */
.chapter-nav {
    position: relative;
    font-family: 'VT323', monospace;
    display: none; /* Hidden until boot completes */
    margin-left: 15px;
}

.chapter-nav.visible {
    display: block;
}

.chapter-nav-toggle {
    background: transparent;
    border: 1px solid #33ff33;
    color: #33ff33;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 4px;
    transition: background-color 0.2s, box-shadow 0.2s;
}

.chapter-nav-toggle:hover,
.chapter-nav-toggle:focus {
    background: rgba(51, 255, 51, 0.1);
    box-shadow: 0 0 10px rgba(51, 255, 51, 0.3);
}

.nav-icon {
    border: solid #33ff33;
    border-width: 0 2px 2px 0;
    display: inline-block;
    padding: 3px;
    transform: rotate(45deg);
    transition: transform 0.2s;
}

.chapter-nav-toggle[aria-expanded="true"] .nav-icon {
    transform: rotate(-135deg);
}

.chapter-list {
    display: none;
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 5px;
    background: rgba(0, 0, 0, 0.95);
    border: 1px solid #33ff33;
    border-radius: 4px;
    list-style: none;
    padding: 5px 0;
    min-width: 220px;
    max-height: 60vh;
    overflow-y: auto;
}

.chapter-nav-toggle[aria-expanded="true"] + .chapter-list {
    display: block;
}

.chapter-list li a {
    display: block;
    padding: 8px 15px;
    color: #33ff33;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s;
    font-size: 14px;
}

.chapter-list li a:hover,
.chapter-list li a:focus {
    background: rgba(51, 255, 51, 0.2);
    outline: none;
}

.chapter-list li a.active {
    background: rgba(51, 255, 51, 0.15);
    border-left: 3px solid #33ff33;
    padding-left: 12px;
}

/* Chapter list scrollbar */
.chapter-list::-webkit-scrollbar {
    width: 8px;
}

.chapter-list::-webkit-scrollbar-track {
    background: #0a0a0a;
}

.chapter-list::-webkit-scrollbar-thumb {
    background: #33ff33;
    border-radius: 4px;
}

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: #000;
    color: #33ff33;
    padding: 10px 20px;
    border: 2px solid #33ff33;
    z-index: 1000;
    font-family: 'VT323', monospace;
    font-size: 18px;
    text-decoration: none;
    transition: top 0.2s;
}

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

/* Focus styles for accessibility */
:focus-visible {
    outline: 2px solid #33ff33;
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

a:focus-visible,
button:focus-visible {
    outline: 2px solid #33ff33;
    outline-offset: 2px;
    box-shadow: 0 0 10px rgba(51, 255, 51, 0.5);
}

.terminal-content:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px rgba(51, 255, 51, 0.3);
}

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

/* Tablet responsive */
@media (max-width: 1024px) and (min-width: 769px) {
    body {
        font-size: 18px;
    }

    .terminal {
        padding: 30px;
        top: 2.5%;
        left: 2.5%;
        width: 95%;
        height: 95%;
    }

    h1 {
        font-size: 40px;
    }

    h2 {
        font-size: 30px;
    }

    h3 {
        font-size: 24px;
    }

    pre {
        font-size: 16px;
    }
}

/* Mobile responsive */
@media (max-width: 768px) {
    body {
        font-size: 16px;
    }

    .terminal {
        padding: 15px;
        top: 1%;
        left: 1%;
        width: 98%;
        height: 98%;
        border-radius: 10px;
    }

    .screen {
        height: calc(100% - 40px);
    }

    .terminal-content {
        padding: 10px;
    }

    .progress-bar-container {
        height: 35px;
        padding: 0 10px;
    }

    h1 {
        font-size: 28px;
        letter-spacing: 1px;
    }

    h2 {
        font-size: 22px;
        letter-spacing: 1px;
    }

    h3 {
        font-size: 18px;
    }

    pre {
        font-size: 13px;
        line-height: 1.3;
    }

    .chapter {
        margin-bottom: 40px;
    }

    .chapter-nav {
        margin-left: 10px;
    }

    .chapter-list {
        max-height: 50vh;
    }
}

/* Small phones */
@media (max-width: 400px) {
    .terminal {
        padding: 10px;
    }

    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 18px;
    }

    h3 {
        font-size: 16px;
    }

    pre {
        font-size: 12px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

@media (prefers-contrast: high) {
    body {
        background: #000000;
    }
    
    .terminal {
        border: 2px solid #ffffff;
    }
    
    h1, h2, h3, p, pre, a {
        color: #ffffff;
        text-shadow: none;
    }
}