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

:root {
    --primary: #4361EE;
    --primary-light: #6B83F2;
    --primary-dark: #3451D1;
    --secondary: #7209B7;
    --success: #06D6A0;
    --success-light: #D4F5E9;
    --error: #EF476F;
    --error-light: #FDE2E9;
    --warning: #FFD166;
    --dark: #1A1A2E;
    --dark-soft: #2D2D44;
    --gray: #6B7280;
    --gray-light: #9CA3AF;
    --gray-lighter: #E5E7EB;
    --bg: #F0F2F5;
    --card: #FFFFFF;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 4px 24px rgba(0,0,0,0.08);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-hover: 0 8px 32px rgba(67,97,238,0.18);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html { font-size: 16px; }

body {
    font-family: 'Nunito', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--dark);
    min-height: 100vh;
    line-height: 1.6;
}

/* ============ HEADER ============ */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 0 2rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 16px rgba(67,97,238,0.3);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    text-decoration: none;
    color: white;
}

.header-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.2rem;
    backdrop-filter: blur(8px);
    border: 2px solid rgba(255,255,255,0.3);
}

.header-title {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.header-subtitle {
    font-size: 0.75rem;
    opacity: 0.8;
    font-weight: 600;
}

.header-back {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    backdrop-filter: blur(4px);
}

.header-back:hover { background: rgba(255,255,255,0.25); }

/* ============ DASHBOARD ============ */
.dashboard {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.welcome {
    text-align: center;
    margin-bottom: 2.5rem;
}

.welcome h1 {
    font-size: 2rem;
    font-weight: 900;
    color: var(--dark);
    margin-bottom: 0.25rem;
}

.welcome p {
    color: var(--gray);
    font-size: 1.05rem;
}

.topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
}

.topic-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.topic-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary-light);
}

.topic-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.topic-card.locked:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
    border-color: transparent;
}

.topic-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    margin-bottom: 1rem;
    color: white;
    font-weight: 800;
}

.topic-card h3 {
    font-size: 1.05rem;
    font-weight: 800;
    margin-bottom: 0.25rem;
    color: var(--dark);
}

.topic-card p {
    font-size: 0.85rem;
    color: var(--gray);
    margin-bottom: 1rem;
}

.progress-bar-container {
    background: var(--gray-lighter);
    border-radius: 100px;
    height: 8px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 100px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    transition: width 0.6s ease;
}

.topic-card .progress-text {
    font-size: 0.8rem;
    color: var(--gray);
    font-weight: 700;
}

.stars-row {
    display: flex;
    gap: 2px;
    margin-top: 0.5rem;
}

.star {
    font-size: 1rem;
    color: var(--gray-lighter);
}

.star.earned { color: var(--warning); }

/* ============ TOPIC VIEW ============ */
.topic-view {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.topic-header {
    text-align: center;
    margin-bottom: 2rem;
}

.topic-header h1 {
    font-size: 1.75rem;
    font-weight: 900;
    margin-bottom: 0.25rem;
}

.topic-header p {
    color: var(--gray);
}

.sections-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.section-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
}

.section-card:hover {
    transform: translateX(6px);
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
}

