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

:root {
    --primary: #FF6B6B;
    --secondary: #4ECDC4;
    --bg-dark: #1a1a2e;
    --bg-light: #16213e;
    --text: #fff;
    --text-muted: #888;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-light) 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    color: var(--text);
}

button, input {
    touch-action: manipulation;
    font-family: inherit;
}

/* Screens */
.screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

/* Logo */
.logo {
    font-size: 2.8rem;
    font-weight: 900;
    color: var(--text);
    text-shadow: 0 0 30px rgba(78, 205, 196, 0.5);
    margin-bottom: 4px;
    letter-spacing: -1px;
}

.logo span {
    color: var(--secondary);
}

.tagline {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 24px;
}

/* Inputs */
input[type="text"] {
    width: 100%;
    max-width: 320px;
    padding: 14px 18px;
    font-size: 1rem;
    border: 2px solid var(--secondary);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    text-align: center;
    margin-bottom: 12px;
    outline: none;
    transition: all 0.2s ease;
}

input[type="text"]::placeholder {
    color: #555;
}

input[type="text"]:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.12);
}

/* Buttons */
.btn-primary {
    width: 100%;
    max-width: 320px;
    padding: 16px 24px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    background: linear-gradient(135deg, var(--primary) 0%, #e55a5a 100%);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    width: 100%;
    max-width: 320px;
    padding: 14px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--secondary);
    background: transparent;
    border: 2px solid var(--secondary);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-secondary:active {
    background: rgba(78, 205, 196, 0.15);
}

.btn-small {
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-start {
    margin-top: 16px;
    animation: pulse-btn 2s infinite;
}

@keyframes pulse-btn {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.4); }
    50% { box-shadow: 0 0 0 12px rgba(255, 107, 107, 0); }
}

.divider {
    color: #555;
    margin: 16px 0;
    font-size: 0.85rem;
}

/* Create Options */
.create-options {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 320px;
    margin-bottom: 4px;
}

.create-options .btn-primary,
.create-options .btn-secondary {
    flex: 1;
    padding: 14px 8px;
    font-size: 0.75rem;
    letter-spacing: 0;
}

/* Join Row */
.join-row {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 320px;
}

.join-row input {
    flex: 1;
    max-width: none;
    margin-bottom: 0;
    font-size: 1.1rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.join-row .btn-secondary {
    width: auto;
    padding: 14px 20px;
    flex-shrink: 0;
}

/* Lobby Section */
.lobby-section {
    width: 100%;
    max-width: 320px;
    margin-top: 20px;
}

.lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.lobby-list {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    max-height: 180px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.lobby-empty {
    padding: 24px 16px;
    text-align: center;
    color: #555;
    font-size: 0.85rem;
}

.lobby-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lobby-item:last-child {
    border-bottom: none;
}

.lobby-item.bot-room {
    background: rgba(78, 205, 196, 0.08);
}

.lobby-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.lobby-host {
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lobby-players {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.lobby-join-btn {
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--bg-dark);
    background: var(--secondary);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    margin-left: 10px;
}

.bot-badge {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 700;
    background: var(--secondary);
    color: var(--bg-dark);
    padding: 2px 5px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}

/* Group Info */
.group-info {
    text-align: center;
    padding: 20px;
    position: absolute;
    bottom: 80px;
    left: 0;
    right: 0;
}

.group-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.group-text {
    color: var(--secondary);
    font-size: 0.95rem;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Room Code Display */
.room-code-display {
    text-align: center;
    margin-bottom: 20px;
    width: 100%;
    max-width: 320px;
}

.room-code-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.room-code-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--secondary);
    letter-spacing: 1px;
    margin-bottom: 12px;
    word-break: break-word;
    line-height: 1.3;
    padding: 0 10px;
}

/* When showing room code (4 letters), make it bigger */
.room-code-value.code-style {
    font-size: 2.2rem;
    letter-spacing: 6px;
    text-shadow: 0 0 20px rgba(78, 205, 196, 0.5);
}

.room-code-display .btn-small {
    margin: 0 4px;
}

/* Waiting Screen */
#waiting-screen {
    justify-content: flex-start;
    padding-top: calc(60px + var(--safe-top));
}

.waiting-title {
    font-size: 1.2rem;
    color: var(--text);
    margin-bottom: 16px;
    font-weight: 600;
}

.players-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
    max-width: 340px;
    padding: 0 10px;
}

.player-tag {
    padding: 8px 14px;
    border-radius: 20px;
    color: var(--text);
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.player-tag .owner-badge {
    font-size: 0.65rem;
    background: rgba(255, 255, 255, 0.3);
    padding: 2px 5px;
    border-radius: 4px;
    text-transform: uppercase;
}

.waiting-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 8px;
    text-align: center;
    padding: 0 20px;
}

/* Countdown Screen */
.countdown-number {
    font-size: 8rem;
    font-weight: 900;
    color: var(--primary);
    text-shadow: 0 0 50px rgba(255, 107, 107, 0.5);
    animation: countdownPulse 1s infinite;
}

@keyframes countdownPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Game Screen */
#game-screen {
    padding: 0;
}

#game-canvas {
    display: block;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.scoreboard {
    position: absolute;
    top: calc(10px + var(--safe-top));
    left: 10px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 12px;
    padding: 10px 12px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.exit-btn {
    position: absolute;
    bottom: calc(30px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 32px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    background: rgba(255, 107, 107, 0.8);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.score-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.score-item:last-child {
    margin-bottom: 0;
}

.score-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.score-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}

.score-value {
    font-weight: 700;
    min-width: 16px;
    text-align: right;
}

/* Result Screen */
#result-screen {
    gap: 8px;
}

.result-text {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--text);
    text-align: center;
}

.result-text.win {
    color: var(--secondary);
    text-shadow: 0 0 30px rgba(78, 205, 196, 0.5);
}

.result-text.lose {
    color: var(--primary);
}

.result-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 8px;
}

#result-screen .btn-primary {
    margin-top: 24px;
}

#result-screen .btn-leave {
    margin-top: 12px;
    max-width: 200px;
    padding: 12px 24px;
    font-size: 0.85rem;
}

/* Small phones (iPhone SE, etc) */
@media (max-height: 700px) {
    .logo {
        font-size: 2.4rem;
    }

    .tagline {
        margin-bottom: 16px;
    }

    .lobby-section {
        margin-top: 12px;
    }

    .lobby-list {
        max-height: 140px;
    }

    .countdown-number {
        font-size: 6rem;
    }

    #waiting-screen {
        padding-top: calc(40px + var(--safe-top));
    }
}

/* Large phones */
@media (min-height: 850px) {
    .logo {
        font-size: 3.2rem;
        margin-bottom: 8px;
    }

    .tagline {
        margin-bottom: 32px;
    }

    .room-code-value {
        font-size: 1.5rem;
    }
}
