body {
    font-family: sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 20px;
    background-color: #f4f4f4;
    color: #333;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2 {
    text-align: center;
    color: #5a5a5a;
    transition: color 0.3s ease;
}

/* New container for header elements */
.header-container {
    text-align: center;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px; /* Space between settings and tabs */
    position: relative; /* Make header-container relative for absolute positioning of settings */
}

.container {
    max-width: 900px;
    margin: 20px auto;
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    gap: 20px;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.input-section {
    flex: 1; /* Takes up available space */
    min-width: 300px; /* Minimum width before wrapping */
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.character-inputs {
    display: flex;
    gap: 20px;
    flex-wrap: wrap; /* Allow character inputs to wrap */
}

.character {
    flex: 1; /* Each character takes up space */
    min-width: 250px; /* Minimum width for character box */
    border: 1px solid #ddd;
    padding: 15px;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-color 0.3s ease;
}

label {
    font-weight: bold;
    margin-bottom: 5px;
    transition: color 0.3s ease;
}

input[type="text"],
textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box; /* Include padding in width */
    font-size: 1rem;
    resize: vertical; /* Allow vertical resizing of textareas */
    background-color: #fff;
    color: #333;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

textarea {
    min-height: 80px; /* Minimum height for details */
}

#extra-info {
    min-height: 100px; /* Minimum height for extra info */
}

.options {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap; /* Allow options to wrap */
}

.word-count-setting {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.word-count-setting input[type="number"] {
    width: 80px; /* Adjust width for number input */
    text-align: center;
}

.image-settings {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    border-top: 1px dashed #ddd;
    padding-top: 15px;
}

.image-settings h2 {
    text-align: left;
    margin-top: 0;
    margin-bottom: 5px;
}

.thumbnail-preview {
    border: 1px solid #ddd;
    border-radius: 4px;
    min-height: 150px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-color: #f9f9f9;
}

.thumbnail-preview img {
    max-width: 100%;
    max-height: 150px; /* Limit height to fit preview box */
    object-fit: contain;
}

.thumbnail-preview p {
    color: #888;
    font-style: italic;
}

.button-group {
    display: flex;
    gap: 10px; /* Space between the buttons */
    flex-wrap: wrap; /* Allow buttons to wrap if needed */
}

.button-group button {
    flex: 1; /* Allow buttons to grow and shrink */
    min-width: 150px; /* Minimum width for each button */
    width: auto; /* Override default 100% width for flex item */
}

button {
    display: block; /* Make button take full width */
    width: 100%;
    padding: 10px 15px;
    background-color: #5cb85c;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: background-color 0.3s ease;
}

button:hover {
    background-color: #4cae4c;
}

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

#post-story-btn {
    background-color: #007bff; /* Different color for post button */
}

#post-story-btn:hover {
    background-color: #0056b3;
}

#generate-image-btn {
    background-color: #6c757d; /* Gray color for image generation */
}
#generate-image-btn:hover {
    background-color: #5a6268;
}

.output-section {
    flex: 1; /* Takes up available space */
    min-width: 300px; /* Minimum width before wrapping */
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#word-count {
    margin-bottom: 5px;
    font-weight: bold;
    text-align: right;
    color: #5a5a5a;
    transition: color 0.3s ease;
}

#story-output {
    border: 1px solid #ddd;
    padding: 15px;
    border-radius: 4px;
    background-color: #f9f9f9;
    white-space: pre-wrap; /* Preserve whitespace and wrap text */
    word-wrap: break-word; /* Break long words */
    min-height: 120px; /* Smaller height for preview */
    overflow: hidden; /* Hide overflow for preview */
    cursor: pointer; /* Indicate it's clickable */
    text-overflow: ellipsis; /* Add ellipsis for overflowed text */
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

#story-output:hover {
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.15); /* Subtle hover effect */
}

.settings-container {
    position: absolute; /* Position absolutely within header-container */
    top: 10px; /* Adjust as needed */
    left: 20px; /* Adjust as needed */
    z-index: 20; /* Ensure it's above other content */
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* Align dropdown to the left */
}