.section-number {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.section-card.completed .section-number {
    background: var(--success);
}

.section-info { flex: 1; }

.section-info h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.section-info p {
    font-size: 0.85rem;
    color: var(--gray);
}

.section-stars {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.section-stars .star { font-size: 1.3rem; }

/* ============ THEORY VIEW ============ */
.theory-view {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1.5rem 100px;
}

.theory-view h2 {
    font-size: 1.5rem;
    font-weight: 900;
    margin-bottom: 1.5rem;
    color: var(--dark);
}

.theory-steps { display: flex; flex-direction: column; gap: 1rem; }

.theory-step {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 4px solid var(--primary);
}

.theory-step.visible {
    opacity: 1;
    transform: translateY(0);
}

.theory-step.highlight {
    border-left-color: var(--warning);
    background: #FFFBEB;
}

.theory-step.example {
    border-left-color: var(--success);
    background: #F0FDF9;
}

.theory-step.danger {
    border-left-color: var(--error);
    background: #FFF5F7;
}

.theory-step h3 {
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.theory-step.highlight h3 { color: #B45309; }
.theory-step.example h3 { color: #059669; }
.theory-step.danger h3 { color: var(--error); }

.theory-step p {
    margin-bottom: 0.5rem;
    line-height: 1.7;
}

.theory-step p:last-child { margin-bottom: 0; }

.math {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--dark);
    text-align: center;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin: 0.75rem 0;
    letter-spacing: 0.5px;
    font-family: 'Nunito', sans-serif;
}

/* Fracciones visuales */
.frac {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 4px;
    font-family: 'Nunito', sans-serif;
}
.frac-num, .frac-den {
    font-weight: 800;
    line-height: 1.2;
    padding: 0 4px;
}
.frac-line {
    width: 100%;
    height: 2px;
    background: currentColor;
    min-width: 20px;
}
.math .frac-num, .math .frac-den { font-size: 1rem; }
.math-inline .frac-num, .math-inline .frac-den { font-size: 0.85rem; }
p .frac-num, p .frac-den { font-size: 0.9rem; }

.math-inline {
    font-weight: 700;
    font-family: 'Courier New', monospace;
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Number Line */
.number-line {
    position: relative;
    margin: 1.5rem 0;
    padding: 2rem 0 1rem;
    overflow-x: auto;
}

.number-line-track {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    position: relative;
    min-width: fit-content;
    margin: 0 auto;
}

.number-line-track::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--dark);
    transform: translateY(-50%);
}

.number-line-track::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -2px;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-left: 10px solid var(--dark);
}

.nl-point {
    position: relative;
    width: 44px;
    text-align: center;
    z-index: 1;
    flex-shrink: 0;
}

.nl-point::before {
    content: '';
    display: block;
    width: 3px;
    height: 14px;
    background: var(--dark);
    margin: 0 auto 4px;
}

.nl-point span {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--dark);
}

.nl-point.zero span {
    color: var(--primary);
    font-size: 1rem;
}

.nl-point.negative span { color: var(--error); }
.nl-point.positive span { color: var(--success); }

/* Interactive Number Line */
.nl-interactive {
    position: relative;
    margin: 1.5rem auto;
    padding: 2.5rem 1rem 2rem;
    max-width: 100%;
    overflow-x: auto;
}

.nl-interactive .nl-track {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    position: relative;
    height: 80px;
    min-width: fit-content;
    margin: 0 auto;
}

.nl-interactive .nl-track::before {
    content: '';
    position: absolute;
    bottom: 30px;
    left: 8px;
    right: 8px;
    height: 3px;
    background: var(--dark);
}

.nl-interactive .nl-tick {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 40px;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
    padding-bottom: 0;
    transition: var(--transition);
}

.nl-interactive .nl-tick:hover .nl-dot {
    background: var(--primary);
    transform: scale(1.5);
}

.nl-interactive .nl-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gray-light);
    border: 2px solid var(--dark);
    margin-bottom: 6px;
    transition: var(--transition);
    position: relative;
    z-index: 2;
}

.nl-interactive .nl-tick.zero .nl-dot {
    background: var(--primary);
    width: 14px;
    height: 14px;
}

.nl-interactive .nl-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--gray);
    user-select: none;
}

.nl-interactive .nl-tick.zero .nl-label {
    color: var(--primary);
    font-size: 0.9rem;
}

.nl-interactive .nl-tick.selected .nl-dot {
    background: var(--primary);
    transform: scale(1.8);
    box-shadow: 0 0 0 4px rgba(67,97,238,0.25);
}

.nl-interactive .nl-tick.correct .nl-dot {
    background: var(--success) !important;
    transform: scale(1.8);
    box-shadow: 0 0 0 4px rgba(6,214,160,0.3);
}

.nl-interactive .nl-tick.wrong .nl-dot {
    background: var(--error) !important;
    transform: scale(1.8);
    box-shadow: 0 0 0 4px rgba(239,71,111,0.3);
}

.nl-interactive .nl-tick.answer .nl-dot {
    background: var(--success) !important;
    transform: scale(1.8);
    border: 3px dashed var(--success);
}

/* Jump arrow on number line */
.nl-jump {
    position: absolute;
    bottom: 48px;
    height: 30px;
    border: 2px solid var(--primary);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    z-index: 3;
    pointer-events: none;
}

.nl-jump::after {
    content: '';
    position: absolute;
    right: -6px;
    bottom: -2px;
    border: 6px solid transparent;
    border-left: 8px solid var(--primary);
}

.nl-jump.negative {
    border-color: var(--error);
}

.nl-jump.negative::after {
    border-left-color: transparent;
    border-right: 8px solid var(--error);
    right: auto;
    left: -6px;
}

.nl-start-marker {
    position: absolute;
    bottom: 46px;
    font-size: 1.2rem;
    z-index: 4;
    pointer-events: none;
}

/* Drag & Drop Order Exercise */
.order-exercise {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
}

.drag-source {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    justify-content: center;
    min-height: 56px;
    padding: 0.5rem;
}

