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

:root {
    /* Dark Mode - Optimized Green Phosphor Theme */
    --bg-color: #0a0a0a;
    --text-color: #33ff33;
    --prompt-color: #00ff00;
    --border-color: #22cc22;
    --glow-color: #33ff33;
    --header-bg: #080808;
    --accent-color: #66ff66;
    --error-color: #ff3333;
    --success-color: #44ff44;
    --warning-color: #ffbb00;
    --dim-color: #1a991a;
    --scanline-opacity: 0.03;
    --text-shadow: 0 0 1px var(--glow-color);
    --font-family: 'JetBrains Mono', 'IBM Plex Mono', 'Courier New', monospace;
}

/* Light Mode - Optimized Amber Terminal Theme */
body.light-mode {
    --bg-color: #fff8e7;
    --text-color: #ff9500;
    --prompt-color: #ff8800;
    --border-color: #cc7700;
    --glow-color: #ffaa00;
    --header-bg: #fff5e0;
    --accent-color: #ffaa00;
    --error-color: #dd0000;
    --success-color: #008800;
    --warning-color: #cc6600;
    --dim-color: #aa7733;
    --scanline-opacity: 0.015;
    --text-shadow: 0 0 0.5px rgba(255, 149, 0, 0.3);
}

/* Support for system dark mode preference */
@media (prefers-color-scheme: dark) {
    :root {
        /* Dark mode is default, no changes needed */
    }
}

@media (prefers-color-scheme: light) {
    /* Auto-switch to light mode if user prefers it */
    body:not(.dark-mode-forced) {
        --bg-color: #fff8e7;
        --text-color: #ff9500;
        --prompt-color: #ff8800;
        --border-color: #cc7700;
        --glow-color: #ffaa00;
        --header-bg: #fff5e0;
        --accent-color: #ffaa00;
        --error-color: #dd0000;
        --success-color: #008800;
        --warning-color: #cc6600;
        --dim-color: #aa7733;
        --scanline-opacity: 0.015;
        --text-shadow: 0 0 0.5px rgba(255, 149, 0, 0.3);
    }
}

/* Base body styles */
body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-size: 14px;
    line-height: 1.6;
}

/* Scanline overlay effect */
.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    background: linear-gradient(
        to bottom,
        transparent 50%,
        var(--glow-color) 50%
    );
    background-size: 100% 4px;
    opacity: var(--scanline-opacity);
    animation: scanlines 8s linear infinite;
}

/* CRT monitor effect */
.scanlines::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 0%, rgba(0, 0, 0, 0.5) 100%);
    pointer-events: none;
}

.scanlines::after {
    content: "";
    position: absolute;
    inset: -8%;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.9) 100%);
    pointer-events: none;
    border-radius: 10% / 20%;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.8);
}

@keyframes scanlines {
    0% { background-position: 0 0; }
    100% { background-position: 0 10px; }
}

/* Theme toggle button */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 12px;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: 16px;
    z-index: 1000;
    transition: all 0.3s ease;
    text-shadow: var(--text-shadow);
}

.theme-toggle:hover {
    background: var(--text-color);
    color: var(--bg-color);
    box-shadow: 0 0 10px var(--glow-color);
}

.theme-toggle:focus {
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}

/* Terminal container */
.terminal-container {
    width: 100%;
    max-width: 900px;
    z-index: 2;
}

.terminal {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 20px var(--glow-color);
    animation: terminalGlow 2s ease-in-out infinite alternate, flicker 10s infinite;
}

body.light-mode .terminal {
    box-shadow: 0 0 15px var(--glow-color);
    animation: terminalGlow 2s ease-in-out infinite alternate, flicker 10s infinite;
}

@keyframes terminalGlow {
    0% { 
        box-shadow: 0 0 20px var(--glow-color);
        filter: brightness(1);
    }
    100% { 
        box-shadow: 0 0 30px var(--glow-color), 0 0 40px var(--glow-color);
        filter: brightness(1.05);
    }
}


