/* === CSS Variables === */
:root {
    --color-primary: #3F6F78;
    --color-text: #6F6F6F;
    --color-text-dark: #4A5E62;
    --color-button-text: #FFFDF9;
    --color-blob-gold: rgba(241, 203, 136, 0.5);
    --color-blob-pink: rgba(255, 182, 193, 0.4);
    --color-blob-gray: rgba(200, 200, 200, 0.4);
    --color-blob-beige: rgba(245, 222, 179, 0.5);
    --color-background: #FAFAFA;
    --color-game-border: #3F6F78;
    --color-success: #4CAF50;
    --color-error: #F44336;
    
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'Playfair Display', Georgia, serif;
    
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

/* === Reset & Base === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    min-height: 100%;
    min-height: -webkit-fill-available;
    font-family: var(--font-main);
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: var(--color-text);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    /* Safe area for notch devices */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* === Screen Container === */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    opacity: 0;
    transition: opacity var(--transition-normal);
    overflow: hidden;
}

.screen.active {
    display: flex;
    opacity: 1;
}

/* === Lamp Decoration === */
.lamp {
    position: absolute;
    width: 45px;
    height: 45px;
    z-index: 10;
    object-fit: contain;
}

.lamp-welcome {
    top: 20px;
    right: 40px;
    animation: glow 2s ease-in-out infinite;
}

.lamp-rules,
.lamp-game,
.lamp-loading,
.lamp-congrats,
.lamp-difficulty {
    top: 20px;
    left: 20px;
    animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
    0%, 100% { filter: brightness(1) drop-shadow(0 0 5px rgba(255, 200, 0, 0.3)); transform: scale(1); }
    50% { filter: brightness(1.2) drop-shadow(0 0 15px rgba(255, 200, 0, 0.6)); transform: scale(1.05); }
}

/* === Welcome Screen === */
#screen-welcome {
    background: linear-gradient(180deg, #FFFFFF 0%, #F5F0E8 50%, #E8E0D8 100%);
}

.welcome-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
    position: relative;
}

.decorations {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.plane-container {
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 250px;
    height: 100px;
}

.dotted-line {
    position: absolute;
    width: 200px;
    height: 80px;
    top: 20px;
    left: 0;
    object-fit: contain;
    opacity: 0.7;
}

.plane {
    position: absolute;
    width: 40px;
    height: 30px;
    top: 0;
    left: 30px;
    object-fit: contain;
    animation: fly 4s ease-in-out infinite;
}

@keyframes fly {
    0%, 100% { transform: translate(0, 0) rotate(-15deg); }
    50% { transform: translate(120px, 40px) rotate(15deg); }
}

.welcome-text {
    text-align: center;
    z-index: 5;
    margin-bottom: 20px;
}

.welcome-title {
    font-family: var(--font-main);
    font-size: 32px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 16px;
}

.welcome-description {
    font-size: 16px;
    line-height: 1.5;
    color: var(--color-text);
    max-width: 320px;
}

.welcome-illustration {
    position: relative;
    width: 320px;
    height: 380px;
    margin-top: 20px;
}

.blob {
    position: absolute;
    object-fit: contain;
    animation: float-blob 6s ease-in-out infinite;
}

.blob-pink {
    width: 180px;
    height: 150px;
    top: 20px;
    left: -20px;
    animation-delay: 0s;
    opacity: 0.8;
}

.blob-gray {
    width: 200px;
    height: 180px;
    top: 40px;
    right: -30px;
    animation-delay: -2s;
    opacity: 0.7;
}

.blob-beige {
    width: 280px;
    height: 220px;
    bottom: 20px;
    left: 20px;
    animation-delay: -4s;
    opacity: 0.9;
}

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

.people-illustration {
    position: absolute;
    width: 260px;
    height: 380px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    object-fit: contain;
    animation: bounce-in 0.8s ease-out;
}

/* === Difficulty Screen === */
#screen-difficulty {
    background: linear-gradient(180deg, #F0F4F8 0%, #E0E8F0 100%);
    background-image: 
        radial-gradient(circle at 30% 30%, rgba(63, 111, 120, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 70% 70%, rgba(241, 203, 136, 0.15) 0%, transparent 50%);
}

.lamp-difficulty {
    top: 20px;
    left: 20px;
    animation: glow 2s ease-in-out infinite;
}

.difficulty-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    margin-top: 30px;
}

.difficulty-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    border: 2px solid transparent;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.difficulty-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.difficulty-card:active {
    transform: translateY(0);
}

.difficulty-card.easy {
    border-color: #4CAF50;
}

.difficulty-card.easy:hover {
    background: rgba(76, 175, 80, 0.1);
}

.difficulty-card.medium {
    border-color: #FF9800;
}

.difficulty-card.medium:hover {
    background: rgba(255, 152, 0, 0.1);
}

.difficulty-card.hard {
    border-color: #F44336;
}

.difficulty-card.hard:hover {
    background: rgba(244, 67, 54, 0.1);
}

.difficulty-icon {
    font-size: 36px;
}

.difficulty-name {
    font-family: var(--font-main);
    font-size: 20px;
    font-weight: 600;
    color: var(--color-primary);
}

.difficulty-range {
    font-size: 14px;
    color: var(--color-text);
    margin-top: 4px;
}

.difficulty-info {
    margin-top: 20px;
    padding: 12px 24px;
    background: rgba(63, 111, 120, 0.1);
    border-radius: 12px;
}

/* === Rules Screen === */
#screen-rules {
    background: linear-gradient(180deg, #F8F4F0 0%, #EDE6E0 100%);
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(241, 203, 136, 0.2) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 182, 193, 0.15) 0%, transparent 50%);
}

