* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    transition: background-color 0.3s ease, color 0.3s ease;
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

body.lock-scroll {
    overflow: hidden;
}

.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: 80px 20px 20px;
    width: 100%;
    flex-grow: 1;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--surface-strong);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
}

.logo {
    font-weight: 600;
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s;
    text-decoration: none;
    color: inherit;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text);
    cursor: pointer;
    margin-left: auto;
}

nav {
    display: flex;
    gap: 20px;
    align-items: center;
}

.github-link {
    color: var(--text);
    display: flex;
    align-items: center;
    transition: opacity 0.2s;
    text-decoration: none;
}

.github-link:hover {
    opacity: 0.7;
}

@media (max-width: 600px) {
    .menu-toggle {
        display: block;
    }
    nav {
        display: none;
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        flex-direction: column;
        background: var(--surface-strong);
        padding: 20px;
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-soft);
    }
    nav.show {
        display: flex;
    }
}

.nav-overlay {
    display: none;
    position: fixed;
    top: 60px;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.3);
    z-index: 999;
}

.nav-overlay.show {
    display: block;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 0.9rem;
    color: var(--muted);
}

.quiz-layout {
    display: block;
}

.quiz-main {
    min-width: 0;
    margin-left: 280px;
    transition: margin-left 0.2s ease;
}

.answered-panel.collapsed + .quiz-main {
    margin-left: 58px;
}

.card {
    background: var(--card);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 20px;
}

.answered-panel {
    --drawer-left: 12px;
    position: fixed;
    top: 80px;
    bottom: 20px;
    left: var(--drawer-left);
    width: 260px;
    z-index: 900;
    padding: 18px;
    overflow: visible;
    transition: transform 0.2s ease;
}

.answered-panel.collapsed {
    transform: translateX(calc(-100% - var(--drawer-left) + 1px));
}

.answered-toggle {
    position: absolute;
    top: 50%;
    right: -38px;
    width: 38px;
    height: 92px;
    padding: 10px 6px;
    border-radius: 0 10px 10px 0;
    border: 1px solid var(--border);
    border-left: none;
    background: var(--card);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    color: var(--text);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow-soft);
    transform: translateY(-50%);
    cursor: pointer;
    z-index: 1;
}

.answered-caret {
    color: var(--muted);
    transition: transform 0.2s ease;
}

.answered-tab-text {
    color: var(--text);
    font-size: 0.82rem;
    line-height: 1;
    writing-mode: vertical-rl;
}

.answered-panel.collapsed .answered-caret {
    transform: rotate(180deg);
}

.answered-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.answered-header h2 {
    font-size: 1rem;
    line-height: 1.2;
}

.answered-count {
    min-width: 48px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-accent);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.8rem;
    text-align: center;
    margin-left: auto;
}

.answered-legend {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    color: var(--muted);
    font-size: 0.74rem;
    margin-top: 14px;
}

.answered-legend span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid var(--border);
    background: var(--bg-accent);
}

.legend-dot.current {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent);
}

.legend-dot.correct {
    background: var(--success);
    border-color: var(--success);
}

.legend-dot.wrong {
    background: var(--danger);
    border-color: var(--danger);
}

.answered-list {
    display: grid;
    gap: 8px;
    max-height: calc(100vh - 215px);
    overflow-y: auto;
    overflow-x: hidden;
    margin-top: 16px;
    padding-right: 2px;
}

