/* CSS Variables - Dark Theme */
:root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-secondary: #94a3b8;
    --color-secondary-hover: #cbd5e1;
    --color-success: #22c55e;
    --color-success-bg: #166534;
    --color-error: #f87171;
    --color-error-bg: #991b1b;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-border: #334155;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --transition: 150ms ease-in-out;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100vh;
}

/* Layout */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2.5rem;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0 0 0.5rem 0;
}

.subtitle {
    color: var(--color-text-muted);
    margin: 0;
    font-size: 1.1rem;
}

.back-link {
    display: inline-block;
    color: var(--color-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    transition: color var(--transition);
}

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

/* Progress bar */
.progress-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background-color: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--color-primary);
    border-radius: 4px;
    transition: width 300ms ease-out;
    width: 0%;
}

.progress-text {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    min-width: 60px;
    text-align: right;
}

/* Quiz list (index page) */
.quiz-list {
    display: grid;
    gap: 1rem;
}

.quiz-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-decoration: none;
    color: inherit;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.quiz-card:hover,
.quiz-card.selected {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.quiz-card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    color: var(--color-text);
}

.quiz-card .meta {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.loading {
    text-align: center;
    color: var(--color-text-muted);
    padding: 2rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}

/* Question card */
.quiz-container {
    min-height: 300px;
}

.question-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.question-type {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-primary);
    background: rgba(59, 130, 246, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}

.question-text {
    font-size: 1.25rem;
    font-weight: 500;
    margin: 0 0 1.5rem 0;
    line-height: 1.5;
}

/* Answer options */
.options-list {
    display: grid;
    gap: 0.75rem;
    list-style: none;
    padding: 0;
    margin: 0;
}

.option-btn {
    display: block;
    width: 100%;
    padding: 1rem 1.25rem;
    text-align: left;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    color: var(--color-text);
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Only apply hover styles on devices with hover capability (not touch) */
@media (hover: hover) and (pointer: fine) {
    .option-btn:hover:not(:disabled) {
        border-color: var(--color-primary);
        background: rgba(59, 130, 246, 0.15);
    }
}

.option-btn:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.option-btn.selected {
    border-color: var(--color-primary);
    background: rgba(59, 130, 246, 0.25);
}

/* Prevent false highlight on newly rendered options (iOS Safari) */
.option-btn.no-interaction {
    pointer-events: none;
}

/* True/False buttons */
.tf-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.tf-btn {
    padding: 1.25rem;
    font-size: 1.1rem;
    font-weight: 500;
    text-align: center;
}

/* Fill in the blank */
.fill-blank-input {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition);
    background: var(--color-bg);
    color: var(--color-text);
}

.fill-blank-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.fill-blank-input:focus-visible {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Submit button */
.submit-container {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

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

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

.btn-primary:disabled {
    background: var(--color-border);
    cursor: not-allowed;
}

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

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

/* Results */
.results-container {
    text-align: center;
}

.results-container.hidden {
    display: none;
}

.results-summary {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

.results-summary h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 1.5rem 0;
}

.score-display {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.score-value {
    color: var(--color-primary);
}

.score-separator {
    color: var(--color-text-muted);
    margin: 0 0.25rem;
}

.score-total {
    color: var(--color-text);
}

.score-percentage {
    font-size: 1.25rem;
    color: var(--color-text-muted);
    margin: 0 0 1rem 0;
}

.score-message {
    font-size: 1.1rem;
    margin: 0;
}

.score-message.excellent {
    color: var(--color-success);
}

.score-message.good {
    color: var(--color-primary);
}

.score-message.medium {
    color: #f59e0b;
}

.score-message.needs-work {
    color: var(--color-error);
}

/* Mistakes section */
.mistakes-section {
    text-align: left;
    margin-bottom: 2rem;
}

.mistakes-section.hidden {
    display: none;
}

.mistakes-section h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 1rem 0;
    text-align: center;
}

.mistakes-list {
    display: grid;
    gap: 1rem;
}

.mistake-card {
    background: var(--color-surface);
    border: 1px solid var(--color-error);
    border-left: 4px solid var(--color-error);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    text-align: left;
}

.mistake-question {
    font-weight: 500;
    margin: 0 0 0.75rem 0;
}

.mistake-detail {
    font-size: 0.9rem;
    margin: 0.25rem 0;
}

.mistake-detail.your-answer {
    color: var(--color-error);
}

.mistake-detail.correct-answer {
    color: var(--color-success);
}

.mistake-explanation {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin: 0.75rem 0 0 0;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

/* Results actions */
.results-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Footer */
footer {
    margin-top: 3rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

footer p {
    margin: 0;
}

/* Help overlay */
.help-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.help-popup {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.help-popup h3 {
    margin: 0 0 1.5rem 0;
    text-align: center;
    font-size: 1.25rem;
}

.shortcuts-list {
    margin: 0 0 1.5rem 0;
}

.shortcuts-list div {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
}

.shortcuts-list div:last-child {
    border-bottom: none;
}

.shortcuts-list dt {
    font-weight: 600;
    color: var(--color-primary);
    min-width: 60px;
}

.shortcuts-list dd {
    margin: 0;
    color: var(--color-text-muted);
    text-align: right;
}

.help-popup button {
    width: 100%;
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 1.5rem 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .question-card {
        padding: 1.5rem;
    }

    .question-text {
        font-size: 1.1rem;
    }

    .tf-options {
        grid-template-columns: 1fr;
    }

    .score-display {
        font-size: 2.5rem;
    }

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

    .results-actions .btn {
        width: 100%;
    }
}