.rules-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 380px;
}

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

.screen-title {
    font-family: var(--font-main);
    font-size: 32px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 16px;
}

.screen-description {
    font-size: 16px;
    line-height: 1.5;
    color: var(--color-text);
    margin-bottom: 12px;
}

.example-numbers {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 24px 0;
}

.example-number {
    position: relative;
    width: 55px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
}

.number-blob {
    position: absolute;
    width: 100%;
    height: 100%;
}

.example-number span {
    position: relative;
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    color: var(--color-text-dark);
    z-index: 2;
}

.correct-answer {
    animation: pulse 1.5s ease-in-out infinite;
}

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

.cat-illustration {
    width: 250px;
    height: 200px;
    margin-top: 30px;
    object-fit: contain;
    animation: wave 2s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% { transform: rotate(-3deg) translateY(0); }
    50% { transform: rotate(3deg) translateY(-5px); }
}

/* === Game Screen === */
#screen-game {
    background: linear-gradient(180deg, #E8EEF0 0%, #D4DFE3 100%);
    background-image: 
        radial-gradient(circle at 30% 70%, rgba(63, 111, 120, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 70% 30%, rgba(241, 203, 136, 0.15) 0%, transparent 50%);
}

.game-header {
    text-align: center;
    padding: 15px 20px;
    z-index: 5;
    width: 100%;
    max-width: 400px;
}

.btn-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
    border-radius: 50%;
    font-size: 24px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    transition: all var(--transition-fast);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close:hover {
    background: var(--color-primary);
    color: var(--color-button-text);
    transform: scale(1.1);
}

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

.timer {
    font-family: var(--font-main);
    font-size: 42px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 8px;
    font-variant-numeric: tabular-nums;
}

.game-subtitle {
    font-size: 16px;
    color: var(--color-text);
}

.game-container {
    flex: 1;
    width: 95%;
    max-width: 500px;
    padding: 10px;
    margin: 5px 0 10px;
    border: 3px solid var(--color-game-border);
    border-radius: 32px;
    position: relative;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    min-height: 500px;
}

.game-number {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform var(--transition-fast);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    width: 120px;
    height: 120px;
}

.game-number:hover {
    transform: scale(1.08);
    z-index: 10;
}

.game-number:active {
    transform: scale(0.95);
}

.game-number svg {
    width: 100%;
    height: 100%;
    transition: all var(--transition-fast);
}

.game-number span {
    position: absolute;
    font-family: var(--font-display);
    font-size: 56px;
    font-weight: 700;
    color: var(--color-text-dark);
    z-index: 2;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.15);
}

.game-number.correct {
    animation: correct-flash 0.4s ease;
}

.game-number.correct svg path {
    fill: var(--color-success);
    fill-opacity: 0.6;
}

.game-number.wrong {
    animation: wrong-shake 0.4s ease;
}

.game-number.wrong svg path {
    fill: var(--color-error);
    fill-opacity: 0.6;
}

@keyframes correct-flash {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

@keyframes wrong-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.game-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    padding: 15px;
    font-size: 16px;
    color: var(--color-text);
}

.game-stats strong {
    color: var(--color-primary);
}

/* === Loading Screen === */
#screen-loading {
    background: linear-gradient(180deg, #FFF5F5 0%, #FFE8E8 100%);
    background-image: 
        radial-gradient(circle at 50% 50%, rgba(255, 100, 100, 0.1) 0%, transparent 60%);
}

.loading-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.heart-animation {
    font-size: 100px;
    animation: heartbeat 1s ease-in-out infinite;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.2); }
    30% { transform: scale(1); }
    45% { transform: scale(1.15); }
    60% { transform: scale(1); }
}

.loading-text {
    font-size: 18px;
    color: var(--color-text);
    margin-top: 30px;
}

.loading-dots {
    display: flex;
    gap: 8px;
    margin-top: 20px;
}

