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

:root {
    --bg: #ffffff;
    --bg2: #f7f7f7;
    --border: #e5e5e5;
    --text: #3c3c3c;
    --text2: #777777;
    --text3: #afafaf;
    --green: #58cc02;
    --green2: #58a700;
    --green3: #399918;
    --green-soft: #d7ffb8;
    --red: #ff4b4b;
    --red2: #ea2b2b;
    --red-soft: #ffdede;
    --blue: #1cb0f6;
    --blue2: #1899d6;
    --blue-soft: #ddf4ff;
    --purple: #ce82ff;
    --orange: #ff9600;
    --yellow: #ffc800;
    --track: #e5e5e5;
}

html, body {
    height: 100%;
    font-family: 'Nunito', sans-serif;
    background: var(--bg2);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 520px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
    background: var(--bg);
    overflow: hidden;
    box-shadow: 0 0 0 1px var(--border);
}

/* ===== SCREENS ===== */
.screen {
    display: none;
    min-height: 100vh;
    padding-bottom: 80px;
    animation: fadeIn 0.3s ease;
}
.screen.active { display: block; }

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

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
    max-width: 520px;
    margin: 0 auto;
}
.overlay.active { display: flex; }

/* ===== DUOLINGO BUTTON (CRITICAL) ===== */
.duo-btn {
    display: block;
    width: 100%;
    padding: 16px 24px;
    border-radius: 16px;
    font-family: 'Nunito', sans-serif;
    font-size: 15px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border: none;
    cursor: pointer;
    position: relative;
    transition: none;
    outline: none;
    -webkit-user-select: none;
    user-select: none;
}

.duo-btn-green {
    background: var(--green);
    color: #fff;
    border-bottom: 4px solid var(--green2);
}
.duo-btn-green:hover:not(:disabled) {
    background: var(--green3);
}
.duo-btn-green:active:not(:disabled) {
    transform: translateY(4px);
    border-bottom: 0px solid var(--green2);
}

.duo-btn-blue {
    background: var(--blue);
    color: #fff;
    border-bottom: 4px solid var(--blue2);
}
.duo-btn-blue:active:not(:disabled) {
    transform: translateY(4px);
    border-bottom: 0px solid var(--blue2);
}

.duo-btn:disabled, .duo-btn.disabled {
    background: var(--border) !important;
    color: var(--text3) !important;
    border-bottom: 4px solid #d1d1d1 !important;
    cursor: default;
    transform: none !important;
}

/* ===== SPLASH ===== */
#splash {
    background: var(--green);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
#splash.active { display: flex; }

.splash-inner { text-align: center; }
.splash-logo-wrap {
    width: 120px; height: 120px;
    margin: 0 auto 20px;
    position: relative;
}
.splash-owl {
    font-size: 72px;
    line-height: 120px;
    animation: owlBounce 1.2s ease infinite;
}
@keyframes owlBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}
.splash-title {
    font-size: 40px;
    font-weight: 900;
    color: #fff;
    letter-spacing: -1px;
}

/* ===== ONBOARD ===== */
#onboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    min-height: 100vh;
    text-align: center;
}
#onboard.active { display: flex; }

.onboard-illustration {
    font-size: 100px;
    margin-bottom: 24px;
}
.onboard-content { width: 100%; max-width: 360px; }
.onboard-content h2 {
    font-size: 26px;
    font-weight: 900;
    color: var(--text);
    margin-bottom: 12px;
    line-height: 1.2;
}
.onboard-sub {
    font-size: 16px;
    color: var(--text2);
    margin-bottom: 32px;
    line-height: 1.5;
}
.onboard-input-wrap { text-align: left; margin-bottom: 24px; }
.onboard-input-wrap label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.onboard-input-wrap input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-family: 'Nunito', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    transition: border-color 0.15s;
    outline: none;
}
.onboard-input-wrap input:focus { border-color: var(--blue); }

/* ===== HOME HEADER ===== */
.home-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 2px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 50;
}
.home-user {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}
.avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--green-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border: 2px solid var(--green);
}
.home-user-text { display: flex; flex-direction: column; }
.home-user-name { font-weight: 800; font-size: 15px; }
.home-user-level { font-size: 12px; color: var(--text2); font-weight: 700; }

