:root {
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2128;
    --border: #30363d;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --accent-dim: rgba(139, 92, 246, 0.15);
    --danger: #f85149;
    --danger-dim: rgba(248, 81, 73, 0.15);
    --success: #3fb950;
    --code-bg: #1c2128;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
    --max-width: 780px;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

a:hover {
    color: var(--accent-hover);
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    width: 100%;
}

.site-header {
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    background: rgba(22, 27, 34, 0.85);
}

.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text) !important;
    letter-spacing: -0.02em;
}

.logo:hover {
    color: var(--accent) !important;
}

nav {
    display: flex;
    gap: 0.5rem;
}

.nav-link {
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.nav-link:hover {
    color: var(--text);
    background: var(--bg-tertiary);
}

main {
    flex: 1;
    padding: 2rem 0;
}

.posts-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.post-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color var(--transition), transform var(--transition);
    margin-bottom: 1.25rem;
}

.post-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.post-cover {
    display: block;
    aspect-ratio: 21/9;
    overflow: hidden;
}

.post-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.post-card:hover .post-cover img {
    transform: scale(1.03);
}

.post-card-body {
    padding: 1.5rem;
}

.post-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.meta-sep {
    opacity: 0.4;
}

.post-title {
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 0.5rem;
    letter-spacing: -0.01em;
}

.post-title a {
    color: var(--text);
}

.post-title a:hover {
    color: var(--accent);
}

.post-excerpt {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.6;
    margin-bottom: 1rem;
}

.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.tag {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    transition: background var(--transition);
}

.tag:hover {
    background: rgba(139, 92, 246, 0.3);
    color: var(--accent);
}

.tag-small {
    padding: 0.1rem 0.4rem;
    font-size: 0.6875rem;
}

.tag-filter-notice {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.clear-filter {
    margin-left: auto;
    color: var(--danger);
    font-size: 0.8125rem;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem 0;
}

.page-btn {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
    transition: all var(--transition);
}

.page-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.page-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.post-full {
    padding-bottom: 2rem;
}

.post-header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.post-header h1 {
    font-size: 2.25rem;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.03em;
    margin: 0.75rem 0;
}

.post-cover-full {
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 2rem;
}

.post-cover-full img {
    width: 100%;
    display: block;
}

.post-content {
    font-size: 1.0625rem;
    line-height: 1.8;
}

.post-content h1 {
    font-size: 1.875rem;
    margin: 2rem 0 1rem;
    font-weight: 700;
}

.post-content h2 {
    font-size: 1.5rem;
    margin: 1.75rem 0 0.75rem;
    font-weight: 700;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.post-content h3 {
    font-size: 1.25rem;
    margin: 1.5rem 0 0.5rem;
    font-weight: 600;
}

.post-content p {
    margin-bottom: 1.25rem;
}

.post-content img {
    max-width: 100%;
    border-radius: var(--radius);
    margin: 1rem 0;
}

.post-content pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
    margin: 1.25rem 0;
    font-size: 0.875rem;
    line-height: 1.5;
}

.post-content code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.875em;
}

.post-content p code,
.post-content li code {
    background: var(--code-bg);
    border: 1px solid var(--border);
    padding: 0.15em 0.4em;
    border-radius: 4px;
}

