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

.btn {
    border: none;
    padding: 12px 28px;
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    letter-spacing: 1px;
}

html, body {
    width: 100%;
    height: 100%;
    background: #1a1a2e;
    color: #eee;
    font-family: 'Courier New', monospace;
    overflow: hidden;
    touch-action: none;
}

/* ------------------------------------------------------------------ */
/* Screens                                                              */
/* ------------------------------------------------------------------ */

.screen {
    display: none;
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.screen.active {
    display: flex;
}

/* ------------------------------------------------------------------ */
/* Lobby                                                                */
/* ------------------------------------------------------------------ */

#screen-lobby h1 {
    font-size: 2.4rem;
    color: #ffd700;
    letter-spacing: 2px;
    margin-bottom: 4px;
}

.subtitle {
    font-size: 0.9rem;
    color: #aaa;
    margin-bottom: 24px;
}

#room-code {
    font-size: 1rem;
    color: #aaa;
    margin-bottom: 16px;
}

#room-code span {
    color: #ffd700;
    font-size: 1.3rem;
    font-weight: bold;
    letter-spacing: 4px;
}

#player-list {
    margin-bottom: 16px;
    text-align: center;
    line-height: 1.8;
    font-size: 1rem;
}

#waiting-msg {
    color: #888;
    font-size: 0.85rem;
    animation: blink 1.2s step-end infinite;
    text-align: center;
    margin-bottom: 16px;
}

#btn-invite {
    background: #2980b9;
    margin-top: 8px;
}

#btn-invite:active {
    background: #3498db;
}

.mode-btn {
    background: #6c3483;
    margin-top: 6px;
    margin-bottom: 6px;
    width: 100%;
}

.mode-btn:active {
    background: #8e44ad;
}

.mode-label {
    font-size: 0.82rem;
    color: #aaa;
    margin-bottom: 4px;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ------------------------------------------------------------------ */
/* Game                                                                 */
/* ------------------------------------------------------------------ */

#screen-game {
    justify-content: flex-start;
    padding: 0;
    gap: 0;
}

#game-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    overflow: hidden;
}

#game-canvas {
    display: block;
    image-rendering: pixelated;
    max-width: 100vw;
    max-height: 100%;
}

/* ------------------------------------------------------------------ */
/* Controls                                                             */
/* ------------------------------------------------------------------ */

#controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 12px 24px 20px;
    flex-shrink: 0;
}

#dpad {
    display: grid;
    grid-template-columns: 56px 56px 56px;
    grid-template-rows: 56px 56px 56px;
    gap: 4px;
}

.dpad-btn {
    background: rgba(255, 255, 255, 0.12);
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    color: #eee;
    font-size: 1.4rem;
    cursor: pointer;
    touch-action: none;
    transition: background 0.08s;
}

.dpad-btn:active {
    background: rgba(255, 255, 255, 0.3);
}

#btn-up    { grid-column: 2; grid-row: 1; }
#btn-left  { grid-column: 1; grid-row: 2; }
#btn-down  { grid-column: 2; grid-row: 3; }
#btn-right { grid-column: 3; grid-row: 2; }

#btn-bomb {
    width: 90px;
    height: 90px;
    background: #c0392b;
    border: 3px solid #922b21;
    border-radius: 50%;
    color: white;
    font-size: 0.9rem;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    touch-action: none;
    transition: background 0.08s;
}

#btn-bomb:active {
    background: #e74c3c;
}

.mute-btn {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    align-self: flex-end;
    touch-action: none;
}

.mute-btn:active {
    background: rgba(255, 255, 255, 0.25);
}

/* ------------------------------------------------------------------ */
/* Game Over                                                            */
/* ------------------------------------------------------------------ */

#screen-gameover {
    gap: 16px;
    overflow-y: auto;
    max-height: 100vh;
}

#gameover-title {
    font-size: 2rem;
    color: #ffd700;
    text-align: center;
}

#btn-play-again {
    background: #27ae60;
    padding: 14px 36px;
    font-size: 1.1rem;
}

/* ------------------------------------------------------------------ */
/* Stats leaderboard                                                    */
/* ------------------------------------------------------------------ */

#gameover-stats {
    width: 100%;
    max-width: 420px;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    color: #eee;
}

.stats-table th {
    padding: 6px 8px;
    text-align: center;
    color: #aaa;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    font-weight: normal;
}

.stats-table td {
    padding: 7px 8px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.07);
}

.stats-table td:nth-child(2) {
    text-align: left;
}

.stats-table tbody tr:nth-child(even) {
    background: rgba(255,255,255,0.04);
}

.stats-table tbody tr.winner-row {
    background: rgba(255, 215, 0, 0.12);
    color: #ffd700;
}

/* ------------------------------------------------------------------ */
/* Countdown overlay                                                    */
/* ------------------------------------------------------------------ */

.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    z-index: 50;
}

.overlay.hidden {
    display: none;
}

#countdown-number {
    font-size: 9rem;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.6);
}

.countdown-animate {
    animation: countdown-pop 0.75s ease-out forwards;
}

@keyframes countdown-pop {
    0%   { transform: scale(0.4); opacity: 0; }
    60%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1);    opacity: 1; }
}

#btn-wait {
    margin-top: 4rem;
    background: #2980b9;
}

#btn-wait:disabled {
    opacity: 0.5;
    cursor: default;
}

#btn-wait.hidden,
#wait-votes.hidden {
    display: none;
}

#wait-votes {
    margin-top: 0.4rem;
    color: #fff;
    font-size: 1rem;
}

/* ------------------------------------------------------------------ */
/* Skin Selector (Lobby)                                               */
/* ------------------------------------------------------------------ */

.skin-selector {
    margin: 16px 0;
    width: 100%;
    max-width: 320px;
}

