/* 
 * CLI Terminal Styles
 * Marc Lanson's personal website
 * Based on Factory Design System
 */

/* ===== RESET ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ===== BASE VARIABLES ===== */
:root {
    --font-mono: 'Berkeley Mono', 'SF Mono', Monaco, Consolas, 'Liberation Mono', Courier, monospace;
    --font-size: 14px;
    --line-height: 1.5;
    
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* ===== THEME: MIDNIGHT (Factory Design System) ===== */
.theme-midnight {
    --bg-primary: #161413;
    --bg-secondary: #1D1B1A;
    --bg-tertiary: #282523;
    --bg-hover: #342F2D;
    
    --text-primary: #F2F0F0;
    --text-secondary: #A89895;
    --text-muted: #80756F;
    
    --accent: #D56A26;
    --accent-hover: #EE6018;
    
    --border: #342F2D;
    --border-strong: #403A37;
    
    --success: #5B8E63;
    --error: #D9363E;
    --warning: #E3992A;
    --link: #50ACF2;
    
    --title-btn-close: #ff5f56;
    --title-btn-min: #ffbd2e;
    --title-btn-max: #27c93f;
}

/* ===== THEME: HIGH CONTRAST ===== */
.theme-contrast {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #111111;
    --bg-hover: #1a1a1a;
    
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --text-muted: #888888;
    
    --accent: #FFFF00;
    --accent-hover: #FFFF00;
    
    --border: #333333;
    --border-strong: #444444;
    
    --success: #00ff00;
    --error: #ff0000;
    --warning: #ffff00;
    --link: #00ffff;
    
    --title-btn-close: #ff0000;
    --title-btn-min: #ffff00;
    --title-btn-max: #00ff00;
}

/* ===== THEME: AS/400 (IBM 5250 Terminal Style) ===== */
/* Key characteristic: Absolute pure black backgrounds.
   Introduction of Cyan/Turquoise which is typical for input fields
   on 5250 terminals, contrasted with standard terminal green.
*/
.theme-as400 {
    /* BACKGROUNDS: Stark, absolute black. No subtle gray gradations. */
    --bg-primary: #000000;
    --bg-secondary: #000000; /* AS/400 screens are usually flat black throughout */
    --bg-tertiary: #080808; /* Only a tiny step up for extreme depth if needed */

    /* HOVER: Simulating a "block cursor" or reverse video effect.
       Instead of getting lighter, we use a dark green block background. */
    --bg-hover: #004400;

    /* TEXT - The core AS/400 Palette */
    /* Primary: A slightly flatter, classic IBM green (less neon than the original theme) */
    --text-primary: #00cf00;
    /* Secondary: THE CRITICAL CHANGE. AS/400 uses Cyan/Turquoise for inputs/labels. */
    --text-secondary: #33e0e0;
    /* Muted: Just a dimmer green */
    --text-muted: #007700;

    /* ACCENTS */
    /* Using the Cyan color as the main accent to highlight active elements */
    --accent: #33e0e0;
    /* Hover changes to pure "High Intensity" White, common on terminals */
    --accent-hover: #ffffff;

    /* BORDERS */
    /* Borders should be subtle or the same color as text, not glowing outlines */
    --border: #005500;
    --border-strong: #33e0e0; /* Strong borders take the cyan highlight color */

    /* STATUS COLORS: A flatter, limited hardware palette */
    --success: #00cf00;
    --error: #cf0000; /* A deeper, darker brick red, not bright neon */
    --warning: #cfcf00; /* A flat mustard/hardware yellow */
    --link: #33e0e0; /* Links act like input fields (Cyan) */

    /* Window buttons flattened to match the palette */
    --title-btn-close: #cf0000;
    --title-btn-min: #cfcf00;
    --title-btn-max: #00cf00;
}

/* ===== BASE STYLES ===== */
html {
    height: 100%;
}

body {
    /* Use dvh for mobile browsers to account for address bar; fallback to vh */
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--font-mono);
    font-size: var(--font-size);
    line-height: var(--line-height);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Allow mobile browsers to detect scroll for address bar hide */
    overflow-x: hidden;
    overflow-y: auto;
}

a {
    color: var(--link);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* ===== TERMINAL CONTAINER ===== */
.terminal-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Use dvh for proper mobile viewport handling; fallback to vh */
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--space-lg);
    background: var(--bg-primary);
}

