/* ===== RESET & BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    font-family: Arial, Helvetica, sans-serif !important;
    display: flex;
    flex-direction: column;
    /* Stabler formula-bar øverst og main under */
    height: 100vh;
    margin: 0;
    overflow: hidden;
    background: linear-gradient(135deg, #0f0f0f 0%, #1a1a1a 50%, #0f0f0f 100%);
    color: #fff;
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    /* Tvinger elementene i en loddrett kø */
    overflow: hidden;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* ===== WELCOME OVERLAY (VERSION-CONTROLLED) ===== */
.welcome-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    pointer-events: auto;
    animation: fadeIn 0.3s ease;
}

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

.welcome-overlay.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

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

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

.welcome-modal {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    /*max-width: 500px;*/
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

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

.welcome-title {
    font-size: 28px;
    color: #1a1a1a;
    margin-bottom: 24px;
    text-align: center;
}

.welcome-content {
    color: #333;
    line-height: 1.6;
    margin-bottom: 24px;
    font-size: 14px;
}

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

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

.welcome-checkbox {
    display: flex;
    align-items: center;
    margin-bottom: 24px;
    gap: 8px;
}

.welcome-checkbox input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
    accent-color: #3498db;
}

.welcome-checkbox label {
    color: #333;
    cursor: pointer;
    font-size: 14px;
    user-select: none;
}

.welcome-close-btn {
    width: 100%;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.welcome-close-btn:hover {
    background: linear-gradient(135deg, #2980b9, #1e5a7a);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.welcome-close-btn:active {
    transform: translateY(0);
}

/* ===== BACK TO MENU BUTTON ===== */
.btn-back-to-menu {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    font-weight: 600;
    background: #34495e;
    color: #ecf0f1;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    border-bottom: 2px solid rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    margin-bottom: 8px;
}

.btn-back-to-menu:hover {
    background: #2c3e50;
    transform: translateY(-2px);
    border-bottom: 2px solid rgba(0, 0, 0, 0.3);
}

.btn-back-to-menu:active {
    transform: translateY(0);
    border-bottom: 2px solid rgba(0, 0, 0, 0.2);
}

/* Mobile responsive adjustments */
@media (max-width: 600px) {
    .welcome-modal {
        padding: 30px 20px;
        max-width: 95%;
        border-radius: 8px;
    }
    
    .welcome-title {
        font-size: 22px;
        margin-bottom: 20px;
    }
    
    .welcome-content {
        font-size: 13px;
        line-height: 1.5;
    }
    
    .welcome-close-btn {
        padding: 10px 20px;
        font-size: 14px;
    }
}

/* ===== SETTINGS MODAL ===== */
.settings-overlay {
    align-items: flex-start;
    padding: 10px;
}

.settings-modal {
    margin-top: 10px;
    margin-bottom: 10px;
    max-height: calc(100vh - 20px);
    display: flex;
    flex-direction: column;
}

.settings-header {
    position: sticky;
    top: 0;
    background: #141414;
    z-index: 10;
    /* VIKTIG: Gi headeren nøyaktig samme farge som modal-bakgrunnen */
    background-color: #1a1a1a;
    /* Sørger for at den har samme farge som modalen */
    /* Skap et klart skille mellom header og resten */
    border-bottom: 1px solid #333;
    padding: 15px 20px;
    /* Dette sørger for at den legger seg pent på toppen */
    display: flex;
    justify-content: space-between;
    align-items: center;
    /*padding-bottom: 10px;
        margin-bottom: 10px;
        border-bottom: 1px solid #2a2a2a;
        flex-wrap: wrap;
        gap: 8px;*/
}

.settings-close-btn {
    flex-shrink: 0;
}

.settings-content {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-top: 10px;
    /* Gir litt avstand fra den sticky headeren */
}



/* ===== CALCULATOR WRAPPER ===== */
#calculator-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
    /* Fyller 100% av det #main-container gir den */
    overflow: hidden;
}

/* ===== FORMULA BAR ===== */
.formula-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    flex-wrap: wrap !important;
    gap: 8px;

    /* Endre fra 8vh til auto/min-height */
    height: auto !important;
    min-height: 65px;

    /* Viktig for å hindre overlapp: */
    position: relative;
    clear: both;
    margin-top: 5px;

    padding: 10px 5px;
    background: #222;
    border: 2px solid #333;
    overflow-x: hidden;
    overflow-y: visible;
    white-space: normal;
    z-index: 10;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

.formula-bar::-webkit-scrollbar {
    height: 6px;
}

.formula-bar::-webkit-scrollbar-track {
    background: #222;
    border-radius: 3px;
}

.formula-bar::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

.formula-bar::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Hide formula bar when marked as hidden (Level 3+) */
.formula-bar.hidden {
    display: none !important;
}

.formula-btn {
    /* 1. Utseende (Beholdes som før) */
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border: 1px solid #444;
    border-radius: 6px;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.1);

    /* 2. Tekst-kontroll (Viktig for å hindre utflod) */
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 100;
    /* Vi senker maks-størrelsen litt og bruker en mindre vw-verdi */
    font-size: clamp(0.6rem, 2vw, 1.0rem) !important;
    white-space: nowrap;
    user-select: none;

    /* 3. Layout-sperrer */
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 0 auto !important;
    width: auto;
    overflow: hidden;
    /* Hindrer innhold i å stikke ut */
    text-overflow: ellipsis;
    /* Legger til ... hvis det mot formodning ikke går */
    min-width: 0;
    /* Tillater knappen å krympe under sitt eget innhold */
    height: 100%;
    padding: 2px 2px;
    box-sizing: border-box;
}

/* Hover og Active effekter */
.formula-btn:hover {
    background: linear-gradient(145deg, #454545, #353535);
    transform: translateY(-1px);
}

.formula-btn:active {
    transform: translateY(1px);
}

/* --- BRØK-LOGIKK --- */
.formula-btn .fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 4px;
    font-size: 0.8em !important;
    /*font-size: clamp(0.5rem, 1.5vw, 1.2rem) !important;*/
    /* Litt mindre for å sikre plass vertikalt */
    flex-shrink: 1;
    /* Lar brøken krympe hvis knappen blir smal */
    min-width: 0;
}

/* Vi fjerner clamp herfra så den arver fra .fraction! */
.formula-btn .numerator,
.formula-btn .denominator,
.formula-btn .fraction-numerator,
.formula-btn .fraction-denominator {
    padding: 0 2px;
    /*font-size: inherit !important;*/
    font-size: 1em;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
}

.formula-btn .fraction-line {
    width: 100%;
    height: 1.5px;
    background: #ffffff;
    margin: 1px 0;
    flex-shrink: 0;
}

/* Ensure all children inherit white color */
.formula-btn *,
.formula-btn div,
.formula-btn span,
.formula-btn .placeholder {
    color: #ffffff;
}

.formula-icon {
    width: 18px;
    height: 18px;
    color: currentColor;
    flex-shrink: 0;
}

/* ===== FORMULA HINT CONTAINER (Level 3 Practice Mode) ===== */
.formula-hint-container {
    display: flex !important;
    /* justify-content skal stå HER for å sentrere barna */
    justify-content: center !important;
    align-items: center !important;
    height: 40px !important;
    width: 100% !important;
    background: #1a1a1a;
    border: 1px solid #3366cc;
    border-radius: 4px;
    margin: 4px 0;
}

.formula-hint-container.hidden {
    display: none !important;
}

.formula-hint-content {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    /* Vi bruker 'gap' her for å styre avstanden mellom tekst og knapp */
    gap: 15px !important;
    /* Fjern justify-content herfra hvis den står der */
}

.formula-hint-text {
    font-size: 12px !important;
    white-space: nowrap !important;
    /* Holder teksten på én linje */
    overflow: hidden;
    text-overflow: ellipsis;
    /* Legger til ... hvis det blir for trangt */
}

.formula-show-btn {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.formula-show-btn:hover {
    background: linear-gradient(135deg, #2980b9, #1e5a7a);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.formula-show-btn:active {
    transform: translateY(0);
}
@media (max-width: 480px) {
    .mobile-hide {
        display: none;
    }

    /* Skjuler den lange teksten på mobil */
    .formula-hint-text {
        font-size: 12px;
    }
}

/* Mobile responsive for formula hint */
@media (max-width: 600px) {
    .formula-hint-container {
        min-height: 40px !important;
        /* Fast lav høyde */
        padding: 4px 10px !important;
    }

    .formula-hint-content {
        flex-direction: row !important;
        /* Tvinger rad istedenfor kolonne */
        justify-content: space-between !important;
        align-items: center !important;
        gap: 8px !important;
    }

    .formula-hint-text {
        font-size: 11px !important;
        /* Mindre tekst på mobil */
        margin: 0 !important;
        line-height: 1 !important;
    }

    .formula-show-btn {
        width: auto !important;
        /* Hindrer knappen i å bli full bredde */
        padding: 4px 8px !important;
        font-size: 11px !important;
        margin: 0 !important;
    }
}

/* Styling for selve knappen og visning i displayet */
.math-container {
    display: inline-flex;
    align-items: center;
}

.exponent,
.exponent-placeholder {
    font-size: 0.75em;
    vertical-align: super;
    position: relative;
    top: -0.5em;
    /* Juster denne for å få "år" i riktig høyde */
    margin-left: 2px;
}

/* Sørg for at den ser ut som en interaktiv placeholder */
.exponent-placeholder {
    background: rgba(52, 152, 219, 0.2);
    /* Lik farge som dine andre placeholders */
    border-radius: 3px;
    padding: 0 2px;
    cursor: pointer;
}

/* ===== MAIN CONTAINER ===== */
#main-container {
    flex: 0 1 auto;
    /* Desktop: side-by-side layout (75/25 split) */
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    height: 100vh;
    padding: 10px;
    gap: 0;
    width: 100%;
    min-height: 0;
    align-items: flex-start;
    box-sizing: border-box;
    overflow: hidden;
}

.calculator-column {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 0 0 60%;
    width: 60%;
    margin: 0 auto;
    box-sizing: border-box;
    min-width: 0;
    
    /*gap: 12px;
    flex: 3;
    min-width: 0;
    min-height: 0;*/
}

.calculator-column .formula-bar {
    width: 100%;
    margin-top: 0;
}

#task-display {
    display: block;
    /* Sikrer at den tar hele bredden og dytter ting ned */
    width: 100%;

    /* Juster høyden så den ikke blir for liten for teksten */
    height: auto;

    /* Fjern eventuell absolute/fixed posisjonering hvis du har det */
    position: relative !important;

    padding: 15px 5px !important;
    margin: 0 0 10px 0 !important;
    /* Margin i bunnen dytter formula-bar ned */

    font-size: clamp(1rem, 3.0vw, 1.4rem) !important;
    line-height: 1.1;
    width: 100%;
    margin: 0 !important;
    text-align: center;
}

