/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: #1a1a1a;
    color: white;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top Score Bar */
.score-bar {
    height: 80px;
    background-color: #2a2a2a;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 20px;
    border-bottom: 2px solid #444;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.score-item {
    text-align: center;
    animation: fadeIn 0.5s ease-in;
}

.score-item h3 {
    font-size: 18px;
    color: #888;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-item p {
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    height: calc(100vh - 80px);
}



/* Game Area */
.game-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #2a2a2a 0%, #1a1a1a 100%);
    padding: 20px;
    position: relative;
}

.game-board {
    background-color: #000;
    border: 3px solid #444;
    position: relative;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    border-radius: 5px;
    display: inline-block;
}

/* Next Pieces Preview */
.next-pieces-container {
    position: absolute;
    left: 100%;
    top: 0;
    margin-left: 20px;
    background-color: rgba(42, 42, 42, 0.9);
    border: 2px solid #444;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    transition: opacity 0.3s ease;
}

.next-pieces-container.hidden {
    display: none;
}

.next-pieces-container h3 {
    color: #4CAF50;
    text-align: center;
    margin: 0 0 10px 0;
    font-size: 18px;
    letter-spacing: 2px;
}

#nextPiecesCanvas {
    display: block;
    background-color: rgba(17, 17, 17, 0.5);
    border-radius: 5px;
}

/* Menu Overlay */
.menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    backdrop-filter: blur(5px);
    border-radius: 5px;
}

.menu-overlay.hidden {
    display: none;
}

.menu {
    background-color: rgba(42, 42, 42, 0.95);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
    border: 2px solid #4CAF50;
    min-width: 360px;
    animation: slideIn 0.3s ease-out;
}

.menu h2 {
    font-size: 32px;
    margin-bottom: 40px;
    text-align: center;
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 50%, #66BB6A 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    letter-spacing: 2px;
    font-weight: 900;
    position: relative;
    padding-bottom: 20px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.menu h2::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 3px;
    background: linear-gradient(90deg, transparent 0%, #4CAF50 20%, #45a049 50%, #4CAF50 80%, transparent 100%);
    border-radius: 2px;
}

.menu h2::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, rgba(76, 175, 80, 0.2) 0%, transparent 70%);
    z-index: -1;
    animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
    0%, 100% {
        opacity: 0.5;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.05);
    }
}

.menu-item {
    background-color: rgba(58, 58, 58, 0.9);
    padding: 20px;
    margin-bottom: 15px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
    font-size: 20px;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.menu-item:last-child {
    margin-bottom: 0;
}

.menu-item:hover {
    background-color: rgba(74, 74, 74, 0.9);
    transform: scale(1.05);
    border-color: #4CAF50;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.menu-item.active {
    background-color: #4CAF50;
    color: #000;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.5);
    animation: glow 1s ease-in-out infinite alternate;
}

.menu-item:active {
    transform: scale(0.98);
}

/* Toggle Switch Styles */
.menu-item.toggle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toggle-indicator {
    background-color: #4CAF50;
    color: #000;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    min-width: 40px;
    text-align: center;
    transition: all 0.3s;
}

.toggle-indicator.off {
    background-color: #666;
    color: #fff;
}

@keyframes glow {
    from {
        box-shadow: 0 4px 15px rgba(76, 175, 80, 0.5);
    }
    to {
        box-shadow: 0 6px 20px rgba(76, 175, 80, 0.8);
    }
}

@keyframes bonusPulse {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

@keyframes specialBonusPulse {
    0% {
        transform: translate(-50%, -50%) scale(0.3) rotate(-15deg);
        opacity: 0;
    }
    20% {
        transform: translate(-50%, -50%) scale(1.5) rotate(5deg);
        opacity: 1;
    }
    40% {
        transform: translate(-50%, -50%) scale(1.2) rotate(-5deg);
    }
    60% {
        transform: translate(-50%, -50%) scale(1.3) rotate(3deg);
    }
    80% {
        transform: translate(-50%, -50%) scale(1.1) rotate(-2deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
        opacity: 0;
    }
}

@keyframes starBurst {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
        box-shadow: 0 0 10px #fff;
    }
    100% {
        transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0);
        opacity: 0;
    }
}

.star-burst {
    border-radius: 50%;
}

/* Particle effect container */
.particle-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background-color: #4CAF50;
    animation: particleFly 1s ease-out forwards;
}

@keyframes particleFly {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(var(--dx), var(--dy)) scale(0);
        opacity: 0;
    }
}

@keyframes scoreFloat {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    100% {
        transform: translateY(-50px);
        opacity: 0;
    }
}

/* Line clear effects */
.line-clearing {
    animation: lineFlash 0.5s ease-in-out;
}

@keyframes lineFlash {
    0%, 100% {
        background-color: rgba(255, 255, 255, 0.1);
    }
    50% {
        background-color: rgba(255, 255, 255, 0.8);
    }
}

/* Game Canvas */
#gameCanvas {
    display: block;
    border-radius: 3px;
}

/* Controls Info */
.controls-info {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background-color: rgba(42, 42, 42, 0.9);
    padding: 20px;
    border-radius: 10px;
    font-size: 14px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.controls-info h4 {
    margin-bottom: 10px;
    color: #4CAF50;
    font-size: 18px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.controls-info p {
    margin-bottom: 5px;
    color: #ddd;
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    align-items: center;
}

.control-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 24px;
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    margin-right: 10px;
    padding: 0 8px;
}

.control-icon.arrow {
    font-size: 16px;
}

.control-icon.color-button {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #fff;
    padding: 0;
}

.control-icon.red { background-color: #ff4444; }
.control-icon.green { background-color: #44ff44; }
.control-icon.yellow { background-color: #ffff44; }
.control-icon.blue { background-color: #4444ff; }

.control-action {
    flex: 1;
    text-align: left;
}

/* Game Over Overlay */
.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.95);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    display: none;
    box-shadow: 0 0 50px rgba(255, 68, 68, 0.5);
    border: 2px solid #ff4444;
    animation: slideDown 0.5s ease-out;
}

.game-over h2 {
    font-size: 48px;
    margin-bottom: 20px;
    color: #ff4444;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
    animation: pulse 1s infinite;
}

.game-over p {
    font-size: 24px;
    margin-bottom: 30px;
    color: #fff;
}

.game-over button {
    padding: 15px 30px;
    font-size: 20px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
}

.game-over button:hover {
    background-color: #45a049;
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.5);
}

.game-over button:active {
    transform: scale(0.98);
}

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

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

@keyframes slideDown {
    from {
        transform: translate(-50%, -60%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, -50%);
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* WebOS TV Specific Styles */
@media screen and (max-width: 1280px) {
    .menu {
        width: 250px;
    }
    
    .menu h2 {
        font-size: 28px;
    }
    
    .menu-item {
        font-size: 18px;
        padding: 15px;
    }
    
    .next-pieces-container {
        transform: scale(0.9);
        margin-left: 10px;
    }
    
    .controls-info {
        bottom: 10px;
        right: 10px;
        padding: 15px;
        font-size: 12px;
    }
    
    .control-icon {
        min-width: 24px;
        height: 20px;
        font-size: 10px;
    }
}

/* TV-specific control styling */
.webos-tv .controls-info {
    background-color: rgba(42, 42, 42, 0.95);
    border: 2px solid #444;
}

.webos-tv .control-icon {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Ensure proper layout for game + next pieces */
.game-wrapper {
    display: inline-flex;
    align-items: flex-start;
    position: relative;
}