/*
 * Copyright (c) 2026 Tuan Pham. All Rights Reserved.
 * Website: https://linux.tuanpham435.work/
 * Unauthorized copying or modification of this file is strictly prohibited.
 */
:root {
    /* Premium Dark Theme Palette */
    --bg-page: #0d1117;
    --bg-terminal: #161b22;
    --terminal-header: #21262d;
    --terminal-border: #30363d;

    --text-main: #e6edf3; /* Brighter white for high contrast */
    --text-muted: #9ba6b2; /* Brighter muted gray */

    --accent-red: #ff8a84;
    --accent-green: #56d364;
    --accent-yellow: #e2c5ff;
    --accent-blue: #a5d6ff;
    --accent-cyan: #7ee787;

    /* macOS Window Controls */
    --mac-close: #ff5f56;
    --mac-min: #ffbd2e;
    --mac-max: #27c93f;

    --question-gradient: linear-gradient(135deg, #ffe4e6, #fbcfe8); /* Ultra soft rose to pastel pink for high readability */

    --transition-speed: 0.3s;

    /* Vi mode indicator */
    --vi-insert-color: #d2a8ff;
    --vi-insert-bg: rgba(210, 168, 255, 0.1);
}

body.light-theme {
    --bg-page: #f0f2f5;
    --bg-terminal: #ffffff;
    --terminal-header: #e1e4e8;
    --terminal-border: #d1d5da;

    --text-main: #24292e;
    --text-muted: #586069;

    --accent-red: #d73a49;
    --accent-green: #28a745;
    --accent-yellow: #805c00; /* Darker, high-contrast brownish yellow */
    --accent-blue: #0366d6;
    --accent-cyan: #22863a;

    --vi-insert-color: #6f42c1;
    --vi-insert-bg: rgba(111, 66, 193, 0.1);

    --question-gradient: linear-gradient(135deg, #881337, #be123c); /* Deep ruby to crimson for elegant contrast */

    /* Light Theme Base */
}

/* Premium Apple-Style Liquid Wave Background */
body {
    background: #020617; /* Slate 950 */
    background-image: linear-gradient(to bottom right, #020617, #0f172a);
}

body.light-theme {
    background: #f8fafc;
    background-image: linear-gradient(to bottom right, #f1f5f9, #e2e8f0);
}

body::before, body::after {
    content: '';
    position: fixed;
    filter: blur(100px); /* Reduced blur for performance */
    z-index: -1;
    pointer-events: none;
    will-change: transform;
    opacity: 0.9;
    border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%; /* Static asymmetric shape */
    transform-style: preserve-3d;
    backface-visibility: hidden;
}

/* Linux Colors: Crimson Liquid Wave */
body::before {
    width: 120vw; height: 120vh;
    background: linear-gradient(135deg, rgba(225, 29, 72, 0.4), rgba(159, 18, 57, 0.1));
    top: -30%; left: -20%;
    animation: liquidWave 35s infinite linear;
}

/* Linux Colors: Royal Blue Liquid Wave */
body::after {
    width: 100vw; height: 100vh;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.35), rgba(30, 58, 138, 0.1));
    bottom: -30%; right: -20%;
    animation: liquidWave 45s infinite linear reverse;
}

body.light-theme::before {
    background: linear-gradient(135deg, rgba(251, 113, 133, 0.5), rgba(244, 63, 94, 0.2));
}
body.light-theme::after {
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.4), rgba(59, 130, 246, 0.1));
}

@keyframes liquidWave {
    0% { 
        transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
    }
    33% { 
        transform: translate3d(5vw, 5vh, 0) rotate(120deg) scale(1.05);
    }
    66% { 
        transform: translate3d(-5vw, -5vh, 0) rotate(240deg) scale(0.95);
    }
    100% { 
        transform: translate3d(0, 0, 0) rotate(360deg) scale(1);
    }
}

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

