/* GhostBeam - Neo-Brutalist Bento Grid Theme */

:root {
    --bg-primary: #f0f0f0; /* Light gray background to pop colors */
    --bg-secondary: #ffffff;
    --bg-tertiary: #ededed;
    --bg-chat: #fdfdfd;
    --text-primary: #000000;
    
    --border-color: #000000;
    --border-width: 4px;
    
    --shadow-distance: 8px;
    --shadow-solid: var(--shadow-distance) var(--shadow-distance) 0px #000000;
    --shadow-active: 2px 2px 0px #000000;
    
    --accent-red: #ff4949;
    --accent-blue: #4d90fe;
    --accent-yellow: #ffdb4d;
    --accent-pink: #ff66b2;
    --accent-green: #00e676;
    --accent-cyan: #18ffff;
    
    --radius: 0px; 
    --radius-full: 999px;
    --transition: transform 0.1s ease, box-shadow 0.1s ease;
    
    --font-heading: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --overlay-grid-a: rgba(0, 0, 0, 0.05);
    --overlay-grid-b: rgba(0, 0, 0, 0.08);
    --hero-panel: #ffffff;
    --modal-overlay: rgba(0, 0, 0, 0.8);
    --theme-toggle-bg: #ffffff;
    --theme-toggle-fg: #000000;
    --text-on-accent: #000000;
    --text-on-accent-strong: #ffffff;
    --stroke-soft: rgba(0, 0, 0, 0.2);
    --inset-shadow: rgba(0, 0, 0, 0.1);
    --heading-shadow: #000000;
}

body.dark-mode {
    --bg-primary: #111216;
    --bg-secondary: #1a1c22;
    --bg-tertiary: #21242d;
    --bg-chat: #171920;
    --text-primary: #f0f1f4;

    --border-color: #3a3d48;
    --shadow-solid: var(--shadow-distance) var(--shadow-distance) 0px rgba(0, 0, 0, 0.45);
    --shadow-active: 2px 2px 0px rgba(0, 0, 0, 0.45);

    --accent-red: #e54868;
    --accent-blue: #5a9cff;
    --accent-yellow: #f5c842;
    --accent-pink: #e86bac;
    --accent-green: #34d885;
    --accent-cyan: #30e0e0;

    --overlay-grid-a: rgba(255, 255, 255, 0.02);
    --overlay-grid-b: rgba(255, 255, 255, 0.035);
    --hero-panel: #1a1c22;
    --modal-overlay: rgba(0, 0, 0, 0.85);
    --theme-toggle-bg: #21242d;
    --theme-toggle-fg: #f0f1f4;
    --text-on-accent: #111216;
    --text-on-accent-strong: #111216;
    --stroke-soft: rgba(255, 255, 255, 0.15);
    --inset-shadow: rgba(0, 0, 0, 0.4);
    --heading-shadow: rgba(0, 0, 0, 0.7);
}

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

body {
    background: var(--bg-primary);
    background-image: 
        linear-gradient(var(--overlay-grid-a) 2px, transparent 2px),
        linear-gradient(90deg, var(--overlay-grid-a) 2px, transparent 2px),
        linear-gradient(var(--overlay-grid-b) 1px, transparent 1px),
        linear-gradient(90deg, var(--overlay-grid-b) 1px, transparent 1px);
    background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
    background-position: -2px -2px, -2px -2px, -1px -1px, -1px -1px;
    font-family: var(--font-body);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    padding: 2rem 1rem;
}

.theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
    font-size: 0.9rem;
    padding: 0.7rem 1rem;
    background: var(--theme-toggle-bg);
    color: var(--theme-toggle-fg);
}

/* Screen Management */
.screen {
    display: none;
    max-width: 900px;
    margin: 0 auto;
}
.screen.active {
    display: block;
}

