/* 
 * Terminal CSS - Professional Terminal Interface
 * Author: Igor Volk
 * Description: Retro terminal styling with modern responsive design and theme support
 */

/* CSS Variables for theming */
:root {
    /* Dark theme (default) - Retro terminal style */
    --bg-primary: #0a0a0a;
    --bg-secondary: #1a1a1a;
    --bg-gradient-start: #0a0a0a;
    --bg-gradient-end: #1a1a1a;
    --text-primary: #00ff41;
    --text-secondary: #00cc33;
    --text-prompt: #00ff41;
    --text-error: #ff6b6b;
    --text-success: #51cf66;
    --text-info: #00cc33;
    --border-primary: #333;
    --border-secondary: #333;
    --cursor-color: #00ff41;
    --scrollbar-track: #1a1a1a;
    --scrollbar-thumb: #333;
    --scrollbar-thumb-hover: #444;
    --placeholder-color: #666;
}

/* Light theme variables */
body.light-theme {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-gradient-start: #f5f5f5;
    --bg-gradient-end: #ffffff;
    --text-primary: #1a4d1a;
    --text-secondary: #2d2d2d;
    --text-prompt: #1a4d1a;
    --text-error: #d63031;
    --text-success: #00b894;
    --text-info: #2d2d2d;
    --border-primary: #cccccc;
    --border-secondary: #cccccc;
    --cursor-color: #1a4d1a;
    --scrollbar-track: #ffffff;
    --scrollbar-thumb: #cccccc;
    --scrollbar-thumb-hover: #999999;
    --placeholder-color: #999999;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Remove all user-select restrictions - let browser handle it naturally */
* {
    user-select: auto !important;
    -webkit-user-select: auto !important;
    -moz-user-select: auto !important;
    -ms-user-select: auto !important;
}

/* Only disable selection for buttons and interactive elements */
.terminal-button,
.theme-toggle {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

.cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    background: var(--cursor-color);
    animation: blink 1.2s infinite;
    margin-left: 2px;
    transition: background 0.3s ease;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
    font-size: 14px;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for mobile keyboards */
    transition: background 0.3s ease, color 0.3s ease;
}

/* Responsive base font scaling */
@media (max-width: 768px) {
    /* Only output text scales - prompts stay original size */
    .output-text {
        font-size: 12px !important;
        font-family: monospace !important;
        line-height: 1.2 !important;
    }
}

@media (max-width: 480px) {
    /* Only output text scales - prompts stay original size */
    .output-text {
        font-size: 9px !important;
        font-family: monospace !important;
        line-height: 1.2 !important;
    }
}

/* Terminal container */
.terminal-container {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for mobile keyboards */
    background: var(--bg-primary);
    border: 2px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    position: relative;
    transition: all 0.3s ease;
    overflow-x: hidden;
}

/* Terminal header */
.terminal-header {
    background: var(--bg-secondary);
    padding: 8px 15px;
    border-bottom: 1px solid var(--border-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
}

.terminal-title {
    color: var(--placeholder-color);
    font-size: 14px;
    flex: 1;
    transition: color 0.3s ease;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
}


.terminal-buttons {
    display: flex;
    gap: 6px;
}

.terminal-button {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.terminal-button:hover {
    transform: scale(1.1);
}

.close { 
    background: #ff5f56; 
}

.minimize { 
    background: #ffbd2e; 
}

.maximize { 
    background: #27ca3f; 
}


/* Open UI button (matches GUI style, but subtle) */
.open-ui-btn {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
    padding: 6px 10px;
    border-radius: 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-right: 10px;
    transition: all 0.25s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    backdrop-filter: blur(6px);
}

.open-ui-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    transform: translateY(-1px);
}

.open-ui-btn:active {
    transform: translateY(0);
}

/* Theme toggle button */
.theme-toggle:hover {
    background: var(--bg-secondary);
    transform: scale(1.05);
}

.theme-icon {
    font-size: 14px;
    transition: transform 0.3s ease;
}

.theme-toggle:active .theme-icon {
    transform: scale(0.9);
}

/* Theme icon updates */
body.light-theme .theme-icon::before {
    content: '☀️';
}

body:not(.light-theme) .theme-icon::before {
    content: '🌙';
}

/* Make sure icons are visible in both themes */
.theme-icon {
    filter: none;
}

/* Terminal body */
.terminal-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    transition: all 0.3s ease;
    min-height: 0; /* Allow flex item to shrink below content size */
}

.terminal-output {
    min-height: calc(100vh - 120px);
    min-height: calc(100dvh - 120px); /* Use dynamic viewport height for mobile keyboards */
    padding-bottom: 20px;
    flex: 1;
    overflow-y: auto;
}

/* Command line display */
.command-line {
    display: flex;
    align-items: baseline;
    margin: 5px 0;
    line-height: 1.4;
}

.prompt {
    color: var(--text-secondary);
    margin-right: 8px;
    flex-shrink: 0;
    transition: color 0.3s ease;
}

/* Remove margin from output text when used inline in command lines */
.command-line .output-text {
    margin: 0;
}


/* Output text styling */
.output-text {
    color: var(--text-secondary);
    margin: 2px 0;
    white-space: pre-wrap;
    line-height: 1.4;
    transition: color 0.3s ease;
}

/* Text selection styling */
::selection {
    background: var(--text-primary) !important;
    color: var(--bg-primary) !important;
}

::-moz-selection {
    background: var(--text-primary) !important;
    color: var(--bg-primary) !important;
}

/* Specific selection for terminal content */
.terminal-output ::selection,
.terminal-body ::selection,
.output-text ::selection {
    background: #00ff0080 !important;
    color: #000000 !important;
}

.terminal-output ::-moz-selection,
.terminal-body ::-moz-selection,
.output-text ::-moz-selection {
    background: #00ff0080 !important;
    color: #000000 !important;
}

.error-text {
    color: var(--text-error);
}

.success-text {
    color: var(--text-success);
}

.info-text {
    color: var(--text-info);
}

/* Input container */
.input-container {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-primary);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
    flex-shrink: 0; /* Don't shrink the input area */
}

