: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);
}

.file-content {
    color: var(--text-file);
    max-width: 100ch;
}

hr {
    border: none;
    background: none;
    margin: 1em 0;
    max-width: 100ch;
    height: auto;
    overflow: hidden;
    color: var(--text-dim);
}

hr::before {
    content: '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -';
    display: block;
    word-break: break-all;
    white-space: nowrap;
    overflow: hidden;
    text-shadow: 0 0 4px var(--text-dim);
}

.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;
    background: none;
    border: none;
    font: inherit;
}

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

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

/* TUI Dialog */
.tui-dialog {
    margin: 8px 0;
    user-select: none;
}

.tui-box {
    color: var(--text-color);
    white-space: pre;
    line-height: 1.4;
    margin: 0;
    font-size: inherit;
}

.tui-option {
    cursor: pointer;
    color: var(--text-dim);
    padding: 0;
    white-space: pre;
    line-height: 1.4;
}

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

.tui-option-selected {
    color: var(--text-bright);
    text-shadow: 0 0 6px var(--text-color), 0 0 12px var(--text-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);
}

/* Tables */
table {
    border-collapse: collapse;
    margin: 0.5em 0;
}

th, td {
    padding: 0.4em 1.2em;
    text-align: left;
    border: 1px solid var(--text-dim);
}

th {
    color: var(--text-bright);
    background: rgba(0, 255, 65, 0.05);
}

td {
    color: var(--text-file);
}

/* Flag Notifications */
.flag-notification-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 255, 65, 0);
    z-index: 10000;
    pointer-events: none;
}

.flag-notification-overlay.flash {
    animation: screen-flash 0.4s ease-out forwards;
}

.flag-notification-overlay.dismiss-flash {
    animation: screen-dismiss-flash 0.4s ease-out forwards;
}

@keyframes screen-flash {
    0% { background: rgba(0, 255, 65, 0.3); }
    100% { background: rgba(0, 255, 65, 0); }
}

@keyframes screen-dismiss-flash {
    0% { background: rgba(255, 255, 255, 0); }
    15% { background: rgba(255, 255, 255, 0.4); }
    100% { background: rgba(255, 255, 255, 0); }
}

.flag-notification {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0) rotate(-10deg);
    background: var(--bg-color);
    border: 3px solid var(--text-color);
    padding: 24px 32px;
    z-index: 10001;
    opacity: 0;
    max-width: 450px;
    min-width: 320px;
    box-shadow:
        0 0 20px var(--text-color),
        0 0 40px var(--text-color),
        0 0 60px rgba(0, 255, 65, 0.5),
        inset 0 0 20px rgba(0, 255, 65, 0.1);
}

.flag-notification.visible {
    animation: flag-entrance 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.flag-notification.visible::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border: 3px solid var(--text-color);
    animation: border-pulse 1s ease-in-out infinite;
}

@keyframes flag-entrance {
    0% {
        opacity: 0;
        transform: translate(-50%, -150%) scale(0.3) rotate(-15deg);
        filter: blur(10px);
    }
    40% {
        opacity: 1;
        transform: translate(-50%, -40%) scale(1.15) rotate(3deg);
        filter: blur(0);
    }
    55% {
        transform: translate(-50%, -55%) scale(0.95) rotate(-2deg);
    }
    70% {
        transform: translate(-50%, -48%) scale(1.05) rotate(1deg);
    }
    85% {
        transform: translate(-50%, -51%) scale(0.98) rotate(-0.5deg);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
        filter: blur(0);
    }
}

@keyframes border-pulse {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 10px var(--text-color);
    }
    50% {
        opacity: 0.5;
        box-shadow: 0 0 20px var(--text-color), 0 0 30px var(--text-color);
    }
}

.flag-notification.dismissing,
.flag-notification.visible.dismissing {
    animation: flag-exit 0.5s cubic-bezier(0.4, 0, 1, 1) forwards !important;
}

@keyframes flag-exit {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
        filter: brightness(1) blur(0);
    }
    15% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.05);
        filter: brightness(1.2) blur(0);
        box-shadow:
            0 0 30px var(--text-color),
            0 0 60px var(--text-color);
    }
    40% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.5);
        filter: brightness(0.5) blur(1px);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0);
        filter: brightness(0) blur(4px);
    }
}

/* Burst rings */
.flag-notification-burst {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: -1;
}

.flag-notification-burst::before,
.flag-notification-burst::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border: 2px solid var(--text-color);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
}

.flag-notification.visible .flag-notification-burst::before {
    animation: burst-ring 0.8s 0.1s ease-out forwards;
}

.flag-notification.visible .flag-notification-burst::after {
    animation: burst-ring 0.8s 0.25s ease-out forwards;
}

@keyframes burst-ring {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(3);
        opacity: 0;
    }
}

/* Particle explosion */
.flag-notification-particles {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
}

.flag-notification-particles span {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--text-color);
    box-shadow: 0 0 6px var(--text-color);
}

