/* ============================================
   Quiz Trainer — App-specific styles
   Palette: Plum / Aubergine
   ============================================ */

:root {
    --theme-primary:          #7E22CE;
    --theme-primary-light:    #9333EA;
    --theme-primary-dark:     #6B21A8;
    --theme-secondary-accent: #A855F7;
    --theme-primary-bg:       #FAF5FF;
    --theme-secondary-bg:     #F3E8FF;
    --theme-text-on-primary:  #ffffff;

    --app-bg-main:            #FFFFFF;
    --app-bg-page:            var(--theme-primary-bg);
    --app-bg-sidebar:         var(--theme-secondary-bg);
    --app-border-color:       #D8B4FE;
    --app-btn-disabled-bg-new:   #C4A3E0;
    --app-btn-disabled-text-new: #6B3F8A;
    --app-text-color-light:   #581C87;

    /* Progress segments */
    --seg-correct:   #10B981;
    --seg-incorrect: rgba(220, 53, 69, 0.55);

    /* Option states */
    --opt-correct-bg:     #D1FAE5;
    --opt-correct-border: #059669;
    --opt-correct-text:   #065F46;
    --opt-wrong-bg:       #FEE2E2;
    --opt-wrong-border:   #DC2626;
    --opt-wrong-text:     #7F1D1D;
}

/* ============ PAGE ============ */
main > .page-section:first-of-type {
    background-color: var(--app-bg-page);
}

/* ============ APP SHELL ============ */
.app-container {
    border: 1px solid var(--app-border-color);
    border-radius: 24px;
    overflow-x: auto;
    background-color: var(--app-bg-main);
    text-align: left;
    transition: all 0.3s ease-in-out;
    max-width: 100%;
}

.app-header {
    display: grid;
    grid-template-columns: 1fr 13fr 1fr;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background-color: var(--theme-primary);
    color: var(--theme-text-on-primary);
    border-bottom: 1px solid var(--theme-primary-dark);
    border-radius: 24px 24px 0 0;
}
.app-header-title {
    grid-column: 2;
    text-align: center;
    padding: 0 1rem;
}
.app-header .btn-icon { justify-self: end; }
.app-header h2 { font-size: 1.2rem; margin: 0; }

.app-main {
    display: grid;
    grid-template-columns: minmax(240px, 34%) 1fr;
}

.app-sidebar,
.app-content {
    padding: 1.5rem;
    min-width: 0;
}
.app-sidebar {
    border-right: 1px solid var(--app-border-color);
    display: flex;
    flex-direction: column;
    background-color: var(--app-bg-sidebar);
}
.app-sidebar section { margin-bottom: 1rem; }
.app-sidebar section:last-child {
    margin-top: auto;
    margin-bottom: 0;
    padding-top: 1rem;
}
.app-sidebar h3 {
    font-size: 1.1rem;
    border-bottom: 2px solid var(--theme-primary);
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
}

/* ============ FORM ============ */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
}
.form-group textarea {
    width: 100%;
    min-height: 120px;
    padding: 0.75rem;
    border: 1px solid var(--app-border-color);
    border-radius: 24px;
    font-family: inherit;
    resize: vertical;
    background-color: #ffffff;
}

.info-box {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background-color: #ffffff;
    border-radius: 24px;
    font-size: 0.85rem;
    line-height: 1.4;
    border-left: 4px solid var(--theme-primary);
    margin: 1rem 0;
}
.info-box i {
    font-size: 1.5rem;
    color: var(--theme-primary);
    margin-top: 0.25rem;
}
.info-box a { color: var(--theme-primary); font-weight: 600; }

