body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background: #1a1a1a;
    color: #d3d3d3;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

.container {
    width: 100%;
    max-width: 600px;
    height: 100vh;
    background: #2b2b2b;
    border-radius: 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

h1 {
    font-family: 'Creepster', cursive;
    color: #a30000;
    font-size: 2.5em;
    margin: 8px 0;
    text-align: center;
    letter-spacing: 3px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.9), -2px -2px 4px rgba(255, 0, 0, 0.3);
}

.label {
    font-weight: 500;
    color: #999;
    margin: 2px 0;
    text-align: center;
    font-size: 0.85em;
}

.status {
    color: #fff;
    padding: 4px 8px;
    border-radius: 5px;
    font-size: 0.85em;
    text-align: center;
    margin: 5px 15px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.status.connected {
    background: #4a773c;
}

.status.disconnected {
    background: #a30000;
}

.code-inputs {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 0 15px;
}

.code-input {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#chat-box {
    border: 1px solid #444;
    border-radius: 10px;
    overflow-y: auto;
    overflow-x: hidden;
    margin: 10px 15px;
    background: #222;
    padding: 10px;
    text-align: left;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
    white-space: normal;
    height: calc(100vh - 540px); /* Default height */
    min-height: 200px; /* Minimum height to prevent collapse */
    max-height: calc(100vh - 200px); /* Maximum height to leave space for other elements */
    position: relative;
}

.resize-handle {
    width: 100%;
    height: 5px;
    background: #444;
    cursor: ns-resize;
    margin: 0 15px;
}

#chat-box .message {
    margin: 8px 0;
    max-width: 80%;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: transform 0.3s ease;
}

#chat-box .message.sender {
    align-items: flex-end;
    margin-left: auto;
}

#chat-box .message.receiver {
    align-items: flex-start;
    margin-right: auto;
}

#chat-box .message .name {
    font-weight: 600;
    font-size: 0.9em;
    color: #d3d3d3;
    margin-bottom: 2px;
}

#chat-box .message .replied-message {
    background: #555;
    color: #d3d3d3;
    font-size: 0.8em;
    padding: 4px 8px;
    border-radius: 10px;
    margin-bottom: 4px;
    max-width: 100%;
    word-wrap: break-word;
    cursor: pointer;
}

#chat-box .message .replied-message img,
#chat-box .message .replied-message video {
    max-width: 50px;
    max-height: 50px;
    border-radius: 5px;
    margin-top: 4px;
}

#chat-box .message .content {
    padding: 8px 12px;
    border-radius: 15px;
    font-size: 1em;
    max-width: 100%;
    word-wrap: break-word;
    position: relative;
}

#chat-box .message.sender .content {
    background: #a30000;
    color: #fff;
}

#chat-box .message.receiver .content {
    background: #444;
    color: #d3d3d3;
}

#chat-box .message .meta {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75em;
    color: #999;
    margin-top: 2px;
}

#chat-box .message.sender .meta {
    justify-content: flex-end;
}

#chat-box .message .status-text {
    font-size: 0.75em;
}

#chat-box .message .status-text.sent::after {
    content: '✓';
    color: #999;
}

#chat-box .message .status-text.delivered::after {
    content: '✓✓';
    color: #999;
}

#chat-box .message .status-text.seen {
    color: #a30000;
}

#chat-box .message .status-text.seen::after {
    content: 'seen';
}

#chat-box .typing-message {
    margin: 8px 0;
    padding: 0;
    max-width: 80%;
    display: flex;
    align-items: center;
    margin-right: auto;
}

#chat-box .typing-message .dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin: 0 2px;
    background: #999;
    border-radius: 50%;
    animation: dot-flashing 1s infinite linear alternate;
}

#chat-box .typing-message .dot:nth-child(2) {
    animation-delay: 0.2s;
}

#chat-box .typing-message .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dot-flashing {
    0% {
        background: #999;
    }
    50%, 100% {
        background: #ccc;
    }
}

#chat-box img, #chat-box video {
    max-width: 200px;
    border-radius: 8px;
    cursor: pointer;
}

#message-input, #friend-code, #my-code-input {
    width: calc(100% - 20px);
    padding: 8px;
    margin: 3px 0;
    border: 1px solid #444;
    border-radius: 20px;
    font-size: 0.9em;
    background: #333;
    color: #d3d3d3;
    transition: border-color 0.3s ease;
}

#message-input:focus, #friend-code:focus, #my-code-input:focus {
    border-color: #a30000;
    outline: none;
}

