:root {
    --bg-dark: #1a1b1c;
    --bg-card: #252627;
    --bg-elevated: #2d2e30;
    --text-primary: #f2ece9;
    --text-secondary: rgba(242, 236, 233, 0.6);
    --text-muted: rgba(242, 236, 233, 0.35);
    --accent: #f07727;
    --accent-glow: rgba(240, 119, 39, 0.4);
    --success: #2ecc71;
    --danger: #e74c3c;
    --border: rgba(242, 236, 233, 0.08);
    --border-hover: rgba(240, 119, 39, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    background: var(--bg-dark);
    min-height: 100vh;
    color: var(--text-primary);
    overflow-x: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* Hex grid background */
.hex-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='49' viewBox='0 0 28 49'%3E%3Cg fill-rule='evenodd'%3E%3Cg fill='%23f2ece9' fill-opacity='1'%3E%3Cpath d='M13.99 9.25l13 7.5v15l-13 7.5L1 31.75v-15l12.99-7.5zM3 17.9v12.7l10.99 6.34 11-6.35V17.9l-11-6.34L3 17.9zM0 15l12.98-7.5V0h-2v6.35L0 12.69v2.3zm0 18.5L12.98 41v8h-2v-6.85L0 35.81v-2.3zM15 0v7.5L27.99 15H28v-2.31h-.01L17 6.35V0h-2zm0 49v-8l12.99-7.5H28v2.31h-.01L17 42.15V49h-2z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* ── Header ── */

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 32px;
    background: var(--bg-card);
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-link {
    display: flex;
    align-items: center;
}

.logo {
    width: 78px;
    height: 60px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover {
    background: #e06617;
    text-decoration: none;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* ── Main ── */

.main {
    position: relative;
    z-index: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px 60px;
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 0;
}

/* ── Forum Hero ── */

.forum-logo {
    display: block;
    width: 100%;
    height: auto;
    margin-bottom: 16px;
}

.forum-subtitle {
    text-align: center;
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ── Search ── */

.search-bar {
    margin-bottom: 20px;
}

.search-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.search-icon {
    flex-shrink: 0;
    color: var(--text-muted);
}

.search-input {
    flex: 1;
}

.search-filter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.search-filter input[type='checkbox'] {
    accent-color: var(--accent);
}

.search-results {
    margin-top: 8px;
}

/* ── Breadcrumbs ── */

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.breadcrumbs a {
    color: var(--text-secondary);
}

.breadcrumbs .sep {
    color: var(--text-muted);
}

/* ── Category List ── */

.category-card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 8px;
    transition: all 0.15s;
    cursor: pointer;
}
.category-card:hover {
    border-color: var(--border-hover);
    box-shadow: 0 0 12px var(--accent-glow);
    text-decoration: none;
}

.category-name {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.category-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.category-stats {
    display: flex;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.category-latest {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}

/* ── Thread List ── */

.thread-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.thread-list-header h2 {
    font-size: 1.3rem;
    font-weight: 500;
}

.thread-row {
    display: flex;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 6px;
    transition: all 0.15s;
    cursor: pointer;
    gap: 16px;
}
.thread-row:hover {
    border-color: var(--border-hover);
    text-decoration: none;
}

.thread-pin {
    color: var(--accent);
    font-size: 0.85rem;
    flex-shrink: 0;
}

.thread-info {
    flex: 1;
    min-width: 0;
}

.thread-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.thread-stats {
    text-align: right;
    flex-shrink: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.thread-replies {
    font-weight: 500;
    color: var(--text-secondary);
}

/* ── Thread View / Posts ── */

.thread-header {
    margin-bottom: 24px;
}

.thread-header h1 {
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.thread-header .thread-meta {
    font-size: 0.85rem;
}

.post {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 10px;
}

.post-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.post-author {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: rgba(240, 119, 39, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    flex-shrink: 0;
}

.post-author-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.post-time {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.post-body {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
    word-wrap: break-word;
}

.post-body a {
    color: var(--accent);
    word-break: break-all;
    cursor: pointer;
}

.post-body img {
    max-width: 100%;
    border-radius: 6px;
    vertical-align: middle;
}

.post-edited {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-style: italic;
}

.post-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}

.locked-notice {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
    background: var(--bg-card);
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* ── Reply / New Thread Form ── */

.compose-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    margin-top: 16px;
}

.compose-box h3 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 12px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus {
    border-color: var(--accent);
}

textarea.form-input {
    resize: vertical;
    min-height: 100px;
}

.form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ── Floating Quote Button ── */

.float-quote-btn {
    position: absolute;
    transform: translateX(-50%);
    z-index: 200;
    padding: 5px 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: background 0.15s;
}

.float-quote-btn:hover {
    background: #e06617;
}

.float-quote-btn::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--accent);
}

/* ── Format Toolbar ── */

.format-toolbar {
    display: flex;
    gap: 4px;
    margin-bottom: 6px;
}

.fmt-btn {
    width: 32px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.fmt-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.fmt-select {
    height: 28px;
    padding: 0 4px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
}

.fmt-select:hover {
    border-color: var(--accent);
}

/* ── Blockquotes ── */

.post-body blockquote {
    border-left: 3px solid var(--accent);
    padding: 8px 12px;
    margin: 8px 0;
    background: rgba(240, 119, 39, 0.06);
    color: var(--text-secondary);
    border-radius: 0 4px 4px 0;
}

/* ── Admin Badge ── */

.admin-badge {
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 400;
}

/* ── Quote Links ── */

.quote-link {
    color: var(--accent);
    font-size: 0.85rem;
    text-decoration: none;
}

.quote-link:hover {
    text-decoration: underline;
}

/* ── Video Embeds ── */

.embed-video {
    position: relative;
    width: 100%;
    max-width: 560px;
    padding-bottom: 56.25%;
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
}

.embed-video iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 8px;
}

/* ── WYSIWYG Editor ── */

.wysiwyg-editor {
    min-height: 100px;
    padding: 10px 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.6;
    outline: none;
    transition: border-color 0.15s;
    word-wrap: break-word;
}

.wysiwyg-editor:focus {
    border-color: var(--accent);
}

.wysiwyg-editor.drag-over {
    border-color: var(--accent);
    background: rgba(240, 119, 39, 0.05);
}

.wysiwyg-editor:empty::before {
    content: 'Write your post…';
    color: var(--text-muted);
    pointer-events: none;
}

.wysiwyg-editor a {
    color: var(--accent);
}

.wysiwyg-editor blockquote {
    border-left: 3px solid var(--accent);
    padding: 8px 12px;
    margin: 8px 0;
    background: rgba(240, 119, 39, 0.06);
    color: var(--text-secondary);
    border-radius: 0 4px 4px 0;
}

.wysiwyg-editor img {
    max-width: 100%;
    border-radius: 6px;
    margin: 8px 0;
    display: block;
}

/* ── Editor Inline Images ── */

.wysiwyg-editor img.editor-img {
    display: inline;
    max-width: 60%;
    border-radius: 6px;
    cursor: pointer;
    vertical-align: middle;
    margin: 0 2px;
}

/* ── Image Upload ── */

.image-upload-area {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.image-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-elevated);
    border: 1px dashed var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color 0.15s;
}
.image-upload-btn:hover {
    border-color: var(--accent);
}

.image-upload-btn input[type='file'] {
    display: none;
}

.image-preview {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.image-preview-thumb {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.image-preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-thumb .remove-img {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ── Login Prompt ── */

.login-prompt {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 16px;
}

/* ── Pagination ── */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
}

.pagination button {
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}
.pagination button:hover {
    border-color: var(--border-hover);
}
.pagination button:disabled {
    opacity: 0.3;
    cursor: default;
}
.pagination button.active {
    border-color: var(--accent);
    color: var(--accent);
}

.pagination .page-info {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ── Category Note ── */

.category-note {
    background: rgba(240, 119, 39, 0.12);
    border: 1px solid rgba(240, 119, 39, 0.3);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    color: var(--accent);
}

/* ── Empty States ── */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state p {
    margin-bottom: 12px;
}

/* ── Version Toast ── */

.version-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--accent);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.85rem;
    z-index: 300;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    display: none;
}

/* ── Bio in posts ── */

.post-author-bio {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    font-style: italic;
}

/* ── Profile Modal ── */

.profile-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100001;
}
.profile-modal-overlay.visible {
    display: flex;
}
.profile-modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 400px;
    width: calc(100% - 32px);
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.profile-modal-box h2 {
    font-size: 1.15rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-primary);
}
.profile-avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}
.profile-avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(240, 119, 39, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 600;
    color: var(--accent);
    overflow: hidden;
    cursor: pointer;
    transition: opacity 0.15s;
}
.profile-avatar-large:hover {
    opacity: 0.8;
}
.profile-avatar-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.bio-counter {
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}
.profile-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* ── Crop Picker ── */

.crop-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100002;
}
.crop-overlay.visible {
    display: flex;
}
.crop-modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 500px;
    width: calc(100% - 32px);
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.crop-modal h3 {
    text-align: center;
    margin-bottom: 16px;
    font-weight: 500;
    color: var(--text-primary);
}
.crop-container {
    position: relative;
    overflow: hidden;
    margin: 0 auto;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    background: var(--bg-dark);
    border-radius: 4px;
}
.crop-image {
    display: block;
    max-width: 100%;
    pointer-events: none;
}
.crop-box {
    position: absolute;
    border: 2px solid var(--accent);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    cursor: move;
    touch-action: none;
}
.crop-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border: 2px solid #fff;
    border-radius: 50%;
    z-index: 1;
}
.crop-handle-nw {
    top: -8px;
    left: -8px;
    cursor: nwse-resize;
}
.crop-handle-ne {
    top: -8px;
    right: -8px;
    cursor: nesw-resize;
}
.crop-handle-sw {
    bottom: -8px;
    left: -8px;
    cursor: nesw-resize;
}
.crop-handle-se {
    bottom: -8px;
    right: -8px;
    cursor: nwse-resize;
}
.crop-preview-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}
.crop-preview-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.crop-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--border);
}
.crop-preview canvas {
    width: 80px;
    height: 80px;
}
.crop-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

/* ── Responsive ── */

@media (max-width: 768px) {
    .header {
        padding: 8px 16px;
    }

    .forum-title {
        font-size: 1rem;
    }

    .main {
        padding: 16px 12px 40px;
    }

    .thread-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .thread-stats {
        text-align: left;
    }

    .category-latest {
        display: none;
    }

    .crop-modal {
        max-width: 100%;
        border-radius: 0;
        max-height: 100vh;
        overflow-y: auto;
    }

    .post-author-bio {
        max-width: 150px;
    }
}

@media (max-width: 480px) {
    .logo {
        width: 36px;
        height: 28px;
    }

    .header-center {
        display: none;
    }
}
