:root {
    --bg-color: #15202b;
    --text-color: #ffffff;
    --input-bg: #22303c;
    --border-color: #38444d;
    --tweet-bg: #192734;
}

body.light-mode {
    --bg-color: #ffffff;
    --text-color: #000000;
    --input-bg: #f5f8fa;
    --border-color: #ccd6dd;
    --tweet-bg: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Helvetica Neue', Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background-color: var(--tweet-bg);
}

h1 {
    font-size: 24px;
    font-weight: bold;
}

#theme-toggle {
    padding: 5px 10px;
    background-color: #1da1f2;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.app {
    display: flex;
    gap: 20px;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.edit-section, .preview-section {
    flex: 1;
}

h2 {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 10px;
}

textarea, input[type="text"] {
    width: 100%;
    padding: 8px;
    margin-top: 5px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--input-bg);
    color: var(--text-color);
}

.tweet-text-container {
    position: relative;
}

#emoji-btn {
    position: absolute;
    right: 10px;
    bottom: 10px;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
}

#emoji-picker {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    padding: 10px;
    display: none;
    z-index: 10;
    max-height: 200px;
    overflow-y: auto;
    width: 100%;
}

.emoji {
    cursor: pointer;
    margin: 5px;
    font-size: 20px;
    display: inline-block;
}

#drop-zone {
    border: 2px dashed var(--border-color);
    padding: 20px;
    text-align: center;
    background: var(--input-bg);
    transition: background 0.2s;
    cursor: pointer;
}

#drop-zone.dragover {
    background: var(--border-color);
}

#image-list {
    list-style: none;
    margin-top: 10px;
}

#image-list li {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    padding: 5px;
    border: 1px solid var(--border-color);
    margin-bottom: 5px;
    border-radius: 4px;
}

#image-list img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    margin-right: 10px;
}

.drag-handle {
    cursor: move;
    margin-right: 10px;
    color: #8899ac;
}

.remove-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: #8899ac;
    cursor: pointer;
    font-size: 16px;
    display: none;
    transition: color 0.2s ease, transform 0.2s ease;
}

#image-list li:hover .remove-btn {
    display: block;
}

#tweet-preview {
    border: 1px solid var(--border-color);
    padding: 15px;
    max-width: 500px;
    background: var(--tweet-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    gap: 10px;
    border-radius: 10px;
}

#preview-profile-pic {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.tweet-content {
    flex: 1;
}

#preview-username {
    font-weight: bold;
}

#preview-text {
    margin-top: 5px;
    word-wrap: break-word;
}

#preview-media {
    margin-top: 10px;
    width: 100%;
}

/* Media container using grid for all layouts */
.media-container {
    display: grid;
    gap: 4px;
    aspect-ratio: 16 / 9;
}

.media-one {
    grid-template-columns: 1fr;
}

.media-one.portrait {
    aspect-ratio: 4 / 5; /* Fixed for single portrait images */
}

.media-one > div {
    border-radius: 10px;
    overflow: hidden;
}

.media-two {
    grid-template-columns: 1fr 1fr;
}

.media-two > div:first-child {
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
    overflow: hidden;
}

.media-two > div:last-child {
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
    overflow: hidden;
}

.media-three {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr; /* Equal rows for symmetry */
    align-items: stretch; /* Ensures images fill their grid areas */
}

.media-three > div:first-child {
    grid-row: 1 / 3;
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
    overflow: hidden;
}

.media-three > div:nth-child(2) {
    border-top-right-radius: 10px;
    overflow: hidden;
}

.media-three > div:nth-child(3) {
    border-bottom-right-radius: 10px;
    overflow: hidden;
}

.media-four {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.media-four > div:nth-child(1) {
    border-top-left-radius: 10px;
    overflow: hidden;
}

.media-four > div:nth-child(2) {
    border-top-right-radius: 10px;
    overflow: hidden;
}

.media-four > div:nth-child(3) {
    border-bottom-left-radius: 10px;
    overflow: hidden;
}

.media-four > div:nth-child(4) {
    border-bottom-right-radius: 10px;
    overflow: hidden;
}

.media-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tweet-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    color: #8899ac;
    font-size: 14px;
}

.tweet-actions span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.like-button {
    cursor: pointer;
    transition: transform 0.2s ease, color 0.2s ease;
}

.like-button.liked {
    transform: scale(1.2);
    color: #e0245e; /* Twitter-like red color */
}

footer {
    text-align: center;
    padding: 10px;
    font-size: 12px;
    color: #8899ac;
}

footer a {
    color: #1da1f2;
    text-decoration: none;
}

#export-collage-btn {
    margin-top: 10px;
    padding: 10px 20px;
    background-color: #1da1f2;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

/* Hover and active styles */
#theme-toggle:hover, #export-collage-btn:hover {
    background-color: #0a84d6;
}

#theme-toggle:active, #export-collage-btn:active {
    transform: scale(0.98);
}

.remove-btn:hover {
    color: #ff0000;
    transform: scale(1.2);
}

/* Focus styles for accessibility */
#theme-toggle:focus, #export-collage-btn:focus, .remove-btn:focus {
    outline: 2px solid #1da1f2;
    outline-offset: 2px;
}

#char-count {
    font-size: 12px;
    margin-top: 5px;
    text-align: right;
    color: var(--text-color);
}

img.emoji {
    height: 1em;
    width: 1em;
    margin: 0 .05em 0 .1em;
    vertical-align: -0.1em;
}

/* Visually hide elements while keeping them accessible to screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

@media (max-width: 768px) {
    .app {
        flex-direction: column;
    }
    .edit-section, .preview-section {
        width: 100%;
    }
    #tweet-preview {
        max-width: 100%;
    }
}
