:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f3f4f6;
    --panel-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --correct-bg: #dcfce7;
    --correct-border: #22c55e;
    --wrong-bg: #fee2e2;
    --wrong-border: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

header {
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    z-index: 10;
}

.header-content h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.header-content h1 span {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 1rem;
    margin-left: 0.5rem;
}

select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    background-color: #fff;
    cursor: pointer;
    outline: none;
}

.audio-player-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    background-color: #f8fafc;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    flex-wrap: wrap; /* in case screen is too small */
}

.audio-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

audio {
    height: 36px;
}

main {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
    overflow-y: auto;
    height: calc(100vh - 140px); /* Discount header roughly */
}

/* Context Text Block */
.context-box {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    font-size: 1.05rem;
    line-height: 1.6;
    color: #334155;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.context-box p {
    margin-top: 0;
}

/* Download Button */
.download-btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background-color: #e2e8f0;
    color: #475569;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background-color 0.2s;
}

.download-btn:hover {
    background-color: #cbd5e1;
}

.interactive-sheet {
    background-color: var(--panel-bg);
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.sheet-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.sheet-header h2 {
    font-size: 1.25rem;
    margin: 0;
}

.score-display {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    background-color: #eef2ff;
    padding: 0.25rem 1rem;
    border-radius: 999px;
}

form {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Sections */
.part-section {
    margin-bottom: 2.5rem;
    background-color: #ffffff;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.part-title-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.part-title-header:hover {
    background-color: #f1f5f9;
}

.part-title-header h3 {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    padding-bottom: 0.5rem;
    margin: 0;
    font-size: 1.25rem;
    display: inline-block;
}

.part-toggle-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--primary);
    cursor: pointer;
    padding: 0.5rem;
}

.part-content {
    display: none;
    margin-top: 1.5rem;
}

.part-content.open {
    display: block;
}

.part-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--bg-color);
    color: var(--primary);
}

.question-row {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.question-row:hover {
    background-color: var(--bg-color);
}

.q-number {
    font-weight: 600;
    width: 30px;
    color: var(--text-muted);
}

.q-input-area {
    flex: 1;
    display: flex;
    gap: 1rem;
}

/* Multiple Choice */
.mc-options {
    display: flex;
    gap: 1rem;
}

.mc-option {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
}

.mc-option input {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

/* Text Input */
input[type="text"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    border-color: var(--primary);
}

/* Correction States */
.question-row.correct {
    background-color: var(--correct-bg);
    border-color: var(--correct-border);
}

.question-row.wrong {
    background-color: var(--wrong-bg);
    border-color: var(--wrong-border);
}

.correct-answer-label {
    display: none;
    margin-left: 1rem;
    font-size: 0.85rem;
    color: var(--wrong-border);
    font-weight: 600;
    background: #fff;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--wrong-border);
}

.question-row.wrong .correct-answer-label {
    display: inline-block;
}

.actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    flex: 1;
}

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

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

.secondary {
    background-color: #f1f5f9;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.secondary:hover {
    background-color: #e2e8f0;
}

/* Theory Box */
.theory-box {
    background-color: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.theory-header {
    background-color: #e2e8f0;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-weight: 600;
    color: var(--primary);
}

.theory-toggle {
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--primary);
    padding: 0;
}

.theory-content {
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #334155;
}

.theory-content.open {
    padding: 1rem;
    max-height: 1000px; /* arbitrary large value for smooth transition */
}

/* Explanation */
.question-wrapper {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed #e2e8f0;
}

.question-text-inline {
    font-size: 1rem;
    line-height: 1.5;
    color: #1e293b;
    margin-bottom: 0.75rem;
    padding: 0 0.5rem;
}

.question-text-inline strong {
    color: var(--primary);
}

.question-row {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.explanation-container {
    margin-top: 0.5rem;
    margin-left: 2.5rem;
}

.explanation-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.85rem;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
}

.explanation-btn:hover {
    text-decoration: underline;
    background: none;
}

.explanation-btn.hidden {
    display: none;
}

.explanation-text {
    background-color: #eff6ff;
    border-left: 4px solid var(--primary);
    padding: 0.75rem;
    margin-top: 0.5rem;
    border-radius: 0 4px 4px 0;
    font-size: 0.9rem;
    color: #1e3a8a;
    display: none;
}

.explanation-text.open {
    display: block;
}

/* Transcript Button & Modal */
.transcript-btn {
    background-color: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #475569;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    margin-left: 1rem;
    transition: all 0.2s ease;
}

.transcript-btn:hover {
    background-color: #e2e8f0;
    color: #1e293b;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    width: 90%;
    max-width: 600px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    max-height: 80vh;
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--primary);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
}

.close-btn:hover {
    color: #0f172a;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #334155;
    white-space: pre-wrap; /* to preserve text formatting */
}

/* Mobile-First Responsiveness */
@media (max-width: 800px) {
    main {
        padding: 1rem;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .audio-player-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    audio {
        width: 100%;
    }

    .transcript-btn {
        margin-left: 0;
        width: 100%;
    }
}