body {
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    background-color: var(--bg-page);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
    z-index: 0;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.app-container {
    width: 100%;
    max-width: 900px;
    height: 90vh;
    min-width: 420px;
    min-height: 300px;
    border: none;
    border-radius: 14px;
    background-color: rgba(255, 255, 255, 0.08); /* Pure Clear Glass Base */
    backdrop-filter: blur(60px) saturate(140%);
    -webkit-backdrop-filter: blur(60px) saturate(140%);
    box-shadow: 0 50px 100px -20px rgba(0, 0, 0, 0.8), /* Soft immense shadow */
        inset 0 0 0 1px rgba(255, 255, 255, 0.15); /* Crisp Apple Rim */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    transition: background-color var(--transition-speed), border-color var(--transition-speed), box-shadow var(--transition-speed), backdrop-filter var(--transition-speed);
}

/* Tinted Mode Backgrounds */
body.tinted-theme .app-container {
    background-color: rgba(13, 17, 23, 0.7); /* Deep dark tint, matching bg-page */
}

body.light-theme.tinted-theme .app-container {
    background-color: rgba(255, 255, 255, 0.75); /* Light tint */
}

/* Maximized state */
.app-container.is-maximized {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
    z-index: 9999;
    transition: none;
}

/* Resize handles */
.resize-handle {
    position: absolute;
    z-index: 50;
    user-select: none;
}

.resize-handle.n {
    top: 0;
    left: 4px;
    right: 4px;
    height: 5px;
    cursor: n-resize;
}

.resize-handle.s {
    bottom: 0;
    left: 4px;
    right: 4px;
    height: 5px;
    cursor: s-resize;
}

.resize-handle.e {
    right: 0;
    top: 4px;
    bottom: 4px;
    width: 5px;
    cursor: e-resize;
}

.resize-handle.w {
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 5px;
    cursor: w-resize;
}

.resize-handle.ne {
    top: 0;
    right: 0;
    width: 12px;
    height: 12px;
    cursor: ne-resize;
}

.resize-handle.nw {
    top: 0;
    left: 0;
    width: 12px;
    height: 12px;
    cursor: nw-resize;
}

.resize-handle.se {
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    cursor: se-resize;
}

.resize-handle.sw {
    bottom: 0;
    left: 0;
    width: 12px;
    height: 12px;
    cursor: sw-resize;
}

/* Hide resize handles when maximized */
.app-container.is-maximized .resize-handle {
    display: none;
}

/* macOS maximize button hover */
.maximize {
    transition: transform 0.15s;
}

.maximize:hover {
    transform: scale(1.2);
}

.terminal-header {
    height: 46px; /* Slightly taller for modern look */
    background-color: transparent; /* Seamless glass */
    border-bottom: 1px solid rgba(255, 255, 255, 0.03); /* Extremely faint separator */
    display: flex;
    align-items: center;
    padding: 0 16px;
    position: relative;
    z-index: 10;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

.window-toggles {
    position: absolute;
    right: 16px;
    display: flex;
    gap: 12px;
}

.theme-toggle {
    cursor: pointer;
    font-size: 1.1rem;
    user-select: none;
    transition: transform 0.2s;
    filter: grayscale(0.2);
}

.theme-toggle:hover {
    transform: scale(1.1);
    filter: none;
}

.window-controls {
    display: flex;
    gap: 8px;
    position: absolute;
    left: 16px;
}

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

.close {
    background-color: var(--mac-close);
}

.minimize {
    background-color: var(--mac-min);
}

.maximize {
    background-color: var(--mac-max);
}

.window-title {
    flex: 1;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0.5px;
}

.terminal-body {
    padding: clamp(8px, 2.5vw, 20px) clamp(10px, 3vw, 24px);
    overflow-y: auto;
    flex: 1;
    font-size: clamp(0.75rem, 1.8vw, 0.88rem);
}

::-webkit-scrollbar {
    width: 12px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--terminal-border);
    border-radius: 6px;
    border: 3px solid var(--bg-terminal);
}

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

#terminal-output {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.6;
    margin-bottom: 10px;
}

.input-line {
    display: flex;
    align-items: center;
    margin-top: 5px;
}

.prompt-host {
    color: var(--accent-green);
    font-weight: 500;
}

.prompt-sep {
    color: var(--text-main);
}

.prompt-dir {
    color: var(--accent-blue);
    font-weight: 500;
}

.prompt-char {
    color: var(--text-main);
    margin-right: 12px;
    font-weight: bold;
}

#cmd-input {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: inherit;
    flex-grow: 1;
    outline: none;
    caret-color: var(--text-main);
}

.system-msg {
    color: var(--text-muted);
}

