/* Core Styles — Mobile-First, Child-Friendly */
:root {
    /* Responsive sizing variables — optimized for phone-first (portrait) */
    --slot-size: clamp(40px, 12vw, 56px);
    --tile-size: clamp(44px, 13vw, 58px);
    --font-sm: clamp(0.85rem, 3vw, 1rem);
    --font-md: clamp(1rem, 3.5vw, 1.2rem);
    --font-lg: clamp(1.1rem, 4vw, 1.4rem);
    --font-xl: clamp(1.3rem, 4.5vw, 1.6rem);
    --font-2xl: clamp(1.6rem, 5.5vw, 2.2rem);
    --gap-xs: clamp(3px, 0.8vw, 5px);
    --gap-sm: clamp(6px, 1.5vw, 10px);
    --gap-md: clamp(10px, 2.5vw, 18px);
    --container-padding: clamp(12px, 3vw, 24px);
    --answer-font: clamp(1.1rem, 5.5vw, 1.8rem);
    /* Child-friendly color palette */
    --color-primary: #4f46e5;
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    --color-accent: #8b5cf6;
    --color-surface: rgba(255, 255, 255, 0.95);
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.15);
    --touch-min: 48px; /* Minimum touch target for children */
}

/* A run of letters that must stay on ONE line (e.g. "danced"). Separators such
   as space / - / . / ? / ! are rendered as their own flex items BETWEEN groups,
   so the word breaks only at those natural points. flex:none prevents the group
   itself from being squashed; white-space:nowrap keeps letters together. */
.word-group {
    display: inline-flex;
    flex-wrap: nowrap;
    white-space: nowrap;
    flex: none;
    gap: var(--gap-xs);
}

body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport for mobile browsers */
    overflow: hidden;
    background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    font-family: 'Fredoka', sans-serif;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    color: white;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

#gameCanvas {
    display: block;
    width: 100vw;
    height: 100vh;
}

/* UI Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.hidden {
    display: none !important;
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15;
}

/* Inventory (pushed down: mute + exit buttons live at the very top-left) */
#inventory {
    position: absolute;
    top: 56px;
    left: 20px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    max-width: 40%;
}

.inv-slot {
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #555;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    position: relative;
}

.inv-level {
    position: absolute;
    bottom: -5px;
    right: -5px;
    background: #D84315;
    color: white;
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 4px;
    font-weight: bold;
}

/* HP Bar */
#status-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.hp-container {
    width: 200px;
    height: 24px;
    background: #333;
    border: 2px solid #555;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.hp-fill {
    height: 100%;
    background: #ff3333;
    width: 100%;
    transition: width 0.1s;
}

.hp-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
}

/* XP Bar */
.xp-bar-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 10px;
    background: #333;
}

.xp-bar-fill {
    height: 100%;
    background: #00ff88;
    width: 0%;
    transition: width 0.2s;
    box-shadow: 0 0 10px #00ff88;
}

/* Stats Badge */
#game-stats {
    position: absolute;
    top: 60px;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.stat-badge {
    background: rgba(0, 0, 0, 0.5);
    padding: 5px 15px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 18px;
}

