@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Nunito:wght@400;600;700;800;900&display=swap');

:root {
    --font-heading: 'Fredoka', 'Nunito', system-ui, sans-serif;
    --font-body: 'Nunito', system-ui, -apple-system, sans-serif;

    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --primary-shadow: #4338CA;

    --secondary: #8B5CF6;
    --secondary-shadow: #7C3AED;

    --accent-gold: #F59E0B;
    --accent-gold-shadow: #D97706;

    --success: #10B981;
    --success-shadow: #059669;

    --error: #EF4444;
    --error-shadow: #DC2626;

    --bg: #EEF2FF;
    --card-bg: #FFFFFF;
    --text-main: #1E1B4B;
    --text-muted: #64748B;

    --radius-lg: 28px;
    --radius: 20px;
    --radius-sm: 12px;

    --shadow: 0 12px 28px -4px rgba(99, 102, 241, 0.12), 0 6px 12px -2px rgba(0, 0, 0, 0.04);
    --shadow-hover: 0 20px 32px -4px rgba(99, 102, 241, 0.2), 0 8px 16px -2px rgba(0, 0, 0, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-body);
}

body {
    background-color: #EBF4FF;
    background-image:
        radial-gradient(at 10% 20%, rgba(224, 242, 254, 0.6) 0px, transparent 50%),
        radial-gradient(at 90% 80%, rgba(238, 242, 255, 0.6) 0px, transparent 50%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='140' viewBox='0 0 220 140'%3E%3Cg fill='%23FFFFFF' fill-opacity='0.55'%3E%3Cpath d='M30,85 C18,85 10,76 10,64 C10,54 17,46 26,44 C30,28 45,16 62,16 C76,16 88,25 93,37 C99,32 107,28 115,28 C129,28 140,38 142,52 C150,53 156,61 156,70 C156,79 148,85 138,85 Z'/%3E%3Cpath d='M130,120 C122,120 115,114 115,106 C115,99 120,93 127,91 C130,79 140,70 152,70 C162,70 171,77 175,86 C180,82 186,79 193,79 C204,79 213,87 214,97 C220,98 225,104 225,110 C225,117 219,120 211,120 Z'/%3E%3C/g%3E%3C/svg%3E");
    background-repeat: repeat;
    background-position: 0 0;
    background-attachment: fixed;
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 2rem 0;
}

h1,
h2,
h3,
h4,
.font-heading {
    font-family: var(--font-heading);
}

/* Global Container */
.container {
    width: 100%;
    max-width: 720px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 auto;
}

/* Playful 3D Buttons */
.btn-start,
.btn-3d {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--primary);
    color: white;
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    padding: 0.85rem 2.25rem;
    border-radius: 99px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 0 var(--primary-shadow), 0 10px 20px rgba(99, 102, 241, 0.25);
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-start:hover,
.btn-3d:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 var(--primary-shadow), 0 14px 24px rgba(99, 102, 241, 0.3);
    filter: brightness(1.05);
}

.btn-start:active,
.btn-3d:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--primary-shadow), 0 4px 10px rgba(99, 102, 241, 0.2);
}

/* Color variations for buttons */
.btn-purple {
    background: var(--secondary);
    box-shadow: 0 6px 0 var(--secondary-shadow), 0 10px 20px rgba(139, 92, 246, 0.25);
}

.btn-purple:hover {
    box-shadow: 0 8px 0 var(--secondary-shadow), 0 14px 24px rgba(139, 92, 246, 0.3);
}

.btn-purple:active {
    box-shadow: 0 2px 0 var(--secondary-shadow), 0 4px 10px rgba(139, 92, 246, 0.2);
}

.btn-green {
    background: var(--success);
    box-shadow: 0 6px 0 var(--success-shadow), 0 10px 20px rgba(16, 185, 129, 0.25);
}

.btn-green:hover {
    box-shadow: 0 8px 0 var(--success-shadow), 0 14px 24px rgba(16, 185, 129, 0.3);
}

.btn-green:active {
    box-shadow: 0 2px 0 var(--success-shadow), 0 4px 10px rgba(16, 185, 129, 0.2);
}

.btn-gold {
    background: var(--accent-gold);
    box-shadow: 0 6px 0 var(--accent-gold-shadow), 0 10px 20px rgba(245, 158, 11, 0.25);
}

.btn-gold:hover {
    box-shadow: 0 8px 0 var(--accent-gold-shadow), 0 14px 24px rgba(245, 158, 11, 0.3);
}

.btn-gold:active {
    box-shadow: 0 2px 0 var(--accent-gold-shadow), 0 4px 10px rgba(245, 158, 11, 0.2);
}

/* Master Input (Hidden) */
#master-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
    color: transparent;
    background: transparent;
    outline: none;
}

/* Flashcard Container */
.flashcard-wrapper {
    position: relative;
    width: 100%;
    height: 400px;
    perspective: 1000px;
}