.answered-group {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.answered-group + .answered-group {
    border-top: 1px solid var(--border);
    margin-top: 4px;
    padding-top: 12px;
}

.answered-group-title {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.answered-grid {
    display: grid;
    grid-template-columns: repeat(5, 38px);
    gap: 6px;
    justify-content: start;
    max-width: 100%;
    overflow: hidden;
}

.answered-panel.collapsed .answered-header {
    display: none;
}

.answered-panel.collapsed .answered-list {
    display: none;
}

.answered-panel.collapsed .answered-legend {
    display: none;
}

.answered-empty {
    color: var(--muted);
    text-align: center;
    font-size: 0.9rem;
    padding: 16px 8px;
}

.answered-item {
    width: 38px;
    min-width: 0;
    aspect-ratio: 1;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-accent);
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
}

.answered-item:disabled {
    opacity: 1;
}

.answered-item:hover {
    border-color: var(--primary);
}

.answered-item.current {
    border-color: var(--primary);
    outline: 3px solid color-mix(in srgb, var(--primary) 20%, transparent);
    outline-offset: 2px;
    color: var(--primary);
}

.answered-item.correct {
    background: var(--success);
    border-color: var(--success);
    color: #ffffff;
}

.answered-item.wrong {
    background: var(--danger);
    border-color: var(--danger);
    color: #ffffff;
}

@media (max-width: 900px) {
    .quiz-main,
    .answered-panel.collapsed + .quiz-main {
        margin-left: 52px;
    }

    .answered-panel {
        --drawer-left: 8px;
        top: 72px;
        bottom: 16px;
        width: min(280px, calc(100vw - 24px));
    }

    .answered-list {
        max-height: calc(100vh - 210px);
    }
}

.question-text {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 20px;
}

/* 图片支持 */
.question-media {
    display: none;
    margin-bottom: 20px;
}

.question-media.has-media {
    display: grid;
    gap: 12px;
}

.question-media img {
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-accent);
}

.options-list {
    list-style: none;
    display: grid;
    gap: 12px;
}

.option-item {
    cursor: pointer;
    padding: 15px;
    border-radius: 12px;
    background: var(--bg-accent);
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.option-item:hover {
    background: var(--primary);
    color: var(--primary-contrast);
}

.option-item.selected {
    background: var(--primary);
    color: var(--primary-contrast);
    border-color: var(--primary);
}

.option-item.correct {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.option-item.wrong {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.option-input {
    display: none;
}

.actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.progress-modal {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.38);
}

.progress-modal-card {
    width: min(420px, 100%);
    padding: 28px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.progress-modal-card h2 {
    color: var(--text);
    font-size: 1.15rem;
    line-height: 1.45;
    font-weight: 700;
}

.progress-modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 24px;
}

button {
    padding: 12px 24px;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-contrast);
}

.btn-secondary {
    background: var(--bg-accent);
    color: var(--text);
    border: 1px solid var(--border);
}

.feedback {
    margin-top: 20px;
    padding: 15px;
    border-radius: 12px;
    font-weight: 600;
    text-align: center;
    display: none;
}

.feedback.correct {
    display: block;
    background: rgba(52, 199, 89, 0.1);
    color: var(--success);
}

.feedback.wrong {
    display: block;
    background: rgba(255, 59, 48, 0.1);
    color: var(--danger);
}

.stats-card {
    display: none;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--muted);
}

.wrong-list {
    margin-top: 20px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.wrong-item {
    margin-bottom: 15px;
    padding: 15px;
    background: rgba(255, 59, 48, 0.05);
    border-radius: 12px;
}

.wrong-text {
    font-weight: 600;
    margin-bottom: 5px;
}

.subject-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    padding: 20px 0;
}

.subject-card {
    background: var(--card);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 150px;
}

.subject-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.subject-card h3 {
    font-size: 1.2rem;
    color: var(--text);
}

.contributor-tag {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    width: 100%;
    opacity: 0.8;
}

.subject-header {
    text-align: center;
    margin-bottom: 20px;
}

.loading {
    text-align: center;
    grid-column: 1 / -1;
    color: var(--muted);
    padding: 40px;
}

/* Hide navigation items until subject is selected */
#quiz-controls, #random-controls {
    display: none;
}

select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-accent);
    color: var(--text);
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

input[type="checkbox"].toggle {
    width: 40px;
    height: 20px;
    appearance: none;
    background: var(--muted);
    border-radius: 20px;
    position: relative;
    cursor: pointer;
    transition: 0.3s;
}

input[type="checkbox"].toggle:checked {
    background: var(--primary);
}

input[type="checkbox"].toggle::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: 0.3s;
}

input[type="checkbox"].toggle:checked::before {
    left: 22px;
}

footer {
    text-align: center;
    padding: 40px 0;
    color: var(--muted);
    font-size: 0.8rem;
    width: 100%;
}

.github-footer-link {
    color: var(--muted);
    transition: color 0.2s;
    text-decoration: none;
    margin: 0 4px;
}

.github-footer-link:hover {
    color: var(--primary);
}

.logo:hover {
    color: var(--primary);
}
