html {
    font-family: -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    height: 100%;
    height: -webkit-fill-available; /* Fix for iOS Safari */
    width: 100%;
    margin: 0;
    padding: 0;
    background-color: #121212;
    color: #e0e0e0;
    box-sizing: border-box;
    overflow: hidden;
    position: fixed;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: inherit;
    height: 100%;
    height: -webkit-fill-available; /* Fix for iOS Safari */
    min-height: -webkit-fill-available; /* Fix for iOS Safari */
    width: 100%;
    margin: 0;
    padding: 0;
    background-color: inherit;
    color: inherit;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
}

#lobby {
    background: #1e1e1e;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(255, 255, 255, 0.1);
    text-align: center;
    max-width: 500px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

#game {
    background: #1e1e1e;
    padding: 6px 12px;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(255, 255, 255, 0.1);
    text-align: center;
    max-width: 640px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100vh;
    overflow: hidden;
    margin: 2px 0;
    position: relative;
}

#lobby h1 {
    color: #3498db;
    margin-bottom: 20px;
    font-size: 36px;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.1);
}

#gameHeader {
    width: 100%;
    flex-shrink: 0;
    margin: 1px 0;
}

.game-title {
    color: #3498db;
    margin: 0;
    font-size: 22px;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 1;
}

.header-controls {
    display: flex;
    align-items: center;
    width: 100%;
    flex-shrink: 0;
    position: relative;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    z-index: 2;
}

.header-right {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    justify-content: flex-end;
    margin-left: auto;
    z-index: 2;
}

.lobby-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.form-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.join-row {
    display: flex;
    width: 100%;
    gap: 8px;
}

input:not([type="color"]) {
    padding: 12px 15px;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 16px;
    width: 100%;
    transition: border-color 0.3s;
    box-sizing: border-box;
    background-color: #2a2a2a;
    color: #e0e0e0;
}

/* Specific style for the room code input */
#roomCode {
    width: 100%;
    flex: 1;
}

input:not([type="color"]):focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
}

input[type="color"] {
    -webkit-appearance: none;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    margin: 0;
    vertical-align: middle;
    background-color: #2a2a2a;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
    border-radius: 4px;
    border: 1px solid #444;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

.eraser-active {
    background-color: #ffecb3 !important;
    border: 1px solid #ffc107 !important;
    color: #333 !important;
}

button {
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s;
    background-color: #3498db;
    color: #ffffff;
    touch-action: manipulation;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}

button:hover {
    background-color: #2980b9;
}

button:active {
    background-color: #1f6aa5;
}

.primary-btn {
    background-color: #3498db;
    color: white;
    width: 100%;
}

.primary-btn:hover {
    background-color: #2980b9;
}

.secondary-btn {
    background-color: #2ecc71;
    color: white;
    white-space: nowrap;
}

/* Specific style for the join button */
.join-row .secondary-btn {
    min-width: 90px;
    padding: 12px 10px;
    font-size: 15px;
}

.secondary-btn:hover {
    background-color: #27ae60;
}

.separator {
    display: flex;
    align-items: center;
    text-align: center;
    color: #666;
    margin: 2px 0;
}

.separator::before,
.separator::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #333;
}

.separator span {
    padding: 0 10px;
    font-style: italic;
}

/* Room buttons */
.room-buttons {
    display: flex;
    gap: 8px;
    margin: 8px 0;
    width: 100%;
}

.room-buttons button {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
}

/* Styles for adaptive button text */
.room-buttons .short-text {
    display: none;
}

@media (max-width: 450px) {
    .room-buttons .full-text {
        display: none;
    }

    .room-buttons .short-text {
        display: inline;
    }
}

/* Keep room buttons on same line even on mobile */
@media (max-width: 500px) {
    .room-buttons {
        flex-direction: row;
        gap: 5px;
    }

    .room-buttons button {
        font-size: 14px;
        padding: 10px 5px;
    }
}

/* Public rooms list */
.public-rooms-container {
    width: 100%;
    margin: 5px 0;
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.public-rooms-container h3 {
    margin: 0 0 10px 0;
    font-size: 1.1em;
    color: #3498db;
}

.public-rooms-list {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #444;
    border-radius: 6px;
    background-color: #2a2a2a;
    padding: 5px;
    margin-bottom: 8px;
    flex: 1;
}

.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    border-radius: 4px;
    margin-bottom: 4px;
    background-color: #333;
    transition: background-color 0.2s;
    cursor: pointer;
}

