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

:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-bg: #eef2ff;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
}

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

/* Navbar */
.navbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.nav-links { display: flex; gap: 8px; }
.nav-links a {
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}
.nav-links a:hover, .nav-links a.active {
    background: var(--primary-bg);
    color: var(--primary);
}
.nav-admin { opacity: 0.5; }
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text);
}
.mobile-nav {
    display: none;
    flex-direction: column;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 8px 24px;
}
.mobile-nav a {
    padding: 12px 0;
    text-decoration: none;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}
.mobile-nav.show { display: flex; }

/* Main content */
#app {
    flex: 1;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
}

/* Footer */
.footer {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover {
    box-shadow: var(--shadow-lg);
}
.card-clickable { cursor: pointer; }
.card-clickable:hover { transform: translateY(-2px); }

/* Home page */
.home-hero {
    text-align: center;
    padding: 60px 20px;
}
.home-hero h1 {
    font-size: 2.5rem;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.home-hero p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 40px;
}
.home-stages {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    max-width: 700px;
    margin: 0 auto;
}
.stage-card {
    text-align: center;
    padding: 40px 24px;
    text-decoration: none;
    color: inherit;
}
.stage-card .icon { font-size: 3rem; margin-bottom: 16px; }
.stage-card h2 { font-size: 1.5rem; margin-bottom: 8px; }
.stage-card p { color: var(--text-secondary); font-size: 0.95rem; }

/* Category grid */
.page-header {
    margin-bottom: 24px;
}
.page-header h1 {
    font-size: 1.75rem;
    margin-bottom: 4px;
}
.page-header .breadcrumb {
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.page-header .breadcrumb a {
    color: var(--primary);
    text-decoration: none;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.category-card {
    text-decoration: none;
    color: inherit;
    padding: 20px;
}
.category-card h3 {
    font-size: 1.1rem;
    margin-bottom: 6px;
}
.category-card .desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 12px;
}
.category-card .count {
    display: inline-block;
    background: var(--primary-bg);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Question list */
.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}
.filters select, .filters input {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    font-size: 0.9rem;
    color: var(--text);
    outline: none;
}
.filters select:focus, .filters input:focus {
    border-color: var(--primary);
}

.question-list { display: flex; flex-direction: column; gap: 12px; }
.question-item {
    padding: 20px;
    cursor: pointer;
}
.question-item .q-header {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.tag-choice { background: #dbeafe; color: #1d4ed8; }
.tag-fill { background: #fef3c7; color: #92400e; }
.tag-solve { background: #d1fae5; color: #065f46; }
.tag-easy { background: #d1fae5; color: #065f46; }
.tag-medium { background: #fef3c7; color: #92400e; }
.tag-hard { background: #fee2e2; color: #991b1b; }

.question-item .q-content {
    font-size: 0.95rem;
    line-height: 1.7;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

/* Question detail */
.question-detail { max-width: 800px; }
.question-detail .q-body {
    font-size: 1.05rem;
    line-height: 1.8;
    margin-bottom: 20px;
}
.question-detail .q-options {
    list-style: none;
    margin-bottom: 20px;
}
.question-detail .q-options li {
    padding: 10px 16px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
}
.question-detail .q-options li:hover {
    border-color: var(--primary);
    background: var(--primary-bg);
}
.question-detail .q-options li.selected {
    border-color: var(--primary);
    background: var(--primary-bg);
}

.answer-section {
    border-top: 2px dashed var(--border);
    padding-top: 20px;
    margin-top: 20px;
}
.answer-section.hidden { display: none; }
.answer-section h3 {
    color: var(--primary);
    margin-bottom: 12px;
}
.answer-section .answer-text {
    background: var(--primary-bg);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 600;
}
.answer-section .explanation {
    background: #f0fdf4;
    padding: 16px;
    border-radius: 8px;
    border-left: 4px solid var(--success);
    line-height: 1.8;
}

.btn {
    display: inline-block;
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    text-align: center;
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 24px;
}
.pagination button {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.pagination button:hover { border-color: var(--primary); color: var(--primary); }
.pagination button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Search page */
.search-box {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}
.search-box input {
    flex: 1;
    padding: 12px 18px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}
.search-box input:focus { border-color: var(--primary); }

/* Admin */
.admin-login {
    max-width: 400px;
    margin: 60px auto;
}
.admin-login h2 {
    text-align: center;
    margin-bottom: 24px;
}
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    font-family: inherit;
}
.form-group textarea {
    min-height: 100px;
    resize: vertical;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
}

.admin-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}
.admin-tabs button {
    padding: 10px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.admin-tabs button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}
.admin-table th, .admin-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.admin-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
}
.admin-table tr:hover td { background: var(--primary-bg); }

.admin-actions {
    display: flex;
    gap: 8px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    text-align: center;
    padding: 20px;
}
.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}
.stat-card .stat-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 32px;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal h2 {
    margin-bottom: 20px;
}
.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* LaTeX preview */
.latex-preview {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    min-height: 60px;
    margin-top: 8px;
}
.latex-preview-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 24px;
    border-radius: 8px;
    color: white;
    font-size: 0.9rem;
    z-index: 300;
    animation: slideIn 0.3s ease;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}
.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 16px; }

/* Responsive */
@media (max-width: 768px) {
    .nav-links { display: none; }
    .mobile-menu-btn { display: block; }
    #app { padding: 16px; }
    .home-hero h1 { font-size: 1.75rem; }
    .home-stages { grid-template-columns: 1fr; }
    .stage-card { padding: 24px; }
    .category-grid { grid-template-columns: 1fr; }
    .search-box { flex-direction: column; }
    .filters { flex-direction: column; }
    .admin-table { font-size: 0.8rem; }
    .admin-table th, .admin-table td { padding: 8px; }
    .modal { width: 95%; padding: 20px; }
}
