* {
    box-sizing: border-box;
}

:root {
    --bg-main: #f5f6f8;
    --bg-card: #fff;
    --bg-card-hover: #fff;
    --bg-header: linear-gradient(135deg, #1f2933 0%, #2d3b47 100%);
    --bg-footer: #fff;
    --bg-input: #fff;
    --bg-btn: #1f2933;
    --bg-btn-hover: #374151;
    --bg-count: #f8fafc;
    --bg-vote: #f8fafc;
    --bg-vote-hover: #f1f5f9;
    --bg-empty: #f8fafc;
    --bg-nav-hover: rgba(255, 255, 255, 0.1);
    
    --text-main: #2a2a2a;
    --text-muted: #6b7280;
    --text-heading: #1a1a1a;
    --text-header: #fff;
    --text-nav: #d9e2ec;
    --text-count: #1f2933;
    
    --link: #1a5f8a;
    --link-hover: #0d3d5c;
    --link-card: #1f2933;
    --link-card-hover: #1a5f8a;
    
    --border: #e5e7eb;
    --border-hover: #d1d5db;
    --border-input: #d1d5db;
    --border-focus: #1a5f8a;
    --border-footer: #e0e2e6;
    
    --success-bg: #ecfdf5;
    --success-border: #a7f3d0;
    --success-text: #065f46;
    
    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --error-text: #991b1b;
    
    --vote-up-bg: #dcfce7;
    --vote-up-border: #86efac;
    --vote-up-text: #166534;
    --vote-down-bg: #fee2e2;
    --vote-down-border: #fca5a5;
    --vote-down-text: #991b1b;
    
    --moderation-bg: #fffbeb;
    --moderation-border: #fcd34d;
    
    --shadow: rgba(0, 0, 0, 0.04);
    --shadow-hover: rgba(0, 0, 0, 0.06);
    --shadow-header: rgba(0, 0, 0, 0.12);
    --shadow-btn: rgba(31, 41, 51, 0.2);
    --focus-ring: rgba(26, 95, 138, 0.12);
    
    --toggle-bg: rgba(255, 255, 255, 0.15);
    --toggle-knob: #fff;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-main: #111827;
    --bg-card: #1f2937;
    --bg-card-hover: #263141;
    --bg-header: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --bg-footer: #1f2937;
    --bg-input: #374151;
    --bg-btn: #3b82f6;
    --bg-btn-hover: #2563eb;
    --bg-count: #374151;
    --bg-vote: #374151;
    --bg-vote-hover: #4b5563;
    --bg-empty: #1f2937;
    --bg-nav-hover: rgba(255, 255, 255, 0.08);
    
    --text-main: #e5e7eb;
    --text-muted: #9ca3af;
    --text-heading: #f9fafb;
    --text-header: #f9fafb;
    --text-nav: #d1d5db;
    --text-count: #f9fafb;
    
    --link: #60a5fa;
    --link-hover: #93c5fd;
    --link-card: #f9fafb;
    --link-card-hover: #60a5fa;
    
    --border: #374151;
    --border-hover: #4b5563;
    --border-input: #4b5563;
    --border-focus: #3b82f6;
    --border-footer: #374151;
    
    --success-bg: #064e3b;
    --success-border: #059669;
    --success-text: #6ee7b7;
    
    --error-bg: #7f1d1d;
    --error-border: #dc2626;
    --error-text: #fca5a5;
    
    --vote-up-bg: #064e3b;
    --vote-up-border: #059669;
    --vote-up-text: #6ee7b7;
    --vote-down-bg: #7f1d1d;
    --vote-down-border: #dc2626;
    --vote-down-text: #fca5a5;
    
    --moderation-bg: #422006;
    --moderation-border: #d97706;
    
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-hover: rgba(0, 0, 0, 0.4);
    --shadow-header: rgba(0, 0, 0, 0.4);
    --shadow-btn: rgba(59, 130, 246, 0.3);
    --focus-ring: rgba(59, 130, 246, 0.25);
    
    --toggle-bg: rgba(59, 130, 246, 0.5);
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-main);
    background: var(--bg-main);
    transition: background 0.3s ease, color 0.3s ease;
}

a {
    color: var(--link);
    text-decoration: none;
    transition: color 0.15s ease;
}

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