.room-item:hover {
    background-color: #444;
}

.room-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
}

.room-host {
    font-weight: bold;
    color: #3498db;
}

.room-details {
    font-size: 0.8em;
    color: #aaa;
}

.room-join {
    background-color: #2ecc71;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
    white-space: nowrap;
    min-width: 45px;
}

.loading-rooms {
    padding: 20px;
    text-align: center;
    color: #888;
    font-style: italic;
}

.no-rooms {
    padding: 20px;
    text-align: center;
    color: #888;
    font-style: italic;
}

#refreshRooms {
    position: absolute;
    top: 0;
    right: 0;
    width: 28px;
    height: 28px;
}

#canvas {
    border: 2px solid #555;
    background: white;
    width: 100%; /* Responsive width */
    max-width: 600px; /* Cap at original size */
    height: 400px;
    box-sizing: border-box;
    display: block;
    margin: 0 auto 0 auto;
    box-shadow: 0 2px 5px rgba(255, 255, 255, 0.1);
    max-height: 55vh; /* Ensure canvas doesn't get too large */
}

#gameInfo {
    margin: 2px 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0;
    gap: 0;
    background: #2a2a2a;
    border-radius: 5px;
    font-size: 0.9em;
    min-height: 32px;
    color: #e0e0e0;
    flex-shrink: 0;
    flex-grow: 0;
    white-space: nowrap;
    overflow-x: auto;
}

#gameInfo span {
    margin: 0 10px;
    white-space: nowrap;
}

#gameInfo .game-info-item {
    flex-shrink: 0;
}

#timer {
    font-weight: bold;
    min-width: 70px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    background-color: #333;
    border-radius: 4px;
    border: 1px solid #444;
    height: 24px;
    color: #e0e0e0;
}

.copyable {
    cursor: pointer;
    border-bottom: 1px dashed #666;
}

.copyable:hover {
    color: #3498db;
}

#gameChat {
    width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    height: calc(50% - 72px);
    overflow: hidden;
}

.chat-container {
    display: flex;
    border: 1px solid #444;
    background: #2a2a2a;
    width: 100%;
    flex: 1;
    overflow: hidden;
    margin-bottom: 0;
}

.input-container {
    display: flex;
    border: 1px solid #444;
    border-top: none;
    background: #2a2a2a;
    width: 100%;
    height: 40px;
}

#players {
    width: 120px;
    padding: 10px;
    border-right: 1px solid #444;
    background: #333;
    font-size: 0.9em;
    overflow-y: auto;
    text-align: left;
    color: #e0e0e0;
}

#players strong {
    display: block;
    margin-bottom: 12px;
    text-align: left;
}

#players div {
    margin-bottom: 6px;
    line-height: 1.3;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-score {
    font-weight: bold;
    margin-left: auto;
    padding-left: 4px;
    min-width: 15px;
    text-align: right;
}

/* Ensure proper alignment for AI player scores */
.ai-player .player-score {
    margin-right: 0;
}

/* Player name that may get trimmed if needed */
#players div span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 75%;
    white-space: nowrap;
}

.disconnected-player {
    position: relative;
    opacity: 0.6;
}

#chat {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1px 6px;
    text-align: left;
    font-family: Arial, sans-serif;
    max-width: 100%;
    color: #e0e0e0;
    font-size: 0.95em;
}

#chat > div {
    margin: 6px 0;
    word-wrap: break-word;
    text-align: left;
    padding-right: 0;
    margin-right: 6px;
    border-bottom: 1px dotted #444;
    padding-bottom: 6px;
    line-height: 1.3;
    max-width: 100%;
    overflow-wrap: anywhere;
}

/* Guess message styling */
.guess-message {
    position: relative;
    margin-left: 3px !important;
    padding-left: 10px !important;
    padding-top: 4px !important;
    padding-bottom: 6px !important;
    margin-bottom: 8px !important;
    background-color: rgba(52, 152, 219, 0.05);
    border-left: 3px solid #3498db !important;
    border-bottom: 1px dotted rgba(52, 152, 219, 0.3) !important;
    max-width: calc(100% - 13px); /* Adjust for padding + border */
    box-sizing: border-box;
}

.guess-message::before {
    content: "✏️";
    font-size: 0.8em;
    opacity: 0.6;
    position: absolute;
    right: 8px;
    top: 4px;
}

.system-message {
    color: #888;
    font-style: italic;
    text-align: center !important;
    background-color: #333;
    padding: 4px 8px !important;
    border-radius: 4px;
    font-size: 0.85em;
}