.terminal {
    width: 100%;
    max-width: 1000px;
    /* Use dvh for proper mobile viewport handling; fallback to vh */
    height: 80vh;
    height: 80dvh;
    max-height: 700px;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    border: 1px solid var(--border-strong);
    background: var(--bg-secondary);
    box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

/* ===== TITLE BAR ===== */
.terminal-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: linear-gradient(to bottom, #3c3c3c, #2b2b2b);
    border-bottom: 1px solid #1e1e1e;
    user-select: none;
}

.title-buttons {
    display: flex;
    gap: 0;
}

.title-btn {
    width: 38px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    border-radius: 0;
    border: 1px solid #202020;
    background: transparent;
    color: #d0d0d0;
    cursor: default;
}

.title-btn.minimize::before {
    content: '\2014'; /* em dash */
}

.title-btn.maximize::before {
    content: '\25A1'; /* hollow square */
    font-size: 10px;
}

.title-btn.close::before {
    content: '\00D7'; /* multiplication sign */
}

.title-text {
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
    text-align: left;
    padding-left: 4px;
}

.title-link {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s ease;
}

.title-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.title-actions {
    display: flex;
    gap: var(--space-sm);
}

.help-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.help-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

/* ===== TERMINAL BODY ===== */
.terminal-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    background: var(--bg-secondary);
}

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

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

.terminal-body::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

.terminal-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== OUTPUT ===== */
#output {
    white-space: pre-wrap;
    word-wrap: break-word;
}

#output .prompt {
    color: var(--accent);
    font-weight: 600;
}

#output .cmd {
    color: var(--accent);
}

#output .accent {
    color: var(--accent);
}

#output .muted {
    color: var(--text-muted);
}

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

#output .success {
    color: var(--success);
}

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

#output .bold {
    font-weight: 600;
}

#output .white {
    color: var(--text-primary);
}

#output .bold.white {
    font-weight: 600;
    color: var(--text-primary);
}

#output a {
    color: var(--link);
}

#output a:hover {
    color: var(--accent-hover);
}

.ascii-art {
    font-size: 10px;
    line-height: 1.1;
    letter-spacing: -0.5px;
    white-space: pre;
    display: block;
}

/* ===== INPUT LINE ===== */
.terminal-input {
    display: flex;
    align-items: center;
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
}

.input-prompt {
    color: var(--accent);
    font-weight: 600;
    margin-right: var(--space-sm);
    user-select: none;
}

#command-form {
    flex: 1;
    display: flex;
}

#command-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size);
    outline: none;
    caret-color: var(--accent);
}

#command-input::placeholder {
    color: var(--text-muted);
}

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

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

/* ===== TERMINAL STATUS BAR ===== */
.terminal-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    user-select: none;
}

.status-left,
.status-center,
.status-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.status-center {
    color: var(--text-muted);
}

.status-hint {
    opacity: 0.7;
}

.status-sep {
    color: var(--border-strong);
}

.status-model {
    color: var(--accent);
}