/* Spesifikk justering for clickable-numbers inni displayet */
.clickable-number {
    font-size: inherit;
    /* Sørger for at tallene følger den nye store størrelsen */
    padding: 2px 4px;
}

/* ===== PAPER (HISTORY) ===== */
.paper {
    background: #fdfaf4;
    border: 2px solid #d6cbb7;
    border-radius: 0 0 15px 0;
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.35),
        inset 0 1px 2px rgba(255, 255, 255, 0.6);
    padding: 16px;
    flex: 0 0 40%;
    width: 40%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    color: #2b2b2b;
    border-left: none;
    border-top: none;
    flex-shrink: 0;
    align-self: stretch;
    min-height: 0;
    box-sizing: border-box;
    /*max-height: 45vh*/
}

.paper-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.paper-title {
    font-size: 18px;
    font-weight: 700;
    color: #4a3f35;
    letter-spacing: 0.5px;
}

.paper-clear {
    border: 2px solid #c9b89a;
    border-radius: 8px;
    padding: 6px 10px;
    background: #fff;
    color: #4a3f35;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
}

.paper-clear:hover {
    background: #fff6ea;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.paper-list {
    background: #fff;
    border: 2px solid #e0d5c4;
    border-radius: 10px;
    padding: 10px 12px;
    flex: 0 1 auto;
    max-height: 45vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.paper-line {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 6px 4px;
    border-bottom: 1px dashed #e3d7c6;
    font-family: 'Times New Roman', 'Cambria Math', 'Latin Modern Math', serif;
    font-size: 16px;
    position: relative;
}

.paper-line:last-child {
    border-bottom: none;
}

.paper-delete-btn {
    background: none;
    border: none;
    color: #c9a888;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.4;
    transition: all 0.15s ease;
    padding: 2px 4px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    user-select: none;
}

.paper-delete-btn:hover {
    opacity: 0.75;
    color: #a8896f;
}

.paper-delete-btn:active {
    opacity: 1;
}

.paper-line.paper-empty {
    grid-template-columns: 1fr;
    justify-items: center;
    opacity: 0.65;
    font-style: italic;
}

/* ===== OFFICIAL SOLUTION STYLING ===== */
.paper-line.official-solution {
    display: block;
    grid-template-columns: none;
    background: linear-gradient(135deg, #e3f4ff 0%, #d4ebf7 100%);
    border: 2px solid #90caf9;
    border-radius: 8px;
    padding: 16px;
    margin: 12px 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #1a1a1a;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.solution-header {
    font-size: 18px;
    font-weight: bold;
    color: #0d47a1;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #90caf9;
}

.solution-step {
    margin: 10px 0;
    padding: 8px 12px;
    background: rgb(255, 255, 255);
    border-left: 3px solid #42a5f5;
    border-radius: 4px;
}

.step-label {
    font-weight: bold;
    color: #1565c0;
    font-size: 14px;
    margin-bottom: 4px;
}

.step-content {
    color: #263238;
    font-size: 14px;
    line-height: 1.6;
}

.step-content strong {
    color: #0d47a1;
}

.solution-answer {
    margin-top: 16px;
    padding: 12px;
    background: rgba(76, 175, 79, 0.753);
    border: 2px solid #4caf50;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    color: #000000;
    text-align: center;
}

.solution-error {
    color: #c62828;
    font-style: italic;
    padding: 8px;
}

.paper-expression,
.paper-result,
.paper-equals {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
}

.paper-expression {
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 3px;
}

.paper-expression-content {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 3px;
    padding: 0;
    width: auto;
    min-width: 0;
    background: transparent;
}

.paper-result {
    justify-content: flex-start;
    font-weight: 700;
}

.paper-equals {
    font-weight: 700;
    opacity: 0.8;
}

/* Fraction style aligned with likningsapp */
.paper .fraction-display {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 2px;
}

.paper .fraction-display .fraction-line {
    height: 2px;
}

/* ===== CALCULATOR BODY ===== */
.calculator {
    background: linear-gradient(145deg, #2a2a2a 0%, #1e1e1e 100%);
    border-radius: 0 0 0 15px;
    padding: clamp(8px, 2vh, 15px);
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.8),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
    flex: 0 1 auto;
    
    border: 2px solid #333;
    border-top: none;
    display: flex;
    flex-direction: column;
    /*flex-grow: 1;        /* Dette tvinger kalkulatoren til å fylle bunnen */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    /*max-width: 800px; /* Valgfri begrensning så den ikke blir absurd bred */
    margin: 0 auto;  /* Sentrerer den horisontalt */
    margin-top: 10px;
    height: 100%;
}

/* ===== CALCULATOR HEADER ===== */
.calculator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 5px 10px;
}

.brand {
    font-size: 20px;
    font-weight: bold;
    color: #00d4ff;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.model {
    font-size: 12px;
    color: #888;
    letter-spacing: 1px;
}

.solar-panel {
    width: 50px;
    height: 8px;
    background: linear-gradient(
        90deg,
        #1a1a2e 0%, #1a1a2e 20%,
        #16213e 20%, #16213e 40%,
        #1a1a2e 40%, #1a1a2e 60%,
        #16213e 60%, #16213e 80%,
        #1a1a2e 80%, #1a1a2e 100%
    );
    border-radius: 2px;
}

/* ===== DISPLAY AREA ===== */
.display {
    background: #c5d1b7;
    background-color: #f4f4f4; /* Eller din farge */
    border-radius: 8px;
    padding: 1vh;
    margin-bottom: 10px;
    /*height: 12vh;*/
    min-height: 6em;
    max-height: 120px;
    box-shadow: 
        inset 0 2px 8px rgba(0, 0, 0, 0.3),
        0 1px 2px rgba(255, 255, 255, 0.1);
    border: 2px solid #555;
    justify-content: space-between;

    display: flex;
    flex-direction: column; /* Legger uttrykk og resultat over hverandre */
    justify-content: flex-end; /* Skyver teksten mot bunnen av displayet */
    align-items: flex-end; /* Høyrestiller tallene (standard for kalkulatorer) */

    overflow: hidden;  /* Hindrer at tekst flyter utenfor rammen */
    word-wrap: break-word; /* Knekker lange tallrekker */
    word-break: break-all;


}

/* ===== TOP CONTROLS ===== */
#top-controls {
    display: grid;
    grid-template-columns: 1fr 1.5fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
}

.utility-column {
    display: flex;
    flex-direction: row;
    gap: 8px;
}

.utility-column .btn {
    flex: 1;
    min-height: auto;
    padding: 6px 12px;
}

.display-expression {
    font-family: Arial, Helvetica, sans-serif;
    font-size: clamp(1rem, 3vh, 2rem);
    color: #000000;
    min-height: 1.5em;   /* Holder plassen selv når den er tom */
    width: 100%;
    text-align: right;
    /*direction: ltr;*/
    outline: none;    /* Fjerner blå ramme ved edit */
    overflow-y: visible;
    line-height: 1.8;
    align-items: flex-start;
    cursor: text;  /* Show text cursor across entire display width */
    padding-right: 15px;  /* 15px hitbox at the end for cursor placement */
    user-select: text;
    -webkit-user-select: text;
    
    word-wrap: break-word;
}

/* Hide cursor when child element has focus */
.display-expression.has-focused-child {
    caret-color: transparent;
}

.display-expression.has-focused-child * {
    caret-color: auto;
}

/* Selection highlight */
.display-expression::selection,
.display-expression *::selection {
    background: rgba(0, 122, 255, 0.3);
    color: #1a1a1a;
}

.fraction-numerator::selection,
.fraction-denominator::selection,
.sqrt-content::selection,
.power-base::selection,
.power-exponent::selection {
    background: rgba(0, 122, 255, 0.4);
}

.display-result {
    font-family: Arial, Helvetica, sans-serif;
    /*font-size: 2.5rem; /* Gjør resultatet større og tydeligere */
    font-size: clamp(1rem, 4vh, 8rem);
    font-weight: bold;
    color: #000;
    width: 100%;
    text-align: right;
    margin-top: auto;
    z-index: 10; /* Sikrer at den ligger "øverst" visuelt */
    font-weight: bold;
    word-break: break-all;
    font-family: 'Courier New', 'Consolas', 'Monaco', monospace;
    margin-top: 5px;
    box-sizing: border-box;
    /*line-height: 1;*/
    flex-shrink: 1;

    /*width: 100%;
    font-size: 3vh;
    */
    /* Tvinger elementet til å bruke all tilgjengelig bredde */
    /* Sikrer at padding ikke dytter tallet ut */
}

/* ===== NUMBER FLASH FEEDBACK ===== */
.number-flash {
    animation: flashEffect 0.15s ease-in-out;
}

@keyframes flashEffect {
    0% {
        background: transparent;
    }
    50% {
        background: rgba(0, 212, 170, 0.3);
    }
    100% {
        background: transparent;
    }
}

/* ===== ANSWER INPUT PULSE EFFECT ===== */
.answer-input-pulse {
    animation: answerPulseEffect 0.4s ease-out;
}

@keyframes answerPulseEffect {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 212, 170, 0.7);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 12px 4px rgba(0, 212, 170, 0.3);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 212, 170, 0);
        transform: scale(1);
    }
}

/* ===== TRANSFER PREVIEW HIGHLIGHT ===== */
.target-highlight {
    box-shadow: 
        inset 0 0 0 2px rgba(0, 212, 170, 0.6),
        0 0 0 3px rgba(0, 212, 170, 0.3),
        0 0 12px 2px rgba(0, 212, 170, 0.2);
    border-color: rgba(0, 212, 170, 0.6) !important;
}

.display-expression.target-highlight {
    background: rgba(0, 212, 170, 0.08);
    border: 2px solid rgba(0, 212, 170, 0.5);
}