/* Subtle vote messages */
.vote-message {
    font-size: 0.8em;
    opacity: 0.8;
    background-color: #2a2a2a;
    padding: 3px 6px !important;
    margin: 4px 0 !important;
    border-left: 3px solid #3498db;
    text-align: left !important;
}

#chatInput {
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    border: none;
    border-radius: 0;
    font-family: Arial, sans-serif;
    height: 40px;
    background-color: #333;
    color: #e0e0e0;
    transition: background-color 0.3s ease;
}

#chatInput:not(:disabled) {
    background-color: #3c3c3c;
}

#chatInput:focus {
    background-color: #4a4a4a;
    outline: none;
}

#prompt {
    font-size: 1.2em;
    color: #ff6f61;
    margin-bottom: 10px;
    flex-shrink: 0;
}

#drawing-view {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#voting {
    width: 100%;
    background: #1e1e1e;
    padding: 15px;
    border: 2px solid #444;
    box-shadow: 0 2px 5px rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
    color: #e0e0e0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

#voting h2 {
    margin-top: 0;
    color: #3498db;
    font-size: 1.4em;
}

#voting-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 15px;
    padding-right: 5px;
    overflow-y: visible;
}

.image-vote-container {
    background: #2a2a2a;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
    position: relative;
}

.vote-image {
    width: 100%;
    height: 240px;
    object-fit: contain;
    background: #f0f0f0;
    display: block;
}

.image-info, .image-vote-container .vote-button {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.image-vote-container:hover .image-info,
.image-vote-container:hover .vote-button {
    opacity: 1;
    visibility: visible;
}

/* Always show voting info and buttons on touch devices */
@media (max-width: 600px) {
    .image-info, .image-vote-container .vote-button {
        opacity: 1;
        visibility: visible;
    }
}

/* Overlay container that covers the image */
.image-info {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px;
    font-size: 0.9em;
    color: #fff;
    background-color: rgba(0, 0, 0, 0.7);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    border-radius: 8px 8px 0 0;
}

.image-info strong {
    color: #3498db;
    margin-right: 4px;
}

.vote-button {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px;
    background: rgba(52, 152, 219, 0.8);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s, opacity 0.2s, visibility 0.2s;
    margin: 0;
    border-radius: 0 0 8px 8px;
}

.vote-button:hover {
    background: rgba(41, 128, 185, 0.9);
}

/* Selected vote button (green) */
.vote-button.voted-selected {
    background: rgba(46, 204, 113, 0.8);
}

/* Show the colored vote button only on hover for Imageinary */
.image-vote-container:hover .vote-button.voted-selected {
    opacity: 1;
    visibility: visible;
}

/* Restore hover behavior for Waim action buttons */
.waim-action-item .vote-button {
    opacity: 0;
    visibility: hidden;
}

.waim-action-item:hover .vote-button {
    opacity: 1;
    visibility: visible;
}

.vote-button.voted-selected:hover {
    background: rgba(39, 174, 96, 0.9);
}

/* Unselected vote buttons (grey) */
.vote-button.voted-unselected {
    background: rgba(127, 140, 141, 0.8);
}

/* Show the grey vote button only on hover */
.image-vote-container:hover .vote-button.voted-unselected,
.waim-action-item:hover .vote-button.voted-unselected {
    opacity: 1;
    visibility: visible;
}

.vote-button.voted-unselected:hover {
    background: rgba(127, 140, 141, 0.9);
}

/* Vote counter styles */
.vote-counter {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-weight: bold;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s, transform 0.3s;
    z-index: 5;
}

.vote-counter.has-votes {
    opacity: 1;
    transform: scale(1);
}

/* Winning vote counter styling */
.vote-counter.winner {
    background-color: rgba(46, 204, 113, 0.9);
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
    transform: scale(1.15);
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Vote animation container */
.vote-animation-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

/* Flying vote animation */
@keyframes flyToCounter {
    0% {
        opacity: 1;
        transform: translate(var(--start-x), var(--start-y)) scale(1);
    }
    80% {
        opacity: 0.8;
    }
    100% {
        opacity: 0;
        transform: translate(var(--end-x), var(--end-y)) scale(0.5);
    }
}

.flying-vote {
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: #3498db;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 12px;
    pointer-events: none;
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
    animation: flyToCounter 0.8s forwards cubic-bezier(0.25, 0.1, 0.25, 1);
}

#voteResults {
    width: 100%;
    font-size: 1.2em;
    color: #ff6f61;
    text-align: center;
    padding: 10px;
    background: #333;
    border-radius: 4px;
    box-sizing: border-box;
    margin-top: 15px;
}

#gameView {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 auto 0 auto;
    width: 100%;
    height: 50%;
    flex: 1;
    min-height: 0; /* Important for flex container to respect available space */
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal scrolling */
}