/* Components */
.game-btn {
    background: linear-gradient(180deg, #FF8A65 0%, #F4511E 100%);
    border-bottom: 4px solid #BF360C;
    color: white;
    border-radius: 14px;
    padding: 14px 26px;
    font-weight: 700;
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.1s;
    pointer-events: auto;
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-top: none;
    border-left: none;
    border-right: none;
    touch-action: manipulation;
}

/* Color variants for .game-btn — Tailwind bg-* classes are overridden by
   the base gradient, so we use explicit color modifiers */
.game-btn.bg-blue-600, .game-btn[class*="bg-blue-6"] {
    background: linear-gradient(180deg, #60a5fa 0%, #2563eb 100%) !important;
    border-bottom-color: #1d4ed8 !important;
}
.game-btn.bg-blue-600:hover, .game-btn[class*="bg-blue-5"]:hover {
    background: linear-gradient(180deg, #93c5fd 0%, #3b82f6 100%) !important;
}
.game-btn.bg-green-600, .game-btn[class*="bg-green-6"],
.game-btn.bg-green-500, .game-btn[class*="bg-green-5"] {
    background: linear-gradient(180deg, #4ade80 0%, #16a34a 100%) !important;
    border-bottom-color: #15803d !important;
}
.game-btn.bg-green-500:hover, .game-btn.bg-green-600:hover {
    background: linear-gradient(180deg, #86efac 0%, #22c55e 100%) !important;
}
.game-btn.bg-indigo-600, .game-btn[class*="bg-indigo-6"],
.game-btn.bg-indigo-500, .game-btn[class*="bg-indigo-5"] {
    background: linear-gradient(180deg, #818cf8 0%, #4f46e5 100%) !important;
    border-bottom-color: #3730a3 !important;
}
.game-btn.bg-indigo-600:hover, .game-btn.bg-indigo-500:hover {
    background: linear-gradient(180deg, #a5b4fc 0%, #6366f1 100%) !important;
}
.game-btn.bg-rose-600, .game-btn[class*="bg-rose-6"] {
    background: linear-gradient(180deg, #fb7185 0%, #e11d48 100%) !important;
    border-bottom-color: #9f1239 !important;
}
.game-btn.bg-rose-600:hover {
    background: linear-gradient(180deg, #fda4af 0%, #f43f5e 100%) !important;
}
.game-btn.bg-orange-600, .game-btn[class*="bg-orange-6"],
.game-btn.bg-orange-500, .game-btn[class*="bg-orange-5"] {
    background: linear-gradient(180deg, #FF8A65 0%, #F4511E 100%) !important;
    border-bottom-color: #BF360C !important;
}
.game-btn.bg-orange-600:hover, .game-btn.bg-orange-500:hover {
    background: linear-gradient(180deg, #FFAB91 0%, #FF7043 100%) !important;
}
/* Gray / slate variant for CLEAR buttons */
.game-btn.bg-gray-500, .game-btn[class*="bg-gray-5"],
.game-btn.bg-slate-600 {
    background: linear-gradient(180deg, #94a3b8 0%, #475569 100%) !important;
    border-bottom-color: #334155 !important;
}
.game-btn.bg-gray-500:hover, .game-btn.bg-slate-600:hover {
    background: linear-gradient(180deg, #cbd5e1 0%, #64748b 100%) !important;
}

.game-btn:active {
    transform: translateY(3px);
    border-bottom-width: 1px;
}

.card {
    background: white;
    color: #475569;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    text-align: center;
    transition: transform 0.2s;
    cursor: pointer;
    border: 4px solid #FF8A65;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    pointer-events: auto;
}

.card:hover {
    transform: scale(1.05);
    border-color: #D84315;
}

.powerup-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 900px;
    width: 95%;
    pointer-events: auto;
}

@media (max-width: 768px) {
    .powerup-grid {
        grid-template-columns: 1fr;
        width: 90%;
        gap: 15px;
    }

    .card {
        padding: 15px;
        /* reduce padding on mobile */
    }
}

/* Minigames */
.minigame-container {
    background: linear-gradient(135deg, #E8F5E9 0%, #E3F2FD 50%, #F3E5F5 100%);
    width: min(96vw, 800px);
    max-height: 96vh;
    max-height: 96dvh;
    border-radius: var(--radius-xl);
    padding: var(--container-padding);
    color: #1e293b;
    box-shadow: var(--shadow-card), 0 0 40px rgba(99, 102, 241, 0.15);
    position: relative;
    pointer-events: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Study Mode Utility Classes */
.study-slot {
    width: var(--slot-size);
    height: var(--slot-size);
    border: 2.5px solid rgba(255, 255, 255, 0.6);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--answer-font);
    font-weight: bold;
    background: #1e293b;
    color: white;
    -webkit-user-select: none;
    user-select: none;
    transition: all 0.15s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.study-slot:active {
    transform: scale(0.95);
}

/* While fitAnswerArea() is measure-shrinking the answer row, slot transitions
   must be OFF: "transition: all" animates width, so mid-loop scrollWidth reads
   the stale pre-transition size and the loop can never converge. */
.fit-measuring .study-slot {
    transition: none !important;
}

.study-letter-btn {
    width: var(--tile-size);
    height: var(--tile-size);
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
    border-radius: 12px;
    color: #1a1a2e;
    font-weight: 700;
    font-size: var(--font-lg);
    box-shadow: 0 4px 0 #d97706, 0 6px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.1s, box-shadow 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
}

.study-letter-btn:hover {
    background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #b45309, 0 8px 16px rgba(0, 0, 0, 0.2);
}

.study-letter-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #d97706, 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ===== Study Round C: Handwriting ===== */
.hw-trace-wrap {
    position: relative;
    line-height: 0;
}

.hw-trace-canvas {
    width: min(66vw, 230px);
    height: min(66vw, 230px);
    background: #fffdf7;
    border: 3px solid rgba(148, 163, 184, 0.55);
    border-radius: 14px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
    touch-action: none;
    cursor: crosshair;
}

.hw-status {
    min-height: 2.8em;
    max-width: 480px;
    margin: 4px 0;
    padding: 0 12px;
    text-align: center;
    line-height: 1.4;
    font-family: system-ui, 'Microsoft YaHei', sans-serif;
    font-size: 14px;
}

.hw-skip[hidden] { display: none !important; }

.game-btn.hw-eraser {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 72px;
    min-height: 64px;
    padding: 5px 12px;
    font-family: system-ui, 'Microsoft YaHei', sans-serif;
    font-size: 13px;
    line-height: 1.2;
}

.hw-eraser svg { width: 54px; height: 37px; }

/* Separators (space / - / . / ? / !) are not slots at all: no box, no shadow.
   The !important is required because body.kid-friendly .study-slot forces a
   background and border onto every .study-slot. */
.study-slot.hw-slot-fixed {
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

/* The kid theme forces a background/border onto every .study-slot with higher
   specificity, so the separator needs its own kid-mode override. */
body.kid-friendly .study-slot.hw-slot-fixed {
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

/* A letter the student does not have to write — either given as context or
   revealed after they ran out of attempts. Dashed border is the visual language
   for "this one is provided"; a letter they wrote uses a solid .bg-green-500. */
.study-slot.hw-slot-given {
    background: #334155;
    border-color: rgba(255, 255, 255, 0.18);
    border-style: dashed;
    color: #94a3b8;
}

.study-slot.hw-slot-revealed {
    background: #78350f;
    border-color: rgba(251, 191, 36, 0.45);
    color: #fcd34d;
}

/* The gap the next accepted letter will land in. */
.study-slot.hw-slot-active {
    border-color: #fbbf24;
    animation: hw-pulse 1.4s ease-in-out infinite;
}

@keyframes hw-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.22), 0 2px 6px rgba(0, 0, 0, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(251, 191, 36, 0.40), 0 2px 6px rgba(0, 0, 0, 0.2); }
}

/* A rejected trace shakes and wipes. No red: it means "not yet", not "wrong". */
.hw-shake {
    animation: hw-shake 0.32s ease-in-out;
}

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

.sentence-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 70px;
    min-height: var(--touch-min);
    border: 2.5px dashed #94a3b8;
    border-radius: 10px;
    padding: 4px 10px;
    background-color: rgba(255, 255, 255, 0.08);
    transition: all 0.2s;
}

.sentence-slot:empty {
    background-color: rgba(99, 102, 241, 0.08);
}

.study-word-tile {
    background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
    color: #1a1a2e;
    padding: clamp(8px, 2vw, 12px) clamp(14px, 3.5vw, 22px);
    border-radius: 10px;
    font-weight: 700;
    font-size: var(--font-md);
    box-shadow: 0 3px 0 #d97706, 0 4px 10px rgba(0, 0, 0, 0.12);
    transition: transform 0.1s;
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
}

.study-word-tile:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #d97706;
}

.study-word-tile.placed {
    background: linear-gradient(180deg, #818cf8 0%, #6366f1 100%);
    color: white;
    box-shadow: 0 3px 0 #4338ca, 0 4px 10px rgba(0, 0, 0, 0.15);
}

/* Feedback states for tiles after CHECK — must override .placed gradient */
.study-word-tile.\!bg-green-500,
.study-word-tile.placed.\!bg-green-500,
.draggable.correct {
    background: linear-gradient(180deg, #4ade80 0%, #16a34a 100%) !important;
    border-bottom-color: #15803d !important;
    box-shadow: 0 3px 0 #15803d, 0 0 12px rgba(34, 197, 94, 0.4) !important;
}
.study-word-tile.\!bg-red-500,
.study-word-tile.placed.\!bg-red-500,
.draggable.wrong {
    background: linear-gradient(180deg, #f87171 0%, #dc2626 100%) !important;
    border-bottom-color: #991b1b !important;
    box-shadow: 0 3px 0 #991b1b, 0 0 12px rgba(239, 68, 68, 0.4) !important;
    animation: shake 0.3s ease-in-out;
}
/* Spelling slot feedback colors */
.study-slot.bg-green-500 {
    background: #16a34a !important;
    border-color: #15803d !important;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}
.study-slot.bg-red-500 {
    background: #dc2626 !important;
    border-color: #991b1b !important;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.study-text-sm {
    font-size: var(--font-sm);
}

.study-text-md {
    font-size: var(--font-md);
}

.study-text-lg {
    font-size: var(--font-lg);
}

.study-text-xl {
    font-size: var(--font-xl);
}

.study-text-2xl {
    font-size: var(--font-2xl);
}

.letter-bubble {
    width: var(--tile-size);
    height: var(--tile-size);
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    background: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: var(--font-lg);
    font-weight: bold;
    box-shadow: 0 4px 0 #cbd5e1, 0 6px 12px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    border-bottom: none;
    transition: transform 0.1s, opacity 0.15s;
}

.letter-bubble:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #cbd5e1;
}

/* Once a palette bubble has been placed, dim & disable it (it stays visible
   because the palette never depletes, but can't be used twice). */
.letter-bubble.used {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
    box-shadow: none;
    border-bottom-color: #eee;
}

/* Improved Draggable Styles */
.draggable {
    background: linear-gradient(180deg, #FF8A65 0%, #F4511E 100%);
    color: white;
    padding: 10px 18px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    font-size: var(--font-md);
    border-bottom: 4px solid #BF360C;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch-min);
    margin: 4px;
    touch-action: manipulation;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    transition: transform 0.1s;
}

.draggable:active {
    transform: translateY(3px);
    border-bottom-width: 1px;
}

.draggable.correct {
    background-color: #22c55e !important;
    /* Green-500 */
    border-color: #15803d !important;
}

.draggable.wrong {
    background-color: #ef4444 !important;
    /* Red-500 */
    border-color: #b91c1c !important;
    animation: shake 0.3s ease-in-out;
}

/* Improved Drop Zone Styles */
.drop-zone {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-width: 80px;
    min-height: var(--touch-min);
    height: auto;
    border-bottom: 3px dashed #94a3b8;
    margin: 0 4px;
    vertical-align: middle;
    transition: all 0.2s;
    background-color: rgba(99, 102, 241, 0.08);
    border-radius: 10px;
    padding: 4px 6px;
}

.drop-zone.filled {
    border-bottom: none;
    background-color: transparent;
    width: auto;
}

.sentence-row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
    font-size: var(--font-lg);
    line-height: 1.6;
    background: rgba(255, 255, 255, 0.7);
    padding: 12px;
    border-radius: 12px;
    gap: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.floating {
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

.damage-text {
    position: absolute;
    color: #ff0055;
    font-weight: bold;
    font-size: 20px;
    pointer-events: none;
    animation: rise 0.5s ease-out forwards;
    text-shadow: 1px 1px 0px white;
}

@keyframes rise {
    to {
        transform: translateY(-30px);
        opacity: 0;
    }
}

.upgrade-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #FFD700;
    color: #D84315;
    font-weight: bold;
    padding: 5px 10px;
    border-radius: 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    font-size: 0.9rem;
    transform: rotate(10deg);
}

/* Feedback Colors */
.text-red-500 {
    color: #ef4444;
}

.text-green-500 {
    color: #22c55e;
}

/* Translation Hints - base styles defined in responsive section below */

.minigame-container .translation-hint {
    color: #7c3aed;
    background: rgba(139, 92, 246, 0.12);
    border-color: rgba(139, 92, 246, 0.3);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== UNO STYLES ========== */
.uno-card {
    width: 52px;
    height: 76px;
    border-radius: 8px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
    cursor: default;
    transition: transform 0.15s, box-shadow 0.15s;
    -webkit-user-select: none;
    user-select: none;
    flex-shrink: 0;
}

.uno-card .uno-tl {
    position: absolute;
    top: 3px;
    left: 5px;
    font-size: 10px;
}

.uno-card .uno-mid {
    font-size: 22px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.uno-card .uno-br {
    position: absolute;
    bottom: 3px;
    right: 5px;
    font-size: 10px;
    transform: rotate(180deg);
}

.uno-card-big {
    width: 80px;
    height: 115px;
    border-radius: 12px;
    border-width: 3px;
}

.uno-card-big .uno-tl {
    font-size: 14px;
    top: 5px;
    left: 7px;
}

.uno-card-big .uno-mid {
    font-size: 32px;
}

.uno-card-big .uno-br {
    font-size: 14px;
    bottom: 5px;
    right: 7px;
}

.uno-glow {
    cursor: pointer;
    box-shadow: 0 0 12px 4px rgba(250, 204, 21, 0.7);
    border-color: #facc15;
    animation: unoPulse 1s ease-in-out infinite;
}

.uno-glow:hover {
    transform: translateY(-8px) scale(1.08);
    box-shadow: 0 0 20px 6px rgba(250, 204, 21, 0.9);
}

.uno-snap {
    cursor: pointer;
    box-shadow: 0 0 12px 4px rgba(168, 85, 247, 0.7);
    border-color: #a855f7;
    animation: unoSnapPulse 0.6s ease-in-out infinite;
}

.uno-snap:hover {
    transform: translateY(-8px) scale(1.08);
    box-shadow: 0 0 20px 6px rgba(168, 85, 247, 0.9);
}

@keyframes unoPulse {

    0%,
    100% {
        box-shadow: 0 0 8px 2px rgba(250, 204, 21, 0.5);
    }

    50% {
        box-shadow: 0 0 16px 6px rgba(250, 204, 21, 0.8);
    }
}

@keyframes unoSnapPulse {

    0%,
    100% {
        box-shadow: 0 0 8px 2px rgba(168, 85, 247, 0.5);
    }

    50% {
        box-shadow: 0 0 16px 6px rgba(168, 85, 247, 0.9);
    }
}

.uno-card-back {
    width: 18px;
    height: 26px;
    background: linear-gradient(135deg, #1e1b4b, #312e81);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    display: inline-block;
}

.uno-card-back-big {
    width: 80px;
    height: 115px;
    background: linear-gradient(135deg, #1e1b4b, #312e81);
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.uno-ai-box {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    transition: all 0.3s;
}

.uno-active {
    background: rgba(250, 204, 21, 0.12) !important;
    border-color: rgba(250, 204, 21, 0.4) !important;
    box-shadow: 0 0 12px rgba(250, 204, 21, 0.2);
}

#uno-player-area {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s;
}

#uno-player-area.uno-active {
    background: rgba(250, 204, 21, 0.1);
    border-color: rgba(250, 204, 21, 0.35);
}

.uno-draw-btn {
    background: #7c3aed;
    color: white;
    border: none;
    border-bottom: 3px solid #5b21b6;
    border-radius: 10px;
    padding: 8px 16px;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.1s;
    margin-left: 8px;
    align-self: center;
}

.uno-draw-btn:hover {
    background: #6d28d9;
}

.uno-draw-btn:active {
    transform: translateY(2px);
    border-bottom-width: 1px;
}

/* ========== THEME TOGGLE BUTTON ========== */
.theme-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #1e1b4b; /* dark indigo base for dark mode */
    color: #facc15;
    border: 3px solid #facc15;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    z-index: 9999;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    outline: none;
    pointer-events: auto;
}

.theme-toggle-btn:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

.theme-toggle-btn:active {
    transform: scale(0.95);
}

/* ========== KID-FRIENDLY THEME OVERRIDES ========== */
body.kid-friendly {
    background: linear-gradient(135deg, #fff5e6 0%, #ffd1b3 100%);
    font-family: 'Nunito', 'Fredoka', sans-serif;
    color: #4a2c11;
}

/* Floating theme toggle when kid-friendly is active */
body.kid-friendly .theme-toggle-btn {
    background: #fff5e6;
    color: #ff7043;
    border-color: #ff7043;
    box-shadow: 0 4px 15px rgba(220, 100, 50, 0.2);
}

/* Overlays in kid-friendly mode */
body.kid-friendly .overlay {
    background: radial-gradient(circle, #fffbf5 0%, #ffeae0 100%) !important;
    backdrop-filter: blur(8px);
}

/* Cards & containers in kid-friendly mode */
body.kid-friendly .step-container,
body.kid-friendly #loginOverlay > div,
body.kid-friendly #changePasswordOverlay > div,
body.kid-friendly #gameSelectionOverlay > div,
body.kid-friendly #gomokuModeSelectionOverlay > div,
body.kid-friendly #gomokuDifficultySelectionOverlay > div,
body.kid-friendly #gomokuGameOverScreen > div,
body.kid-friendly #unoGameOverScreen > div,
body.kid-friendly #gameOverScreen > div,
body.kid-friendly .minigame-container {
    background-color: rgba(255, 255, 255, 0.95) !important;
    border: 3px solid #ffccbc !important;
    color: #4e342e !important;
    box-shadow: 0 10px 30px rgba(220, 100, 50, 0.15) !important;
    border-radius: 24px !important;
}

/* Headings color */
body.kid-friendly h1,
body.kid-friendly h2,
body.kid-friendly h3,
body.kid-friendly h4 {
    color: #e65100 !important;
    background: none !important;
    -webkit-text-fill-color: initial !important;
    background-clip: border-box !important;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
}

/* Text elements */
body.kid-friendly p,
body.kid-friendly span:not(#themeToggleIcon),
body.kid-friendly label {
    color: #5d4037 !important;
}

/* Inputs styling */
body.kid-friendly input {
    background-color: #efebe9 !important;
    color: #3e2723 !important;
    border: 2px solid #d7ccc8 !important;
    border-radius: 12px !important;
}

body.kid-friendly input:focus {
    border-color: #ff8a65 !important;
    box-shadow: 0 0 0 2px rgba(255, 138, 101, 0.2) !important;
}

/* Game buttons in kid mode */
body.kid-friendly .game-btn {
    background: #ff7043 !important;
    border-bottom: 4px solid #d84315 !important;
    color: white !important;
    border-radius: 16px !important;
    font-family: 'Fredoka', sans-serif;
    transition: transform 0.1s, background-color 0.2s;
}

body.kid-friendly .game-btn:hover {
    background: #ff8a65 !important;
}

body.kid-friendly .game-btn:active {
    transform: translateY(4px);
    border-bottom-width: 0 !important;
}

/* Wizard / selector buttons */
body.kid-friendly .step-container button:not(.game-btn) {
    background: #ffe0b2 !important;
    color: #e65100 !important;
    border: 2px solid #ffcc80 !important;
    border-radius: 12px !important;
    font-weight: bold;
    transition: all 0.2s;
}

body.kid-friendly .step-container button:not(.game-btn):hover {
    background: #ffcc80 !important;
    transform: translateY(-2px);
}

/* Study mode specific overrides */
body.kid-friendly #studyModeOverlay {
    background: radial-gradient(circle, #fffcf7 0%, #ffd9c2 100%) !important;
}

body.kid-friendly #study-title {
    color: #e65100 !important;
    font-family: 'Fredoka', sans-serif;
    font-weight: 700;
}

body.kid-friendly #study-instruction {
    color: #6d4c41 !important;
}

body.kid-friendly .study-slot {
    background: #efebe9 !important;
    border: 2px solid #d7ccc8 !important;
    color: #4e342e !important;
    border-radius: 10px !important;
}

body.kid-friendly .study-letter-btn {
    background: #ffb74d !important;
    color: #3e2723 !important;
    border-bottom: 4px solid #f57c00 !important;
}

body.kid-friendly .study-letter-btn:hover {
    background: #ffa726 !important;
}

body.kid-friendly .hw-trace-canvas {
    border: 3px solid #d7ccc8 !important;
}

body.kid-friendly .study-slot.hw-slot-given {
    background: #efebe9 !important;
    border: 2px dashed #bcaaa4 !important;
    color: #6d4c41 !important;
}

body.kid-friendly .study-slot.hw-slot-revealed {
    background: #ffe0b2 !important;
    border-color: #ffb74d !important;
    color: #6d4c41 !important;
}

body.kid-friendly .study-slot.hw-slot-active {
    border-color: #fb8c00 !important;
}

body.kid-friendly .study-word-tile {
    background: #ffb74d !important;
    color: #3e2723 !important;
}

body.kid-friendly .draggable {
    background: #ff7043 !important;
    border-bottom: 4px solid #d84315 !important;
}

body.kid-friendly .drop-zone {
    background-color: rgba(255, 255, 255, 0.8) !important;
    border-bottom: 3px dashed #ffab91 !important;
}

body.kid-friendly .sentence-row {
    background: rgba(255, 255, 255, 0.8) !important;
    border: 2px solid #ffe0b2 !important;
}

body.kid-friendly .audio-play-btn {
    background: linear-gradient(180deg, #ff7043 0%, #d84315 100%) !important;
    box-shadow: 0 4px 0 #bf360c, 0 6px 16px rgba(216, 67, 21, 0.3) !important;
}

body.kid-friendly .study-word-tile.placed {
    background: linear-gradient(180deg, #ff7043 0%, #e64a19 100%) !important;
    color: white !important;
    box-shadow: 0 3px 0 #bf360c !important;
}

body.kid-friendly .translation-hint {
    color: #e65100 !important;
    background: rgba(255, 152, 0, 0.1) !important;
    border-color: rgba(255, 152, 0, 0.3) !important;
}

/* ========== STUDY MODE LAYOUT ENHANCEMENTS ========== */
#studyModeOverlay {
    padding: 12px 8px;
    justify-content: flex-start;
    padding-top: env(safe-area-inset-top, 12px);
}

#studyModeOverlay #study-title {
    font-size: var(--font-xl);
    margin-bottom: 2px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#studyModeOverlay #study-instruction {
    font-size: var(--font-md);
    margin-bottom: 12px;
    opacity: 0.85;
}

#study-game-area {
    padding: 0 4px;
    max-width: 100%;
}

/* Progress indicator for study rounds */
.study-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    margin-bottom: 12px;
    overflow: hidden;
}

.study-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #34d399);
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* Audio play button — larger for small hands */
.audio-play-btn {
    width: 64px;
    height: 64px;
    min-width: 64px;
    min-height: 64px;
    border-radius: 50%;
    background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    box-shadow: 0 4px 0 #1d4ed8, 0 6px 16px rgba(37, 99, 235, 0.3);
    cursor: pointer;
    transition: transform 0.1s;
    touch-action: manipulation;
}

.audio-play-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #1d4ed8;
}

/* Match pair rows — study mode Round F & game mode */
.match-pair-row {
    background: rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    padding: 6px;
    transition: all 0.2s;
}

.match-pair-row .sentence-a {
    font-size: var(--font-md);
    line-height: 1.4;
    padding: 10px 12px;
    border-radius: 10px;
}

.match-pair-row .sentence-b-slot,
.match-pair-row .gm-sentence-b-slot {
    font-size: var(--font-md);
    min-height: var(--touch-min);
    padding: 10px 12px;
    border-radius: 10px;
}

/* Sentence B tiles — larger tap targets */
.sentence-b-tile,
.gm-sentence-b-tile {
    min-height: var(--touch-min);
    padding: 10px 14px;
    font-size: var(--font-sm);
    border-radius: 10px;
    transition: all 0.15s;
}

.sentence-b-tile:active,
.gm-sentence-b-tile:active {
    transform: scale(0.95);
}

/* ========== MOBILE-FIRST RESPONSIVE RULES ========== */

/* Small phones (up to 380px) */
@media (max-width: 380px) {
    :root {
        --slot-size: clamp(34px, 10vw, 42px);
        --tile-size: clamp(38px, 11vw, 44px);
        --font-sm: 0.8rem;
        --font-md: 0.9rem;
        --gap-sm: 4px;
        --gap-md: 8px;
    }
    
    .game-btn {
        padding: 12px 18px;
        font-size: 1rem;
    }
    
    .minigame-container {
        padding: 10px;
        border-radius: 14px;
    }
    
    .sentence-row {
        font-size: 1rem;
        padding: 8px;
    }
}

/* Standard phones (381px-480px) — PRIMARY TARGET */
@media (max-width: 480px) {
    #studyModeOverlay {
        padding: 10px 6px;
        padding-top: max(10px, env(safe-area-inset-top));
    }
    
    #studyModeOverlay #study-title {
        font-size: 1.2rem;
    }
    
    .minigame-container {
        width: 98vw;
        padding: 12px 10px;
        border-radius: 16px;
    }
    
    .match-pair-row {
        flex-direction: column !important;
    }
    
    .sentence-row {
        padding: 10px 8px;
        gap: 3px;
    }
    
    .drop-zone {
        min-width: 60px;
        margin: 0 2px;
    }
}

/* Tablets and larger phones in landscape */
@media (min-width: 768px) {
    :root {
        --slot-size: clamp(44px, 5vw, 56px);
        --tile-size: clamp(48px, 5.5vw, 60px);
    }
    
    #studyModeOverlay {
        padding: 20px 24px;
    }
    
    .minigame-container {
        padding: 24px;
    }
    
    .match-pair-row {
        flex-direction: row !important;
    }
}

/* Landscape orientation — reduce vertical space, spread horizontally */
@media (orientation: landscape) and (max-height: 500px) {
    #studyModeOverlay {
        padding: 4px 16px;
    }
    
    #studyModeOverlay #study-title {
        font-size: 1rem;
        margin-bottom: 0;
    }
    
    #studyModeOverlay #study-instruction {
        font-size: 0.85rem;
        margin-bottom: 4px;
    }
    
    #study-game-area {
        max-width: 90vw;
    }
    
    .minigame-container {
        max-height: 94vh;
        max-width: 90vw;
    }
    
    .audio-play-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        font-size: 1.1rem;
    }
    
    .game-btn {
        padding: 8px 18px;
        min-height: 40px;
    }
    
    /* In landscape, use horizontal layout for scramble rounds */
    #study-game-area > div {
        gap: 4px !important;
    }
    
    .match-pair-row {
        flex-direction: row !important;
    }
    
    #study-progress-indicator {
        margin-bottom: 4px;
    }
    
    .translation-hint {
        padding: 4px 12px;
        margin: 2px auto 4px;
    }
}

/* Widescreen (large landscape/desktop) — use available horizontal space */
@media (min-width: 900px) and (min-height: 500px) {
    #study-game-area {
        max-width: 800px;
    }
    
    .minigame-container {
        width: min(90vw, 800px);
    }
    
    #sentence-drop-zone,
    #sentence-word-bank,
    #scramble-slots,
    #scramble-bank,
    #handwriting-slots {
        max-width: 700px;
    }
}

/* ========== GAME MODE MINIGAME LAYOUT IMPROVEMENTS ========== */

/* Spelling Game (Word Scramble in game mode) */
#spellingGame .minigame-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#spelling-input-display {
    background: rgba(255, 255, 255, 0.9);
    border: 2.5px dashed #cbd5e1;
    border-radius: 12px;
    padding: 10px 8px;
    min-height: 56px;
}

#spelling-keyboard {
    gap: var(--gap-sm) !important;
}

/* Word Rec Game */
#wordRecGame .minigame-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#rec-options {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--gap-sm);
    width: 100%;
}

#rec-options .game-btn {
    flex: 1 1 calc(50% - var(--gap-sm));
    max-width: calc(50% - var(--gap-sm));
    min-height: 56px;
    font-size: var(--font-lg);
    padding: 14px 12px;
    text-align: center;
    word-break: break-word;
}

