:root {
    --theme-surface: #ffffff;
    --theme-surface-soft: #f9f9fb;
    --theme-border: #f0f2f5;
    --theme-text: #1c1e21;
    --theme-muted-text: #4b4b4b;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #111318;
    --gray: #aab2c0;
    --primary: #ff6262;
    --theme-surface: #1b2028;
    --theme-surface-soft: #232a34;
    --theme-border: #333c4d;
    --theme-text: #f5f7fb;
    --theme-muted-text: #d7dde8;
}

html[data-theme="dark"],
html[data-theme="dark"] body {
    background: var(--bg) !important;
    color: var(--theme-text) !important;
}

.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: nowrap !important;
}

.logo {
    flex: 0 0 auto;
}

.nav-user-info,
.nav-controls {
    min-width: 0;
    max-width: calc(100% - 112px);
    flex: 0 1 auto;
    overflow: hidden;
}

.nav-user-info > a {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
}

.username-display,
.user-tag {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.username-text,
.user-tag {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.username-text {
    display: inline-block;
    flex: 1 1 auto;
    max-width: 100%;
}

.user-tag {
    display: inline-block;
    flex: 1 1 auto;
}

.nav-icon,
.nav-link,
.notif-wrapper,
.online-badge {
    flex: 0 0 auto;
}

.upload-field {
    display: block;
    padding: 14px 16px;
    margin-bottom: 10px;
    border: 2px dashed var(--theme-border);
    border-radius: 16px;
    background: var(--theme-surface-soft);
    color: var(--theme-text);
    cursor: pointer;
}

.upload-field span {
    display: block;
    font-size: 13px;
    font-weight: 800;
    color: var(--theme-text);
}

.upload-field input[type="file"] {
    width: 100%;
    padding: 0;
    margin: 10px 0 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.upload-hint {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--gray);
}

.post-thumb,
.post-image,
.current-post-image {
    display: block;
    width: 100%;
    background: var(--theme-surface-soft);
}

.post-thumb {
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 18px;
    margin-bottom: 18px;
}

.post-image,
.current-post-image {
    max-height: 560px;
    object-fit: contain;
    border-radius: 22px;
    margin: 0 0 24px;
}

.current-image-box {
    margin: 6px 0 12px;
}

.remove-image-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -8px 0 12px;
    color: var(--gray);
    font-size: 13px;
    font-weight: 700;
}

.remove-image-row input {
    width: auto;
    margin: 0;
}

.option-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    margin: 12px 0;
    background: #fff7f7;
    border: 1px solid #ffe0e0;
    border-radius: 16px;
}

.option-row input {
    width: auto;
    margin: 3px 0 0;
}

.option-row strong {
    display: block;
    font-size: 13px;
    color: var(--theme-text);
}

.option-row small,
.option-row span span {
    display: block;
    color: var(--gray);
    font-size: 12px;
    font-weight: 600;
}

.theme-setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    margin: 0 0 10px;
    background: var(--theme-surface-soft);
    border: 1px solid var(--theme-border);
    border-radius: 16px;
}

.theme-setting-row strong,
.theme-setting-row small {
    display: block;
}

.theme-setting-row strong {
    color: var(--theme-text);
    font-size: 13px;
}

.theme-setting-row small {
    color: var(--gray);
    font-size: 12px;
    font-weight: 600;
}

.theme-setting-row input {
    width: 42px !important;
    height: 24px;
    margin: 0 !important;
    flex: 0 0 auto;
    accent-color: var(--primary);
    cursor: pointer;
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .edit-card,
html[data-theme="dark"] .post-card,
html[data-theme="dark"] .my-status-card,
html[data-theme="dark"] .members-card,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .comment-card,
html[data-theme="dark"] .reply-card-item,
html[data-theme="dark"] .add-card,
html[data-theme="dark"] .event-card,
html[data-theme="dark"] .patch-card,
html[data-theme="dark"] .events-preview,
html[data-theme="dark"] .notif-popup {
    background: var(--theme-surface) !important;
    border-color: var(--theme-border) !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.22) !important;
}

html[data-theme="dark"] .top-nav,
html[data-theme="dark"] .nav-user-info,
html[data-theme="dark"] .nav-controls,
html[data-theme="dark"] .notif-header {
    background: rgba(27, 32, 40, 0.9) !important;
    border-color: var(--theme-border) !important;
}

html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select,
html[data-theme="dark"] .status-select {
    background: var(--theme-surface-soft) !important;
    border-color: var(--theme-border) !important;
    color: var(--theme-text) !important;
}

html[data-theme="dark"] input:focus,
html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] select:focus {
    background: var(--theme-surface) !important;
}

html[data-theme="dark"] .post-title,
html[data-theme="dark"] .section-title,
html[data-theme="dark"] .feed-header,
html[data-theme="dark"] .comments-title,
html[data-theme="dark"] .event-title,
html[data-theme="dark"] .event-preview-title,
html[data-theme="dark"] .members-card h4,
html[data-theme="dark"] .edit-card h2,
html[data-theme="dark"] .edit-card h3,
html[data-theme="dark"] .card h3,
html[data-theme="dark"] .notif-header h4,
html[data-theme="dark"] .user-tag,
html[data-theme="dark"] .username-display,
html[data-theme="dark"] .back-btn,
html[data-theme="dark"] .stat-val,
html[data-theme="dark"] .patch-list li strong,
html[data-theme="dark"] .profile-link {
    color: var(--theme-text) !important;
}