/* Terminal header */
.terminal-header {
    background: var(--header-bg);
    padding: 10px 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
    box-shadow: inset 0 -1px 0 var(--glow-color);
}

.terminal-title {
    font-weight: 600;
    text-shadow: var(--text-shadow);
}

/* Terminal body */
.terminal-body {
    padding: 20px;
    min-height: 400px;
    max-height: 70vh;
    overflow-y: auto;
    font-size: 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--text-color) var(--bg-color);
}

.terminal-body::-webkit-scrollbar {
    width: 8px;
}

.terminal-body::-webkit-scrollbar-track {
    background: var(--bg-color);
}

.terminal-body::-webkit-scrollbar-thumb {
    background: var(--text-color);
    border-radius: 4px;
    opacity: 0.7;
}

/* Terminal output */
#terminal-output {
    white-space: pre-wrap;
    word-wrap: break-word;
    margin-bottom: 10px;
}

.output-line {
    margin-bottom: 5px;
    text-shadow: var(--text-shadow);
    animation: fadeIn 0.3s ease-in;
    user-select: text;
    cursor: text;
}

.output-line a {
    color: var(--text-color);
    text-decoration: underline;
    cursor: pointer;
    transition: opacity 0.2s;
}

.output-line a:hover {
    opacity: 0.8;
    color: var(--accent-color);
    text-shadow: 0 0 8px var(--glow-color);
}

.copy-button {
    display: inline-block;
    margin-left: 10px;
    padding: 2px 8px;
    border: 1px solid var(--text-color);
    background: transparent;
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-button:hover {
    background: var(--text-color);
    color: var(--bg-color);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.command-line {
    color: var(--prompt-color);
    margin-top: 10px;
}

.error-line {
    color: var(--error-color);
    text-shadow: 0 0 1px var(--error-color);
}

.success-line {
    color: var(--success-color);
    text-shadow: 0 0 1px var(--success-color);
}

.dim {
    color: var(--dim-color);
    opacity: 0.8;
}

/* Input line */
.input-line {
    display: flex;
    align-items: center;
    position: relative;
}

.prompt {
    color: var(--prompt-color);
    margin-right: 8px;
    text-shadow: var(--text-shadow);
}

#typed-text {
    color: var(--text-color);
    text-shadow: var(--text-shadow);
}

/* Cursor - Full character block */
.cursor {
    display: inline-block;
    width: 10px;
    height: 1.2em;
    background: var(--accent-color);
    animation: blink 1s infinite;
    margin-left: 2px;
    vertical-align: text-bottom;
    box-shadow: 0 0 3px var(--glow-color);
}

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

/* Hidden input */
.terminal-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

/* Terminal footer */
.terminal-footer {
    padding: 10px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--header-bg);
}

.help-text {
    font-size: 12px;
    opacity: 0.7;
    text-shadow: var(--text-shadow);
}

/* Mobile input container */
.mobile-input-container {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    padding: env(safe-area-inset-bottom, 0);
}

.quick-commands {
    display: flex;
    gap: 8px;
    padding: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.quick-commands::-webkit-scrollbar {
    display: none;
}

.quick-cmd {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 16px;
    font-family: var(--font-family);
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    min-height: 44px;
    text-shadow: var(--text-shadow);
}

.quick-cmd:active {
    background: var(--text-color);
    color: var(--bg-color);
    transform: scale(0.95);
}

.mobile-input-bar {
    display: flex;
    gap: 8px;
    padding: 8px;
    align-items: center;
    background: var(--header-bg);
}

.mobile-input-field {
    flex: 1;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 12px;
    font-family: var(--font-family);
    font-size: 16px; /* Prevents zoom on iOS */
    border-radius: 4px;
    min-height: 44px;
}

.mobile-input-field:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: -1px;
}

.mobile-input-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 12px;
    font-family: var(--font-family);
    font-size: 18px;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.mobile-input-btn:active {
    background: var(--text-color);
    color: var(--bg-color);
    transform: scale(0.95);
}