@media (max-width: 480px) {
    #rec-options .game-btn {
        flex: 1 1 100%;
        max-width: 100%;
    }
}

/* Grammar Game (Sentence Scramble in game mode) */
#grammarGame .minigame-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#word-dock {
    background: rgba(241, 245, 249, 0.9);
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    padding: 10px;
    min-height: 60px;
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-sm);
    justify-content: center;
    align-items: center;
}

/* Sentence Match Game */
#sentenceMatchGame .minigame-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#sentencematch-pairs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#sentencematch-dock {
    background: rgba(241, 245, 249, 0.9);
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    padding: 10px;
    min-height: 60px;
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-sm);
    justify-content: center;
    align-items: center;
}

/* Timer bars — more visible */
#wordRecGame .bg-gray-300,
#spellingGame .bg-gray-300 {
    height: 8px !important;
    border-radius: 4px;
}

/* Vocab image in rounds */
.vocab-image {
    width: clamp(80px, 25vw, 140px);
    height: clamp(80px, 25vw, 140px);
    object-fit: contain;
    border-radius: 12px;
    border: 2px solid rgba(148, 163, 184, 0.4);
    background: rgba(255, 255, 255, 0.1);
}

/* Translation hint improvements */
.translation-hint {
    font-size: var(--font-md);
    color: #a78bfa;
    background: rgba(139, 92, 246, 0.12);
    border: 1.5px solid rgba(139, 92, 246, 0.3);
    border-radius: 10px;
    padding: 8px 16px;
    margin: 4px auto 8px;
    text-align: center;
    max-width: 95%;
    animation: fadeIn 0.3s ease-in;
    font-weight: 500;
}

