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

body {
    background: #1a0e0a;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 800px;
    height: 650px;
}

/* Title Screen */
#title-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    background: radial-gradient(ellipse at center, #3d2614 0%, #1a0e0a 70%);
    border-radius: 12px;
    border: 3px solid #5a3a1e;
    position: relative;
    overflow: hidden;
}

#title-screen::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background:
        radial-gradient(circle at 20% 30%, rgba(76, 50, 20, 0.4) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(76, 50, 20, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(60, 40, 15, 0.2) 0%, transparent 60%);
    pointer-events: none;
}

#title-screen h1 {
    font-size: 72px;
    color: #e8a0d0;
    text-shadow:
        0 0 20px rgba(232, 160, 208, 0.5),
        0 0 40px rgba(232, 160, 208, 0.3),
        3px 3px 0 #5a2040;
    letter-spacing: 8px;
    line-height: 1.1;
    margin-bottom: 10px;
    z-index: 1;
}

.subtitle {
    color: #c89070;
    font-size: 18px;
    letter-spacing: 6px;
    margin-bottom: 40px;
    z-index: 1;
}

#start-btn, #game-over-screen button {
    background: linear-gradient(180deg, #e8a0d0, #c06898);
    color: #1a0e0a;
    border: none;
    padding: 15px 50px;
    font-size: 22px;
    font-weight: bold;
    border-radius: 30px;
    cursor: pointer;
    letter-spacing: 3px;
    transition: all 0.3s;
    z-index: 1;
    text-transform: uppercase;
}

#start-btn:hover, #game-over-screen button:hover {
    transform: scale(1.08);
    box-shadow: 0 0 30px rgba(232, 160, 208, 0.5);
}

.controls-info {
    margin-top: 30px;
    z-index: 1;
}

.controls-info p {
    color: #8a6a50;
    font-size: 14px;
    margin: 5px 0;
}

/* Game Screen */
#game-screen {
    height: 100%;
    display: flex;
    flex-direction: column;
}

#hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: #2a1a10;
    border-radius: 12px 12px 0 0;
    border: 2px solid #5a3a1e;
    border-bottom: none;
    height: 50px;
}

#hud-left {
    display: flex;
    gap: 20px;
}

#level-display, #score-display {
    color: #e8a0d0;
    font-size: 16px;
    font-weight: bold;
    letter-spacing: 2px;
}

#hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

#timer-bar-container {
    width: 200px;
    height: 16px;
    background: #1a0e0a;
    border-radius: 8px;
    border: 1px solid #5a3a1e;
    overflow: hidden;
}

#timer-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #80c040, #c0e060);
    border-radius: 8px;
    transition: width 0.3s ease;
}

#timer-label {
    color: #80c040;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 2px;
}

#game-canvas {
    border: 2px solid #5a3a1e;
    border-top: none;
    border-radius: 0 0 12px 12px;
    display: block;
    background: #2d1f0e;
    touch-action: none;
}

/* D-pad */
#dpad {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 0 4px;
}

@media (pointer: coarse) {
    #dpad { display: flex; }
}

.dpad-row {
    display: flex;
    gap: 4px;
    align-items: center;
}

.dpad-btn {
    width: 58px;
    height: 58px;
    background: rgba(232, 160, 208, 0.12);
    border: 2px solid rgba(232, 160, 208, 0.25);
    border-radius: 10px;
    color: #e8a0d0;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s, border-color 0.1s;
}

.dpad-btn:active {
    background: rgba(232, 160, 208, 0.3);
    border-color: rgba(232, 160, 208, 0.6);
}

.dpad-center {
    width: 58px;
    height: 58px;
    background: transparent;
    border: none;
    pointer-events: none;
}

/* Responsive scaling for small screens */
@media (max-width: 820px) {
    body {
        justify-content: flex-start;
        overflow-y: auto;
        padding: 8px 0;
    }
}

/* Level Transition */
#level-transition {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(26, 14, 10, 0.95);
    border-radius: 12px;
    z-index: 10;
    animation: fadeIn 0.5s;
}

#level-transition h2 {
    font-size: 60px;
    color: #e8a0d0;
    text-shadow: 0 0 30px rgba(232, 160, 208, 0.6);
    letter-spacing: 6px;
    animation: pulse 1s infinite;
}

#level-transition p {
    color: #c89070;
    font-size: 18px;
    margin-top: 15px;
    letter-spacing: 3px;
}

/* Game Over */
#game-over-screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(26, 14, 10, 0.95);
    border-radius: 12px;
    z-index: 10;
}

#game-over-screen h2 {
    font-size: 52px;
    color: #e85050;
    text-shadow: 0 0 20px rgba(232, 80, 80, 0.5);
    letter-spacing: 4px;
    margin-bottom: 20px;
}

#game-over-screen p {
    color: #c89070;
    font-size: 20px;
    margin: 5px 0;
}

#game-over-screen button {
    margin-top: 30px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ===== LEADERBOARD ===== */
#title-leaderboard-section {
    margin-top: 16px;
    width: 100%;
    max-width: 420px;
    z-index: 1;
}

.lb-heading {
    color: #e8a0d0;
    font-size: 12px;
    letter-spacing: 4px;
    margin-bottom: 6px;
    font-weight: bold;
    text-align: center;
}

.leaderboard-panel {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 8px;
    border: 1px solid #5a3a1e;
    overflow-y: auto;
    max-height: 140px;
}

#gameover-leaderboard {
    max-height: 160px;
    max-width: 420px;
    width: 100%;
    margin-bottom: 10px;
}

.lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.lb-table th {
    color: #7a5a40;
    padding: 5px 8px;
    text-align: left;
    border-bottom: 1px solid #3a2810;
    font-size: 11px;
    letter-spacing: 1px;
    position: sticky;
    top: 0;
    background: #1e1008;
}

.lb-table td {
    color: #c89070;
    padding: 4px 8px;
}

.lb-table tbody tr:hover td {
    background: rgba(255, 255, 255, 0.04);
}

.lb-gold td  { color: #ffd700; }
.lb-silver td { color: #c0c0c0; }
.lb-bronze td { color: #cd7f32; }

.lb-empty {
    color: #5a4030;
    font-size: 13px !important;
    padding: 12px;
    text-align: center;
}

.leaderboard-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
    justify-content: center;
}

.lb-btn {
    background: #2e1c10;
    color: #c89070;
    border: 1px solid #5a3a1e;
    padding: 6px 14px;
    font-size: 11px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    letter-spacing: 2px;
    transition: all 0.2s;
    text-transform: uppercase;
}

.lb-btn:hover {
    background: #4a3520;
    color: #e8a0d0;
    border-color: #e8a0d0;
}

.lb-icon-btn {
    padding: 6px 12px;
    font-size: 15px;
    letter-spacing: 0;
}

#secret-o {
    cursor: inherit;
    user-select: none;
}

/* Save score form */
#save-score-form {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 12px 0 8px;
}

#player-name {
    background: #2a1a10;
    border: 1px solid #5a3a1e;
    color: #e8a0d0;
    padding: 8px 14px;
    font-size: 15px;
    border-radius: 8px;
    outline: none;
    letter-spacing: 2px;
    width: 160px;
    font-family: inherit;
}

#player-name:focus {
    border-color: #e8a0d0;
    box-shadow: 0 0 10px rgba(232, 160, 208, 0.2);
}

#save-score-form button {
    background: linear-gradient(180deg, #a0e060, #70c030);
    color: #1a0e0a;
    border: none;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    letter-spacing: 2px;
    transition: transform 0.2s;
}

#save-score-form button:hover {
    transform: scale(1.06);
}