#toolbar {
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background-color: #2a2a2a;
    border-radius: 6px;
    border: 1px solid #444;
    box-shadow: 0 1px 3px rgba(255, 255, 255, 0.05);
    align-self: center;
    position: relative;
    z-index: 100;
    width: auto;
    white-space: nowrap;
}

#toolbar.disabled {
    opacity: 0.5;
    pointer-events: none;
}

#toolbar select {
    padding: 4px 6px;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: #333;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 13px;
    height: 28px;
    vertical-align: middle;
    margin: 0;
}

#toolbar button {
    padding: 4px 8px;
    font-size: 13px;
    height: 28px;
    min-width: 55px;
    background-color: #333;
    border: 1px solid #444;
    color: #e0e0e0;
    font-weight: normal;
    vertical-align: middle;
    margin: 0;
}

#toolbar button:hover {
    background-color: #444;
    transform: none;
}

@media (max-height: 800px) {
    #game h1 {
        font-size: 22px;
        margin: 0 0 10px 0;
    }

    #canvas {
        height: 350px;
    }

    .chat-container {
        height: 200px;
    }

    #voting-images {
        max-height: 400px;
    }

    .vote-image {
        height: 200px;
    }
}

@media (max-height: 700px) {
    #game h1 {
        font-size: 20px;
        margin: 0 0 5px 0;
    }

    #canvas {
        height: 300px;
    }

    .chat-container {
        height: 160px;
    }

    #toolbar {
        padding: 4px 6px;
    }

    #toolbar button {
        min-width: 50px;
        font-size: 12px;
    }
}

/* AI Personality Editor Styles */
.ai-personality-editor {
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
}

.ai-editor-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.ai-selection {
    margin-bottom: 15px;
}

.ai-selection select {
    width: 100%;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #444;
    font-size: 16px;
    background-color: #333;
    color: #e0e0e0;
}

#aiPersonalityFormContainer {
    border: 1px solid #444;
    border-radius: 8px;
    padding: 20px;
    background-color: #2a2a2a;
}

#aiPersonalityFormContainer h4 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #e0e0e0;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-group input[type="text"],
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 14px;
    background-color: #333;
    color: #e0e0e0;
}

.form-group textarea {
    min-height: 120px;
    font-family: monospace;
}

.form-hint {
    margin-top: 5px;
    font-size: 12px;
    color: #999;
    font-style: italic;
}

