:root {
    --primary: #4a90e2;
    --bg-color: #f4f7f6;
    --text-color: #333;
    --box-bg: #f4f4f4;
    --border-color: #333;
    --btn-text-color: #fff;
    --feedback-bg: #fff;
    --option-bg: #eee;
    --option-border: #333;
    --option-text-color: #333;
    --abort-text-color: #999;
    --abort-border-color: #ddd;
    --bg: #f4f7f6;
    --text: #333;
    --card-bg: #fff;
    --success: #2ecc71;
    --error: #e74c3c;
    --draggable: #3498db;
    --droppable: #ecf0f1;
}

body.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --box-bg: #1d1f23;
    --border-color: #3a3f47;
    --btn-text-color: #e0e0e0;
    --feedback-bg: #2a2a2a;
    --option-bg: #23262b;
    --option-border: #4b5563;
    --option-text-color: #e5e7eb;
    --abort-text-color: #cccccc;
    --abort-border-color: #9ca3af;
    --bg: var(--bg-color);
    --text: var(--text-color);
}

/* Dark-mode-specific visibility overrides for key UI elements. */
body.dark-mode #question-container #question-text {
    color: var(--text-color);
}

body.dark-mode #game-title,
body.dark-mode #stats-text,
body.dark-mode .stats-text,
body.dark-mode #current-q-num,
body.dark-mode .bookmark-btn,
body.dark-mode #total-q-num {
    color: var(--text-color);
}

body.dark-mode #abort-quiz-btn {
    color: var(--abort-text-color) !important;
    border-color: var(--abort-border-color) !important;
}

body.dark-mode .btn-abort {
    color: var(--abort-text-color);
    border-color: var(--abort-border-color);
}

body.dark-mode #feedback-container,
body.dark-mode #feedback-box {
    background-color: var(--feedback-bg);
}

body.dark-mode .option-btn {
    color: var(--option-text-color);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Arial, Helvetica, sans-serif !important;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column; /* Tvinger elementene under hverandre */
    align-items: center;    /* Sentrerer elementene horisontalt */
    justify-content: center;
    min-height: 100vh;
}

.main-container {
    width: 100%;
    max-width: clamp(60vw, 98vw, 100vw);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* Containeren må være flex for å fylle høyden */
.main-container {
    display: flex;
    flex-direction: column;
    min-height: clamp(520px, 100vh, 700px); 
    /*520px;*/
    /* Din faste 1200x550 layout */
    position: relative;
    /*background: var(--bg-color);*/
    overflow: hidden;
}

/* Den nye meny-visningen */
.menu-container {
    flex: 1;
    /* Fyller all tilgjengelig plass i main-container */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /*padding: 40px;*/
    width: 100%;
    box-sizing: border-box;
    transition: opacity 0.3s ease;
    /* For penere overgang */
}

/* Fjern modal-stilen */
.start-menu-modal {
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
    max-width: 900px !important;
    /* Gjør menyen litt bredere og luftigere */
}

/* Gruppering av knapper for en ryddig look */
.start-menu-groups {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    /* Sørger for at det fungerer på mobil */
    width: 100%;
}

.menu-card {
    flex: 1;
    /*min-width: 250px;*/
    background: rgba(255, 255, 255, 0.05);
    /* Svak bakgrunn for å skille seksjonene */
    padding: 20px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Header & Stats */
header {
    text-align: center;
    margin-bottom: 20px;
}

.stats-bar {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
    font-size: 1.2rem;
    font-weight: bold;
}

/* Game Board */
.game-board {
    display: flex;
    flex-direction: column;
    gap: 30px;
    flex-grow: 1;
}

h3 {
    text-align: center;
    margin-bottom: 15px;
    color: #555;
}

.box-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal {
    background: white;
    padding: clamp(10px, 2vh, 30px);
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    width: 95%;
    max-width: 91vw;
}

.btn-abort {
    display: block;
    margin: 20px auto 10px auto;
    padding: 5px 10px;
    font-size: 0.75rem;
    color: #999;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.btn-abort i {
    font-size: 0.7rem;
}

.btn-abort:hover {
    opacity: 1;
    color: #666;
    border-color: #b8b8b8;
}

.abort-container {
    /*position: absolute;
    bottom: 15px;*/
    /* Avstand fra den absolutte bunnen av containeren */
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    /* Sentrerer knappen horisontalt */
    /*pointer-events: none;*/
    /* Gjør at wrappperen ikke blokkerer klikk bak seg */
}

#start-menu-view {
    /*width: 95%;*/
    max-width: 95vw;
    /*padding: clamp(0rem, 2vw, 1.8rem);*/
    justify-content: space-evenly;
}

#start-menu-modal {
    width: 95%;
    max-width: 90vw;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    text-align: left;
    justify-content: space-evenly;
}

.start-menu-groups {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.start-menu-header {
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 14px;
}

.start-menu-header p {
    margin-top: 6px;
    color: #4b5563;
}

.start-menu-header {
    width: 100%;
    /*max-width: 900px;*/
    /* Matcher max-width på gruppen under */
    /*min-width: 250px;*/
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Sentrerer tekst og dropdown */
    text-align: center;
}

/* Sørg for at wrapperen rundt select-menyen fyller bredden */
.start-category-wrapper {
    display: grid !important;
    /* Lager så mange kolonner som mulig, minimum 180px per knapp */
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    width: 100%;
    margin-top: 20px;
}

/* Gjør selve dropdown-menyen bredere og mer "proff" */
.start-category-select {
    width: 100%;
    /*max-width: 500px;*/
    /* Gir den en god bredde på PC, men ikke over hele skjermen */
    padding: 12px;
    font-size: 1.1rem;
}

/*.start-category-wrapper {
    margin-top: 12px;
}

.start-category-select {
    width: 100%;
    min-height: auto;
    padding: 10px;
}*/

.category-buttons-container {
    display: none;
}

.category-btn {
    flex: 1 1 180px;
        /* Prøver å være 180px, men kan vokse (1) */
    min-height: 60px;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background-color: white;
    cursor: pointer;
    transition: transform 0.1s;
}

/* Spesifikke regler for eksamensknappen */
.category-btn-exam {
    background-color: #eed4a3 !important;
    /* Den grønnfargen du hadde */
    font-weight: bold;
    border: 1px solid #2d5a27;
    /* Denne gjør at knappen strekker seg over alle kolonnene på raden */
    /* flex-grow: 999 gjør at denne knappen alltid prioriterer 
           å ta ALL ledig plass på raden den havner på.
        */
    flex: 999 1 250px;
    margin-top: 5px;
}

.category-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.category-btn.active {
    border-color: #2563eb;
    background: #38df6d6b;
    border: 3px solid;
    /*color: #ffffff;*/
}

@media (min-width: 801px) {
    #category-select {
        display: none;
    }

    .category-buttons-container {
        display: flex;
        flex-wrap: wrap;
        /* Tillater flere rader */
        gap: 12px;
        width: 100%;
        justify-content: flex-start;
        /* Starter fra venstre */
    }
}

@media (max-width: 800px) {
    #category-select {
        display: block;
        align-items: center;
    }

    .category-buttons-container {
        display: none;
    }
}