.question-text {
    background: var(--question-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
    margin-top: 20px;
    margin-bottom: 8px;
    font-weight: 700; /* Bolder makes gradient pop */
    letter-spacing: 0.3px;
    line-height: 1.4;
}

.user-cmd {
    color: var(--text-main);
}

.correct-msg {
    color: var(--accent-green);
    margin-top: 4px;
}

.error-msg {
    color: var(--accent-red);
    margin-top: 4px;
}

.score-msg {
    color: var(--accent-blue);
    margin-top: 20px;
    margin-bottom: 5px;
    border-left: 3px solid var(--accent-blue);
    padding: 10px 15px;
    background: rgba(121, 192, 255, 0.05);
    border-radius: 0 8px 8px 0;
    line-height: 1.6;
}

::selection {
    background: rgba(121, 192, 255, 0.3);
    color: var(--text-main);
}

.hidden {
    display: none !important;
}


/* Vi Editor Styles */
#vi-editor {
    position: absolute;
    top: 46px;
    left: 0;
    right: 0;
    bottom: 0;
    bottom: 0;
    background-color: transparent;
    z-index: 20;
    display: flex;
    flex-direction: column;
}

body.light-theme .app-container {
    background-color: rgba(255, 255, 255, 0.35); /* Pure Clear Light Glass */
    backdrop-filter: blur(60px) saturate(140%);
    -webkit-backdrop-filter: blur(60px) saturate(140%);
    box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.15),
        inset 0 0 0 1px rgba(255, 255, 255, 0.4); /* Crisp Light Rim */
}

body.light-theme .terminal-header {
    background-color: transparent;
    border-bottom-color: rgba(0, 0, 0, 0.05);
}



.vi-header {
    background-color: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 5px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

#vi-textarea {
    flex: 1;
    background-color: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.88rem;
    padding: 10px;
    resize: none;
    outline: none;
    line-height: 1.6;
    tab-size: 2;
    -moz-tab-size: 2;
}

/* Caret hack to simulate block cursor in normal mode */
#vi-textarea.vi-normal {
    caret-color: var(--text-main);
}

.vi-status-line {
    background-color: rgba(255, 255, 255, 0.03); /* Glass integration */
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    padding: 4px 10px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0;
    min-height: 28px;
}

#vi-mode-display {
    color: var(--vi-insert-color, #d2a8ff);
    background: var(--vi-insert-bg, rgba(210, 168, 255, 0.1));
    min-width: 100px;
    font-weight: bold;
    padding: 1px 8px;
    border-radius: 3px;
}

#vi-cmd-display {
    flex: 1;
    color: var(--text-main);
}

.vi-hint {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: auto;
}

@media screen and (max-width: 768px) {
    body {
        padding: 0;
    }

    .app-container {
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        border: none;
        min-width: unset;
    }

    .resize-handle {
        display: none;
    }

    .terminal-body {
        padding: 6px 10px;
        font-size: 0.78rem;
        line-height: 1.45;
    }

    #terminal-output {
        line-height: 1.45;
        margin-bottom: 6px;
    }

    .terminal-header {
        height: 36px;
        padding: 0 12px;
    }

    .window-title {
        font-size: 0.72rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding: 0 36px;
    }

    .control {
        width: 10px;
        height: 10px;
    }

    .window-controls {
        gap: 6px;
    }

    .theme-toggle {
        font-size: 0.95rem;
        right: 12px;
    }

    .prompt-char {
        margin-right: 6px;
    }

    .input-line {
        flex-wrap: nowrap;
        align-items: center;
    }

    #cmd-input {
        width: 100%;
        margin-top: 0;
        padding-left: 6px;
        font-size: 0.78rem;
    }

    .score-msg {
        padding: 4px 0 4px 10px;
        margin-top: 16px;
    }

    .question-text {
        margin-top: 14px;
        margin-bottom: 6px;
    }

    .app-copyright {
        font-size: 0.65rem;
        padding: 6px;
    }
}

.app-copyright {
    position: absolute;
    bottom: 0px;
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 10px;
    opacity: 0.5;
    pointer-events: auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    z-index: 100;
}

.app-copyright a {
    color: var(--accent-blue);
    text-decoration: none;
}

.app-copyright a:hover {
    text-decoration: underline;
}