/* ── Typing Game ── */

:root {
    --game-bg: #f0f7f5;
    --key-size: 48px;
    --key-radius: 12px;
    --key-bg: #ffffff;
    --key-border: #e3ecea;
    --key-active: #1d9a8a;
    --key-highlight: rgba(29, 154, 138, 0.2);
    --key-correct: #a8e6cf;
    --reward-gold: #f5d76e;
    --reward-mint: #a8e6cf;
    --reward-lavender: #c3b1e1;
}

.activity-game-body {
    background: var(--game-bg) !important;
}

/* Hide Kittu chat widget and chat notification during game */
.activity-game-body #kittu-widget,
.activity-game-body .kittu-widget,
.activity-game-body [id*="kittu"],
.activity-game-body [class*="kittu"],
.activity-game-body #chat-notification-badge,
.activity-game-body .chat-notification-badge {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.typing-game-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 700px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ── Top Bar ── */

.typing-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    flex-shrink: 0;
}

.typing-topbar-back {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary, #1f2a30);
    text-decoration: none;
    font-size: 1rem;
    transition: background 0.2s;
}

.typing-topbar-back:hover {
    background: rgba(0, 0, 0, 0.05);
}

.typing-topbar-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.typing-topbar-mode {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary, #1f2a30);
}

.typing-topbar-demo {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #e8f5e9;
    color: #2e7d32;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
}

.typing-topbar-progress {
    font-size: 0.75rem;
    color: var(--text-muted, #5f6f7a);
}

.typing-topbar-actions {
    display: flex;
    gap: 4px;
}

.typing-topbar-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-primary, #1f2a30);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.typing-topbar-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* ── Display Area ── */

.typing-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
    min-height: 0;
}

