/* Math Wizard Frontend Game Styles — v2.0 */
*, *::before, *::after { box-sizing: border-box; }

.mw-game-wrapper {
    font-family: 'Segoe UI', 'Nunito', Arial, sans-serif;
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    user-select: none;
    -webkit-user-select: none;
}

/* === SCREENS === */
.mw-screen { width: 100%; }

/* === LOBBY === */
.mw-lobby-screen { padding: 20px 0; }
.mw-lobby-header { text-align: center; margin-bottom: 32px; }
.mw-title {
    font-size: clamp(28px, 5vw, 48px);
    font-weight: 900;
    background: linear-gradient(135deg, #7c3aed 0%, #db2777 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0 0 8px;
    letter-spacing: -1px;
}
.mw-subtitle { color: #6b7280; font-size: 18px; margin: 0; }

.mw-topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.mw-topic-card {
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
    transition: transform .2s, box-shadow .2s, border-color .2s;
    cursor: pointer;
}
.mw-topic-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(124,58,237,.2); border-color: #7c3aed; }

.mw-topic-thumb {
    height: 120px;
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mw-color-1 { background: linear-gradient(135deg, #7c3aed, #a78bfa); }
.mw-color-2 { background: linear-gradient(135deg, #db2777, #f9a8d4); }
.mw-color-3 { background: linear-gradient(135deg, #d97706, #fcd34d); }
.mw-color-4 { background: linear-gradient(135deg, #059669, #6ee7b7); }
.mw-color-5 { background: linear-gradient(135deg, #dc2626, #fca5a5); }
.mw-color-6 { background: linear-gradient(135deg, #0284c7, #7dd3fc); }
.mw-topic-icon { font-size: 48px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)); }

.mw-topic-info { padding: 12px 16px 8px; }
.mw-topic-num { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: #7c3aed; }
.mw-topic-title { font-size: 15px; font-weight: 700; color: #1f2937; margin: 4px 0 6px; line-height: 1.3; }
.mw-topic-desc { font-size: 12px; color: #6b7280; margin: 0; line-height: 1.4; }

.mw-topic-footer { padding: 8px 16px 14px; display: flex; justify-content: space-between; align-items: center; }
.mw-topic-badges { font-size: 12px; color: #7c3aed; font-weight: 600; }
.mw-badge-count { display: inline-block; }

/* === BUTTONS === */
.mw-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 50px;
    font-size: 15px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: transform .1s, box-shadow .1s, filter .1s;
    letter-spacing: .3px;
}
.mw-btn:active { transform: scale(.96); }
.mw-btn-primary {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: #fff;
    box-shadow: 0 4px 14px rgba(109,40,217,.4);
}
.mw-btn-primary:hover { filter: brightness(1.1); }
.mw-btn-secondary {
    background: #f3f4f6;
    color: #374151;
    box-shadow: 0 2px 6px rgba(0,0,0,.1);
}
.mw-btn-secondary:hover { background: #e5e7eb; }
.mw-btn-icon {
    background: rgba(255,255,255,.8);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s;
}
.mw-btn-icon:hover { background: #fff; }

/* === GAME SCREEN === */
.mw-game-scene {
    position: relative;
    border-radius: 20px;
    overflow: visible; /* MLC overlays need to escape this container */
    min-height: 480px;
    background: linear-gradient(180deg, #1e1b4b 0%, #312e81 50%, #4c1d95 100%);
    display: flex;
    flex-direction: column;
}

.mw-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    z-index: 0;
    opacity: .9;
}

.mw-hud {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(4px);
    gap: 12px;
}
.mw-hud-left  { display: flex; align-items: center; gap: 10px; flex: 1; }
.mw-hud-center { flex: 2; text-align: center; }
.mw-hud-right  { flex: 1; text-align: right; }

.mw-topic-name { color: #c4b5fd; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.mw-score-display { color: #fff; font-size: 18px; font-weight: 800; }
.mw-score-label { font-size: 11px; font-weight: 400; opacity: .7; margin-left: 4px; }
.mw-progress-track { height: 6px; background: rgba(255,255,255,.2); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.mw-progress-fill { height: 100%; background: linear-gradient(90deg, #a78bfa, #4ade80); border-radius: 3px; transition: width .4s cubic-bezier(.4,0,.2,1); }
.mw-batch-info { color: #fcd34d; font-size: 13px; font-weight: 700; white-space: nowrap; }

/* === BATTLEFIELD === */
.mw-battlefield {
    position: relative;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 20px 30px 0;
    flex: 1;
    min-height: 180px;
}

.mw-character-zone, .mw-enemy-zone { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.mw-character { text-align: center; }
.mw-char-img { font-size: 64px; line-height: 1; filter: drop-shadow(0 4px 12px rgba(0,0,0,.5)); transition: transform .3s; }
.mw-char-img img { width: 80px; height: 80px; object-fit: contain; }
.mw-char-name { color: #fff; font-size: 12px; font-weight: 700; text-shadow: 0 1px 4px rgba(0,0,0,.8); margin-top: 4px; }
.mw-health-bar { width: 80px; height: 8px; background: rgba(0,0,0,.4); border-radius: 4px; overflow: hidden; }
.mw-health-fill { height: 100%; border-radius: 4px; transition: width .5s ease; }

.mw-spell-zone { flex: 1; text-align: center; position: relative; min-height: 60px; }

/* === PROBLEM PANEL === */
.mw-problem-panel {
    position: relative;
    z-index: 10;
    background: rgba(15,10,40,.85);
    backdrop-filter: blur(8px);
    padding: 10px 20px 20px;
    border-top: 2px solid rgba(167,139,250,.4);
}

.mw-batch-label {
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: #fcd34d;
    letter-spacing: .5px;
    margin-bottom: 6px;
    text-transform: uppercase;
    opacity: .85;
}

.mw-timer-bar { height: 4px; background: rgba(255,255,255,.15); border-radius: 2px; overflow: hidden; margin-bottom: 10px; }
.mw-timer-fill { height: 100%; background: linear-gradient(90deg, #4ade80, #facc15, #f87171); width: 100%; transition: width .1s linear; }

.mw-problem-text {
    text-align: center;
    font-size: clamp(20px, 4vw, 32px);
    font-weight: 800;
    color: #fff;
    letter-spacing: .5px;
    margin-bottom: 14px;
    text-shadow: 0 2px 8px rgba(0,0,0,.6);
    min-height: 40px;
    line-height: 1.2;
}

.mw-answer-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.mw-answer-input {
    width: 160px;
    padding: 12px 16px;
    font-size: 24px;
    font-weight: 800;
    text-align: center;
    border: 2px solid rgba(167,139,250,.6);
    border-radius: 12px;
    background: rgba(255,255,255,.1);
    color: #fff;
    outline: none;
    transition: border-color .2s, background .2s;
    -moz-appearance: textfield;
    /* Wider for word problem text answers */
}
.mw-answer-input::-webkit-outer-spin-button,
.mw-answer-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.mw-answer-input:focus  { border-color: #a78bfa; background: rgba(255,255,255,.18); }
.mw-answer-input.mw-correct { border-color: #4ade80; background: rgba(74,222,128,.2); }
.mw-answer-input.mw-wrong   { border-color: #f87171; background: rgba(248,113,113,.2); }

.mw-feedback {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    min-height: 28px;
    margin-top: 8px;
    transition: opacity .3s;
}
.mw-feedback.mw-correct-msg { color: #4ade80; }
.mw-feedback.mw-wrong-msg   { color: #f87171; }

/* === SPELL ANIMATIONS === */
.mw-spell {
    position: absolute;
    font-size: 36px;
    animation: mwSpellFly 0.6s ease-in-out forwards;
    pointer-events: none;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
@keyframes mwSpellFly {
    0%   { transform: translate(-50%,-50%) scale(0.5); opacity:1; }
    50%  { transform: translate(-50%,-80%) scale(1.4); opacity:1; }
    100% { transform: translate(80%, -50%) scale(0.8); opacity:0; }
}
.mw-char-img.mw-shake { animation: mwShake 0.4s ease; }
@keyframes mwShake {
    0%,100% { transform: translateX(0); }
    25%     { transform: translateX(-10px); }
    75%     { transform: translateX(10px); }
}
.mw-char-img.mw-attack { animation: mwAttack 0.3s ease; }
@keyframes mwAttack {
    0%,100% { transform: scale(1); }
    50%     { transform: scale(1.15) translateX(8px); }
}

/* === RESULT SCREEN (retry) === */
.mw-result { padding: 40px 20px; text-align: center; }
.mw-result-inner {
    max-width: 500px;
    margin: 0 auto;
    background: linear-gradient(135deg, #1e1b4b, #4c1d95);
    border-radius: 24px;
    padding: 40px 32px;
    color: #fff;
    box-shadow: 0 20px 60px rgba(109,40,217,.4);
}
.mw-result-icon  { font-size: 72px; margin-bottom: 16px; }
.mw-result-title { font-size: 32px; font-weight: 900; margin: 0 0 8px; }
.mw-result-msg   { font-size: 16px; opacity: .85; margin: 0 0 20px; line-height: 1.5; }
.mw-result-stats { background: rgba(0,0,0,.3); border-radius: 12px; padding: 16px; margin-bottom: 20px; font-size: 16px; line-height: 2; }
.mw-result-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* === BADGE CELEBRATION OVERLAY === */
.mw-badge-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 10, 50, 0.82);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: mwFadeIn .35s ease;
}
@keyframes mwFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.mw-badge-popup {
    max-width: 480px;
    width: 92%;
    background: linear-gradient(145deg, #1e1b4b, #4c1d95);
    border: 3px solid #fbbf24;
    border-radius: 28px;
    padding: 44px 36px 36px;
    text-align: center;
    color: #fff;
    box-shadow: 0 0 60px rgba(251,191,36,.35), 0 20px 60px rgba(0,0,0,.5);
    animation: mwPopup .4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes mwPopup {
    from { transform: scale(0.6); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.mw-topic-complete-popup {
    border-color: #ffd700;
    box-shadow: 0 0 80px rgba(255,215,0,.4), 0 20px 60px rgba(0,0,0,.5);
}

.mw-badge-icon  { font-size: 80px; margin-bottom: 12px; animation: mwBounce 0.6s ease .2s both; }
@keyframes mwBounce {
    0%   { transform: scale(0) rotate(-20deg); }
    60%  { transform: scale(1.25) rotate(8deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.mw-badge-title { font-size: 30px; font-weight: 900; margin: 0 0 10px; color: #fbbf24; }
.mw-badge-msg   { font-size: 16px; opacity: .88; margin: 0 0 24px; line-height: 1.5; }

.mw-badge-earned, .mw-all-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 28px;
}

.mw-badge-medal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: transform .2s;
}
.mw-badge-medal-earned {
    background: rgba(251,191,36,.18);
    border-color: #fbbf24;
    animation: mwSparkle 2s ease infinite;
}
@keyframes mwSparkle {
    0%,100% { box-shadow: 0 0 6px rgba(251,191,36,.4); }
    50%      { box-shadow: 0 0 18px rgba(251,191,36,.9); }
}
.mw-badge-medal-locked {
    background: rgba(255,255,255,.06);
    border-color: rgba(255,255,255,.15);
    font-size: 20px;
    opacity: .5;
}
.mw-badge-medal-more {
    color: rgba(255,255,255,.6);
    font-size: 13px;
    align-self: center;
    margin-left: 4px;
}

.mw-badge-popup-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* === LOADING === */
.mw-loading {
    position: fixed;
    inset: 0;
    background: rgba(30,27,75,.7);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mw-loading-spinner { font-size: 64px; animation: mwSpin 1s linear infinite; }
@keyframes mwSpin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* === RESPONSIVE === */
@media (max-width: 600px) {
    .mw-topics-grid   { grid-template-columns: 1fr 1fr; gap: 12px; }
    .mw-battlefield   { padding: 12px 16px 0; }
    .mw-char-img      { font-size: 48px; }
    .mw-problem-text  { font-size: 22px; }
    .mw-answer-input  { width: 100px; font-size: 20px; padding: 10px 12px; }
    .mw-hud           { padding: 8px 10px; }
    .mw-topic-name    { max-width: 80px; font-size: 11px; }
    .mw-badge-popup   { padding: 32px 20px 24px; }
    .mw-badge-title   { font-size: 22px; }
}

@media (max-width: 400px) {
    .mw-topics-grid { grid-template-columns: 1fr; }
}