.settings-btn {
    padding: 5px 10px; /* Smaller padding for emoji button */
    font-size: 2em; /* Larger font size for emoji */
    background-color: transparent; /* Transparent background */
    color: #333; /* Dark color for the gear emoji */
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: color 0.3s ease, transform 0.3s ease;
    width: auto; /* Override general button width */
}

.settings-btn:hover {
    background-color: transparent; /* Keep transparent */
    color: #007bff; /* Change color on hover */
    transform: rotate(15deg); /* Slight rotation on hover */
}

.style-switcher {
    text-align: left; /* Align text to left */
    margin-top: 5px; /* Space between settings button and style buttons */
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    /* No longer absolute, let it flow below settings button within its flex container */
    position: static; 
    transform: none;
    z-index: 10;
    display: flex; /* Arrange buttons horizontally */
    flex-direction: column; /* Stack buttons vertically */
    flex-wrap: nowrap; /* Prevent wrapping of style buttons */
    gap: 5px; /* Smaller gap */
}

.style-switcher.hidden {
    display: none;
}

.style-btn {
    padding: 8px 15px;
    margin: 0; /* Reset margin as gap is used */
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #eee;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease;
    width: auto; /* Override general button width */
}

.style-btn:hover {
    background-color: #ddd;
}

/* Red Style */
body.red-style {
    background-color: #ffebee;
    color: #b71c1c;
}

body.red-style h1,
body.red-style h2,
body.red-style label,
body.red-style #word-count {
    color: #d32f2f;
}

body.red-style .container {
    background-color: #ef9a9a;
    box-shadow: 0 0 10px rgba(183, 28, 28, 0.2);
}

body.red-style .character {
    border-color: #e57373;
}

body.red-style input[type="text"],
body.red-style textarea {
    background-color: #ffcdd2;
    border-color: #ef9a9a;
    color: #b71c1c;
}

body.red-style button {
    background-color: #c62828;
}

body.red-style button:hover {
    background-color: #b71c1c;
}
body.red-style #post-story-btn {
    background-color: #b71c1c;
}
body.red-style #post-story-btn:hover {
    background-color: #a30000;
}
body.red-style #generate-image-btn {
    background-color: #8d1c1c;
}
body.red-style #generate-image-btn:hover {
    background-color: #7b1818;
}

body.red-style #story-output {
    background-color: #ffcdd2;
    border-color: #e57373;
    color: #b71c1c;
}
body.red-style .thumbnail-preview {
    background-color: #ffcdd2;
    border-color: #e57373;
}
body.red-style .thumbnail-preview p {
    color: #b71c1c;
}
body.red-style .image-settings {
    border-top-color: #e57373;
}

body.red-style .settings-btn {
    background-color: transparent;
    color: #d32f2f;
}

body.red-style .settings-btn:hover {
    background-color: transparent;
    color: #ef9a9a;
}

body.red-style .style-switcher {
    background-color: #ef9a9a;
    border-color: #e57373;
}

body.red-style .style-btn {
    background-color: #ffcdd2;
    border-color: #ef9a9a;
    color: #b71c1c;
}

body.red-style .style-btn:hover {
    background-color: #e57373;
}

/* Blue Style */
body.blue-style {
    background-color: #e3f2fd;
    color: #0d47a1;
}

body.blue-style h1,
body.blue-style h2,
body.blue-style label,
body.blue-style #word-count {
    color: #1976d2;
}

body.blue-style .container {
    background-color: #90caf9;
    box-shadow: 0 0 10px rgba(13, 71, 161, 0.2);
}

body.blue-style .character {
    border-color: #64b5f6;
}

body.blue-style input[type="text"],
body.blue-style textarea {
    background-color: #bbdefb;
    border-color: #90caf9;
    color: #0d47a1;
}

body.blue-style button {
    background-color: #1565c0;
}

