/* ===== CSS RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    background: linear-gradient(180deg, #f3e8ff 0%, #dbeafe 100%);
    min-height: 100vh;
}

#app {
    position: relative;
    min-height: 100vh;
}

/* ===== SCREEN MANAGEMENT ===== */
.screen {
    display: none;
    min-height: 100vh;
    padding: 1rem;
}

.screen:not(.hidden) {
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.result-container {
    max-width: 600px;
    text-align: center;
}

/* ===== TYPOGRAPHY ===== */
.main-title {
    font-size: 2rem;
    font-weight: 900;
    text-align: center;
    color: #7e22ce;
    margin-bottom: 2rem;
}

.subtitle {
    font-size: 1.25rem;
    text-align: center;
    color: #374151;
    margin-bottom: 2rem;
}

.screen-title {
    font-size: 1.75rem;
    font-weight: 900;
    text-align: center;
    color: #7e22ce;
    margin-bottom: 1rem;
}

/* ===== BUTTONS ===== */
.back-btn {
    background: #6b7280;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
}

.back-btn:hover {
    background: #4b5563;
    transform: translateY(-2px);
}

.back-btn:active {
    transform: translateY(0);
}

/* ===== PLAYER MODE SELECTION ===== */
.player-mode-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    max-width: 800px;
    margin: 0 auto;
}

.mode-card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    padding: 2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.mode-card:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
}

.mode-card:active {
    transform: scale(0.98);
}

.single-mode {
    border: 4px solid #a855f7;
}

.multi-mode {
    border: 4px solid #3b82f6;
}

.mode-emoji {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.mode-title {
    font-size: 1.5rem;
    font-weight: 900;
}

.single-mode .mode-title {
    color: #7e22ce;
}

.multi-mode .mode-title {
    color: #1d4ed8;
}

/* ===== CHARACTER SELECTION ===== */
.character-prompt {
    text-align: center;
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: #374151;
}

.characters-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto 1.5rem;
}