/* ===== NEXT FIELD VISUAL HINT ===== */
.next-hint {
    background: rgba(52, 152, 219, 0.12);
    border: 1px dashed rgba(52, 152, 219, 0.5) !important;
    border-radius: 3px;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

/* ===== SMART JUMP HOVER PREVIEW ===== */
.jump-preview {
    background: rgba(52, 152, 219, 0.2);
    border: 2px solid rgba(52, 152, 219, 0.7) !important;
    border-radius: 3px;
    box-shadow: 0 0 8px rgba(52, 152, 219, 0.3);
    transition: all 0.15s ease;
}

/* ===== PAPER RESULT INTERACTIVE ===== */
.paper-result {
    cursor: pointer;
    transition: all 0.2s ease;
}

.paper-result:hover {
    color: #00d4aa;
}

/* ===== DISPLAY ELEMENTS ===== */
/* Justering for å utligne størrelsesforskjell i uttrykk */
.display-expression {
    display: flex;
    /*font-size: 1.5vh;*/
    align-items: center;
    gap: 4px;
    line-height: 1;
}

/* ===== OPERATOR SYMBOLS ===== */\n.operator-inline {
    color: #1a1a1a;
    font-weight: 500;
    padding: 0 2px;
    display: inline;
    user-select: none;
}

/* ===== VERTICAL FRACTION IN DISPLAY ===== */
.fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 4px;
    vertical-align: middle;
    position: relative;
}

.fraction-numerator {
    min-width: 18px;
    padding: 3px 8px;
    text-align: center;
    outline: none;
    /*font-size: 15px;*/
    /*font-size: 2.5vh;*/
    font-size: clamp(1rem, 2vh, 2rem);
    color: #1a1a1a;
    cursor: pointer;
    user-select: text;
    -webkit-user-select: text;
}