.menu-card {
    background: #edf3ff;
    border: 1px solid #d3dffa;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.12);
}

.menu-card-review,
.menu-card-system {
    background: #f8fafc;
    border-color: #e5e7eb;
    box-shadow: none;
}

.start-action-btn {
    width: 100%;
    min-height: 52px;
    font-size: 1.02rem;
    font-weight: 700;
    padding: 14px 16px;
    border-radius: 12px;
    background: #2563eb;
    color: #fff;
}

.start-action-btn:hover {
    background: #1d4ed8;
}

.start-secondary-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

@media (min-width: 801px) {
    #start-menu-modal {
        width: 90%;
        max-width: 60vw;
        min-height: 60vh;
    }

    .start-menu-groups {
        flex-direction: row;
        justify-content: center;
        align-items: flex-start;
        gap: 20px;
    }

    .start-menu-groups .menu-card {
        flex: 1;
        min-width: 0;
    }
}

@media (max-width: 800px) {
    .start-menu-groups {
        flex-direction: column;
        gap: 12px;
    }
}
@media (max-width: 480px) {
    .start-category-wrapper {
        grid-template-columns: 1fr;
    }
}

.review-btn,
.system-btn {
    width: 100%;
    min-height: 44px;
    border-radius: 12px;
    font-size: 0.95rem;
    padding: 10px 14px;
}

.review-btn {
    background: #f5bf4b;
    color: #fff;
}

.review-btn:hover {
    background: #0b5f59;
}

.stats-btn {
    background: #40e640;
    color: #fff;
}
.info-btn {
    background: #d92e2e;
    color: #fff;
}
.system-btn {
    background: #6b7280;
    color: #fff;
}

.system-btn:hover {
    background: #4b5563;
}

.settings-save-btn {
    margin-top: 14px;
    width: 100%;
}

/* Draggable Items (Begreper) */
.draggable {
    background-color: var(--draggable);
    color: white;
    padding: 15px;
    border-radius: 8px;
    cursor: grab;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, opacity 0.2s;
    user-select: none;
}

.draggable:active {
    cursor: grabbing;
    transform: scale(1.05);
}

.draggable.dragging {
    opacity: 0.5;
}

/* Droppable Targets (Forklaringer) */
.droppable {
    background-color: var(--card-bg);
    border: 2px dashed #bdc3c7;
    border-radius: 8px;
    padding: 15px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: all 0.3s;
    font-size: 0.95rem;
}

.droppable.hovered {
    background-color: #d6eaf8;
    border-color: var(--primary);
    transform: scale(1.02);
}

/* Success State */
.droppable.correct {
    background-color: var(--success);
    color: white;
    border-style: solid;
    border-color: #27ae60;
}

/* Animation for wrong answer */
.shake {
    animation: shake 0.5s;
    border-color: var(--error);
    background-color: #fadbd8;
}

@keyframes shake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    50% {
        transform: translateX(5px);
    }

    75% {
        transform: translateX(-5px);
    }

    100% {
        transform: translateX(0);
    }
}

/* Overlay / Menus */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.hidden {
    display: none;
}

.btn-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: bold;
    color: var(--btn-text-color);
    transition: opacity 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn.small {
    padding: 8px 16px;
    font-size: 0.9rem;
}

.btn:hover {
    opacity: 0.9;
}

.green {
    background-color: var(--success);
}

.yellow {
    background-color: #f1c40f;
    color: black;
}

.red {
    background-color: var(--error);
}

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

/* --- Tillegg for Flervalgsquiz --- */

/* Progresjonsbar */
.progress-section {
    width: 100%;
    max-width: 600px;
    margin: 0 auto 20px auto;
    text-align: center;
}

.progress-track {
    background-color: #e0e0e0;
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 5px;
}

.progress-fill {
    height: 100%;
    background-color: var(--success);
    width: 0%;
    transition: width 0.3s ease;
}

/* Quiz Layout */
.game-board-quiz {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.question-box {
    background-color: #fff;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 100%;
    text-align: center;
    border-left: 5px solid var(--primary);
}

#question-text {
    font-size: clamp(1.1rem, 4vw, 1.8rem);
    color: var(--text-color);
    margin: 0;
    line-height: 1.4;
}

.question-image {
    display: block;
    margin: 15px auto;
    /* Sentrerer horisontalt og gir luft over/under */

    /* STØRRELSE */
    width: 80%;
    /* Tvinger bildet til å fylle 80% av containeren */
    max-width: 500px;
    max-height: 25vh;
    /* Men aldri bredere enn 500px (juster etter ønske) */
    /*min-height: 200px;*/
    /* Sikrer at det alltid er en viss høyde */

    /* BILDEBEHANDLING */
    object-fit: contain;
    /* Bevarer proporsjoner uten å beskjære */
    background-color: rgba(255, 255, 255, 0.03);
    /* Gir en svak ramme hvis bildet er gjennomsiktig */

    border-radius: 8px;
    transition: transform 0.2s ease;
}

body.dark-mode .question-image {
    border-color: rgba(255, 255, 255, 0.2);
    background-color: rgba(255, 255, 255, 0.06);
    filter: brightness(1.02) contrast(1.03);
}

#question-subcategory-label {
    display: none !important;
    /* Tar null plass */
}

/* Når brukeren har svart, tvinger vi den frem */
.show-subcategory #question-subcategory-label {
    display: block !important;
    animation: fadeIn 0.4s ease-in;
    /* Valgfri animasjon for myk overgang */
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 0.8;
    }
}

.glossary-term {
    position: relative;
    border-bottom: 2px dotted #16a34a;
    cursor: help;
    font-weight: 600;
}

.glossary-term::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%) translateY(4px);
    min-width: 180px;
    max-width: min(280px, 80vw);
    padding: 8px 10px;
    border-radius: 8px;
    background: #111827;
    color: #f9fafb;
    font-size: 0.82rem;
    line-height: 1.35;
    text-align: left;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 15;
}

.glossary-term:hover::after,
.glossary-term.active::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.score-card .glossary-term,
#scoreboard-container .glossary-term {
    all: unset !important;
    font-weight: inherit !important;
    text-decoration: none !important;
    color: inherit !important;
    border: none !important;
}

@media print {
    .glossary-term {
        all: unset !important;
        font-weight: inherit !important;
        text-decoration: none !important;
        color: inherit !important;
        border: none !important;
    }
}

@media (max-width: 700px) {
    .glossary-term {
        border-bottom-width: 3px;
        padding-bottom: 1px;
    }
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: clamp(10px, 2vw, 20px);
    width: 100%;
    max-width: 100%;
        /* Hindrer gridet i å bli bredere enn forelderen */
}