body.blue-style button:hover {
    background-color: #0d47a1;
}
body.blue-style #post-story-btn {
    background-color: #0d47a1;
}
body.blue-style #post-story-btn:hover {
    background-color: #003366;
}
body.blue-style #generate-image-btn {
    background-color: #3f51b5;
}
body.blue-style #generate-image-btn:hover {
    background-color: #303f9f;
}

body.blue-style #story-output {
    background-color: #bbdefb;
    border-color: #64b5f6;
    color: #0d47a1;
}
body.blue-style .thumbnail-preview {
    background-color: #bbdefb;
    border-color: #64b5f6;
}
body.blue-style .thumbnail-preview p {
    color: #0d47a1;
}
body.blue-style .image-settings {
    border-top-color: #64b5f6;
}

body.blue-style .settings-btn {
    background-color: transparent;
    color: #1976d2;
}

body.blue-style .settings-btn:hover {
    background-color: transparent;
    color: #90caf9;
}

body.blue-style .style-switcher {
    background-color: #90caf9;
    border-color: #64b5f6;
}

body.blue-style .style-btn {
    background-color: #bbdefb;
    border-color: #90caf9;
    color: #0d47a1;
}

body.blue-style .style-btn:hover {
    background-color: #64b5f6;
}

/* Dark Mode Style */
body.dark-style {
    background-color: #2c2c2c;
    color: #e0e0e0;
}

body.dark-style h1,
body.dark-style h2,
body.dark-style label,
body.dark-style #word-count {
    color: #f5f5f5;
}

body.dark-style .container {
    background-color: #3c3c3c;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
}

body.dark-style .character {
    border-color: #555;
}

body.dark-style input[type="text"],
body.dark-style textarea {
    background-color: #444;
    border-color: #555;
    color: #e0e0e0;
}

body.dark-style button {
    background-color: #6a6a6a;
}

body.dark-style button:hover {
    background-color: #5a5a5a;
}
body.dark-style #post-story-btn {
    background-color: #5a5a5a;
}
body.dark-style #post-story-btn:hover {
    background-color: #4a4a4a;
}
body.dark-style #generate-image-btn {
    background-color: #4a4a4a;
}
body.dark-style #generate-image-btn:hover {
    background-color: #3a3a3a;
}

body.dark-style #story-output {
    background-color: #444;
    border-color: #555;
    color: #e0e0e0;
}
body.dark-style .thumbnail-preview {
    background-color: #444;
    border-color: #555;
}
body.dark-style .thumbnail-preview p {
    color: #ccc;
}
body.dark-style .image-settings {
    border-top-color: #555;
}

body.dark-style .settings-btn {
    background-color: transparent;
    color: #f5f5f5;
}

body.dark-style .settings-btn:hover {
    background-color: transparent;
    color: #ccc;
}

body.dark-style .style-switcher {
    background-color: #3c3c3c;
    border-color: #555;
}

body.dark-style .style-btn {
    background-color: #444;
    border-color: #555;
    color: #e0e0e0;
}

body.dark-style .style-btn:hover {
    background-color: #555;
}

.style-btn.active {
    border-color: #5cb85c;
    box-shadow: 0 0 5px rgba(92, 184, 92, 0.5);
}

/* Tab Styles */
.tab-container {
    display: flex; /* Make buttons align horizontally */
    gap: 10px; /* Space between tab buttons */
}

.tab-btn {
    padding: 10px 20px;
    margin: 0; /* Reset margin as gap is used */
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #f0f0f0;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    font-size: 1.1rem;
    width: auto; /* Override general button width */
}

.tab-btn:hover {
    background-color: #e0e0e0;
}

.tab-btn.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

.tab-btn.active:hover {
    background-color: #0056b3;
}

.content-section.hidden {
    display: none;
}

/* Community Stories List */
#community-stories-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 10px;
}

.community-story-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    background-color: #f9f9f9;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer; /* Indicate it's clickable */
    display: flex; /* Enable flexbox for card content */
    align-items: flex-start; /* Align thumbnail and text to top */
    gap: 15px; /* Space between thumbnail and text content */
}

