/* MirthCode Terminal Styles */

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

/* -- Theme variables ---------------------------------------------------- */

:root {
    --term-bg: #151518;
    --term-viewport-bg: #0a0a0c;
    --term-window-bg: #151518;
    --term-titlebar-bg: #1c1c20;
    --term-text: #d4d4d8;
    --term-text-muted: #63636a;
    --term-accent: #06b6d4;
    --term-border: #27272e;
    --term-prompt: #6e6e78;
    --term-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 8px 20px rgba(0, 0, 0, 0.3);
    --term-dot-red: #ff5f57;
    --term-dot-yellow: #febc2e;
    --term-dot-green: #28c840;
}

.terminal-light {
    --term-bg: #ffffff;
    --term-viewport-bg: #e8e8ec;
    --term-window-bg: #ffffff;
    --term-titlebar-bg: #f2f2f5;
    --term-text: #1a1a1e;
    --term-text-muted: #8e8e93;
    --term-accent: #0e7490;
    --term-border: #d4d4d8;
    --term-prompt: #6e6e73;
    --term-shadow: 0 20px 60px rgba(0, 0, 0, 0.1), 0 8px 20px rgba(0, 0, 0, 0.05);
}

/* -- Base --------------------------------------------------------------- */

body {
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    background: var(--term-viewport-bg);
    color: var(--term-text);
    height: 100svh;
    height: 100vh;
    overflow: hidden;
    overscroll-behavior: none;
}

@supports (height: 100svh) {
    body { height: 100svh; }
}

/* -- Viewport ----------------------------------------------------------- */

.terminal-viewport {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100svh;
    height: 100vh;
    padding: 24px;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

@supports (height: 100svh) {
    .terminal-viewport { height: 100svh; }
}

/* -- Window ------------------------------------------------------------- */

.terminal-window {
    width: 100%;
    max-width: 1040px;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--term-window-bg);
    border: 1px solid var(--term-border);
    border-radius: 10px;
    box-shadow: var(--term-shadow);
    overflow: hidden;
}

/* -- Title bar ---------------------------------------------------------- */

.terminal-titlebar {
    display: flex;
    align-items: center;
    height: 38px;
    padding: 0 14px;
    background: var(--term-titlebar-bg);
    border-bottom: 1px solid var(--term-border);
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
}

.titlebar-dots {
    display: flex;
    align-items: center;
    gap: 7px;
}

.dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
}

.dot-red    { background: var(--term-dot-red); }
.dot-yellow { background: var(--term-dot-yellow); }
.dot-green  { background: var(--term-dot-green); }

.titlebar-title {
    flex: 1;
    text-align: center;
    font-size: 0.75rem;
    color: var(--term-text-muted);
    font-weight: 500;
    letter-spacing: 0.01em;
}

.titlebar-spacer {
    width: 47px;
}

.titlebar-toggle {
    display: flex;
    gap: 1px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 4px;
    padding: 1px;
}

.titlebar-toggle-btn {
    font-family: inherit;
    font-size: 0.5625rem;
    font-weight: 500;
    color: var(--term-text-muted);
    background: transparent;
    border: none;
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.titlebar-toggle-btn:hover {
    color: var(--term-text);
}

.titlebar-toggle-btn.active {
    color: var(--term-text);
    background: rgba(255, 255, 255, 0.08);
}

/* -- Terminal body ------------------------------------------------------ */

.terminal-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 20px 24px 0;
}

/* -- Output ------------------------------------------------------------- */

.terminal-output {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.terminal-output .line {
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 1.5em;
}

.terminal-output .line.command {
    display: flex;
    align-items: baseline;
}

.terminal-output .line.command .prompt-echo,
.terminal-output .line.command .cmd-text {
    display: inline;
    vertical-align: baseline;
    font-size: inherit;
    line-height: inherit;
}

.terminal-output .line.command .prompt-echo {
    color: var(--term-prompt);
    flex-shrink: 0;
}

.terminal-output .line.command .cmd-text {
    color: var(--term-text);
}

/* -- Input -------------------------------------------------------------- */

.terminal-input-line {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 0 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--term-border);
    flex-shrink: 0;
}

.terminal-prompt {
    color: var(--term-prompt);
    font-size: 0.9375rem;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
    white-space: nowrap;
}

.terminal-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--term-text);
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.6;
    outline: none;
    caret-color: var(--term-accent);
    caret-shape: block;
}

.terminal-input:focus {
    outline: none;
}

.terminal-input::placeholder {
    color: var(--term-text-muted);
    opacity: 0.35;
}

/* -- Scrollbar ---------------------------------------------------------- */

.terminal-output::-webkit-scrollbar {
    width: 6px;
}

.terminal-output::-webkit-scrollbar-track {
    background: transparent;
}

.terminal-output::-webkit-scrollbar-thumb {
    background: var(--term-border);
    border-radius: 3px;
}

.terminal-output {
    scrollbar-width: thin;
    scrollbar-color: var(--term-border) transparent;
}

/* -- Game container ----------------------------------------------------- */

.game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--term-viewport-bg);
    z-index: 100;
}

.game-container.hidden {
    display: none;
}

#game-hud {
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.875rem;
    color: var(--term-text-muted);
    margin-bottom: 1rem;
    text-align: center;
}

#game-canvas {
    border: 1px solid var(--term-border);
    max-width: 100vw;
    max-height: 70vh;
    touch-action: none;
}

/* -- Arcade theme ------------------------------------------------------- */

.theme-arcade {
    --term-viewport-bg: #07070a;
    --term-window-bg: #101015;
    --term-titlebar-bg: #0c0c10;
    --term-text: #f2f2f2;
    --term-text-muted: #5a5a66;
    --term-accent: #06b6d4;
    --term-border: #3a3a46;
    --term-prompt: #5a5a66;
    --term-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 12px 40px rgba(0, 0, 0, 0.6);
    --term-dot-red: #c43e3a;
    --term-dot-yellow: #c4a02a;
    --term-dot-green: #2a9e3e;
}

.theme-arcade .terminal-window {
    border-width: 2px;
    border-radius: 4px;
}

.theme-arcade .terminal-titlebar {
    border-bottom-width: 2px;
}

.theme-arcade .dot {
    border-radius: 2px;
    width: 10px;
    height: 10px;
}

.theme-arcade .titlebar-title {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.6875rem;
}

.theme-arcade .titlebar-toggle {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid #3a3a46;
    border-radius: 2px;
}

.theme-arcade .titlebar-toggle-btn {
    border-radius: 1px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.theme-arcade .titlebar-toggle-btn.active {
    background: #06b6d4;
    color: #f2f2f2;
}

.theme-arcade .terminal-output .line.command .prompt-echo {
    color: #5a5a66;
}

/* -- Mobile ------------------------------------------------------------- */

@media (max-width: 768px) {
    .terminal-viewport {
        padding: 0;
        padding-top: env(safe-area-inset-top);
    }

    .terminal-window {
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
        box-shadow: none;
    }

    .terminal-body {
        padding: 16px 16px 0;
    }

    .terminal-output {
        font-size: 0.875rem;
        line-height: 1.55;
    }

    .terminal-input {
        font-size: 1rem;
    }

    .terminal-prompt {
        font-size: 0.875rem;
    }

    #game-canvas {
        max-width: 95vw;
        max-height: 60vh;
    }
}

@media (max-width: 480px) {
    .terminal-body {
        padding: 12px 12px 0;
    }

    .terminal-output {
        font-size: 0.8125rem;
    }

    .terminal-input {
        font-size: 1rem;
    }

    .terminal-prompt {
        font-size: 0.8125rem;
    }
}
