@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap");

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

/* -- Base ------------------------------------------- */
body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: linear-gradient(135deg, #fef7f2 0%, #fdf0e6 30%, #fff5f0 60%, #fef9f5 100%);
    background-attachment: fixed;
    color: #2d3436;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: safe center;
    padding: 1rem;
    -webkit-tap-highlight-color: transparent;
}

/* playful background dots */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: radial-gradient(circle, #fad4c0 1px, transparent 1px);
    background-size: 28px 28px;
    opacity: 0.35;
    pointer-events: none;
    z-index: 0;
}

.container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 640px;
    background: #ffffff;
    border-radius: 24px;
    padding: 2.25rem 2rem;
    box-shadow: 0 8px 40px rgba(201, 142, 104, 0.15),
0 2px 8px rgba(0,0,0,0.06);
    border: 2px solid #fce8dd;
    transition: border-color 0.3s;
}

h1 {
    font-size: 1.7rem;
    font-weight: 800;
    color: #e17055;
    margin-bottom: 0.15rem;
    text-align: center;
    letter-spacing: 0;
}
.subtitle {
    font-size: 0.9rem;
    color: #b2a198;
    margin-bottom: 1.4rem;
    text-align: center;
    font-weight: 600;
}

/* -- Mascot ----------------------------------- */
/* -- Mascot wrapper: anchors topic graphics without affecting layout -- */
.mascot-wrapper {
    position: relative;
    width: 90px;
    height: 75px;
    margin: 0 auto 0.3rem;
}
.mascot {
    width: 100%;
    height: 100%;
    overflow: hidden;          /* clip anything outside the bounding box */
}
.mascot svg,
.mascot img {
    width: 100%;
    height: 100%;
    display: block;
}
/* Topic decorations sit outside the mascot but inside the wrapper */
.mascot-wrapper .topic-decor {
    position: absolute;
    pointer-events: none;
}
@keyframes mascotBob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-5px); }
}

/* -- Keyframes ------------------------------------- */

/* -- Onboarding pages ---------------------------- */
.page {
    display: none;
    position: relative;
}
.page.active {
    display: block;
    animation: fadeIn 0.3s ease-out both;
}
.page-exercise.active {
    display: flex;
    flex-direction: column;
    min-height: min(720px, calc(100dvh - 5.5rem));
    gap: 0.15rem;
}

/* Language page */
.onboard-panel {
    text-align: center;
    margin: 0 auto 1rem;
    max-width: 480px;
}
.onboard-panel-learning {
    padding-top: 0.2rem;
}
.onboard-panel-ui,
.topic-panel {
    padding: 1rem 0.9rem;
    border: 1px solid rgba(232,221,211,0.78);
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(255,255,255,0.94), rgba(255,250,246,0.94));
    box-shadow: 0 8px 24px rgba(201,142,104,0.08);
}
.onboard-mascot {
    width: 108px;
    height: 90px;
    margin: 0.65rem auto 0.55rem;
}
.onboard-kicker {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 1.45rem;
    padding: 0.18rem 0.62rem;
    border-radius: 999px;
    background: #fff1e8;
    color: #c65f44;
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.4rem;
}
.onboard-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: #e17055;
    text-align: center;
    margin-bottom: 0.15rem;
    letter-spacing: 0;
}
.onboard-title-sm { font-size: 1.4rem; }
.onboard-sub {
    font-size: 0.92rem;
    color: #b2a198;
    text-align: center;
    font-weight: 600;
    margin-bottom: 0.65rem;
}
.selection-hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: 340px;
    padding: 0.45rem 0.7rem;
    border-radius: 12px;
    background: rgba(108,92,231,0.08);
    color: #5f5a75;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.3;
}
.context-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
    margin-top: 0.7rem;
}
.context-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 1.75rem;
    padding: 0.28rem 0.62rem;
    border-radius: 999px;
    border: 1px solid rgba(139,126,116,0.18);
    background: #fff;
    color: #5f5a75;
    font-size: 0.76rem;
    font-weight: 800;
    line-height: 1.2;
}
.context-pill-learning {
    color: #6c5ce7;
    border-color: rgba(108,92,231,0.18);
    background: rgba(108,92,231,0.08);
}
.context-pill-note {
    color: #8b7e74;
    background: rgba(247,242,238,0.82);
}
.lang-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.62rem;
}
.lang-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    min-height: 5.6rem;
    padding: 0.72rem 0.4rem;
    background: #fff;
    border: 2px solid #e8ddd3;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}
