/* ==========================================================================
   CSS Variables & Themes
   ========================================================================== */

:root {
    --bg-color: #0b0f19;
    --text-color: #00ff41;
    --dim-text: #008f11;
    --highlight: #00ff41;
    --tab-bg: #111827;
    --border-color: #1f2937;
    --font-family: 'Fira Code', 'Courier New', monospace;
    --window-border: #1e293b;
    --error-color: #ff5f56;
    --overlay-fade: rgba(0, 0, 0, 0.4);
    --scanline-dark: rgba(0, 0, 0, 0.1);
    --glow-color: rgba(0, 255, 65, 0.5);
    --shadow-color: rgba(0, 255, 65, 0.05);
    --address-bar-bg: rgba(255, 255, 255, 0.05);
}

body.theme-hacker {
    --bg-color: #000000;
    --text-color: #0f0;
    --dim-text: #070;
    --highlight: #0f0;
    --tab-bg: #000;
}

body.theme-amber {
    --bg-color: #1a1100;
    --text-color: #ffb000;
    --dim-text: #b37b00;
    --highlight: #ffcc00;
    --tab-bg: #1a1100;
}

body.theme-light {
    --bg-color: #ffffff;
    --text-color: #333333;
    --dim-text: #666666;
    --highlight: #000000;
    --tab-bg: #f3f4f6;
    --border-color: #e5e7eb;
    --window-border: #d1d5db;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

body {
    background-color: #000;
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.5;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

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

/* ==========================================================================
   Accessibility
   ========================================================================== */

.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    background: var(--bg-color);
    color: var(--text-color);
    padding: 8px 16px;
    z-index: 200;
    text-decoration: none;
    font-weight: bold;
}

.skip-link:focus {
    top: 0;
}

/* ==========================================================================
   CRT Effects
   ========================================================================== */

.crt-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle, transparent 60%, var(--overlay-fade) 100%);
    pointer-events: none;
    z-index: 100;
}

.scanlines {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(to bottom, transparent, transparent 50%, var(--scanline-dark) 50%, var(--scanline-dark));
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 99;
}

/* ==========================================================================
   Terminal Container
   ========================================================================== */

.terminal-container {
    width: 95%;
    max-width: 1000px;
    height: 85vh;
    height: 85dvh;
    border: 1px solid var(--window-border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), 0 0 15px var(--shadow-color);
    position: relative;
    z-index: 10;
    overflow: hidden;
}

/* ==========================================================================
   Terminal Header & Controls
   ========================================================================== */

.terminal-header {
    border-bottom: 1px solid var(--border-color);
    background-color: var(--tab-bg);
    padding: 10px 0;
    display: flex;
    align-items: center;
}

.window-controls {
    display: flex;
    align-items: center;
    padding: 0 15px;
    gap: 8px;
}