html[data-theme="dark"] .post-excerpt,
html[data-theme="dark"] .post-body,
html[data-theme="dark"] .comment-text,
html[data-theme="dark"] .notif-msg,
html[data-theme="dark"] .event-desc,
html[data-theme="dark"] .patch-list li,
html[data-theme="dark"] .event-preview-meta,
html[data-theme="dark"] .subtitle,
html[data-theme="dark"] .profile-bio {
    color: var(--theme-muted-text) !important;
}

html[data-theme="dark"] .read-btn,
html[data-theme="dark"] .feed-status-badge,
html[data-theme="dark"] .code-tag,
html[data-theme="dark"] .event-time {
    background: var(--theme-surface-soft) !important;
    border-color: var(--theme-border) !important;
    color: var(--theme-text) !important;
}

html[data-theme="dark"] .partner-section,
html[data-theme="dark"] .event-date-box,
html[data-theme="dark"] .event-preview-date,
html[data-theme="dark"] .option-row,
html[data-theme="dark"] .theme-setting-row,
html[data-theme="dark"] .mark-read-btn {
    background: rgba(255, 98, 98, 0.11) !important;
    border-color: rgba(255, 98, 98, 0.26) !important;
}

html[data-theme="dark"] .anonymous-badge {
    background: var(--theme-surface-soft) !important;
    border-color: var(--theme-border) !important;
    color: var(--theme-text) !important;
}

html[data-theme="dark"] .anonymous-name {
    color: var(--theme-text) !important;
}

html[data-theme="dark"] .event-preview-row {
    border-color: var(--theme-border) !important;
}

html[data-theme="dark"] .notif-item {
    color: var(--theme-text) !important;
    border-color: var(--theme-border) !important;
}

html[data-theme="dark"] .notif-item:hover,
html[data-theme="dark"] .notif-item.unread {
    background: rgba(255, 98, 98, 0.08) !important;
}

html[data-theme="dark"] .unchastity-bar,
html[data-theme="dark"] .mini-meter-bg,
html[data-theme="dark"] .flag-bar {
    background: #303744 !important;
}

html[data-theme="dark"] .success {
    background: rgba(46, 204, 113, 0.12) !important;
    border-color: rgba(46, 204, 113, 0.26) !important;
}

html[data-theme="dark"] .error,
html[data-theme="dark"] .alert.error {
    background: rgba(255, 98, 98, 0.12) !important;
    border-color: rgba(255, 98, 98, 0.26) !important;
}

@media (max-width: 640px) {
    html,
    body {
        overflow-x: hidden;
    }

    body .container {
        width: 100%;
        max-width: none;
        padding: 16px !important;
    }

    body .navbar {
        flex-wrap: nowrap !important;
        align-items: center !important;
        gap: 10px;
        padding-bottom: 22px !important;
    }

    body .top-nav,
    body .nav-header {
        gap: 10px;
        flex-wrap: wrap;
        align-items: flex-start !important;
    }

    body .nav-user-info {
        max-width: calc(100% - 102px);
        flex-wrap: nowrap !important;
        gap: 7px !important;
        padding: 6px 9px !important;
    }

    body .nav-controls,
    body .notif-wrapper {
        max-width: 100%;
        flex-wrap: wrap;
        gap: 8px !important;
    }

    body .username-display {
        flex-wrap: nowrap !important;
        gap: 5px !important;
    }

    body .username-text {
        max-width: clamp(74px, 24vw, 150px);
    }

    body .profile-name,
    body .post-author,
    body .leader-row {
        flex-wrap: wrap;
    }

    body .logo,
    body .nav-header h2,
    body h1,
    body .post-title,
    body .version-title {
        letter-spacing: 0 !important;
    }

    body .profile-card {
        padding: 28px 16px !important;
        border-radius: 22px !important;
    }

    body .card,
    body .edit-card,
    body .post-card,
    body .members-card,
    body .my-status-card,
    body .events-preview,
    body .add-card,
    body .patch-card,
    body .comment-card,
    body .flag-box {
        padding: 18px !important;
        border-radius: 20px !important;
    }

    body .post-title {
        font-size: 20px !important;
    }

    body .post-excerpt,
    body .post-body,
    body .comment-text,
    body .event-desc,
    body .patch-list li,
    body .notif-msg,
    body .status-pill,
    body .feed-status-badge {
        overflow-wrap: anywhere;
        word-break: normal;
    }

    body input,
    body textarea,
    body select,
    body button {
        font-size: 16px !important;
    }

    body .btn,
    body .btn-post,
    body .submit-btn,
    body .read-btn,
    body .status-submit {
        min-height: 44px;
    }

    body .post-info {
        width: 100%;
        margin-left: 0 !important;
    }

    body .notif-popup {
        position: fixed !important;
        left: 16px !important;
        right: 16px !important;
        top: 72px !important;
        width: auto !important;
        max-height: 72vh;
    }

    body .notif-body {
        max-height: calc(72vh - 56px) !important;
    }

    body .event-preview-row {
        grid-template-columns: 52px 1fr;
        gap: 12px;
    }

    body .profile-action-row {
        flex-direction: column;
    }
}

@media (max-width: 380px) {
    body .container {
        padding: 14px !important;
    }

    body .online-badge {
        padding: 3px 6px;
        font-size: 9px;
    }

    body .username-text {
        max-width: 70px;
    }

    body .nav-icon,
    body .nav-link {
        font-size: 17px !important;
    }
}