.flashcard {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 3px solid rgba(224, 231, 255, 0.8);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    position: absolute;
    top: 0;
    left: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.flashcard.slide-out-left {
    transform: translateX(-120%) rotateY(-15deg);
    opacity: 0;
}

.flashcard.slide-in-right {
    transform: translateX(120%) rotateY(15deg);
    opacity: 0;
}

/* Typography for Math Problems */
.math-problem {
    font-family: var(--font-heading);
    font-size: 6rem;
    font-weight: 700;
    letter-spacing: -2px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    width: 100%;
    white-space: nowrap;
}

/* Visual Answer Input Slot */
.visual-input {
    display: inline-block;
    font-family: var(--font-heading);
    width: 180px;
    min-height: 6rem;
    border-bottom: 8px solid #CBD5E1;
    border-radius: 8px 8px 0 0;
    text-align: center;
    color: var(--primary);
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.visual-input.correct {
    color: var(--success);
    border-color: var(--success);
    background: #ECFDF5;
}

.visual-input.wrong {
    color: var(--error);
    border-color: var(--error);
    background: #FEF2F2;
    animation: shake 0.4s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-3px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(5px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-7px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(7px, 0, 0);
    }
}

.header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-muted);
    font-family: var(--font-heading);
}

.progress-container {
    width: 100%;
    height: 16px;
    background: #E2E8F0;
    border-radius: 99px;
    margin-bottom: 2.5rem;
    overflow: hidden;
    padding: 3px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #F59E0B 0%, #10B981 100%);
    border-radius: 99px;
    width: 0%;
    transition: width 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    body {
        align-items: flex-start;
        padding: 0.25rem 0;
    }

    .container {
        padding: 0.5rem 0.75rem;
        margin: 0 auto;
    }

    .flashcard-wrapper {
        height: 220px;
    }

    .flashcard {
        padding: 1rem 0.75rem;
    }

    .math-problem {
        font-size: 4rem;
        gap: 0.5rem;
    }

    .visual-input {
        width: 105px;
        min-height: 3.2rem;
        border-bottom-width: 5px;
    }

    .header {
        font-size: 0.95rem;
        margin-bottom: 0.35rem;
    }

    .progress-container {
        height: 12px;
        margin-bottom: 0.75rem;
    }
}

/* Concept Hint Button in Header */
.btn-concept-hint {
    background: #FEF3C7;
    color: #B45309;
    border: 2px solid #FCD34D;
    border-radius: 99px;
    padding: 0.35rem 0.85rem;
    font-size: 0.9rem;
    font-weight: 800;
    font-family: var(--font-heading);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
    box-shadow: 0 3px 0 #D97706;
}

.btn-concept-hint:hover {
    background: #FDE68A;
    transform: translateY(-1px);
}

.btn-concept-hint:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #D97706;
}

/* =========================================
   CONCEPT INTRO MODAL
   ========================================= */
.intro-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(30, 27, 75, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 1rem;
    animation: fadeIn 0.3s ease;
}

.intro-modal-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(99, 102, 241, 0.35);
    border: 4px solid #EEF2FF;
    width: 100%;
    max-width: 500px;
    padding: 1.75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    animation: slideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.intro-header {
    text-align: center;
}

.level-badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 700;
    padding: 0.3rem 1rem;
    border-radius: 99px;
    margin-bottom: 0.4rem;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.25);
}

.intro-title {
    font-family: var(--font-heading);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-main);
}

.worked-example-board {
    width: 100%;
    background: #F8FAFC;
    border: 2px solid #E2E8F0;
    border-radius: 16px;
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.column-table {
    display: grid;
    grid-template-columns: 35px 70px 70px;
    gap: 0.5rem;
    font-family: var(--font-heading);
    font-size: 2.2rem;
    font-weight: 700;
    text-align: center;
    position: relative;
    align-items: center;
}

.col-header {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--text-muted);
    border-bottom: 2px dashed #CBD5E1;
    padding-bottom: 0.25rem;
}

.col-tens {
    color: #6366F1;
}

.col-ones {
    color: #EC4899;
}

.col-op {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.row-line {
    grid-column: span 3;
    height: 4px;
    background: var(--text-main);
    border-radius: 2px;
    margin: 0.25rem 0;
}

/* Vertical Bersusun Card Layout (Level 5-8) */
.vertical-math-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin: 0 auto;
}

.vertical-table {
    display: grid;
    grid-template-columns: 35px 35px 35px;
    justify-content: center;
    row-gap: 0.25rem;
    font-family: var(--font-heading);
    font-size: 2.75rem;
    font-weight: 700;
    text-align: center;
    align-items: center;
}

.col-ans-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 3rem;
}

.vertical-input {
    width: 100%;
    min-height: 3.5rem;
    border-bottom: 5px solid #CBD5E1;
    border-radius: 4px 4px 0 0;
    display: grid;
    grid-template-columns: 35px 35px;
    gap: 0;
    align-items: center;
    justify-content: center;
    background: transparent;
    padding: 0;
}