.button-row {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* Notification styles */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 4px;
    background-color: #333;
    color: white;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 300px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.notification.success {
    background-color: #4CAF50;
}

.notification.error {
    background-color: #f44336;
}

.notification.info {
    background-color: #2196F3;
}

/* Button styling for editor buttons in lobby */
.editor-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

@media (max-width: 600px) {
    html, body {
        height: 100%;
    }

    #lobby, #game {
        margin: 0;
        border-radius: 0;
        height: 100%;
        width: 100%;
        max-width: 100%;
        box-shadow: none;
        box-sizing: border-box;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    #game {
        padding: 0 4px;
        height: 100%; /* Full height on mobile */
        max-height: -webkit-fill-available; /* Fix for iOS Safari */
        display: flex;
        flex-direction: column;
    }

    /* Adjust positioning of header buttons on mobile */
    #viewPromptBtn {
        top: 10px !important;
        right: 10px !important;
    }

    .ai-buttons {
        top: 10px !important;
        left: 10px !important;
    }

    #canvas {
        width: 100%;
        height: auto;
        min-height: 200px;
        aspect-ratio: 3/2;
        max-width: 100%;
        border-radius: 8px;
    }

    #gameInfo {
        background: #2a2a2a;
        border-radius: 4px;
        align-items: center;
        min-height: 30px;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .chat-container {
        display: flex;
        flex-direction: row;
        flex: 1;
        overflow: hidden;
        margin-bottom: 0;
    }

    #players {
        width: 90px;
        min-width: 90px;
        border-right: 1px solid #444;
        padding: 8px;
        height: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 0.85em;
    }

    #chat {
        width: 100%;
        padding: 6px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        min-height: 0;
        font-size: 0.9em;
    }

    #chat > div {
        margin: 5px 0;
        padding-bottom: 5px;
    }

    #toolbar {
        flex-wrap: wrap;
        justify-content: center;
        padding: 4px;
        width: 100%;
    }

    #toolbar button,
    #toolbar select,
    #toolbar input {
        margin: 2px;
        padding: 8px 6px;
        font-size: 12px;
        height: 32px;
    }

    #gameInfo span {
        margin: 0 6px;
        font-size: 0.9em;
        white-space: nowrap;
    }

    #voting-images {
        grid-template-columns: 1fr;
    }

    .lobby-form {
        width: 100%;
        padding: 0;
    }

    /* Keep join row as row even on mobile */
    .join-row {
        flex-direction: row;
        gap: 8px;
    }

    #lobby h1 {
        font-size: 24px;
        margin: 5px 0 15px;
    }

    .public-rooms-list {
        max-height: 30vh;
    }

    .public-rooms-container h3 {
        margin: 0 0 5px 0;
    }

    .header-controls {
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-left, .header-right {
        flex-wrap: nowrap;
        flex-shrink: 0;
    }

    .input-container {
        display: flex;
        width: 100%;
        height: 40px;
    }

    #chatInput {
        height: 40px;
        font-size: 16px;  /* Prevents iOS zoom on focus */
    }

    /* Fix for iOS Safari bottom toolbar */
    .input-container {
        padding-bottom: env(safe-area-inset-bottom, 0);
        position: relative;
        z-index: 10; /* Ensure it's above other elements */
        flex-shrink: 0; /* Prevent it from shrinking */
    }

    /* More space for small screens */
    #voting {
        padding: 10px;
        margin-bottom: 10px;
    }

    #voting h2 {
        font-size: 18px;
        margin: 5px 0 10px 0;
    }

    #voting-images {
        gap: 10px;
        overflow-y: visible;
    }

    .drawing-view {
        margin-bottom: 5px;
    }
}

@media (max-width: 520px) {
    .game-title {
        display: none;
    }
}

@media (max-width: 380px) {
    #gameInfo {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .room-container {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .room-code-text {
        display: none;
    }

    .room-container .icon-btn {
        margin-left: 0;
    }

    #players {
        width: 80px;
        min-width: 80px;
        font-size: 0.8em;
    }

    #players strong {
        margin-bottom: 8px;
    }
}

/* Additional mobile optimizations for extra small screens */
@media (max-width: 380px) {
    /* Make join button smaller on very small screens */
    .join-row .secondary-btn {
        min-width: 80px;
        padding: 10px 8px;
        font-size: 14px;
    }

    /* Make room buttons even smaller on very small screens */
    .room-buttons button {
        font-size: 13px;
        padding: 8px 4px;
        min-width: 0;
    }
    #players {
        width: 80px !important;
        min-width: 80px !important;
        font-size: 0.75em !important;
        padding: 6px !important;
    }

    #players strong {
        margin-bottom: 6px !important;
    }

    #players div {
        margin-bottom: 4px !important;
    }

    #chat {
        font-size: 0.85em !important;
        padding: 5px !important;
    }

    #chat > div {
        margin: 4px 0 !important;
        padding-bottom: 4px !important;
    }

    .system-message {
        padding: 3px 6px !important;
        font-size: 0.8em !important;
    }
}

#toolbar button {
    min-height: 28px;
}

/* Waim game styling */
.game-type-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
    width: 100%;
}

.game-type-selector label {
    font-weight: bold;
    color: #3498db;
}

.game-type-selector select {
    padding: 8px 12px;
    border: 1px solid #444;
    border-radius: 6px;
    background-color: #2a2a2a;
    color: #e0e0e0;
    font-size: 16px;
    flex-grow: 1;
}

#waim-view {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%; /* Fill all available height */
    min-height: 0; /* Important for flex to respect available space */
}

.waim-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
}

.waim-image-container {
    width: 100%;
    background-color: #333;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative; /* Important for absolute positioning of overlay */
    flex: 1;
    min-height: 0; /* Important for flex container to respect the available space */
}

.waim-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    max-height: none; /* Allow image to take full height of container */
}

/* Removed standalone waim-description in favor of overlay */

.waim-inventory {
    background-color: #2a2a2a;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.9em;
    position: relative;
    z-index: 10; /* Ensure inventory appears above the image */
    flex-shrink: 0; /* Don't allow inventory to shrink */
}

