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

body {
    font-family: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 25%, #2d1b4e 50%, #1a1f3a 75%, #0a0e27 100%);
    background-size: 400% 400%;
    animation: gradientShift 20s ease infinite;
    color: #e8eaf6;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    padding-bottom: 60px;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: 
        radial-gradient(circle at 20% 30%, rgba(138, 43, 226, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(75, 0, 130, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(30, 144, 255, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.app {
    width: min(720px, 100%);
    min-height: 600px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.topbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.stat {
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.2) 0%, rgba(75, 0, 130, 0.15) 100%);
    border-radius: 16px;
    padding: 10px 12px;
    text-align: center;
    border: 1px solid rgba(138, 43, 226, 0.3);
    backdrop-filter: blur(10px);
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 6px 16px rgba(138, 43, 226, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.label {
    font-size: 0.65rem;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    display: block;
    font-weight: 600;
}

.value {
    font-size: 1.2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #e8eaf6 0%, #c5cae9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 20px rgba(138, 43, 226, 0.5);
}

.play {
    position: relative;
    background: linear-gradient(135deg, rgba(10, 14, 39, 0.8) 0%, rgba(26, 31, 58, 0.6) 100%);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 12px;
    border: 2px solid rgba(138, 43, 226, 0.2);
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.play::before {
    content: '';
    position: absolute;
    inset: 0;
    background: 
        linear-gradient(45deg, transparent 30%, rgba(138, 43, 226, 0.1) 50%, transparent 70%);
    animation: scanLine 3s linear infinite;
    pointer-events: none;
}

@keyframes scanLine {
    0% { transform: translateX(-100%) translateY(-100%); }
    100% { transform: translateX(100%) translateY(100%); }
}

.grid-wrap {
    width: 100%;
    max-width: 384px;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.grid {
    width: 100%;
    height: 100%;
    display: grid;
    gap: 12px;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    perspective: 1000px;
}

.cell {
    background: linear-gradient(135deg, #4a148c 0%, #6a1b9a 50%, #8e24aa 100%);
    border-radius: 12px;
    border: 2px solid rgba(138, 43, 226, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(20px, 3.8vw, 32px);
    color: #fff;
    font-weight: 800;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow: 
        0 4px 12px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform-style: preserve-3d;
}

.cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cell:hover::before {
    opacity: 1;
}

.cell:hover {
    transform: translateY(-4px) scale(1.05) rotateX(5deg);
    box-shadow: 
        0 8px 24px rgba(138, 43, 226, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    border-color: rgba(138, 43, 226, 0.7);
}

.cell:active {
    transform: translateY(-2px) scale(1.02);
}

.cell span {
    position: relative;
    z-index: 1;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.cell.decoy {
    opacity: 0.95;
}

.hint {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 1.4rem;
    opacity: 0;
    transform: scale(0.5) rotate(0deg);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: #ffd700;
    pointer-events: none;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8));
    z-index: 10;
}

.hint.active {
    opacity: 1;
    transform: scale(1.2) rotate(360deg);
    animation: pulseGlow 0.5s ease;
}

@keyframes pulseGlow {
    0%, 100% { filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8)); }
    50% { filter: drop-shadow(0 0 20px rgba(255, 215, 0, 1)); }
}

.footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn {
    border: none;
    border-radius: 14px;
    padding: 12px 20px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-size: 0.95rem;
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.btn:hover::before {
    opacity: 1;
}

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

.start-btn {
    background: linear-gradient(135deg, #00e676 0%, #00c853 100%);
    color: #0a0e27;
    box-shadow: 0 4px 16px rgba(0, 230, 118, 0.4);
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 230, 118, 0.6);
}

.stop-btn {
    background: linear-gradient(135deg, #ff6f00 0%, #e65100 100%);
    color: #fff;
    box-shadow: 0 4px 16px rgba(255, 111, 0, 0.4);
}

.stop-btn.hidden {
    display: none;
}

.stop-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 111, 0, 0.6);
}

.info-btn {
    background: linear-gradient(135deg, #7c4dff 0%, #651fff 100%);
    color: #fff;
    box-shadow: 0 4px 16px rgba(124, 77, 255, 0.4);
}

.info-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(124, 77, 255, 0.6);
}

.reward-btn {
    flex: 1 1 100%;
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.3) 0%, rgba(75, 0, 130, 0.2) 100%);
    color: #e8eaf6;
    white-space: normal;
    border: 1px solid rgba(138, 43, 226, 0.4);
    backdrop-filter: blur(10px);
}

.reward-btn:hover {
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.4) 0%, rgba(75, 0, 130, 0.3) 100%);
    border-color: rgba(138, 43, 226, 0.6);
}

.status-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 0.85rem;
    opacity: 0.9;
}

.reward-timer {
    font-weight: 700;
    color: #00e676;
    text-shadow: 0 0 10px rgba(0, 230, 118, 0.5);
}

.reward-timer.hidden {
    display: none;
}

.best {
    white-space: nowrap;
    opacity: 0.8;
}

.end-screen {
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 39, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.end-screen.hidden {
    display: none;
}

.end-card {
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.2) 0%, rgba(75, 0, 130, 0.15) 100%);
    padding: 32px;
    border-radius: 24px;
    text-align: center;
    width: min(400px, 90%);
    border: 2px solid rgba(138, 43, 226, 0.3);
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.end-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #e8eaf6 0%, #c5cae9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.end-score, .end-streak {
    margin-bottom: 12px;
    font-size: 1.1rem;
    opacity: 0.9;
}

.info-modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 39, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.info-modal.hidden {
    display: none;
}

.info-card {
    background: linear-gradient(135deg, rgba(138, 43, 226, 0.2) 0%, rgba(75, 0, 130, 0.15) 100%);
    padding: 28px;
    border-radius: 24px;
    width: min(600px, 92%);
    max-height: 80vh;
    overflow: auto;
    border: 2px solid rgba(138, 43, 226, 0.3);
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.info-title {
    font-size: 1.4rem;
    font-weight: 800;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #e8eaf6 0%, #c5cae9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.info-text p {
    margin-bottom: 12px;
    line-height: 1.6;
    color: #e8eaf6;
    opacity: 0.9;
}

.info-text strong {
    color: #c5cae9;
    font-weight: 700;
}

.neutral-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    color: #e8eaf6;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(10px);
    min-width: 44px;
    min-height: 44px;
}

.neutral-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

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

.neutral-btn svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

@media (max-width: 640px) {
    body {
        align-items: stretch;
        justify-content: flex-start;
    }

    .app {
        min-height: 100vh;
    }

    .play {
        padding: 10px;
        max-height: 40svh;
    }

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

    .grid {
        gap: 8px;
    }

    .grid-wrap {
        max-width: 224px;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .btn {
        width: 100%;
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .reward-btn {
        order: 4;
        padding: 12px 16px;
        font-size: 0.9rem;
        line-height: 1.3;
    }

    .neutral-btn {
        width: 100%;
        justify-content: center;
    }
}