.post-content ul, .post-content ol {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.post-content li {
    margin-bottom: 0.375rem;
}

.post-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.post-content a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.post-content video, .post-content audio {
    max-width: 100%;
    border-radius: var(--radius);
    margin: 1rem 0;
}

.post-nav-bottom {
    padding: 2rem 0;
    border-top: 1px solid var(--border);
}

.post-nav-bottom a {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.post-nav-bottom a:hover {
    color: var(--accent);
}

.empty-state {
    text-align: center;
    padding: 4rem 0;
    color: var(--text-secondary);
}

.site-footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    margin-top: auto;
}

.site-footer p {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

/* Attachments in posts */

.attachments-section {
    margin-top: 2.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.attachments-section h3 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.attachments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.attachment-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color var(--transition);
}

.attachment-card:hover {
    border-color: var(--accent);
}

.attachment-preview {
    aspect-ratio: 16/10;
    overflow: hidden;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.attachment-preview video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.attachment-preview-audio {
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
}

.attachment-preview-audio audio {
    width: 100%;
}

.attachment-preview-file {
    flex-direction: column;
}

.attachment-icon-large {
    font-size: 2.5rem;
}

.attachment-info {
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.attachment-name {
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.attachment-size {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.btn-download {
    display: block;
    text-align: center;
    padding: 0.5rem;
    background: var(--accent-dim);
    color: var(--accent);
    font-size: 0.8125rem;
    font-weight: 500;
    transition: background var(--transition);
    border-top: 1px solid var(--border);
}

.btn-download:hover {
    background: rgba(139, 92, 246, 0.3);
    color: var(--accent);
}

/* Admin */

.admin-layout {
    max-width: 1000px;
}

.admin-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 2rem;
    background: var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.admin-tab {
    flex: 1;
    text-align: center;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
}

.admin-tab:hover {
    color: var(--text);
    background: var(--bg-tertiary);
}

.admin-tab.active {
    color: var(--accent);
    background: var(--bg-tertiary);
}

.editor-section h2,
.posts-manager h2,
.files-manager h2 {
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
    font-weight: 700;
}

.editor-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.input-title {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1.25rem;
    font-weight: 600;
    outline: none;
    transition: border-color var(--transition);
}

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

.cover-image-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cover-image-section label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.cover-preview {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    max-height: 200px;
}

.cover-preview img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.btn-remove-cover {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
}

.toolbar button {
    padding: 0.375rem 0.625rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8125rem;
    transition: all var(--transition);
    font-family: inherit;
}

.toolbar button:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border);
}

.toolbar-right {
    margin-left: auto;
}

.btn-preview {
    color: var(--accent) !important;
    font-weight: 500;
}

#postContent {
    width: 100%;
    min-height: 400px;
    padding: 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    color: var(--text);
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    resize: vertical;
    outline: none;
    transition: border-color var(--transition);
    tab-size: 4;
}

#postContent:focus {
    border-color: var(--accent);
}

#postContent.drag-over {
    border-color: var(--accent);
    background: var(--accent-dim);
}

.preview-area {
    padding: 1.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    min-height: 400px;
    overflow-y: auto;
}

.preview-area img {
    max-width: 100%;
    border-radius: var(--radius);
}

.upload-progress {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.375rem;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

#progressText, #bulkProgressText {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

#postTags {
    width: 100%;
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
    outline: none;
    transition: border-color var(--transition);
}

#postTags:focus {
    border-color: var(--accent);
}

.attachments-editor {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.attachments-editor label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.attachments-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.attachment-item-name {
    flex: 1;
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.attachment-item-size {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.editor-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-primary {
    padding: 0.625rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-danger {
    padding: 0.625rem 1.5rem;
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.admin-posts-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.admin-post-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    gap: 1rem;
}

.admin-post-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    flex: 1;
}

.admin-post-title {
    font-weight: 500;
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.admin-post-title:hover {
    color: var(--accent);
}

.admin-post-meta-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.admin-post-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.admin-post-att {
    font-size: 0.6875rem;
    color: var(--text-secondary);
}

.admin-post-actions {
    display: flex;
    gap: 0.375rem;
    flex-shrink: 0;
}

.btn-small {
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-small:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-small-danger:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* Files manager */

.files-manager {
    width: 100%;
}

.files-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.files-count {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
}

.file-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color var(--transition);
}

.file-card:hover {
    border-color: var(--accent);
}

.file-preview {
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.file-preview video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.file-preview-icon {
    font-size: 2.5rem;
}

.file-info {
    padding: 0.5rem 0.625rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.file-name {
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.6875rem;
    color: var(--text-secondary);
}

.file-actions {
    display: flex;
    gap: 2px;
    padding: 0.375rem;
    border-top: 1px solid var(--border);
}

.file-actions .btn-small {
    flex: 1;
}

/* Toast */

.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--accent);
    color: white;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 9999;
    pointer-events: none;
}

.toast-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Install / Login */

.install-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.install-box {
    width: 100%;
    max-width: 420px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.install-box h1 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.install-box form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.install-box label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.install-box input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color var(--transition);
}

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

.install-box button {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

.install-box button:hover {
    background: var(--accent-hover);
}

.error-msg {
    background: var(--danger-dim);
    border: 1px solid rgba(248, 81, 73, 0.3);
    color: var(--danger);
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

/* Responsive */

@media (max-width: 640px) {
    .header-inner {
        height: 56px;
    }

    .post-header h1 {
        font-size: 1.625rem;
    }

    .post-card-body {
        padding: 1rem;
    }

    .post-title {
        font-size: 1.125rem;
    }

    .admin-post-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .admin-post-actions {
        width: 100%;
    }

    .editor-actions {
        flex-direction: column;
    }

    .btn-primary, .btn-danger {
        width: 100%;
        text-align: center;
    }

    .toolbar {
        gap: 1px;
    }

    .toolbar button {
        padding: 0.3rem 0.5rem;
        font-size: 0.75rem;
    }

    .attachments-grid {
        grid-template-columns: 1fr;
    }

    .files-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .admin-tabs {
        flex-direction: column;
    }
}

::selection {
    background: var(--accent-dim);
    color: var(--text);
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}