.waim-inventory details {
    cursor: pointer;
}

.waim-inventory details[open] {
    position: relative;
}

.waim-inventory details[open] .inventory-items {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background-color: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px 8px 0 0;
    padding: 10px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    max-height: 60vh; /* Allow it to take up to 60% of viewport height */
    overflow-y: auto;
    z-index: 10;
}

.waim-inventory summary {
    font-weight: bold;
    color: #3498db;
    padding: 4px 0;
    position: relative;
    list-style: none; /* Remove default arrow */
    outline: none;
}

.waim-inventory summary::-webkit-details-marker {
    display: none; /* Remove default arrow in WebKit browsers */
}

.waim-inventory summary::after {
    content: '▲'; /* Custom upward arrow */
    font-size: 10px;
    margin-left: 8px;
    transition: transform 0.3s;
    display: inline-block;
    vertical-align: middle;
}

.waim-inventory details[open] summary::after {
    transform: rotate(180deg); /* Flip arrow when open */
}

.inventory-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.inventory-item {
    background-color: #333;
    padding: 4px 8px;
    border-radius: 4px;
    display: inline-block;
    border: 1px solid #444;
}

.empty-inventory {
    font-style: italic;
    opacity: 0.7;
    color: #aaa;
}

.waim-description-overlay {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
    white-space: normal;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0 0 8px 8px;
    pointer-events: none; /* Allow clicking through the overlay */
    font-size: 0.9em;
    line-height: 1.5;
    background: linear-gradient(to bottom,
                               rgba(0,0,0,0) 0%,
                               rgba(0,0,0,0.75) 15%,
                               rgba(0,0,0,0.9) 40%);
    max-height: 100%;
    /* Ensure overlay only covers the image */
    z-index: 5;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

#waim-world-image:hover .waim-description-overlay {
    opacity: 1;
    visibility: visible;
}

.overlay-text-container {
    padding: 18px 20px 22px;
    text-align: center;
    width: 100%;
    max-height: 100%;
    overflow-y: auto;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    box-sizing: border-box; /* Ensure padding is included in width calculation */
}

/* Mobile styles for Waim overlay text */
@media (max-width: 600px) {
    .waim-description-overlay {
        font-size: 0.8em;
    }

    .overlay-text-container {
        padding: 15px 16px 18px;
    }
}

@media (max-width: 380px) {
    .waim-description-overlay {
        font-size: 0.75em;
    }

    .overlay-text-container {
        padding: 12px 14px 16px;
    }
}

#waim-voting {
    width: 100%;
    background: #1e1e1e;
    padding: 15px;
    border: 2px solid #444;
    box-shadow: 0 2px 5px rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
    border-radius: 8px;
}

.waim-action-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.waim-action-item {
    background: #2a2a2a;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.vote-option-container.own-action {
    background-color: #253342; /* Darker blue background for own action */
    box-shadow: 0 2px 10px rgba(52, 152, 219, 0.3);
    border: 1px solid rgba(52, 152, 219, 0.5);
}

.own-action-label {
    margin-left: 5px;
    color: #3498db;
    font-size: 0.8em;
    font-style: italic;
}

.waim-action-item img {
    width: 100%;
    height: 180px;
    object-fit: contain;
    background: #f0f0f0;
    border-radius: 4px;
    position: relative;
}

.waim-action-result {
    font-size: 0.9em;
    line-height: 1.4;
    flex-grow: 1;
    display: none; /* Hide by default, will overlay on hover */
}

.waim-action-item .image-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: 4px;
}

.waim-action-item:hover .waim-action-result {
    display: block;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 18px 16px;
    background: linear-gradient(to bottom,
                               rgba(0,0,0,0) 0%,
                               rgba(0,0,0,0.75) 15%,
                               rgba(0,0,0,0.9) 40%);
    color: white;
    z-index: 5;
    border-radius: 0 0 4px 4px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    text-align: center;
    max-height: 70%;
    overflow-y: auto;
}

.waim-action-button {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    bottom: 0;
    width: 100%;
    margin-top: 10px;
}

.waim-action-button:hover {
    background-color: #2980b9;
}

.waim-action-button.voted {
    background-color: #2ecc71;
}

@media (max-width: 600px) {
    .waim-action-options {
        grid-template-columns: 1fr;
    }

    .waim-action-item .waim-action-result {
        font-size: 0.85em;
        padding: 10px 6px;
    }
}