.container {
    max-width: 920px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.site-header {
    background: var(--bg-header);
    color: var(--text-header);
    padding: 0;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px var(--shadow-header);
    transition: background 0.3s ease;
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 16px;
    padding-bottom: 16px;
    flex-wrap: wrap;
}

.header-search {
    display: flex;
    align-items: center;
    flex: 1 1 180px;
    max-width: 320px;
    min-width: 140px;
}

.header-search input[type="search"] {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px 0 0 6px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-header);
    font-family: inherit;
    font-size: 0.9rem;
}

.header-search input[type="search"]::placeholder {
    color: rgba(255, 255, 255, 0.55);
}

.header-search input[type="search"]:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.45);
    background: rgba(255, 255, 255, 0.18);
}

.header-search-btn {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-left: none;
    border-radius: 0 6px 6px 0;
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-header);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}

.header-search-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.logo {
    color: var(--text-header);
    font-weight: 700;
    font-size: 1.35rem;
    text-decoration: none;
    letter-spacing: -0.02em;
}

.logo:hover {
    color: var(--text-header);
    text-decoration: none;
}

.site-header nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.site-header nav a {
    color: var(--text-nav);
    padding: 8px 14px;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.15s ease;
    font-size: 0.95rem;
}

.site-header nav a:hover {
    color: var(--text-header);
    background: var(--bg-nav-hover);
    text-decoration: none;
}

/* Theme Toggle */
.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    margin-left: 8px;
    border-radius: 6px;
    font-size: 1.1rem;
    line-height: 1;
    transition: background 0.15s ease;
}

.theme-toggle:hover {
    background: var(--bg-nav-hover);
}

.theme-icon-dark {
    display: none;
}

[data-theme="dark"] .theme-icon-light {
    display: none;
}

[data-theme="dark"] .theme-icon-dark {
    display: inline;
}

/* Footer */
.site-footer {
    margin-top: 56px;
    padding: 24px 0;
    border-top: 1px solid var(--border-footer);
    color: var(--text-muted);
    font-size: 0.9rem;
    background: var(--bg-footer);
    transition: background 0.3s ease, border-color 0.3s ease;
}

/* Typography */
h1, h2 {
    color: var(--text-heading);
    line-height: 1.3;
    font-weight: 600;
    transition: color 0.3s ease;
}

h1 {
    font-size: 1.75rem;
    margin-bottom: 20px;
}

.page-title {
    margin-top: 0;
}

/* Flash messages */
.flash {
    padding: 12px 16px;
    margin-bottom: 20px;
    border-radius: 6px;
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success-text);
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.flash-error {
    border-color: var(--error-border);
    background: var(--error-bg);
    color: var(--error-text);
}

/* Question list */
.question-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.question-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px 18px;
    margin-bottom: 10px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px var(--shadow);
}

.question-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    box-shadow: 0 4px 12px var(--shadow-hover);
    transform: translateY(-1px);
}

.question-item-main {
    flex: 1;
    min-width: 0;
}

.question-item h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
    font-weight: 600;
}

.question-item h2 a {
    color: var(--link-card);
}

.question-item h2 a:hover {
    color: var(--link-card-hover);
}

.question-answers-count {
    flex-shrink: 0;
    text-align: center;
    padding: 10px 14px;
    background: var(--bg-count);
    border-radius: 6px;
    min-width: 64px;
    transition: background 0.3s ease;
}

.question-answers-num {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    color: var(--text-count);
    transition: color 0.3s ease;
}

