:root {
    --bg-color: #0a0a0a;
    --text-color: #00ff41;
    --text-dim: #00aa2a;
    --text-bright: #33ff66;
    --text-file: #9a9a9a;
    --prompt-color: #00ff41;
    --error-color: #ff3333;
    --warning-color: #ffaa00;
    --link-color: #00aaff;
    --selection-bg: #00ff4133;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    min-height: 100%;
    background: var(--bg-color);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-color);
}

body {
    overflow-y: auto;
    overflow-x: hidden;
}

::selection {
    background: var(--selection-bg);
    color: var(--text-bright);
}

/* Terminal */
.terminal {
    min-height: 100vh;
    padding: 16px;
    background: var(--bg-color);
}

/* Terminal Output */
#terminal-output {
    padding-bottom: 0;
}

.output-line {
    white-space: pre-wrap;
    word-wrap: break-word;
    margin-bottom: 2px;
}

.output-line.command {
    color: var(--text-bright);
}

.output-line.error {
    color: var(--error-color);
}

.output-line.warning {
    color: var(--warning-color);
}

.output-line.dim {
    color: var(--text-dim);
}

.output-line.file-content {
    color: var(--text-file);
}

.output-line.completions {
    color: var(--text-dim);
    font-family: inherit;
}

.output-line.link {
    color: var(--link-color);
    cursor: pointer;
    text-decoration: underline;
}

.output-line.link:hover {
    color: #33ccff;
}

/* Input Line */
.terminal-input-line {
    white-space: nowrap;
}

.prompt {
    color: var(--prompt-color);
}

/* Completions Overlay */
.completions-overlay {
    display: none;
    padding: 4px 0;
    margin-top: 4px;
    font-family: inherit;
    white-space: pre;
}

.completions-overlay.visible {
    display: block;
}

.completion-row {
    line-height: 1.4;
}

.completion-dir {
    color: var(--link-color);
}

.completion-file {
    color: var(--text-dim);
}

#terminal-input-mirror {
    color: var(--text-color);
}

#terminal-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

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

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

/* ASCII Art */
.ascii-art {
    color: var(--text-color);
    white-space: pre;
    font-size: 10px;
    line-height: 1.1;
}

@media (min-width: 600px) {
    .ascii-art {
        font-size: 12px;
    }
}

/* CRT Effects (optional, toggle with .crt class on body) */
body.crt {
    overflow-x: hidden;
    overflow-y: auto;
}

body.crt .terminal {
    animation: crt-flicker 0.15s infinite;
    text-shadow: 0 0 1px var(--text-color);
}

/* Scanlines overlay */
body.crt::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.4),
        rgba(0, 0, 0, 0.4) 1px,
        transparent 1px,
        transparent 3px
    );
    pointer-events: none;
    z-index: 9999;
}

/* Vignette and screen curvature */
body.crt::after {
    content: '';
    position: fixed;
    top: -2%;
    left: -2%;
    right: -2%;
    bottom: -2%;
    background: radial-gradient(
        ellipse at center,
        transparent 0%,
        transparent 60%,
        rgba(0, 0, 0, 0.4) 90%,
        rgba(0, 0, 0, 0.8) 100%
    );
    pointer-events: none;
    z-index: 9998;
}

/* Screen curvature container */
body.crt .terminal {
    transform: perspective(1000px) rotateX(0.5deg);
    border-radius: 20px;
    box-shadow:
        inset 0 0 60px rgba(0, 255, 65, 0.05),
        inset 0 0 120px rgba(0, 0, 0, 0.3);
}

/* Subtle CRT flicker */
@keyframes crt-flicker {
    0% { opacity: 0.97; }
    5% { opacity: 0.98; }
    10% { opacity: 0.99; }
    15% { opacity: 0.97; }
    20% { opacity: 1; }
    25% { opacity: 0.98; }
    30% { opacity: 0.99; }
    35% { opacity: 0.97; }
    40% { opacity: 1; }
    45% { opacity: 0.99; }
    50% { opacity: 0.98; }
    55% { opacity: 1; }
    60% { opacity: 0.97; }
    65% { opacity: 0.99; }
    70% { opacity: 1; }
    75% { opacity: 0.98; }
    80% { opacity: 0.97; }
    85% { opacity: 1; }
    90% { opacity: 0.99; }
    95% { opacity: 0.98; }
    100% { opacity: 1; }
}

/* Refresh line animation - uses dedicated element to avoid transform context issues */
#crt-scanline {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 16px;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        rgba(0, 255, 65, 0.4) 40%,
        rgba(255, 255, 255, 0.7) 48%,
        rgba(255, 255, 255, 0.7) 52%,
        rgba(0, 255, 65, 0.4) 60%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 9997;
    animation: crt-refresh 6s linear infinite;
    mix-blend-mode: overlay;
}

@keyframes crt-refresh {
    0% { top: -3px; }
    100% { top: 100vh; }
}