.vertical-input.correct {
    color: var(--success);
    border-color: var(--success);
    background: #ECFDF5;
}

.vertical-input.wrong {
    color: var(--error);
    border-color: var(--error);
    background: #FEF2F2;
    animation: shake 0.4s cubic-bezier(.36, .07, .19, .97) both;
}

.vertical-input .tens-digit,
.vertical-input .ones-digit {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 35px;
    height: 100%;
    font-family: var(--font-heading);
    font-size: 2.75rem;
    font-weight: 700;
    text-align: center;
    color: var(--primary);
}

@media (max-width: 480px) {
    .vertical-table {
        grid-template-columns: 30px 30px 30px;
        font-size: 2.2rem;
        row-gap: 0.2rem;
    }

    .vertical-input {
        grid-template-columns: 30px 30px;
        min-height: 2.8rem;
    }

    .vertical-input .tens-digit,
    .vertical-input .ones-digit {
        width: 30px;
        font-size: 2.2rem;
    }
}

.btn-card-hint {
    position: absolute;
    top: 14px;
    right: 18px;
    background: transparent;
    border: none;
    font-size: 1.6rem;
    cursor: pointer;
    opacity: 0.7;
    transition: transform 0.2s, opacity 0.2s;
    z-index: 10;
}

.btn-card-hint:hover {
    opacity: 1;
    transform: scale(1.25);
}

.carry-tens-wrapper {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.carry-digit-float {
    position: absolute;
    top: -22px;
    left: 50%;
    font-size: 1.3rem;
    color: #10B981;
    font-weight: 900;
    opacity: 0;
    animation: shiftToTens 5.5s ease-out forwards;
}

.borrow-tens-wrapper {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
    min-height: 2.5rem;
    width: 100%;
}

.tens-orig {
    font-size: 2.2rem;
    font-weight: 800;
    color: #6366F1;
    animation: origToCross 6.5s ease-out forwards;
}

.tens-crossed {
    position: absolute;
    top: -2px;
    font-size: 1.2rem;
    font-weight: 800;
    text-decoration: line-through #EF4444 3px;
    color: #9CA3AF;
    opacity: 0;
    animation: fadeInCross 6.5s ease-out forwards;
}

.tens-new {
    position: absolute;
    bottom: -6px;
    font-size: 1.8rem;
    font-weight: 800;
    color: #10B981;
    opacity: 0;
    animation: fadeInNew 6.5s ease-out forwards;
}

.ones-borrow-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ones-borrow-wrapper .borrow-digit-float {
    position: absolute;
    left: -24px;
    top: 0px;
    font-size: 2.2rem;
    color: #F59E0B;
    font-weight: 900;
    opacity: 0;
    animation: borrowToOnes 6.5s ease-out forwards;
}

@keyframes shiftToTens {

    0%,
    58% {
        transform: translate(50px, 30px) scale(0.5);
        opacity: 0;
    }

    72% {
        transform: translate(-50%, -5px) scale(1.2);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, 0px) scale(1);
        opacity: 1;
    }
}

@keyframes borrowToOnes {

    0%,
    55% {
        transform: translate(-35px, 20px) scale(0.5);
        opacity: 0;
    }

    75% {
        transform: translate(0px, 0px) scale(1.2);
        opacity: 1;
    }

    100% {
        transform: translate(0px, 0px) scale(1);
        opacity: 1;
    }
}

@keyframes origToCross {

    0%,
    35% {
        opacity: 1;
        transform: scale(1);
    }

    45%,
    100% {
        opacity: 0;
        transform: scale(0.8);
    }
}

@keyframes fadeInCross {

    0%,
    35% {
        opacity: 0;
    }

    45%,
    100% {
        opacity: 1;
    }
}

@keyframes fadeInNew {

    0%,
    35% {
        opacity: 0;
        transform: translateY(5px);
    }

    55%,
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.intro-narration-box {
    background: #EFF6FF;
    border-left: 4px solid var(--primary);
    padding: 0.9rem 1.1rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    width: 100%;
}

.btn-audio-speaker {
    background: white;
    border: 2px solid #DBEAFE;
    font-size: 1.5rem;
    padding: 0.45rem;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
    transition: transform 0.15s;
}

.btn-audio-speaker:hover {
    transform: scale(1.1);
}

.intro-narration-text {
    font-size: 0.95rem;
    line-height: 1.45;
    color: #1E40AF;
    font-weight: 700;
}

.intro-footer {
    display: flex;
    justify-content: space-between;
    width: 100%;
    gap: 1rem;
}

.btn-secondary {
    background: #F1F5F9;
    color: #475569;
    font-family: var(--font-heading);
    font-weight: 700;
    padding: 0.75rem 1.5rem;
    border-radius: 99px;
    border: 2px solid #E2E8F0;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.2s, transform 0.15s;
}

.btn-secondary:hover {
    background: #E2E8F0;
    transform: translateY(-1px);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

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

    to {
        transform: translateY(0);
    }
}