.question-answers-label {
    display: block;
    margin-top: 4px;
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.question-meta {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.question-excerpt {
    margin: 6px 0 8px;
    font-size: 0.92rem;
    line-height: 1.5;
    color: var(--text-main);
}

.search-mark {
    background: rgba(26, 95, 138, 0.18);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

[data-theme="dark"] .search-mark {
    background: rgba(59, 130, 246, 0.25);
}

.list-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.list-filter,
.list-filter-current {
    display: inline-block;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
    text-decoration: none;
}

.list-filter {
    background: var(--bg-card);
    color: var(--text-main);
}

.list-filter:hover {
    border-color: var(--border-focus);
    color: var(--link);
    text-decoration: none;
}

.list-filter-current {
    background: var(--bg-btn);
    color: #fff;
    border-color: var(--bg-btn);
    font-weight: 500;
}

/* Question page */
.question-body {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 18px 20px;
    margin-bottom: 24px;
    font-size: 1.02rem;
    line-height: 1.7;
    box-shadow: 0 1px 3px var(--shadow);
    transition: all 0.3s ease;
}

/* Answers */
.answers-section {
    margin-top: 32px;
}

.answers-section h2 {
    font-size: 1.2rem;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.answer-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px 18px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px var(--shadow);
    transition: all 0.3s ease;
}

.answer-item-best {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 1px var(--border-focus);
}

.answer-best-label {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--link);
    margin-bottom: 8px;
}

.answer-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.answer-body {
    margin-bottom: 14px;
    line-height: 1.7;
}

/* Voting */
.vote-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.vote-form {
    display: inline;
}

.vote-btn {
    background: var(--bg-vote);
    border: 1px solid var(--border);
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.vote-btn:hover {
    background: var(--bg-vote-hover);
    border-color: var(--border-hover);
}

.vote-btn.active-up {
    background: var(--vote-up-bg);
    border-color: var(--vote-up-border);
    color: var(--vote-up-text);
}

.vote-btn.active-down {
    background: var(--vote-down-bg);
    border-color: var(--vote-down-border);
    color: var(--vote-down-text);
}

.vote-count {
    min-width: 2em;
    text-align: center;
    color: var(--text-muted);
    font-weight: 500;
}

/* Forms */
.form-block {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 20px;
    margin-top: 20px;
    box-shadow: 0 1px 3px var(--shadow);
    transition: all 0.3s ease;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-heading);
}

.form-group input[type="text"],
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.15s ease;
    background: var(--bg-input);
    color: var(--text-main);
}

.form-group input[type="text"]:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-group textarea {
    min-height: 150px;
    resize: vertical;
    line-height: 1.6;
}

.form-hint {
    margin: 6px 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.ask-hint {
    margin-bottom: 16px;
    padding: 12px 14px;
    background: var(--bg-empty);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.92rem;
    line-height: 1.5;
}

.ask-hint p {
    margin: 0 0 8px;
}

.ask-hint ul {
    margin: 0;
    padding-left: 20px;
}

.ask-hint li {
    margin-bottom: 4px;
}

.ask-hint li:last-child {
    margin-bottom: 0;
}

/* Buttons */
.btn {
    display: inline-block;
    background: var(--bg-btn);
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.btn:hover {
    background: var(--bg-btn-hover);
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow-btn);
}

.btn:active {
    transform: translateY(0);
}

.btn-danger {
    background: #8b3a3a;
}

.btn-danger:hover {
    background: #a04444;
    color: #fff;
}

.moderation-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
}

.moderation-actions form {
    display: inline;
}

/* Errors */
.errors {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: 4px;
    padding: 12px 16px;
    margin-bottom: 16px;
    color: var(--error-text);
    transition: all 0.3s ease;
}

.errors ul {
    margin: 0;
    padding-left: 20px;
}

.errors li {
    margin-bottom: 4px;
}

.errors li:last-child {
    margin-bottom: 0;
}

/* Breadcrumbs */
.breadcrumbs {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.4;
}

.breadcrumbs a {
    color: var(--link);
    text-decoration: none;
}

.breadcrumbs a:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

.breadcrumbs-sep {
    margin: 0 8px;
    color: var(--text-muted);
    opacity: 0.7;
}

.breadcrumbs-current {
    color: var(--text-main);
}

/* Tag cloud */
.tag-cloud-section {
    margin-bottom: 20px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.tag-cloud-heading {
    margin: 0 0 12px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
    line-height: 1.4;
}

.tag-cloud-item {
    display: inline-block;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    text-decoration: none;
    color: var(--link);
    background: var(--bg-main);
    transition: background 0.15s ease, border-color 0.15s ease;
}

.tag-cloud-item:hover {
    border-color: var(--border-focus);
    background: var(--bg-vote-hover);
    text-decoration: none;
}

.tag-cloud-xs { font-size: 0.75rem; }
.tag-cloud-sm { font-size: 0.82rem; }
.tag-cloud-md { font-size: 0.92rem; font-weight: 500; }
.tag-cloud-lg { font-size: 1.02rem; font-weight: 600; }
.tag-cloud-xl { font-size: 1.12rem; font-weight: 700; }

.question-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 14px 0 0;
}

.question-tag {
    display: inline-block;
    padding: 3px 9px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    color: var(--link);
    background: var(--bg-main);
}

.question-tag:hover {
    border-color: var(--border-focus);
    text-decoration: none;
}

.home-tags-section {
    margin-top: 36px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.home-tags-section h2 {
    font-size: 1.1rem;
    margin: 0 0 12px;
    color: var(--text-heading);
}

.home-tags-section .question-tags {
    margin: 0;
}

.tags-more {
    margin: 14px 0 0;
    font-size: 0.9rem;
}

.tags-more a {
    font-weight: 600;
}

.tag-page-count {
    margin: -8px 0 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Related questions */
.related-section {
    margin-top: 36px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.related-section h2 {
    font-size: 1.1rem;
    margin: 0 0 14px;
    color: var(--text-heading);
}

.related-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.related-list li {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.related-list li:last-child {
    border-bottom: none;
}

.related-list a {
    text-decoration: none;
    font-weight: 600;
    color: var(--link-card);
}

.related-list a:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

.related-meta {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 3px;
}

/* Pagination */
.pagination {
    margin-top: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}

.pagination a,
.pagination-current {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-card);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.15s ease;
}

.pagination a:hover {
    border-color: var(--border-focus);
    color: var(--link);
    text-decoration: none;
}

.pagination-current {
    background: var(--bg-btn);
    color: #fff;
    border-color: var(--bg-btn);
}

.pagination-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    color: var(--text-muted);
    user-select: none;
}

.pagination-nav {
    font-weight: 600;
}

.search-form {
    margin-bottom: 24px;
}

.search-form-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.search-form-row input[type="search"] {
    flex: 1;
    min-width: 200px;
    padding: 10px 12px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    background: var(--bg-input);
    color: var(--text-main);
}

.search-form-row input[type="search"]:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.search-results-count {
    color: var(--text-muted);
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.empty-note {
    color: var(--text-muted);
    font-style: italic;
    padding: 20px;
    text-align: center;
    background: var(--bg-empty);
    border-radius: 6px;
    margin: 14px 0;
    transition: all 0.3s ease;
}

/* Moderation box */
.moderation-box {
    background: var(--moderation-bg);
    border: 1px solid var(--moderation-border);
    border-radius: 6px;
    padding: 16px;
    transition: all 0.3s ease;
}

/* Responsive */
@media (max-width: 640px) {
    body {
        font-size: 15px;
    }

    .container {
        padding: 0 14px;
    }

    .site-header {
        margin-bottom: 14px;
    }

    .site-header .container {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .logo {
        font-size: 1.15rem;
    }

    .header-search {
        order: 3;
        flex: 1 1 100%;
        max-width: none;
    }

    .header-search input[type="search"] {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    .header-search-btn {
        padding: 6px 10px;
    }

    .site-header nav {
        order: 4;
        width: 100%;
        gap: 4px;
        flex-wrap: wrap;
    }

    .site-header nav a {
        padding: 6px 8px;
        font-size: 0.85rem;
    }

    .theme-toggle {
        order: 2;
        margin-left: auto;
        padding: 4px;
        font-size: 1rem;
    }

    h1 {
        font-size: 1.35rem;
        margin-bottom: 14px;
    }

    .question-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 14px;
    }

    .question-item h2 {
        font-size: 1rem;
    }

    .question-answers-count {
        align-self: flex-start;
        min-width: auto;
        padding: 6px 12px;
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .question-answers-num {
        font-size: 1.1rem;
    }

    .question-answers-label {
        margin-top: 0;
        font-size: 0.7rem;
    }

    .form-block {
        padding: 16px;
    }

    .question-body {
        padding: 14px 16px;
    }

    .answer-item {
        padding: 12px 14px;
    }

    .pagination {
        margin-top: 20px;
    }

    .pagination a,
    .pagination-current,
    .pagination-ellipsis {
        min-width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    .site-footer {
        margin-top: 32px;
        padding: 16px 0;
    }
}