/* Chromatic aberration on text */
body.crt .output-line,
body.crt .prompt,
body.crt #terminal-input-mirror,
body.crt .ascii-art {
    text-shadow:
        -0.5px 0 rgba(255, 0, 0, 0.25),
        0.5px 0 rgba(0, 255, 255, 0.25),
        0 0 1px var(--text-color);
}

/* Enhanced glow for CRT mode */
body.crt .glow {
    text-shadow:
        -0.5px 0 rgba(255, 0, 0, 0.25),
        0.5px 0 rgba(0, 255, 255, 0.25),
        0 0 3px var(--text-color),
        0 0 6px var(--text-color);
}

/* Phosphor persistence effect on cursor */
body.crt .cursor {
    box-shadow: 0 0 3px var(--text-color);
}

/* Text Glow Effect */
.glow {
    text-shadow:
        0 0 5px var(--text-color),
        0 0 10px var(--text-color),
        0 0 20px var(--text-color);
}

/* Directory/File Listings */
.listing {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 4px 16px;
    margin: 8px 0;
}

.listing-item {
    cursor: pointer;
}

.listing-item:hover {
    color: var(--text-bright);
}

.listing-item.dir::before {
    content: '';
    color: var(--link-color);
}

.listing-item.dir {
    color: var(--link-color);
}

/* Help Table */
.help-table {
    margin: 8px 0;
}

.help-row {
    display: flex;
    gap: 16px;
    margin-bottom: 4px;
}

.help-cmd {
    min-width: 120px;
    color: var(--text-bright);
}

.help-desc {
    color: var(--text-dim);
}

/* Matrix Effect Container */
#matrix-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9998;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s;
}

#matrix-canvas.active {
    opacity: 1;
}

/* Login Page */
.login-options {
    margin: 16px 0;
}

.login-option {
    display: block;
    padding: 8px 0;
    color: var(--link-color);
    cursor: pointer;
    text-decoration: none;
}

.login-option:hover {
    color: var(--text-bright);
}

.login-option::before {
    content: '> ';
    color: var(--prompt-color);
}

/* Error Pages */
.error-code {
    font-size: 48px;
    font-weight: bold;
    color: var(--error-color);
    margin: 16px 0;
}

.error-message {
    color: var(--text-dim);
    margin-bottom: 16px;
}

/* Typing Animation */
.typing {
    overflow: hidden;
    border-right: 2px solid var(--text-color);
    white-space: nowrap;
    animation: typing 2s steps(40, end), blink-caret 0.75s step-end infinite;
}

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

@keyframes blink-caret {
    from, to { border-color: transparent; }
    50% { border-color: var(--text-color); }
}

/* Responsive */
@media (max-width: 600px) {
    .terminal {
        padding: 8px;
    }

    html, body {
        font-size: 12px;
    }
}

/* Accessibility - clickable elements */
[role="button"],
[tabindex="0"] {
    cursor: pointer;
}

[role="button"]:focus,
[tabindex="0"]:focus {
    outline: 1px dashed var(--text-color);
    outline-offset: 2px;
}

/* Page content styling */
.page-content {
    margin: 8px 0;
}

.page-content h1,
.page-content h2,
.page-content h3 {
    color: var(--text-bright);
    margin: 16px 0 8px 0;
}

.page-content h1::before { content: '# '; color: var(--text-dim); }
.page-content h2::before { content: '## '; color: var(--text-dim); }
.page-content h3::before { content: '### '; color: var(--text-dim); }

.page-content p {
    margin: 8px 0;
}

.page-content ul,
.page-content ol {
    margin: 8px 0 8px 24px;
}

.page-content li {
    margin: 4px 0;
}

.page-content li::marker {
    color: var(--text-dim);
}

.page-content code {
    background: #1a1a1a;
    padding: 2px 6px;
    border-radius: 2px;
    color: var(--warning-color);
}

.page-content pre {
    background: #1a1a1a;
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 8px 0;
}

.page-content pre code {
    background: transparent;
    padding: 0;
}

.page-content a {
    color: var(--link-color);
}

.page-content a:hover {
    color: var(--text-bright);
}

.page-content blockquote {
    border-left: 2px solid var(--text-dim);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-dim);
    font-style: italic;
}

/* API Key Display */
.apikey-display {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    background: rgba(0, 255, 65, 0.1);
    padding: 8px 12px;
    border-radius: 4px;
    margin: 4px 0;
}

.apikey-display code {
    color: var(--prompt-color);
    font-family: inherit;
    font-size: inherit;
    user-select: all;
}

.copy-btn {
    background: transparent;
    border: 1px solid var(--text-dim);
    color: var(--text-dim);
    padding: 2px 8px;
    border-radius: 3px;
    font-family: inherit;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.15s;
}

.copy-btn:hover {
    border-color: var(--text-color);
    color: var(--text-color);
}
