* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 1200px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
    position: relative;
}

.screen {
    display: none;
}

.screen.active {
    display: block;
}

h1 {
    font-size: 2.5em;
    color: #333;
    text-align: center;
    margin-bottom: 10px;
}

h2 {
    font-size: 2em;
    color: #333;
    text-align: center;
    margin-bottom: 30px;
}

h3 {
    font-size: 1.5em;
    color: #333;
    text-align: center;
    margin-bottom: 20px;
}

.subtitle {
    text-align: center;
    color: #666;
    font-size: 1.1em;
    margin-bottom: 30px;
}

.instructions {
    background: #f8f9fa;
    border-radius: 14px;
    padding: 24px 28px;
    margin-bottom: 30px;
    border-left: 4px solid #2196F3;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.04);
}

.instructions-title {
    font-size: 1.2em;
    font-weight: 700;
    color: #333;
    margin-bottom: 14px;
}

.instructions-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 10px 24px;
}

.instructions-list li {
    display: flex;
    align-items: flex-start;
    font-size: 0.95em;
    color: #555;
    line-height: 1.6;
}

.instructions-list .bullet-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    margin-right: 8px;
    font-size: 0.8em;
    font-weight: 700;
    color: #1976D2;
    background: #e3f2fd;
}

.instructions-list strong {
    font-weight: 700;
}

.start-form {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 25px;
    margin-bottom: 30px;
}

.form-group {
    margin-bottom: 25px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 1em;
    color: #333;
    font-weight: 600;
    margin-bottom: 12px;
    text-align: center;
}

#playerName {
    width: 100%;
    padding: 12px 15px;
    font-size: 1em;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    transition: border-color 0.3s ease;
    font-family: inherit;
}

#playerName:focus {
    outline: none;
    border-color: #667eea;
}

.difficulty-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-difficulty {
    flex: 1;
    min-width: 120px;
    padding: 20px 15px;
    font-size: 1em;
    background: white;
    border: 3px solid #e0e0e0;
    color: #333;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: none;
    letter-spacing: normal;
}

.btn-difficulty[data-difficulty="easy"] {
    border-color: #4caf50;
    background: #e8f5e9;
    color: #2e7d32;
}

.btn-difficulty[data-difficulty="easy"]:hover {
    border-color: #4caf50;
    background: #c8e6c9;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3);
}

.btn-difficulty[data-difficulty="easy"].selected {
    background: linear-gradient(135deg, #4caf50 0%, #66bb6a 100%);
    color: white;
    border-color: #4caf50;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
}

.btn-difficulty[data-difficulty="medium"] {
    border-color: #2196F3;
    background: #e3f2fd;
    color: #1565c0;
}

.btn-difficulty[data-difficulty="medium"]:hover {
    border-color: #2196F3;
    background: #bbdefb;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(33, 150, 243, 0.3);
}

.btn-difficulty[data-difficulty="medium"].selected {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    color: white;
    border-color: #2196F3;
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.4);
}

.btn-difficulty[data-difficulty="hard"] {
    border-color: #f44336;
    background: #ffebee;
    color: #c62828;
}

.btn-difficulty[data-difficulty="hard"]:hover {
    border-color: #f44336;
    background: #ffcdd2;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(244, 67, 54, 0.3);
}

.btn-difficulty[data-difficulty="hard"].selected {
    background: linear-gradient(135deg, #f44336 0%, #ef5350 100%);
    color: white;
    border-color: #f44336;
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.4);
}

.difficulty-range {
    display: block;
    font-size: 0.85em;
    margin-top: 5px;
    opacity: 0.8;
}

.btn-difficulty.selected .difficulty-range {
    opacity: 0.9;
}

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

.game-header-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.best-badge {
    align-self: flex-start;
    padding: 4px 10px;
    border-radius: 999px;
    background: #fff3e0;
    border: 1px solid #ffb74d;
    font-size: 0.8em;
    font-weight: 600;
    color: #f57c00;
}

