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

body {
    background: #1a1a2e;
    color: #eee;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

.container {
    text-align: center;
    max-width: 700px;
    padding: 0.5rem;
    width: 100%;
    margin: 0 auto;
}

h1 {
    font-size: 2.5rem;
    color: #00d2a0;
    text-transform: uppercase;
    letter-spacing: 4px;
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.score-board {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    padding: 0 0.25rem;
    color: #ccc;
    flex-wrap: wrap;
    min-height: 1.8rem;
}

.score-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#timerDisplay {
    color: #e94560;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

#powerUpDisplay {
    color: #ffd54f;
    font-weight: 600;
    min-width: 50px;
}

.options-row {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: #aaa;
}

.option-group select {
    background: #16213e;
    color: #eee;
    border: 1px solid #0f3460;
    padding: 0.2rem 0.35rem;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
}

#canvasWrap {
    position: relative;
    display: inline-block;
}

.shake {
    animation: shake 0.15s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

#gameCanvas {
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 4px;
    display: block;
    margin: 0 auto;
    max-width: 100%;
    transition: background 0.3s, border-color 0.3s;
}

.score-popup {
    position: absolute;
    pointer-events: none;
    font-weight: 700;
    font-size: 1.1rem;
    z-index: 10;
    transition: none;
}

#pauseOverlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

#pauseOverlay.hidden { display: none; }

.pause-menu {
    background: #1a1a2e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    padding: 1.5rem 2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pause-menu h2 {
    color: #00d2a0;
    font-size: 1.5rem;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.pause-menu button {
    background: #00d2a0;
    color: #1a1a2e;
    border: none;
    padding: 0.5rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.pause-menu button:hover { background: #00b88a; }
.pause-menu button:last-child {
    background: #0f3460;
    color: #ccc;
}
.pause-menu button:last-child:hover { background: #1a4a80; }

.controls-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.65rem;
    row-gap: 0.4rem;
    margin-top: 0.7rem;
    flex-wrap: wrap;
}

.theme-selector,
.snake-style-selector,
.obstacle-selector {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.82rem;
    color: #aaa;
}

.theme-selector select,
.snake-style-selector select,
.obstacle-selector select {
    background: #16213e;
    color: #eee;
    border: 1px solid #0f3460;
    padding: 0.22rem 0.35rem;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
}

#restartBtn {
    background: #00d2a0;
    color: #1a1a2e;
    border: none;
    padding: 0.35rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

#restartBtn:hover { background: #00b88a; }

#muteBtn {
    background: #16213e;
    color: #eee;
    border: 1px solid #0f3460;
    padding: 0.35rem 0.6rem;
    font-size: 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
    line-height: 1;
}

#muteBtn:hover { background: #0f3460; }

.mobile-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.7rem;
}

@media (pointer: coarse) { .mobile-controls { display: flex; } }

.dir-btn {
    width: 52px;
    height: 52px;
    font-size: 1.2rem;
    background: #16213e;
    color: #00d2a0;
    border: 2px solid #0f3460;
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.dir-btn:active { background: #0f3460; transform: scale(0.93); }

.dir-row { display: flex; gap: 52px; }

.high-scores { margin-top: 0.7rem; text-align: center; }

.high-scores h3 {
    font-size: 0.9rem;
    color: #f0c040;
    margin-bottom: 0.25rem;
}

#scoreList {
    list-style: none;
    display: inline-block;
    text-align: left;
}

#scoreList li {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    font-size: 0.83rem;
    padding: 0.12rem 0;
    color: #aaa;
}

#scoreList li span:first-child { color: #888; }

.achievements-section { margin-top: 0.7rem; text-align: center; }

.achievements-section h3 {
    font-size: 0.9rem;
    color: #f0c040;
    margin-bottom: 0.25rem;
}

.achievement-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem;
}

.achievement-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.72rem;
    padding: 0.18rem 0.45rem;
    border-radius: 12px;
    border: 1px solid #333;
    color: #666;
    opacity: 0.5;
    transition: all 0.3s;
}

.achievement-badge.unlocked {
    border-color: #f0c040;
    color: #f0c040;
    opacity: 1;
    background: rgba(240, 192, 64, 0.1);
}

.notification {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(240, 192, 64, 0.95);
    color: #1a1a2e;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 100;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}

.notification.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
}

#customModal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

#customModal.hidden { display: none; }

#enemyModal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

#enemyModal.hidden { display: none; }

#enemyModal .custom-modal-content {
    background: #1a1a2e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    padding: 1.2rem 1.5rem;
    min-width: 260px;
    max-width: 90vw;
}

/* Header untuk dua modal */
#customModal .custom-modal-header,
#enemyModal .custom-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

/* Close button khusus, jangan ikut style tombol action */
#customModal .custom-modal-header button,
#enemyModal .custom-modal-header button {
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 0;
    cursor: pointer;
    line-height: 1;
    min-height: 0;
}

#customModal .custom-modal-header button:hover,
#enemyModal .custom-modal-header button:hover {
    color: #eee;
}

/* Custom Snake modal layout fix */
#customModal .custom-modal-content {
    min-width: 300px;
    max-width: min(90vw, 320px);
    padding: 1.35rem 1.5rem;
    background: #1a1a2e;
    border: 2px solid #0f3460;
    border-radius: 12px;
}

/* Force modal body to align normally, not centered */
#customModal .custom-modal-body {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.72rem;
    text-align: left;
}

