/* =========================================
   QUIZ & PUZZLE STYLING
   ========================================= */

/* Colours come from --qk-* tokens (zero specificity, so a course can override
   them with a plain `body { --qk-good: ... }`). Text, background, border and
   accent follow Bootstrap's mode-aware variables (--bs-body-color, --bs-body-bg,
   --bs-border-color, --bs-primary). Muted text, the state colours and the state
   tints are derived here instead, because --bs-secondary-color is a brand
   accent (not muted text) and --bs-success/-danger/-warning (and their
   *-subtle/-emphasis variants) are compiled from the light palette in both
   Quarto bundles. Dark values apply under Quarto's `body.quarto-dark`.

   Contrast (WCAG), measured:
     light  text #363D45 on #FFFDFC 10.8:1   muted (75% text) #686D73 5.1:1
            good #2E7D32 5.1:1, bad #B3261E 6.5:1, warn #B34700 5.4:1 as text on the page;
            body text on their tints (20-25%) 7.1:1 or better
     dark   text #E0DAD2 on #131415 13.3:1   muted (75% text) #ADA8A3 7.8:1
            good #7FCF86 9.8:1, bad #F08A8A 7.7:1, warn #FFA066 9.2:1 as text on the page;
            body text on their tints (20-25%) 7.7:1 or better */

