:root {
    --bg-base: #050505;
    --bg-app: #0a0a0c;
    --surface: #141418;
    --surface-highlight: #1f1f25;
    --primary: #00ff88;
    --primary-dim: rgba(0, 255, 136, 0.2);
    --text-main: #ffffff;
    --text-muted: #888899;
    --msg-mine: #004d29;
    --msg-theirs: #1f1f25;
    --danger: #ff4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-base);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh; /* Modern mobile viewport handling */
    width: 100vw;
    overflow: hidden;
}

/* 9:16 Aspect Ratio Container for Desktop, Fullscreen for Mobile */
#app-container {
    width: 100%;
    height: 100%;
    background-color: var(--bg-app);
    position: relative;
    display: flex;
    flex-direction: column;
}

@media (min-aspect-ratio: 9/16) and (min-width: 600px) {
    #app-container {
        height: 90vh;
        width: calc(90vh * 9 / 16);
        border-radius: 24px;
        border: 1px solid #222;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 20px var(--primary-dim);
        overflow: hidden;
    }
}

.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0; 
    left: 0;
    background: var(--bg-app);
}

.screen.active {
    display: flex;
}

/* --- Setup Screen --- */
#setup-screen {
    padding: 30px 20px;
    justify-content: flex-start;
    align-items: center;
    text-align: center;
    overflow-y: auto;
}

.logo {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 40px;
    margin-top: 20px;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.info-box, .connect-box {
    background: var(--surface);
    padding: 25px 20px;
    border-radius: 16px;
    width: 100%;
    margin-bottom: 20px;
    border: 1px solid #222;
}

.info-box p, .connect-box p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.info-box h2 {
    color: var(--text-main);
    font-size: 1.4rem;
    margin-bottom: 12px;
    word-break: break-all;
    font-family: monospace;
    background: var(--bg-base);
    padding: 10px;
    border-radius: 8px;
    user-select: all;
}

button {
    background: var(--primary);
    color: #000;
    border: none;
    padding: 14px 20px;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    font-size: 1rem;
    transition: transform 0.1s, opacity 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

button:active {
    transform: scale(0.98);
    opacity: 0.8;
}

button:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
}

#peer-ready-note {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: -6px 0 16px;
    min-height: 1.2rem;
}

input {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    border: 1px solid #333;
    background: var(--bg-base);
    color: var(--text-main);
    margin-bottom: 15px;
    font-size: 1rem;
    outline: none;
    font-family: monospace;
    transition: border-color 0.2s;
}

input:focus {
    border-color: var(--primary);
}

.disclaimer {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: auto;
    line-height: 1.6;
    padding: 20px 0;
}

/* --- Chat Screen --- */
.chat-header {
    background: var(--surface);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #222;
    z-index: 10;
}

#disconnect-btn {
    width: auto;
    padding: 8px;
    background: var(--surface-highlight);
    color: var(--danger);
    font-size: 1.2rem;
    margin-right: 15px;
    border-radius: 8px;
}

.header-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    overflow: hidden;
}

#chat-status {
    color: var(--text-main);
    font-weight: 600;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.secure-badge {
    font-size: 0.65rem;
    color: var(--primary);
    background: var(--primary-dim);
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 4px;
    font-weight: bold;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    color: var(--text-main);
    word-wrap: break-word;
    position: relative;
}

.message.mine {
    align-self: flex-end;
    background: var(--msg-mine);
    border-bottom-right-radius: 4px;
}

.message.theirs {
    align-self: flex-start;
    background: var(--msg-theirs);
    border-bottom-left-radius: 4px;
}

.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    max-width: 100%;
    padding: 5px;
}

.chat-input-area {
    background: var(--surface);
    padding: 15px;
    display: flex;
    gap: 10px;
    border-top: 1px solid #222;
    padding-bottom: calc(15px + env(safe-area-inset-bottom)); /* iOS safe area */
}

.chat-input-area input {
    margin-bottom: 0;
    flex: 1;
    border-radius: 20px;
    padding: 12px 20px;
    font-family: inherit;
}

.chat-input-area button {
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
}