/* --- VS character-select cards --- */
.vs-char-card {
    background: rgba(0, 0, 0, 0.45);
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 14px 10px;
    transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.vs-char-card:active { transform: scale(0.97); }
.vs-char-card.vs-char-selected {
    border-color: #facc15;
    box-shadow: 0 0 18px rgba(250, 204, 21, 0.45);
    background: rgba(60, 45, 0, 0.45);
}

/* --- VS 'new version' promo (game-selection menu, shown once per device) --- */
.vs-promo-badge {
    text-align: center;
    font-weight: 800;
    font-size: 1.05rem;
    color: #fff59d;
    text-shadow: 0 0 8px rgba(255, 213, 79, 0.8);
    margin-bottom: -8px;
    animation: vsPromoPulse 1.1s ease-in-out infinite;
}
@keyframes vsPromoPulse {
    0%, 100% { transform: scale(1); opacity: 0.85; }
    50% { transform: scale(1.06); opacity: 1; }
}
.vs-promo-glow {
    animation: vsPromoGlow 1.3s ease-in-out infinite;
    outline: 3px solid #ffd54f;
}
@keyframes vsPromoGlow {
    0%, 100% { box-shadow: 0 0 10px 2px rgba(255, 213, 79, 0.55); }
    50% { box-shadow: 0 0 26px 8px rgba(255, 213, 79, 0.95); }
}