.fraction-numerator:focus {
    background: rgba(0, 122, 255, 0.2);
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

.fraction-numerator:empty::before {
    content: '□';
    color: #888;
}

.fraction-line {
    width: 100%;
    min-width: 18px;
    height: 2px;
    background: #1a1a1a;
    margin: 1px 0;
}

.fraction-denominator {
    min-width: 18px;
    padding: 3px 8px;
    text-align: center;
    outline: none;
    font-size: clamp(1rem, 2vh, 2rem);
    color: #1a1a1a;
    cursor: pointer;
    user-select: text;
    -webkit-user-select: text;
}

.fraction-denominator:focus {
    background: rgba(0, 122, 255, 0.2);
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

.fraction-denominator:empty::before {
    content: '□';
    color: #888;
}

/* ===== SIMPLIFIED FRACTION CLASSES (for formula bar templates) ===== */
.numerator {
    min-width: 18px;
    padding: 3px 8px;
    text-align: center;
    outline: none;
    font-size: clamp(1rem, 2vh, 2rem);
    color: #1a1a1a;
    cursor: pointer;
}

.numerator:focus {
    background: rgba(0, 122, 255, 0.2);
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

.numerator:empty::before {
    content: '□';
    color: #888;
}

.denominator {
    min-width: 18px;
    padding: 3px 8px;
    text-align: center;
    outline: none;
    font-size: clamp(1rem, 2vh, 2rem);
    color: #1a1a1a;
    cursor: pointer;
}

.denominator:focus {
    background: rgba(0, 122, 255, 0.2);
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

.denominator:empty::before {
    content: '□';
    color: #888;
}

/* ===== PLACEHOLDER SPANS ===== */
.placeholder {
    display: inline;
    outline: none;
    padding: 2px 4px;
    cursor: pointer;
    color: #1a1a1a;
    user-select: text;
    -webkit-user-select: text;
}

.placeholder:focus {
    background: rgba(0, 122, 255, 0.2);
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

/* ===== NESTED/INLINE FRACTION ===== */
.fraction-inline {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    font-size: 14px;
    margin: 0 2px;
    vertical-align: middle;
}

.fraction-nested {
    min-width: 15px;
    padding: 2px 8px;
    font-size: 13px;
}

/* ===== NESTED/INLINE SQRT ===== */
.sqrt-inline {
    display: inline-flex;
    align-items: center;
    font-size: 14px;
    margin: 0 2px;
    vertical-align: middle;
}

.sqrt-inline .sqrt-symbol {
    font-size: 18px;
    margin-right: 1px;
}

.sqrt-nested {
    min-width: 15px;
    padding: 3px 8px 0 8px;
    font-size: 13px;
}

/* ===== NESTED/INLINE POWER ===== */
.power-inline {
    display: inline-flex;
    align-items: flex-start;
    font-size: 14px;
    margin: 0 2px;
    vertical-align: middle;
}

.power-nested {
    min-width: 12px;
    padding: 2px 6px;
}

.power-nested.power-exponent {
    font-size: 11px;
    margin-top: -4px;
}

/* ===== SQRT DISPLAY ===== */
.sqrt {
    display: inline-flex;
    align-items: center;
    margin: 0 3px;
    vertical-align: middle;
}

.sqrt-symbol {
    font-size: 20px;
    font-weight: bold;
    margin-right: 2px;
    color: #1a1a1a;
    pointer-events: none;
}

.sqrt-content {
    border-top: 2px solid #1a1a1a;
    padding: 5px 10px 0 10px;
    min-width: 18px;
    outline: none;
    font-size: 15px;
    color: #1a1a1a;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
}

.sqrt-content:focus {
    background: rgba(0, 122, 255, 0.2);
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

.sqrt-content:empty::before {
    content: '□';
    color: #888;
}

/* ===== POWER DISPLAY ===== */
.power {
    display: inline-flex;
    align-items: flex-start;
    /*margin: 0 3px;*/
    vertical-align: middle;
}

.power-base {
    min-width: 18px;
    /*padding: 3px 8px;*/
    outline: none;
    /*font-size: 1rem;*/
    color: #1a1a1a;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
}

.power-base:focus {
    background: rgba(0, 122, 255, 0.2);
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

.power-base:empty::before {
    content: '□';
    color: #888;
}

.power-exponent {
    min-width: 14px;
    /*padding: 2px 7px;*/
    outline: none;
    font-size: 1rem;
    color: #1a1a1a;
    cursor: text;
    margin-left: -2px;
    margin-top: -5px;
    user-select: text;
    -webkit-user-select: text;
}

.power-exponent:focus {
    background: rgba(0, 122, 255, 0.2);
    border-radius: 3px;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

.power-exponent:empty::before {
    content: '□';
    color: #888;
    font-size: 11px;
}

/* ===== BUTTONS GRID ===== */
.buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(5, 1fr);
    grid-auto-rows: 1fr;
    gap: 0.5vh;
    flex: 1;
}

#calculator-grid {
    flex: 1;
    display: grid;
    grid-template-rows: repeat(5, 1fr);
    gap: 0.5vh;
}

.buttons button[onclick="deleteChar()"] {
    grid-column: span 1;
    background: #00a2ff;
    color: #ffffff;
}

.btn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border: 1px solid #444;
    border-radius: 6px;
    color: #fff;
    font-size: 2.2vh;
    padding: 0;
    cursor: pointer;
    transition: all 0.1s ease;
    font-weight: 500;
    box-shadow: 
        0 2px 6px rgba(0, 0, 0, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.1);
    font-family: 'Courier New', monospace;
    user-select: none;
    min-height: 0;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    background: linear-gradient(145deg, #454545, #353535);
    transform: translateY(-1px);
    box-shadow: 
        0 3px 8px rgba(0, 0, 0, 0.5),
        inset 0 1px 1px rgba(255, 255, 255, 0.15);
}

.btn:active {
    transform: translateY(1px);
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.4),
        inset 0 2px 3px rgba(0, 0, 0, 0.3);
}

/* ===== BUTTON TYPES ===== */
.btn.number {
    background: linear-gradient(145deg, #4a4a4a, #3a3a3a);
    color: #fff;
    font-size: 4.2vh;
    font-weight: 600;
}

.btn.number:hover {
    background: linear-gradient(145deg, #555, #454545);
}

.btn.operator {
    background: linear-gradient(145deg, #ff6b35, #f7931e);
    color: #000000;
    font-weight: bold;
    font-size: 4.2vh;
}

.btn.operator:hover {
    background: linear-gradient(145deg, #ff8555, #ffa03e);
}

.btn.function {
    background: linear-gradient(145deg, #555, #444);
    color: #8be3e9;
    font-weight: bold;
    font-size: clamp(0.8rem, 2.2vh, 1.4rem)
}

.btn.function:hover {
    background: linear-gradient(145deg, #666, #555);
}

.btn.function.active {
    background: linear-gradient(145deg, #00d4aa, #00a389);
    color: #fff;
    box-shadow: 
        0 2px 6px rgba(0, 212, 170, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

.btn.function.active:hover {
    background: linear-gradient(145deg, #00e4ba, #00b399);
}

/* ===== RESET BUTTON (NULLSTILL) STYLING ===== */
.btn.reset-btn {
    background: linear-gradient(100deg, #8B4513, #654321) !important;
    color: #f5f5f5 !important;
    font-weight: 700 !important;
}

.btn.reset-btn:hover {
    background: linear-gradient(145deg, #a0522d, #8B4513) !important;
    transform: translateY(-2px);
    box-shadow: 
        0 3px 8px rgba(139, 69, 19, 0.5),
        inset 0 1px 1px rgba(255, 255, 255, 0.2) !important;
}

.btn.reset-btn:active {
    transform: translateY(0px);
    box-shadow: 
        0 1px 2px rgba(139, 69, 19, 0.3),
        inset 0 1px 1px rgba(0, 0, 0, 0.3) !important;
}

.btn.special {
    background: linear-gradient(145deg, #4a5568, #3a4558);
    color: #a0d8ff;
    font-weight: bold;
}

.btn.special:hover {
    background: linear-gradient(145deg, #5a6678, #4a5568);
}

.btn.equals {
    background: linear-gradient(145deg, #00d4aa, #00a389);
    color: #fff;
    font-weight: bold;
    font-size: 2.2vh;
}

.btn.equals {
    grid-column: span 2;
}

.btn.equals:hover {
    background: linear-gradient(145deg, #00e4ba, #00b399);
}

/* ===== BUTTON ICONS ===== */
.btn-icon {
    height: 2.5vh;
    width: auto;
    color: currentColor;
    max-height: 100%;
    max-width: 100%;
}

.btn svg {
    height: 2.5vh;
    width: auto;
}

.btn-symbol {
    /*font-size: 20px;*/
    line-height: 1;
}

.level-label {
    margin-right: 0.3em;
}

/* ===== FRACTION BUTTON DISPLAY ===== */
.fraction-btn-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.frac-num {
    font-size: 14px;
    margin-bottom: 1px;
}

.frac-bar {
    width: 100%;
    height: 1.5px;
    background: currentColor;
    margin: 1px 0;
}

.frac-den {
    font-size: 14px;
    margin-top: 1px;
}

/* ===== ERROR STATE ===== */
.error {
    color: #ff3b30 !important;
    font-weight: bold;
}

/* ===== TOP CONTROL SECTION ===== */
.control-section {
    display: grid;
    grid-template-columns: 1fr 1.5fr 1fr;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
}

.control-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-btn {
    background: linear-gradient(145deg, #555, #444);
    border: 1px solid #444;
    border-radius: 6px;
    color: #00d4ff;
    font-size: 14px;
    font-weight: bold;
    padding: 12px 8px;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 
        0 2px 6px rgba(0, 0, 0, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.1);
    user-select: none;
    min-height: 42px;
}

.control-btn:hover {
    background: linear-gradient(145deg, #666, #555);
    transform: translateY(-1px);
    box-shadow: 
        0 3px 8px rgba(0, 0, 0, 0.5),
        inset 0 1px 1px rgba(255, 255, 255, 0.15);
}

.control-btn:active {
    transform: translateY(1px);
    box-shadow: 
        0 1px 4px rgba(0, 0, 0, 0.4),
        inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.placeholder-btn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    opacity: 0.5;
    cursor: default;
}

.placeholder-btn:hover {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    transform: none;
}

/* ===== DRAG AND DROP INDICATORS ===== */
.drop-zone-active {
    background: rgba(0, 122, 255, 0.15) !important;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.5) !important;
    transition: all 0.2s ease;
}

.insertion-indicator {
    position: absolute;
    width: 2px;
    height: 24px;
    background: #007aff;
    pointer-events: none;
    z-index: 1000;
    animation: blink 0.8s infinite;
    box-shadow: 0 0 4px rgba(0, 122, 255, 0.6);
}

@keyframes blink {
    0%, 49% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0.3;
    }
}

/* Highlight for nested contenteditable during drag */
.fraction-numerator.drop-zone-active,
.fraction-denominator.drop-zone-active,
.numerator.drop-zone-active,
.denominator.drop-zone-active,
.sqrt-content.drop-zone-active,
.power-base.drop-zone-active,
.power-exponent.drop-zone-active {
    background: rgba(0, 122, 255, 0.2) !important;
    border-radius: 3px;
}

/* ===== RESPONSIVE ===== */
/* Generell regel for små skjermer (både mobil og lav PC-skjerm) */
@media screen and (max-height: 775px) {
    /* 1. Skjul headeren helt */
    .calculator-header {
        display: none !important;
    }

    /* 2. Minimal padding på oppgaven */
    #task-display {
        padding: 10px 5px !important;
        /* Litt mindre minimumsstørrelse for å unngå horisontal scrolling på smale telefoner */
        font-size: clamp(1rem, 2.5vw, 1.2rem) !important;
    }

    /* 3. Krymp formel-knappene og innholdet */
    .formula-bar {
        height: auto;
        min-height: 4rem;
        gap: 3px;
        padding: 0.5em 0.8em;
    }

    .formula-btn {
        padding: 4px 6px;
        /*font-size: 0.8rem;*/
        min-height: 0; /* Fjerner sperren vi fant i stad */
    }

    /* Krymp brøker og tekst inni formel-knappene */
    .formula-btn .fraction {
        /*transform: scale(0.8); /* Skalerer ned brøker uten å ødelegge layout */
        font-size: 0.8em !important;
        margin: 0 2px;
    }
}

/* Treffer skjermer som er 1300px brede eller smalere, 
   ELLER skjermer som er veldig lave (typisk laptoper) */
@media screen and (max-width: 1250px),
screen and (max-height: 650px) {

    /* Her legger du justeringene dine, for eksempel: */
    .formula-bar {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            /*flex-wrap: wrap !important;*/
            /*gap: 8px;*/
    
            /* Endre fra 8vh til auto/min-height */
            height: auto !important;
            min-height: 65px;
    
            /* Viktig for å hindre overlapp: */
            position: relative;
            clear: both;
            margin-top: 5px;
    
            padding: 10px 5px;
            background: #222;
            border: 2px solid #333;
            overflow-x: hidden;
            overflow-y: visible;
            white-space: normal;
            z-index: 10;
            box-sizing: border-box;
            width: 100%;
            max-width: 100%;
        }

        .formula-btn {
        padding: 2px 0px;
        font-size: clamp(0.6rem, 1.1vw, 1.5rem) !important;
        /*min-height: 48px;*/
    }

    .formula-btn .fraction {
        /*transform: scale(0.9);*/
        /*transform-origin: center;*/
        /*font-size: 0.9em !important;*/
        margin: 0 2px !important;
    }

    .formula-btn .numerator,
    .formula-btn .denominator,
    .formula-btn .fraction-numerator,
    .formula-btn .fraction-denominator {
        padding: 1px 2px !important;
        font-size: inherit !important;
        /*font-size: 1.8em !important;*/
        line-height: 1.1 !important;
    }

    .formula-btn .placeholder {
        font-size: 2.8em !important;
    }
}

/* Ekstra aggressiv krymping for de aller minste skjermene */
@media screen and (max-height: 650px) {
    #task-container {
        margin: 2px 0;
    }
    
    .display-result {
        @media screen and (max-height: 650px) {
    #task-container {
        margin: 2px 0;
    }
    
    .display-result {
        /*font-size: 2.5vh;*/
        font-size: clamp(1rem, 5vh, 5rem);
    }
}
    }
}

/* Maintain horizontal scroll layout on tablets */
@media (max-width: 769px) {
    .formula-bar {
        padding: 8px 4px;
        gap: 6px;
        min-height: auto;
    }

    .formula-btn {
        padding: 8px 10px;
        /*min-height: 48px;*/
    }

    .formula-btn .fraction {
        /*transform: scale(0.9);*/
        /*transform-origin: center;*/
        /*font-size: 0.9em !important;*/
        margin: 0 2px !important;
    }

    .formula-btn .numerator,
    .formula-btn .denominator,
    .formula-btn .fraction-numerator,
    .formula-btn .fraction-denominator {
        padding: 1px 2px !important;
        font-size: inherit !important;
        /*font-size: 1.8em !important;*/
        line-height: 1.1 !important;
    }

    .formula-btn .placeholder {
        font-size: 2.8em !important;
    }

    #calculator-wrapper {
        max-width: 100%;
    }
    
    #main-container {
        flex-direction: column;
        gap: 15px;
        height: auto;
        overflow: visible;
    }

    .calculator-column {
        flex: 0 0 100%;
        width: 100%;
        height: auto;
        margin: 0;
    }

    .paper {
        flex: 0 0 100%;
        width: 100%;
        height: auto;
        border-radius: 14px;
        border: 2px solid #d6cbb7;
        padding: 14px;
    }

    .calculator {
        border-radius: 0 0 15px 15px;
    }

    .paper-list {
        padding: 8px 10px;
        gap: 6px;
    }
    
    .paper-line {
        gap: 8px;
        padding: 4px 2px;
        font-size: 14px;
    }
}


/* ===== TASK SECTION ===== */
#task-container,
.task-container {
    width: 100%;
    max-width: 100%;
    margin: 0.5vh 0;
    height: auto;
    max-height: none;
    overflow: visible;
    background: linear-gradient(145deg, #2a2a2a 0%, #1e1e1e 100%);
    border: 2px solid #333;
    border-radius: 12px;
    padding: clamp(2px, 1vh, 8px) 2vw;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.8),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    position: relative;
}

.task-controls,
#default-task-buttons,
#task-controls {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    gap: 8px;
    margin-bottom: 6px;
    padding: 0;
    align-items: center;
    justify-content: space-between;
}

/* Home Button - Prominent with Blue Accent */
#homeBtn {
    border: 2px solid #3a5a7a !important;
    background: linear-gradient(145deg, #1a2a3a, #0f1a2a) !important;
    color: #e0f4ff !important;
    font-weight: 700 !important;
    position: relative;
    padding: 6px 12px !important;
    flex: 0 1 auto;
}

#homeBtn:hover {
    border-color: #5a8aaa !important;
    background: linear-gradient(145deg, #2a3a4a, #1a2a3a) !important;
    box-shadow: 
        0 4px 12px rgba(90, 170, 200, 0.3),
        inset 0 1px 2px rgba(224, 244, 255, 0.2) !important;
    transform: translateY(-2px) !important;
}

#homeBtn:active {
    transform: translateY(0px) !important;
    box-shadow: 
        0 2px 6px rgba(90, 170, 200, 0.2),
        inset 0 2px 4px rgba(0, 0, 0, 0.3) !important;
}

/* Settings Button - Small Icon-Only */
.small-icon-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.9rem !important;
    flex-shrink: 0;
}

#settingsBtn.settings-btn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a) !important;
    border: 1px solid #555 !important;
}

#settingsBtn.settings-btn:hover {
    background: linear-gradient(145deg, #454545, #353535) !important;
    border-color: #666 !important;
    transform: scale(1.08) !important;
    box-shadow: 
        0 3px 8px rgba(0, 0, 0, 0.5),
        inset 0 1px 1px rgba(255, 255, 255, 0.15) !important;
}

#settingsBtn.settings-btn:active {
    transform: scale(0.95) !important;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.4),
        inset 0 2px 3px rgba(0, 0, 0, 0.3) !important;
}

#bgMusicToggleBtn.audio-toggle-btn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a) !important;
    border: 1px solid #555 !important;
}

#bgMusicToggleBtn.audio-toggle-btn:hover {
    background: linear-gradient(145deg, #454545, #353535) !important;
    border-color: #666 !important;
    transform: scale(1.08) !important;
    box-shadow: 
        0 3px 8px rgba(0, 0, 0, 0.5),
        inset 0 1px 1px rgba(255, 255, 255, 0.15) !important;
}

#bgMusicToggleBtn.audio-toggle-btn:active {
    transform: scale(0.95) !important;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.4),
        inset 0 2px 3px rgba(0, 0, 0, 0.3) !important;
}

#bgMusicToggleBtn.audio-toggle-btn.muted {
    opacity: 0.5;
}

/* ===== VOLUME CONTROLLER STYLING ===== */
.volume-wrapper {
    display: flex;
    align-items: center;
    position: relative;
    gap: 0;
}

.volume-wrapper:hover .volume-slider-container {
    width: 100px;
    opacity: 1;
}

.volume-slider-container {
    width: 0;
    opacity: 0;
    overflow: hidden;
    transition: width 0.3s ease, opacity 0.3s ease;
    display: flex;
    align-items: center;
    padding: 0 0px;
}

#mute-btn.mute-btn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a) !important;
    border: 1px solid #555 !important;
}

#mute-btn.mute-btn:hover {
    background: linear-gradient(145deg, #454545, #353535) !important;
    border-color: #666 !important;
    transform: scale(1.08) !important;
    box-shadow: 
        0 3px 8px rgba(0, 0, 0, 0.5),
        inset 0 1px 1px rgba(255, 255, 255, 0.15) !important;
}

#mute-btn.mute-btn:active {
    transform: scale(0.95) !important;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.4),
        inset 0 2px 3px rgba(0, 0, 0, 0.3) !important;
}

#mute-btn.mute-btn.muted {
    opacity: 0.5;
}

/* Theory Center Button */
#theoryCenterBtn {
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a) !important;
    border: 1px solid #555 !important;
    color: #ddd !important;
}

