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

body {
    font-family: Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

#game-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 900px;
}

h1 {
    color: #333;
    margin-bottom: 20px;
    font-size: 2em;
}

#game {
    margin: 20px auto;
    border: 3px solid #667eea;
    border-radius: 10px;
    overflow: hidden;
    /* Give the canvas parent a stable, defined box (width + 4:3 aspect) so
       Phaser's Scale.FIT has a fixed target. Previously this was
       display:inline-block with no size, so the parent shrank to the canvas
       while the canvas fit to the parent — a feedback loop that made the game
       resize a few times on load before settling. */
    width: 800px;
    max-width: 100%;
    aspect-ratio: 4 / 3;
}

#instructions {
    margin-top: 20px;
    padding: 15px;
    background: #f0f0f0;
    border-radius: 8px;
}

#instructions h2 {
    color: #667eea;
    font-size: 1.3em;
    margin-bottom: 10px;
}

#instructions p {
    color: #555;
    font-size: 1em;
}

/* Mobile-specific controls visibility */
.mobile-controls {
    display: none;
}

.desktop-controls {
    display: block;
}

/* Mobile responsive styles */
@media screen and (max-width: 768px) {
    body {
        padding: 10px;
        align-items: flex-start;
    }
    
    #game-container {
        padding: 15px;
        border-radius: 10px;
        width: 100%;
        max-width: 100%;
    }
    
    h1 {
        font-size: 1.5em;
        margin-bottom: 10px;
    }
    
    #game {
        margin: 10px auto;
        border-width: 2px;
        max-width: 100%;
    }
    
    #game canvas {
        max-width: 100% !important;
        height: auto !important;
        display: block;
    }
    
    #instructions {
        margin-top: 10px;
        padding: 10px;
    }
    
    #instructions h2 {
        font-size: 1.1em;
        margin-bottom: 8px;
    }
    
    #instructions p {
        font-size: 0.9em;
    }
    
    .mobile-controls {
        display: block;
    }
    
    .desktop-controls {
        display: none;
    }
}

/* Extra small devices */
@media screen and (max-width: 480px) {
    body {
        padding: 5px;
    }
    
    #game-container {
        padding: 10px;
    }
    
    h1 {
        font-size: 1.2em;
    }
    
    #instructions {
        padding: 8px;
    }
    
    #instructions h2 {
        font-size: 1em;
    }
    
    #instructions p {
        font-size: 0.85em;
    }
}

/* Voice Controls Styles */
#voice-controls {
    margin: 15px auto;
    text-align: center;
}

#voice-chat-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    font-weight: 600;
}

#voice-chat-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

#voice-chat-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#voice-chat-btn.voice-active {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 4px 15px rgba(56, 239, 125, 0.4);
    }
    50% {
        box-shadow: 0 4px 25px rgba(56, 239, 125, 0.8);
    }
}

#mic-select {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 16px;
    font-size: 16px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    font-weight: 600;
    display: inline-block;
    margin: 0 10px;
    min-width: 200px;
}

#mic-select:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

#mic-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#mic-select option {
    background: white;
    color: #333;
}

#disconnect-btn {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.4);
    font-weight: 600;
    margin-left: 10px;
}

#disconnect-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.6);
}

@media screen and (max-width: 768px) {
    #voice-controls {
        margin: 10px auto;
    }
    
    #voice-chat-btn {
        padding: 10px 20px;
        font-size: 14px;
        display: block;
        width: 100%;
        margin: 8px auto;
    }
    
    #mic-select {
        padding: 10px 16px;
        font-size: 14px;
        display: block;
        width: 100%;
        margin: 8px auto;
    }
    
    #disconnect-btn {
        padding: 10px 20px;
        font-size: 14px;
        display: block;
        width: 100%;
        margin: 8px auto;
    }
}

/* Disconnected page styles */
.disconnected-message {
    font-size: 1.2em;
    margin-bottom: 15px;
}

.disconnected-explanation {
    margin-bottom: 20px;
}

