/* === CSS Variables — Magic Theme === */
:root {
    --primary: #7B2FBE;
    --primary-light: #9B59B6;
    --primary-dark: #5B1F8E;
    --gold: #FFD700;
    --gold-dark: #DAA520;
    --success: #4CAF50;
    --success-light: #81C784;
    --error: #FF5252;
    --error-light: #FF8A80;
    --bg-dark: #1a0533;
    --bg-darker: #0f0220;
    --bg-card: rgba(255, 255, 255, 0.08);
    --bg-card-solid: #2a1548;
    --text-light: #f0e6ff;
    --text-white: #ffffff;
    --text-muted: #b8a0d0;
    --border-glow: rgba(123, 47, 190, 0.5);
    --font-size-base: 16px;
    --font-size-lg: 1.25rem;
    --font-size-xl: 1.5rem;
    --font-size-2xl: 2rem;
    --font-size-3xl: 2.5rem;
    --radius: 12px;
    --radius-lg: 20px;
    --touch-min: 48px;
    --transition: 0.3s ease;
}

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

html {
    font-size: var(--font-size-base);
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark) url('../images/bg/bg-texture.png') repeat;
    background-size: 1024px 1024px;
    color: var(--text-light);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* Hide scrollbars globally — mobile game feel */
body, #game-container {
    scrollbar-width: none;
}
body::-webkit-scrollbar,
#game-container::-webkit-scrollbar {
    display: none;
}

/* === Game Container === */
#game-container {
    position: relative;
    z-index: 1;
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* === Header === */
#game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: rgba(15, 2, 32, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-glow);
    position: sticky;
    top: 0;
    z-index: 100;
}

#game-header.hidden {
    display: none;
}

.header-title {
    font-size: var(--font-size-lg);
    font-weight: bold;
    color: var(--gold);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.coins-counter {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--font-size-lg);
    font-weight: bold;
    color: var(--gold);
    position: relative;
}

.coin-icon {
    width: 22px;
    height: 22px;
    object-fit: contain;
    vertical-align: middle;
}

.coins-popup {
    position: absolute;
    right: 0;
    top: -20px;
    font-size: 0.9rem;
    color: var(--gold);
    font-weight: bold;
    animation: coinPopup 1s ease-out forwards;
    pointer-events: none;
}

.coins-popup.hidden {
    display: none;
}

@keyframes coinPopup {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-30px); }
}

/* === Views === */
.view {
    display: none;
    flex: 1;
    flex-direction: column;
}

.view.active {
    display: flex;
}

/* === Start Screen === */
#view-start {
    background: url('../images/bg/bg-splash.png') center center / cover no-repeat;
}

.start-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    gap: 12px;
    background: linear-gradient(
        180deg,
        rgba(15, 2, 32, 0.45) 0%,
        rgba(15, 2, 32, 0.7) 40%,
        rgba(15, 2, 32, 0.7) 60%,
        rgba(15, 2, 32, 0.45) 100%
    );
}

.start-character {
    animation: float 3s ease-in-out infinite;
    filter: drop-shadow(0 0 20px rgba(123, 47, 190, 0.6));
    line-height: 1;
}

.start-character img {
    width: 120px;
    height: 120px;
    object-fit: contain;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.start-title {
    font-size: var(--font-size-3xl);
    color: var(--gold);
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
    letter-spacing: 2px;
}

.start-subtitle {
    font-size: var(--font-size-lg);
    color: var(--text-muted);
    font-weight: normal;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

/* Name input */
/* Player selection */
.player-select {
    width: 100%;
    max-width: 320px;
}

.player-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.player-select-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 2px solid var(--primary-light);
    border-radius: var(--radius);
    color: var(--text-white);
    font-size: var(--font-size-lg);
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}

.player-select-btn:active {
    transform: scale(0.97);
    border-color: var(--gold);
    background: var(--primary);
}

.player-select-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.player-select-name {
    flex: 1;
    font-weight: bold;
}

.player-select-coins {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--font-size-base);
    color: var(--gold);
}

.coin-icon-sm {
    width: 18px;
    height: 18px;
}

.player-select-new {
    border-style: dashed;
    justify-content: center;
    opacity: 0.7;
}

.player-select-new:active {
    opacity: 1;
}

.player-form.hidden,
.player-select.hidden {
    display: none;
}

.start-name-field {
    width: 100%;
    max-width: 260px;
    margin: 0 auto;
}

.start-name-input {
    width: 100%;
    padding: 10px 16px;
    font-size: var(--font-size-lg);
    font-weight: bold;
    text-align: center;
    color: var(--gold);
    background: var(--bg-card);
    border: 2px solid var(--primary-light);
    border-radius: var(--radius);
    outline: none;
    caret-color: var(--gold);
}

.start-name-input::placeholder {
    color: var(--text-muted);
    font-weight: normal;
    font-size: var(--font-size-base);
}

.start-name-input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.3);
}

/* Avatar picker */
.start-avatar-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