.drag-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    height: 48px;
    padding: 0 14px;
    background: var(--primary);
    color: white;
    font-family: 'Nunito', sans-serif;
    font-size: 1.15rem;
    font-weight: 800;
    border-radius: var(--radius-sm);
    cursor: grab;
    user-select: none;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    touch-action: none;
}

.drag-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.drag-item.dragging {
    opacity: 0.4;
    cursor: grabbing;
}

.drag-item.correct-item {
    background: var(--success);
}

.drag-item.wrong-item {
    background: var(--error);
}

.drop-zones {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.drop-zone-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.drop-zone-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--gray-light);
    text-transform: uppercase;
}

.drop-slot {
    width: 56px;
    height: 48px;
    border: 3px dashed var(--gray-lighter);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--dark);
    background: var(--bg);
    transition: var(--transition);
}

.drop-slot.drag-over {
    border-color: var(--primary);
    background: #EEF0FF;
    transform: scale(1.05);
}

.drop-slot.filled {
    border-style: solid;
    border-color: var(--primary-light);
    background: #F0F3FF;
}

.drop-slot.correct-slot {
    border-color: var(--success);
    background: var(--success-light);
    color: #065F46;
}

.drop-slot.wrong-slot {
    border-color: var(--error);
    background: var(--error-light);
    color: #9B1C31;
}

.order-arrow {
    font-size: 1.2rem;
    color: var(--gray-lighter);
    display: flex;
    align-items: center;
    padding-top: 16px;
}

@media (max-width: 600px) {
    .drag-item { min-width: 44px; height: 42px; font-size: 1rem; padding: 0 10px; }
    .drop-slot { width: 48px; height: 42px; font-size: 1rem; }
    .drop-zones { gap: 0.3rem; }
}

/* Sign Rules Table */
.sign-table {
    width: 100%;
    max-width: 320px;
    margin: 1rem auto;
    border-collapse: collapse;
    font-weight: 700;
    text-align: center;
}

.sign-table th, .sign-table td {
    padding: 0.6rem 1rem;
    border: 2px solid var(--gray-lighter);
}

.sign-table th {
    background: var(--primary);
    color: white;
    font-size: 1rem;
}

.sign-table .positive { color: var(--success); font-size: 1.1rem; }
.sign-table .negative { color: var(--error); font-size: 1.1rem; }

/* ============ GRAFICOS EDUCATIVOS ============ */

/* Barra de fraccion */
.frac-bar {
    display: flex;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid var(--dark);
    margin: 0.75rem auto;
    max-width: 360px;
}
.frac-bar .frac-part {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.8rem;
    color: white;
    border-right: 2px solid rgba(255,255,255,0.3);
}
.frac-bar .frac-part:last-child { border-right: none; }
.frac-bar .frac-part.filled { background: var(--primary); }
.frac-bar .frac-part.empty { background: var(--gray-lighter); color: var(--gray); }
.frac-bar-label {
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--gray);
    margin-top: 4px;
}

/* Filas de barras para comparar equivalentes */
.frac-compare {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
}
.frac-compare-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.frac-compare-row .frac-label {
    font-weight: 800;
    font-size: 1rem;
    min-width: 40px;
    text-align: right;
    font-family: 'Courier New', monospace;
}
.frac-compare-row .frac-bar { margin: 0; flex: 1; }
.frac-compare .equals-sign {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--success);
    margin: 0.25rem 0;
}

/* Barra de porcentaje */
.pct-bar-wrap {
    margin: 1rem auto;
    max-width: 360px;
}
.pct-bar {
    height: 32px;
    background: var(--gray-lighter);
    border-radius: 100px;
    overflow: hidden;
    position: relative;
}
.pct-bar .pct-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
    font-size: 0.85rem;
    min-width: 40px;
    transition: width 0.6s ease;
}
.pct-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--gray);
    margin-top: 4px;
}