.rejoin-button {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 25px;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
}

.rejoin-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

/* Lobby page styles */
.lobby-container {
    max-width: 800px;
}

/* Player setup section */
.player-setup-section {
    margin: 20px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.player-setup-section h2 {
    color: #667eea;
    font-size: 1.3em;
    margin-bottom: 15px;
}

.input-group {
    margin-bottom: 15px;
    text-align: left;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.input-group label {
    display: block;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
    font-size: 14px;
}

#player-name-input {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    border: 2px solid #667eea;
    border-radius: 8px;
    box-sizing: border-box;
}

#player-name-input:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.color-swatches {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.color-swatch {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 3px solid transparent;
    padding: 0;
    cursor: pointer;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s ease;
}

.color-swatch:hover {
    transform: scale(1.12);
}

.color-swatch.selected {
    border-color: #fff;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.45);
}

/* --- Pool minigame HUD --- */
.pool-hud {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(31, 27, 22, 0.9);
    color: #efeae3;
    padding: 10px 18px;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
    z-index: 10000;
}

.pool-hud[hidden] {
    display: none;
}

.pool-hint {
    font-size: 0.9em;
    color: #cfc7bc;
}

.pool-exit-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: #7d5e3f;
    color: #fff;
    cursor: pointer;
}

/* --- Bookcase UI --- */
.book-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

/* display:flex above would override the hidden attribute — keep hidden hiding. */
.book-modal[hidden] {
    display: none;
}

.book-content {
    background: #efeae3;
    border-radius: 14px;
    padding: 24px;
    max-width: 90vw;
    width: 460px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
    text-align: center;
}

.book-content h2 {
    color: #4a4239;
    margin-bottom: 16px;
}

.book-shelf {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    padding: 12px;
    background: #6b4a2f;
    border-radius: 8px;
}

.book-spine {
    width: 36px;
    height: 120px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    box-shadow: inset -4px 0 rgba(0, 0, 0, 0.18), 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s ease;
    /* Title reads down the spine like a real book */
    writing-mode: vertical-rl;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
    color: rgba(255, 255, 255, 0.95);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.book-spine:hover {
    transform: translateY(-6px);
}

.book-title {
    color: #4a4239;
    font-size: 1.05em;
    margin-bottom: 10px;
}

.book-reader .book-page {
    background: #fffdf7;
    color: #333;
    height: 340px;
    max-height: 55vh;
    overflow: hidden;
    border-radius: 6px;
    padding: 22px 26px;
    text-align: left;
    font-size: 1em;
    line-height: 1.6;
    white-space: pre-wrap;
    box-shadow: inset 0 0 0 1px #e0d8c8;
}

.book-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
}

.book-nav-btn {
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    background: #7d5e3f;
    color: #fff;
    cursor: pointer;
}

.book-nav-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.book-page-indicator {
    color: #7a726a;
    font-size: 0.9em;
}

.book-back-btn,
.book-close-btn {
    margin-top: 16px;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
}

.book-back-btn {
    background: #7d5e3f;
    color: #fff;
    margin-right: 8px;
}

.book-close-btn {
    background: #d9cdbf;
    color: #4a4239;
}

.create-room-section {
    margin: 20px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.create-room-section h2 {
    color: #667eea;
    font-size: 1.3em;
    margin-bottom: 15px;
}

#room-name-input {
    width: 100%;
    max-width: 400px;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #667eea;
    border-radius: 8px;
    margin-bottom: 10px;
    box-sizing: border-box;
}

#room-name-input:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#room-name-input.input-error {
    border-color: #e74c3c;
}

.input-error-message {
    color: #e74c3c;
    font-size: 14px;
    margin-bottom: 10px;
    margin-top: -5px;
}

.room-create-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    font-weight: 600;
}

.room-create-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.room-list-section {
    margin: 20px 0;
}

.room-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 0 20px;
}

.room-list-header h2 {
    color: #667eea;
    font-size: 1.3em;
    margin: 0;
}