.flag-notification.visible .flag-notification-particles span:nth-child(1) { animation: particle 0.8s 0.05s ease-out forwards; --angle: 0deg; }
.flag-notification.visible .flag-notification-particles span:nth-child(2) { animation: particle 0.8s 0.1s ease-out forwards; --angle: 45deg; }
.flag-notification.visible .flag-notification-particles span:nth-child(3) { animation: particle 0.8s 0.05s ease-out forwards; --angle: 90deg; }
.flag-notification.visible .flag-notification-particles span:nth-child(4) { animation: particle 0.8s 0.15s ease-out forwards; --angle: 135deg; }
.flag-notification.visible .flag-notification-particles span:nth-child(5) { animation: particle 0.8s 0.05s ease-out forwards; --angle: 180deg; }
.flag-notification.visible .flag-notification-particles span:nth-child(6) { animation: particle 0.8s 0.1s ease-out forwards; --angle: 225deg; }
.flag-notification.visible .flag-notification-particles span:nth-child(7) { animation: particle 0.8s 0.05s ease-out forwards; --angle: 270deg; }
.flag-notification.visible .flag-notification-particles span:nth-child(8) { animation: particle 0.8s 0.15s ease-out forwards; --angle: 315deg; }

@keyframes particle {
    0% {
        transform: rotate(var(--angle)) translateY(0) scale(1);
        opacity: 1;
    }
    100% {
        transform: rotate(var(--angle)) translateY(150px) scale(0);
        opacity: 0;
    }
}

/* Corner flares */
.flag-notification-flare {
    position: absolute;
    width: 40px;
    height: 40px;
    background: var(--text-color);
    opacity: 0;
    filter: blur(10px);
}

.flag-notification-flare:nth-child(1) { top: -20px; left: -20px; }
.flag-notification-flare:nth-child(2) { top: -20px; right: -20px; }
.flag-notification-flare:nth-child(3) { bottom: -20px; left: -20px; }
.flag-notification-flare:nth-child(4) { bottom: -20px; right: -20px; }

.flag-notification.visible .flag-notification-flare {
    animation: flare 0.6s ease-out forwards;
}

@keyframes flare {
    0% { opacity: 0; transform: scale(0); }
    50% { opacity: 1; transform: scale(1.5); }
    100% { opacity: 0; transform: scale(2); }
}

.flag-notification-content {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 1;
}

.flag-notification-icon {
    font-size: 48px;
    flex-shrink: 0;
    animation: icon-bounce 0.6s ease-out;
    filter: drop-shadow(0 0 10px var(--text-color));
}

.flag-notification.visible .flag-notification-icon {
    animation: icon-bounce 0.6s 0.3s ease-out;
}

@keyframes icon-bounce {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.3); }
    50% { transform: scale(0.9); }
    75% { transform: scale(1.1); }
}

.flag-notification-text {
    flex: 1;
    min-width: 0;
}

.flag-notification-name {
    color: var(--text-bright);
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 6px;
    text-shadow: 0 0 10px var(--text-color);
}

.flag-notification.visible .flag-notification-name {
    animation: text-glow 1.5s ease-in-out infinite;
}

@keyframes text-glow {
    0%, 100% { text-shadow: 0 0 10px var(--text-color); }
    50% { text-shadow: 0 0 20px var(--text-color), 0 0 30px var(--text-color); }
}

.flag-notification-description {
    color: var(--text-dim);
    font-size: 14px;
}

.flag-notification-dismiss {
    background: transparent;
    border: 1px solid var(--text-dim);
    color: var(--text-dim);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    padding: 6px 12px;
    flex-shrink: 0;
    transition: all 0.2s;
}

.flag-notification-dismiss:hover {
    color: var(--text-color);
    border-color: var(--text-color);
    box-shadow: 0 0 10px var(--text-color);
}

/* Side Notifications (email/file) */
.side-notification-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9990;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 320px;
    pointer-events: none;
}

.side-notification {
    background: var(--bg-color);
    border: 1px solid var(--text-dim);
    padding: 12px 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    pointer-events: auto;
    cursor: pointer;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.side-notification.visible {
    transform: translateX(0);
    opacity: 1;
}

.side-notification.dismissing {
    transform: translateX(120%);
    opacity: 0;
}

.side-notification:hover {
    border-color: var(--text-color);
    box-shadow: 0 0 8px rgba(0, 255, 65, 0.3);
}

.side-notification-icon {
    font-size: 20px;
    flex-shrink: 0;
    line-height: 1;
}

.side-notification-content {
    flex: 1;
    min-width: 0;
}

.side-notification-title {
    color: var(--text-bright);
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.side-notification-subtitle {
    color: var(--text-dim);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.side-notification-dismiss {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.side-notification-dismiss:hover {
    color: var(--text-color);
}

/* Limit visible notifications on mobile */
@media (max-width: 600px) {
    .side-notification-container {
        right: 8px;
        top: 8px;
        max-width: calc(100vw - 16px);
    }

}
