@font-face {
    font-family: 'Tetris';
    src: url('fonts/tetris.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

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

body {
    font-family: 'Tetris', 'Arial', sans-serif;
    background: url('images/back.png') no-repeat center center;
    background-size: cover;
    color: #fff;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.scene {
    display: none;
    width: 100%;
    max-width: 1200px;
    padding: 20px;
}

.scene.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Menu Scene */
.menu-container {
    text-align: center;
}

.menu-container h1 {
    font-size: 6rem;
    margin-bottom: 3rem;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    animation: floatingMotion 2s ease-in-out infinite, rainbowGlow 3s linear infinite;
    cursor: default;
}

.menu-container h1:hover {
    animation: floatingMotion 2s ease-in-out infinite, rainbowGlowHover 1.5s linear infinite;
}

@keyframes floatingMotion {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

@keyframes rainbowGlow {
    0% { text-shadow: 0 0 30px #ff0000, 0 0 50px #ff0000; }
    16.66% { text-shadow: 0 0 30px #ff7f00, 0 0 50px #ff7f00; }
    33.33% { text-shadow: 0 0 30px #ffff00, 0 0 50px #ffff00; }
    50% { text-shadow: 0 0 30px #00ff00, 0 0 50px #00ff00; }
    66.66% { text-shadow: 0 0 30px #0000ff, 0 0 50px #0000ff; }
    83.33% { text-shadow: 0 0 30px #8b00ff, 0 0 50px #8b00ff; }
    100% { text-shadow: 0 0 30px #ff0000, 0 0 50px #ff0000; }
}

@keyframes rainbowGlowHover {
    0% { text-shadow: 0 0 40px #ff0000, 0 0 60px #ff0000, 0 0 80px #ff0000; }
    16.66% { text-shadow: 0 0 40px #ff7f00, 0 0 60px #ff7f00, 0 0 80px #ff7f00; }
    33.33% { text-shadow: 0 0 40px #ffff00, 0 0 60px #ffff00, 0 0 80px #ffff00; }
    50% { text-shadow: 0 0 40px #00ff00, 0 0 60px #00ff00, 0 0 80px #00ff00; }
    66.66% { text-shadow: 0 0 40px #0000ff, 0 0 60px #0000ff, 0 0 80px #0000ff; }
    83.33% { text-shadow: 0 0 40px #8b00ff, 0 0 60px #8b00ff, 0 0 80px #8b00ff; }
    100% { text-shadow: 0 0 40px #ff0000, 0 0 60px #ff0000, 0 0 80px #ff0000; }
}

.menu-btn {
    display: block;
    width: 300px;
    padding: 15px 30px;
    margin: 15px auto;
    font-size: 1.2rem;
    font-weight: bold;
    font-family: 'Tetris', 'Arial', sans-serif;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid #fff;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

/* Game Scene */
#game-scene {
    background: url('images/TetrBack.jpg') no-repeat center center fixed;
    background-size: cover;
    position: relative;
}

#game-scene::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('images/TetrBack.jpg') no-repeat center center;
    background-size: cover;
    z-index: -1;
}

.game-container {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    justify-content: center;
}

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

.panel-title {
    font-size: 1.2rem;
    font-weight: bold;
    text-align: center;
    margin-bottom: 10px;
}

canvas {
    border: 2px solid #fff;
    background: black;
    display: block;
}

#game-canvas {
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    background: transparent;
}

#hold-canvas, #next-canvas {
    background: rgba(0, 0, 0, 0.5);
}

.stats {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.stat-item {
    margin: 10px 0;
    font-size: 1.1rem;
}

.stat-label {
    font-weight: bold;
    margin-right: 10px;
}

#tspin-indicator {
    color: #ff00ff;
    font-weight: bold;
    font-size: 1rem;
    min-height: 20px;
    display: block;
}

.controls-info {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    width: 100%;
}

.controls-info h3 {
    margin-bottom: 10px;
    text-align: center;
    font-size: 1rem;
}

.controls-info p {
    margin: 6px 0;
    font-size: 0.85rem;
}

/* Game Over Overlay */
.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;
    z-index: 10;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 40px;
    background: url('images/back.png') center center, rgba(30, 60, 114, 0.9);
    background-size: cover;
    background-blend-mode: overlay;
    border-radius: 15px;
    border: 2px solid #fff;
}

.overlay-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
}

.overlay-content p {
    font-size: 1.5rem;
    margin-bottom: 20px;
}

#player-name {
    width: 100%;
    padding: 10px;
    font-size: 1.2rem;
    font-family: 'Tetris', 'Arial', sans-serif;
    margin-bottom: 20px;
    border: 2px solid #fff;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-align: center;
}

#player-name::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.game-field-container {
    position: relative;
    background: #2a2a2a;
}

.game-field-container.shake {
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-1.5px, -1px); }
    20% { transform: translate(1.5px, 1px); }
    30% { transform: translate(-1.5px, 1px); }
    40% { transform: translate(1.5px, -1px); }
    50% { transform: translate(-1.5px, -1px); }
    60% { transform: translate(1.5px, 1px); }
    70% { transform: translate(-1.5px, 1px); }
    80% { transform: translate(1.5px, -1px); }
    90% { transform: translate(-1.5px, -1px); }
}

.game-field-container::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    pointer-events: none;
    z-index: 10;
    opacity: 0;
}

.game-field-container.flash-1::before {
    animation: flash1 2s ease-out;
}

.game-field-container.flash-2::before {
    animation: flash2 2.5s ease-out;
}

.game-field-container.flash-3::before {
    animation: flash3 3s ease-out;
}

.game-field-container.flash-4::before {
    animation: flash4 3.5s ease-out;
}

@keyframes flash1 {
    0% { 
        opacity: 0.5;
        box-shadow: 0 0 60px 20px rgba(100, 200, 255, 1), inset 0 0 60px 20px rgba(100, 200, 255, 0.8);
    }
    100% { 
        opacity: 0;
        box-shadow: 0 0 0 0 rgba(100, 200, 255, 0);
    }
}

@keyframes flash2 {
    0% { 
        opacity: 0.66;
        box-shadow: 0 0 80px 30px rgba(100, 255, 100, 1), inset 0 0 80px 30px rgba(100, 255, 100, 0.9);
    }
    100% { 
        opacity: 0;
        box-shadow: 0 0 0 0 rgba(100, 255, 100, 0);
    }
}

@keyframes flash3 {
    0% { 
        opacity: 0.66;
        box-shadow: 0 0 100px 40px rgba(255, 200, 100, 1), inset 0 0 100px 40px rgba(255, 200, 100, 0.95);
    }
    100% { 
        opacity: 0;
        box-shadow: 0 0 0 0 rgba(255, 200, 100, 0);
    }
}

@keyframes flash4 {
    0% { 
        opacity: 0.66;
        box-shadow: 0 0 100px 40px rgba(255, 100, 255, 1), 0 0 160px 60px rgba(255, 255, 100, 1), inset 0 0 120px 50px rgba(255, 100, 255, 1);
    }
    50% {
        box-shadow: 0 0 100px 40px rgba(100, 255, 255, 1), 0 0 180px 70px rgba(255, 100, 100, 1), inset 0 0 140px 60px rgba(100, 255, 255, 1);
    }
    100% { 
        opacity: 0;
        box-shadow: 0 0 0 0 rgba(255, 100, 255, 0);
    }
}

/* Leaderboard Scene */
.leaderboard-container {
    text-align: center;
    width: 100%;
    max-width: 600px;
}

.leaderboard-container h1 {
    font-size: 3rem;
    margin-bottom: 2rem;
    animation: rainbowGlow 3s linear infinite;
    cursor: default;
}

.leaderboard-container h1:hover {
    animation: rainbowGlowHover 1.5s linear infinite;
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    overflow: hidden;
}

#leaderboard-table th,
#leaderboard-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

#leaderboard-table th {
    background: rgba(0, 0, 0, 0.5);
    font-size: 1.2rem;
}

#leaderboard-table tr:hover {
    background: rgba(255, 255, 255, 0.1);
}

#leaderboard-table td:first-child,
#leaderboard-table th:first-child {
    text-align: center;
    width: 60px;
}

#leaderboard-table td:last-child,
#leaderboard-table th:last-child {
    text-align: right;
}

/* Error Notification */
.error-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 0, 0, 0.9);
    color: #fff;
    padding: 15px 30px;
    border-radius: 10px;
    border: 2px solid #fff;
    font-size: 1.1rem;
    font-weight: bold;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    animation: slideDown 0.3s ease-out;
}

.error-notification.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Credits Scene */
.credits-container {
    text-align: center;
    width: 100%;
    max-width: 800px;
}

.credits-container h1 {
    font-size: 3rem;
    margin-bottom: 2rem;
    animation: rainbowGlow 3s linear infinite;
    cursor: default;
}

.credits-container h1:hover {
    animation: rainbowGlowHover 1.5s linear infinite;
}

.credits-content {
    background: rgba(0, 0, 0, 0.3);
    padding: 30px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    margin-bottom: 2rem;
    line-height: 1.8;
}

.credits-content p {
    font-size: 1.1rem;
    margin: 8px 0;
}

.credits-content a {
    color: #00f0f0;
    text-decoration: none;
}

.credits-content a:hover {
    text-decoration: underline;
}

/* Volume Control */
.volume-control {
    position: fixed;
    bottom: 20px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(0, 0, 0, 0.5);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    z-index: 100;
}

.volume-control label {
    font-size: 0.9rem;
    font-weight: bold;
    font-family: 'Tetris', 'Arial', sans-serif;
    text-align: center;
}

.volume-slider {
    width: 150px;
    cursor: pointer;
}