.character-card {
    background: white;
    border: 4px solid #d1d5db;
    border-radius: 1rem;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.character-card:hover {
    transform: scale(1.05);
}

.character-card.selected {
    border-color: #a855f7;
    background: #faf5ff;
}

.character-card.disabled {
    border-color: #d1d5db;
    background: #f3f4f6;
    opacity: 0.5;
    cursor: not-allowed;
}

.character-card.disabled:hover {
    transform: scale(1);
}

.character-emoji {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.character-name {
    font-size: 1rem;
    font-weight: 900;
    color: #374151;
}

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

.continue-btn {
    background: #a855f7;
    color: white;
    padding: 1rem 2rem;
    border-radius: 0.75rem;
    border: none;
    font-size: 1.25rem;
    font-weight: 900;
    cursor: pointer;
    transition: all 0.2s ease;
}

.continue-btn:hover {
    background: #9333ea;
    transform: translateY(-2px);
}

.continue-btn:active {
    transform: translateY(0);
}

/* ===== MAIN MENU ===== */
.selected-characters-card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 1rem;
    margin-bottom: 1rem;
}

.single-character-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.single-character-display .character-emoji {
    font-size: 2.5rem;
}

.single-character-display .character-name {
    font-size: 1.125rem;
}

.multi-character-display {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.player-display {
    text-align: center;
    padding: 0.75rem;
    border-radius: 0.5rem;
}

.player-display.player1 {
    background: #faf5ff;
}

.player-display.player2 {
    background: #eff6ff;
}

.player-display .character-emoji {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.player-label {
    font-size: 0.875rem;
    font-weight: 900;
    color: #374151;
}

.sound-toggle-btn {
    width: 100%;
    background: white;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.sound-toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15);
}

.sound-toggle-btn:active {
    transform: translateY(0);
}

/* ===== LEVELS ===== */
.levels-card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 1rem;
}

.levels-title {
    font-size: 1.25rem;
    font-weight: 900;
    text-align: center;
    margin-bottom: 1rem;
    color: #374151;
}

.level-item {
    padding: 0.75rem;
    border-radius: 0.75rem;
    border: 4px solid;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.level-item.unlocked {
    border-color: #4ade80;
    background: #f0fdf4;
}

.level-item.locked {
    border-color: #d1d5db;
    background: #f3f4f6;
    opacity: 0.5;
}

.level-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.level-emoji {
    font-size: 2rem;
}

.level-details {
    text-align: left;
}

.level-name {
    font-weight: 900;
    color: #374151;
    font-size: 1rem;
}

.level-target {
    font-size: 0.875rem;
    color: #6b7280;
}

.start-level-btn {
    background: #a855f7;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: none;
    font-weight: 900;
    cursor: pointer;
    transition: all 0.2s ease;
}

.start-level-btn:hover {
    background: #9333ea;
    transform: scale(1.05);
}

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

.locked-icon {
    font-size: 1.5rem;
    color: #6b7280;
}

/* ===== GAME SCREEN ===== */
#gameScreen {
    padding: 0.75rem;
}

.floating-sound-btn {
    position: fixed;
    top: 0.5rem;
    right: 0.5rem;
    background: white;
    border: none;
    padding: 0.5rem;
    border-radius: 50%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    font-size: 1.25rem;
    cursor: pointer;
    z-index: 100;
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.floating-sound-btn:hover {
    transform: scale(1.1);
}

.floating-sound-btn:active {
    transform: scale(0.9);
}

.game-header {
    text-align: center;
    margin-bottom: 0.75rem;
}

.level-title {
    font-size: 1.25rem;
    font-weight: 900;
    color: #7e22ce;
}

.game-stats {
    font-size: 0.875rem;
    font-weight: 900;
    color: #dc2626;
    margin-top: 0.25rem;
}

.stat-divider {
    margin: 0 0.5rem;
}

/* ===== PLAYERS INFO ===== */
.players-info {
    margin-bottom: 0.75rem;
}

.single-player-info {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 0.75rem;
    text-align: center;
}

.single-player-info .character-emoji {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.player-score {
    font-size: 0.875rem;
}

.score-value {
    color: #16a34a;
    font-weight: 900;
}

.multi-player-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.player-info-card {
    background: white;
    border-radius: 0.75rem;
    padding: 0.75rem;
    text-align: center;
    transition: all 0.2s ease;
}

.player-info-card.active {
    box-shadow: 0 0 0 4px #fbbf24;
}

.turn-indicator {
    font-size: 0.75rem;
    font-weight: 900;
    color: #d97706;
    margin-bottom: 0.25rem;
}

.player-info-card .character-emoji {
    font-size: 1.5rem;
}

.player-info-card .player-score {
    font-size: 0.75rem;
}

/* ===== HINT BOX ===== */
.hint-box {
    background: #fef3c7;
    border: 2px solid #fbbf24;
    border-radius: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}

.hint-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hint-text {
    flex: 1;
    font-size: 0.75rem;
    font-weight: 700;
    color: #92400e;
}

.next-hint-btn {
    background: #fbbf24;
    color: #92400e;
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    border: none;
    font-size: 0.75rem;
    font-weight: 900;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
}

.next-hint-btn:hover {
    background: #f59e0b;
}

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

/* ===== NUMBER GRID ===== */
.game-grid-container {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 0.5rem;
    margin-bottom: 0.75rem;
}

.grid-title {
    font-size: 0.75rem;
    font-weight: 900;
    text-align: center;
    color: #7e22ce;
    margin-bottom: 0.5rem;
}

.number-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.number-cell {
    aspect-ratio: 1;
    border-radius: 0.25rem;
    border: 2px solid;
    font-weight: 900;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    background: #dbeafe;
    border-color: #3b82f6;
    color: #1e40af;
}

.number-cell:hover:not(.prime):not(.crossed):not(:disabled) {
    background: #bfdbfe;
    transform: scale(1.1);
}

.number-cell:active:not(:disabled) {
    transform: scale(0.95);
}

.number-cell.empty {
    background: transparent;
    border: none;
    cursor: default;
    pointer-events: none;
}

.number-cell.prime {
    background: #22c55e;
    border-color: #16a34a;
    color: white;
}

.number-cell.crossed {
    background: #fecaca;
    border-color: #fca5a5;
    color: #9ca3af;
    text-decoration: line-through;
}

.number-cell:disabled {
    cursor: not-allowed;
}

/* ===== LEGEND ===== */
.legend {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.25rem;
    font-size: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.legend-color {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 0.125rem;
}

.prime-color {
    background: #22c55e;
}

.crossed-color {
    background: #fecaca;
}

.available-color {
    background: #dbeafe;
}

/* ===== GAME ACTIONS ===== */
.game-actions {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.action-btn {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: none;
    font-size: 0.875rem;
    font-weight: 900;
    cursor: pointer;
    color: white;
    transition: all 0.2s ease;
}

.action-btn:hover {
    transform: translateY(-2px);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn.menu-btn {
    background: #ef4444;
}

.action-btn.menu-btn:hover {
    background: #dc2626;
}

.action-btn.restart-btn {
    background: #a855f7;
}

.action-btn.restart-btn:hover {
    background: #9333ea;
}

/* ===== RESULT SCREENS ===== */
.victory-title {
    font-size: 2.25rem;
    font-weight: 900;
    color: #16a34a;
    margin-bottom: 1rem;
}

.victory-emoji {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.timesup-title {
    font-size: 2.25rem;
    font-weight: 900;
    color: #dc2626;
    margin-bottom: 1rem;
}

.result-card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.result-level-name {
    font-size: 1.5rem;
    font-weight: 900;
    margin-bottom: 0.75rem;
    color: #374151;
}

.result-score {
    font-size: 1.25rem;
    color: #374151;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.result-btn {
    width: 100%;
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    border: none;
    font-size: 1.125rem;
    font-weight: 900;
    cursor: pointer;
    color: white;
    transition: all 0.2s ease;
}

.result-btn:hover {
    transform: translateY(-2px);
}

.result-btn:active {
    transform: translateY(0);
}

.next-level-btn {
    background: #22c55e;
}

.next-level-btn:hover {
    background: #16a34a;
}

.menu-btn-result {
    background: #a855f7;
}

.menu-btn-result:hover {
    background: #9333ea;
}

.retry-btn {
    background: #f97316;
}

.retry-btn:hover {
    background: #ea580c;
}

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

/* ===== RESPONSIVE DESIGN ===== */

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
    .characters-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .mode-emoji {
        font-size: 5rem;
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
    .main-title {
        font-size: 2.5rem;
    }

    .player-mode-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .mode-emoji {
        font-size: 6rem;
    }

    .mode-title {
        font-size: 2rem;
    }

    .level-title {
        font-size: 1.5rem;
    }

    .game-stats {
        font-size: 1rem;
    }

    .hint-text {
        font-size: 0.875rem;
    }

    .number-grid {
        gap: 0.375rem;
    }

    .number-cell {
        font-size: 1rem;
    }

    .grid-title {
        font-size: 0.875rem;
    }

    .legend {
        font-size: 0.875rem;
    }

    .legend-color {
        width: 1rem;
        height: 1rem;
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    #gameScreen {
        padding: 1.5rem;
    }

    .game-header {
        margin-bottom: 1rem;
    }

    .players-info {
        margin-bottom: 1rem;
    }

    .hint-box {
        margin-bottom: 1rem;
    }

    .game-grid-container {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .number-grid {
        gap: 0.5rem;
    }

    .number-cell {
        font-size: 1.125rem;
    }
}

/* Prevent text selection on interactive elements */
button,
.mode-card,
.character-card,
.number-cell {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .number-cell:hover:not(.prime):not(.crossed):not(:disabled) {
        transform: none;
    }

    .number-cell:active:not(:disabled) {
        transform: scale(0.9);
        background: #93c5fd;
    }
}