#theoryCenterBtn:hover {
    background: linear-gradient(145deg, #454545, #353535) !important;
    border-color: #666 !important;
    transform: scale(1.08) !important;
    box-shadow: 
        0 3px 8px rgba(0, 0, 0, 0.5),
        inset 0 1px 1px rgba(255, 255, 255, 0.15) !important;
}

#theoryCenterBtn:active {
    transform: scale(0.95) !important;
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.4),
        inset 0 2px 3px rgba(0, 0, 0, 0.3) !important;
}

.volume-slider {
    width: 100%;
    height: 5px;
    border-radius: 3px;
    background: linear-gradient(to right, #3a3a3a, #2a2a2a);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4ade80;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(74, 222, 128, 0.4);
    transition: all 0.2s ease;
}

.volume-slider::-webkit-slider-thumb:hover {
    background: #22c55e;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.6);
    transform: scale(1.1);
}

.volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4ade80;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(74, 222, 128, 0.4);
    transition: all 0.2s ease;
}

.volume-slider::-moz-range-thumb:hover {
    background: #22c55e;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.6);
    transform: scale(1.1);
}

.volume-slider::-moz-range-track {
    background: transparent;
    border: none;
}

.volume-slider::-moz-range-progress {
    background: linear-gradient(to right, #4ade80, #22c55e);
}

/* Ensure the slider fills the container smoothly */
.volume-slider::-webkit-slider-runnable-track {
    background: linear-gradient(to right, #3a3a3a, #2a2a2a);
    height: 5px;
    border-radius: 3px;
}

.level-lock-toast {
    display: none;
    position: absolute;
    top: 6px;
    right: 8px;
    max-width: calc(100% - 16px);
    opacity: 0;
    margin: 0;
    padding: 0;
    background: rgba(20, 20, 20, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.78rem;
    line-height: 1.3;
    transition: opacity 0.25s ease;
    overflow: hidden;
    z-index: 20;
}

.level-lock-toast.show {
    display: block;
    opacity: 1;
    padding: 8px 12px;
}

.task-btn {
    flex: 1;
    min-width: 150px;
    min-height: auto;
    padding: 6px 12px;
    font-size: 15px;
    font-weight: 600;
    background: linear-gradient(145deg, #3a3a3a, #2a2a2a);
    border: 1px solid #444;
    border-radius: 6px;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 
        0 2px 6px rgba(0, 0, 0, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.1);
    font-family: 'Courier New', monospace;
    user-select: none;
}

.task-btn:hover {
    background: linear-gradient(145deg, #454545, #353535);
    transform: translateY(-1px);
    box-shadow: 
        0 3px 8px rgba(0, 0, 0, 0.5),
        inset 0 1px 1px rgba(255, 255, 255, 0.15);
}

.task-btn:active {
    transform: translateY(1px);
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.4),
        inset 0 2px 3px rgba(0, 0, 0, 0.3);
}

.task-menu-btn {
    display: none;
    min-width: auto;
    padding: 10px 12px;
    font-size: 0.9rem;
}

@media (max-width: 600px) {
    html,
    body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    body {
        padding-bottom: 50px;
    }

    #main-container {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    #calculator-wrapper {
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    #homeBtn,
    #selectTaskTypeBtn,
    #statsBtn,
    #settingsBtn {
        display: none;
    }

    #taskMenuBtn {
        display: inline-flex;
        flex: 0 0 auto;
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    .level-label {
        display: none;
        margin-right: 0.3em;
    }

    #task-controls {
        display: flex;
        flex-wrap: nowrap;
        gap: 5px;
    }

    .level-toggle-btn {
        min-width: auto;
    }

    .btn-text-label {
        display: none;
    }

    .task-controls,
    #default-task-buttons,
    #task-controls {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: space-between;
        align-items: center;
        gap: 6px;
    }

    .formula-bar {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        overflow-x: hidden !important;
        padding: 6px 4px;
        gap: 6px;
        min-height: auto;
    }

    .formula-btn {
        width: 100%;
        padding: 6px 8px;
        /*min-height: 44px;*/
    }

    .formula-btn .fraction {
        /*font-size: 0.9em !important;*/
        margin: 0 3px;
    }

    .formula-btn .numerator,
    .formula-btn .denominator,
    .formula-btn .fraction-numerator,
    .formula-btn .fraction-denominator {
        padding: 2px;
        font-size: inherit !important;
        /*font-size: 0.9em;*/
        line-height: 1.2;
    }
}

@media (max-width: 480px) {
    #main-container {
        flex-direction: column;
        gap: 12px;
        padding: 4px 12px 12px 12px;
        min-height: 0;
    }

    #top-controls {
        gap: 6px;
        margin-bottom: 10px;
    }

    .utility-column {
        flex: 1;
    }

    .calculator {
        padding: 8px;
        border-radius: 0 0 15px 15px;
    }

    .calculator-header {
        display: none;
    }

    .paper {
        border-radius: 14px;
        border: 2px solid #d6cbb7;
        padding: 12px;
    }

    .btn {
        padding: 8px 4px;
        font-size: clamp(10px, 2vh, 16px);
        min-height: 40px;
    }

    .btn.number {
        font-size: clamp(12px, 2.2vh, 18px);
    }

    .btn.operator {
        font-size: clamp(12px, 2.4vh, 18px);
    }

    .control-section {
        gap: 8px;
    }

    .control-btn {
        font-size: 13px;
        padding: 8px 6px;
        min-height: 36px;
    }

    .btn-icon {
        width: 18px;
        height: 18px;
    }

    .display {
        padding: 6px;
        /*min-height: 60px;*/
        max-height: 120px;
    }

    .display-expression {
        font-size: 1.2rem;
        min-height: 30px;
    }

    .display-result {
        font-size: 1.2rem;
    }

    .formula-bar {
        display: grid !important;
        justify-content: space-evenly;
        grid-template-columns: repeat(3, 1fr) !important;
        overflow-x: hidden !important;
        padding: 0.6em 0.4em !important;
        gap: 4px;
        min-height: auto;
        border-radius: 8px 8px 0 0;
    }

    .formula-btn {
        width: 100%;
        padding: 0.2em 0.4em !important;
        /*padding: 6px 8px;*/
        /*min-height: 42px;*/
    }

    .formula-btn .numerator,
    .formula-btn .denominator,
    .formula-btn .fraction-numerator,
    .formula-btn .fraction-denominator {
        padding: 1px 2px;
        /*font-size: 0.85em;*/
        line-height: 1.1;
    }

    .formula-btn .fraction {
        /*font-size: 0.8em;*/
        margin: 0 2px;
    }

    .task-display {
        display: block;
        height: auto;
        min-height: auto;
        padding: 6px;
        font-size: clamp(0.5rem, 2.2vh, 1.2rem);
        line-height: 1.5;
    }

    .paper-list {
        font-size: clamp(0.5rem, 2.2vh, 1.2rem);
    }

    .paper-line {
        font-size: clamp(0.75rem, 2.2vh, 1.5rem);
    }

    .buttons {
        gap: 4px;
    }
}

.task-menu-overlay {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 12;
    display: none;
    padding: 6px 0 0 0;
}

.task-menu-overlay.visible {
    display: block;
}

