:root {
    --bg-color: #0f172a;
    --board-bg: #1e293b;
    --cell-bg: #334155;
    --cell-gap: 4px;
    --board-gap: 4px;
    --cell-size: clamp(32px, 9vmin, 48px);
    --tray-cell-size: clamp(20px, 5vmin, 28px);
    --text-color: #f8fafc;
    --accent-color: #38bdf8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: var(--text-color);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    overflow: hidden;
    touch-action: none;
    transition: background-color 1s ease;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 500px;
    padding: 15px;
    position: relative;
}

/* Header - Block Blast Style */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 10px;
}

.best-score-box {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    padding: 10px 15px;
    border-radius: 12px;
    text-align: center;
    min-width: 70px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.best-score-box .label {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 700;
    letter-spacing: 1px;
    display: block;
}

.best-score-box .value {
    font-size: 1.2rem;
    font-weight: 800;
    color: white;
    display: block;
}

.current-score-box {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    padding: 15px 30px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
    flex: 1;
    max-width: 200px;
}

.current-score-box .value {
    font-size: 2.5rem;
    font-weight: 900;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.settings-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: all 0.2s;
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(45deg);
}

/* Combo Counter */
#combo-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 900;
    color: #fbbf24;
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.8), 0 4px 8px rgba(0,0,0,0.5);
    pointer-events: none;
    opacity: 0;
    z-index: 100;
}

#combo-display.show {
    animation: comboPopup 1.2s ease-out forwards;
}

@keyframes comboPopup {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
    40% { transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -70%) scale(0.8); }
}

/* Board */
#board-wrapper {
    padding: 10px;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    border-radius: 20px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5), 0 10px 30px rgba(0,0,0,0.6);
    transition: all 0.3s;
}

#board-wrapper.shake {
    animation: screenShake 0.4s ease;
}

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

#board {
    display: grid;
    grid-template-columns: repeat(8, var(--cell-size));
    grid-template-rows: repeat(8, var(--cell-size));
    gap: var(--board-gap);
}

.cell {
    background: var(--cell-bg);
    border-radius: 6px;
    position: relative;
    transition: background 0.1s;
}

.cell.ghost-valid {
    background: rgba(56, 189, 248, 0.4);
    box-shadow: inset 0 0 10px rgba(56, 189, 248, 0.6);
}

.cell.ghost-invalid {
    background: rgba(239, 68, 68, 0.4);
    box-shadow: inset 0 0 10px rgba(239, 68, 68, 0.6);
}

.cell.clearing {
    animation: clearFlash 0.3s ease-out;
}

@keyframes clearFlash {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.1); filter: brightness(2); background: white; }
    100% { transform: scale(0); filter: brightness(0); opacity: 0; }
}

/* Floating Score */
.floating-score {
    position: absolute;
    font-size: 1.5rem;
    font-weight: 900;
    color: #fbbf24;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    pointer-events: none;
    z-index: 50;
    animation: floatUp 1s ease-out forwards;
}

@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-80px) scale(1.5); }
}

/* Blocks */
.block {
    width: 100%;
    height: 100%;
    border-radius: 6px;
}

/* Tray */
#tray {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    min-height: 120px;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    border-radius: 20px;
    padding: 15px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.tray-piece {
    display: grid;
    gap: 3px;
    cursor: grab;
    transition: transform 0.2s, opacity 0.2s;
    touch-action: none;
}

.tray-piece:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.tray-piece.used {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
}

/* Floating Drag Element */
.floating-piece {
    position: fixed;
    display: grid;
    gap: var(--board-gap);
    pointer-events: none;
    z-index: 1000;
    opacity: 0.9;
    filter: drop-shadow(0 10px 15px rgba(0,0,0,0.5));
}

/* Effects Canvas */
#effects-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
}

/* Settings Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    min-width: 300px;
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 30px;
    color: var(--accent-color);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.setting-item span {
    font-size: 1.1rem;
    font-weight: 600;
}

.toggle-btn {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

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

.close-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    border: none;
    padding: 12px 32px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 12px;
    cursor: pointer;
    margin-top: 20px;
    transition: transform 0.1s;
    box-shadow: 0 4px 0 #1d4ed8;
}

.close-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* Game Over Overlay */
#game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease-out;
}

#game-over-overlay.hidden {
    display: none;
}

.game-over-content {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.game-over-content h2 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: #ef4444;
}

.game-over-content p {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: #94a3b8;
}

.game-over-content span {
    color: var(--accent-color);
    font-weight: bold;
}

#restart-btn {
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    color: white;
    border: none;
    padding: 12px 32px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 4px 0 #0284c7;
}

#restart-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

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