.home-stats { display: flex; gap: 12px; }
.hstat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 800;
    font-size: 14px;
    color: var(--text2);
}
.hstat-icon { font-size: 18px; }

/* ===== DAILY GOAL ===== */
.daily-goal {
    padding: 14px 20px 16px;
    border-bottom: 2px solid var(--border);
    background: var(--bg);
}
.dg-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.dg-label {
    font-size: 12px;
    font-weight: 800;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.dg-val {
    font-size: 13px;
    font-weight: 700;
    color: var(--text2);
}
.dg-val b { color: var(--green); font-weight: 900; }
.dg-track {
    height: 14px;
    background: var(--track);
    border-radius: 7px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.dg-fill {
    height: 100%;
    background: var(--green);
    border-radius: 7px;
    width: 0%;
    transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ===== SECTION LABEL ===== */
.section-label {
    font-size: 12px;
    font-weight: 800;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 20px 20px 10px;
    background: var(--bg);
}

/* ===== TOPICS ===== */
.topics-list {
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.topic-card {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 18px 16px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
    overflow: hidden;
}
.topic-card:hover { background: var(--bg2); }
.topic-card:active { transform: scale(0.98); }

.topic-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 6px;
    background: var(--topic-c, var(--green));
    border-radius: 16px 0 0 16px;
}

.topic-top {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
}
.topic-icon {
    width: 56px; height: 56px;
    border-radius: 12px;
    background: var(--topic-bg, var(--green-soft));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
}
.topic-info h3 {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 3px;
}
.topic-info p {
    font-size: 13px;
    color: var(--text2);
    font-weight: 600;
}

.topic-track {
    height: 14px;
    background: var(--track);
    border-radius: 7px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.topic-fill {
    height: 100%;
    background: var(--topic-c, var(--green));
    border-radius: 7px;
    width: 0%;
    transition: width 0.5s ease;
}
.topic-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text2);
}

/* ===== PATH ===== */
.path-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 2px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 50;
}
.back-btn {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text2);
    width: 40px; height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    font-weight: 700;
}
.back-btn:hover { background: var(--bg2); }
.path-title-wrap { flex: 1; }
.path-title {
    font-size: 20px;
    font-weight: 900;
    color: var(--text);
}
.path-subtitle {
    font-size: 13px;
    color: var(--text2);
    font-weight: 700;
}

.path-scroll {
    padding: 32px 20px 100px;
    overflow-y: auto;
}
.path-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    position: relative;
}
.path-tree::before {
    content: '';
    position: absolute;
    left: 50%; transform: translateX(-50%);
    width: 4px; height: 100%;
    background: linear-gradient(to bottom, var(--path-c, var(--green)), var(--track));
    border-radius: 2px;
    z-index: 0;
}

.path-node {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 28px;
    cursor: pointer;
}
.path-node.locked { cursor: default; opacity: 0.45; }
.path-node:hover:not(.locked) { transform: scale(1.05); transition: transform 0.15s; }

.p-bubble {
    width: 68px; height: 68px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 900;
    border: 4px solid var(--border);
    background: var(--bg);
    position: relative;
    transition: all 0.3s ease;
}
.p-bubble.completed {
    background: var(--path-c, var(--green));
    border-color: var(--path-c2, var(--green2));
    color: #fff;
    box-shadow: 0 4px 0 var(--path-c2, var(--green2));
}
.p-bubble.current {
    border-color: var(--path-c, var(--green));
    color: var(--path-c, var(--green));
    box-shadow: 0 0 0 6px rgba(88, 204, 2, 0.15);
    animation: nodePulse 2s ease infinite;
}
.p-bubble.locked {
    background: var(--bg2);
    border-color: #d1d1d1;
    color: #b0b0b0;
}
@keyframes nodePulse {
    0%, 100% { box-shadow: 0 0 0 6px rgba(88, 204, 2, 0.15); }
    50% { box-shadow: 0 0 0 10px rgba(88, 204, 2, 0.08); }
}