.difficulty-badge {
    min-width: 120px;
    text-align: center;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.difficulty-badge-label {
    font-size: 0.85em;
}

.difficulty-badge-range {
    font-size: 0.75em;
    opacity: 0.85;
}

.difficulty-badge.easy {
    background: #e8f5e9;
    color: #2e7d32;
    border-color: #4caf50;
}

.difficulty-badge.medium {
    background: #e3f2fd;
    color: #1565c0;
    border-color: #2196F3;
}

.difficulty-badge.hard {
    background: #ffebee;
    color: #c62828;
    border-color: #f44336;
}

.game-info {
    display: flex;
    justify-content: space-around;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 20px;
}

.current-number-display {
    text-align: center;
}

.label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 10px;
    font-weight: 500;
}

.number-display {
    font-size: 3em;
    font-weight: bold;
    color: #2196F3;
    background: #f0f0f0;
    border-radius: 15px;
    padding: 20px 40px;
    min-width: 150px;
    text-align: center;
}

.numbers-placed {
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.numbers-placed-label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.numbers-placed-counter {
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    padding: 8px 18px;
    border-radius: 999px;
    background: #e3f2fd;
    border: 2px solid #2196F3;
    font-weight: 700;
    color: #1565c0;
    gap: 3px;
}

.numbers-placed-counter span {
    font-size: 1.6em;
}

.high-score {
    font-size: 0.9em !important;
    margin-top: 5px;
}

.high-score span {
    font-size: 1.2em;
    color: #ff9800;
}

.slots-container {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.slot {
    background: #f8f9fa;
    border: 3px solid #e0e0e0;
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    min-height: 100px;
    width: 80px;
    flex: 0 0 80px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.slot:hover:not(.filled):not(.disabled) {
    border-color: #2196F3;
    background: #e3f2fd;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(33, 150, 243, 0.3);
}

.slot.filled {
    background: #e8f5e9;
    border-color: #4caf50;
    cursor: pointer;
}

.slot.filled.movable {
    background: #e3f2fd;
    border-color: #2196F3;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.slot.filled.movable:active {
    cursor: grabbing;
}

.slot.filled:hover.movable {
    background: #bbdefb;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(33, 150, 243, 0.4);
}

.slot.drag-over {
    background: #90caf9;
    border-color: #2196F3;
    border-width: 4px;
}

.slot.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.slot.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.slot-number {
    font-size: 0.9em;
    color: #999;
    font-weight: 600;
    margin-bottom: 5px;
}

.slot-content {
    font-size: 1.8em;
    font-weight: bold;
    color: #333;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.score-display {
    text-align: center;
    margin: 10px 0 24px;
}

.score-label {
    font-size: 0.95em;
    color: #888;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
}

.final-score-display {
    font-size: 4.5em;
    font-weight: 800;
    color: #1976D2;
    margin: 0;
    padding: 22px 42px;
    background: radial-gradient(circle at top, #e8f3ff 0%, #d0e4ff 45%, #bcd8ff 100%);
    border-radius: 24px;
    border: none;
    display: inline-block;
    min-width: 160px;
    box-shadow: 0 16px 40px rgba(25, 118, 210, 0.35);
}

.final-score-display.highlighted {
    animation: scorePulse 1s ease-in-out;
}

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

.player-stats {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 25px;
    margin: 30px 0;
    border-left: 4px solid #2196F3;
}

.player-stats h3 {
    text-align: center;
    margin-bottom: 20px;
    color: #333;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    justify-items: center;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    background: white;
    border-radius: 8px;
    min-width: 150px;
}

.stat-label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 8px;
    font-weight: 500;
}

.stat-value {
    font-size: 2em;
    font-weight: bold;
    color: #2196F3;
}

.game-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-over-controls {
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn {
    padding: 15px 40px;
    font-size: 1.1em;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.4);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.6);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.start-button-group {
    text-align: center;
    margin-top: 10px;
}

.btn-start {
    padding: 14px 48px;
    font-size: 1.05em;
    font-weight: 700;
    border-radius: 999px;
    background: linear-gradient(135deg, #43a047 0%, #66bb6a 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(76, 175, 80, 0.45);
}

.btn-start:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(76, 175, 80, 0.6);
}

.btn-start:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.message {
    text-align: center;
    font-size: 1.05em;
    color: #555;
    margin: 22px auto 26px;
    padding: 14px 22px;
    background: #f9fafb;
    border-radius: 999px;
    max-width: 780px;
}

.final-slots {
    margin: 28px 0 18px;
}

.final-slots h3 {
    font-size: 1.15em;
    margin-bottom: 16px;
}

.final-slots .slots-container {
    padding: 14px 18px;
    border-radius: 14px;
    background: #fafafa;
    border: 1px dashed #e0e0e0;
}

.final-slots .slot {
    cursor: default;
}

.final-slots .slot:hover {
    transform: none;
    border-color: #4caf50;
}

.problem-number-display {
    text-align: center;
    margin: 26px 0 24px;
    padding: 20px 24px;
    background: #fff7f7;
    border-radius: 16px;
    border: 1px solid #ffcdd2;
}

.problem-label {
    font-size: 0.9em;
    color: #888;
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.problem-number {
    font-size: 3.2em;
    font-weight: 800;
    color: #d32f2f;
    margin: 10px 0 6px;
    padding: 14px 26px;
    background: #ffebee;
    border-radius: 18px;
}

.blocking-numbers {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.blocking-number {
    font-size: 1.6em;
    font-weight: 700;
    color: #fff;
    background: #ef5350;
    padding: 10px 20px;
    border-radius: 999px;
    border: none;
    box-shadow: 0 6px 16px rgba(244, 67, 54, 0.35);
}

.slot.highlight-problem {
    background: #ffebee !important;
    border-color: #f44336 !important;
    border-width: 4px !important;
    box-shadow: 0 0 15px rgba(244, 67, 54, 0.6) !important;
}

/* Home screen difficulty stats */
.difficulty-stats-wrapper {
    margin-top: 20px;
}

.difficulty-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.difficulty-stat {
    background: #ffffff;
    border-radius: 8px;
    padding: 10px 15px;
    min-width: 160px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.difficulty-name {
    font-weight: 700;
    color: #333;
}

.difficulty-high-score,
.difficulty-perfects {
    font-size: 0.9em;
    color: #555;
}

.difficulty-perfects span {
    font-weight: 600;
    color: #ff9800;
}

/* Fireworks celebration */
.fireworks-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 20;
}

.gameOverScreen,
#gameOverScreen {
    position: relative;
}

.celebration-active .final-score-display {
    box-shadow: 0 0 40px rgba(255, 193, 7, 0.9);
}

.firework {
    position: absolute;
    bottom: 0;
    width: 4px;
    height: 80px;
    background: transparent;
    animation: fireworkShoot 1s ease-out infinite;
    animation-delay: var(--fw-delay, 0s);
}

.firework::before {
    content: '';
    position: absolute;
    top: 0;
    left: -40px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.9);
    box-shadow:
        0 0 0 2px rgba(255, 193, 7, 0.8),
        0 0 20px 4px rgba(255, 235, 59, 0.9);
    opacity: 0;
    transform: scale(0.1);
    animation: fireworkExplode 1s ease-out infinite;
    animation-delay: var(--fw-delay, 0s);
}

@keyframes fireworkShoot {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    70% {
        transform: translateY(-60vh);
        opacity: 1;
    }
    100% {
        transform: translateY(-60vh);
        opacity: 0;
    }
}

@keyframes fireworkExplode {
    0% {
        opacity: 0;
        transform: scale(0.1);
    }
    30% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(1.5);
    }
}

/* Win animation */
@keyframes winPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.slot.filled.win {
    animation: winPulse 0.5s ease;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    h1 {
        font-size: 2em;
    }

    h2 {
        font-size: 1.5em;
    }

    .slots-container {
        flex-wrap: nowrap;
        gap: 10px;
        overflow-x: auto;
    }
    
    .slot {
        width: 70px;
        flex: 0 0 70px;
        min-width: 70px;
    }

    .slot {
        min-height: 80px;
        padding: 10px;
    }

    .number-display {
        font-size: 2em;
        padding: 15px 30px;
    }
}