.control {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.close { background-color: var(--error-color); }
.minimize { background-color: #ffbd2e; }
.maximize { background-color: #27c93f; }

.address-bar {
    background: var(--address-bar-bg);
    padding: 4px 15px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--dim-text);
    min-width: 250px;
    text-align: center;
}

/* ==========================================================================
   Status Bar & Tabs
   ========================================================================== */

.status-bar {
    display: flex;
    justify-content: space-between;
    padding: 8px 20px;
    font-size: 12px;
    border-bottom: 1px solid var(--border-color);
    font-weight: bold;
}

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

.tabs-bar {
    display: flex;
    padding: 10px 20px 0;
    border-bottom: 1px solid var(--border-color);
}

.tab {
    padding: 6px 16px;
    background-color: transparent;
    color: var(--dim-text);
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    border: none;
    font-family: var(--font-family);
    user-select: none;
    transition: color 0.15s;
}

.tab:hover {
    color: var(--text-color);
}

.tab.active {
    color: var(--text-color);
    border-bottom: 2px solid var(--highlight);
    cursor: default;
}

.tab-close {
    opacity: 0.4;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    margin-left: 2px;
}

.tab-close:hover {
    opacity: 1;
    color: var(--error-color);
}

.tab-add {
    font-size: 16px;
    font-weight: bold;
}

/* Session containers (tab panels) */
.session-content {
    display: none;
}

.session-content.active {
    display: block;
}

/* ==========================================================================
   Terminal Body & Content
   ========================================================================== */

.terminal-body {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--dim-text) var(--bg-color);
}

.terminal-body::-webkit-scrollbar {
    width: 8px;
}
.terminal-body::-webkit-scrollbar-track {
    background: var(--bg-color);
}
.terminal-body::-webkit-scrollbar-thumb {
    background-color: var(--dim-text);
    border-radius: 4px;
}

.ascii-art {
    white-space: pre;
    font-weight: bold;
    margin-bottom: 15px;
    text-shadow: 0 0 5px var(--glow-color);
    line-height: 1.1;
    font-size: 14px;
    color: var(--highlight);
}

.subtitle {
    color: var(--dim-text);
    margin-bottom: 30px;
}

.welcome-box {
    margin-bottom: 30px;
    display: inline-block;
}

.welcome-box p {
    margin: 5px 0;
}

.highlight {
    color: var(--highlight);
    font-weight: bold;
}

/* ==========================================================================
   Clickable Commands (button reset)
   ========================================================================== */

.clickable {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dashed;
    text-underline-offset: 4px;
    transition: all 0.2s ease;
}

.clickable:hover,
.clickable:focus-visible {
    background-color: var(--text-color);
    color: var(--bg-color) !important;
    text-decoration: none;
}

button.cmd-link {
    background: none;
    border: none;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    padding: 0;
    font-weight: inherit;
    line-height: inherit;
    color: var(--highlight);
}

/* ==========================================================================
   Output Area
   ========================================================================== */

#output {
    margin-bottom: 20px;
    width: 100%;
}

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

.output-cmd {
    display: flex;
    margin-top: 15px;
    margin-bottom: 5px;
}

/* ==========================================================================
   Terminal Input
   ========================================================================== */

.terminal-input-area {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-color);
    position: relative;
}

.prompt {
    color: var(--text-color);
    font-weight: bold;
    margin-right: 15px;
    white-space: nowrap;
}

#cmd-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: var(--font-family);
    font-size: 14px;
    outline: none;
    font-weight: bold;
}

.type-hint {
    color: var(--dim-text);
    font-size: 12px;
    opacity: 0.5;
    position: absolute;
    right: 20px;
}

/* ==========================================================================
   Error & Tables
   ========================================================================== */

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

table {
    border-collapse: collapse;
    width: 100%;
    max-width: 600px;
    margin: 10px 0;
}

th, td {
    text-align: left;
    padding: 6px 12px;
}

th {
    color: var(--dim-text);
    border-bottom: 1px dotted var(--dim-text);
}

/* ==========================================================================
   Matrix Canvas
   ========================================================================== */

#matrix-canvas-container {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 5;
    background-color: #000;
}

/* ==========================================================================
   Boot Animation
   ========================================================================== */

.boot-line {
    font-size: 12px;
    color: var(--dim-text);
    margin-bottom: 2px;
}