@media (max-width: 380px) {
    .waim-action-item .waim-action-result {
        font-size: 0.8em;
        padding: 6px 4px;
    }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #1e1e1e;
    padding: 20px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 4px 8px rgba(255, 255, 255, 0.2);
    color: #e0e0e0;
    position: relative;
}

.modal-content h2 {
    margin-top: 0;
    color: #3498db;
}

.modal-content p {
    margin-bottom: 20px;
}

.modal-content input {
    margin: 15px 0;
    background-color: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
}

.modal-content button {
    padding: 10px 15px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.3s;
}

.modal-content button:hover {
    background: #2980b9;
}

/* AI Personality Editor and Selector Styles */
.modal-content.ai-personality-editor,
.modal-content.ai-selector {
    max-width: 700px;
    width: 90vw;
}

.ai-editor-container .form-group {
    margin-bottom: 20px;
}

.ai-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.ai-editor-container h4 {
    margin-top: 0;
    margin-bottom: 0;
    color: #2980b9;
}

.danger-btn {
    background-color: #e74c3c;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
}

.danger-btn:hover {
    background-color: #c0392b;
}

.ai-editor-container textarea {
    width: 100%;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #444;
    background-color: #2a2a2a;
    color: #e0e0e0;
    margin-bottom: 5px;
}

.ai-editor-container .form-hint {
    font-size: 12px;
    color: #999;
    margin-top: 2px;
}

/* AI Personality Selector Styles */
.modal-content.ai-selector.compact {
    max-width: 400px;
    padding: 15px;
    position: relative;
}

@media (max-width: 600px) {
    .modal-content.ai-selector.compact {
        max-width: 90%;
        width: 90%;
        padding: 20px;
    }

    .ai-personality-option {
        padding: 15px;
        margin-bottom: 10px;
    }
}

.ai-personality-list-container {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #444;
    border-radius: 6px;
    margin: 10px 0;
    padding: 5px;
    background-color: #252525;
}

.ai-personality-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.ai-personality-option {
    padding: 12px;
    border-radius: 6px;
    background-color: #2a2a2a;
    cursor: pointer;
    transition: background-color 0.2s;
    border: 1px solid #444;
    text-align: left;
}

.ai-personality-option:hover {
    background-color: #3a3a3a;
    border-color: #555;
}

.ai-option-header {
    margin-bottom: 4px;
}

.ai-option-header strong {
    font-size: 15px;
    color: #3498db;
}

.ai-option-description {
    margin: 0;
    color: #b0b0b0;
    font-size: 13px;
    line-height: 1.3;
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.game-info-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 2px;
    min-height: 20px;
    padding: 0 6px;
    border-radius: 3px;
    background-color: #333;
    box-shadow: 0 1px 2px rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.room-container {
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.room-code-text {
    display: inline-block;
}

.icon-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    touch-action: manipulation;
}

.icon-btn:hover {
    background: #333;
}

.danger-btn {
    background-color: rgba(231, 76, 60, 0.1);
    border: 1px solid rgba(231, 76, 60, 0.5);
}

.danger-btn:hover {
    background-color: rgba(231, 76, 60, 0.3);
}

.icon-btn .icon {
    font-size: 14px;
}

.host-prompt-btn {
    background-color: #2ecc71;
    border: 2px solid #27ae60;
    box-shadow: 0 0 5px rgba(46, 204, 113, 0.5);
}

.host-prompt-btn:hover {
    background-color: #27ae60;
}

/* Styling for top-left AI add button */
#addAIBtn {
    background-color: #2ecc71;
    border: 1px solid #27ae60;
}

#addAIBtn:hover {
    background-color: #27ae60;
}

#viewPromptBtn {
    background-color: #9b59b6;
    border: 1px solid #8e44ad;
}

#viewPromptBtn:hover {
    background-color: #8e44ad;
}

#leaveRoomBtn {
    background-color: rgba(231, 76, 60, 0.2);
    border: 1px solid rgba(231, 76, 60, 0.5);
}

#leaveRoomBtn:hover {
    background-color: rgba(231, 76, 60, 0.4);
}

/* When host-only is shown (for the host) */
.host-only.show {
    display: flex !important;
}

/* Ensure button display properties don't get overridden */
.ai-buttons.show #addAIBtn {
    display: inline-block !important;
}

