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

/* Prevent iOS Safari zoom and selection issues */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body.touch-device {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

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

.game-header {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px 15px 0 0;
    padding: 20px 30px;
    box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.1);
}

.game-header h1 {
    text-align: center;
    font-size: 3em;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 15px;
    font-weight: bold;
    letter-spacing: 5px;
}

.header-stats {
    display: flex;
    justify-content: space-around;
    gap: 20px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.stat-label {
    font-size: 0.9em;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 2em;
    font-weight: bold;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-content {
    display: flex;
    gap: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 0 0 15px 15px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.side-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-section {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.panel-section h3 {
    font-size: 1.1em;
    color: #333;
    margin-bottom: 10px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#nextCanvas {
    display: block;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
}

.lives-container {
    display: flex;
    justify-content: center;
    gap: 10px;
    font-size: 2em;
}

.life {
    animation: heartbeat 1.5s ease-in-out infinite;
}

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

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

.bonus-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.6);
    padding: 10px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.bonus-item:hover {
    transform: translateX(5px);
    background: rgba(255, 255, 255, 0.9);
}

.bonus-icon {
    font-size: 1.5em;
}

.bonus-count {
    font-weight: bold;
    font-size: 1.2em;
    color: #667eea;
}

.difficulty-display,
.high-score {
    text-align: center;
    font-size: 1.5em;
    font-weight: bold;
    color: #667eea;
    padding: 10px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
}

.controls-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-item {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 5px;
    font-size: 0.9em;
}

.control-item span:first-child {
    font-weight: bold;
    color: #667eea;
}

.bonus-control {
    border-left: 3px solid #4ade80;
}

.game-area {
    position: relative;
    flex-shrink: 0;
}

#gameCanvas {
    display: block;
    background: #1a1a2e;
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(102, 126, 234, 0.5), inset 0 0 50px rgba(0, 0, 0, 0.3);
    /* Prevent touch actions on canvas for Safari */
    touch-action: none;
    -webkit-touch-callout: none;
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    transition: opacity 0.3s ease;
}

.game-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    color: white;
    padding: 30px;
}

.overlay-content h2 {
    font-size: 2.5em;
    margin-bottom: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.overlay-content p {
    font-size: 1.2em;
    margin-bottom: 25px;
    color: #ccc;
}

.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

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

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.btn-easy {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    color: white;
}

.btn-medium {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
}

.btn-hard {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.panel-section {
    animation: fadeIn 0.5s ease-out;
}

/* Responsive */
@media (max-width: 1024px) {
    .game-content {
        flex-direction: column;
    }

    .side-panel {
        flex-direction: row;
    }

    .left-panel,
    .right-panel {
        order: 2;
    }

    .game-area {
        order: 1;
        margin: 0 auto;
    }
}

@media (max-width: 768px) {
    .game-header h1 {
        font-size: 2em;
    }

    .stat-value {
        font-size: 1.5em;
    }

    .side-panel {
        flex-direction: column;
    }

    #gameCanvas {
        width: 100%;
        height: auto;
    }
}

/* Particle effect for line clears */
@keyframes particle-explosion {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0);
    }
}

.particle {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    pointer-events: none;
    animation: particle-explosion 1s ease-out forwards;
}

/* Touch Controls */
.touch-controls {
    display: none;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
    padding: 15px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.3) 0%, rgba(118, 75, 162, 0.3) 100%);
    border-radius: 15px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.touch-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.touch-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 70px;
    height: 60px;
    border: none;
    border-radius: 12px;
    font-size: 1.5em;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
    /* Safari iOS button fix */
    -webkit-appearance: none;
    appearance: none;
}

.touch-btn:active,
.touch-btn:focus {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    outline: none;
}

.touch-icon {
    pointer-events: none;
}

/* Direction buttons */
.touch-left,
.touch-right,
.touch-down {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.touch-left:active,
.touch-right:active,
.touch-down:active {
    background: linear-gradient(135deg, #5a6fd4 0%, #6a4290 100%);
}

/* Rotate button */
.touch-rotate {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    color: white;
}

.touch-rotate:active {
    background: linear-gradient(135deg, #3ecc72 0%, #1db050 100%);
}

/* Hard drop button */
.touch-drop {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    font-size: 1.2em;
}

.touch-drop:active {
    background: linear-gradient(135deg, #dc8c0a 0%, #c46806 100%);
}

/* Pause button */
.touch-pause {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    color: white;
}

.touch-pause:active {
    background: linear-gradient(135deg, #5f6673 0%, #414953 100%);
}

/* Bonus buttons */
.touch-bonus {
    width: 90px;
    height: 50px;
    font-size: 1.3em;
}

.touch-bonus-life {
    background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
}

.touch-bonus-life:active {
    background: linear-gradient(135deg, #2ec98d 0%, #0ea573 100%);
}

.touch-bonus-block {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

.touch-bonus-block:active {
    background: linear-gradient(135deg, #e5ae20 0%, #dc8c0a 100%);
}

.touch-bonus-line {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.touch-bonus-line:active {
    background: linear-gradient(135deg, #dc3d3d 0%, #c82222 100%);
}

/* Touch controls visibility is managed by JavaScript for Safari compatibility */
/* These media queries serve as fallback */
@media (hover: none) and (pointer: coarse) {
    .touch-controls {
        display: flex;
    }
}

/* Hide keyboard controls info on touch devices */
body.touch-device .controls-info {
    display: none;
}

/* Make touch buttons larger on smaller screens */
@media (max-width: 480px) {
    .touch-btn {
        width: 60px;
        height: 55px;
        font-size: 1.3em;
    }

    .touch-bonus {
        width: 80px;
        height: 45px;
        font-size: 1.2em;
    }

    .touch-controls {
        padding: 10px;
        gap: 8px;
    }

    .touch-row {
        gap: 8px;
    }
}