/* Knapper for svaralternativer */
.option-btn {
    /* 1. Layout og størrelse */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    min-height: clamp(60px, 12vh, 90px);
    /* Justert for 550px høyde */
    padding: clamp(8px, 2vh, 15px) 10px;
    box-sizing: border-box;
    min-width: 0;

    /* 2. Tekst og formatering */
    font-size: clamp(0.85rem, 2.5vh, 1.1rem);
    /* Skalerer med høyde */
    font-weight: 200;
    white-space: normal !important;
    word-wrap: break-word;
    overflow-wrap: break-word;

    /* 3. Visuelt design (bruker variablene dine) */
    background-color: var(--option-bg, white);
    color: var(--option-text-color, #333);
    border: 2px solid var(--option-border, #dcdcdc);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.option-btn b {
    font-weight: 700 !important; 
    display: inline-block; /* Gjør at margin faktisk fungerer stabilt */
    margin-left:0.4vw;
    margin-right: 0.4vw;
}

.option-btn var {
    font-weight: 700 !important; 
    display: inline-block; /* Gjør at margin faktisk fungerer stabilt */
    margin-left:0.4vw;
    margin-right: 0.4vw;
}

/* Hindre at matematikk-containere dytter ut boksene */
.option-btn mjx-container {
    max-width: 100% !important;
    /* Fjerner scrollbar */
    display: inline-block !important;
    align-items: center;
    margin: 0 2px !important;
}

/* Global MathJax container fixes to prevent layout issues */
.mjx-chtml {
    white-space: normal !important;
}

mjx-container {
    display: inline-block !important;
    margin: 0 2px !important;
}


.option-btn:hover:not(:disabled) {
    background-color: #f0f8ff;
    border-color: var(--primary);
    transform: translateY(-2px);
}

/* Tilstander for svar */
.option-btn.correct {
    background-color: var(--success);
    color: white;
    border-color: #27ae60;
    transform: scale(1.02); /* Gjør dem bittelitt større */
}

.option-btn.wrong {
    background-color: var(--error);
    color: white;
    border-color: #c0392b;
    opacity: 0.8;
}

.option-btn:disabled {
    cursor: default;
    transform: none;
}

/* Feedback boks nederst */
.feedback-box {
    width: 100%;
    background-color: var(--feedback-bg);
    border-top: 4px solid var(--primary);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.05);
    margin-top: clamp(5px, 2vh, 20px);
    animation: slideUp 0.3s ease-out;
}

.feedback-box.correct-border {
    border-color: var(--success);
}

.feedback-box.wrong-border {
    border-color: var(--error);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}



/* --- Tillegg for Rangering (Ranking) --- */

.game-board-ranking {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 20px;
}

.ranking-workspace {
    display: flex;
    flex-wrap: wrap;
    gap: 40px;
    justify-content: center;
    width: 100%;
}

/* Kolonnen med nummererte plasser */
.slots-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 300px;
}

.rank-slot {
    background-color: #ecf0f1;
    border: 2px dashed #bdc3c7;
    border-radius: 8px;
    padding: 10px;
    min-height: 60px;
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 40px;
    /* Plass til nummeret */
}

/* Nummerering (1, 2, 3...) */
.rank-slot::before {
    content: attr(data-index);
    position: absolute;
    left: 10px;
    font-weight: bold;
    color: #7f8c8d;
    font-size: 1.2rem;
}

.rank-slot.hovered {
    background-color: #d6eaf8;
    border-color: var(--primary);
}

/* Banken med brikker */
.pool-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 300px;
    padding: 20px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

/* Selve brikkene */
.rank-item {
    background-color: var(--card-bg);
    border: 2px solid var(--primary);
    color: var(--text);
    padding: 12px;
    border-radius: 6px;
    cursor: grab;
    font-weight: 600;
    text-align: center;
    user-select: none;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.rank-item:active {
    cursor: grabbing;
}

.rank-item.dragging {
    opacity: 0.5;
}

/* Feedback farger på slots */
.rank-slot.correct-slot {
    border-style: solid;
    border-color: var(--success);
    background-color: #e8f8f5;
}

.rank-slot.wrong-slot {
    border-style: solid;
    border-color: var(--error);
    background-color: #fadbd8;
}

.action-bar {
    margin-top: 20px;
}


/* Adminverktøy*/
#admin-debug-box {
    position: fixed;
    bottom: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: #00ff00;
    /* "Hacker" grønn for å skille seg ut */
    padding: 10px;
    border-radius: 5px;
    font-family: monospace;
    font-size: 12px;
    z-index: 10000;
    pointer-events: none;
    /* Klikk går gjennom boksen */
    max-width: 250px;
}

.admin-skip-btn {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: #ff9800;
    color: white;
    border: none;
    padding: 10px;
    border-radius: 5px;
    cursor: pointer;
    z-index: 10000;
}

/* Markerer korrekt svar i admin-modus */
.admin-correct-hint {
    border: 2px solid gold !important;
}

/* Responsivitet */
@media (max-width: 700px) {
    .ranking-workspace {
        flex-direction: column;
    }

    .slots-column,
    .pool-area {
        width: 100%;
        min-width: auto;
    }
}

/* --- Tillegg for Begreps-match (Drag & Drop) --- */

.game-board-match {
    display: flex;
    justify-content: center;
    gap: 40px;
    width: 100%;
    margin-top: 20px;
    flex-wrap: wrap;
}

.column {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 45%;
    min-width: 250px;
}

/* Brikkene */
.draggable,
.droppable {
    background-color: white;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    font-size: 1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80px;
    font-weight: 500;
}

/* De som skal dras (Begreper) */
.draggable {
    cursor: grab;
    background-color: #f8f9fa;
    color: var(--primary);
    border-color: var(--primary);
}

.draggable:active {
    cursor: grabbing;
}

.draggable.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

/* Mål-boksene (Forklaringer) */
.droppable {
    border-style: dashed;
    background-color: #fff;
}

.droppable.hovered {
    background-color: #eaf2f8;
    border-color: var(--primary);
    transform: scale(1.02);
}

/* Tilstander */
.matched {
    background-color: var(--success);
    color: white;
    border-color: #27ae60;
    border-style: solid;
    cursor: default;
    animation: pulse 0.3s ease-in-out;
}

.wrong-match {
    background-color: var(--error);
    color: white;
    animation: shake 0.4s;
}

/* Når et begrep er brukt opp, kan vi skjule det eller gjøre det inaktivt */
.draggable.hidden {
    visibility: hidden;
    opacity: 0;
}

/* Animasjoner */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

/* ------------------------------------------------------------------ */
/*  Daily Streak Display                                                */
/* ------------------------------------------------------------------ */

.streak-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.92rem;
    transition: background 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
    user-select: none;
    justify-content: center;
    cursor: pointer;
}

.streak-fire {
    font-size: 1.3rem;
    display: inline-block;
    transition: filter 0.3s ease;
}

.streak-inactive {
    background: #f1f5f9;
    color: #94a3b8;
    border: 1px solid #e2e8f0;
}

.streak-inactive .streak-fire {
    filter: grayscale(1) opacity(0.5);
}

.streak-active {
    background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
    color: #c2410c;
    border: 1px solid #fed7aa;
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.2);
    animation: streak-pulse 1.8s ease-in-out infinite;
}

.streak-active .streak-fire {
    filter: none;
}

.streak-burst {
    animation: streak-burst 350ms ease-out forwards !important;
}

.streak-click-pop {
    animation: streak-click-pop 180ms ease-out;
}

body.dark-mode .streak-inactive {
    background: #1e293b;
    color: #475569;
    border-color: #334155;
}

body.dark-mode .streak-active {
    background: linear-gradient(135deg, #431407 0%, #7c2d12 100%);
    color: #fdba74;
    border-color: #c2410c;
}

@keyframes streak-pulse {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.04); }
}

