body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f4f4f9;
            margin: 0;
            padding: 0px;
            min-height: 100vh;
            box-sizing: border-box;
        }

        #app-container {
            width: 100%;
            max-width: 1800px;
            background: white;
            padding: clamp(8px, 4vh, 20px);
            border-radius: 12px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            box-sizing: border-box;
            display: flex;
            flex-direction: column;
            height: 100vh;
            overflow-y: auto;
            overflow-x: hidden;
        }

        .hidden {
            display: none !important;
        }

        .v-hidden {
            visibility: hidden !important;
        }

                /* Stil for nivå-knappene */
        .level-select-btn {
            width: 34px;
            height: 34px;
            border-radius: 50%;
            border: 2px solid #9ca3af;
            background-color: #f3f4f6;
            color: #1f2937;
            font-weight: 700;
            font-size: 1rem;
            cursor: pointer;
            transition: all 0.15s ease;
            
            /* Dette fikser sentreringen: */
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0; /* Fjerner standard padding som kan dytte tallet ut av kurs */
            line-height: 1; /* Sørger for at teksthøyden ikke lager tull */
        }

        /* Stil når knappen er valgt (den blå fargen på bildet ditt) */
        .level-select-btn.active {
            background-color: #2563eb; /* En fin blåfarge */
            color: white;
            border-color: #2563eb;
        }

        /* Stil når man holder over (hover) */
        .level-select-btn:hover:not(.active) {
            background-color: #e5e7eb;
            border-color: #6b7280;
        }

        /* ==================== WELCOME OVERLAY ==================== */
        .welcome-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: rgba(0, 0, 0, 0.7);
            backdrop-filter: blur(5px);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 2000;
            padding: 20px;
            box-sizing: border-box;
        }

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

        .welcome-modal {
            background: #ffffff;
            border-radius: 16px;
            max-width: 1200px;
            width: 100%;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
            overflow: hidden;
            display: flex;
            flex-direction: column;
            max-height: 90vh;
        }

        .welcome-header {
            background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
            color: #ffffff;
            padding: 30px 28px 25px 28px;
            text-align: center;
        }

        .welcome-header h2 {
            margin: 0;
            font-size: clamp(1.3rem, 5vw, 1.8rem);
            font-weight: 700;
            line-height: 1.3;
        }

        .welcome-content {
            padding: 28px;
            overflow-y: auto;
            flex: 1;
        }

        .welcome-feature {
            display: flex;
            gap: 16px;
            margin-bottom: 24px;
            align-items: flex-start;
        }

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

        .welcome-icon {
            font-size: 2rem;
            flex-shrink: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 50px;
            height: 50px;
            background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
            border-radius: 12px;
        }

        .welcome-feature h3 {
            margin: 0 0 6px 0;
            font-size: 1.1rem;
            color: #0f172a;
            font-weight: 700;
        }

        .welcome-feature p {
            margin: 0;
            font-size: 0.95rem;
            color: #475569;
            line-height: 1.5;
        }

        .welcome-footer {
            padding: 20px 28px;
            border-top: 1px solid #e2e8f0;
            background: #f8fafc;
            display: flex;
            flex-direction: column;
            gap: 12px;
            align-items: center;
        }

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

        .welcome-checkbox {
            width: 18px;
            height: 18px;
            cursor: pointer;
            accent-color: #2563eb;
        }

        .welcome-checkbox-label {
            font-size: 0.9rem;
            color: #475569;
            cursor: pointer;
            user-select: none;
        }

        .welcome-start-btn {
            background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
            color: #ffffff;
            border: none;
            padding: 14px 40px;
            font-size: 1.05rem;
            font-weight: 700;
            border-radius: 10px;
            cursor: pointer;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            box-shadow: 0 8px 20px rgba(37, 99, 235, 0.3);
            min-height: 48px;
        }

        .welcome-start-btn:hover {
            background: linear-gradient(135deg, #0284c7 0%, #1d4ed8 100%);
            transform: translateY(-2px);
            box-shadow: 0 12px 28px rgba(37, 99, 235, 0.4);
        }

        .welcome-start-btn:active {
            transform: translateY(0);
            box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
        }

        /* Responsive adjustments for welcome modal */
        @media (max-width: 600px) {
            .welcome-modal {
                max-width: 95vw;
                max-height: 95vh;
            }

            .welcome-header {
                padding: 24px 20px 20px 20px;
            }

            .welcome-header h2 {
                font-size: 1.3rem;
            }

            .welcome-content {
                padding: 20px;
            }

            .welcome-feature {
                gap: 12px;
                margin-bottom: 20px;
            }

            .welcome-icon {
                width: 45px;
                height: 45px;
                font-size: 1.8rem;
            }

            .welcome-feature h3 {
                font-size: 1rem;
            }

            .welcome-feature p {
                font-size: 0.9rem;
            }

            .welcome-footer {
                padding: 16px 20px;
            }

            .welcome-checkbox-label {
                font-size: 0.85rem;
            }

            .welcome-start-btn {
                width: 100%;
                padding: 12px 24px;
                font-size: 1rem;
            }
        }

        #game-layer {
            display: flex;
            flex-direction: column;
            gap: 16px;
            width: 100%;
        }

        #game-sidebar {
            display: flex;
            flex-direction: column;
            gap: 14px;
            width: 100%;
        }

        #menu-layer {
            width: 100%;
            border: 1px solid #e2e8f0;
            border-radius: 16px;
            background: linear-gradient(160deg, #f8fbff 0%, #eef4ff 100%);
            padding: 18px;
            padding-bottom: 50px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 16px;
            box-sizing: border-box;
            min-height: 80vh;
        }

        #menu-dashboard {
            display: flex;
            flex-direction: column;
            gap: 20px;
            width: 100%;
            max-width: 800px;
            align-items: stretch;
        }

        @media (min-width: 1024px) {
            #menu-dashboard {
                flex-direction: row;
                max-width: 1200px;
                gap: 30px;
                align-items: flex-start;
            }
        }

        #menu-hero {
            background: #ffffff;
            border: 1px solid #e2e8f0;
            border-radius: 14px;
            padding: 18px;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        @media (min-width: 1024px) {
            #menu-hero {
                width: 380px;
                flex-shrink: 0;
            }
        }

        #menu-subtitle {
            margin: 0;
            color: #475569;
            line-height: 1.45;
            font-size: 0.98rem;
            text-align: center;
        }

        .streak-container {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            align-self: center;
            padding: 6px 12px;
            border-radius: 999px;
            font-weight: 700;
            font-size: 0.92rem;
            transition: transform 180ms ease, box-shadow 180ms ease, color 180ms ease, background 180ms ease;
        }

        .streak-flame {
            display: inline-flex;
            transition: filter 180ms ease;
        }

        .streak-inactive {
            background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%);
            color: #4b5563;
            box-shadow: 0 4px 10px rgba(107, 114, 128, 0.2);
        }

        .streak-inactive .streak-flame {
            filter: grayscale(100%) brightness(0.8);
        }

        .streak-active {
            background: linear-gradient(135deg, #f97316 0%, #ef4444 100%);
            color: #fff7ed;
            text-shadow: 0 0 10px rgba(255, 165, 0, 0.5);
            box-shadow: 0 6px 16px rgba(239, 68, 68, 0.25);
            animation: streak-pulse 1.8s ease-in-out infinite;
        }

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

        .streak-burst {
            animation: streak-burst 300ms ease-out;
        }

        @keyframes streak-pulse {
            0%, 100% {
                transform: scale(1);
                box-shadow: 0 6px 16px rgba(239, 68, 68, 0.25);
            }
            50% {
                transform: scale(1.03);
                box-shadow: 0 8px 20px rgba(249, 115, 22, 0.4);
            }
        }

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

        .streak-encouragement {
            margin: 2px 0 0 0;
            text-align: center;
            color: #334155;
            font-size: 0.9rem;
            font-weight: 600;
            line-height: 1.35;
        }

        #menu-title {
            text-align: center;
        }

        #btn-open-theory {
            margin-top: 6px;
            width: 100%;
            min-height: 52px;
            border-radius: 12px;
            background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
            color: #fff;
            font-weight: 700;
            font-size: 1rem;
            box-shadow: 0 10px 18px -10px rgba(37, 99, 235, 0.75);
        }

        #btn-open-theory:hover {
            background: linear-gradient(135deg, #0284c7 0%, #1d4ed8 100%);
        }

        #menu-modules {
            display: flex;
            flex-direction: column;
            width: 100%;
            gap: 15px;
            box-sizing: border-box;
        }

        @media (min-width: 1024px) {
            #menu-modules {
                flex: 1;
                min-width: 0;
            }
        }

        #menu-buttons {
            display: flex;
            flex-direction: column;
            gap: 15px;
            width: 100%;
            box-sizing: border-box;
        }

        .menu-action-card {
            width: 100%;
            box-sizing: border-box;
            min-width: 0;
            min-height: 58px;
            background: #ffffff;
            border: 1px solid #e2e8f0;
            border-radius: 12px;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            padding: 12px 14px;
            text-align: left;
            color: #0f172a;
            transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
            position: relative;
        }

        .menu-action-card:hover {
            transform: scale(1.02);
            border-color: #2563eb;
            box-shadow: 0 10px 18px -10px rgba(37, 99, 235, 0.55);
        }

        /* Survival Mode - Special Styling */
        .menu-action-card-survival {
            background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
            border: 2px solid #fbbf24;
            box-shadow: 0 4px 12px rgba(109, 40, 217, 0.3), 0 0 20px rgba(251, 191, 36, 0.2);
            animation: survival-pulse 2s ease-in-out infinite;
        }

        .menu-action-card-survival .menu-action-title,
        .menu-action-card-survival .menu-action-description {
            color: #ffffff;
        }

        .menu-action-card-survival .menu-action-icon {
            color: #fbbf24;
            font-size: 1.5rem;
        }

        .menu-action-card-survival:hover {
            transform: scale(1.04);
            border-color: #fcd34d;
            box-shadow: 0 12px 24px rgba(109, 40, 217, 0.5), 0 0 30px rgba(251, 191, 36, 0.4);
            background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
        }

        @keyframes survival-pulse {
            0%, 100% {
                box-shadow: 0 4px 12px rgba(109, 40, 217, 0.3), 0 0 20px rgba(251, 191, 36, 0.2);
            }
            50% {
                box-shadow: 0 4px 12px rgba(109, 40, 217, 0.5), 0 0 30px rgba(251, 191, 36, 0.4);
            }
        }

        .menu-action-content {
            display: flex;
            flex-direction: column;
            gap: 2px;
            min-width: 0;
            max-width: 100%;
        }

        .menu-action-title {
            font-size: 1rem;
            font-weight: 700;
            color: #0f172a;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .menu-action-description {
            font-size: 0.82rem;
            color: #64748b;
            white-space: normal;
            word-wrap: break-word;
            overflow-wrap: anywhere;
            line-height: 1.3;
        }

        .menu-action-icon {
            flex-shrink: 0;
            color: #2563eb;
            font-weight: 700;
            font-size: 0.9rem;
        }

        #menu-footer-actions {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
            justify-content: center;
            border-top: 1px solid #dbe3f0;
            padding-top: 12px;
            width: 100%;
            max-width: 800px;
            box-sizing: border-box;
        }

        @media (min-width: 1024px) {
            #menu-footer-actions {
                max-width: 1200px;
            }
        }

        .menu-secondary-btn {
            min-height: 50px;
            padding: 10px 14px;
            border-radius: 10px;
            border: 1px solid #cbd5e1;
            background: #ffffff;
            color: #1e293b;
            font-size: 0.92rem;
            font-weight: 600;
            box-shadow: 0 2px 4px rgba(15, 23, 42, 0.08);
        }

        .menu-secondary-btn:hover {
            border-color: #2563eb;
            color: #1d4ed8;
            background: #f8fbff;
        }

        /* Responsive typography for titles */
        h1, h2 {
            font-size: clamp(1.2rem, 4vw, 2rem);
            margin-top: 0;
        }

        h3 {
            font-size: clamp(1rem, 3vw, 1.5rem);
        }

        #menu-title,
        #task-instruction {
            word-wrap: break-word;
            white-space: normal;
        }

        #task-instruction {
            font-size: clamp(0.9rem, 2.5vw, 1.1rem);
            line-height: 1.5;
            background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
            padding: 15px 25px;
            border-radius: 10px;
            border-left: 4px solid #2196f3;
            box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
            text-align: center;
            font-weight: 600;
            margin: 15px 0;
            transition: all 0.3s ease;
        }

        #task-top-row {
            display: flex;
            gap: 15px;
            align-items: stretch;
            margin: 15px 0;
        }

        #task-top-row #task-instruction {
            flex: 1;
            margin: 0;
        }

        #trig-function-container {
            flex: 0 0 290px;
            max-width: 100%;
        }

        #trig-formula-display {
            height: 100%;
            background: #ffffff;
            border: 2px solid #d8dee8;
            border-radius: 10px;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
            padding: 12px 14px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            gap: 8px;
        }

        .formula-active {
            display: flex;
            align-items: center;
            gap: 8px;
            color: #1f2937;
            font-size: clamp(0.9rem, 2vw, 1.05rem);
            font-weight: 600;
        }

        #formula-function {
            min-width: 60px;
            color: #374151;
            font-weight: 700;
            text-transform: lowercase;
        }

        .formula-equals {
            color: #6b7280;
            font-weight: 600;
        }

        .formula-fraction-interactive {
            display: flex;
            flex-direction: column;
            align-items: center;
            line-height: 1;
            gap: 3px;
        }

        .fraction-box {
            width: 50px;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 2px solid #cbd5e1;
            border-radius: 6px;
            background: #f8fafc;
            color: #64748b;
            font-weight: 700;
            font-size: 1.1rem;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .fraction-box.glow {
            background: #fef3c7;
            border-color: #fbbf24;
            box-shadow: 0 0 12px rgba(251, 191, 36, 0.6), inset 0 0 8px rgba(251, 191, 36, 0.3);
            animation: pulse-glow 1.5s ease-in-out infinite;
        }

        @keyframes pulse-glow {
            0%, 100% {
                box-shadow: 0 0 12px rgba(251, 191, 36, 0.6), inset 0 0 8px rgba(251, 191, 36, 0.3);
            }
            50% {
                box-shadow: 0 0 20px rgba(251, 191, 36, 0.8), inset 0 0 12px rgba(251, 191, 36, 0.4);
            }
        }

        .fraction-box.filled {
            background: #ecfdf5;
            border-color: #10b981;
            color: #059669;
        }

        .fraction-box.filled-color {
            background: rgba(0, 0, 0, 0.02);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .fraction-box.filled-color:not(.glow) {
            box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
        }

        .fraction-divider {
            width: 48px;
            height: 2px;
            background: #334155;
            margin: 2px 0;
        }

        .formula-row {
            display: flex;
            align-items: center;
            gap: 8px;
            color: #1f2937;
            font-size: clamp(0.85rem, 2vw, 0.95rem);
            font-weight: 600;
        }

        .formula-label {
            min-width: 52px;
            color: #374151;
            font-weight: 700;
            text-transform: lowercase;
        }

        .formula-equals {
            color: #6b7280;
        }

        .formula-fraction {
            display: inline-flex;
            flex-direction: column;
            align-items: center;
            line-height: 1.05;
        }

        .formula-numerator,
        .formula-denominator {
            display: block;
            padding: 1px 8px;
            white-space: nowrap;
        }

        .formula-denominator {
            border-top: 2px solid #334155;
            margin-top: 3px;
            padding-top: 3px;
        }

        #task-instruction.instruction-updated {
            animation: pulse-instruction 0.6s ease-out;
        }

        #stat-box {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 12px 20px;
            border-radius: 8px;
            font-size: clamp(0.8rem, 3vw, 1.2rem);
            font-weight: 600;
            text-align: center;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
            margin: 10px 0;
        }

        #stat-box span {
            font-weight: 700;
            color: #fff;
        }

        #trig-choices-container {
            width: 100%;
            display: flex;
            justify-content: center;
            gap: 12px;
            flex-wrap: wrap;
            padding: 0 10px;
            box-sizing: border-box;
        }

        #trig-choices-container.hidden {
            display: none !important;
        }

        #canvas-container {
            width: 100%;
            max-width: 100vw;
            height: auto;
            aspect-ratio: 1 / 1;
            border: 1px solid #ccc;
            background: #fafafa;
            box-sizing: border-box;
            position: relative;
        }

        #ui-container {
            position: absolute;
            bottom: 10px;
            left: 10px;
            z-index: 100;
            display: flex;
            flex-direction: column;
            gap: 8px;
            max-width: 320px;
            background: rgba(255, 255, 255, 0.95);
            padding: 12px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        }

        #ui-container p {
            margin: 5px 0;
            font-size: 12px;
            color: #555;
        }

        /* Button styles for Side Selection (Steps 1 & 2) */
        .btn-side-choice {
            padding: 10px 16px !important;
            font-size: 14px !important;
            min-width: 150px !important;
            border-radius: 6px !important;
            font-weight: bold !important;
            color: white !important;
            border: none !important;
            cursor: pointer !important;
            transition: all 0.2s ease !important;
        }

        .btn-side-choice[data-side="motstående"] {
            background: #ff4d4d !important;
        }

        .btn-side-choice[data-side="motstående"]:hover {
            background: #ff6666 !important;
            transform: scale(1.02);
        }

        .btn-side-choice[data-side="hosliggende"] {
            background: #4d79ff !important;
        }

        .btn-side-choice[data-side="hosliggende"]:hover {
            background: #6699ff !important;
            transform: scale(1.02);
        }

        .btn-side-choice[data-side="hypotenus"] {
            background: #2eb82e !important;
        }

        .btn-side-choice[data-side="hypotenus"]:hover {
            background: #52c752 !important;
            transform: scale(1.02);
        }

        /* Neutral button styles for other steps */
        .btn-formula-choice,
        .btn-rearrange-choice {
            padding: 10px 16px !important;
            font-size: 1rem !important;
            min-width: 200px !important;
            border-radius: 6px !important;
            background: #e8e8e8 !important;
            color: #333 !important;
            border: 2px solid #ccc !important;
            font-weight: bold !important;
            cursor: pointer !important;
            transition: all 0.2s ease !important;
            justify-content: center;
        }

        .btn-formula-choice:hover,
        .btn-rearrange-choice:hover {
            background: #d0d0d0 !important;
            transform: scale(1.02);
        }

        /* Next button styles */
        #btn-step-next,
        #btn-finish-problem {
            padding: 10px 20px !important;
            font-size: 14px !important;
            min-width: 180px !important;
            border-radius: 6px !important;
            background: #2196F3 !important;
            color: white !important;
            border: none !important;
            font-weight: bold !important;
            cursor: pointer !important;
            transition: all 0.2s ease !important;
            margin-top: 8px !important;
        }

        #btn-step-next:hover {
            background: #0b7dda !important;
        }

        #btn-finish-problem {
            background: #28a745 !important;
        }

        #btn-finish-problem:hover {
            background: #218838 !important;
        }

        #game-start-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.98);
            backdrop-filter: blur(5px);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: clamp(2px, 1vw, 15px);
            padding: clamp(5px, 1vw, 30px);
            box-sizing: border-box;
            z-index: 1000;
            pointer-events: all;
        }

        #game-start-overlay.hidden {
            display: none;
        }

        #game-start-overlay h2 {
            margin: 0;
            font-size: clamp(1.5rem, 5vw, 2.5rem);
            color: #2c3e50;
            text-align: center;
            font-weight: 700;
        }

        #game-level-description {
            margin: 0;
            font-size: clamp(0.85rem, 2.5vw, 1.05rem);
            color: #555;
            text-align: center;
            max-width: 80%;
            line-height: 1.5;
        }

        #game-instructions-text {
            margin: 0;
            font-size: clamp(0.75rem, 2vw, 0.9rem);
            color: #999;
            text-align: center;
            max-width: 90%;
            line-height: 1.5;
            font-style: italic;
        }

        #btn-actual-start {
            padding: 18px 40px;
            font-size: clamp(1.1rem, 3vw, 1.4rem);
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 12px;
            cursor: pointer;
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            min-height: 60px;
        }

        #btn-actual-start:hover {
            transform: translateY(-3px);
            box-shadow: 0 10px 30px rgba(102, 126, 234, 0.5);
            background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
        }

        #btn-actual-start:active {
            transform: translateY(-1px);
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
        }

        #side-panel {
            width: 100%;
            max-width: 600px;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }

        #btn-back {
            margin-top: auto;
        }

        .btn-trig-choice {
            min-width: 100px;
            padding: 12px 22px;
            border-radius: 10px;
            border: 2px solid transparent;
            color: #000000;
            font-size: 1rem;
            font-weight: 700;
            letter-spacing: 0.5px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
            margin: 0;
            cursor: pointer;
        }

        .btn-trig-choice:hover {
            transform: translateY(-3px);
            filter: brightness(1.08);
            box-shadow: 0 7px 20px rgba(0, 0, 0, 0.25);
        }

        .btn-trig-choice:active {
            transform: translateY(-1px);
            box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
        }

        .btn-trig-choice.sin,
        .btn-trig-choice[data-function="sin"] {
            background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
            border-color: #1e40af;
        }

        .btn-trig-choice.sin:hover,
        .btn-trig-choice[data-function="sin"]:hover {
            background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
        }

        .btn-trig-choice.cos,
        .btn-trig-choice[data-function="cos"] {
            background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
            border-color: #166534;
        }

        .btn-trig-choice.cos:hover,
        .btn-trig-choice[data-function="cos"]:hover {
            background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
        }

        .btn-trig-choice.tan,
        .btn-trig-choice[data-function="tan"] {
            background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
            border-color: #92400e;
        }

        .btn-trig-choice.tan:hover,
        .btn-trig-choice[data-function="tan"]:hover {
            background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
        }

        /* Side selection buttons use the same color families as sin/cos/tan */
        .btn-trig-choice[data-side="motstående"] {
            background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
            border-color: #1e40af;
        }

        .btn-trig-choice[data-side="motstående"]:hover {
            background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
        }

        .btn-trig-choice[data-side="hosliggende"] {
            background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
            border-color: #166534;
        }

        .btn-trig-choice[data-side="hosliggende"]:hover {
            background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
        }

        .btn-trig-choice[data-side="hypotenus"] {
            background: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
            border-color: #92400e;
        }

        .btn-trig-choice[data-side="hypotenus"]:hover {
            background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
        }

        /* Neutral style for equation/formula option buttons (step 4) */
        .btn-trig-choice[data-option] {
            background: #f8fafc;
            border-color: #cbd5e1;
            color: #111827;
            box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
        }

        .btn-trig-choice[data-option]:hover {
            background: #f1f5f9;
            border-color: #94a3b8;
            color: #0f172a;
            transform: none;
            filter: none;
            box-shadow: 0 3px 8px rgba(15, 23, 42, 0.15);
        }

        .btn-trig-choice[data-option]:active {
            transform: none;
            box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
        }

        #canvas-container + #side-panel #ui-container {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            align-items: center;
            gap: 10px;
        }

        button {
            padding: 12px 20px;
            cursor: pointer;
            border: none;
            background: #007bff;
            color: white;
            border-radius: 5px;
            font-size: 16px;
            min-height: 44px;
            transition: background 0.2s ease;
        }

        button:hover {
            background: #0056b3;
        }

        #feedback-msg {
            font-weight: bold;
            font-size: 18px;
        }

        /* Mobile-friendly responsive design */
        @media (max-width: 768px) {
            #menu-layer {
                padding: 10px;
                padding-bottom: 28px;
                justify-content: flex-start;
            }

            #menu-dashboard {
                gap: 16px;
            }

            #task-instruction {
                margin: 0 !important;
                padding: 5px 3px;
            }

            /* Fixed Back button at bottom on mobile */
            #btn-back {
                position: fixed;
                bottom: 0;
                left: 0;
                width: 100%;
                margin: 0;
                padding: 15px;
                padding-bottom: max(15px, env(safe-area-inset-bottom));
                background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
                color: #ffffff;
                font-weight: 700;
                border-radius: 0;
                box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
                z-index: 1000;
                min-height: 54px;
            }

            #btn-back:hover {
                background: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
            }

            /* Add spacing to prevent content being covered by fixed button */
            #game-sidebar {
                padding-bottom: 10px;
                gap: 2px;
            }

            #game-layer {
                padding-bottom: 10px;
                gap: 2px;
            }

            #stat-box {
                margin-bottom: 0;
            }
        }

        @media (max-width: 600px) {
            body {
                padding: 10px;
            }

            #app-container {
                padding: 5px;
                border-radius: 8px;
            }

            #task-top-row {
                flex-direction: column;
                margin: 5px;
            }

            #trig-function-container {
                flex: 1 1 auto;
            }

            #trig-formula-display {
                padding: 10px 12px;
            }

            .btn-trig-choice {
                /*flex: 1 1 calc(33.333% - 5px);*/
                min-width: 90px;
                margin: 0;
                padding: 12px 8px;
                font-size: clamp(10px, 1rem, 1.5rem);
            }

            button {
                width: 100%;
                padding: 14px 20px;
            }

            #feedback-msg {
                font-size: 16px;
            }

            p {
                font-size: 14px;
            }

            #menu-layer {
                max-height: none;
                padding: 14px;
            }
        }

        @media (max-width: 400px) {
            h1 {
                font-size: 1.2rem;
            }
        }

        /* Feedback animations */
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
            20%, 40%, 60%, 80% { transform: translateX(8px); }
        }

        @keyframes green-flash {
            0%, 100% { border-color: #ccc; box-shadow: none; }
            50% { border-color: #28a745; box-shadow: 0 0 15px rgba(40, 167, 69, 0.6); }
        }

        @keyframes pulse-instruction {
            0% { transform: scale(1); border-left-color: #2196f3; }
            50% { transform: scale(1.02); border-left-color: #ff9800; box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3); }
            100% { transform: scale(1); border-left-color: #2196f3; }
        }

        #canvas-container.feedback-correct {
            animation: green-flash 0.5s ease-in-out;
        }

        #canvas-container.feedback-wrong {
            animation: shake 0.5s ease-in-out;
        }

        @media (orientation: landscape) and (max-height: 500px) {
            #game-layer {
                flex-direction: row;
                align-items: flex-start;
                justify-content: center;
            }

            #game-sidebar {
                max-width: 360px;
            }

            #canvas-container {
                width: auto;
                height: auto;
                max-height: 80vh;
                max-width: 80vh;
                flex: 0 0 auto;
            }
        }

        @media (min-width: 1024px) {
            #game-layer {
                flex-direction: row;
                align-items: stretch;
                gap: 20px;
                flex:1;
                height:0;
                width: 100%;
            }

            #game-sidebar {
                flex: 1 1 auto;
                min-width: 340px;
                padding: clamp(0px, 1vh, 18px);
                border-right: 2px solid #e0e7ff;
                background: linear-gradient(180deg, #f8fafc 0%, #f3f5fb 100%);
                border-radius: 0;
                box-shadow: inset -2px 0 8px rgba(0, 0, 0, 0.02);
                display: flex;
                flex-direction: column;
                gap: clamp(8px, 4vh, 18px);
                height: 100%;
                overflow-y: auto;
            }

            #stat-box {
                order: -2;
                margin: 0 !important;
                padding: clamp(8px, 4vh, 16px);
                font-size: 0.95rem;
                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                border-radius: 10px;
            }

            #task-top-row {
                order: -1;
                flex-direction: column;
                gap: 12px;
                align-items: stretch;
                margin: 0 !important;
            }

            #task-instruction {
                margin: 0 !important;
                padding: 14px 16px;
                font-size: clamp(0.8rem, 4vh, 2rem);
                line-height: 1.4;
            }

            #trig-function-container {
                flex: 0 0 auto;
                order: 0;
            }

            #trig-choices-container {
                order: 1;
                margin: 0 !important;
                flex-direction: column;
                width: 100%;
                padding: 0 !important;
            }

            #trig-choices-container .btn-trig-choice {
                width: 100%;
                padding: 10px 14px !important;
                font-size: 1rem !important;
                min-width: auto !important;
            }

            #side-panel {
                order: 2;
                margin: 0 !important;
                max-width: 100%;
                gap: 10px !important;
                margin-top: auto !important;
            }

            #side-panel button {
                padding: 11px 14px;
                font-size: 0.9rem;
                min-height: auto;
            }

            #canvas-container {
                display: flex;
                align-items: center;
                justify-content: center;
                overflow: hidden;
                flex: 3 1 auto;
                max-width: none;
                min-width: 560px;
                height: auto;
                border-radius: 10px;
            }
        }

        /* ==================== STATISTICS OVERLAY ==================== */
        #stats-layer {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: rgba(0, 0, 0, 0.95);
            display: flex;
            justify-content: center;
            z-index: 1000;
            padding: 20px;
            box-sizing: border-box;
            overflow-y: auto;
        }

        #stats-overlay {
            width: 100%;
            max-width: 1200px;
            background: #1a1a1a;
            border-radius: 12px;
            padding: 30px;
            color: #fff;
            box-sizing: border-box;
        }

        #stats-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            border-bottom: 2px solid #333;
            padding-bottom: 15px;
        }

        #stats-header h1 {
            margin: 0;
            color: #fff;
            font-size: 2em;
        }

        .btn-stats-close {
            background: #e74c3c;
            padding: 8px 16px;
            font-size: 14px;
        }

        .btn-stats-close:hover {
            background: #c0392b;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 20px;
        }

        .stats-card {
            background: #2a2a2a;
            border: 1px solid #444;
            border-radius: 8px;
            padding: 20px;
            position: relative;
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .btn-reset-task {
            position: absolute;
            top: 10px;
            right: 10px;
            width: 28px;
            height: 28px;
            border: 1px solid #555;
            border-radius: 6px;
            background: #1f1f1f;
            color: #ddd;
            cursor: pointer;
            font-size: 14px;
            line-height: 1;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .btn-reset-task:hover {
            background: #3a1f1f;
            border-color: #aa4a4a;
            color: #fff;
        }

        .stats-card-title {
            font-size: 1.1em;
            font-weight: 600;
            color: #fff;
        }

        .stats-card-stars {
            font-size: 1.3em;
            color: #f1c40f;
            display: flex;
            gap: 4px;
        }

        .stats-card-section {
            display: flex;
            flex-direction: column;
            gap: 8px;
            padding-top: 8px;
            border-top: 1px solid #444;
        }

        .stats-card-section:first-of-type {
            border-top: none;
            padding-top: 0;
        }

        .stats-card-section-title {
            font-size: 0.85em;
            font-weight: 600;
            color: #27ae60;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 4px;
        }

        .stats-card-row {
            display: flex;
            justify-content: space-between;
            font-size: 0.9em;
        }

        .stats-card-label {
            color: #aaa;
        }

        .stats-card-value {
            color: #fff;
            font-weight: 600;
        }

        .stats-progress-bar {
            width: 100%;
            height: 8px;
            background: #444;
            border-radius: 4px;
            overflow: hidden;
            margin: 10px 0;
        }

        .stats-progress-fill {
            height: 100%;
            background: linear-gradient(90deg, #27ae60 0%, #2ecc71 100%);
            border-radius: 4px;
            transition: width 0.3s ease;
        }

        .stats-card-row.mastery {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 0.85em;
            margin-top: 5px;
        }

        .btn-launch-level {
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
            border: none;
            color: white;
            padding: 10px 16px;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            font-size: 0.9em;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
            margin-top: auto;
        }

        .btn-launch-level:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
        }

        .btn-launch-level:active {
            transform: translateY(0);
        }

        .stats-details {
            display: none;
        }

        .btn-toggle-stats {
            background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
            border: none;
            color: white;
            padding: 8px 12px;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            font-size: 0.85em;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
            margin-top: 8px;
            align-self: flex-start;
        }

        .btn-toggle-stats:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(39, 174, 96, 0.4);
        }

        .btn-toggle-stats:active {
            transform: translateY(0);
        }

        /* Responsive grid */
        @media (max-width: 900px) {
            .stats-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        @media (max-width: 600px) {
            .stats-grid {
                grid-template-columns: 1fr;
            }

            #stats-overlay {
                padding: 20px;
            }

            #stats-header h1 {
                font-size: 1.5em;
            }
        }

        /* ==================== SETTINGS OVERLAY ==================== */
        #settings-layer {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: rgba(0, 0, 0, 0.95);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 1000;
            padding: 20px;
            box-sizing: border-box;
        }

        #settings-overlay {
            width: 100%;
            max-width: 700px;
            background: #1a1a1a;
            border-radius: 12px;
            padding: 30px;
            color: #fff;
            box-sizing: border-box;
            border: 1px solid #333;
        }

        #settings-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 24px;
            border-bottom: 2px solid #333;
            padding-bottom: 15px;
        }

        #settings-header h1 {
            margin: 0;
            color: #fff;
            font-size: 2em;
        }

        .btn-settings-close {
            background: #e74c3c;
            padding: 8px 16px;
            font-size: 14px;
        }

        .btn-settings-close:hover {
            background: #c0392b;
        }

        .settings-group {
            display: flex;
            flex-direction: column;
            gap: 8px;
            margin-bottom: 20px;
            padding: 14px;
            border-radius: 8px;
            background: #2a2a2a;
            border: 1px solid #444;
        }

        .settings-group label {
            color: #ddd;
            font-weight: 600;
            font-size: 0.95rem;
        }

        .settings-row {
            flex-direction: row;
            align-items: center;
            justify-content: space-between;
            gap: 14px;
        }

        .settings-row span {
            color: #ddd;
            font-weight: 600;
            font-size: 0.95rem;
        }

        .switch {
            position: relative;
            display: inline-block;
            width: 50px;
            height: 24px;
            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: #ccc;
            transition: .4s;
            border-radius: 34px;
        }

        .slider:before {
            position: absolute;
            content: "";
            height: 18px;
            width: 18px;
            left: 3px;
            bottom: 3px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
        }

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

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

        #setting-sfx-volume,
        #setting-music-volume {
            width: 100%;
            accent-color: #2ecc71;
        }

        @media (max-width: 600px) {
            #settings-overlay {
                padding: 20px;
            }

            #settings-header h1 {
                font-size: 1.5em;
            }
        }

        /* ========== SURVIVAL MODE STYLES ========== */

        /* Heart animations */
        #stat-box .survival-heart {
            display: inline-block;
            font-size: 1.2em;
            margin: 0 2px;
            color: #e74c3c;
            animation: heartbeat 1.2s ease-in-out infinite;
            transition: transform 0.1s ease;
        }

        #stat-box .survival-heart-lost {
            animation: none;
            opacity: 0.5;
            filter: grayscale(100%);
            transition: filter 0.3s ease;
        }

        /* OVERRIDE for lost hearts - This must be stronger! */
        #stat-box .survival-heart.lost-life {
            animation: none !important;
            filter: grayscale(100%) brightness(0.7) !important;
            opacity: 0.2 !important;
            transform: scale(0.8) !important;
            color: #666 !important; /* Forces a grey color if filter fails */
        }

        .lost-life {
            filter: grayscale(100%);
            opacity: 0.3;
            display: inline-block;
            transform: scale(0.9);
            transition: opacity 0.3s ease, filter 0.3s ease, transform 0.3s ease;
        }

        @keyframes heartbeat {
            0%, 100% {
                transform: scale(1);
            }
            50% {
                transform: scale(1.1);
            }
        }

        /* Shake animation for stat box when life is lost */
        #stat-box.stat-box-shake {
            animation: shake 0.3s cubic-bezier(.36, .07, .19, .97) both;
        }

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

        /* Survival mode result breakdown styling */
        .survival-error-breakdown {
            background: #fff3cd;
            padding: 15px;
            border-radius: 8px;
            margin: 15px 0;
            border-left: 4px solid #ffc107;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
        }

        .survival-error-breakdown h4 {
            margin: 0 0 12px 0;
            color: #856404;
            font-size: 1.05rem;
            font-weight: 600;
        }

        .survival-error-breakdown ul {
            margin: 0;
            padding-left: 20px;
            list-style-type: none;
        }

        .survival-error-breakdown li {
            margin: 8px 0;
            color: #856404;
            line-height: 1.4;
            position: relative;
            padding-left: 20px;
        }

        .survival-error-breakdown li:before {
            content: "▸";
            position: absolute;
            left: 0;
            font-weight: bold;
        }

        .survival-lifetime-stats {
            background: #e7f3ff;
            padding: 12px;
            border-radius: 6px;
            margin: 15px 0;
            border-left: 4px solid #0066cc;
            font-size: 0.95rem;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
        }

        .survival-lifetime-stats p {
            margin: 6px 0;
            color: #003366;
            line-height: 1.5;
        }

        .survival-lifetime-stats strong {
            font-weight: 700;
            color: #0052a3;
        }

        /* Victory overlay and message */
        #victory-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            display: none;
            align-items: center;
            justify-content: center;
            background: rgba(0, 0, 0, 0.7);
            backdrop-filter: blur(4px);
            z-index: 2000;
            padding: 16px;
            box-sizing: border-box;
        }

        #victory-message {
            max-width: 90%;
            width: 450px;
            max-height: 90vh;
            overflow-y: auto;
            background: #f8fafc;
            border: 3px solid #22c55e;
            border-radius: 16px;
            padding: 30px;
            box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2);
            text-align: center;
            animation: victory-slide-in 0.4s ease-out;
        }

        @keyframes victory-slide-in {
            from {
                opacity: 0;
                transform: translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* Responsive adjustments */
        @media (max-width: 600px) {
            .survival-error-breakdown,
            .survival-lifetime-stats {
                padding: 12px;
                font-size: 0.9rem;
            }

            .survival-error-breakdown h4 {
                font-size: 1rem;
            }

            #stat-box .survival-heart,
            #stat-box .survival-heart-lost {
                font-size: 1em !important;
                margin: 0 1px !important;
            }
        }

        /* Animation for button shake on wrong answer */
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
            20%, 40%, 60%, 80% { transform: translateX(5px); }
        }