/* Cuadricula para raiz cuadrada */
.square-grid {
    display: inline-grid;
    gap: 2px;
    margin: 0.75rem auto;
    padding: 4px;
    background: var(--gray-lighter);
    border-radius: 6px;
}
.square-grid .sq-cell {
    width: 22px;
    height: 22px;
    background: var(--primary);
    border-radius: 3px;
}
.square-grid .sq-cell.sq-remainder {
    background: #F97316;
}
.square-grid-label {
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--gray);
    margin-top: 4px;
}
.grids-row {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    align-items: flex-end;
    flex-wrap: wrap;
    margin: 1rem 0;
}
.grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Balanza para ecuaciones */
.balance {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 0;
    margin: 1rem auto;
    max-width: 360px;
}
.balance-side {
    flex: 1;
    background: var(--bg);
    border: 2px solid var(--gray-lighter);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    text-align: center;
    font-weight: 800;
    font-size: 1.1rem;
    font-family: 'Courier New', monospace;
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.balance-side.left { border-right: none; border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: #EEF0FF; }
.balance-side.right { border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: #F0FDF9; }
.balance-pivot {
    width: 3px;
    height: 60px;
    background: var(--dark);
    position: relative;
}
.balance-pivot::before {
    content: '=';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--dark);
    background: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--dark);
}
.balance-base {
    width: 100%;
    height: 4px;
    background: var(--dark);
    border-radius: 2px;
    margin-top: 2px;
}

/* Flecha de proporcionalidad */
.prop-diagram {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}
.prop-col {
    text-align: center;
    font-weight: 800;
}
.prop-col .prop-val {
    font-size: 1.3rem;
    padding: 0.5rem 1rem;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
}
.prop-col .prop-label {
    font-size: 0.75rem;
    color: var(--gray);
    font-weight: 600;
}
.prop-arrow {
    font-size: 2rem;
    color: var(--primary);
}
.prop-arrow.up { color: var(--success); }
.prop-arrow.down { color: var(--error); }

.theory-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    background: var(--card);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    z-index: 50;
}

/* ============ EXERCISE VIEW ============ */
.exercise-view {
    max-width: 680px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.exercise-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.exercise-header h2 {
    font-size: 1.4rem;
    font-weight: 900;
    margin-bottom: 0.25rem;
}

.exercise-header .level-badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 800;
    color: white;
    margin-bottom: 0.75rem;
}

.level-badge.l1 { background: var(--success); }
.level-badge.l2 { background: var(--warning); color: var(--dark); }
.level-badge.l3 { background: var(--error); }

.exercise-progress {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 2rem;
}

.exercise-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gray-lighter);
    transition: var(--transition);
}

.exercise-dot.current { background: var(--primary); transform: scale(1.2); }
.exercise-dot.correct { background: var(--success); }
.exercise-dot.wrong { background: var(--error); }

.exercise-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    text-align: center;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: var(--transition);
}

.exercise-card.shake {
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-10px); }
    40% { transform: translateX(10px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

.exercise-card.correct-flash {
    animation: correctFlash 0.6s ease;
}

@keyframes correctFlash {
    0% { box-shadow: var(--shadow); }
    50% { box-shadow: 0 0 0 4px var(--success), 0 4px 24px rgba(6,214,160,0.3); }
    100% { box-shadow: var(--shadow); }
}

.exercise-question {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--gray);
}

.exercise-expression {
    font-size: 2rem;
    font-weight: 900;
    color: var(--dark);
    margin-bottom: 2rem;
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
    line-height: 1.4;
}

.exercise-input-group {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.exercise-input {
    font-family: 'Nunito', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    text-align: center;
    width: 140px;
    padding: 0.75rem 1rem;
    border: 3px solid var(--gray-lighter);
    border-radius: var(--radius-sm);
    outline: none;
    transition: var(--transition);
    color: var(--dark);
}

.exercise-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(67,97,238,0.15);
}

.exercise-input.correct {
    border-color: var(--success);
    background: var(--success-light);
}

.exercise-input.wrong {
    border-color: var(--error);
    background: var(--error-light);
}

.exercise-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    max-width: 400px;
    margin: 0 auto 1rem;
}

.exercise-option {
    font-family: 'Nunito', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 0.85rem 1rem;
    border: 3px solid var(--gray-lighter);
    border-radius: var(--radius-sm);
    background: white;
    cursor: pointer;
    transition: var(--transition);
    color: var(--dark);
}

.exercise-option:hover {
    border-color: var(--primary-light);
    background: #F0F3FF;
}

.exercise-option.selected {
    border-color: var(--primary);
    background: #E8ECFD;
}

.exercise-option.correct {
    border-color: var(--success);
    background: var(--success-light);
    color: #065F46;
}

.exercise-option.wrong {
    border-color: var(--error);
    background: var(--error-light);
    color: #9B1C31;
}