@keyframes streak-burst {
    0%   { transform: scale(1); }
    55%  { transform: scale(1.18); }
    100% { transform: scale(1); }
}

@keyframes streak-click-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.06); }
    100% { transform: scale(1); }
}

/* Mobil */
@media (max-width: 700px) {
    .game-board-match {
        flex-direction: column;
        align-items: center;
    }

    .column {
        width: 100%;
    }
}

/* Container for hele quizen */
.quiz-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Hovedoppsettet */
.quiz-layout {
    display: flex;
    flex-direction: column;
    gap: 30px;
    max-width: 900px;
    margin: 40px auto;
}

/* Spørsmålsboksen øverst */
.question-container {
    background: var(--box-bg);
    border: 2px solid var(--border-color);
    padding: clamp(10px, 2vh, 30px);
    width: 100%;
    box-sizing: border-box;
    align-items: center; /* Sentrerer alt innhold (bilde + tekst) */
    text-align: center;
    min-height: fit-content;
}

/* 2x2 Rutenett for knappene */
.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* To kolonner */
    gap: clamp(0.8rem, 20px, 30px);
}


/* Bunnseksjonen */
.quiz-footer {
    display: flex;
    justify-content: space-between;
    /* Forklaring venstre, knapp høyre */
    align-items: flex-end;
    margin-top: 20px;
}

.explanation-box {
    background: #f4f4f4;
    border: 2px solid #333;
    padding: 15px;
    width: 65%;
    /* Tar opp mesteparten av plassen til venstre */
    min-height: 60px;
}

/* Definer en ny stil for Neste-knappen */
#next-btn {
    background-color: #4a90e2;
    /* En tydelig blåfarge som skiller seg ut */
    color: white;
    font-weight: bold;
    border: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease;
    animation: pulse-animation 2s infinite;
    /* Legger til pulsering */
}

#next-btn:hover {
    background-color: #357abd;
    transform: scale(1.02);
}

/* Pulseringseffekten */
@keyframes pulse-animation {
    0% {
        box-shadow: 0 0 0 0px rgba(74, 144, 226, 0.7);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(74, 144, 226, 0);
    }

    100% {
        box-shadow: 0 0 0 0px rgba(74, 144, 226, 0);
    }
}


/* --- Specific updates for #feedback-box layout (Side-by-Side) --- */

#feedback-box {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    /* Remove padding to allow button full height/touch edges */
    overflow: hidden;
    /* Keep border radius */
}

/* Tvinger MathJax til å oppføre seg som vanlig tekst */
mjx-container {
    display: inline-block !important;
    margin: 0 5px !important;
    vertical-align: middle !important;
    max-width: 100% !important;
    overflow-x: visible;
    overflow-y: visible;
    font-size: clamp(1rem, 3vh, 1.4rem) !important;
    font-family: inherit !important;
    color: inherit !important;
}

mjx-mo {
    margin-left: 0.2em !important;
    margin-right: 0.2em !important;
}

.mjx-chtml {
    white-space: normal !important;
    line-height: 1.5;
}

#feedback-box #feedback-text {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: clamp(10px, 2vh, 20px);
    /* Add padding back to text
    display: flex;*/
    display: block;        /* ENDRET fra flex: nå flyter tekst og matte sammen */
    align-items: center;
    /* Vertically center text */
    line-height: 1.6;
    /* Anbefalt: gir plass til høye mattetegn (som brøker) */
    box-sizing: border-box;
    overflow-wrap: break-word;
    hyphens: auto;
    word-break: break-word;
    font-size: clamp(0.8rem, 2.5vw, 1.1rem);
}

#feedback-box #next-btn {
    width: 100%;
    margin: 0;
    border-radius: 0;
    /* Remove radius to fit corner */
    height: auto;
    /* Flex stretch fills height */
    display: flex;
    /* For centering content */
    align-items: center;
    justify-content: center;
    padding: clamp(12px, 2vw, 15px) clamp(15px, 3vw, 20px);
    order: -1;
    /* Move to top of flex container */
    font-size: clamp(0.9rem, 2vh, 1.5rem);
}

/* Handle hidden state explicitly to avoid flex overriding it */
#feedback-box #next-btn.hidden {
    display: none;
}

.ai-btn {
    width: 100%;
    border: 1px solid #3f4b5f;
    border-radius: 10px;
    padding: 8px 14px;
    background: #162131;
    color: #e8eef8;
    font-size: clamp(0.8rem, 1.5vh, 1.6rem);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

/* Keep feedback action buttons on one row with predictable sizing. */
#feedback-text .feedback-action-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

#feedback-text .feedback-action-row .ai-btn {
    flex: 1;
    width: auto;
    min-width: 0;
}

#feedback-text .feedback-action-row .save-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Standard tilstand */
.bookmark-btn {
    padding: 8px 14px;
    border-radius: 4px;
    border: 1px solid #ccc;
    cursor: pointer;
    font-size: clamp(0.8rem, 1.5vh, 1.6rem);
    font-weight: 500;
    transition: all 0.3s ease;
    background-color: transparent;
    color: #333;
}

/* Tilstand når knappen er aktiv/lagret */
.bookmark-btn.is-saved {
    background-color: #10b981;
    color: white;
    border-color: #059669;
}

@media (max-width: 600px) {
    #feedback-text .feedback-action-row {
        gap: 8px;
    }

    #feedback-text .feedback-action-row .ai-btn {
        flex: 1 1 auto;
        min-width: 0;
    }

    #feedback-text .feedback-action-row .bookmark-btn {
        flex: 0 1 120px;
        min-width: 100px;
        white-space: normal;
        line-height: 1.2;
        padding: 8px 10px;
    }
}

@media (max-width: 300px) {
    #feedback-text .feedback-action-row {
        flex-direction: column;
        align-items: stretch;
    }

    #feedback-text .feedback-action-row .ai-btn,
    #feedback-text .feedback-action-row .bookmark-btn {
        width: 100%;
        min-width: 0;
    }
}

.ai-btn:hover {
    background: #1f3047;
    border-color: #5f7390;
    transform: translateY(-1px);
}

@media (max-height: 600px) {
    .main-container {
        gap: 4px;
        padding: 5px;
        justify-content: flex-start;
    }

    header {
        margin-bottom: 6px;
    }

    h1,
    h2 {
        font-size: clamp(1rem, 3.2vh, 1.35rem) !important;
        line-height: 1.2;
    }

    .game-board,
    .game-board-quiz {
        gap: 8px;
    }

    .question-container {
        padding: clamp(10px, 2vh, 24px);
    }

    #question-text {
        font-size: clamp(0.95rem, 3vh, 1.15rem) !important;
        margin: 0;
        line-height: 1.25;
    }

    .options-grid {
        gap: clamp(5px, 2vh, 15px);
    }

    #next-btn {
        padding: clamp(0.85rem, 2.4vh, 1rem) !important;
        font-size: clamp(0.85rem, 2.4vh, 1rem) !important;
    }

    .ai-btn {
        padding: 6px 10px;
        font-size: clamp(0.75rem, 2vw, 0.9rem);
    }
}

