:root {
    --background-color: #DAE0E6;
    --content-bg: #FFFFFF;
    --content-bg-hover: #F5F7F8;
    --border-color: #CCCCCC;
    --text-color: #1c1c1c;
    --text-light: #787C7E;
    --brand-blue: #0079D3;
    --brand-orange: #FF4500;
}

body {
    font-family: 'Noto Sans', sans-serif;
    margin: 0;
    background-color: var(--background-color);
    color: var(--text-color);
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
header {
    background-color: var(--content-bg);
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'IBM Plex Sans', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    text-decoration: none;
    color: var(--text-color);
}

.logo img {
    height: 32px;
    width: 32px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    font-weight: bold;
}

.create-post-btn {
    background-color: var(--brand-blue);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
}
.create-post-btn:hover {
    opacity: 0.9;
}

/* New: Settings cog */
.settings-cog {
    cursor: pointer;
    margin-left: 0.5rem;
    color: var(--text-light);
    font-size: 1.2rem;
    transition: color 0.2s;
}

.settings-cog:hover {
    color: var(--text-color);
}

/* New: User avatar in header */
.user-avatar-small {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
}

/* Main Layout */
.main-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.5rem;
    align-items: flex-start;
}

/* Post List */
.post-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.post-card {
    display: flex;
    background-color: var(--content-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.post-card:hover {
    border-color: #898989;
}

.vote-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
    background-color: #F8F9FA;
    flex-shrink: 0;
}

.vote-arrow {
    width: 24px;
    height: 24px;
    cursor: pointer;
    fill: var(--text-light);
}

.vote-arrow.up.voted { fill: var(--brand-orange); }
.vote-arrow.down.voted { fill: var(--brand-blue); }
.vote-arrow:hover { background-color: #e9e9e9; border-radius: 4px; }


.vote-count {
    font-weight: bold;
    font-size: 0.9rem;
    margin: 4px 0;
}

.post-content-container {
    padding: 0.5rem 1rem;
    flex-grow: 1;
}

.post-meta {
    font-size: 0.8rem;
    color: var(--text-light);
}
.post-meta a {
    color: var(--text-color);
    font-weight: bold;
    text-decoration: none;
}
.post-meta a:hover { text-decoration: underline; }

.post-title {
    font-size: 1.2rem;
    margin: 0.5rem 0;
}
.post-body-preview, .post-body {
    font-size: 0.9rem;
    line-height: 1.4;
    max-height: 100px;
    overflow: hidden;
    mask-image: linear-gradient(180deg, #000 60%, transparent);
    -webkit-mask-image: linear-gradient(180deg, #000 60%, transparent);
}
.post-body {
    max-height: none;
    mask-image: none;
    -webkit-mask-image: none;
    margin-top: 1rem;
    word-break: break-word;
}

.post-actions {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--text-light);
}
.attachment-icon {
    font-size: 1rem;
}
.delete-btn {
    color: #ff4500;
    cursor: pointer;
}
.delete-btn:hover { text-decoration: underline; }

/* Subreddit Header */
.subreddit-header {
    margin-bottom: 1rem;
}

.subreddit-banner {
    height: 128px;
    background-color: var(--brand-blue);
    background-size: cover;
    background-position: center;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

.subreddit-banner.editable:hover,
.subreddit-icon.editable:hover {
    cursor: pointer;
    opacity: 0.8; /* Subtle visual cue */
}

.subreddit-icon.editable {
    box-shadow: 0 0 0 4px var(--content-bg), 0 0 0 5px var(--brand-blue); /* Add a border to indicate editability */
}

.subreddit-info-bar {
    background-color: var(--content-bg);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
}

.subreddit-info-content {
    display: flex;
    align-items: flex-start;
    padding: 0 1rem;
}

.subreddit-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 4px solid var(--content-bg);
    margin-top: -14px;
    background-color: var(--content-bg);
    object-fit: cover; /* Ensure image fills the circle */
}

.subreddit-details {
    padding: 0.75rem 1rem;
}

.subreddit-name {
    font-size: 1.75rem;
    font-weight: bold;
    margin: 0;
}

.subreddit-id {
    font-size: 0.9rem;
    color: var(--text-light);
    font-weight: 500;
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sidebar-widget {
    background-color: var(--content-bg);
    border-radius: 4px;
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.widget-header {
    background-color: var(--brand-blue);
    color: white;
    padding: 0.75rem;
    font-size: 1rem;
    font-weight: bold;
}
.widget-content {
    padding: 1rem;
}
.widget-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.widget-content li {
    margin-bottom: 0.5rem;
}
.widget-content a {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 500;
}
.widget-content a:hover { text-decoration: underline; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 0.75rem; }
.form input, .form textarea, .form select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-sizing: border-box;
    font-family: 'Noto Sans', sans-serif;
    font-size: 1rem;
}
.form textarea {
    min-height: 120px;
    resize: vertical;
}

.form-button {
    align-self: flex-end;
    background-color: var(--brand-blue);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
}
.form-button:hover { opacity: 0.9; }

.form-button-secondary {
    align-self: flex-start;
    background-color: transparent;
    color: var(--brand-blue);
    border: 1px solid var(--brand-blue);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.form-button-secondary:hover { background-color: #f0f8ff; }


.form-attachment {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.form-attachment input[type="file"] {
    display: none;
}
.file-name {
    font-size: 0.9rem;
    color: var(--text-light);
}
#attachment-preview {
    margin-top: 1rem;
    max-width: 100%;
}
#attachment-preview img,
#attachment-preview video {
    max-width: 100%;
    max-height: 400px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}
#attachment-preview audio {
    width: 100%;
}

.post-attachment {
    margin: 1rem 0;
}
.post-attachment img,
.post-attachment video {
    max-width: 100%;
    max-height: 600px;
    display: block;
    margin: 0 auto;
    border-radius: 4px;
}
.post-attachment audio {
    width: 100%;
}


/* Post Detail */
.post-detail-view {
    background-color: var(--content-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
}
.comment-section { padding: 1rem; }
.comment-form { margin-bottom: 1.5rem; }
.comments-list { display: flex; flex-direction: column; gap: 1rem; }

.comment {
    border-left: 2px solid #EDEFF1;
    padding-left: 1rem;
}
.comment-meta {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 0.25rem;
}
.comment-meta .author { color: var(--text-color); font-weight: bold; }
.comment-body { margin: 0; }

/* New: Settings Modal */
.settings-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.settings-modal-content {
    background-color: var(--content-bg);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    width: 90%;
    max-width: 600px;
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
}

.settings-modal-content h3 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.settings-modal-content .close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
}
.settings-modal-content .close-btn:hover {
    color: var(--text-color);
}

.settings-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section h4 {
    margin-top: 0;
    margin-bottom: 1rem;
    color: var(--text-color);
}

/* Profile Picture section */
.current-avatar-preview {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--brand-blue);
    margin-bottom: 1rem;
}

/* Theme selection */
.theme-options {
    display: flex;
    gap: 1rem;
}
.theme-btn {
    background-color: var(--background-color);
    border: 2px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    color: var(--text-color);
    transition: background-color 0.2s, border-color 0.2s;
}
.theme-btn:hover {
    background-color: var(--content-bg-hover);
}
.theme-btn.active {
    border-color: var(--brand-blue);
    background-color: var(--brand-blue);
    color: white;
}
.theme-btn.active.redit-red-theme { /* Specific style for Redit Red active button */
    background-color: var(--brand-orange);
    border-color: var(--brand-orange);
}

/* Dark Theme */
body.theme-dark {
    --background-color: #343536;
    --content-bg: #1A1A1B;
    --content-bg-hover: #212122;
    --border-color: #444444;
    --text-color: #D7DADC;
    --text-light: #818384;
}
body.theme-dark header {
    background-color: var(--content-bg);
    border-bottom-color: var(--border-color);
}
body.theme-dark .logo {
    color: var(--text-color);
}
body.theme-dark .vote-container {
    background-color: var(--content-bg-hover);
}
body.theme-dark .vote-arrow:hover {
    background-color: #3a3a3b;
}
body.theme-dark .post-meta a {
    color: var(--text-color);
}
body.theme-dark .sidebar-widget,
body.theme-dark .post-card,
body.theme-dark .post-detail-view,
body.theme-dark .subreddit-info-bar,
body.theme-dark .settings-modal-content {
    background-color: var(--content-bg);
    border-color: var(--border-color);
}
body.theme-dark .subreddit-icon.editable {
    box-shadow: 0 0 0 4px var(--content-bg), 0 0 0 5px var(--brand-blue);
}
body.theme-dark .form input,
body.theme-dark .form textarea,
body.theme-dark .form select {
    background-color: var(--content-bg);
    border-color: var(--border-color);
    color: var(--text-color);
}
body.theme-dark .theme-btn {
    background-color: var(--background-color);
    border-color: var(--border-color);
    color: var(--text-color);
}
body.theme-dark .theme-btn:hover {
    background-color: var(--content-bg-hover);
}
body.theme-dark .theme-btn.active {
    background-color: var(--brand-blue);
    border-color: var(--brand-blue);
    color: white;
}


/* Redit Red Theme */
body.theme-redit header {
    background-color: var(--brand-orange);
    border-bottom-color: var(--brand-orange);
    color: white; /* Ensure text is white on orange */
}
body.theme-redit .logo {
    color: white;
}
body.theme-redit .settings-cog {
    color: white;
}
body.theme-redit .settings-cog:hover {
    color: rgba(255, 255, 255, 0.8);
}

body.theme-redit .create-post-btn {
    background-color: var(--brand-blue); /* Keep blue for contrast */
}
body.theme-redit .create-post-btn:hover {
    opacity: 0.9;
}

body.theme-redit .subreddit-banner {
    background-color: var(--brand-orange);
}
body.theme-redit .subreddit-icon.editable {
    box-shadow: 0 0 0 4px var(--content-bg), 0 0 0 5px var(--brand-orange); /* Use orange border for editable icon */
}

body.theme-redit .widget-header {
    background-color: var(--brand-orange);
    color: white;
}

body.theme-redit .form-button {
    background-color: var(--brand-orange);
}
body.theme-redit .form-button:hover {
    opacity: 0.9;
}

body.theme-redit .form-button-secondary {
    color: var(--brand-orange);
    border: 1px solid var(--brand-orange);
}
body.theme-redit .form-button-secondary:hover {
    background-color: #ffe6d9; /* Lighter orange for hover */
}
body.theme-redit .theme-btn.active.redit-red-theme {
    background-color: var(--brand-orange);
    border-color: var(--brand-orange);
    color: white;
}

@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
    .sidebar {
        grid-row: 1; /* Move sidebar to top on mobile */
    }
}