.boot-ok   { color: #27c93f; }
.boot-warn { color: #ffbd2e; }

/* ==========================================================================
   Help Table Extras
   ========================================================================== */

.help-section-header {
    padding-top: 12px;
    color: var(--dim-text);
    font-weight: bold;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 1px;
}

.help-hint {
    margin-top: 10px;
    color: var(--dim-text);
    font-size: 12px;
}

/* ==========================================================================
   Vim / Nano Screen
   ========================================================================== */

.vim-screen {
    border: 1px solid var(--border-color);
    margin: 8px 0;
    font-family: var(--font-family);
}

.vim-content {
    color: var(--dim-text);
    padding: 8px;
    min-height: 120px;
    margin: 0;
    line-height: 1.5;
}

.vim-statusline {
    background: var(--dim-text);
    color: var(--bg-color);
    padding: 2px 8px;
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: bold;
}

.vim-mode-indicator {
    color: var(--bg-color);
    font-weight: bold;
    min-width: 80px;
}

.nano-header,
.nano-shortcuts {
    background: var(--dim-text);
    color: var(--bg-color);
    padding: 2px 8px;
    font-size: 12px;
    font-weight: bold;
}

/* ==========================================================================
   Top Display
   ========================================================================== */

.top-display {
    background: var(--bg-color);
    padding: 8px;
    border: 1px solid var(--border-color);
    white-space: pre;
    font-size: 12px;
    margin: 8px 0;
    font-family: var(--font-family);
    line-height: 1.4;
}

/* ==========================================================================
   Neofetch Component
   ========================================================================== */

.neofetch {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.neofetch-ascii {
    color: var(--highlight);
    font-weight: bold;
    margin: 0;
}

.neofetch-title {
    font-weight: bold;
    color: var(--highlight);
}

.neofetch-separator {
    color: var(--dim-text);
}

.neofetch-label {
    color: var(--highlight);
    font-weight: bold;
}

.neofetch-colors {
    margin-top: 5px;
}

.neofetch-color {
    display: inline-block;
    width: 15px;
    height: 15px;
}

/* ==========================================================================
   Responsive: Tablet (768px - 1024px)
   ========================================================================== */

@media (max-width: 1024px) {
    .terminal-container {
        width: 98%;
        height: 90vh;
        height: 90dvh;
    }
}

/* ==========================================================================
   Responsive: Mobile (<768px)
   ========================================================================== */

@media (max-width: 768px) {
    .ascii-art {
        font-size: 8px;
        line-height: 1;
        overflow: hidden;
    }
    .terminal-container {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        border: none;
    }
    .terminal-body {
        padding: 15px;
    }
    .status-bar {
        display: none;
    }
    .type-hint {
        display: none;
    }
    .terminal-input-area {
        padding: 12px 15px;
    }
    .prompt {
        margin-right: 8px;
    }
    .prompt-short { display: inline; }
    .prompt-full { display: none; }
    .address-bar {
        min-width: 150px;
    }
    .welcome-box {
        font-size: 12px;
        margin-bottom: 20px;
    }
    .subtitle {
        margin-bottom: 15px;
    }

    /* Touch-friendly tap targets (min 44px) */
    button.cmd-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    .clickable {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    th, td {
        padding: 8px 8px;
    }

    /* Neofetch mobile */
    .neofetch-ascii {
        font-size: 10px;
        line-height: 1.1;
    }
}

/* ==========================================================================
   Responsive: Small phones (<400px)
   ========================================================================== */

@media (max-width: 400px) {
    .ascii-art {
        font-size: 6px;
    }
    .terminal-body {
        padding: 10px;
    }
    .terminal-input-area {
        padding: 10px;
    }
    .welcome-box {
        font-size: 11px;
    }
}

/* ==========================================================================
   Accessibility: Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .scanlines {
        display: none;
    }
    .crt-overlay {
        display: none;
    }
    .clickable {
        transition: none;
    }
    .ascii-art {
        text-shadow: none;
    }
}

/* ==========================================================================
   Accessibility: High Contrast
   ========================================================================== */

@media (prefers-contrast: more) {
    :root {
        --bg-color: #000000;
        --text-color: #ffffff;
        --dim-text: #cccccc;
        --highlight: #ffffff;
        --border-color: #ffffff;
        --window-border: #ffffff;
    }
    .crt-overlay,
    .scanlines {
        display: none;
    }
}

/* ==========================================================================
   Auto Color Scheme Detection
   ========================================================================== */

@media (prefers-color-scheme: light) {
    body:not(.theme-hacker):not(.theme-amber):not(.theme-default) {
        --bg-color: #ffffff;
        --text-color: #333333;
        --dim-text: #666666;
        --highlight: #000000;
        --tab-bg: #f3f4f6;
        --border-color: #e5e7eb;
        --window-border: #d1d5db;
    }
}