.task-menu-panel {
    background: rgba(18, 18, 18, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}

.task-menu-panel .task-btn {
    width: 100%;
    min-width: 0;
}

.level-toggle-btn {
    min-width: 140px;
    font-size: 0.85rem;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    background: linear-gradient(145deg, #2f2f2f, #242424);
}

.level-toggle-btn.level-1 {
    color: #7cb342;
    border-color: rgba(124, 179, 66, 0.45);
    box-shadow:
        0 2px 6px rgba(124, 179, 66, 0.15),
        inset 0 1px 1px rgba(255, 255, 255, 0.08);
}

.level-toggle-btn.level-2 {
    color: #fbc02d;
    border-color: rgba(251, 192, 45, 0.45);
    box-shadow:
        0 2px 6px rgba(251, 192, 45, 0.15),
        inset 0 1px 1px rgba(255, 255, 255, 0.08);
}

.level-toggle-btn.level-3 {
    color: #e53935;
    border-color: rgba(229, 57, 53, 0.5);
    box-shadow:
        0 2px 6px rgba(229, 57, 53, 0.18),
        inset 0 1px 1px rgba(255, 255, 255, 0.08);
}

.task-btn-primary {
    background: linear-gradient(145deg, #00d4aa, #00a389);
    color: #ffffff;
    font-weight: bold;
    border-color: #00b399;
}

.task-btn-primary:hover {
    background: linear-gradient(145deg, #00e4ba, #00b399);
    box-shadow: 
        0 3px 8px rgba(0, 212, 170, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

.task-btn-primary:active {
    transform: translateY(1px);
    box-shadow: 
        0 1px 3px rgba(0, 0, 0, 0.4),
        inset 0 2px 3px rgba(0, 0, 0, 0.3);
}

.task-display {
    background: linear-gradient(145deg, #1f1f1f, #2a2a2a);
    border: 2px solid #3a3a3a;
    border-radius: 8px;
    padding: 20px;
    min-height: auto;
    display: block;
    color: #c5d1b7;
    font-size: 18px;
    line-height: 1.8;
    text-align: center;
    box-shadow: 
        inset 0 2px 8px rgba(0, 0, 0, 0.3),
        0 1px 2px rgba(255, 255, 255, 0.05);
    word-wrap: break-word;
    overflow-y: visible;
    max-height: none;
    flex-shrink: 1;
}

.task-placeholder {
    color: #888;
    font-style: italic;
    margin: 0;
    padding: 0;
    line-height: 1.2;
}

/* ===== GAME STATUS BAR CONTROLS ===== */
#game-status-bar {
    display: none !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-bottom: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    gap: 12px;
}

#game-status-bar.visible {
    display: flex !important;
}

#mode-info {
    flex: 1;
    text-align: center;
    font-size: 0.85rem;
    color: #aaa;
}

#exit-btn {
    flex-shrink: 0;
    transition: all 0.15s ease;
    background: #e74c3c !important;
    color: white !important;
    border: none !important;
    padding: 6px 12px !important;
    border-radius: 4px !important;
    font-size: 0.75rem !important;
    cursor: pointer !important;
}

#exit-btn:hover {
    background: #d64035 !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(231, 76, 60, 0.4);
}

#exit-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Responsive adjustments for task controls (6 buttons total) */
@media (max-width: 1024px) {
    .task-controls {
        gap: 10px;
    }
    
    .task-btn {
        flex: 0 1 auto;
        min-width: 120px;
        white-space: nowrap;
    }
}

@media (max-width: 768px) {
    #homeBtn {
        padding: 9px 14px !important;
        font-size: 0.85rem !important;
        flex: 0 1 auto;
    }

    .small-icon-btn {
        width: 34px !important;
        height: 34px !important;
        min-width: 34px !important;
    }

    .task-controls {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center;
        gap: 8px;
        margin-bottom: 12px;
    }
    
    .task-btn {
        padding: 9px 12px !important;
        font-size: 0.9rem !important;
        flex: 0 1 auto;
        min-width: 0;
        white-space: nowrap;
    }
}

@media (max-width: 480px) {
    #homeBtn {
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
        flex: 1 1 calc(50% - 4px);
    }

    .small-icon-btn {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        flex: 0 0 32px;
    }

    .task-controls {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center;
        gap: 6px;
        margin-bottom: 10px;
    }
    
    .task-btn {
        padding: 8px 10px !important;
        font-size: 0.75rem !important;
        flex: 0 1 auto;
        min-width: 0;
        white-space: nowrap;
    }
}

/* ===== CLICKABLE NUMBERS ===== */
.clickable-number {
    border-bottom: 2px dashed #00d4aa;
    color: #00d4aa;
    cursor: pointer;
    font-weight: bold;
    padding: 0 2px;
    margin: 0 4px;
    transition: all 0.2s ease;
    display: inline-block;
    white-space: nowrap;
}

.clickable-number:hover {
    background-color: rgba(0, 212, 170, 0.1);
    transform: translateY(-1px);
    border-bottom-style: solid;
}

.clicked-anim {
    transform: scale(0.95);
    background-color: rgba(0, 212, 170, 0.2);
}

/* ===== MASTERY CHALLENGE NOTIFICATION ===== */
.mastery-notification {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: linear-gradient(135deg, #ff9500 0%, #ff6b00 100%);
    border: 2px solid #ffb84d;
    border-radius: 8px;
    color: #ffffff;
    font-weight: 700;
    font-size: 0.9rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 
        0 4px 12px rgba(255, 149, 0, 0.3),
        inset 0 1px 2px rgba(255, 255, 255, 0.3);
    animation: masteryPulse 2s ease-in-out;
}

@keyframes masteryPulse {
    0% {
        transform: scale(1);
        box-shadow: 
            0 4px 12px rgba(255, 149, 0, 0.3),
            inset 0 1px 2px rgba(255, 255, 255, 0.3);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 
            0 6px 18px rgba(255, 149, 0, 0.5),
            inset 0 1px 2px rgba(255, 255, 255, 0.4);
    }
    100% {
        transform: scale(1);
        box-shadow: 
            0 4px 12px rgba(255, 149, 0, 0.3),
            inset 0 1px 2px rgba(255, 255, 255, 0.3);
    }
}

/* ===== RESPONSIVE TASK SECTION ===== */
@media (max-width: 768px) {
    .task-container {
        margin: 0 auto 15px auto;
        padding: 12px;
    }
    
    .task-controls {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center;
        gap: 10px;
    }
    
    .task-btn {
        min-width: 0;
        padding: 10px 12px;
        font-size: 14px;
        flex: 0 1 auto;
        white-space: nowrap;
    }
    
    .task-display {
        display: block;
        padding: 14px;
        min-height: auto;
        height: auto;
        font-size: clamp(0.6rem, 1.5vh, 1.2rem);
        line-height: 1.6;
    }
}

@media (max-width: 480px) {
    .task-container {
        margin: 0 auto 12px auto;
        padding: clamp(5px, 2vw, 10px);
        border-radius: 10px;
        max-height: none;
        overflow: visible;
    }
    
    .task-controls {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center;
        gap: 6px;
    }
    
    .task-btn {
        width: auto;
        min-width: 0;
        padding: 8px 10px;
        font-size: clamp(0.72rem, 3.2vw, 0.9rem);
        flex: 0 1 auto;
        white-space: nowrap;
    }

    #homeBtn,
    #selectTaskTypeBtn,
    #statsBtn,
    #settingsBtn {
        display: none;
    }

    #taskMenuBtn {
        display: inline-flex;
        flex: 0 0 auto;
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    #levelToggleBtn {
        flex: 1 1 auto;
    }

    #game-status-bar {
        margin-bottom: 6px !important;
        padding: 4px 6px !important;
        font-size: 0.7rem !important;
        border-radius: 4px !important;
        gap: 8px;
    }

    #exit-btn {
        padding: 4px 8px !important;
        font-size: 0.65rem !important;
        border-radius: 4px !important;
    }
    
    .task-display {
        padding: 12px;
        min-height: auto;
        font-size: clamp(0.72rem, 3.2vw, 0.9rem);
        line-height: 1.5;
    }
}