/* Base Bento Box (Neo-Brutalist Component) */
.bento-box {
    background: var(--bg-secondary);
    border: var(--border-width) solid var(--border-color);
    box-shadow: var(--shadow-solid);
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

/* Base Buttons & Inputs */
.neo-btn {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.2rem;
    text-transform: uppercase;
    padding: 1rem 1.5rem;
    cursor: pointer;
    background: var(--bg-secondary);
    border: var(--border-width) solid var(--border-color);
    box-shadow: var(--shadow-solid);
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}
.neo-btn:hover {
    transform: translate(calc(var(--shadow-distance) / 2), calc(var(--shadow-distance) / 2));
    box-shadow: 4px 4px 0px var(--border-color);
}
.neo-btn:active {
    transform: translate(var(--shadow-distance), var(--shadow-distance));
    box-shadow: 0px 0px 0px var(--border-color);
}

.neo-btn.primary { background: var(--accent-blue); color: var(--text-on-accent-strong); }
.neo-btn.secondary { background: var(--accent-pink); color: var(--text-on-accent); }
.neo-btn.danger { background: var(--accent-red); color: var(--text-on-accent-strong); }
.neo-btn.outline { background: transparent; }
.neo-btn.small { padding: 0.5rem 1rem; font-size: 0.9rem; }
.neo-btn.square { padding: 0.5rem; width: 50px; height: 50px; font-size: 1.2rem;}

.full-width { width: 100%; }
.mt-1 { margin-top: 1rem; }
.hidden { display: none !important; }
.uppercase { text-transform: uppercase; }

.neo-input {
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 600;
    padding: 1rem;
    border: var(--border-width) solid var(--border-color);
    background: var(--bg-secondary);
    width: 100%;
    outline: none;
    box-shadow: inset 4px 4px 0px var(--inset-shadow);
}
.neo-input:focus {
    background: var(--accent-yellow);
    color: var(--text-on-accent);
}

.neo-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    font-family: var(--font-heading);
    font-weight: 800;
    text-transform: uppercase;
    background: var(--accent-cyan);
    border: 2px solid var(--border-color);
    box-shadow: 3px 3px 0px var(--border-color);
    font-size: 0.9rem;
}
.neo-badge.small { box-shadow: 2px 2px 0px var(--border-color); font-size: 0.8rem;}
a.neo-badge { text-decoration: none; color: var(--text-primary); }
a.neo-badge:hover { background: var(--accent-yellow); }

/* ==== BENTO GRID LAYOUTS ==== */

/* Landing Setup */
#landing-screen .bento-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: minmax(150px, auto);
    gap: 1.5rem;
}

.hero-box {
    grid-column: span 2;
    background: var(--accent-yellow);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
}

.hero-box h1 {
    font-family: var(--font-heading);
    font-size: 4rem;
    font-weight: 800;
    letter-spacing: -2px;
    background: var(--hero-panel);
    border: var(--border-width) solid var(--border-color);
    padding: 0.25rem 1rem;
    box-shadow: 4px 4px 0px var(--border-color);
    margin: 1rem 0;
}

.hero-box .tagline {
    font-weight: 700;
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

.logo-container {
    background: var(--hero-panel);
    border: var(--border-width) solid var(--border-color);
    border-radius: 50%;
    width: 116px;
    height: 116px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 4px 4px 0 var(--border-color);
    overflow: hidden;
}

.ghost-logo {
    width: 86%;
    height: 86%;
    object-fit: contain;
    display: block;
}
.ghost-logo-dark {
    display: none;
}
body.dark-mode .ghost-logo-light {
    display: none;
}
body.dark-mode .ghost-logo-dark {
    display: block;
}

.create-box {
    background: var(--accent-cyan);
}
.join-box {
    background: var(--bg-secondary);
}

.create-box h2, .join-box h2, .info-box h2, .privacy-box h2 {
    font-family: var(--font-heading);
    font-size: 2rem;
    margin-bottom: 0.5rem;
    border-bottom: 4px solid var(--border-color);
    padding-bottom: 0.5rem;
    display: inline-block;
}
.create-box p, .join-box p {
    font-weight: 600;
    margin-bottom: 1.5rem;
}

.info-box {
    grid-column: span 2;
    background: var(--accent-pink);
}
.info-box p {
    font-weight: 600;
    line-height: 1.5;
    background: var(--bg-secondary);
    padding: 1rem;
    border: 3px solid var(--border-color);
    margin-bottom: 1rem;
}

.privacy-box {
    grid-column: span 2;
    background: var(--bg-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}
.privacy-box h2 { margin-bottom: 0; border: none; }
.privacy-box p { font-weight: 600; font-family: var(--font-heading); }

/* Create & Join Screens */
.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--accent-red);
    color: var(--text-on-accent-strong);
    margin-bottom: 1.5rem;
    border: var(--border-width) solid var(--border-color);
    box-shadow: var(--shadow-solid);
}
.app-header h2 { font-family: var(--font-heading); font-size: 1.5rem; text-shadow: 2px 2px 0 var(--heading-shadow);}

