:root {
    --bg: #1a1a2e;
    --card: #2d2d4a;
    --primary: #fff;
    --dim: #8b8ba3;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--primary);
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

#app {
    width: 100%;
    height: 100%;
    max-width: 500px;
    margin: 0 auto;
    position: relative;
}

.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    background: var(--bg);
}

.screen.active { display: flex; }

.screen-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
}

.screen-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.screen-header h2 {
    flex: 1;
    text-align: center;
    margin-right: 52px;
    font-size: 18px;
    font-weight: 600;
}

/* Buttons */
.btn {
    padding: 16px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
}

.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.4; }

.btn-primary {
    background: #fff;
    color: #1a1a2e;
}

.btn-secondary {
    background: var(--card);
    color: var(--primary);
}

.btn-outline {
    background: var(--card);
    color: var(--dim);
}

.btn-back {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: var(--card);
    color: var(--primary);
    font-size: 18px;
    cursor: pointer;
}

.btn-icon { display: none; }

/* Loading */
#loading-screen {
    justify-content: center;
    align-items: center;
}

.loading-content { text-align: center; }

.loading-content .logo {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.loading-content h1 {
    font-size: 16px;
    font-weight: 400;
    color: var(--dim);
    margin-bottom: 40px;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--card);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Menu */
#menu-screen .screen-content {
    justify-content: center;
    align-items: center;
}

.logo-large {
    font-size: 42px;
    font-weight: 700;
    letter-spacing: 3px;
    margin-bottom: 8px;
}

.game-title {
    font-size: 16px;
    color: var(--dim);
    font-weight: 400;
    margin-bottom: 48px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 280px;
}

.player-stats {
    margin-top: 48px;
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.stat-label {
    font-size: 12px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
}

/* Mode Select */
.multiplayer-info {
    text-align: center;
    padding: 32px 24px;
    margin-bottom: 24px;
    background: var(--card);
    border-radius: 16px;
}

.multiplayer-info .info-icon {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 12px;
}

.multiplayer-info p {
    font-size: 14px;
    color: var(--dim);
    line-height: 1.6;
}

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

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 24px;
}

.modal.active { display: flex; }

.modal-content {
    background: var(--card);
    padding: 28px;
    border-radius: 20px;
    width: 100%;
    max-width: 300px;
}

.modal-content h3 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 18px;
    font-weight: 600;
}

.modal-content input {
    width: 100%;
    padding: 16px;
    font-size: 22px;
    text-align: center;
    border: none;
    border-radius: 12px;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 8px;
    background: var(--bg);
    color: var(--primary);
    font-weight: 600;
}

.modal-content input:focus { outline: none; }
.modal-content input::placeholder { color: var(--dim); }

.modal-buttons {
    display: flex;
    gap: 12px;
}

.modal-buttons .btn { flex: 1; }

.error-text {
    color: #ef4444;
    font-size: 13px;
    text-align: center;
    margin-top: 12px;
}

/* Room Lobby */
.room-code-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: var(--card);
    border-radius: 16px;
    padding: 20px 24px;
    margin-bottom: 20px;
}

.room-code-display {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 8px;
    font-family: 'SF Mono', monospace;
}

.btn-copy {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.15);
    color: var(--dim);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-copy.copied {
    background: #4ade80;
    color: #000;
}

.room-mode {
    text-align: center;
    margin-bottom: 20px;
    color: var(--dim);
    font-size: 14px;
}

.mode-value { color: var(--primary); }

.players-list {
    flex: 1;
    background: var(--card);
    border-radius: 16px;
    padding: 12px;
    margin-bottom: 20px;
    overflow-y: auto;
}

.player-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.player-item:last-child { margin-bottom: 0; }
.player-item.local { background: rgba(255,255,255,0.08); }

.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-name {
    font-size: 15px;
    font-weight: 500;
}

.host-badge {
    font-size: 11px;
    padding: 3px 8px;
    background: var(--dim);
    color: var(--bg);
    border-radius: 6px;
    font-weight: 600;
}

.player-status {
    font-size: 13px;
    color: var(--dim);
}

.player-status.ready { color: #4ade80; }

.room-actions {
    display: flex;
    gap: 12px;
}

.room-actions .btn { flex: 1; }

.room-status {
    text-align: center;
    color: var(--dim);
    margin-top: 16px;
    font-size: 14px;
}

.hidden { display: none !important; }
.btn-ready-active { background: #ef4444; color: #fff; }

/* Leaderboard */
.leaderboard-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: var(--card);
    border-radius: 12px;
    padding: 6px;
}

.tab {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--dim);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.tab.active {
    background: #fff;
    color: var(--bg);
}

.leaderboard-list {
    flex: 1;
    background: var(--card);
    border-radius: 16px;
    padding: 12px;
    overflow-y: auto;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.leaderboard-row:last-child { margin-bottom: 0; }
.leaderboard-row.local { background: rgba(255,255,255,0.08); }

.lb-rank {
    width: 32px;
    font-size: 15px;
    color: var(--dim);
}

.lb-name {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
}

.lb-score {
    font-size: 15px;
    font-weight: 600;
}

.player-rank {
    text-align: center;
    padding: 16px;
    color: var(--dim);
    font-size: 14px;
}

.no-data, .loading, .error {
    text-align: center;
    padding: 40px;
    color: var(--dim);
}

/* Settings */
.settings-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.setting-item {
    background: var(--card);
    border-radius: 16px;
    padding: 20px;
}

.setting-label {
    display: block;
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 14px;
}

.setting-options {
    display: flex;
    gap: 10px;
}

.setting-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 24px;
    background: var(--bg);
    color: var(--dim);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.setting-btn.active {
    background: #fff;
    color: var(--bg);
}

/* Game Over */
#game-over-screen .screen-content {
    justify-content: center;
    align-items: center;
}

#game-over-screen h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 32px;
}

.result-panel {
    text-align: center;
    margin-bottom: 40px;
}

.score-label {
    font-size: 12px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    font-size: 72px;
    font-weight: 700;
    margin-top: 8px;
}

.high-score-notice {
    margin-top: 20px;
    padding: 10px 20px;
    background: #4ade80;
    border-radius: 24px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    display: inline-block;
}

.multiplayer-results {
    width: 100%;
    max-width: 300px;
    margin-bottom: 32px;
}

.multiplayer-results h3 {
    text-align: center;
    margin-bottom: 16px;
    font-size: 15px;
    font-weight: 500;
}

.results-list {
    background: var(--card);
    border-radius: 16px;
    padding: 12px;
}

.result-row {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 8px;
}

.result-row:last-child { margin-bottom: 0; }
.result-row.local { background: rgba(255,255,255,0.08); }
.result-row.winner { background: rgba(74, 222, 128, 0.15); }

.result-rank {
    width: 32px;
    font-size: 16px;
}

.result-name {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
}

.result-score {
    font-size: 15px;
    font-weight: 600;
}

.game-over-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 280px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 14px 24px;
    background: var(--card);
    color: var(--primary);
    border-radius: 12px;
    font-size: 14px;
    opacity: 0;
    transition: all 0.2s;
    z-index: 200;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