/* ===== PRACTICE THEME BUTTON ===== */
.practice-theme-btn {
    width: 100%;
    padding: 10px 12px;
    margin-top: 8px;
    background: linear-gradient(145deg, #0d6efd, #0a51cb);
    border: 1px solid rgba(13, 110, 253, 0.6);
    border-radius: 6px;
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 
        0 2px 6px rgba(13, 110, 253, 0.25),
        inset 0 1px 1px rgba(255, 255, 255, 0.2);
    font-family: 'Courier New', monospace;
    user-select: none;
}

.practice-theme-btn:hover {
    background: linear-gradient(145deg, #0f7cff, #0b56d4);
    transform: translateY(-1px);
    box-shadow: 
        0 3px 8px rgba(13, 110, 253, 0.35),
        inset 0 1px 1px rgba(255, 255, 255, 0.25);
}

.practice-theme-btn:active {
    transform: translateY(1px);
    box-shadow: 
        0 1px 3px rgba(13, 110, 253, 0.25),
        inset 0 2px 3px rgba(0, 0, 0, 0.15);
}

/* ===== THEME LEVEL STARS ===== */
.theme-level-stars {
    font-size: 0.95rem;
    color: #ffc107;
    font-weight: 600;
    letter-spacing: 2px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
    white-space: nowrap;
}

/* ===== ANSWER CHECK SECTION ===== */
.answer-section {
    margin-top: 5px;
    padding-top: 5px;
    border-top: 2px dashed #d6cbb7;
}

.answer-inputs {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.answer-input {
    flex: 1;
    min-width: 120px;
    padding: 12px 16px;
    font-size: 16px;
    font-family: 'Courier New', monospace;
    border: 2px solid #c9b89a;
    border-radius: 8px;
    background: #fff;
    color: #2b2b2b;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.answer-input:focus {
    border-color: #00d4aa;
    box-shadow: 
        inset 0 1px 2px rgba(0, 0, 0, 0.1),
        0 0 0 3px rgba(0, 212, 170, 0.2);
}

.answer-input::placeholder {
    color: #999;
}

.answer-btn {
    padding: 12px 24px;
    min-width: 140px;
    background: linear-gradient(145deg, #00d4aa, #00a389);
    border: 2px solid #00b399;
    color: #fff;
    font-weight: bold;
    font-size: 15px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    box-shadow: 
        0 2px 6px rgba(0, 212, 170, 0.3),
        inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

.answer-btn:hover {
    background: linear-gradient(145deg, #00e4ba, #00b399);
    transform: translateY(-1px);
    box-shadow: 
        0 3px 8px rgba(0, 212, 170, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

.answer-btn:active {
    transform: translateY(1px);
    box-shadow: 
        0 1px 3px rgba(0, 212, 170, 0.3),
        inset 0 2px 3px rgba(0, 0, 0, 0.1);
}

/* ===== FEEDBACK MESSAGE ===== */
.feedback-message {
    min-height: 0;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: all 0.3s ease;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: space-between;
}

.feedback-message.feedback-visible {
    max-height: 100px;
    opacity: 1;
    padding: 5px 12px;
    border-radius: 8px;
    animation: slideDown 0.3s ease;
    display: flex;
}

@keyframes slideDown {
    from {
        max-height: 0;
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        max-height: 100px;
        opacity: 1;
        transform: translateY(0);
    }
}

/* Success feedback */
.feedback-success-container {
    background: linear-gradient(145deg, #1a3a2e 0%, #0f2a25 100%);
    border: 2px solid #00d4aa;
    border-left: 4px solid #00d4aa;
}

.feedback-success {
    display: flex;
    flex: 0 1 auto;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    text-align: left;
    width: 100%;
    justify-content: space-between;
    padding: 5px 12px;
}

.feedback-success .feedback-text {
    color: #00d4aa;
    font-size: clamp(0.6rem, 1.5vh, 1.2rem);
    font-weight: bold;
}

/* Error feedback */
.feedback-error-shown {
    background: linear-gradient(145deg, #3a1a1a 0%, #2a0f0f 100%);
    border: 2px solid #ff4444;
    border-left: 4px solid #ff4444;
}

.feedback-error-container {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    text-align: left;
    width: 100%;
}

.feedback-error-container .feedback-text {
    color: #ff6666;
    font-size: clamp(0.75rem, 1.8vh, 0.95rem);
    font-weight: bold;
}

.feedback-error-container .feedback-text.feedback-error {
    color: #ff6666;
}

/* Answer display feedback */
.feedback-answer-shown {
    background: linear-gradient(145deg, #1a2a3a 0%, #0f1a2a 100%);
    border: 2px solid #4488ff;
    border-left: 4px solid #4488ff;
}

.feedback-answer-container {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    text-align: left;
    width: 100%;
}

.feedback-answer-container .feedback-text {
    color: #88ccff;
    font-size: clamp(0.75rem, 1.8vh, 0.9rem);
}

.feedback-answer-container .feedback-text strong {
    color: #00d4aa;
    font-size: clamp(0.8rem, 2vh, 1rem);
}

/* Feedback text and buttons */
.feedback-text {
    margin: 0;
    color: #fff;
    font-size: clamp(0.75rem, 1.8vh, 0.9rem);
    white-space: nowrap;
}

.feedback-error {
    color: #ff6666;
}

.feedback-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: nowrap;
}

.feedback-btn {
    padding: 0.5rem 1.0rem;
    min-height: 0.7rem;
    font-size: clamp(0.8rem, 1.5vh, 1rem);
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Courier New', monospace;
    white-space: nowrap;
    background: #4154ff;
}

.feedback-btn-primary {
    background: linear-gradient(145deg, #00d4aa, #00a389);
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 212, 170, 0.3);
}

.feedback-btn-primary:hover {
    background: linear-gradient(145deg, #00e4ba, #00b399);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 212, 170, 0.4);
}

.feedback-btn-primary:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0, 212, 170, 0.3);
}

.feedback-btn-secondary {
    background: linear-gradient(145deg, #555, #444);
    color: #fff;
    border: 1px solid #666;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.feedback-btn-secondary:hover {
    background: linear-gradient(145deg, #666, #555);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
}

.feedback-btn-secondary:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Feedback info paragraphs (progress, lives, etc.) */
.feedback-success p,
.feedback-error-container p,
.feedback-answer-container p {
    margin: 0;
    font-size: clamp(0.6rem, 1.5vh, 1rem);
}

/* ===== RESPONSIVE ANSWER SECTION ===== */
@media (max-width: 768px) {
    .answer-inputs {
        gap: 8px;
    }
    
    .answer-input {
        padding: 10px 12px;
        font-size: 16px;
    }
    
    .answer-btn {
        padding: 10px 16px;
        min-width: 100px;
        font-size: 13px;
    }
    
    .feedback-btn {
        padding: 3px 8px;
        min-width: auto;
        font-size: clamp(0.8rem, 1.5vh, 1rem);
    }
}

@media (max-width: 480px) {
    .answer-section {
        margin-top: 12px;
        padding-top: 12px;
        border-top: 2px dashed #d6cbb7;
    }
    
    .answer-inputs {
        flex-direction: column;
        gap: 6px;
    }
    
    .answer-input {
        width: 100%;
        padding: 10px 10px;
        font-size: 16px;
    }
    
    .answer-btn {
        width: 100%;
        padding: 11px 10px;
        min-width: unset;
        font-size: 13px;
    }
    
    .feedback-btn {
        flex: 0;
        min-width: auto;
        padding: 3px 8px;
        font-size: 10px;
    }
    
    .feedback-buttons {
        gap: 4px;
    }
    
    .feedback-text {
        font-size: 15px;
    }

    .calculator-column {
        max-width: 100%;
        width: 100%;
        margin: 0 auto;
    }
}

    /* ===== THEORY CENTER OVERLAY ===== */
    .theory-overlay {
        position: fixed;
        inset: 0;
        background: rgba(8, 8, 10, 0.82);
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 18px;
        z-index: 1001;
        animation: fadeIn 0.25s ease;
    }

    .theory-modal {
        width: min(1100px, 96vw);
        height: min(560px, 86vh);
        background: radial-gradient(circle at top left, rgba(28, 40, 45, 0.9), rgba(16, 18, 22, 0.98) 55%),
                    linear-gradient(160deg, rgba(22, 22, 26, 0.98), rgba(8, 10, 12, 0.98));
        border: 1px solid rgba(120, 170, 190, 0.3);
        border-radius: 18px;
        box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
        display: flex;
        flex-direction: column;
        color: #ffffff;
        font-family: "Trebuchet MS", Verdana, "Segoe UI", sans-serif;
        overflow: hidden;
    }

    .theory-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px 22px;
        border-bottom: 1px solid rgba(120, 170, 190, 0.25);
        background: rgba(12, 16, 18, 0.85);
    }

    .theory-header-text h2 {
        margin: 0;
        font-size: 1.4rem;
        letter-spacing: 0.4px;
    }

    .theory-subtitle {
        margin-top: 4px;
        font-size: 0.9rem;
        color: rgba(209, 226, 230, 0.75);
    }

    .theory-close-btn {
        background: linear-gradient(135deg, #54616b, #3b4650);
        border: 1px solid rgba(255, 255, 255, 0.1);
        color: #f4f7f8;
        padding: 8px 16px;
        border-radius: 8px;
        font-weight: 600;
        cursor: pointer;
    }

    .theory-body {
        display: flex;
        gap: 16px;
        padding: 16px;
        flex: 1;
        min-height: 0;
    }

    .theory-nav {
        width: 230px;
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding-right: 6px;
        overflow-y: auto;
    }

    .theory-topic-btn {
        background: rgba(18, 22, 26, 0.9);
        border: 1px solid rgba(120, 170, 190, 0.25);
        border-radius: 10px;
        color: #cfe3e8;
        padding: 10px 12px;
        font-size: 0.95rem;
        text-align: left;
        transition: all 0.2s ease;
        cursor: pointer;
    }

    .theory-topic-btn:hover {
        border-color: rgba(140, 200, 220, 0.7);
        color: #ffffff;
        transform: translateX(2px);
    }

    .theory-topic-btn.is-active {
        background: linear-gradient(135deg, rgba(45, 130, 150, 0.9), rgba(30, 70, 85, 0.9));
        border-color: rgba(160, 220, 240, 0.9);
        color: #ffffff;
        box-shadow: 0 6px 16px rgba(18, 56, 68, 0.4);
    }

    .theory-content {
        flex: 1;
        min-height: 0;
        background: rgba(12, 14, 18, 0.7);
        border: 1px solid rgba(120, 170, 190, 0.2);
        border-radius: 14px;
        padding: 16px;
        overflow-y: auto;
    }

    .theory-content-inner {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    .theory-example {
        padding: 14px;
        border-radius: 12px;
        background: rgba(18, 24, 30, 0.85);
        border: 1px solid rgba(120, 170, 190, 0.18);
    }

    .theory-example h3 {
        margin: 0 0 8px 0;
        font-size: 1rem;
        color: #f5fbff;
    }

    .theory-note {
        font-size: 0.9rem;
        color: rgba(214, 232, 236, 0.75);
        margin-bottom: 12px;
    }

    .theory-usage {
        display: flex;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 14px;
        border-radius: 12px;
        border: 1px solid rgba(120, 170, 190, 0.25);
        background: rgba(120, 170, 190, 0.12);
        color: rgba(230, 245, 250, 0.92);
        font-size: 0.9rem;
        margin-top: 12px;
    }

    .theory-usage-icon {
        font-size: 1.05rem;
        line-height: 1.2;
        margin-top: 2px;
    }

    @media (max-width: 900px) {
        .theory-modal {
            height: min(620px, 88vh);
        }

        .theory-body {
            flex-direction: column;
        }

        .theory-nav {
            width: 100%;
            flex-direction: row;
            flex-wrap: wrap;
            padding-right: 0;
        }

        .theory-topic-btn {
            flex: 1 1 190px;
        }
    }

    @media (max-height: 600px) {
        .theory-modal {
            height: min(500px, 92vh);
        }

        .theory-header {
            padding: 12px 16px;
        }

        .theory-body {
            padding: 12px;
        }
    }

/* ===== ROUNDING MODAL STYLES ===== */
.rounding-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-in-out;
}

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

.rounding-modal {
    background: linear-gradient(135deg, #1a1a1a 0%, #222 100%);
    border: 2px solid #ff9500;
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(255, 149, 0, 0.3),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
    animation: slideUp 0.3s ease-out;
}

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

.rounding-modal-header {
    text-align: center;
    margin-bottom: 25px;
}

.rounding-modal-header h2 {
    font-size: 20px;
    color: #ff9500;
    font-weight: bold;
    margin: 0;
}

.rounding-number-display {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    text-align: center;
}

.rounding-number-display p {
    font-size: 16px;
    color: #ccc;
    margin: 0;
}

.rounding-number-display strong {
    color: #ff9500;
    font-size: 18px;
    font-weight: bold;
}

.rounding-question {
    text-align: center;
    margin-bottom: 20px;
}

.rounding-question p {
    font-size: 16px;
    color: #fff;
    margin: 0;
}

.rounding-digit-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.rounding-digit-btn {
    background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    border: 2px solid #444;
    border-radius: 8px;
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Courier New', 'Consolas', monospace;
}

.rounding-digit-btn:hover {
    background: linear-gradient(135deg, #ff9500 0%, #ffb300 100%);
    border-color: #ff9500;
    color: #000;
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(255, 149, 0, 0.5);
}

.rounding-digit-btn:active {
    transform: scale(0.95);
    background: linear-gradient(135deg, #e68400 0%, #ff9500 100%);
}

.rounding-feedback {
    padding: 12px;
    margin-bottom: 15px;
    border-radius: 6px;
    text-align: center;
    font-size: 14px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rounding-feedback-error {
    background: rgba(220, 53, 69, 0.2);
    border: 1px solid #dc3545;
    color: #ff6b6b;
}

.rounding-feedback p {
    margin: 0;
}

.rounding-close-btn {
    width: 100%;
    background: linear-gradient(135deg, #555 0%, #333 100%);
    border: 2px solid #666;
    border-radius: 8px;
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Courier New', 'Consolas', monospace;
}

.rounding-close-btn:hover {
    background: linear-gradient(135deg, #666 0%, #444 100%);
    border-color: #888;
    box-shadow: 0 0 10px rgba(200, 200, 200, 0.2);
}

.rounding-close-btn:active {
    transform: scale(0.98);
    background: linear-gradient(135deg, #444 0%, #222 100%);
}

/* ===== RESPONSIVE ROUNDING MODAL ===== */
@media (max-width: 768px) {
    .rounding-modal {
        padding: 20px;
        max-width: 90%;
    }
    
    .rounding-modal-header h2 {
        font-size: 18px;
    }
    
    .rounding-number-display p {
        font-size: 14px;
    }
    
    .rounding-number-display strong {
        font-size: 16px;
    }
    
    .rounding-question p {
        font-size: 14px;
    }
    
    .rounding-digit-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 6px;
    }
    
    .rounding-digit-btn {
        font-size: 16px;
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .rounding-modal {
        padding: 15px;
    }
    
    .rounding-modal-header h2 {
        font-size: 16px;
    }
    
    .rounding-number-display {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .rounding-number-display p {
        font-size: 12px;
    }
    
    .rounding-number-display strong {
        font-size: 14px;
    }
    
    .rounding-question p {
        font-size: 12px;
    }
    
    .rounding-digit-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 4px;
        margin-bottom: 15px;
    }
    
    .rounding-digit-btn {
        font-size: 14px;
        padding: 10px;
    }
    
    .rounding-close-btn {
        font-size: 14px;
        padding: 10px;
    }
}

/* ===== SETTINGS MODAL ===== */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1100;
    padding: 20px;
    overflow-y: auto;
}

.settings-modal {
    background: #141414;
    /* Samme farge overalt */
    border: 1px solid #2a2a2a;
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    /* FJERN padding: 22px; herfra */
    padding: 0;
    color: #e0e0e0;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
    overflow: hidden;
    /* Sørger for at headeren følger border-radiusen øverst */
}

.settings-header {
    position: sticky;
    top: 0;
    width: 100%;
    z-index: 100;
    background-color: #141414;
    /* Matcher modalen */
    border-bottom: 1px solid #2a2a2a;
    padding: 20px 22px;
    /* Her legger vi paddingen i stedet */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: #fff;
    flex: 0 1 auto;
    min-width: 0;
}

.settings-close-btn {
    background: #2d2d2d;
    border: 1px solid #3a3a3a;
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 22px;
    /* Legg padding her så innholdet ikke treffer kanten */
}

/* Smalere skjermer (f.eks. 320px bredde) */
@media screen and (max-width: 350px) {
    .settings-content {
        padding: 12px;
        /* Sparer plass på sidene */
        gap: 10px;
        /* Tettere mellom boksene */
    }

    .settings-row {
        padding: 10px;
        /* Mindre luft inni hver boks */
    }
}

.settings-row {
    background: #1b1b1b;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
    padding: 14px;
    display: grid;
    gap: 10px;
}

.settings-labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.settings-value {
    font-weight: 700;
    color: #8ddcff;
}

.settings-hint {
    font-size: 0.85rem;
    color: #9a9a9a;
}

#setting-questions-range {
    width: 100%;
}

#setting-questions-number {
    width: 100%;
    background: #0f0f0f;
    border: 1px solid #2a2a2a;
    color: #e0e0e0;
    padding: 8px 10px;
    border-radius: 8px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    transition: 0.2s;
    border-radius: 20px;
    border: 1px solid #444;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 2px;
    background-color: #bbb;
    transition: 0.2s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #2ecc71;
    border-color: #27ae60;
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(22px);
    background-color: #eafff0;
}

@media (max-width: 480px) {
    .settings-modal {
        padding: 2px;
    }

    .settings-row {
        padding: 2px;
    }
}

/* ===== LANDSCAPE MODE FIX FOR SETTINGS MODAL ===== */
@media screen and (max-height: 500px) {
    .settings-overlay {
        align-items: flex-start;
        padding: 10px;
    }

    .settings-modal {
        margin-top: 10px;
        margin-bottom: 10px;
        max-height: calc(100vh - 20px);
        display: flex;
        flex-direction: column;
    }

    .settings-header {
        position: sticky;
        top: 0;
        background: #141414;
        z-index: 10;
        /* VIKTIG: Gi headeren nøyaktig samme farge som modal-bakgrunnen */
        background-color: #1a1a1a;
        /* Sørger for at den har samme farge som modalen */
        /* Skap et klart skille mellom header og resten */
        border-bottom: 1px solid #333;
        padding: 15px 20px;
        /* Dette sørger for at den legger seg pent på toppen */
        display: flex;
        justify-content: space-between;
        align-items: center;
        /*padding-bottom: 10px;
        margin-bottom: 10px;
        border-bottom: 1px solid #2a2a2a;
        flex-wrap: wrap;
        gap: 8px;*/
    }

    .settings-close-btn {
        flex-shrink: 0;
    }

    .settings-content {
        overflow-y: auto;
        flex: 1;
        min-height: 0;
        padding-top: 10px; /* Gir litt avstand fra den sticky headeren */
    }
}

/* ===== MANUAL LEVEL WARNING MODAL ===== */
.level-warning-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1100;
    animation: fadeIn 0.3s ease-in-out;
}

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

.level-warning-content {
    background: linear-gradient(135deg, #1a1a1a 0%, #222 100%);
    border: 2px solid #444;
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    text-align: center;
    color: #e0e0e0;
}

.level-warning-content h2 {
    font-size: 1.5rem;
    margin: 0 0 15px 0;
    color: #fff;
    font-weight: 600;
}

.level-warning-explanation {
    font-size: 0.95rem;
    line-height: 1.6;
    margin: 0 0 20px 0;
    color: #bbb;
}

.level-warning-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.level-warning-btn {
    padding: 10px 20px;
    font-size: 0.95rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
    min-width: 130px;
}

.level-warning-btn-primary {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: #fff;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.level-warning-btn-primary:hover {
    background: linear-gradient(135deg, #2980b9, #1f618d);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(52, 152, 219, 0.4);
}

.level-warning-btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.2);
}

.level-warning-btn-secondary {
    background: linear-gradient(135deg, #555, #444);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.level-warning-btn-secondary:hover {
    background: linear-gradient(135deg, #666, #555);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.level-warning-btn-secondary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* ===== UTILITY CLASSES ===== */
.hidden {
    display: none !important;
}

/* ===== MOBILE LANDSCAPE FIX (Horizontal Scroll for Formula Bar) ===== */
@media screen and (max-height: 500px) and (max-width: 950px) {
    html,
    body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto !important;
        overflow-x: hidden;
    }

    body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto !important;
    }

    #main-container {
        height: auto;
        min-height: auto;
        overflow-y: visible !important;
    }

    #calculator-wrapper {
        height: auto;
        min-height: auto;
        overflow: visible !important;
    }

    .calculator-column {
        height: auto;
        min-height: auto;
    }

    /* Switch formula bar to horizontal scroll layout */
    .formula-bar {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .formula-btn {
        flex: 1 0 auto !important;
        width: auto !important;
        min-width: 130px;
        min-height: 48px;
        height: 100%;
        white-space: nowrap;
    }

    /* ===== TASK MENU BUTTON LOGIC FOR LANDSCAPE ===== */
    /* Hide individual task buttons */
    #homeBtn,
    #selectTaskTypeBtn,
    #statsBtn,
    #settingsBtn {
        display: none !important;
    }

    /* Show task menu button */
    #taskMenuBtn {
        display: inline-flex !important;
        flex: 0 0 auto;
        padding: 8px 10px;
        font-size: 0.85rem;
    }

    /* Ensure task controls layout */
    #task-controls,
    .task-controls,
    #default-task-buttons {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center;
        justify-content: space-between;
        gap: 5px;
    }

    .task-btn {
        flex: 0 1 auto;
        min-width: 0;
        white-space: nowrap;
    }

    /* Hide text labels */
    .level-label,
    .btn-text-label {
        display: none !important;
    }

    /* Adjust level toggle button */
    .level-toggle-btn {
        min-width: auto;
    }
}

@media screen and (max-width: 350px) {

    /* Gjør hele modalen litt mer kompakt */
    #settings-modal {
        padding: 10px !important;
        width: 95% !important;
    }

    /* Reduser padding i hver rad for å spare vertikal plass */
    .settings-row {
        padding: 10px 8px !important;
        gap: 5px !important;
    }

    /* Gjør overskriftene mindre så de ikke tar to linjer */
    .settings-row h3 {
        font-size: 0.9rem !important;
        max-width: 60%;
        /* Gir plass til bryteren på høyre side */
    }

    /* Gjør beskrivelsesteksten mindre eller skjul den hvis det er ekstremt trangt */
    .settings-row p {
        font-size: 0.75rem !important;
        line-height: 1.2 !important;
    }

    /* Juster sliders (lydstyrke/oppgaver) så de ikke tar for mye plass */
    input[type="range"] {
        height: 20px;
    }
}

/* ===== SCOREBOARD MOBIL-FIX (Overstyrer inline styles) ===== */
@media (max-width: 600px) {

    /* Selve den mørke bakgrunnen */
    #scoreboard-overlay {
        padding: 10px 0 !important;
    }

    /* Den hvite/grå boksen inni */
    #scoreboard-overlay>div {
        padding: 15px !important;
        gap: 12px !important;
        width: 98% !important;
        margin-top: 5px !important;
        max-height: calc(100vh - 20px) !important;
    }

    /* Topp-seksjonen med tittel og knapper */
    #scoreboard-overlay>div>div:first-child {
        flex-direction: column !important;
        /* Stabler tittel og knapper */
        align-items: center !important;
        text-align: center !important;
        gap: 15px !important;
    }

    /* Overskriften */
    #scoreboard-overlay h2 {
        font-size: 1.1rem !important;
        /* Krymper tittelen betraktelig */
        margin: 0 !important;
    }

    /* Beholderen for Nullstill og Tilbake-knappene */
    #scoreboard-overlay div[style*="display: flex; gap: 10px;"] {
        width: 100% !important;
        justify-content: center !important;
    }

    /* Selve knappene øverst */
    #scoreboard-overlay .btn {
        flex: 1 !important;
        /* Lar knappene dele bredden likt */
        max-width: 150px !important;
        padding: 12px 5px !important;
        font-size: 0.85rem !important;
    }

    /* Rutenettet med oppgavetyper */
    #scoreboard-list {
        grid-template-columns: 1fr !important;
        /* Tvinger én kolonne */
        gap: 12px !important;
    }

    /* Individuelle statistikk-kort */
    #scoreboard-list>div {
        padding: 12px !important;
    }

    /* Gjør teksten inni kortene litt mer kompakt */
    #scoreboard-list div[style*="font-size: 1.05rem"] {
        font-size: 1rem !important;
    }
}