.current-prompt {
    color: var(--text-secondary);
    margin-right: 8px;
    flex-shrink: 0;
    transition: color 0.3s ease;
}

.command-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: inherit;
    outline: none;
    caret-color: var(--cursor-color);
    transition: color 0.3s ease, caret-color 0.3s ease;
}

.command-input::placeholder {
    color: var(--placeholder-color);
    transition: color 0.3s ease;
}


@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}



/* Scrollbar styling */
.terminal-body::-webkit-scrollbar {
    width: 8px;
}

.terminal-body::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    transition: background 0.3s ease;
}

.terminal-body::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
    transition: background 0.3s ease;
}

.terminal-body::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Game specific styles */
.game-board {
    font-family: 'Courier New', monospace;
    line-height: 1.2;
    margin: 10px 0;
}

.game-feedback {
    color: var(--text-info);
    margin: 5px 0;
}

.game-stats {
    color: var(--text-secondary);
    font-weight: bold;
}

/* CV content specific styles */
.cv-section {
    margin: 15px 0;
}

.cv-header {
    color: var(--text-primary);
    font-weight: bold;
    margin-bottom: 10px;
}

.cv-content {
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Mobile responsiveness - scale output text only */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
    }
    
    .terminal-container {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    .terminal-body {
        overflow-x: hidden;
        max-width: 100%;
    }
    
    
    /* Ensure text wrapping and no horizontal scroll */
    .output-text {
        word-break: break-all;
        overflow-wrap: break-word;
        white-space: pre-wrap;
        max-width: 100%;
    }
    
    /* Ensure keyboard doesn't push content up */
    .terminal-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border: 1px solid var(--border-primary);
        overflow-x: hidden;
    }
    
    .terminal-body {
        padding: 8px;
        overflow-x: hidden;
        word-wrap: break-word;
    }
    
    .input-container {
        padding: 6px 8px;
        flex-wrap: nowrap;
    }
    
    .current-prompt {
        margin-right: 3px;
        font-size: 16px; /* Match command input font size */
    }
    
    .command-input {
        font-size: 16px; /* Prevent Safari auto-zoom */
        min-width: 0;
        flex: 1;
    }
    
    
    /* Ensure text wrapping and no horizontal scroll */
    .output-text {
        word-break: break-all;
        overflow-wrap: break-word;
        max-width: 100%;
    }
    
    .terminal-header {
        padding: 6px 8px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .terminal-buttons {
        order: 0;
        flex-shrink: 0;
    }
    
    
    .output-text {
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: pre-wrap;
    }
}