/* Head / Body / Eye / Glow rows */
#customModal .color-row {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 42px;
    align-items: center;
    gap: 0.85rem;
    margin: 0;
    text-align: left;
}

#customModal .color-row label,
#customModal .color-row span {
    justify-self: start;
    text-align: left;
}

#customModal .color-row input[type="color"] {
    justify-self: end;
    width: 40px;
    height: 30px;
    padding: 0;
    border: 1px solid #0f3460;
    border-radius: 5px;
    cursor: pointer;
    background: #10213d;
}

/* Restore dark button style */
/* Base actions untuk dua modal */
#customModal .custom-modal-actions,
#enemyModal .custom-modal-actions {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.75rem;
}

/* Custom Snake = 2 tombol */
#customModal .custom-modal-actions {
    grid-template-columns: repeat(2, 1fr);
}

/* Enemy Settings = 3 tombol */
#enemyModal .custom-modal-actions {
    grid-template-columns: repeat(3, 1fr);
}

/* Action buttons, bukan tombol X */
#customModal .custom-modal-actions button,
#enemyModal .custom-modal-actions button {
    background: #10213d;
    color: #f1f5f9;
    border: 1px solid #0f3460;
    border-radius: 5px;
    min-height: 36px;
    padding: 0.4rem 0.55rem;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
}

#customModal .custom-modal-actions button:hover,
#enemyModal .custom-modal-actions button:hover {
    background: #13284a;
    border-color: #1e5fa8;
}

/* Preset dots */
#customModal .preset-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.2rem;
}

#customModal .preset-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #0f3460;
}

.preset-btn {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #0f3460;
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s;
}

.preset-btn:hover { transform: scale(1.2); }

.slider-row {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.slider-row label {
    font-size: 0.82rem;
    color: #aaa;
    display: flex;
    justify-content: space-between;
}

.slider-row label span {
    color: #00d2a0;
    font-weight: 600;
}

.slider-row input[type="range"] {
    width: 100%;
    height: 4px;
    appearance: none;
    background: #0f3460;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #00d2a0;
    border: none;
    cursor: pointer;
}

.modal-divider {
    height: 1px;
    background: #0f3460;
    margin: 0.3rem 0;
}

.enemy-colors-grid {
    display: grid;
    grid-template-columns: repeat(5, 64px);
    gap: 0.5rem;
    justify-content: center;
    justify-items: center;
    align-items: start;
    margin: 0.65rem auto 0;
}

.enemy-color-slot {
    width: 66px;
    min-width: 66px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.32rem;
    padding: 0.42rem 0.18rem;
    border-radius: 7px;
    background: rgba(15, 52, 96, 0.20);
    border: 1px solid rgba(0, 212, 170, 0.10);
}

.slot-label {
    font-size: 0.58rem;
    line-height: 1;
    opacity: 0.78;
    margin-bottom: 0.05rem;
}

.enemy-color-slot label,
.enemy-color-slot .enemy-number {
    font-size: 0.58rem;
    line-height: 1;
    opacity: 0.78;
    margin-bottom: 0.05rem;
}

.enemy-color-slot input[type="color"] {
    width: 24px;
    height: 24px;
    padding: 0;
    border: 2px solid #181f38;
    border-radius: 5px;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
    appearance: none;
    -webkit-appearance: none;
}

.enemy-color-slot input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border: none;
    border-radius: 4px;
}

.enemy-color-slot input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.enemy-color-slot input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

.enemyColorPicker { cursor: pointer; }
.enemyArchetype { cursor: pointer; }

.enemy-color-slot select {
    width: 58px;
    max-width: 58px;
    height: 20px;
    box-sizing: border-box;
    border-radius: 4px;
    border: 1px solid #0f3460;
    background: #16213e;
    color: #d9d9d9;
    font-size: 0.5rem;
    font-weight: 600;
    padding: 0 0.1rem;
    cursor: pointer;
    outline: none;
    text-align: center;
}

.enemy-color-slot select:hover,
.enemy-color-slot select:focus {
    border-color: #00d4aa;
    background: #10213d;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 0.65rem;
    margin-top: 0.7rem;
    font-size: 0.77rem;
    color: #aaa;
    flex-wrap: wrap;
}

.legend-item { display: flex; align-items: center; gap: 3px; }

.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

.dot.normal { background: #e94560; }
.dot.golden { background: #f0c040; }
.dot.speed  { background: #4fc3f7; }
.dot.slow   { background: #81c784; }
.dot.powerup { background: #ffd54f; }
.dot.portal { background: #ce93d8; }

.instructions {
    margin-top: 0.65rem;
    font-size: 0.8rem;
    color: #888;
}

@media (max-width: 480px) {
    #enemyModal .custom-modal-content {
        min-width: 0;
        width: min(95vw, 360px);
        padding: 1rem 0.75rem;
    }

    .enemy-colors-grid {
        grid-template-columns: repeat(3, 64px);
        gap: 0.4rem;
    }

    .enemy-color-slot {
        width: 62px;
        min-width: 62px;
        padding: 0.35rem 0.12rem;
    }

    .enemy-color-slot select {
        width: 54px;
        max-width: 54px;
        font-size: 0.45rem;
        height: 18px;
    }

    #enemyModal .custom-modal-actions {
        grid-template-columns: 1fr;
        gap: 0.4rem;
    }
}