.loading-dots span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-primary);
    animation: dots 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dots {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* === Congratulation Screen === */
#screen-congratulation {
    background: linear-gradient(180deg, #F0FFF4 0%, #E8F5E9 100%);
    background-image: 
        radial-gradient(circle at 30% 30%, rgba(76, 175, 80, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 70% 70%, rgba(241, 203, 136, 0.2) 0%, transparent 50%);
}

.congrats-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    max-width: 380px;
}

.woman-illustration {
    width: 320px;
    height: 300px;
    margin-top: 40px;
    object-fit: contain;
    animation: celebrate 2s ease-in-out infinite;
}

@keyframes celebrate {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-10px) scale(1.02); }
}

/* === Button Styles === */
.btn-primary {
    width: 90%;
    max-width: 340px;
    height: 55px;
    margin-bottom: 30px;
    background: var(--color-primary);
    color: var(--color-button-text);
    font-family: var(--font-main);
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 40px;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 4px 15px rgba(63, 111, 120, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(63, 111, 120, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(63, 111, 120, 0.3);
}

/* === Transitions between screens === */
.screen-enter {
    animation: screen-fade-in 0.4s ease forwards;
}

.screen-exit {
    animation: screen-fade-out 0.3s ease forwards;
}

@keyframes screen-fade-in {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes screen-fade-out {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-20px); }
}

@keyframes bounce-in {
    0% { transform: translate(-50%, -50%) scale(0); }
    50% { transform: translate(-50%, -50%) scale(1.1); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

/* === Mobile Responsive === */
@media (max-width: 400px) {
    .welcome-title,
    .screen-title {
        font-size: 26px;
    }
    
    .welcome-description,
    .screen-description {
        font-size: 14px;
    }
    
    .game-container {
        padding: 12px;
        min-height: 300px;
    }
    
    .game-number {
        width: 65px;
        height: 60px;
    }
    
    .game-number span {
        font-size: 20px;
    }
    
    .timer {
        font-size: 32px;
    }
    
    .btn-close {
        width: 36px;
        height: 36px;
        font-size: 20px;
        top: 10px;
        right: 10px;
    }
    
    .lamp {
        width: 35px;
        height: 35px;
    }
    
    .welcome-illustration {
        width: 260px;
        height: 320px;
    }
    
    .people-illustration {
        width: 220px;
        height: 320px;
    }
    
    .cat-illustration {
        width: 200px;
        height: 160px;
    }
    
    .difficulty-card {
        padding: 14px 18px;
    }
    
    .difficulty-icon {
        font-size: 28px;
    }
    
    .difficulty-name {
        font-size: 16px;
    }
    
    .btn-primary {
        height: 50px;
        font-size: 15px;
    }
}

/* === Very small screens (Telegram Mini App) === */
@media (max-width: 360px) {
    .screen {
        padding: 10px;
    }
    
    .welcome-title,
    .screen-title {
        font-size: 24px;
    }
    
    .welcome-description,
    .screen-description {
        font-size: 13px;
    }
    
    .game-container {
        min-height: 280px;
        border-radius: 24px;
    }
    
    .game-number {
        width: 58px;
        height: 54px;
    }
    
    .game-number span {
        font-size: 18px;
    }
    
    .timer {
        font-size: 28px;
    }
    
    .example-numbers {
        gap: 8px;
    }
    
    .example-number {
        width: 45px;
        height: 42px;
    }
    
    .example-number span {
        font-size: 22px;
    }
    
    .woman-illustration {
        width: 260px;
        height: 240px;
    }
}

/* === Short screens === */
@media (max-height: 650px) {
    .screen {
        padding: 10px 15px;
    }
    
    .welcome-illustration {
        height: 260px;
    }
    
    .people-illustration {
        height: 260px;
    }
    
    .cat-illustration {
        width: 180px;
        height: 140px;
        margin-top: 15px;
    }
    
    .game-container {
        min-height: 240px;
        margin: 5px 0 10px;
    }
    
    .game-header {
        padding: 10px;
    }
    
    .btn-primary {
        margin-bottom: 15px;
    }
    
    .woman-illustration {
        width: 240px;
        height: 200px;
        margin-top: 20px;
    }
    
    .difficulty-options {
        gap: 10px;
        margin-top: 20px;
    }
}

/* === Desktop Responsive === */
@media (min-width: 768px) {
    .screen {
        padding: 40px;
    }
    
    .game-container {
        max-width: 450px;
        min-height: 400px;
        padding: 20px;
    }
    
    .game-number {
        width: 90px;
        height: 85px;
    }
    
    .game-number span {
        font-size: 28px;
    }
    
    .btn-close {
        width: 44px;
        height: 44px;
        font-size: 28px;
    }
}