.refresh-btn {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(56, 239, 125, 0.4);
    font-weight: 600;
}

.refresh-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(56, 239, 125, 0.6);
}

.room-list {
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
    min-height: 200px;
}

/* Credits button + modal */
.credits-section {
    margin-top: 20px;
}

.credits-btn {
    background: transparent;
    color: #667eea;
    border: 2px solid #667eea;
    padding: 8px 22px;
    font-size: 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.credits-btn:hover {
    background: #667eea;
    color: white;
}

.credits-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 1000;
}

.credits-modal[hidden] {
    display: none;
}

.credits-content {
    background: #fff;
    border-radius: 15px;
    padding: 30px;
    max-width: 480px;
    width: 100%;
    text-align: left;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.credits-content h2 {
    color: #333;
    margin-bottom: 15px;
    text-align: center;
}

.credits-content h3 {
    color: #667eea;
    font-size: 1.1em;
    margin: 18px 0 8px;
}

.credits-content ul {
    list-style: none;
    color: #555;
    line-height: 1.6;
}

.credits-content a {
    color: #667eea;
    font-weight: 600;
}

.credits-close-btn {
    display: block;
    margin: 24px auto 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 28px;
    font-size: 15px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.credits-close-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

/* Auth bar + sign-in modal (opt-in accounts) */
.auth-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 10px;
}

.auth-status {
    color: #666;
    font-size: 13px;
}

.auth-btn {
    background: transparent;
    color: #667eea;
    border: 2px solid #667eea;
    padding: 6px 16px;
    font-size: 13px;
    border-radius: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 600;
}

.auth-btn:hover {
    background: #667eea;
    color: white;
}

.auth-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 1000;
}

.auth-modal[hidden] {
    display: none;
}

.auth-content {
    background: #fff;
    border-radius: 15px;
    padding: 28px;
    max-width: 400px;
    width: 100%;
    text-align: left;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.auth-content h2 {
    color: #333;
    margin-bottom: 6px;
    text-align: center;
}

.auth-subtitle {
    color: #777;
    font-size: 13px;
    text-align: center;
    margin-bottom: 16px;
}

.auth-message {
    background: #eef0ff;
    color: #445;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 14px;
}

.auth-message.auth-error {
    background: #ffeaea;
    color: #a33;
}

.auth-content .input-group {
    margin-bottom: 12px;
}

.auth-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 6px;
}

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

.auth-close-btn {
    display: block;
    margin: 18px auto 0;
    background: none;
    border: none;
    color: #888;
    font-size: 14px;
    cursor: pointer;
    text-decoration: underline;
}

.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin-bottom: 10px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.room-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.room-info {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-right: 15px;
}

.room-name {
    font-weight: 600;
    color: #333;
    font-size: 1.1em;
}

.player-count {
    color: #667eea;
    font-weight: 600;
    margin-left: 15px;
}

.room-join-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    font-weight: 600;
    min-width: 80px;
}

.room-join-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.no-rooms-message,
.loading-message,
.error-message {
    text-align: center;
    color: #666;
    font-size: 1.1em;
    padding: 40px 20px;
}

.error-message {
    color: #e74c3c;
}

.back-to-lobby-btn {
    display: inline-block;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    text-decoration: none;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(245, 87, 108, 0.4);
    font-weight: 600;
    margin-left: 10px;
}

.back-to-lobby-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.6);
}

@media screen and (max-width: 768px) {
    .lobby-container {
        padding: 15px;
    }
    
    .player-setup-section {
        padding: 15px;
    }
    
    .create-room-section {
        padding: 15px;
    }
    
    .room-list-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .room-list-header h2 {
        font-size: 1.1em;
    }
    
    .room-item {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .room-info {
        margin-right: 0;
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .room-join-btn {
        width: 100%;
    }
    
    .back-to-lobby-btn {
        display: block;
        width: 100%;
        margin: 10px 0;
        text-align: center;
    }
}