.mobile-input-submit {
    background: var(--accent-color);
    color: var(--bg-color);
    border-color: var(--accent-color);
    font-weight: bold;
}

/* Scroll to bottom button */
.scroll-to-bottom {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    z-index: 99;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.scroll-to-bottom:active {
    transform: scale(0.9);
}

.scroll-to-bottom.visible {
    display: flex;
    align-items: center;
    justify-content: center;
}


/* Subtle chromatic aberration - removed for performance */

/* Screen flicker effect */
@keyframes flicker {
    0%, 92%, 94%, 100% { opacity: 1; }
    93% { opacity: 0.97; }
}


/* Responsive design - Tablets and Mobile */
@media (max-width: 768px) {
    body {
        font-size: 14px; /* Increased from 12px */
        padding: 10px;
        padding-bottom: 120px; /* Space for mobile input */
    }
    
    .terminal-body {
        padding: 15px;
        min-height: 350px;
        max-height: calc(100vh - 280px); /* Account for mobile input */
        font-size: 14px; /* Increased from 12px */
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    .theme-toggle {
        top: 10px;
        right: 10px;
        padding: 10px 14px; /* Increased for better touch target */
        font-size: 16px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .terminal-header {
        padding: 8px 12px;
    }
    
    .terminal-footer {
        padding: 8px 15px;
    }
    
    .help-text {
        font-size: 12px;
    }
    
    /* Show mobile input container on mobile */
    .mobile-input-container {
        display: block;
    }
    
    /* Hide desktop input on mobile */
    .terminal-input {
        display: none;
    }
    
    /* Adjust cursor for mobile */
    .cursor {
        display: none; /* Hide cursor on mobile */
    }
    
    /* Improve touch targets */
    .copy-button {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    /* Disable CRT effect on mobile for performance */
    .scanlines::before,
    .scanlines::after {
        display: none;
    }
    
    /* Disable text shadows on mobile for performance */
    .output-line {
        text-shadow: none;
    }
    
    /* Optimize animations for mobile */
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    /* Better word wrapping on mobile */
    .output-line {
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 14px; /* Increased from 11px */
        line-height: 1.8; /* Better readability */
    }
    
    .terminal-body {
        font-size: 14px; /* Increased from 11px */
        padding: 12px;
        min-height: 300px;
        max-height: calc(100vh - 300px); /* More space for input */
    }
    
    .terminal {
        border-radius: 6px;
    }
    
    /* Enhanced touch targets for mobile */
    .theme-toggle {
        min-width: 44px;
        min-height: 44px;
        font-size: 16px;
        padding: 10px;
    }
    
    /* Make links easier to tap */
    .output-line a {
        display: inline-block;
        padding: 4px 8px;
        margin: -4px -8px;
    }
    
    .help-text {
        font-size: 10px;
    }
}

/* Additional semantic color classes */
.warning-line {
    color: var(--warning-color);
    text-shadow: 0 0 1px var(--warning-color);
}

.accent-line {
    color: var(--accent-color);
    text-shadow: var(--text-shadow);
}

.info-line {
    color: var(--text-color);
    opacity: 0.9;
}

/* Enhanced focus indicators */
.copy-button:focus,
.theme-toggle:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(var(--glow-color), 0.2);
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --text-color: #44ff44;
        --bg-color: #000000;
        --text-shadow: none;
        --scanline-opacity: 0;
    }
    
    body.light-mode {
        --text-color: #aa4400;
        --bg-color: #ffffff;
        --text-shadow: none;
        --scanline-opacity: 0;
    }
}

/* Focus styles for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--text-color);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .theme-toggle,
    .scanlines,
    .cursor,
    .terminal-footer {
        display: none;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
    
    .terminal {
        border: 1px solid black !important;
        box-shadow: none !important;
        background: white !important;
    }
    
    .terminal-header {
        background: #f0f0f0 !important;
        border-bottom: 1px solid black !important;
    }
    
    .output-line,
    .prompt,
    #typed-text {
        color: black !important;
        text-shadow: none !important;
    }
}