:root {
    --tile-size: 40px;
    --tile-color: #bdc3c7;
    --target-color: #e74c3c;
    --block-color: #f39c12;
    --bg-color: #2c3e50;
    --panel-bg: rgba(52, 73, 94, 0.95);
    --accent-color: #f39c12;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: white;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    touch-action: none;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* UI Layer */
#ui-layer {
    position: absolute;
    top: 20px;
    width: 100%;
    z-index: 50;
    pointer-events: none;
}

#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
}

#level-info {
    font-size: 22px;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#user-info {
    font-size: 18px;
    color: #bdc3c7;
    display: flex;
    align-items: center;
    pointer-events: auto;
}

#logout-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 5px;
    border-radius: 6px;
    margin-left: 12px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
}

#logout-btn:hover { background: #c0392b; }

#message {
    text-align: center;
    font-size: 18px;
    height: 24px;
    color: #f1c40f;
    margin-top: 10px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* Modal Styles */
.modal {
    position: fixed;
    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: 1000;
}

.modal-content {
    background: #34495e;
    padding: 40px 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0,0,0,0.6);
    border: 1px solid rgba(255,255,255,0.1);
    width: 300px;
}

.modal-icon { margin-bottom: 15px; }
.modal-content h2 { margin: 0; color: var(--accent-color); letter-spacing: 2px; }
.modal-content p { color: #bdc3c7; margin-bottom: 25px; }

#nickname-input {
    width: 100%;
    padding: 14px;
    margin-bottom: 20px;
    border-radius: 10px;
    border: 2px solid #2c3e50;
    background: #1a252f;
    color: white;
    text-align: center;
    font-size: 18px;
    box-sizing: border-box;
}

#start-game-btn {
    width: 100%;
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    transition: transform 0.1s;
}
#start-game-btn:active { transform: scale(0.98); }

/* Leaderboard Styles */
#leaderboard {
    position: absolute;
    top: 100px;
    right: 20px;
    background: var(--panel-bg);
    border-radius: 15px;
    padding: 18px;
    width: 200px;
    z-index: 60;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: -5px 5px 20px rgba(0,0,0,0.3);
    transform: translateX(230px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#leaderboard.active { transform: translateX(0); }

.rank-header {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #f1c40f;
    margin-bottom: 15px;
    font-size: 14px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 10px;
}

#rank-list {
    list-style: none;
    padding: 0; margin: 0;
}

#rank-list li {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

#toggle-rank-btn {
    position: absolute;
    left: -50px;
    top: 0;
    width: 50px;
    height: 50px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 12px 0 0 12px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: -2px 0 10px rgba(0,0,0,0.2);
}

/* Game Stage */
#stage-container {
    perspective: 1200px;
    width: 100%;
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

#stage {
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(45deg);
}

.tile {
    position: absolute;
    width: var(--tile-size);
    height: var(--tile-size);
    background-color: var(--tile-color);
    border: 1px solid rgba(0,0,0,0.1);
    box-sizing: border-box;
    box-shadow: 0 5px 0 rgba(0,0,0,0.2);
}

.tile.target {
    background-color: var(--target-color);
    box-shadow: 0 0 20px var(--target-color);
}

/* Block Styles */
#block-container {
    position: absolute;
    transform-style: preserve-3d;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#block {
    position: absolute;
    transform-style: preserve-3d;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    width: var(--tile-size);
    height: var(--tile-size);
}

.block-face {
    position: absolute;
    background-color: var(--block-color);
    border: 1px solid rgba(255,255,255,0.4);
    box-sizing: border-box;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.5);
    backface-visibility: hidden;
    opacity: 0.9;
}

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    bottom: 80px;
    width: 100%;
    display: none;
    justify-content: space-between;
    padding: 0 25px;
    box-sizing: border-box;
    pointer-events: none;
    z-index: 100;
}

@media (max-width: 768px) {
    #mobile-controls { display: flex; }
    :root { --tile-size: 32px; }
    #leaderboard { top: 70px; }
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: auto;
}

.control-group.left { flex-direction: row; }

.control-btn {
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 18px;
    color: white;
    font-size: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    backdrop-filter: blur(8px);
}

.control-btn:active { background: rgba(255, 255, 255, 0.3); }

/* Ad Container */
#ad-container {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 120;
    background: rgba(0,0,0,0.1);
}

@media (max-width: 768px) {
    #ad-container { height: auto; min-height: 50px; }
    #ad-container ins { max-width: 100%; }
}