.create-bento, .join-bento {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

/* Create boxes */
.status-loading {
    grid-column: span 2;
    background: var(--accent-yellow);
    text-align: center;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 800;
    padding: 3rem;
}
.connection-controls {
    grid-column: span 2;
    background: var(--bg-secondary);
}

.connection-controls h3, .qr-bento h3, .scan-bento h3 {
    font-family: var(--font-heading);
    background: var(--border-color);
    color: var(--bg-secondary);
    display: inline-block;
    padding: 4px 8px;
    margin-bottom: 1rem;
}

.neo-input-box {
    display: flex;
    border: var(--border-width) solid var(--border-color);
    background: var(--bg-tertiary);
    box-shadow: inset 3px 3px 0 var(--inset-shadow);
}
#room-code {
    flex: 1;
    font-family: 'Space Grotesk', monospace;
    font-size: 2rem;
    font-weight: 800;
    text-align: center;
    padding: 1rem;
    background: var(--accent-cyan);
}
.link-box input {
    flex: 1;
    font-family: monospace;
    font-size: 1.1rem;
    font-weight: bold;
    padding: 0 1rem;
    border: none;
    background: transparent;
    outline: none;
}
.neo-input-box .neo-btn {
    border: none;
    border-left: var(--border-width) solid var(--border-color);
    box-shadow: none;
}
.neo-input-box .neo-btn:hover { transform: none; background: var(--bg-tertiary); }

.qr-bento {
    grid-column: span 2;
    background: var(--accent-green);
    display: flex;
    flex-direction: column;
    align-items: center;
}
#qr-code {
    background: var(--bg-secondary);
    padding: 1rem;
    border: 4px solid var(--border-color);
}

/* Join boxes */
.input-bento {
    grid-column: span 1;
    background: var(--accent-cyan);
}
.scan-bento {
    grid-column: span 1;
    background: var(--bg-secondary);
}
.input-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 1.5rem;
}
.input-group label {
    font-family: var(--font-heading);
    font-weight: 800;
    margin-bottom: 0.5rem;
    background: var(--border-color);
    color: var(--bg-secondary);
    display: inline-block;
    padding: 2px 6px;
    align-self: flex-start;
}

.outline-box {
    border: 4px solid var(--border-color);
    background: var(--bg-secondary);
    min-height: 200px;
}

/* Chat Screen */
#chat-screen {
    height: 90vh; /* Leave room for margin */
    max-width: 1000px;
    background: var(--bg-secondary);
    border: var(--border-width) solid var(--border-color);
    box-shadow: var(--shadow-solid);
}
#chat-screen.active {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 4rem);
}
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--accent-yellow);
    border-bottom: var(--border-width) solid var(--border-color);
}
.room-stats { display: flex; align-items: center; gap: 1rem; font-weight: 800; min-width: 0; }
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
#chat-room-name {
    display: inline-block;
    max-width: 55vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--bg-chat);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.system-message {
    align-self: center;
    background: var(--accent-red);
    color: var(--text-on-accent-strong);
    font-family: var(--font-heading);
    font-weight: 800;
    padding: 0.5rem 1rem;
    border: 3px solid var(--border-color);
    box-shadow: 4px 4px 0 var(--border-color);
}

.message {
    max-width: 80%;
    padding: 1rem;
    border: 3px solid var(--border-color);
    box-shadow: 4px 4px 0 var(--border-color);
    background: var(--bg-secondary);
    font-weight: 600;
    word-break: break-word;
}
.message.own {
    align-self: flex-end;
    background: var(--accent-blue);
    color: var(--text-on-accent-strong);
}
.message.other {
    align-self: flex-start;
    background: var(--accent-cyan);
    color: var(--text-on-accent);
}
.message-header {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    border-bottom: 2px solid var(--stroke-soft);
    padding-bottom: 0.25rem;
}
.message-content { line-height: 1.5; }
.file-message {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.file-preview {
    max-width: 100%;
    max-height: 220px;
    object-fit: contain;
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
}
.file-preview-blurred {
    filter: blur(14px);
}
.file-meta {
    font-size: 0.85rem;
    font-weight: 800;
    word-break: break-word;
}
.file-download {
    width: fit-content;
    text-decoration: none;
}
.transfer-progress-track {
    width: 100%;
    height: 12px;
    border: 2px solid var(--border-color);
    background: var(--bg-tertiary);
    overflow: hidden;
}
.transfer-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-green);
    transition: width 0.15s ease;
}
.transfer-status {
    font-size: 0.8rem;
    font-weight: 800;
}
.transfer-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.message-time {
    font-size: 0.75rem;
    font-weight: 700;
    text-align: right;
    margin-top: 0.5rem;
    opacity: 0.8;
}

.typing-box {
    background: var(--accent-pink);
    color: var(--text-on-accent);
    padding: 0.5rem 1rem;
    font-family: var(--font-heading);
    font-weight: 800;
    border-top: var(--border-width) solid var(--border-color);
    border-bottom: var(--border-width) solid var(--border-color);
}

