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

:root {
    --bg-color: #0a0a0a;
    --terminal-bg: #0c0c0c;
    --terminal-fg: #33ff33;
    --terminal-dim: #1a661a;
    --terminal-error: #ff3333;
    --terminal-system: #ffff33;
    --terminal-chat: #33ccff;
    --font-mono: 'Courier New', 'Lucida Console', monospace;
}

html, body {
    height: 100%;
    background: var(--bg-color);
    color: var(--terminal-fg);
    font-family: var(--font-mono);
    font-size: 14px;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

.fullscreen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#login-screen {
    background: var(--bg-color);
    padding: 20px;
}

#ascii-logo {
    font-size: 12px;
    line-height: 1.2;
    color: var(--terminal-fg);
    text-align: left;
    margin-bottom: 20px;
    white-space: pre;
}

#login-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-top: 20px;
}

#login-form .prompt {
    color: var(--terminal-fg);
    margin-bottom: 5px;
}

#nickname-input {
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--terminal-fg);
    color: var(--terminal-fg);
    font-family: var(--font-mono);
    font-size: 16px;
    padding: 5px 0;
    width: 300px;
    outline: none;
}

#nickname-input:focus {
    border-bottom-color: var(--terminal-system);
}

#login-error {
    color: var(--terminal-error);
    margin-top: 10px;
    font-size: 14px;
}

#connection-status {
    margin-top: 30px;
    color: var(--terminal-dim);
    font-size: 12px;
}

#connection-status.connected {
    color: var(--terminal-fg);
}

#connection-status.error {
    color: var(--terminal-error);
}

/* Game Container */
#game-container {
    display: flex;
    height: 100%;
    width: 100%;
}

/* Responsive */
@media (max-width: 900px) {
    #ascii-logo {
        font-size: 8px;
    }

    #game-container {
        flex-direction: column;
    }

    #terminal-panel {
        flex: 2 !important;
    }

    #chat-panel {
        flex: 1 !important;
        border-left: none !important;
        border-top: 1px solid var(--terminal-dim);
    }
}

@media (max-width: 600px) {
    html, body {
        font-size: 13px;
        height: 100%;
        height: calc(var(--vh, 1vh) * 100);
        overflow: hidden;
        position: fixed;
        width: 100%;
        touch-action: manipulation;
    }

    #login-screen {
        padding: 15px;
        justify-content: flex-start;
        padding-top: 5vh;
        overflow-y: auto;
        height: 100%;
        height: calc(var(--vh, 1vh) * 100);
    }

    #ascii-logo {
        font-size: 4.5px;
        line-height: 1.1;
        margin-bottom: 15px;
    }

    #login-form {
        width: 100%;
        padding: 0 10px;
    }

    #login-form .prompt {
        font-size: 12px;
        margin-bottom: 8px;
        display: block;
    }

    #nickname-input,
    #password-input {
        width: 100%;
        max-width: 280px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 8px 0;
    }

    /* Mobile game layout - fixed input at bottom */
    #game-container {
        flex-direction: column;
        height: 100%;
        height: calc(var(--vh, 1vh) * 100);
        overflow: hidden;
    }

    #terminal-panel {
        flex: 1 !important;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 8px;
    }

    #terminal-output {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 5px;
        font-size: 12px;
        line-height: 1.3;
    }

    #terminal-input-line {
        flex-shrink: 0;
        padding: 8px 0;
        border-top: 1px solid var(--terminal-dim);
        background: var(--terminal-bg);
    }

    #prompt {
        font-size: 11px;
    }

    #command-input {
        font-size: 16px; /* Prevents iOS zoom */
    }

    /* Chat panel - collapsible on mobile */
    #chat-panel {
        flex: 0 0 auto !important;
        max-width: 100% !important;
        max-height: 25vh;
        min-height: 80px;
        border-left: none !important;
        border-top: 1px solid var(--terminal-dim);
        overflow: hidden;
    }

    #chat-header {
        padding: 6px 10px;
        font-size: 11px;
    }

    #chat-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 12px;
        padding: 8px;
    }

    .chat-message {
        margin-bottom: 6px;
    }
}

/* Extra small screens (iPhone SE, etc.) */
@media (max-width: 375px) {
    #ascii-logo {
        font-size: 3.8px;
    }

    #terminal-output {
        font-size: 11px;
    }

    #chat-panel {
        max-height: 20vh;
    }
}

/* Safe area insets for notched iPhones */
@supports (padding: env(safe-area-inset-bottom)) {
    @media (max-width: 600px) {
        #terminal-input-line {
            padding-bottom: calc(8px + env(safe-area-inset-bottom));
        }

        #chat-panel {
            padding-bottom: env(safe-area-inset-bottom);
        }

        #login-screen {
            padding-top: calc(5vh + env(safe-area-inset-top));
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
        }
    }
}

/* Password form styles */
#password-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

#password-input {
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--terminal-fg);
    color: var(--terminal-fg);
    font-family: var(--font-mono);
    font-size: 16px;
    padding: 5px 0;
    width: 300px;
    outline: none;
}

#password-input:focus {
    border-bottom-color: var(--terminal-system);
}

/* Ending Screen Overlay */
#ending-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 2s ease-in;
}

#ending-content {
    max-width: 800px;
    max-height: 90vh;
    padding: 40px;
    background: var(--terminal-bg);
    border: 2px solid var(--terminal-fg);
    border-radius: 4px;
    box-shadow: 0 0 50px rgba(51, 255, 51, 0.3);
    overflow-y: auto;
}

#ending-title {
    font-size: 24px;
    color: var(--terminal-system);
    text-align: center;
    margin-bottom: 30px;
    text-shadow: 0 0 10px var(--terminal-system);
}

#ending-text {
    font-size: 14px;
    line-height: 1.6;
    color: var(--terminal-fg);
    white-space: pre-wrap;
    word-wrap: break-word;
}

#ending-footer {
    margin-top: 30px;
    text-align: center;
}

#ending-close {
    background: transparent;
    border: 1px solid var(--terminal-fg);
    color: var(--terminal-fg);
    font-family: var(--font-mono);
    font-size: 16px;
    padding: 10px 30px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#ending-close:hover {
    background: var(--terminal-fg);
    color: var(--bg-color);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Ending solo vs collective variants */
#ending-overlay.solo #ending-content {
    border-color: var(--terminal-dim);
    box-shadow: 0 0 30px rgba(51, 255, 51, 0.2);
}

#ending-overlay.collective #ending-content {
    border-color: var(--terminal-system);
    box-shadow: 0 0 80px rgba(255, 255, 51, 0.4);
}

#ending-overlay.collective #ending-title {
    color: var(--terminal-system);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        text-shadow: 0 0 10px var(--terminal-system);
    }
    50% {
        text-shadow: 0 0 30px var(--terminal-system), 0 0 60px var(--terminal-system);
    }
}