.community-story-card:hover {
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.15); /* Subtle hover effect */
}

.community-story-card-content { /* New div to contain text content */
    flex: 1; /* Allow text content to take remaining space */
}

.story-card-thumbnail { /* Style for thumbnail within the card */
    width: 120px;
    height: 90px;
    object-fit: cover; /* Cover the area, cropping if necessary */
    border-radius: 4px;
    flex-shrink: 0; /* Prevent thumbnail from shrinking */
    border: 1px solid #eee;
}

body.dark-style .story-card-thumbnail {
    border-color: #666;
}

.community-story-card h3 {
    margin-top: 0;
    margin-bottom: 5px;
    color: #333;
    transition: color 0.3s ease;
}

.community-story-card p {
    font-size: 0.9rem;
    color: #555;
    margin-top: 0;
    margin-bottom: 10px;
    transition: color 0.3s ease;
}

.community-story-card small {
    display: block;
    text-align: right;
    color: #777;
    font-size: 0.8em;
}

/* Story preview text within the card */
.story-preview-text {
    font-size: 0.95rem;
    color: #555;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 100px; /* Limit height of preview */
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 10px;
}

/* Dark mode adjustments for community section */
body.dark-style .tab-btn {
    background-color: #555;
    color: #eee;
    border-color: #666;
}

body.dark-style .tab-btn:hover {
    background-color: #666;
}

body.dark-style .tab-btn.active {
    background-color: #6a6a6a;
    border-color: #6a6a6a;
}

body.dark-style .tab-btn.active:hover {
    background-color: #5a5a5a;
}

body.dark-style #community-stories-list {
    border-color: #555;
}

body.dark-style .community-story-card {
    background-color: #444;
    border-color: #555;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

body.dark-style .community-story-card h3 {
    color: #f5f5f5;
}

body.dark-style .community-story-card p,
body.dark-style .story-preview-text {
    color: #ccc;
}
body.dark-style .community-story-card small {
    color: #aaa;
}

/* Modal Styles */
.modal {
    position: fixed; /* Stay in place */
    z-index: 100; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    display: none; /* Changed from flex to none */
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    border-radius: 8px;
    width: 90%; /* Could be more responsive */
    max-width: 700px; /* Max width for readability */
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
    position: relative;
    max-height: 90vh; /* Max height to prevent overflow on small screens */
    overflow-y: auto; /* Scroll content if it's too long */
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.modal-content h2 {
    text-align: center;
    margin-top: 0;
    color: #333;
}

.modal-content p {
    text-align: center;
    font-style: italic;
    color: #666;
    margin-bottom: 15px;
}

#modal-story-thumbnail { /* Style for thumbnail in modal */
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto 20px auto;
    border-radius: 8px;
    border: 1px solid #ddd;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
body.dark-style #modal-story-thumbnail {
    border-color: #555;
}

#modal-story-full-text {
    white-space: pre-wrap; /* Preserve whitespace and wrap text */
    word-wrap: break-word; /* Break long words */
    color: #333;
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 20px; /* Space before interactions */
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}

/* Dark mode for modal */
body.dark-style .modal-content {
    background-color: #3c3c3c;
    border-color: #555;
    color: #e0e0e0;
}

body.dark-style .modal-content h2 {
    color: #f5f5f5;
}

body.dark-style .modal-content p {
    color: #bbb;
}

body.dark-style #modal-story-full-text {
    color: #e0e0e0;
}

body.dark-style .close-button {
    color: #bbb;
}

body.dark-style .close-button:hover,
body.dark-style .close-button:focus {
    color: #fff;
}

/* New styles for interactions (likes/comments) */
.modal-interactions {
    border-top: 1px solid #eee;
    padding-top: 20px;
    margin-top: 20px;
}

body.dark-style .modal-interactions {
    border-top-color: #555;
}

.likes-section {
    text-align: center;
    margin-bottom: 20px;
    display: flex; /* Use flexbox to align buttons */
    justify-content: center; /* Center the buttons horizontally */
    gap: 15px; /* Space between like and dislike buttons */
}