.p-star {
    position: absolute;
    top: -6px; right: -6px;
    font-size: 20px;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.15));
}
.p-label {
    font-size: 13px;
    font-weight: 800;
    margin-top: 10px;
    text-align: center;
    max-width: 140px;
    line-height: 1.3;
    color: var(--text);
}
.p-connector {
    width: 4px; height: 24px;
    background: var(--track);
    border-radius: 2px;
    margin-bottom: 0;
}
.p-connector.done { background: var(--path-c, var(--green)); }

/* ===== LESSON / EXERCISE HEADER ===== */
.lesson-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 2px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 50;
}
.close-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text2);
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    font-weight: 700;
}
.close-btn:hover { background: var(--bg2); }
.lesson-track {
    flex: 1;
    height: 14px;
    background: var(--track);
    border-radius: 7px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.lesson-fill {
    height: 100%;
    background: var(--green);
    border-radius: 7px;
    width: 0%;
    transition: width 0.4s ease;
}
.lesson-hearts {
    font-size: 14px;
    font-weight: 800;
    min-width: 50px;
    text-align: right;
    color: var(--text);
}

/* ===== LESSON BODY ===== */
.lesson-body {
    padding: 28px 20px;
    min-height: calc(100vh - 180px);
}
.lesson-title {
    font-size: 26px;
    font-weight: 900;
    margin-bottom: 20px;
    line-height: 1.2;
    color: var(--text);
}
.lesson-text {
    font-size: 17px;
    line-height: 1.7;
    color: var(--text);
    margin-bottom: 24px;
}
.lesson-text strong { color: var(--green2); font-weight: 800; }
.math-hl {
    background: var(--green-soft);
    color: var(--green2);
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 800;
    font-family: 'Courier New', monospace;
    font-size: 0.95em;
    border: 1px solid var(--border);
}

.example-card {
    background: #fff9e6;
    border: 2px solid #ffd900;
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 20px;
}
.ex-label {
    font-size: 11px;
    font-weight: 900;
    color: #b38f00;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ex-label::before { content: '💡'; font-size: 16px; }
.ex-step {
    padding: 10px 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
}
.ex-step:last-child { border-bottom: none; }
.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px; height: 22px;
    background: #b38f00;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 900;
    margin-right: 8px;
    flex-shrink: 0;
}

/* ===== LESSON FOOTER ===== */
.lesson-footer {
    padding: 16px 20px 24px;
    border-top: 2px solid var(--border);
    background: var(--bg);
    position: sticky;
    bottom: 0;
    z-index: 40;
}

/* ===== EXERCISE ===== */
#exercise { display: flex; flex-direction: column; min-height: 100vh; }
.ex-body { flex: 1; padding: 28px 20px; }
.ex-question {
    font-size: 22px;
    font-weight: 900;
    margin-bottom: 8px;
    line-height: 1.35;
    color: var(--text);
}
.ex-hint {
    font-size: 15px;
    color: var(--text2);
    margin-bottom: 28px;
    min-height: 22px;
    font-weight: 600;
}

/* ===== OPTION CARDS (GRID SELECTION) ===== */
.ex-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.opt-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    font-family: 'Nunito', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
    outline: none;
    -webkit-user-select: none;
    user-select: none;
    position: relative;
}
.opt-card:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-soft); }
.opt-card:disabled { cursor: default; opacity: 0.8; }

.opt-card.selected {
    border-color: var(--blue);
    background: var(--blue-soft);
}
.opt-card.correct {
    border-color: var(--green);
    background: var(--green-soft);
}
.opt-card.wrong {
    border-color: var(--red);
    background: var(--red-soft);
}