.skin-selector h3 {
    color: #ffd700;
    font-size: 0.9rem;
    margin-bottom: 8px;
    text-align: center;
}

.skins-grid-inline {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.skins-grid-inline::-webkit-scrollbar {
    height: 4px;
}

.skins-grid-inline::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
}

.skin-option {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    padding: 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid transparent;
    transition: all 0.15s;
}

.skin-option.selected {
    border-color: #ffd700;
    background: rgba(255, 215, 0, 0.15);
}

.skin-option.locked {
    opacity: 0.6;
}

.skin-option:active {
    transform: scale(0.95);
}

.skin-option .skin-preview {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 6px;
}

.skin-option.selected .skin-preview {
    border-color: #ffd700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.skin-name {
    font-size: 0.7rem;
    color: #eee;
    margin-bottom: 2px;
}

.skin-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 8px;
}

.skin-badge.equipped {
    background: #27ae60;
    color: white;
}

.skin-badge.own {
    background: rgba(255, 255, 255, 0.15);
    color: #aaa;
}

.skin-badge.locked {
    background: rgba(231, 76, 60, 0.8);
    color: white;
}

/* ------------------------------------------------------------------ */
/* Skin Preview Modal                                                  */
/* ------------------------------------------------------------------ */

.skin-preview-modal {
    background: #1a1a2e;
    border-radius: 20px;
    padding: 32px 24px 24px;
    max-width: 340px;
    width: 90%;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.btn-close-preview {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-close-preview:active {
    background: rgba(255, 255, 255, 0.2);
}

.skin-preview-large {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 24px;
}

.skin-preview-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
    margin-bottom: 16px;
}

/* Large live-model canvas shown in the preview modal. */
.model-preview-large {
    width: 120px;
    height: 120px;
    border-radius: 14px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
    margin-bottom: 16px;
}

.default-colors-preview {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

/* Default-skin preview: one live-model canvas per player-slot color. */
.color-option {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.3);
    display: block;
}

.skin-preview-large h2 {
    color: #ffd700;
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.skin-description {
    color: #aaa;
    font-size: 0.9rem;
    text-align: center;
    margin: 0;
    max-width: 280px;
}

.skin-preview-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-preview {
    border: none;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-preview:active {
    transform: scale(0.98);
}

.btn-preview-equip {
    background: #27ae60;
    color: white;
}

.btn-preview-equip:active {
    background: #219a52;
}

.btn-preview-buy {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    color: white;
}

.btn-preview-buy:active {
    background: linear-gradient(135deg, #e67e22, #d35400);
}

.stars-icon {
    font-size: 1.1rem;
}

.btn-preview-close {
    background: rgba(255, 255, 255, 0.1);
    color: #ccc;
}

.btn-preview-close:active {
    background: rgba(255, 255, 255, 0.2);
}

.btn-preview-disabled {
    background: rgba(255, 255, 255, 0.1);
    color: #666;
    cursor: default;
}

.btn-preview-disabled:active {
    transform: none;
}

/* ------------------------------------------------------------------ */
/* Shop Tabs                                                           */
/* ------------------------------------------------------------------ */

.shop-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    justify-content: center;
}

.shop-tab {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    color: #aaa;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.shop-tab.active {
    background: #ffd700;
    color: #1a1a2e;
}

.shop-tab:active {
    transform: scale(0.95);
}

/* ------------------------------------------------------------------ */
/* Accessories                                                        */
/* ------------------------------------------------------------------ */

.accessories-container {
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
}

.accessories-container.hidden {
    display: none;
}

.skins-grid-inline.hidden {
    display: none;
}

.accessory-slot-section {
    margin-bottom: 16px;
}

.accessory-slot-title {
    color: #ffd700;
    font-size: 0.75rem;
    margin-bottom: 8px;
    text-align: center;
}

.accessories-grid {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.accessories-grid::-webkit-scrollbar {
    height: 4px;
}

.accessories-grid::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
}

.accessory-option {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    padding: 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid transparent;
    transition: all 0.15s;
    min-width: 64px;
}

.accessory-option.equipped {
    border-color: #ffd700;
    background: rgba(255, 215, 0, 0.15);
}

.accessory-option.locked {
    opacity: 0.6;
}

.accessory-option:active {
    transform: scale(0.95);
}

.accessory-option .accessory-preview {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 6px;
}

.accessory-option.accessory-none .accessory-preview {
    background: rgba(255, 255, 255, 0.1) !important;
    border: 2px dashed rgba(255, 255, 255, 0.3);
}

.accessory-option.accessory-none .accessory-preview span {
    font-size: 0.65rem;
    color: #888;
}

.accessory-option.equipped .accessory-preview {
    border-color: #ffd700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

.accessory-icon {
    font-size: 1.2rem;
}

.accessory-name {
    font-size: 0.65rem;
    color: #eee;
    margin-bottom: 2px;
    text-align: center;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.accessory-badge {
    font-size: 0.6rem;
    padding: 2px 5px;
    border-radius: 6px;
}

.accessory-badge.equipped {
    background: #27ae60;
    color: white;
}

.accessory-badge.own {
    background: rgba(255, 255, 255, 0.15);
    color: #aaa;
}

.accessory-badge.locked {
    background: rgba(231, 76, 60, 0.8);
    color: white;
}

.accessory-preview-large {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.accessory-preview-large .accessory-icon {
    font-size: 3rem;
}

.accessory-preview-large.accessory-none {
    background: rgba(255, 255, 255, 0.1) !important;
    border: 4px dashed rgba(255, 255, 255, 0.3);
    box-shadow: none;
}

.accessory-preview-large.accessory-none span {
    font-size: 1rem;
    color: #888;
}