/* --- Toast Message Notification --- */
.toast-message {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: rgba(30, 30, 30, 0.92);
    color: #ffffff;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 5000;
    animation: slideUpFadeIn 0.3s ease-out, fadeOut 0.5s ease-in 2.5s;
    pointer-events: none;
}

.toast-message.toast-actionable {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: min(92vw, 340px);
    justify-content: space-between;
    pointer-events: auto;
    animation: slideUpFadeIn 0.3s ease-out;
}

.toast-action-btn {
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
}

.toast-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes slideUpFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* --- Scoreboard Redesign --- */
.scoreboard-modal {
    /*width: 90%;*/
    max-width: 95vw;
    height: 95vh;
    display: flex;
    flex-direction: column;
    padding: 0 !important; /* Override standard modal padding */
    overflow: hidden;
    overflow-x: hidden;
    background-color: #f8f9fa;
}

.scoreboard-header {
    background-color: white;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.scoreboard-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

/* Close/neutral buttons in the scoreboard header need an explicit colour;
   without a colour class (.blue/.red/.green) the background would be
   transparent/browser-default and nearly invisible. */
.scoreboard-actions .btn:not(.blue):not(.red):not(.green):not(.yellow) {
    background-color: #4b5563;
    color: #fff;
}
body.dark-mode .scoreboard-actions .btn:not(.blue):not(.red):not(.green):not(.yellow) {
    background-color: #374151;
    color: #f3f4f6;
}

.scoreboard-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.scoreboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
    align-items: start;
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    overflow-x: hidden;
}

.score-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: transform 0.2s;
}

.score-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.score-card-details-toggle {
    margin-top: 12px;
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    color: #1e3a8a;
    font-size: 0.84rem;
    font-weight: 700;
    padding: 8px 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.score-card-details-toggle:hover {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

.score-card-details-toggle:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

.score-card-details {
    display: none;
    overflow: hidden;
    opacity: 0;
    max-height: 0;
    margin-top: 0;
    transition: max-height 0.3s ease, opacity 0.25s ease, margin-top 0.25s ease;
}

.score-card-details.is-expanded {
    display: block;
    opacity: 1;
    max-height: 520px;
    margin-top: 12px;
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.score-badge {
    background-color: #eee;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.85rem;
}

.score-badge.high { background-color: #d1fae5; color: #065f46; }
.score-badge.med { background-color: #fef3c7; color: #92400e; }
.score-badge.low { background-color: #fee2e2; color: #991b1b; }

.card-date {
    font-size: 0.8rem;
    color: #999;
}

.card-title {
    font-size: 1.1rem;
    font-weight: bold;
    color: #333;
    margin: 0;
}

.card-meta {
    font-size: 0.9rem;
    color: #666;
    display: flex;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid #f9f9f9;
}

/* --- Settings Modal --- */
#settings-modal {
    z-index: 120;
}

.settings-modal-content {
    width: min(92vw, 560px);
    text-align: left;
    max-height: 90vh;
    overflow-y: auto;
}

.settings-modal-content h2 {
    margin-bottom: 14px;
}

.settings-sections-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.settings-section {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #f8fafc;
    padding: 12px;
}

.settings-row {
    margin-top: 14px;
}

.settings-label {
    display: block;
    font-weight: 700;
    margin-bottom: 8px;
    color: #374151;
}

.settings-select {
    width: 100%;
    min-height: auto;
    padding: 10px;
}

.settings-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px;
    background: #f9fafb;
}

.settings-toggle-row .settings-label {
    margin-bottom: 0;
    font-weight: 600;
    line-height: 1.35;
}

.switch {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 32px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #d1d5db;
    border-radius: 999px;
    transition: 0.2s ease;
}

.slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 4px;
    top: 4px;
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: 0.2s ease;
}

.switch input:checked + .slider {
    background-color: #22c55e;
}

.switch input:checked + .slider:before {
    transform: translateX(24px);
}

.switch input:focus + .slider {
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
}

@media (min-width: 801px) and (min-height: 501px) {
    .settings-modal-content {
        width: min(95vw, 860px);
    }

    .settings-sections-grid {
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }
}

@media (max-height: 600px) {
    .settings-section {
        padding: 8px;
    }

    .settings-row {
        margin-top: 10px;
    }

    .settings-label {
        font-size: 0.85rem;
        margin-bottom: 6px;
    }

    .settings-select {
        padding: 8px;
        font-size: 0.9rem;
    }

    .switch {
        width: 50px;
        height: 28px;
    }

    .slider:before {
        width: 20px;
        height: 20px;
        left: 4px;
        top: 4px;
    }

    .switch input:checked + .slider:before {
        transform: translateX(22px);
    }

    #setting-sfx-volume,
    #setting-music-volume {
        height: 18px;
    }
}

@media (max-width: 600px) {
    .settings-toggle-row {
        align-items: center;
    }

    .switch {
        width: 62px;
        height: 36px;
    }

    .slider:before {
        width: 28px;
        height: 28px;
    }

    .switch input:checked + .slider:before {
        transform: translateX(26px);
    }
}

@media (max-width: 800px) {
    .settings-sections-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Repetition Overlay --- */
#repetition-overlay .modal {
    border: 3px solid var(--primary);
    background: #fdfdfd;
}
/* Spesialtilpasning for lave skjermer (f.eks. bærbare PC-er eller små vinduer) */
@media (max-height: 780px) {
    .main-container {
        padding: 10px;
        gap: clamp(1px, 1.5vw, 15px);
        justify-content: space-evenly;
    }

    mjx-container {
    font-size: clamp(0.8rem, 3vh, 1.2rem);
    }

    .game-board {
        justify-content: space-evenly;
        gap: clamp(8px, 2vw, 15px);
    }

    header {
        margin-bottom: 5px;
    }

    h1 {
        font-size: 1.2rem !important;
        /* Krymper tittelen */
    }

    .question-card {
        padding: 2vh 20px !important;
        margin-bottom: 10px !important;
    }

    #question-text {
        /* Balanced typography for better readability */
        font-size: clamp(0.8rem, 5vh, 1rem) !important;
        line-height: 1.5;
    }

    .btn {
        font-size: clamp(0.8rem, 2vh, 1rem)
    }

    .options-grid {
        display: flex;
        flex-wrap: wrap;
        /* Dette er nøkkelen! */
        gap: clamp(8px, 2vw, 15px);
        width: 100%;
        flex-direction: column;
        /*flex-grow: 1;*/
    }

    .option-btn {
        /*padding: 8px 12px !important;
        font-size: clamp(0.8rem, 2vh, 1.3rem) !important;
        min-height: 60px !important;*/
        /* flex: 1 1 200px; betyr:
               - 1: Grow (ta så mye plass du kan)
               - 1: Shrink (krymp hvis du må)
               - 200px: "Knekkpunktet" – hvis det er mindre enn 200px tilgjengelig per knapp, 
                 hopper de ned på hver sin linje.
            */
        font-size: clamp(0.8rem, 1rem, 1.3rem) !important;
        flex: 1 1 calc(50% - 12px);
        min-width: 130px;
        /*gap: clamp(0.8rem, 1rem, 1.3rem);*/
        /* Juster denne verdien etter hvor lang teksten din er */
        font-weight: 200;
        /* Resten av din eksisterende styling */
        min-height: 12vh;
        display: flex;
        align-items: center;
        justify-content: center;
        white-space: normal !important;
    }

    .option-btn b {
    font-weight: 700 !important; 
    display: inline-block; /* Gjør at margin faktisk fungerer stabilt */
    margin-left:0.4vw;
    margin-right: 0.4vw;
    }

    .option-btn var {
    font-weight: 700 !important; 
    display: inline-block; /* Gjør at margin faktisk fungerer stabilt */
    margin-left:0.4vw;
    margin-right: 0.4vw;
    }

    .stats-bar {
        font-size: 0.9rem !important;
        margin-top: 5px;
    }
}

/* Mobil-tilpasning */
@media (max-width: 600px) {
    .options-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        /* 1 kolonne på mobil */
        gap: clamp(8px, 2vw, 15px);
        width: 100%;
    }
    #quiz-game-content.has-image #game-title,
    #quiz-game-content.has-image #quiz-title {
        display: none !important;
    }

        /* BUTTON EXPANSION - fill entire grid cell */
    .option-btn {
        padding: clamp(8px, 1.5vh, 15px) 10px;
        font-size: clamp(0.6rem, 0.8rem, 1.2rem) !important;
        min-height: 10vh;
        line-height: 1.2;
        font-weight: 200;
    }

    .option-btn mjx-math {
    font-size: clamp(0.6rem, 1rem, 1.1rem) !important;
    white-space: normal !important;
    }

    #game-title {
        font-size: clamp(1.3rem, 5vw, 1.8rem);
        margin-bottom: 10px;
    }

    .question-container {
        padding: clamp(8px, 2vw, 20px);
        background: #e2f189;
    }

    .question-box {
        padding: clamp(15px, 3vw, 20px);
        margin-bottom: 15px;
    }

    #feedback-box {
        margin-top: 15px;
        border-radius: 8px;
    }

    #feedback-box #feedback-text {
        padding: clamp(12px, 3vw, 15px);
        min-height: auto;
    }

    #feedback-box #next-btn {
        padding: clamp(10px, 2vw, 12px) clamp(15px, 3vw, 20px);
        font-size: clamp(0.9rem, 2.5vw, 1rem);
    }

    .progress-section {
        margin-bottom: 15px;
    }

    header {
        margin-bottom: 15px;
    }

    .scoreboard-content {
        padding: 2px;
    }

    .score-card {
        padding: 2px 5px;
        max-width: 100ch;
    }

    .scoreboard-actions {
        gap: 8px;
        align-items: center;
        justify-content: center;
    }

    .score-card-details.is-expanded {
        max-height: 640px;
    }
    
    .start-menu-header {
    margin-bottom: 5px;
    }
}