.lang-card:hover {
    border-color: #f0b89a;
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
.lang-card:active { transform: scale(0.96); }
.prompt-lang-card {
    border-color: rgba(108,92,231,0.14);
}
.prompt-lang-card:hover {
    border-color: rgba(108,92,231,0.34);
    box-shadow: 0 6px 18px rgba(108,92,231,0.1);
}
.prompt-lang-card.selected {
    border-color: #6c5ce7;
    background: #f4f1ff;
}
.lang-flag { font-size: 1.6rem; }
.lang-name {
    font-size: 0.72rem;
    font-weight: 700;
    color: #2d3436;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
}

/* Topic page */
.topic-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 2.2rem;
    margin-bottom: 0.75rem;
}
.topic-topbar .back-btn {
    position: static;
}
.language-switch-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    min-height: 2rem;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    border: 1px solid rgba(108,92,231,0.18);
    background: rgba(255,255,255,0.92);
    color: #5f5a75;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(82,73,160,0.08);
}
.language-switch-btn:hover {
    border-color: rgba(108,92,231,0.34);
    transform: translateY(-1px);
}
.language-switch-icon {
    font-size: 1rem;
    line-height: 1;
}
.topic-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.topic-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    min-height: 6.6rem;
    padding: 0.8rem 0.5rem;
    background: #fff;
    border: 2px solid #e8ddd3;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    text-align: center;
}
.topic-card:hover { border-color: #00b894; transform: scale(1.03); box-shadow: 0 4px 16px rgba(0,180,120,0.1); }
.topic-card:active { transform: scale(0.96); }
.topic-card-emoji {
    font-size: 2.4rem; line-height: 1; text-align: center;
    margin-bottom: 0.2rem;
}
.topic-card-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: #2d3436;
}