.feedback {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.95rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.feedback.visible { opacity: 1; }

.feedback.correct {
    background: var(--success-light);
    color: #065F46;
}

.feedback.wrong {
    background: var(--error-light);
    color: #9B1C31;
}

/* ============ BUTTONS ============ */
.btn {
    font-family: 'Nunito', sans-serif;
    font-size: 1rem;
    font-weight: 800;
    padding: 0.75rem 2rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary:hover { background: var(--primary-dark); transform: translateY(-2px); }

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

.btn-success:hover { background: #05C090; transform: translateY(-2px); }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-outline:hover { background: #F0F3FF; }

.btn-ghost {
    background: transparent;
    color: var(--gray);
}

.btn-ghost:hover { color: var(--dark); background: var(--gray-lighter); }

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

/* ============ RESULTS MODAL ============ */
.results-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
    animation: fadeIn 0.3s ease;
}

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

.results-card {
    background: white;
    border-radius: var(--radius);
    padding: 2.5rem;
    text-align: center;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.results-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.results-card h2 {
    font-size: 1.5rem;
    font-weight: 900;
    margin-bottom: 0.5rem;
}

.results-card p {
    color: var(--gray);
    margin-bottom: 0.25rem;
}

.results-score {
    font-size: 3rem;
    font-weight: 900;
    color: var(--primary);
    margin: 1rem 0;
}

.results-score.passed { color: var(--success); }
.results-score.failed { color: var(--error); }

.results-card .btn { margin: 0.5rem; }

/* ============ CONFETTI ============ */
.confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 300;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -10px;
    animation: confettiFall 3s linear forwards;
}

@keyframes confettiFall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ============ UTILITIES ============ */
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* ============ RESPONSIVE ============ */
@media (max-width: 600px) {
    .header { padding: 0 1rem; }
    .header-title { font-size: 1.1rem; }
    .dashboard, .topic-view, .theory-view, .exercise-view {
        padding: 1.25rem 1rem;
    }
    .welcome h1 { font-size: 1.5rem; }
    .topics-grid { grid-template-columns: 1fr; }
    .exercise-expression { font-size: 1.5rem; }
    .exercise-options { grid-template-columns: 1fr; }
    .theory-nav { flex-direction: column; }
    .theory-nav .btn { width: 100%; justify-content: center; }
}

/* ============ INTERACTIVE THEORY WIDGETS ============ */
.iw { margin: 1rem 0; }
.iw-controls {
    display: flex; gap: 0.5rem; justify-content: center;
    align-items: center; margin: 0.5rem 0; flex-wrap: wrap;
}
.iw-btn {
    font-family: 'Nunito', sans-serif; width: 40px; height: 40px;
    border-radius: 50%; border: 2px solid var(--gray-lighter);
    background: white; font-size: 1.2rem; font-weight: 800;
    cursor: pointer; transition: var(--transition);
    display: flex; align-items: center; justify-content: center;
    color: var(--dark);
}
.iw-btn:hover { border-color: var(--primary); background: #F0F3FF; }
.iw-btn:active { transform: scale(0.9); }
.iw-value {
    font-size: 1.4rem; font-weight: 900;
    font-family: 'Courier New', monospace;
    min-width: 48px; text-align: center; color: var(--dark);
}
.iw-label {
    font-size: 0.8rem; font-weight: 700;
    color: var(--gray); text-align: center;
}
.iw-slider {
    -webkit-appearance: none; width: 100%; max-width: 320px;
    height: 8px; border-radius: 100px; background: var(--gray-lighter);
    outline: none; cursor: pointer;
}
.iw-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 28px; height: 28px;
    border-radius: 50%; background: var(--primary);
    cursor: pointer; border: 3px solid white;
    box-shadow: var(--shadow-sm);
}
.iw-hint {
    font-size: 0.85rem; color: var(--gray); text-align: center;
    margin-top: 0.5rem; font-style: italic;
}
.iw-pill {
    display: inline-block; padding: 6px 14px; border-radius: 100px;
    font-weight: 800; font-size: 1.1rem; cursor: pointer;
    border: 2px solid var(--gray-lighter); background: white;
    transition: var(--transition); user-select: none;
    font-family: 'Courier New', monospace;
}
.iw-pill:hover { border-color: var(--primary); transform: translateY(-2px); }
.iw-pill.negative { color: var(--error); border-color: #FECDD3; background: #FFF5F7; }
.iw-pill.checked {
    background: var(--error); color: white;
    border-color: var(--error); transform: scale(1.05);
}
.iw-step-highlight {
    background: #FEF3C7; border-radius: 6px; padding: 2px 8px;
    cursor: pointer; border: 2px solid var(--warning);
    transition: var(--transition); font-weight: 900;
}
.iw-step-highlight:hover {
    background: #FDE68A; transform: scale(1.05);
}
.iw-frac-display { text-align: center; }
.iw-frac-bars { margin: 0.5rem 0; }
.iw-table-input:focus { outline: none; border-color: var(--primary) !important; }