/* ============ SIDEBAR ACTIONS ============ */
.actions-message {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--app-border-color);
    border-radius: 24px;
    margin-bottom: 0.5rem;
    min-height: 50px;
    padding: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-color);
    transition: all 0.3s ease;
}
.actions-message.actions-message--success { color: #155724; background-color: #d4edda; border: 1px solid #c3e6cb; }
.actions-message.actions-message--error   { color: #721c24; background-color: #f8d7da; border: 1px solid #f5c6cb; }
.actions-message.actions-message--info    { color: #0c5460; background-color: #d1ecf1; border: 1px solid #bee5eb; }

.app-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.app-actions .btn { flex: 1; }
.app-actions .btn-primary { background-color: var(--theme-primary); color: var(--theme-text-on-primary); }
.app-actions .btn-primary:hover { background-color: var(--theme-primary-dark); }

.app-container .btn:disabled,
.app-container .btn-primary:disabled,
.app-container .btn-secondary:disabled {
    background-color: var(--app-btn-disabled-bg-new);
    color: var(--app-btn-disabled-text-new);
    border-color: transparent;
    opacity: 1;
    cursor: not-allowed;
}

/* Focus toggle icon */
.btn-icon {
    background: none;
    border: 1px solid transparent;
    border-radius: 50%;
    width: 40px; height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--theme-text-on-primary);
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.btn-icon:hover { background-color: rgba(255,255,255,0.1); }
.btn-icon .fa-compress { display: none; }
.app-container.is-focused .btn-icon .fa-expand  { display: none; }
.app-container.is-focused .btn-icon .fa-compress { display: inline-block; }

/* ============ FOCUS MODE ============ */
body.focus-mode-active {
    overflow: hidden;
    background-color: var(--theme-primary);
}
body.focus-mode-active .site-header,
body.focus-mode-active .footer,
body.focus-mode-active main > *:not(#app-section-wrapper) { display: none; }
body.focus-mode-active #app-section-wrapper { padding: 0; background-color: transparent; }
body.focus-mode-active #app-section-wrapper .container { max-width: none; padding: 0; }

.app-container.is-focused {
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
    width: 100%;
}
.app-container.is-focused .app-header {
    border-radius: 0;
    border-top: none;
}
.app-container.is-focused .app-main { flex-grow: 1; min-height: 0; }
.app-container.is-focused .app-sidebar,
.app-container.is-focused .app-content { display: flex; flex-direction: column; }

/* ============ QUIZ VIEWER ============ */
.quiz-viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* --- Status bar (counter + progress + toggle) --- */
.quiz-status {
    display: grid;
    grid-template-columns: 1fr 3fr 1fr;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.progress-container {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}
.swap-container {
    grid-column: 3;
    display: flex;
    justify-content: center;
    align-items: center;
    justify-self: center;
}
.swap-control-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}
.card-counter { font-weight: 700; font-size: 1.2rem; }

/* Segmented progress bar — green correct, red incorrect */
.progress-bar {
    width: 80%;
    height: 12px;
    background-color: var(--app-border-color);
    border-radius: 12px;
    overflow: hidden;
    margin: 0 auto;
    display: flex;
}
.progress-segment {
    height: 100%;
    transition: background-color 0.3s ease;
}
.progress-segment--correct   { background-color: var(--seg-correct); }
.progress-segment--incorrect { background-color: var(--seg-incorrect); }

.swap-label { font-size: 0.9rem; font-weight: 600; text-align: center; }

/* Toggle switch */
.toggle-control {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    font-size: 1.2rem;
    color: var(--text-color);
}
.toggle-control input {
    position: absolute;
    opacity: 0;
    width: 0; height: 0;
}
.toggle-ui {
    position: relative;
    width: 40px; height: 22px;
    background-color: var(--app-border-color);
    border-radius: 11px;
    transition: background-color 0.2s ease-in-out;
    flex-shrink: 0;
}
.toggle-ui::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 18px; height: 18px;
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    transition: transform 0.2s ease-in-out;
}
.toggle-control input:checked + .toggle-ui { background-color: var(--theme-primary); }
.toggle-control input:checked + .toggle-ui::after { transform: translateX(18px); }

/* --- Question area --- */
.question-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
    border: 1px solid var(--app-border-color);
    border-radius: 24px;
    background-color: #fff;
    position: relative;
    overflow: hidden;
    min-height: 180px;
}
.question-intro {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--app-text-color-light);
}
.question-intro i { font-size: 2.5rem; color: var(--text-color); }
.question-intro p { font-size: 1.5rem; font-weight: 500; line-height: 1.4; }

.question-text {
    font-weight: 700;
    line-height: 1.3;
    font-size: 3rem;
    color: var(--theme-primary-dark);
    transition: font-size 0.3s ease;
}
.question-text.font-size-xl { font-size: 4.5rem; }
.question-text.font-size-lg { font-size: 3.75rem; }
.question-text.font-size-md { font-size: 3rem; }
.question-text.font-size-sm { font-size: 2.25rem; }

/* --- Feedback strip (always present, no height change) --- */
.quiz-feedback {
    min-height: 50px;
    padding: 0.75rem;
    margin-top: 1rem;
    border-radius: 24px;
    text-align: center;
    font-weight: 600;
    font-size: 1rem;
    opacity: 0;
    transform: translateY(-5px);
    transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.quiz-feedback.is-correct  { opacity: 1; transform: translateY(0); color: #155724; background-color: #d4edda; }
.quiz-feedback.is-incorrect{ opacity: 1; transform: translateY(0); color: #721c24; background-color: #f8d7da; }
.quiz-feedback.is-info     { opacity: 1; transform: translateY(0); color: #0c5460; background-color: #d1ecf1; }

/* --- Options grid — 2×2, always 4 buttons, fixed height --- */
.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 1rem;
}
.option-btn {
    background-color: #ffffff;
    border: 2px solid var(--app-border-color);
    border-radius: 16px;
    padding: 0 1.25rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
    cursor: pointer;
    text-align: left;
    height: 64px;           /* fixed — no jumpiness */
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    overflow: hidden;
}
.option-btn:not(:disabled):hover {
    background-color: var(--theme-secondary-bg);
    border-color: var(--theme-primary-light);
    transform: translateY(-2px);
}
.option-btn:not(:disabled):active { transform: translateY(0); }

/* Letter badge */
.option-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px; height: 26px;
    background-color: var(--app-border-color);
    color: var(--theme-primary-dark);
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 800;
    flex-shrink: 0;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.option-text { flex: 1; line-height: 1.3; }

/* Correct */
.option-btn.is-correct { background-color: var(--opt-correct-bg); border-color: var(--opt-correct-border); color: var(--opt-correct-text); }
.option-btn.is-correct .option-letter { background-color: var(--opt-correct-border); color: #fff; }

/* Wrong */
.option-btn.is-wrong { background-color: var(--opt-wrong-bg); border-color: var(--opt-wrong-border); color: var(--opt-wrong-text); }
.option-btn.is-wrong .option-letter { background-color: var(--opt-wrong-border); color: #fff; }

/* Reveal correct after wrong pick */
.option-btn.is-revealed { background-color: var(--opt-correct-bg); border-color: var(--opt-correct-border); color: var(--opt-correct-text); opacity: 0.75; }
.option-btn.is-revealed .option-letter { background-color: var(--opt-correct-border); color: #fff; }

/* Disabled plain state */
.option-btn:disabled:not(.is-correct):not(.is-wrong):not(.is-revealed) { opacity: 0.4; cursor: not-allowed; }

/* --- Controls row — always 4 buttons, static position --- */
.quiz-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-top: auto;
    padding-top: 1.5rem;
}
.quiz-controls .btn-primary { background-color: var(--theme-primary); color: var(--theme-text-on-primary); }
.quiz-controls .btn-primary:hover:not(:disabled) { background-color: var(--theme-primary-dark); }

/* ============ COMPLETION ============ */
.question-area.is-completed { background-color: #d4edda; color: #155724; }
.question-area.is-completed .question-intro p { font-size: 1.2rem; margin: 0; color: inherit; }
.question-area.is-completed .question-intro i { color: inherit; font-size: 3rem; }
.question-area.is-completed .completion-content h3 { font-size: 1.5rem; margin-bottom: 0.5rem; }

/* ============ RESPONSIVE ============ */

/* Desktop focus */
@media (min-width: 768px) {
    .app-container:not(.is-focused) .app-header {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }
    .app-container.is-focused {
        position: fixed;
        top: 0; left: 0;
        width: 100%;
        height: calc(var(--vh, 1vh) * 100);
        z-index: 2000;
    }
    .app-container.is-focused .app-main {
        grid-template-columns: minmax(240px, 25%) 1fr;
    }
    .app-container.is-focused .app-main,
    .app-container.is-focused .app-sidebar {
        overflow-y: auto;
    }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 992px) {
    .app-sidebar, .app-content { padding: 0.75rem; }
    .app-sidebar h3 { font-size: 1rem; margin-bottom: 0.25rem; }
    .info-box { margin: 0.5rem 0; padding: 0.75rem; }
    .quiz-status { margin-bottom: 0.5rem; }
    .quiz-controls { padding-top: 0.5rem; }
}

/* Tablet & mobile — controls go 2×2 */
@media (max-width: 992px) {
    .quiz-controls { grid-template-columns: 1fr 1fr; }
}

/* Mobile */
@media (max-width: 768px) {
    .app-main { grid-template-columns: 1fr; }
    .app-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--app-border-color);
    }
    .quiz-status {
        grid-template-columns: 2fr 1fr;
        gap: 0.5rem;
    }
    .progress-container { grid-column: 1; }
    .swap-container     { grid-column: 2; }

    .question-area { min-height: 200px; }

    .question-text.font-size-xl { font-size: 3.5rem; }
    .question-text.font-size-lg { font-size: 3rem; }
    .question-text.font-size-md { font-size: 2.4rem; }
    .question-text.font-size-sm { font-size: 1.8rem; }

    body.focus-mode-active { overflow: hidden; }
    .app-container.is-focused {
        position: fixed;
        top: 0; left: 0;
        width: 100%;
        height: calc(var(--vh, 1vh) * 100);
        z-index: 2000;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .app-container.is-focused .app-main,
    .app-container.is-focused .app-sidebar { overflow-y: visible; }

    .app-container:not(.is-focused) .app-header {
        padding-top: 1.15rem;
        padding-bottom: 1.15rem;
    }
    .app-actions .btn,
    .quiz-controls .btn { padding-top: 0.8rem; padding-bottom: 0.8rem; }
}

/* Small mobile */
@media (max-width: 480px) {
    .options-grid { grid-template-columns: 1fr; }
    .option-btn { height: 56px; }
    .quiz-status .swap-label { display: none; }
    .question-text.font-size-xl { font-size: 2.8rem; }
    .question-text.font-size-lg { font-size: 2.4rem; }
    .question-text.font-size-md { font-size: 2.0rem; }
    .question-text.font-size-sm { font-size: 1.6rem; }
}