/* --- Scoreboard header: narrow phones (≤ 480px) --- */
@media (max-width: 480px) {
    .scoreboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 14px;
    }

    .scoreboard-actions {
        width: 100%;
        justify-content: flex-start;
        gap: 6px;
    }

    .scoreboard-actions .btn.small {
        font-size: 0.78rem;
        padding: 6px 11px;
    }
}

/* --- Mobile Landscape Mode Optimization --- */
@media (max-height: 500px) and (orientation: landscape) {
    /* Prevent scrolling and maximize container */
    body {
        overflow: hidden;
        padding: 3px;
        height: 100vh;
        display: flex;
        justify-content: center;
    }
    
    .main-container {
        padding: 5px;
        gap: 3px;
        width: 100%;
        max-width: none;
        height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    /* Hide non-essential elements */
    #game-title,
    h1,
    .stats-text,
    .subtitle {
        display: none;
    }
    
    /* Minimal header */
    header {
        margin-bottom: 3px;
        padding: 2px 5px;
        flex-shrink: 0;
    }
    
    /* Ultra-slim progress bar */
    .progress-section {
        margin-bottom: 3px;
    }
    
    .progress-track {
        height: 4px;
    }
    
    /* Scale up question box but keep it minimal */
    .question-box,
    .question-container {
        padding: 8px;
        margin-bottom: 5px;
        min-height: auto;
        max-height: none;
        border-radius: 6px;
        flex-shrink: 0;
    }
    
    #question-text {
        font-size: clamp(1.0rem, 5vh, 1.2rem);
        line-height: 1.3;
        margin: 0;
    }
    
    /* FULL HEIGHT GRID - expand to fill all available space */
    .options-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: 1fr 1fr !important;
        gap: 15px;
        margin-bottom: 5px;
        flex-grow: 1;
        height: auto;
        max-height: none;
        width: 100%;
        max-width: none;
    }
    
    /* BUTTON EXPANSION - fill entire grid cell */
    .option-btn {
        padding: 10px;
        font-size: clamp(1rem, 6vh, 1.5rem);
        min-height: auto;
        max-height: none;
        height: 100%;
        width: 100%;
        line-height: 1.3;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }
    
    /* Optimize feedback box */
    #feedback-box {
        position: relative;
        margin: 5px 0 0 0;
        border-radius: 6px;
        max-height: 25vh;
        overflow-y: auto;
        flex-shrink: 0;
    }
    
    #feedback-box #feedback-text {
        padding: 8px 10px;
        font-size: clamp(0.85rem, 2.5vh, 1rem);
        line-height: 1.3;
    }
    
    #feedback-box #next-btn {
        padding: 10px;
        font-size: clamp(0.9rem, 2.5vh, 1.1rem);
    }
    
    /* Minimize overlays */
    .overlay .modal {
        max-height: 90vh;
        overflow-y: auto;
        padding: 15px;
    }
    
    /* Compact main game board - fill all space */
    .game-board,
    .game-board-quiz {
        gap: 3px;
        flex-grow: 1;
        display: flex;
        flex-direction: column;
        height: auto;
        max-height: none;
    }
    
    /* Scale MathJax appropriately */
    mjx-container {
        font-size: clamp(0.9rem, 2vh, 1.2rem) !important;
    }

        /* Fjern scrollbar og tving MathJax til å krympe inni knappene */
        .option-btn mjx-container {
            overflow-x: visible !important;
            /* Fjerner scrollbar */
            max-width: 100% !important;
            display: inline-block !important;
        }
    
        /* Gjør fonten i knappene litt mindre på de minste skjermene */
        @media (max-width: 470px) {
            .option-btn {
                font-size: clamp(0.85rem, 3vw, 1rem) !important;
                padding: 12px 8px !important;
            }
        }
        
}

/* Welcome Overlay */
.welcome-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    /* Mørk bakgrunn som dekker alt */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    /* Høyere enn alt annet */
    transition: opacity 0.3s ease;
}