@media (max-width: 480px) {
    body {
        overflow-x: hidden;
    }
    
    .terminal-container {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    .terminal-body {
        overflow-x: hidden;
        max-width: 100%;
    }
    
    
    /* Ensure text wrapping and no horizontal scroll on small screens */
    .output-text {
        word-break: break-all;
        overflow-wrap: break-word;
        white-space: pre-wrap;
        max-width: 100%;
    }
    
    .terminal-container {
        border: 1px solid var(--border-primary);
    }
    
    .terminal-body {
        padding: 6px;
        overflow-x: hidden;
    }
    
    .input-container {
        padding: 4px 6px;
        min-height: 32px;
    }
    
    .current-prompt {
        font-size: 16px; /* Match command input font size */
        margin-right: 2px;
    }
    
    .command-input {
        font-size: 16px; /* Prevent Safari auto-zoom */
        min-width: 0;
    }
    
    .terminal-header {
        padding: 4px 6px;
        min-height: 40px;
    }
    
}

/* JavaScript-based mobile detection for better Safari compatibility */
body.mobile-device.portrait-orientation {
    .current-prompt {
        font-size: 16px; /* Match command input font size */
    }
    
    .command-input {
        font-size: 16px; /* Prevent Safari auto-zoom */
    }
}

body.mobile-device.portrait-orientation.safari-browser {
    .current-prompt {
        font-size: 16px; /* Match command input font size */
    }
    
    .command-input {
        font-size: 16px; /* Prevent Safari auto-zoom */
    }
}

/* Mobile device optimizations - only when actual mobile devices are detected */

/* Touch-friendly enhancements for mobile - but allow smaller sizes when explicitly set */
@media (max-width: 768px) and (pointer: coarse) {
    .terminal-button,
    .theme-toggle,
    .open-ui-btn {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        /* Removed min-height/min-width to allow our smaller sizes */
    }
    
    .command-input {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
}

/* Override size constraints only for actual mobile devices - not browser resize */
body.mobile-device .terminal-button {
    min-width: auto !important;
    min-height: auto !important;
}


body.mobile-device .open-ui-btn {
    padding: 4px 7px !important;
    min-width: auto !important;
    min-height: auto !important;
}

body.mobile-device .theme-toggle {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
}



body.mobile-device.portrait-orientation .open-ui-btn {
    padding: 3px 5px !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    body {
        background: #000000;
        color: #00ff00;
    }
    
    .terminal-container {
        border-color: #00ff00;
    }
    
    .terminal-header {
        background: #000000;
        border-bottom-color: #00ff00;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .cursor {
        animation: none;
        opacity: 1;
    }
    
    .terminal-button {
        transition: none;
    }
}

/* Print styles */
@media print {
    .terminal-container {
        border: 1px solid #000;
    }
    
    .input-container {
        display: none;
    }
    
    .terminal-buttons {
        display: none;
    }
    
    body {
        background: white;
        color: black;
    }
    
    .output-text {
        color: black;
    }
}
