*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: #0a0a0a;
    overscroll-behavior: none;
}

.game-body {
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    height: 100dvh;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    overflow: hidden;
}

.game-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-shrink: 0;
    height: 2.25rem;
    padding: 0 0.75rem;
    background: #121212;
    border-bottom: 1px solid #2a2a2a;
    font-family: system-ui, sans-serif;
    font-size: 0.8rem;
}

.back-link {
    color: #888;
    text-decoration: none;
    white-space: nowrap;
}

.back-short {
    display: none;
}

.back-link:hover {
    color: #ccc;
}

.game-bar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.conn-status {
    flex-shrink: 0;
    font-family: ui-monospace, monospace;
    font-size: 0.65rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.conn-status::before {
    content: "";
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    margin-right: 0.3rem;
    vertical-align: 0.05em;
}

.conn-status[data-state="connected"] {
    color: #6a9;
}

.conn-status[data-state="connected"]::before {
    background: #6a9;
}

.conn-status[data-state="connecting"],
.conn-status[data-state="reconnecting"] {
    color: #b93;
}

.conn-status[data-state="connecting"]::before,
.conn-status[data-state="reconnecting"]::before {
    background: #b93;
}

.conn-status[data-state="reconnecting"]::before {
    animation: conn-pulse 1.4s ease-in-out infinite;
}

@keyframes conn-pulse {
    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.35;
    }
}

.seed-badge {
    color: #666;
    font-family: ui-monospace, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#terminal-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    padding: 4px;
    background: #0a0a0a;
    cursor: text;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y;
}

#terminal {
    width: 100%;
    height: 100%;
}

#terminal .xterm-viewport {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

#terminal .xterm-screen {
    padding-bottom: 0.75rem;
}

#terminal .xterm-cursor-layer {
    display: none;
}

#crt-scanline-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
        linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 4px, 6px 100%;
    z-index: 10;
    pointer-events: none;
}

#terminal-wrap::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, 0.35) 100%);
    z-index: 11;
    pointer-events: none;
}

#terminal-wrap.light-terminal #crt-scanline-overlay {
    opacity: 0.2;
    background:
        linear-gradient(rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.04) 50%),
        linear-gradient(90deg, rgba(255, 0, 0, 0.02), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.02));
    background-size: 100% 4px, 6px 100%;
}

#terminal-wrap.light-terminal::after {
    background: radial-gradient(ellipse at center, transparent 80%, rgba(0, 0, 0, 0.05) 100%);
}

.command-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    z-index: 20;
    padding: 0.5rem 0.75rem;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    background: #121212;
    border-top: 1px solid #2a2a2a;
}

.command-prompt {
    flex-shrink: 0;
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
    font-size: 15px;
    line-height: 1;
    color: #888;
    user-select: none;
}

#command-input {
    flex: 1;
    min-width: 0;
    padding: 0.35rem 0;
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
    font-size: 15px;
    line-height: 1.2;
    color: #e0e0e0;
    background: transparent;
    border: none;
    outline: none;
}

#command-input::placeholder {
    color: #555;
}

#command-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .game-bar {
        height: 2.5rem;
        padding: 0 0.5rem;
        font-size: 0.75rem;
    }

    #terminal-wrap {
        padding: 2px;
    }

    #crt-scanline-overlay {
        opacity: 0.38;
    }

    #terminal-wrap::after {
        opacity: 0.35;
    }

    #terminal-wrap.light-terminal #crt-scanline-overlay {
        opacity: 0.12;
    }

    #terminal-wrap.light-terminal::after {
        opacity: 0.35;
    }

    .command-bar {
        min-height: 2.75rem;
        padding: 0.625rem 0.5rem;
        padding-bottom: max(0.625rem, env(safe-area-inset-bottom));
    }

    .command-prompt,
    #command-input {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .back-long {
        display: none;
    }

    .back-short {
        display: inline;
    }

    .conn-status {
        font-size: 0.6rem;
    }

    .seed-badge {
        max-width: 6.5rem;
        font-size: 0.65rem;
    }
}