.typing-letter-container {
    width: 220px;
    height: 220px;
    border-radius: 32px;
    background: #ffffff;
    box-shadow: 0 8px 32px rgba(29, 154, 138, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.typing-letter {
    font-size: 120px;
    font-weight: 700;
    color: var(--key-active);
    line-height: 1;
    font-family: 'Poppins', sans-serif;
    user-select: none;
    transition: transform 0.3s ease;
}

.typing-letter.shake {
    animation: gentleShake 0.4s ease;
}

@keyframes gentleShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.typing-letter.correct {
    animation: gentlePop 0.3s ease;
}

@keyframes gentlePop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.typing-instruction {
    font-size: 1.1rem;
    color: var(--text-muted, #5f6f7a);
    margin: 0;
    text-align: center;
}

/* ── Reward Container ── */

.typing-reward {
    position: relative;
    height: 40px;
    width: 200px;
    margin-top: 8px;
}

/* ── Feedback Messages ── */

.typing-feedback {
    font-size: 1.15rem;
    font-weight: 600;
    text-align: center;
    min-height: 1.6em;
    margin: 4px 0 0;
    padding: 0 12px;
    transition: opacity 0.5s ease;
    opacity: 0;
}

.typing-feedback--correct {
    color: #1d9a8a;
}

.typing-feedback--wrong {
    color: #e67e22;
}

.typing-feedback--idle {
    color: #7c8a96;
    font-style: italic;
    font-weight: 500;
    animation: idlePulse 2s ease-in-out infinite;
}

@keyframes idlePulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.reward-bubble {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    opacity: 0;
    animation: floatUp 1.2s ease forwards;
}

@keyframes floatUp {
    0% { opacity: 0; transform: translateY(0) scale(0.5); }
    20% { opacity: 0.8; transform: translateY(-10px) scale(1); }
    100% { opacity: 0; transform: translateY(-50px) scale(0.8); }
}

/* ── Keyboard Toggle (desktop only) ── */

.typing-keyboard-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    margin: 16px auto 0;
    border: 1.5px solid var(--key-border);
    border-radius: var(--radius-pill, 999px);
    background: var(--key-bg);
    color: var(--text-muted, #5f6f7a);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.typing-keyboard-toggle:hover {
    border-color: var(--key-active);
    color: var(--key-active);
}

.typing-keyboard-toggle i {
    font-size: 0.9rem;
}

/* ── Desktop hint ── */

.typing-desktop-hint {
    display: none;
}

/* ── On-Screen Keyboard ── */

.typing-keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 0 24px;
    flex-shrink: 0;
}

.typing-keyboard-row {
    display: flex;
    gap: 5px;
    justify-content: center;
}

.typing-key {
    width: var(--key-size);
    height: var(--key-size);
    border-radius: var(--key-radius);
    border: 1.5px solid var(--key-border);
    background: var(--key-bg);
    color: var(--text-primary, #1f2a30);
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Poppins', sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.typing-key:active {
    transform: scale(0.95);
    background: var(--key-highlight);
}

.typing-key.highlight {
    background: var(--key-highlight);
    border-color: var(--key-active);
}

.typing-key.correct {
    background: var(--key-correct);
    border-color: var(--key-correct);
}

.typing-key.highlight-row {
    background: rgba(29, 154, 138, 0.08);
    border-color: rgba(29, 154, 138, 0.25);
}

/* ── Settings Panel ── */

.typing-settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.typing-settings-panel {
    background: #fff;
    border-radius: 20px;
    padding: 24px 20px 32px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.typing-settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.typing-settings-header h3 {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
}

.typing-setting-group {
    margin-bottom: 18px;
}

.typing-setting-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted, #5f6f7a);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.typing-setting-options {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.typing-setting-btn {
    padding: 7px 14px;
    border-radius: var(--radius-pill, 999px);
    border: 1.5px solid var(--key-border);
    background: transparent;
    color: var(--text-primary, #1f2a30);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.typing-setting-btn.active {
    background: var(--key-active);
    border-color: var(--key-active);
    color: #fff;
}

.typing-slider {
    width: 100%;
    accent-color: var(--key-active);
}

/* ── Summary & Expiry Overlays ── */

.typing-summary-overlay,
.typing-guest-expiry {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.typing-summary-panel {
    background: #fff;
    border-radius: 20px;
    padding: 36px 28px;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.typing-summary-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0 0 6px;
    color: var(--text-primary, #1f2a30);
}

.typing-summary-desc {
    font-size: 0.9rem;
    color: var(--text-muted, #5f6f7a);
    margin: 0 0 24px;
}

.typing-summary-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin: 24px 0;
}

.typing-summary-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.typing-summary-stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--key-active);
}

.typing-summary-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted, #5f6f7a);
    margin-top: 2px;
}

.typing-summary-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 20px;
}

/* ── Desktop: hide keyboard, show toggle ── */

@media (min-width: 769px) {
    .typing-keyboard {
        display: none;
    }

    .typing-keyboard.show {
        display: flex;
    }

    .typing-keyboard-toggle {
        display: flex;
    }

    .typing-desktop-hint {
        display: block;
        text-align: center;
        font-size: 0.82rem;
        color: var(--text-muted, #5f6f7a);
        margin-top: 12px;
    }

    .typing-desktop-hint i {
        margin-right: 4px;
        color: var(--key-active);
    }
}

/* ── Mobile: keyboard always visible in viewport ── */

@media (max-width: 768px) {
    /* Hide header, bottom nav for immersive game */
    .activity-game-body header,
    .activity-game-body .navbar,
    .activity-game-body .mobile-bottom-nav {
        display: none !important;
    }

    .typing-game-wrapper {
        min-height: 100dvh;
        padding: 0 8px;
        padding-bottom: 160px;
        overflow: hidden;
    }

    .typing-display {
        flex: 1;
        padding: 10px 0 0;
        min-height: 0;
        justify-content: center;
    }

    .typing-keyboard-toggle,
    .typing-desktop-hint {
        display: none !important;
    }

    .typing-letter-container {
        width: 140px;
        height: 140px;
        margin-bottom: 10px;
        border-radius: 24px;
    }

    .typing-letter {
        font-size: 76px;
    }

    .typing-instruction {
        font-size: 0.95rem;
    }

    .typing-reward {
        height: 20px;
        margin-top: 2px;
    }

    .typing-keyboard {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        border-top: 1px solid var(--key-border);
        padding: 12px 4px 20px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        z-index: 100;
    }

    .typing-key {
        width: 34px;
        height: 42px;
        font-size: 0.9rem;
        border-radius: 10px;
    }

    .typing-keyboard-row {
        gap: 4px;
    }

    .typing-summary-stats {
        gap: 16px;
    }

    .typing-topbar {
        padding: 8px 0;
    }
}

@media (max-width: 380px) {
    .typing-key {
        width: 30px;
        height: 38px;
        font-size: 0.82rem;
        border-radius: 8px;
    }

    .typing-keyboard-row {
        gap: 3px;
    }

    .typing-letter-container {
        width: 100px;
        height: 100px;
    }

    .typing-letter {
        font-size: 52px;
    }
}

@media (min-width: 577px) and (max-width: 768px) {
    .typing-key {
        width: 38px;
        height: 40px;
    }

    .typing-letter-container {
        width: 130px;
        height: 130px;
    }

    .typing-letter {
        font-size: 68px;
    }
}