.welcome-modal {
    background: var(--box-bg, #1a1a1a);
    /* Bruk dine eksisterende CSS-variabler */
    border: 1px solid var(--accent-color, #3b82f6);
    padding: clamp(10px, 3vh, 30px);
    border-radius: 15px;
    max-width: 90vw;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    /* Lar deg scrolle hvis teksten er lang */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    font-size: clamp(0.8rem, 3vh, 1.5rem);
    line-height: 2;
}
.welcome-close-btn{
    background: rgba(0, 83, 192, 0.85);
}
.welcome-content {
    text-align: left;
    margin: 20px 0;
    line-height: 1.2;
}

/* Animasjon for fjerning */
.welcome-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.welcome-overlay.hidden {
    display: none !important;
}

.welcome-title {
    font-size: clamp(0.85rem, 2vh, 1rem);
    color: #1a1a1a;
    margin-bottom: clamp(10px, 2.2vh, 30px);
    text-align: center;
}

.welcome-content p {
    margin-bottom: 5px;
}

.welcome-content p:last-child {
    margin-bottom: 0;
}

/* Manual overlay – slightly wider modal and subheading styles */
.manual-modal {
    max-width: 95vw;
    text-align: left;
}

.manual-content h3 {
    font-size: 1rem;
    font-weight: 700;
    margin: 10px 0 4px;
    padding-bottom: 2px;
    border-bottom: 1px solid var(--accent-color, #3b82f6);
    color: var(--accent-color, #3b82f6);
    text-align: left;
}

.manual-content h3:first-child {
    margin-top: 0;
}

/* --- Short viewport optimization for desktop/laptop --- */
@media (max-height: 700px) and (min-width: 900px) {
    #quiz-game-content.has-image #game-title,
    #quiz-game-content.has-image #quiz-title,
    #quiz-game-content.has-image .stats-text {
        display: none !important;
    }

    #quiz-game-content.has-image .game-board {
        gap: 12px;
    }

    #quiz-game-content.has-image #question-container,
    #quiz-game-content.has-image .question-container {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: clamp(0.4rem, 1vh, 1.5rem);
        flex-wrap: wrap;
        padding: 12px;
    }

    #quiz-game-content.has-image #question-container #shared-context-box,
    #quiz-game-content.has-image #question-container #question-subcategory-label,
    #quiz-game-content.has-image .question-container #shared-context-box,
    #quiz-game-content.has-image .question-container #question-subcategory-label {
        flex: 0 0 100%;
    }

    #quiz-game-content.has-image #question-container #question-image,
    #quiz-game-content.has-image .question-container #question-image,
    #quiz-game-content.has-image #question-container .question-image,
    #quiz-game-content.has-image .question-container .question-image {
        flex: 0 0 45%;
        width: 45%;
        max-width: 50%;
        max-height: 10rem;
        margin: 0;
    }

    #quiz-game-content.has-image #question-container #question-text,
    #quiz-game-content.has-image .question-container #question-text {
        flex: 1 1 45%;
        margin: 0;
        text-align: left;
        line-height: 1.6;
    }

    #quiz-game-content.has-image #feedback-box {
        margin-top: 8px;
    }

}

/* --- Click-to-enlarge question image modal --- */
.question-image-clickable {
    cursor: zoom-in;
}

.image-modal {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.88);
    padding: 22px;
}

.image-modal.hidden {
    display: none !important;
}

.image-modal-content {
    position: relative;
    width: min(96vw, 1300px);
    max-height: 94vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.5);
    object-fit: contain;
}

.image-modal-close {
    position: absolute;
    top: -14px;
    right: -14px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.9);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.image-modal-close:hover {
    background: rgba(31, 41, 55, 0.95);
}

/* =================================================================== */
/*  Universal Dashboard — Statistics Overview                           */
/*  Generated by StatsManager.generateDashboardHTML()                  */
/* =================================================================== */

/* ---- Dashboard color tokens — override to retheme ---- */
:root {
    --db-header-from:         #1e3a5f;
    --db-header-mid:          #2d6a9f;
    --db-header-to:           #1a5276;
    --db-header-text:         #ffffff;
    --db-bar-track-light:     rgba(255, 255, 255, 0.2);
    --db-bar-fill-from:       #34d399;
    --db-bar-fill-to:         #10b981;
    --db-activity-accent:     #0ea5e9;
    --db-activity-card-from:  #f0f9ff;
    --db-activity-card-to:    #ecfeff;
    --db-activity-title:      #0c4a6e;
    --db-activity-empty:      #cbd5e1;
    --db-activity-low:        #dc2626;
    --db-activity-med:        #d97706;
    --db-activity-high:       #16a34a;
    --db-category-track:      #e5e7eb;
    --db-streak-value-color:  #0c4a6e;
    --db-streak-label-color:  #64748b;
    --db-streak-divider:      rgba(14, 165, 233, 0.18);
}

/* --- Global Progress Header --- */
.db-progress-header {
    grid-column: 1;
    background: linear-gradient(
        135deg,
        var(--db-header-from) 0%,
        var(--db-header-mid) 60%,
        var(--db-header-to) 100%
    );
    border-radius: 14px;
    padding: 24px 28px;
    color: var(--db-header-text);
    box-shadow: 0 4px 24px rgba(30, 58, 95, 0.22);
    margin-bottom: 4px;
    text-align: left;
    font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
    
}

.db-progress-header__title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.db-progress-header__title i {
    font-size: 1.6rem;
    opacity: 0.9;
}

.db-progress-header__title h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.2px;
}

.db-progress-header__stats {
    display: flex;
    flex-direction: column;
    gap: 28px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.db-progress-header__stat-big {
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1;
}

.db-progress-header__stat-label {
    font-size: 0.8rem;
    opacity: 0.75;
    margin-top: 3px;
}

.db-progress-bar {
    height: 10px;
    width: 100%;
    border-radius: 999px;
    background: var(--db-bar-track-light);
    overflow: hidden;
}

.db-progress-bar__fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--db-bar-fill-from), var(--db-bar-fill-to));
    transition: width 400ms ease;
    /* width: set inline (data-driven) */
}

.db-progress-footer {
    margin-top: 8px;
    font-size: 0.8rem;
    opacity: 0.7;
}

/* --- Record Mode Card --- */
.db-record-card {
    border: 2px solid gold;
}

/* --- Streak + Activity Combined Card --- */
.db-combo-card {
    border-top: 3px solid var(--db-activity-accent);
    background: linear-gradient(
        135deg,
        var(--db-activity-card-from) 0%,
        var(--db-activity-card-to) 100%
    );
}

.db-combo-card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.db-combo-card__badge-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.db-combo-card__badge-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--db-streak-label-color);
    text-align: right;
    line-height: 1.15;
}

.db-combo-card .card-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--db-activity-title);
}

/* --- 4-stat streak row --- */
.db-streak-row {
    display: flex;
    justify-content: space-around;
    gap: 8px;
    flex-wrap: wrap;
    padding: 14px 0 16px;
    border-bottom: 1px solid var(--db-streak-divider);
    margin-bottom: 12px;
}

.db-streak-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 56px;
    text-align: center;
}

.db-streak-item__icon {
    font-size: 1.6rem;
    line-height: 1;
}

.db-streak-item__value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--db-streak-value-color);
    line-height: 1.1;
}

.db-streak-item__label {
    font-size: 0.7rem;
    color: var(--db-streak-label-color);
    font-weight: 600;
    white-space: nowrap;
}

/* --- 7-day bar chart --- */
.db-activity-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 6px;
    min-height: 80px;
    padding-top: 12px;
    position: relative;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: clip;
}

.db-activity-bar-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    /* Larger touch target for mobile */
    padding-top: 8px;
    padding-bottom: 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    border-radius: 6px;
    transition: background 120ms ease;
    position: relative;
    box-sizing: border-box;
}