#like-button {
    background-color: #28a745;
    padding: 8px 15px;
    font-size: 1rem;
    display: inline-block; /* Allow it to center */
    width: auto; /* Reset width */
}

#like-button:hover {
    background-color: #218838;
}

/* Dislike button styles */
#dislike-button {
    background-color: #dc3545; /* Red color for dislike */
    padding: 8px 15px;
    font-size: 1rem;
    display: inline-block;
    width: auto;
}

#dislike-button:hover {
    background-color: #c82333;
}

.comments-section h3 {
    text-align: left;
    margin-top: 0;
    margin-bottom: 15px;
    color: #333;
}

body.dark-style .comments-section h3 {
    color: #f5f5f5;
}

#comments-list {
    border: 1px solid #ddd;
    padding: 10px;
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 15px;
    border-radius: 4px;
    background-color: #f9f9f9;
}

body.dark-style #comments-list {
    background-color: #444;
    border-color: #555;
}

.comment-item {
    padding: 10px 0;
    border-bottom: 1px dashed #eee;
}

body.dark-style .comment-item {
    border-bottom-color: #555;
}

.comment-item:last-child {
    border-bottom: none;
}

.comment-author {
    font-size: 0.9em;
    color: #555;
    margin-bottom: 5px;
}

body.dark-style .comment-author {
    color: #ccc;
}

.comment-content {
    font-size: 0.95em;
    color: #333;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.comment-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin-top: 10px;
    border-radius: 4px;
}

body.dark-style .comment-content {
    color: #e0e0e0;
}

.comment-meta {
    display: block;
    font-size: 0.75em;
    color: #777;
    text-align: right;
    margin-top: 5px;
}

body.dark-style .comment-meta {
    color: #aaa;
}

.comment-input-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#new-comment-text {
    min-height: 60px;
    max-height: 120px; /* Limit height for comment input */
}

#post-comment-btn {
    width: auto; /* Adjust to fit content */
    align-self: flex-end; /* Align button to the right */
    background-color: #007bff;
}

#post-comment-btn:hover {
    background-color: #0056b3;
}

body.dark-style #post-comment-btn {
    background-color: #5a5a5a;
}

body.dark-style #post-comment-btn:hover {
    background-color: #4a4a4a;
}

/* New Community Tab Styles */
.community-tabs {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    gap: 10px;
}

.community-tab-btn {
    padding: 8px 15px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #f0f0f0;
    cursor: pointer;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    font-size: 1rem;
}

.community-tab-btn:hover {
    background-color: #e0e0e0;
}

.community-tab-btn.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

.community-tab-btn.active:hover {
    background-color: #0056b3;
}

body.dark-style .community-tab-btn {
    background-color: #555;
    color: #eee;
    border-color: #666;
}

body.dark-style .community-tab-btn:hover {
    background-color: #666;
}

body.dark-style .community-tab-btn.active {
    background-color: #6a6a6a;
    border-color: #6a6a6a;
}

body.dark-style .community-tab-btn.active:hover {
    background-color: #5a5a5a;
}

/* Story Stats in Community Card */
.story-stats {
    display: flex;
    gap: 15px;
    font-size: 0.9em;
    color: #777;
    margin-top: 5px;
    margin-bottom: 10px;
}

body.dark-style .story-stats {
    color: #aaa;
}

/* Style for the owner tag */
.owner-tag {
    background-color: #f0ad4e; /* A distinct background color */
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7em;
    font-weight: bold;
    margin-left: 5px; /* Space from the username */
    vertical-align: middle; /* Align nicely with text */
    white-space: nowrap; /* Prevent tag from breaking */
}

/* Dark mode for owner tag */
body.dark-style .owner-tag {
    background-color: #d68e2a; /* A slightly darker shade for dark mode */
}

/* Style for the dynamic rank tag */
.rank-tag {
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7em;
    font-weight: bold;
    margin-left: 5px;
    vertical-align: middle;
    white-space: nowrap;
}

.hidden {
    display: none;
}