body {
    font-family: 'Nunito', sans-serif;
    background: linear-gradient(135deg, #fefce8 0%, #e0f2fe 50%, #fce7f3 100%);
    min-height: 100vh;
    color: #0f172a;
    overflow-x: hidden;
}
.font-display {
    font-family: 'Fredoka', sans-serif;
}
.font-hand {
    font-family: 'Edu SA Hand', cursive;
}
/* Färgglada 3px ramar */
.border-3 {
    border-width: 3px;
    border-style: solid;
}
.border-b-3 {
    border-bottom-width: 3px;
    border-bottom-style: solid;
}
.btn-3d {
    transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.15s ease;
    box-shadow: 0 4px 0 rgba(15, 23, 42, 0.14);
}
.btn-3d:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 rgba(15, 23, 42, 0.16);
}
.btn-3d:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(15, 23, 42, 0.14);
}

/* Rutpapper för uppställning, textuppgifter & kladdblock */
.math-grid-paper {
    display: inline-grid;
    background-color: #ffffff;
    border: 2.5px solid #93c5fd;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(14, 116, 144, 0.08);
}
.math-grid-cell {
    width: 52px;
    height: 52px;
    border-right: 1px solid #cbd5e1;
    border-bottom: 1px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.55rem;
    font-weight: 700;
    position: relative;
    user-select: none;
}
.math-grid-cell:last-child {
    border-right: none;
}
.math-grid-row-line {
    border-bottom: 3.5px solid #0f172a !important;
}
.math-grid-input {
    width: 100%;
    height: 100%;
    text-align: center;
    background: transparent;
    border: none;
    outline: none;
    font-family: 'Edu SA Hand', cursive;
    font-size: 1.65rem;
    font-weight: 700;
    color: #0f172a;
    caret-color: #0284c7;
}
.level-step-card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    text-align: left;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 18px;
    padding: 12px 16px;
    font-family: 'Fredoka', sans-serif;
    transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.level-step-card:hover {
    border-color: #818cf8;
    background: #eef2ff;
    transform: translateY(-1px);
}
.level-step-num {
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #6366f1;
    color: #fff;
    font-weight: 900;
    font-size: 1.05rem;
}
.level-step-icon { font-size: 1.5rem; flex: none; }
.level-step-text { display: flex; flex-direction: column; }
.level-step-text strong { font-weight: 800; color: #1e293b; }
.level-step-text small { font-weight: 700; color: #94a3b8; font-size: 0.75rem; }
.level-explore-chip {
    padding: 8px 14px;
    border-radius: 999px;
    background: #fff;
    border: 2px solid #c7d2fe;
    color: #4338ca;
    font-weight: 800;
    font-size: 0.85rem;
    transition: background 0.12s ease, transform 0.12s ease;
}
.level-explore-chip:hover { background: #e0e7ff; transform: translateY(-1px); }
.level-step-stars { margin-left: auto; display: flex; gap: 1px; flex: none; }
.lvl-star { font-size: 1rem; color: #e2e8f0; transition: color 0.2s ease; }
.lvl-star.on { color: #f59e0b; text-shadow: 0 1px 2px rgba(245, 158, 11, 0.35); }
.level-explore-chip .level-step-stars { margin-left: 6px; }
.level-explore-chip .lvl-star { font-size: 0.75rem; }
.level-crumb-label .level-step-stars { display: inline-flex; margin-left: 6px; }
.level-crumb-label .lvl-star { font-size: 0.8rem; }

/* Grodhopp på tallinjen: båge som växer fram + hoppande groda */
.jump-arc {
    position: absolute;
    bottom: 0;
    border: 3px solid #059669;
    border-bottom: none;
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
    transform-origin: bottom center;
    animation: arcGrow 0.45s ease-out;
}
.jump-arc-label {
    position: absolute;
    transform: translateX(-50%);
    background: #fff;
    border: 2px solid #059669;
    color: #047857;
    font-weight: 900;
    font-size: 0.7rem;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 999px;
    box-shadow: 0 1px 3px rgba(4, 120, 87, 0.2);
    animation: labelPop 0.45s ease-out;
    white-space: nowrap;
}
@keyframes labelPop {
    0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
    100% { opacity: 1; transform: translateX(-50%) scale(1); }
}
@keyframes arcGrow {
    0% { transform: scaleY(0); opacity: 0; }
    60% { opacity: 1; }
    100% { transform: scaleY(1); opacity: 1; }
}
@keyframes frogHop {
    0% { transform: translateY(0) scale(1); }
    40% { transform: translateY(-16px) scale(1.15); }
    100% { transform: translateY(0) scale(1); }
}
.frog-hop { animation: frogHop 0.45s ease; }

.math-grid-input::placeholder {
    color: #94a3b8;
    opacity: 0.55;
    font-family: 'Fredoka', sans-serif;
}
.math-grid-input:focus {
    background-color: #e0f2fe;
    box-shadow: inset 0 0 0 2.5px #0284c7;
}
/* Liten grön minnessiffra / 10-lån överst */
.math-grid-carry-input {
    font-family: 'Edu SA Hand', cursive !important;
    font-size: 1.15rem !important;
    font-weight: 700 !important;
    color: #059669 !important;
    padding-top: 8px;
}

/* Överstruken siffra vid växling / lån */
.digit-struck {
    position: relative;
    color: #94a3b8 !important;
}
div.digit-struck::after {
    content: '';
    position: absolute;
    left: 18%;
    right: 18%;
    top: 50%;
    height: 3.5px;
    background-color: #ef4444;
    border-radius: 999px;
    transform: translateY(-50%) rotate(-26deg);
    pointer-events: none;
    z-index: 5;
}
input.digit-struck {
    background-image: linear-gradient(
        to top left,
        transparent calc(50% - 2px),
        #ef4444 calc(50% - 1.5px),
        #ef4444 calc(50% + 1.5px),
        transparent calc(50% + 2px)
    ) !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: 66% 66% !important;
}

/* Felmarkering i svarsrutor – visar exakt vilken talsort som brast */
.cell-wrong {
    border-color: #ef4444 !important;
    background-color: #fef2f2 !important;
    color: #b91c1c !important;
    animation: cellShake .4s ease;
}
.cell-right {
    border-color: #10b981 !important;
    background-color: #ecfdf5 !important;
}
@keyframes cellShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* Staplade bråk & blandad form */
.stacked-frac {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    line-height: 1.05;
    margin: 0 3px;
}
.stacked-frac-num {
    padding: 0 5px 2px 5px;
    border-bottom: 2.5px solid currentColor;
    font-weight: 800;
}
.stacked-frac-den {
    padding: 2px 5px 0 5px;
    font-weight: 800;
}
.stacked-mixed {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    vertical-align: middle;
}
.stacked-mixed-whole {
    font-size: 1.45em;
    font-weight: 800;
    line-height: 1;
}

/* Hjälptabell hover & låst markering */
.mult-table-cell {
    transition: background-color 0.1s ease, color 0.1s ease, transform 0.1s ease;
}
.mult-hl-row-col {
    background-color: #fef08a !important;
    color: #713f12 !important;
}
.mult-hl-header {
    background-color: #f59e0b !important;
    color: #ffffff !important;
}
.mult-hl-active {
    background-color: #fb923c !important;
    color: #ffffff !important;
    transform: scale(1.08);
    box-shadow: 0 2px 8px rgba(234, 88, 12, 0.35);
    z-index: 2;
}

/* Animationer för visuella ledtrådar & pilar */
@keyframes hintStepReveal {
    0% { opacity: 0; transform: translateY(10px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes drawSvgPath {
    from { stroke-dashoffset: 320; }
    to { stroke-dashoffset: 0; }
}
@keyframes pulseGlowRing {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.12); opacity: 0.45; }
}
@keyframes arrowNudgeRight {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(4px); }
}
.hint-step-card {
    animation: hintStepReveal 0.38s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes hintBoxIn {
    0% { opacity: 0; transform: translateY(14px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
.hint-box-enter { animation: hintBoxIn 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
.svg-arc-draw {
    stroke-dasharray: 320;
    stroke-dashoffset: 320;
    animation: drawSvgPath 0.85s ease-out forwards;
}
.svg-arc-draw-delay {
    stroke-dasharray: 320;
    stroke-dashoffset: 320;
    animation: drawSvgPath 0.85s ease-out 0.35s forwards;
}
.hint-pulse-ring {
    transform-origin: center;
    transform-box: fill-box;
    animation: pulseGlowRing 1.4s ease-in-out infinite;
}
.hint-arrow-nudge {
    display: inline-block;
    animation: arrowNudgeRight 1.1s ease-in-out infinite;
}

/* Lugn vy (Fokusläge) */
body.focus-mode-active {
    background: #f8fafc !important;
}
body.focus-mode-active .gamification-badge {
    display: none !important;
}
    

/* Klockvisare som sveper från 12 till rätt läge */
.clock-hand {
    transform-box: view-box;
    transform-origin: center;
    animation: clockHandSweep 0.85s cubic-bezier(0.3, 1.35, 0.45, 1) both;
}
.clock-hand-hour {
    animation-duration: 0.65s;
}
@keyframes clockHandSweep {
    from { transform: rotate(0deg); }
    to { transform: rotate(var(--hand-rot, 0deg)); }
}

/* Bråk-av-antal: högar poppar in med fördröjning */
.pile-pop {
    animation: pilePop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes pilePop {
    from { transform: scale(0.3) translateY(10px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

/* Respektera animationskänsliga användare */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Kortbyte: ny fråga skjuts in från höger vid varje genererad fråga */
@keyframes cardIn {
    from { opacity: 0; transform: translateX(46px) scale(0.98); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}
.card-in { animation: cardIn 0.38s cubic-bezier(0.22, 0.9, 0.3, 1) both; }

@keyframes cardCorrect {
    0% { transform: scale(1); }
    35% { transform: scale(1.018) rotate(0.6deg); }
    70% { transform: scale(0.996) rotate(-0.4deg); }
    100% { transform: scale(1) rotate(0deg); }
}
.card-correct { animation: cardCorrect 0.42s cubic-bezier(0.3, 0.9, 0.4, 1) both; }

@keyframes cardWrong {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-7px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(2px); }
}
.card-wrong { animation: cardWrong 0.4s ease-out both; }

/* Svarsknappar: grön pulse vid rätt, skak + urgråning vid fel */
@keyframes optCorrectPulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.07); }
    100% { transform: scale(1); }
}
.opt-correct {
    animation: optCorrectPulse 0.45s cubic-bezier(0.3, 0.9, 0.4, 1) both;
    background: #d1fae5 !important;
    border-color: #059669 !important;
    color: #064e3b !important;
}
.opt-wrong {
    animation: cardWrong 0.4s ease-out both;
    opacity: 0.45;
    filter: grayscale(55%);
}

/* Sifferchips: tal i frågetexter och feedback får en markerad "piller" */
.qnum {
    display: inline-block;
    padding: 0 0.32em;
    margin: 0 0.04em;
    border-radius: 0.5em;
    background: #fef3c7;
    color: #78350f;
    font-weight: 800;
    border-bottom: 2px solid #fbbf24;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

/* Platsvärdesfärger: ental grön, tiotal blå, hundratal röd, tusental lila */
.pv-1 { color: #059669; font-weight: 800; }
.pv-10 { color: #0284c7; font-weight: 800; }
.pv-100 { color: #e11d48; font-weight: 800; }
.pv-1000 { color: #9333ea; font-weight: 800; }
.pv-col-1 { background: rgba(16, 185, 129, 0.10) !important; }
.pv-col-10 { background: rgba(2, 132, 199, 0.10) !important; }
.pv-col-100 { background: rgba(225, 29, 72, 0.10) !important; }
.pv-col-1000 { background: rgba(147, 51, 234, 0.10) !important; }

/* Miniatyr-uppställning i ledtrådssteg */
.math-grid-mini .math-grid-cell {
    width: 34px;
    height: 32px;
    font-size: 1.05rem;
}
.math-grid-mini .math-grid-carry {
    font-family: 'Edu SA Hand', cursive;
    font-size: 0.8rem;
    font-weight: 700;
    color: #059669;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 2px;
}
.math-grid-mini .cell-hl {
    box-shadow: inset 0 0 0 2.5px #f59e0b;
    background: rgba(245, 158, 11, 0.14) !important;
}