.opt-letter {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--bg2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 900;
    color: var(--text2);
    flex-shrink: 0;
    border: 2px solid var(--border);
    transition: all 0.15s;
}
.opt-card.selected .opt-letter { background: var(--blue); color: #fff; border-color: var(--blue); }
.opt-card.correct .opt-letter { background: var(--green); color: #fff; border-color: var(--green); }
.opt-card.wrong .opt-letter { background: var(--red); color: #fff; border-color: var(--red); }

/* ===== INPUT AREA ===== */
.ex-input-area { display: flex; flex-direction: column; gap: 16px; }
.ex-input-area.hidden { display: none !important; }
#ex-input {
    width: 100%;
    padding: 18px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-family: 'Nunito', sans-serif;
    font-size: 28px;
    font-weight: 900;
    text-align: center;
    color: var(--text);
    letter-spacing: 2px;
    outline: none;
    transition: border-color 0.15s;
    background: var(--bg);
}
#ex-input:focus { border-color: var(--blue); }
#ex-input.correct { border-color: var(--green); background: var(--green-soft); }
#ex-input.wrong { border-color: var(--red); background: var(--red-soft); }

.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.numpad button {
    padding: 18px;
    font-size: 22px;
    font-weight: 900;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    color: var(--text);
    transition: background 0.1s, transform 0.05s;
    outline: none;
}
.numpad button:hover { background: var(--bg2); }
.numpad button:active { transform: scale(0.95); background: var(--border); }
.numpad button[data-k="del"] {
    background: var(--red-soft);
    border-color: var(--red);
    color: var(--red);
}

/* ===== FEEDBACK BAR (FOOTER STATE MODAL) ===== */
.feedback-bar {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 0 0 14px;
    animation: slideUp 0.25s ease;
}
.feedback-bar.active { display: flex; }
.feedback-icon { font-size: 28px; }
.feedback-text {
    font-size: 16px;
    font-weight: 800;
}
.feedback-text.correct { color: var(--green2); }
.feedback-text.wrong { color: var(--red2); }

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

/* ===== DONE OVERLAY ===== */
.done-card {
    background: var(--bg);
    border-radius: 16px;
    padding: 36px 28px;
    width: 100%;
    max-width: 340px;
    text-align: center;
    border: 2px solid var(--border);
    animation: popIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
    z-index: 10;
}
@keyframes popIn {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}
.done-emoji { font-size: 80px; margin-bottom: 12px; animation: owlBounce 1.5s ease infinite; }
.done-title { font-size: 24px; font-weight: 900; margin-bottom: 6px; }
.done-sub { font-size: 15px; color: var(--text2); margin-bottom: 24px; line-height: 1.5; }
.done-rewards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
}
.reward-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg2);
    border-radius: 12px;
    font-size: 16px;
    font-weight: 800;
    border: 2px solid var(--border);
}
.reward-row .r-icon { font-size: 24px; }
.reward-row .r-val { color: var(--green); }
#confetti { position: absolute; inset: 0; pointer-events: none; z-index: 5; }

/* ===== PROFILE ===== */
.profile-body { padding: 20px 20px 100px; }
.profile-card {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    text-align: center;
    margin-bottom: 20px;
}
.profile-avatar {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--green-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    margin: 0 auto 12px;
    border: 3px solid var(--green);
}
.profile-name { font-size: 20px; font-weight: 900; margin-bottom: 4px; }
.profile-badge {
    display: inline-block;
    background: var(--green);
    color: #fff;
    padding: 4px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 900;
}

.profile-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 28px;
}
.pstat {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}
.pstat-val { font-size: 28px; font-weight: 900; color: var(--green); margin-bottom: 2px; }
.pstat-label { font-size: 12px; font-weight: 800; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }

.ach-list { display: flex; flex-direction: column; gap: 10px; }
.ach-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    opacity: 0.4;
    transition: opacity 0.3s, border-color 0.3s;
}
.ach-item.unlocked {
    opacity: 1;
    border-color: var(--green);
    background: var(--green-soft);
}
.ach-icon { font-size: 32px; }
.ach-info h4 { font-size: 15px; font-weight: 900; margin-bottom: 2px; }
.ach-info p { font-size: 13px; color: var(--text2); font-weight: 600; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 520px;
    display: flex;
    background: var(--bg);
    border-top: 2px solid var(--border);
    padding: 6px 0;
    z-index: 100;
}
.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text2);
    font-family: 'Nunito', sans-serif;
    font-size: 11px;
    font-weight: 800;
    transition: color 0.15s;
    outline: none;
    position: relative;
}
.nav-tab.active { color: var(--green); }
.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: 2px;
    width: 20px; height: 3px;
    background: var(--green);
    border-radius: 3px;
}
.nav-icon { font-size: 22px; }

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.shake { animation: shake 0.4s ease; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

@media (max-width: 520px) { #app { box-shadow: none; } }