.avatar-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.avatar-option {
    width: 52px;
    height: 52px;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.avatar-option img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.avatar-option:active {
    transform: scale(0.9);
}

.avatar-option.selected {
    border-color: var(--gold);
    background: rgba(255, 215, 0, 0.15);
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.3);
}

.start-flavor {
    font-size: 1rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 12px;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--touch-min);
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: var(--font-size-lg);
    font-weight: bold;
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--text-white);
    border: 2px solid var(--gold);
    box-shadow: 0 4px 15px rgba(123, 47, 190, 0.4);
}

.btn-primary:active {
    box-shadow: 0 2px 8px rgba(123, 47, 190, 0.3);
}

.btn-large {
    width: 100%;
    max-width: 300px;
    min-height: 56px;
    font-size: var(--font-size-xl);
    border-radius: var(--radius-lg);
}

/* === Toggle switch setting === */
.toggle-setting {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    padding: 6px 0;
}

.toggle-checkbox {
    display: none;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    transition: background var(--transition);
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition);
}

.toggle-checkbox:checked + .toggle-switch {
    background: var(--primary-light);
}

.toggle-checkbox:checked + .toggle-switch::after {
    left: 23px;
    background: var(--gold);
}

.toggle-label {
    font-size: var(--font-size-base);
    color: var(--text-light);
}

.btn-option {
    background: var(--bg-card);
    color: var(--text-white);
    border: 2px solid var(--primary-light);
    min-height: 56px;
    font-size: var(--font-size-xl);
}

.btn-option:active {
    background: var(--primary);
    border-color: var(--gold);
}

.btn-option.selected-correct {
    background: var(--success);
    border-color: var(--success-light);
}

.btn-option.selected-wrong {
    background: var(--error);
    border-color: var(--error-light);
    animation: shake 0.5s ease-in-out;
}

/* === Results Screen === */
#results-title {
    font-size: var(--font-size-2xl);
    color: var(--gold);
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

.results-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    gap: 20px;
}

.results-stars {
    font-size: 3rem;
    letter-spacing: 8px;
}

.results-coins {
    font-size: var(--font-size-xl);
    color: var(--gold);
    font-weight: bold;
}

.results-stats {
    color: var(--text-muted);
    font-size: 1rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.victory-boss-emoji {
    font-size: 3rem;
    letter-spacing: 8px;
}

.victory-boss-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.star--earned {
    filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.6));
}

.star--empty {
    opacity: 0.4;
    font-size: 2.5rem;
}

/* === Feedback Animations === */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

@keyframes pulseGreen {
    0% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.6); }
    70% { box-shadow: 0 0 0 20px rgba(76, 175, 80, 0); }
    100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}

@keyframes pulseRed {
    0% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.6); }
    70% { box-shadow: 0 0 0 20px rgba(255, 82, 82, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0); }
}

.feedback-correct {
    animation: pulseGreen 0.8s ease-out;
}

.feedback-wrong {
    animation: shake 0.5s ease-in-out, pulseRed 0.8s ease-out;
}

.feedback-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    pointer-events: none;
}

.feedback-emoji {
    font-size: 4rem;
    animation: feedbackPop 0.8s ease-out forwards;
}

.feedback-vfx {
    width: 120px;
    height: 120px;
    object-fit: contain;
    animation: feedbackPop 0.8s ease-out forwards;
}

@keyframes feedbackPop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

/* === Cat Cheerleader === */
.cat-cheer {
    position: fixed;
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    z-index: 250;
    pointer-events: none;
    animation: catCheerIn 0.5s ease-out;
}

.cat-cheer-emoji {
    font-size: 3.5rem;
    animation: catBounce 0.6s ease-in-out infinite;
}

.cat-cheer-text {
    font-size: var(--font-size-lg);
    font-weight: bold;
    color: var(--gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    background: rgba(15, 2, 32, 0.85);
    padding: 6px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--gold);
    white-space: nowrap;
}

.cat-cheer--super .cat-cheer-emoji {
    font-size: 4.5rem;
}

.cat-cheer--super .cat-cheer-text {
    font-size: var(--font-size-xl);
    color: var(--text-white);
    background: linear-gradient(135deg, var(--primary) 0%, var(--gold-dark) 100%);
    border: 2px solid var(--gold);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
}

.cat-cheer--out {
    animation: catCheerOut 0.5s ease-in forwards;
}

@keyframes catCheerIn {
    0% { transform: translateX(-50%) translateY(40px) scale(0); opacity: 0; }
    60% { transform: translateX(-50%) translateY(-10px) scale(1.1); opacity: 1; }
    100% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}

@keyframes catCheerOut {
    to { transform: translateX(-50%) translateY(-30px); opacity: 0; }
}

@keyframes catBounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-8px) rotate(-5deg); }
    75% { transform: translateY(-8px) rotate(5deg); }
}

/* === Utility === */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

/* === Tablet breakpoint === */
@media (min-width: 768px) {
    :root {
        --font-size-base: 18px;
    }

    #game-container {
        max-width: 520px;
    }
}