/* Exercise header + back button */
.exercise-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
    min-height: 34px;
    margin-bottom: 0.45rem;
    font-weight: 700;
    font-size: 0.85rem;
}
.exercise-header-icons {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.18rem 0.35rem;
    border: 1px solid rgba(232,221,211,0.72);
    border-radius: 999px;
    background: rgba(255,255,255,0.82);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.exercise-header-prompt {
    color: #5f5a75;
}
.exercise-header-prompt .exercise-header-lang {
    color: #6c5ce7;
}
.exercise-header-icons:hover {
    border-color: rgba(108,92,231,0.28);
    box-shadow: 0 4px 14px rgba(82,73,160,0.12);
    transform: translateY(-1px);
}
.exercise-header-icons:active {
    transform: translateY(0);
}
.exercise-header-lang {
    color: #e17055;
    font-size: 1.15rem;
    line-height: 1;
}
.exercise-header-topic {
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.15rem;
    line-height: 1;
}
.back-btn {
    background: none; border: none; font-family: inherit;
    position: fixed; top: 0.4rem; left: 0.4rem;
    z-index: 5; font-size: 1rem; font-weight: 700; color: #8b7e74;
    cursor: pointer; width: 32px; height: 32px;
    border-radius: 50%; transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,0.85); backdrop-filter: blur(4px);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.back-btn:hover { color: #e17055; background: #fff; }
.back-btn-sm { width: 28px; height: 28px; font-size: 0.9rem; top: 0.35rem; left: 0.35rem; }

@keyframes popIn {
    0%   { transform: scale(0.85); opacity: 0; }
    55%  { transform: scale(1.04); opacity: 1; }
    75%  { transform: scale(0.97); }
    100% { transform: scale(1);    opacity: 1; }
}
@keyframes slideUpFade {
    0%   { transform: translateY(14px); opacity: 0; }
    100% { transform: translateY(0);    opacity: 1; }
}
@keyframes fadeIn {
    0%   { opacity: 0; }
    100% { opacity: 1; }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    15%      { transform: translateX(-7px); }
    30%      { transform: translateX(7px); }
    45%      { transform: translateX(-5px); }
    60%      { transform: translateX(5px); }
    75%      { transform: translateX(-3px); }
    90%      { transform: translateX(3px); }
}
@keyframes bounceCorrect {
    0%   { transform: scale(0.92); }
    40%  { transform: scale(1.05); }
    65%  { transform: scale(0.97); }
    85%  { transform: scale(1.01); }
    100% { transform: scale(1); }
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-4px); }
}
@keyframes glowPulse {
    0%, 100% { box-shadow: 0 2px 12px rgba(0,180,120,0.08); }
    50%      { box-shadow: 0 4px 20px rgba(0,180,120,0.16); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toastSlideUp {
    0%   { transform: translateX(-50%) translateY(20px); opacity: 0; }
    100% { transform: translateX(-50%) translateY(0);    opacity: 1; }
}
@keyframes confettiFall {
    0%   { transform: translateY(-30px) rotate(0deg) scale(1); opacity: 1; }
    100% { transform: translateY(50px) rotate(540deg) scale(0.2); opacity: 0; }
}

/* -- Language selector -------------------------------- */
.options {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}
.options label {
    font-size: 0.9rem;
    font-weight: 700;
    color: #8b7e74;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.options select {
    background: #fff;
    border: 2px solid #e8ddd3;
    color: #2d3436;
    padding: 0.45rem 0.65rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.options select:hover { border-color: #f0b89a; transform: scale(1.03); }
.options select:focus {
    outline: none;
    border-color: #e17055;
    box-shadow: 0 0 0 3px rgba(225,112,85,0.15);
}

/* -- Button-group selectors ------------------------ */
.btn-group {
    display: flex;
    gap: 0.35rem;
}
.btn-group-btn {
    background: #fff;
    border: 2px solid #e8ddd3;
    color: #8b7e74;
    padding: 0.4rem 0.75rem;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s, background 0.2s, color 0.2s;
    white-space: nowrap;
}
.btn-group-btn:hover {
    border-color: #f0b89a;
    transform: scale(1.04);
}
.btn-group-btn.active {
    background: #6c5ce7;
    border-color: #6c5ce7;
    color: #fff;
    box-shadow: 0 2px 8px rgba(108,92,231,0.24);
}
.btn-group-btn.active:hover {
    border-color: #5848c2;
    background: #5848c2;
}
.selector-label {
    font-size: 0.88rem;
    font-weight: 700;
    color: #8b7e74;
    white-space: nowrap;
}

/* -- Swipe throw-away animation ----------------- */
.challenge-box.swiping-red {
    border-color: #e17055 !important;
    background: linear-gradient(135deg, #fff5f5 0%, #ffe0e0 100%) !important;
    box-shadow: 0 4px 20px rgba(225,112,85,0.2) !important;
}
.challenge-box.throw-left {
    animation: throwLeft 0.4s ease-in forwards;
}
.challenge-box.throw-right {
    animation: throwRight 0.4s ease-in forwards;
}
@keyframes throwLeft {
    to { transform: translateX(-120%); opacity: 0; }
}
@keyframes throwRight {
    to { transform: translateX(120%); opacity: 0; }
}
.challenge-box.pop-in {
    animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* -- Challenge sentence ------------------------------- */
.challenge-box {
    position: relative;
    background: linear-gradient(135deg, #fffdf8 0%, #f7f8ff 100%);
    border: 2px solid #e6dfd6;
    border-radius: 18px;
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
    text-align: center;
    box-shadow: 0 3px 16px rgba(96,72,46,0.08);
    transition: border-color 0.3s, box-shadow 0.3s, transform 0.3s;
    min-height: clamp(280px, 40dvh, 420px);
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    touch-action: pan-y;
}
.challenge-box:hover {
    border-color: #cfc8f6;
    box-shadow: 0 6px 22px rgba(96,72,46,0.12);
    transform: translateY(-2px);
}
.challenge-box.has-result {
    border-color: #d7d2ec;
    min-height: clamp(360px, 52dvh, 500px);
}
.challenge-box.pop .challenge-text {
    animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.challenge-label {
    font-size: 0.75rem;
    font-weight: 800;
    color: #6c5ce7;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}
.speak-btn {
    position: absolute; top: 0.5rem; right: 0.5rem;
    background: rgba(255,255,255,0.85); border: none; cursor: pointer;
    color: #00b894; padding: 4px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; z-index: 2;
    width: 30px; height: 30px;
    backdrop-filter: blur(4px);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.speak-btn svg { width: 18px; height: 18px; }
.speak-btn:hover { color: #00a381; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.speak-btn:active { transform: scale(0.9); }
.speak-btn.speaking { color: #e17055; animation: pulse 1s ease-in-out infinite; }
.challenge-stage {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 10.5rem;
    flex: 1 1 auto;
}
.challenge-text {
    width: 100%;
    font-size: 1.55rem;
    font-weight: 700;
    color: #263238;
    line-height: 1.5;
    transition: color 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.22rem;
    min-height: 10.5rem;
    max-height: 15rem;
    overflow-y: auto;
    overflow-wrap: anywhere;
    padding: 0.1rem 0.25rem;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y;
}
.challenge-text-original {
    display: block;
    font-size: 1.08rem;
    font-weight: 650;
    color: #94a3b8;
    text-align: center;
    line-height: 1.42;
}
.challenge-text-inner {
    display: block;
    text-align: center;
}
.challenge-text-browser {
    color: #263238;
}
.challenge-translation {
    font-size: 0.85rem;
    font-weight: 500;
    color: #64748b;
    text-align: center;
    margin-top: 0.3rem;
    font-style: italic;
}
.challenge-loading {
    position: absolute;
    inset: 0;
    z-index: 1;
    color: #8b7e74;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease-in;
}
.challenge-loading.htmx-request {
    opacity: 1;
}
.challenge-box.is-loading .challenge-loading {
    opacity: 1;
}
.loading-dots {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.42rem;
    min-height: 2rem;
}
.challenge-loading .loading-dots {
    gap: 7px;
    min-height: 32px;
}
.loading-dots span {
    width: 0.62rem;
    height: 0.62rem;
    border-radius: 50%;
    background: #9aa4b2;
    box-shadow: 0 4px 10px rgba(71,85,105,0.16);
    animation: loadingBounce 900ms ease-in-out infinite;
}
.challenge-loading .loading-dots span {
    width: 9px;
    height: 9px;
    flex: 0 0 9px;
}
.loading-dots span:nth-child(2) {
    animation-delay: 120ms;
}
.loading-dots span:nth-child(3) {
    animation-delay: 240ms;
}
@keyframes loadingBounce {
    0%, 80%, 100% { transform: translateY(0) scale(0.96); opacity: 0.62; }
    40% { transform: translateY(-4px) scale(1.02); opacity: 1; }
}

/* Remove sentence text from the stage while the loading overlay is active. */
.challenge-box.is-loading .challenge-text,
#challenge-loading.htmx-request ~ .challenge-text {
    display: none;
}

/* -- Feedback panel ----------------------------- */
.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 0.65rem;
}
.result-summary {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}
.result-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex: 0 0 auto;
}
.result-emoji {
    font-size: 2rem;
    text-align: center;
    line-height: 1;
    animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.result-status {
    font-size: 1.05rem;
    font-weight: 800;
    text-align: left;
    letter-spacing: 0;
}
.result.correct .result-status { color: #0d8f75; }
.result.incorrect .result-status { color: #c65f44; }
.result.pending .result-status { color: #64748b; }
.result-speak-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(108,92,231,0.22);
    background: #ffffff;
    color: #5f6ee8;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(82,73,160,0.12);
    transition: transform 0.18s ease, box-shadow 0.18s ease, color 0.18s ease;
}
.result-speak-btn:hover {
    color: #c65f44;
    transform: translateY(-1px);
    box-shadow: 0 7px 18px rgba(82,73,160,0.18);
}
.result-speak-btn.speaking {
    color: #c65f44;
    animation: pulse 1s ease-in-out infinite;
}
.result-report-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid rgba(139,126,116,0.18);
    background: rgba(255,255,255,0.82);
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    cursor: pointer;
    transition: transform 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.result-report-btn:hover {
    color: #6c5ce7;
    border-color: rgba(108,92,231,0.28);
    transform: translateY(-1px);
}
.result-label-text {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
    display: block;
    margin-bottom: 0.25rem;
}
.result-row {
    background: rgba(255,255,255,0.86);
    border: 1px solid rgba(139,126,116,0.16);
    border-radius: 12px;
    padding: 0.62rem 0.78rem;
    margin-bottom: 0.45rem;
    font-size: 0.94rem;
    line-height: 1.45;
    color: #2d3436;
}
.result-value {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    overflow-wrap: anywhere;
}
.result-row:last-child {
    margin-bottom: 0;
}
.result-you-said {
    font-weight: 600;
}
.result-expected {
    color: #64748b;
    font-weight: 500;
}
.result.correct .result-you-said {
    color: #1f4f46;
}
.result.incorrect .result-you-said {
    color: #2d3436;
}
.result.pending {
    border-left-color: #94a3b8;
    background: linear-gradient(135deg, #fbfcff 0%, #ffffff 100%);
}
.result.pending .result-you-said {
    color: #475569;
}
.result-loading-value {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}
.result-loading-text {
    color: #64748b;
    font-weight: 700;
}
.result-loading-dots {
    width: auto;
    min-height: 1.1rem;
}
.result-loading-dots span {
    width: 0.34rem;
    height: 0.34rem;
}
.challenge-box .result {
    display: none;
    margin-top: 0.75rem;
    text-align: left;
    flex: 0 0 auto;
}
.challenge-box.has-result .challenge-text {
    min-height: 4.25rem;
    max-height: 6.5rem;
    flex: 0 0 auto;
}
.challenge-box.has-result .challenge-stage {
    min-height: 4.25rem;
    flex: 0 0 auto;
}
.challenge-box.has-result .result {
    display: block;
}
.challenge-box.has-result ~ .record-section {
    display: none;
}
/* -- Difficulty + Text-length selectors ----------- */
.selector-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}
.selector-row label {
    font-size: 0.88rem;
    font-weight: 700;
    color: #8b7e74;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.selector-row select {
    background: #fff;
    border: 2px solid #e8ddd3;
    color: #2d3436;
    padding: 0.45rem 0.65rem;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.selector-row select:hover { border-color: #f0b89a; transform: scale(1.03); }
.selector-row select:focus {
    outline: none;
    border-color: #e17055;
    box-shadow: 0 0 0 3px rgba(225,112,85,0.15);
}

/* -- Record section ------------------------------- */
.record-section {
    text-align: center;
    margin-top: auto;
    margin-bottom: 0.5rem;
    padding-top: 0.25rem;
    min-height: 126px;
}
.record-btn {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    border: 4px solid #00b894;
    background: linear-gradient(135deg, #e6fff5 0%, #ccfbf1 100%);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.5rem;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 18px rgba(0,184,148,0.18);
    position: relative;
    padding: 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
.record-btn::before {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px dashed transparent;
    transition: all 0.3s;
}
.record-btn:hover::before {
    border-color: #00b894;
    animation: spin 8s linear infinite;
}
.record-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0,184,148,0.3);
}
.record-btn:disabled,
.record-btn.is-disabled {
    cursor: not-allowed;
    opacity: 0.48;
    filter: grayscale(0.35);
    transform: none;
    box-shadow: 0 2px 10px rgba(45,52,54,0.08);
}
.record-btn:disabled::before,
.record-btn.is-disabled::before {
    border-color: transparent;
    animation: none;
}
.record-btn:disabled:hover,
.record-btn.is-disabled:hover {
    transform: none;
    box-shadow: 0 2px 10px rgba(45,52,54,0.08);
}
.record-btn.recording {
    background: linear-gradient(135deg, #ffeaea 0%, #ffe0e0 100%);
    border-color: #e17055;
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 0 4px 20px rgba(225,112,85,0.3);
}
.record-btn.recording::before {
    border-color: #e17055;
    animation: spin 4s linear infinite;
}
.record-btn.recording:hover {
    background: linear-gradient(135deg, #ffd6d6 0%, #ffc4c4 100%);
    transform: scale(1.08);
}
.record-icon {
    width: 0;
    height: 0;
    border-left: 26px solid #00b894;
    border-top: 15px solid transparent;
    border-bottom: 15px solid transparent;
    margin-left: 5px;
    transition: all 0.2s;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}
.record-btn:hover .record-icon {
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}
.recording .record-icon {
    border: none;
    width: 24px;
    height: 24px;
    background: #e17055;
    border-radius: 4px;
    margin-left: 0;
    filter: none;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(225,112,85,0.4); }
    50%      { box-shadow: 0 0 0 16px rgba(225,112,85,0); }
}
.record-label {
    font-size: 0.88rem;
    font-weight: 700;
    color: #b2a198;
    transition: color 0.3s;
}
.record-label .timer {
    color: #e17055;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
}
.level-bar {
    width: 100%;
    height: 5px;
    background: #f5eee8;
    border-radius: 3px;
    margin-top: 0.75rem;
    overflow: hidden;
    visibility: hidden;
}
.level-bar.active { visibility: visible; }
.level-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #00b894, #fdcb6e, #e17055);
    border-radius: 3px;
    transition: width 0.08s linear;
}

/* -- Result --------------------------------------- */
.result {
    margin-top: 0;
    background: linear-gradient(135deg, #ffffff 0%, #fbfaf9 100%);
    border: 1px solid #e6dfd6;
    border-left: 5px solid #9aa4b2;
    border-radius: 14px;
    padding: 0.95rem;
    min-height: 3rem;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.92rem;
    line-height: 1.5;
    color: #2d3436;
    box-shadow: 0 8px 24px rgba(96,72,46,0.1);
    overflow: hidden;
}
.result.animate-in {
    animation: slideUpFade 0.4s ease-out both;
}
.result.correct {
    border-color: #e6dfd6;
    border-left-color: #0d8f75;
    background: linear-gradient(135deg, #ffffff 0%, #f4fbf8 100%);
    animation: slideUpFade 0.35s ease-out both;
}
.result.incorrect {
    border-color: #e6dfd6;
    border-left-color: #c65f44;
    background: linear-gradient(135deg, #ffffff 0%, #fff8f5 100%);
    animation: slideUpFade 0.35s ease-out both;
}

/* -- Action buttons (post-result) ---------------- */
.action-buttons {
    display: flex;
    gap: 1.25rem;
    align-items: center;
    justify-content: center;
    margin-top: auto;
    margin-bottom: 0.5rem;
    padding-top: 0.25rem;
    min-height: 126px;
    animation: slideUpFade 0.35s 0.15s ease-out both;
}
.action-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}
.action-btn:hover {
    transform: scale(1.12);
}
.action-btn:active {
    transform: scale(0.94);
}
.action-btn.try-again {
    background: linear-gradient(135deg, #e17055 0%, #fab1a0 100%);
    color: #fff;
    box-shadow: 0 6px 22px rgba(225,112,85,0.35);
}
.action-btn.try-again:hover {
    box-shadow: 0 8px 30px rgba(225,112,85,0.5);
}
.action-btn.next {
    background: linear-gradient(135deg, #6c5ce7 0%, #74b9ff 100%);
    color: #fff;
    box-shadow: 0 6px 22px rgba(108,92,231,0.32);
}
.action-btn.next:hover {
    box-shadow: 0 8px 30px rgba(108,92,231,0.45);
}
.action-btn.next.loading {
    pointer-events: none;
    opacity: 0.7;
}
.action-btn.next.loading svg {
    animation: spin 0.8s linear infinite;
}

/* -- Confetti burst (correct answer) ------------ */
.confetti-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 10;
}
.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    animation: confettiFall 0.9s ease-out forwards;
}

.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2.5px solid #e8ddd3;
    border-top: 2.5px solid #00b894;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 0.5rem;
}

.result .spinner { border-color: #e8ddd3; border-top-color: #00b894; }

/* -- Toast ---------------------------------------- */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #e17055 0%, #d63031 100%);
    color: #fff;
    padding: 0.7rem 1.4rem;
    border-radius: 12px;
    font-size: 0.88rem;
    font-weight: 700;
    font-family: inherit;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(225,112,85,0.3);
}
.toast.show {
    opacity: 1;
    animation: toastSlideUp 0.35s ease-out both;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.beta-gate {
    position: relative;
    z-index: 1;
    width: min(92vw, 420px);
    background: #fff;
    border: 2px solid #fce8dd;
    border-radius: 20px;
    padding: 2rem 1.5rem;
    box-shadow: 0 8px 40px rgba(201, 142, 104, 0.15), 0 2px 8px rgba(0,0,0,0.06);
    text-align: center;
}
.beta-gate-mascot {
    width: 108px;
    height: 90px;
    margin: 0 auto 0.7rem;
}
.beta-gate-mascot img {
    width: 100%;
    height: 100%;
    display: block;
}
.beta-gate-copy {
    color: #8b7e74;
    font-weight: 700;
    margin: 0.35rem 0 1rem;
}
.beta-gate-form {
    display: grid;
    gap: 0.7rem;
}
.beta-gate-form input {
    width: 100%;
    border: 2px solid #e8ddd3;
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
    font: inherit;
    font-weight: 700;
    text-align: center;
}
.beta-gate-form input:focus {
    outline: none;
    border-color: #6c5ce7;
    box-shadow: 0 0 0 3px rgba(108,92,231,0.14);
}
.beta-gate-form button,
.feedback-send {
    border: none;
    border-radius: 12px;
    background: #6c5ce7;
    color: #fff;
    padding: 0.75rem 1rem;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(108,92,231,0.25);
}
.beta-gate-form button:hover,
.feedback-send:hover {
    background: #5848c2;
}
.beta-gate-error {
    color: #c65f44;
    font-size: 0.86rem;
    font-weight: 800;
}

.feedback-toggle {
    position: fixed;
    left: 8px;
    bottom: 8px;
    z-index: 200;
    width: 32px;
    height: 32px;
    border: 1px solid rgba(48,54,61,0.16);
    border-radius: 50%;
    background: rgba(255,255,255,0.9);
    color: #6b7280;
    font: inherit;
    font-size: 16px;
    font-weight: 900;
    cursor: pointer;
    opacity: 0.68;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.feedback-toggle:hover {
    opacity: 0.95;
    color: #6c5ce7;
}
.feedback-modal[hidden] {
    display: none;
}
.feedback-modal {
    position: fixed;
    inset: 0;
    z-index: 220;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(env(safe-area-inset-top, 0px) + 1rem) 1rem calc(var(--keyboard-inset, 0px) + env(safe-area-inset-bottom, 0px) + 1rem);
    background: rgba(45,52,54,0.28);
    backdrop-filter: blur(3px);
    overflow-y: auto;
    overscroll-behavior: contain;
}
.feedback-modal.keyboard-open {
    align-items: flex-start;
}
.feedback-dialog {
    position: relative;
    width: min(92vw, 360px);
    max-height: calc(100dvh - var(--keyboard-inset, 0px) - env(safe-area-inset-top, 0px) - 2rem);
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e6dfd6;
    border-radius: 16px;
    padding: 1rem;
    box-shadow: 0 16px 44px rgba(45,52,54,0.18);
}
.feedback-dialog h2 {
    color: #2d3436;
    font-size: 1rem;
    text-align: left;
    margin: 0 2rem 0.75rem 0;
}
.feedback-dialog textarea {
    width: 100%;
    resize: vertical;
    min-height: 6rem;
    max-height: 32dvh;
    border: 2px solid #e8ddd3;
    border-radius: 12px;
    padding: 0.75rem;
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.4;
    color: #2d3436;
}
.feedback-dialog textarea:focus {
    outline: none;
    border-color: #6c5ce7;
    box-shadow: 0 0 0 3px rgba(108,92,231,0.14);
}
.feedback-close {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: #f7f2ee;
    color: #8b7e74;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}
.feedback-send {
    width: 100%;
    margin-top: 0.75rem;
    min-height: 46px;
}

.debug-toggle {
    position: fixed;
    right: 6px;
    bottom: 6px;
    z-index: 200;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(48,54,61,0.22);
    border-radius: 50%;
    background: rgba(255,255,255,0.86);
    color: #6b7280;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.55;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.debug-toggle:hover {
    opacity: 0.9;
    color: #00a381;
}
.debug-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 199;
    max-height: 35vh;
    overflow-y: auto;
    padding: 8px 10px;
    border-top: 2px solid #30363d;
    background: #0d1117;
    color: #c9d1d9;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 11px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

/* -- Mobile -------------------------------------- */
@media (max-width: 768px) {
    body {
padding: 0;
align-items: stretch;
min-height: 100dvh;
background-attachment: scroll;
    }
    .container {
width: 100%;
max-width: none;
min-height: 100dvh;
border: none;
border-radius: 0;
box-shadow: none;
padding: env(safe-area-inset-top, 1rem) 1.1rem env(safe-area-inset-bottom, 1rem);
display: flex;
flex-direction: column;
justify-content: center;
    }
    .page-exercise.active {
min-height: calc(100dvh - env(safe-area-inset-top, 1rem) - env(safe-area-inset-bottom, 1rem));
gap: 0.25rem;
    }
    #page-language.active,
    #page-prompt-language.active,
    #page-topic.active {
display: flex;
flex-direction: column;
justify-content: center;
min-height: calc(100dvh - env(safe-area-inset-top, 1rem) - env(safe-area-inset-bottom, 1rem));
    }
    #page-topic.active {
justify-content: flex-start;
padding-top: clamp(1.25rem, 7dvh, 4rem);
    }
    .onboard-panel {
margin-bottom: 0.85rem;
    }
    .onboard-panel-ui,
    .topic-panel {
padding: 0.85rem 0.75rem;
border-radius: 14px;
    }
    .onboard-mascot {
width: 104px;
height: 86px;
margin-top: 0;
    }
    .lang-grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 0.5rem;
    }
    .lang-card {
min-height: 5rem;
padding: 0.62rem 0.3rem;
border-radius: 12px;
    }
    .lang-flag { font-size: 1.42rem; }
    .lang-name { font-size: 0.72rem; max-width: 6.1rem; }
    .topic-topbar {
margin-bottom: 0.55rem;
    }
    .topic-grid {
gap: 0.55rem;
    }
    .topic-card {
min-height: 6rem;
padding: 0.65rem 0.45rem;
border-radius: 12px;
    }
    .topic-card-emoji {
font-size: 2.2rem;
    }
    .context-row {
margin-top: 0.55rem;
    }
    .exercise-header {
min-height: 28px;
margin-bottom: 0.2rem;
    }
    h1 { font-size: 1.45rem; }
    .subtitle { font-size: 0.82rem; margin-bottom: 1.1rem; }
    .challenge-box {
padding: 0.9rem;
border-radius: 14px;
min-height: 0;
flex: 1 1 auto;
margin-bottom: 0.35rem;
    }
    .challenge-text {
font-size: 1.32rem;
min-height: 7.25rem;
max-height: none;
overflow: visible;
    }
    .challenge-stage { min-height: 7.25rem; }
    .challenge-box.has-result { min-height: 0; }
    .challenge-box.has-result .challenge-text {
min-height: 3.3rem;
max-height: 5.2rem;
overflow: hidden;
    }
    .challenge-box.has-result .challenge-stage { min-height: 3.3rem; }
    .result-header { margin-bottom: 0.55rem; }
    .result-row {
padding: 0.56rem 0.65rem;
margin-bottom: 0.42rem;
    }
    .result-label-text { font-size: 0.66rem; }
    .result-value {
-webkit-line-clamp: 2;
line-clamp: 2;
    }
    .result-emoji { font-size: 2rem; }
    .result-status { font-size: 1.05rem; }
    .options {
flex-direction: column;
align-items: center;
gap: 0.5rem;
    }
    .page-exercise .selector-row {
flex-direction: row;
align-items: center;
justify-content: center;
gap: 0.45rem;
margin-bottom: 0.42rem;
flex-wrap: nowrap;
    }
    .selector-label { font-size: 0.8rem; }
    .page-exercise .selector-label {
width: 5.8rem;
text-align: right;
flex: 0 0 auto;
    }
    .page-exercise .btn-group {
gap: 0.25rem;
flex: 0 1 auto;
    }
    .page-exercise .btn-group-btn {
font-size: 0.78rem;
padding: 0.34rem 0.44rem;
border-radius: 8px;
min-width: 3.05rem;
    }
    .options label, .selector-row label {
width: 100%;
max-width: 280px;
justify-content: space-between;
font-size: 0.82rem;
    }
    .options select, .selector-row select {
font-size: 0.82rem;
padding: 0.4rem 0.55rem;
    }
    .record-btn { width: 76px; height: 76px; border-width: 3px; }
    .record-icon { border-left-width: 22px; border-top-width: 13px; border-bottom-width: 13px; }
    .recording .record-icon { width: 20px; height: 20px; }
    .result { padding: 0.75rem; font-size: 0.86rem; border-radius: 14px; }
    .action-buttons {
gap: 1rem;
min-height: 110px;
padding-top: 0;
margin-bottom: 0.2rem;
    }
    .action-btn { width: 56px; height: 56px; }
    .action-btn svg { width: 19px; height: 19px; }
}

@media (max-width: 380px) {
    .action-btn { width: 50px; height: 50px; }
    .action-btn svg { width: 17px; height: 17px; }
    .container { padding: env(safe-area-inset-top, 0.5rem) 0.8rem env(safe-area-inset-bottom, 0.5rem); }
    h1 { font-size: 1.3rem; }
    .onboard-title-sm { font-size: 1.2rem; }
    .lang-grid { gap: 0.42rem; }
    .lang-card { min-height: 4.7rem; }
    .lang-name { font-size: 0.68rem; max-width: 5.4rem; }
    .context-pill { font-size: 0.7rem; }
    .language-switch-label { max-width: 6.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .challenge-text { font-size: 1.18rem; }
    .record-btn { width: 68px; height: 68px; }
    .record-icon { border-left-width: 20px; border-top-width: 12px; border-bottom-width: 12px; margin-left: 4px; }
    .recording .record-icon { width: 18px; height: 18px; }
}