button {
    padding: 6px 12px;
    margin: 3px;
    background: #a30000;
    color: #fff;
    border: none;
    border-radius: 15px;
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.1s ease;
}

button:hover:not(:disabled) {
    background: #c70000;
    transform: scale(1.03);
}

button:disabled {
    background: #555;
    cursor: not-allowed;
}

.button-group {
    display: flex;
    justify-content: center;
    gap: 10px;
}

#connect-btn {
    background: #4a773c;
}

#connect-btn:hover:not(:disabled) {
    background: #5a8a4c;
}

#disconnect-btn {
    background: #7a0000;
}

#disconnect-btn:hover:not(:disabled) {
    background: #8a1010;
}

#file-input {
    display: none;
}

.file-label {
    display: inline-block;
    padding: 6px;
    margin: 3px;
    background: none;
    color: #d3d3d3;
    font-size: 1.2em;
    cursor: pointer;
    transition: color 0.3s ease;
}

.file-label:hover {
    color: #a30000;
}

.send-btn {
    background: none;
    padding: 6px;
    margin: 3px;
    font-size: 1.2em;
    color: #d3d3d3;
    border: none;
    cursor: pointer;
    transition: color 0.3s ease;
}

.send-btn:hover {
    color: #a30000;
}

.input-container {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: #2b2b2b;
    border-top: 1px solid #444;
    width: 100%;
    max-width: 570px;
    box-sizing: border-box;
    flex-wrap: nowrap;
    position: sticky;
    bottom: 0;
    z-index: 10;
}

#message-input {
    flex: 1;
    margin: 3px 5px;
}

#my-code {
    font-weight: 600;
    color: #a30000;
}

.file-preview {
    margin: 3px 5px;
    color: #d3d3d3;
    font-size: 0.85em;
    text-align: center;
    max-width: 50px;
}

.file-preview img, .file-preview video {
    max-width: 50px;
    max-height: 50px;
    border-radius: 5px;
    margin-top: 5px;
}

/* Reply preview area above input */
.reply-preview-area {
    display: none;
    background: #333;
    padding: 5px 15px;
    border-top: 1px solid #444;
    width: 100%;
    max-width: 570px;
    box-sizing: border-box;
    flex-direction: row;
    align-items: center;
    gap: 5px;
    position: sticky;
    bottom: 50px; /* Adjust based on input container height */
    z-index: 10;
}

.reply-preview-area.active {
    display: flex;
}

.reply-preview {
    background: #555;
    color: #d3d3d3;
    font-size: 0.8em;
    padding: 4px 8px;
    border-radius: 5px;
    word-wrap: break-word;
    flex: 1;
}

.reply-preview img, .reply-preview video {
    max-width: 50px;
    max-height: 50px;
    border-radius: 5px;
}

.cancel-reply {
    background: #555;
    padding: 5px;
    font-size: 0.8em;
    border: none;
    color: #fff;
    border-radius: 5px;
    cursor: pointer;
}

.cancel-reply:hover {
    background: #666;
}

/* Full-screen media overlay */
.media-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.media-overlay.active {
    display: flex;
}

.media-overlay-content {
    position: relative;
    text-align: center;
}

.media-overlay-content img, .media-overlay-content video {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: 10px;
}

.close-btn {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: #fff;
    font-size: 2em;
    cursor: pointer;
}

.download-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 8px 16px;
    background: #a30000;
    color: #fff;
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.9em;
    transition: background 0.3s ease;
}

.download-btn:hover {
    background: #c70000;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .container {
        height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .code-inputs {
        flex-direction: column;
        gap: 5px;
    }

    .input-container {
        max-width: calc(100% - 30px);
        flex-wrap: nowrap;
    }

    #message-input {
        flex: 1;
        margin: 3px 5px;
    }

    .file-label {
        margin: 3px 5px;
    }

    .file-preview {
        display: block;
    }

    #chat-box {
        height: calc(100vh - 560px); /* Default height for mobile */
        min-height: 200px;
        max-height: calc(100vh - 220px);
    }

    .resize-handle {
        margin: 0 15px;
    }

    .reply-preview-area {
        max-width: calc(100% - 30px);
        bottom: 50px; /* Adjust based on input container height */
    }
}

@media (min-width: 601px) {
    .input-container {
        flex-wrap: nowrap;
    }

    #message-input {
        flex: 1;
        margin: 3px 5px;
    }

    .file-label {
        margin: 3px 5px;
    }

    .file-preview {
        margin: 3px 5px;
    }
}