.ai-player {
    position: relative;
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.remove-ai-btn {
    cursor: pointer;
    opacity: 0; /* Still hidden by default, shown on hover */
    transition: opacity 0.2s;
    display: inline-flex; /* Flex for centering content */
    align-items: center;
    justify-content: center;
    color: #e74c3c; /* Red color */
    font-size: 1em; /* Slightly larger than before (was 0.9em) */
    background-color: rgba(231, 76, 60, 0.1); /* Light red background */
    border-radius: 50%; /* Circular shape */
    width: 18px; /* Increased from 14px */
    height: 18px; /* Increased from 14px */
    line-height: 18px; /* Matches height for vertical centering */
    text-align: center;
    position: absolute;
    right: 0;
    vertical-align: middle; /* Aligns with text baseline */
    flex-shrink: 0; /* Prevent shrinking */
}

/* Show button when hovering over the player div */
.ai-player:hover .remove-ai-btn {
    opacity: 1;
}

/* Hide score when hovering over AI player to make room for the X button */
.ai-player:hover .player-score {
    display: none;
}
.remove-ai-btn:hover {
    background-color: rgba(231, 76, 60, 0.3); /* Darker red on hover */
    color: #fff; /* White text on hover for contrast */
}

/* Prompt view modal styles */
.prompt-view {
    max-width: 600px;
    width: 90%;
    padding: 25px;
    max-height: 90vh;
    overflow-y: auto;
    background: #1e1e1e;
    color: #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(255, 255, 255, 0.1);
    position: relative;
}

.prompt-content {
    background: #2a2a2a;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
    font-family: monospace;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    line-height: 1.5;
}

/* Prompt editor styles */
.prompt-editor {
    max-width: 800px;
    width: 90%;
    padding: 30px;
    max-height: 90vh;
    overflow-y: auto;
    background: #1e1e1e; /* Dark container background */
    color: #e0e0e0; /* Light text */
    border-radius: 12px; /* Match game container */
    box-shadow: 0 5px 20px rgba(255, 255, 255, 0.1); /* Subtle white shadow */
    position: relative;
}

.editor-section {
    margin-bottom: 25px;
    padding: 15px;
    background: #2a2a2a; /* Slightly lighter dark background */
    border-radius: 8px;
    text-align: left;
}

.prompt-help {
    font-size: 0.9em;
    color: #888; /* Gray for secondary text */
    margin-top: 5px;
}

#promptTemplate {
    width: 100%;
    font-family: monospace;
    padding: 10px;
    border: 1px solid #444; /* Dark border */
    border-radius: 4px;
    margin: 10px 0;
    background: #333; /* Dark input background */
    color: #e0e0e0; /* Light text */
}

.editor-controls {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.test-area {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin: 15px 0;
}

.test-canvas-container {
    border: 1px solid #444; /* Dark border */
    padding: 10px;
    background: white; /* Keep white for canvas visibility */
    border-radius: 4px;
}

#testCanvas {
    border: 1px solid #555; /* Slightly lighter dark border */
    background: white; /* Keep white for drawing */
    display: block;
    margin-bottom: 10px;
}

.test-tools {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

.test-input {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-width: 200px;
}

.test-result {
    margin-top: 15px;
    background: #2a2a2a; /* Dark background */
    padding: 15px;
    border-radius: 4px;
    border: 1px solid #444; /* Dark border */
    min-height: 150px;
    color: #e0e0e0; /* Light text */
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    background: none;
    border: none;
    cursor: pointer;
    color: #e0e0e0; /* Light text */
    z-index: 5;
}

.close-btn:hover {
    color: #3498db; /* Blue accent on hover */
}

.loading {
    padding: 20px;
    text-align: center;
    color: #888; /* Gray for loading text */
}

.error {
    padding: 10px;
    color: #e74c3c; /* Red for error */
    background: #3a2a2a; /* Dark red-toned background */
    border-radius: 4px;
}

.test-image {
    max-width: 100%;
    border-radius: 4px;
    border: 1px solid #444; /* Dark border */
}

code {
    background: #333; /* Dark code background */
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
    color: #e0e0e0; /* Light text */
}

/* Global error notification styles */
.error-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    background-color: #e74c3c;
    color: white;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    text-align: center;
    font-weight: bold;
    max-width: 90%;
    animation: fadeInOut 5s ease-in-out forwards;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateX(-50%) translateY(-20px); }
    10% { opacity: 1; transform: translateX(-50%) translateY(0); }
    80% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-20px); }
}

@media (max-width: 600px) {
.test-area {
    flex-direction: column;
}

.prompt-editor {
    padding: 20px;
}
}