.chat-input-area {
    display: flex;
    padding: 1rem;
    background: var(--bg-secondary);
    gap: 1rem;
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}
.chat-input-area .neo-input { box-shadow: none; border-width: 3px;}
.chat-input-area .neo-btn { box-shadow: 4px 4px 0 var(--border-color); }
#btn-attach {
    flex-shrink: 0;
}

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}
.error-box { max-width: 500px; background: var(--accent-red); color: var(--text-on-accent-strong); }
.error-box h2 { border-bottom: 3px solid var(--border-color); padding-bottom: 0.5rem; margin-bottom: 1rem;}
.error-box p { font-weight: 600; font-size: 1.1rem; }

.confirm-box {
    max-width: 520px;
    background: var(--accent-yellow);
    color: var(--text-on-accent);
}
.confirm-box h2 {
    border-bottom: 3px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}
.confirm-box p {
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.4;
}
.confirm-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.privacy-modal-box {
    max-width: 620px;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.privacy-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.privacy-modal-box h2 {
    border-bottom: 3px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 0;
}

.founder-btn {
    text-decoration: none;
    flex-shrink: 0;
}

.privacy-modal-box p {
    font-weight: 600;
    line-height: 1.45;
    margin-bottom: 0.75rem;
}

/* Dark mode element overrides */
body.dark-mode .connection-controls h3,
body.dark-mode .qr-bento h3,
body.dark-mode .scan-bento h3 {
    background: #f0f1f4;
    color: #111216;
}

body.dark-mode .input-group label {
    background: #f0f1f4;
    color: #111216;
}

body.dark-mode .hero-box {
    background: var(--accent-yellow);
}

body.dark-mode .hero-box h1 {
    color: #f0f1f4;
    border-color: #3a3d48;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.45);
}

body.dark-mode .neo-badge {
    border-color: #3a3d48;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.45);
    color: #111216;
}

body.dark-mode .neo-btn:hover {
    box-shadow: 4px 4px 0px #3a3d48;
}

body.dark-mode .neo-input:focus {
    background: #3a3520;
    color: #f5c842;
}

body.dark-mode .link-box input {
    color: var(--text-primary);
}

body.dark-mode .error-box {
    color: #fff;
}

body.dark-mode .error-box h2 {
    border-bottom-color: rgba(255, 255, 255, 0.3);
}

body.dark-mode .system-message {
    border-color: #3a3d48;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
    color: #fff;
}

body.dark-mode .message.own {
    color: #fff;
}

body.dark-mode .app-header {
    color: #fff;
}

body.dark-mode .message {
    border-color: #3a3d48;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.45);
}

body.dark-mode .chat-header {
    border-bottom-color: #3a3d48;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        padding: 0.75rem 0.5rem;
    }

    #landing-screen .bento-grid {
        grid-template-columns: 1fr;
    }
    .hero-box, .info-box, .privacy-box {
        grid-column: span 1;
    }
    .hero-box h1 { font-size: 3rem; }
    
    .create-bento, .join-bento {
        grid-template-columns: 1fr;
    }
    .status-loading, .connection-controls, .qr-bento, .input-bento, .scan-bento {
        grid-column: span 1;
    }
    
    #room-code { font-size: 1.5rem; }

    .theme-toggle {
        top: auto;
        bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
        right: 0.5rem;
        padding: 0.6rem 0.8rem;
        font-size: 0.82rem;
    }

    body.keyboard-open .theme-toggle {
        display: none;
    }

    #chat-screen.active {
        height: calc(100dvh - 1rem);
    }

    .chat-header {
        padding: 0.75rem;
    }

    .room-stats {
        gap: 0.5rem;
        font-size: 0.9rem;
    }

    #chat-room-name {
        max-width: 44vw;
    }

    .chat-input-area {
        gap: 0.5rem;
        padding: 0.65rem;
        padding-bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
    }

    .chat-input-area .neo-input {
        font-size: 16px;
        padding: 0.75rem;
    }

    #btn-send,
    #btn-attach,
    .neo-btn.square {
        width: 44px;
        min-width: 44px;
        height: 44px;
        padding: 0.35rem;
        font-size: 1rem;
    }
}

@media (max-width: 420px) {
    .theme-toggle {
        min-width: 44px;
        padding: 0.5rem;
    }

    #chat-room-name {
        max-width: 36vw;
    }

    #peer-count {
        font-size: 0.68rem;
        padding: 0.2rem 0.45rem;
    }

    .chat-container {
        padding: 0.7rem;
    }
}

@keyframes blinker { 50% { opacity: 0; } }
.blink { animation: blinker 1s linear infinite; }