/* ===== COMMAND SHORTCUTS ===== */
.command-shortcuts {
    display: flex;
    justify-content: center;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

.cmd-shortcut {
    padding: var(--space-xs) var(--space-md);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.cmd-shortcut:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.cmd-shortcut:active,
.cmd-shortcut.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    /* ===== GLOBAL LAYOUT ===== */
    /* Main containers get full bleed with clean margins */
    body {
        padding: 0;
    }

    .terminal-wrapper,
    .blog-wrapper {
        width: 100%;
        padding: 0;
    }

    /* ===== GLOBAL TYPOGRAPHY ===== */
    /* Scale fonts fluidly based on viewport width */
    :root {
        --font-size: clamp(13px, 4vw, 14px);
    }

    /* All heading levels use clamp() */
    h1, h2, h3, h4, h5, h6 {
        font-size: clamp(20px, 6vw, 28px);
        line-height: 1.2;
        margin-bottom: var(--space-md);
        text-wrap: balance;
    }

    h1 { font-size: clamp(24px, 7vw, 32px); }
    h2 { font-size: clamp(20px, 6vw, 28px); }
    h3 { font-size: clamp(18px, 5.5vw, 24px); }
    h4 { font-size: clamp(16px, 5vw, 20px); }

    /* Body text scaling */
    p, span, div:not(.terminal), li, td, th, .bold {
        font-size: clamp(13px, 4vw, 14px);
        line-height: 1.4;
        letter-spacing: -0.02em;
        hyphens: auto;
        overflow-wrap: break-word;
        text-align: left !important;
    }

    /* Terminal-specific typography */
    #output .bold.white,
    #output .bold {
        font-size: clamp(14px, 5vw, 16px);
        line-height: 1.4;
        margin-bottom: var(--space-xs) !important;
    }

    #output li {
        margin-bottom: var(--space-xs) !important;
    }

    #output .cmd {
        font-size: clamp(13px, 4.5vw, 14px);
    }

    #output {
        font-size: clamp(13px, 4vw, 14px);
        line-height: 1.4;
        width: 100%;
        max-width: none;
        white-space: pre-line;
    }

    #output .prompt {
        font-size: clamp(13px, 4vw, 14px);
    }

    /* List break handling */
    #output li,
    #output ul,
    #output ol {
        hyphens: auto;
        overflow-wrap: break-word;
    }

    /* Blog heading balance */
    .blog-title,
    .post-header .post-title {
        text-wrap: balance;
    }

    /* ===== UNIVERSAL ALIGNMENT ===== */
    /* Force left alignment on mobile */
    .terminal-title,
    .blog-header,
    .blog-footer,
    .post-footer,
    #output,
    .prose {
        text-align: left !important;
    }

    /* Terminal status bar aligned right on mobile */
    .terminal-status {
        text-align: right !important;
        justify-content: flex-end;
    }

    /* ===== COMPONENT STACKING ===== */
    /* Stack horizontal layouts */
    .blog-header,
    .blog-footer,
    .title-actions {
        flex-direction: column;
        gap: var(--space-md);
        align-items: flex-start;
    }

    .status-left,
    .status-center,
    .status-right {
        align-items: flex-start;
    }

    /* ===== TERMINAL STYLING ===== */
    .terminal {
        height: 85vh;
        height: 85dvh;
        max-height: none;
        min-height: 90vh;
        min-height: 90dvh;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
    }

    .terminal-title {
        padding: var(--space-xs) var(--space-sm);
    }

    .title-text {
        font-size: clamp(10px, 3.5vw, 12px);
        letter-spacing: -0.01em;
    }

    .terminal-body {
        padding: 20px;
    }

    .terminal-input {
        padding: 0;
        min-height: 48px;
    }

    .input-prompt {
        margin-right: var(--space-sm);
    }

    .terminal-status {
        font-size: 10px;
        padding: var(--space-xs) var(--space-sm);
        gap: var(--space-xs);
    }

    .status-center {
        display: none;
    }

    .status-left,
    .status-right {
        gap: var(--space-xs);
    }

    /* ===== TOUCH TARGETS ===== */
    #output a {
        display: inline-flex;
        padding: var(--space-xs) var(--space-sm);
        margin: calc(var(--space-xs) * -1) calc(var(--space-sm) * -1);
        min-height: 44px;
        min-width: 44px;
        align-items: center;
        justify-content: center;
        text-decoration: underline;
        text-decoration-thickness: 1px;
        text-underline-offset: 2px;
    }

    .command-shortcuts {
        flex-wrap: wrap;
        gap: var(--space-sm);
        margin-top: var(--space-md);
    }

    .cmd-shortcut,
    .cmd-shortcut + .cmd-shortcut {
        min-height: 44px;
        min-width: 44px;
        padding: var(--space-xs) var(--space-md);
        font-size: clamp(11px, 4vw, 12px);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .help-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }

    /* ===== ASCII ART SCALING ===== */
    .ascii-art {
        font-size: clamp(4px, 2.5vw, 8px);
        letter-spacing: clamp(-1px, -0.05vw, -0.5px);
        line-height: 1.1;
        white-space: pre;
        overflow-x: auto;
        max-width: 100%;
    }

    /* ===== BLOG & PROSE STYLING ===== */
    .blog-main,
    .post-content,
    .prose {
        padding: var(--space-md) var(--space-sm);
    }

    .prose pre,
    .prose code {
        overflow-x: auto;
        white-space: pre-wrap;
        word-break: break-word;
    }

    /* ===== MOBILE OPTIMIZATIONS ===== */
    *, *::before, *::after {
        box-sizing: border-box;
    }

    a, button, .cmd-shortcut {
        -webkit-tap-highlight-color: color-mix(in srgb, var(--accent) 25%, transparent);
    }
}

@media (max-width: 480px) {
    :root {
        --font-size: 13px;
    }

    .terminal-wrapper {
        padding: var(--space-sm);
    }

    .terminal {
        /* Use dvh for mobile address bar; fallback to vh */
        height: 90vh;
        height: 90dvh;
        border-radius: var(--radius-sm);
    }

    .title-text {
        font-size: 11px;
    }

    .ascii-art {
        font-size: 5px;
        letter-spacing: -1px;
        white-space: pre;
        overflow-x: auto;
    }

    .cmd-shortcut {
        padding: var(--space-xs) var(--space-sm);
        font-size: 11px;
    }

    .terminal-status {
        font-size: 9px;
        padding: var(--space-xs) var(--space-sm);
    }

    .status-left {
        display: none;
    }

    #command-input {
        font-size: 16px; /* Prevents mobile browser zoom on focus */
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    .cursor {
        animation: none;
        opacity: 1;
    }
}

#command-input:focus {
    outline: none;
}

.cmd-shortcut:focus-visible,
.help-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.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;
}