:where(body) {
    --qk-text: var(--bs-body-color, #363d45);
    --qk-bg: var(--bs-body-bg, #fffdfc);
    --qk-border: var(--bs-border-color, #ccc);
    --qk-accent: var(--bs-primary, #0f6e6b);
    --qk-muted: color-mix(in srgb, var(--qk-text) 75%, var(--qk-bg));
    --qk-good: #2e7d32;
    --qk-bad: #b3261e;
    --qk-warn: #b34700;
    --qk-good-tint: color-mix(in srgb, var(--qk-good) 20%, var(--qk-bg));
    --qk-bad-tint: color-mix(in srgb, var(--qk-bad) 25%, var(--qk-bg));
}

:where(body.quarto-dark) {
    --qk-good: #7fcf86;
    --qk-bad: #f08a8a;
    --qk-warn: #ffa066;
}

/* Wrapper for Puzzle + Story */
.scenario-block {
    margin-bottom: 25px; /* Reduced from 40px */
    width: 100%;
}

/* The White Box Container */
.puzzle-box {
    background: var(--qk-bg);
    border: 1px solid var(--qk-border);
    padding: 20px; /* Reduced padding from 25px */
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 15px; /* Reduced spacing */
}

/* --- BUTTONS (Single/Multiple Choice) --- */
.quiz-option {
    display: block;
    width: 100%;
    padding: 10px 12px; /* Tighter padding */
    margin-bottom: 6px;
    text-align: left;
    background: var(--qk-bg);
    border: 1px solid var(--qk-border); /* Thinner border */
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    color: var(--qk-text);
}

.quiz-option:hover:not(:disabled) {
    border-color: var(--qk-accent);
    background-color: color-mix(in srgb, var(--qk-accent) 8%, var(--qk-bg));
}

/* Selected State */
.quiz-option.selected {
    border-color: var(--qk-accent);
    background-color: var(--qk-bg);
    font-weight: bold;
    box-shadow: 0 0 0 1px var(--qk-accent) inset; /* Inner border glow */
}

/* Correct State (Persistent even if disabled) */
/* text-emphasis/bg-subtle are mode-aware Bootstrap tokens: they invert
   in dark mode, so the solved state stays readable on dark backgrounds. */
.quiz-option.correct,
.quiz-option.correct:disabled {
    color: var(--qk-text) !important;
    opacity: 1 !important;
    background-color: var(--qk-good-tint) !important;
    border-color: var(--qk-good) !important;
    font-weight: bold;
    cursor: default;
}

/* Wrong State */
.quiz-option.wrong {
    border-color: var(--qk-bad) !important;
    background-color: var(--qk-bad-tint) !important;
}

/* Disabled State (e.g. greyed out during the penalty cooldown). */
/* Scoped away from .correct and .wrong so those keep their own colors. */
.quiz-option:disabled:not(.correct):not(.wrong) {
    color: var(--qk-muted);
    opacity: 0.55;
    cursor: not-allowed;
}

/* --- MULTI-RESPONSE CONTAINER --- */
/* Whole-container feedback (shake + outline) so a wrong guess doesn't
   single out any one option and give away which ones were correct. */
.quiz-options.wrong {
    /* An outline around the whole group: an inset shadow only showed in the
       gaps between the full-width options, as stray coloured stripes. */
    outline: 2px solid var(--qk-warn);
    outline-offset: 4px;
    border-radius: 8px;
}

/* --- INPUT FIELDS (Type Answer) --- */
.quiz-input {
    /* Layout & Size */
    display: block; /* Forces it to be on its own line */
    width: 100%; /* Takes up full width of the box */
    box-sizing: border-box; /* Ensures padding doesn't break width */
    margin: 10px 0; /* Adds space above and below */

    /* Visuals */
    padding: 12px;
    font-size: 1.1rem;
    border: 2px solid var(--qk-border);
    border-radius: 6px;
    background-color: var(--qk-bg);
    color: var(--qk-text);
    transition: all 0.2s ease;
}

.quiz-input:focus {
    outline: none;
    border-color: var(--qk-accent); /* Brand Glow */
    box-shadow: 0 0 8px
        color-mix(in srgb, var(--qk-accent) 15%, transparent);
}

.quiz-input:disabled {
    background-color: color-mix(in srgb, var(--qk-text) 6%, var(--qk-bg));
    color: var(--qk-muted);
    border-color: var(--qk-border);
    cursor: not-allowed;
}

/* Success State (Green) */
.quiz-input.correct {
    background-color: var(--qk-good-tint) !important;
    border-color: var(--qk-good) !important;
    color: var(--qk-text);
    font-weight: bold;
}

/* Error State (Red) */
.quiz-input.wrong {
    border-color: var(--qk-bad) !important;
    background-color: var(--qk-bad-tint) !important;
}

/* --- K-PRIM TABLE (4 richtig/falsch rows) --- */
.kprim-table {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 10px 0;
}

.kprim-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--qk-border);
    border-radius: 6px;
    background: var(--qk-bg);
    flex-wrap: wrap;
}

.kprim-statement {
    flex: 1 1 auto;
    text-align: left;
}

.kprim-buttons {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.kprim-true,
.kprim-false {
    padding: 6px 14px;
    border: 1px solid var(--qk-border);
    border-radius: 5px;
    background: var(--qk-bg);
    color: var(--qk-text);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.kprim-true:hover:not(:disabled),
.kprim-false:hover:not(:disabled) {
    border-color: var(--qk-accent);
}

.kprim-true.selected,
.kprim-false.selected {
    border-color: var(--qk-accent);
    background-color: color-mix(in srgb, var(--qk-accent) 15%, var(--qk-bg));
    box-shadow: 0 0 0 1px var(--qk-accent) inset;
}

.kprim-true.correct,
.kprim-false.correct {
    color: var(--qk-text) !important;
    background-color: var(--qk-good-tint) !important;
    border-color: var(--qk-good) !important;
}

.kprim-true:disabled:not(.correct),
.kprim-false:disabled:not(.correct) {
    color: var(--qk-muted);
    opacity: 0.55;
    cursor: not-allowed;
}

/* Whole-table feedback for a wrong guess, mirrors .quiz-options.wrong:
   never mark individual rows so the correct answers stay hidden. */
.kprim-table.wrong {
    box-shadow: 0 0 0 2px var(--qk-warn) inset;
    border-radius: 8px;
}

/* --- ACTION AREA --- */
/* The fill leans 15 % towards the text colour: darker on a light page, lighter
   on a dark one, so the label clears 4.5:1 on mid-tone brand accents too
   (#537E8F: 4.36:1 plain, 5.0:1 mixed). */
.quiz-submit {
    background-color: color-mix(in srgb, var(--qk-accent) 85%, var(--qk-text));
    color: var(--qk-bg);
    border: none;
    padding: 8px 16px; /* Compact button */
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 5px;
    font-size: 0.95rem;
}

.quiz-submit:disabled {
    background-color: var(--qk-muted);
    cursor: not-allowed;
    opacity: 0.7;
}

/* --- Success Feedback Color --- */
.quiz-feedback.success {
    color: var(--qk-good) !important; /* Force success color, override default red */
}

/* --- REVEALED TEXT (Story) --- */
.revealed-text {
    display: none; /* Hidden by default */
    margin-top: 15px; /* Reduced spacing */
    animation: fadeText 1.5s;
}

@keyframes fadeText {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- ERROR ANIMATION (Shake) --- */
.shake {
    animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shake {
    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }
    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }
    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }
    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

/* --- POST-ANSWER FEEDBACK NOTE (revealed by JS after a question is solved) --- */
.quiz-feedback-note {
    margin-top: 10px;
    padding: 10px 12px;
    border-left: 3px solid var(--qk-accent);
    background: color-mix(in srgb, var(--qk-accent) 6%, var(--qk-bg));
    border-radius: 4px;
    font-size: 0.95rem;
}

/* --- PER-OPTION EXPLANATION (shown under a single-choice box after a wrong pick) --- */
.quiz-option-explanation {
    margin: 4px 0 8px;
    font-size: 0.9rem;
    color: var(--qk-muted);
}

/* --- PROGRESS BAR (live solved counter + first-try score) --- */
.quiz-progress {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    align-items: baseline;
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: var(--qk-muted);
}

.quiz-progress-score {
    font-weight: 600;
    color: var(--qk-good);
}

/* --- START-OVER CONTROL (persistence reset) --- */
.quiz-reset {
    margin-left: auto;
    padding: 2px 10px;
    font-size: 0.8rem;
    border: 1px solid var(--qk-border);
    border-radius: 5px;
    background: var(--qk-bg);
    color: var(--qk-muted);
    cursor: pointer;
}

.quiz-reset:hover {
    border-color: var(--qk-accent);
    color: var(--qk-accent);
}

/* --- K-PRIM PER-STATEMENT NOTE (revealed after the grid is solved) --- */
.kprim-note {
    flex-basis: 100%;
    margin-top: 6px;
    padding: 8px 10px;
    font-size: 0.9rem;
    border-left: 3px solid var(--qk-good);
    background: color-mix(in srgb, var(--qk-good) 6%, var(--qk-bg));
    border-radius: 4px;
}