.db-activity-bar-wrap:hover {
    background: rgba(14, 165, 233, 0.07);
}

.db-activity-bar {
    width: 100%;
    max-width: 22px;
    border-radius: 8px;
    transition: height 200ms ease;
    /* height & background: set inline (data-driven) */
}

.db-activity-label {
    font-size: 0.7rem;
    color: var(--db-streak-label-color);
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

/* --- Tap-to-view tooltip for mobile activity bars --- */
.db-activity-tap-tooltip {
    display: none;
    position: absolute;
    left: 50%;
    bottom: calc(100% + 6px);
    transform: translateX(-50%);
    z-index: 20;
    font-size: 0.74rem;
    font-weight: 800;
    color: #f8fafc;
    background: rgba(15, 23, 42, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-radius: 7px;
    padding: 8px 12px;
    width: auto;
    white-space: nowrap;
    text-align: center;
    line-height: 1.4;
    pointer-events: none;
    box-shadow: 0 8px 20px rgba(2, 6, 23, 0.22);
    box-sizing: border-box;
}

.db-activity-bar-wrap.is-active .db-activity-tap-tooltip {
    display: block;
}

/* Keep edge tooltips inside chart bounds so they are not cut off. */
.db-activity-bar-wrap:first-child .db-activity-tap-tooltip,
.db-activity-bar-wrap:nth-child(2) .db-activity-tap-tooltip {
    left: 0;
    transform: none;
}

.db-activity-bar-wrap:last-child .db-activity-tap-tooltip,
.db-activity-bar-wrap:nth-last-child(2) .db-activity-tap-tooltip {
    left: auto;
    right: 0;
    transform: none;
}

.db-activity-bar-wrap.is-active .db-activity-bar {
    outline: 2px solid #0ea5e9;
    outline-offset: 2px;
    filter: brightness(1.12);
}

/* --- Category card progress bar --- */
.db-category-track {
    height: 10px;
    width: 100%;
    border-radius: 999px;
    background: var(--db-category-track);
    overflow: hidden;
    margin-top: 12px;
    margin-bottom: 8px;
}

.db-category-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 260ms ease;
    /* width & background: set inline (data-driven) */
}

/* --- Card top row (replaces inline flex on .card-top) --- */
.db-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.db-card-top .card-title {
    margin: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* --- Full-width button utility --- */
.db-full-btn {
    width: 100%;
    margin-top: 15px;
}

/* --- Empty state --- */
.db-empty-state {
    grid-column: 1 / -1;
    padding: 18px;
    text-align: center;
}

.db-empty-state p {
    margin: 0;
}

/* Dark mode adjustments */
body.dark-mode .db-combo-card {
    background: linear-gradient(135deg, #0c1e2e 0%, #0e2233 100%);
}

body.dark-mode .db-streak-item__value {
    color: #93c5fd;
}

body.dark-mode .db-streak-item__label,
body.dark-mode .db-activity-label {
    color: #94a3b8;
}

body.dark-mode .db-activity-tap-tooltip {
    color: #f8fafc;
    background: rgba(2, 6, 23, 0.98);
    border-color: rgba(125, 211, 252, 0.42);
}

body.dark-mode .db-combo-card__badge-label {
    color: #94a3b8;
}

body.dark-mode .db-category-track {
    background: #374151;
}

@media (max-width: 480px) {
    .db-progress-header {
        padding: 16px 18px;
    }

    .db-progress-header__stat-big {
        font-size: 1.7rem;
    }

    .db-streak-item__value {
        font-size: 1.3rem;
    }

    .db-streak-item__icon {
        font-size: 1.3rem;
    }

    .db-streak-item__label {
        font-size: 0.65rem;
    }
}

/* --- Compact dashboard layout reorganization --- */
.db-top-section,
.db-middle-section,
.db-bottom-section,
.stats-lazy-sections,
#stats-lazy-sections {
    display: contents;
}

@media (min-width: 801px) {
    .scoreboard-grid {
        grid-auto-flow: row dense;
    }

    .db-progress-header,
    .db-combo-card {
        grid-column: span 1;
    }
}

@media (max-width: 800px) {
    .scoreboard-grid {
        grid-template-columns: minmax(0, 1fr);
        padding: 10px;
    }
}

.db-top-section .db-progress-header,
.db-top-section .db-combo-card {
    margin: 0;
    min-height: 0;
    max-height: 320px;
    overflow: hidden;
}

.db-top-section .db-progress-header {
    padding: 14px 16px;
    border-radius: 12px;
}

.db-top-section .db-progress-header__title {
    margin-bottom: 10px;
    gap: 8px;
}

.db-top-section .db-progress-header__title h2 {
    font-size: 1.02rem;
}

.db-top-section .db-progress-header__title i {
    font-size: 1.15rem;
}

.db-top-section .db-progress-header__stats {
    gap: 3vh 16px;
    margin-bottom: 10px;
}

.db-top-section .db-progress-header__stat-big {
    font-size: 1.4rem;
}

.db-top-section .db-progress-header__stat-label {
    font-size: 0.72rem;
    margin-top: 2px;
}

.db-top-section .db-progress-footer {
    margin-top: 6px;
    font-size: 0.72rem;
}

.db-top-section .db-combo-card {
    padding: 12px 14px;
    border-radius: 12px;
}

.db-top-section .db-combo-card__header {
    margin-bottom: 6px;
}

.db-top-section .db-combo-card__badge-label {
    font-size: 0.6rem;
}

.db-top-section .db-combo-card .card-title {
    font-size: 0.95rem;
}

.db-top-section .db-streak-row {
    padding: 8px 0 8px;
    margin-bottom: 8px;
    gap: 4px;
}

.db-top-section .db-streak-item {
    min-width: 48px;
    gap: 2px;
}

.db-top-section .db-streak-item__icon {
    font-size: 1rem;
}

.db-top-section .db-streak-item__value {
    font-size: 1.1rem;
    line-height: 1;
}

.db-top-section .db-streak-item__label {
    font-size: 0.62rem;
}

.db-top-section .db-activity-chart {
    min-height: 52px;
    gap: 4px;
    padding-top: 6px;
}

.db-top-section .db-activity-bar-wrap {
    gap: 3px;
}

.db-top-section .db-activity-bar {
    max-width: 10px;
    border-radius: 5px;
}

.db-top-section .db-activity-label {
    font-size: 0.58rem;
}

.db-top-section .db-activity-tap-tooltip {
    font-size: 0.6rem;
    padding: 1px 5px;
}

.db-compact-meta {
    margin-top: 6px;
    padding-top: 8px;
}

.db-meta-card__rows {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.db-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.88rem;
    color: #475569;
}

.db-meta-row strong {
    font-size: 0.95rem;
    color: #0f172a;
}

body.dark-mode .db-meta-row {
    color: #cbd5e1;
}

body.dark-mode .db-meta-row strong {
    color: #e2e8f0;
}

@media (max-width: 900px) {
    .db-top-section {
        grid-template-columns: 1fr;
    }

    .db-top-section .db-progress-header,
    .db-top-section .db-combo-card {
        max-height: none;
    }
}