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

body {
    background: #c0c0c0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    overflow: hidden;
    touch-action: manipulation;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
}

#header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 12px 0 4px;
    position: relative;
}

#header-text {
    text-align: center;
}

#title {
    font-family: 'Press Start 2P', cursive;
    font-size: 22px;
    font-weight: 400;
    color: #333;
    letter-spacing: 0;
    line-height: 1.4;
}

#subtitle {
    font-family: 'Press Start 2P', cursive;
    font-size: 8px;
    color: #666;
    margin-top: 6px;
    line-height: 1.4;
}

#luba-face {
    width: 92px;
    height: auto;
    transform: rotate(-20deg);
    margin-left: -20px;
    margin-right: -16px;
    margin-top: -8px;
    z-index: 1;
}

#menu-bar {
    display: flex;
    gap: 0;
    background: #e0e0e0;
    border: 1px solid #999;
    border-radius: 4px;
    overflow: hidden;
    margin: 6px 0;
}

.menu-item {
    padding: 6px 16px;
    font-size: 14px;
    cursor: pointer;
    color: #333;
}

.menu-item:active {
    background: #ccc;
}

.dropdown {
    position: absolute;
    background: #f0f0f0;
    border: 1px solid #999;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
    min-width: 180px;
    overflow: hidden;
}

.dropdown.hidden {
    display: none;
}

.dropdown-item {
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dropdown-item:active {
    background: #d0d0d0;
}

.dropdown-separator {
    height: 1px;
    background: #ccc;
    margin: 2px 0;
}

.check {
    width: 16px;
    display: inline-block;
    text-align: center;
    font-weight: bold;
}

/* Status bar */
#status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #c0c0c0;
    border: 2px inset #999;
    padding: 6px 8px;
    width: fit-content;
    gap: 8px;
    border-radius: 2px;
}

#face-button {
    cursor: pointer;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#flag-display, #time-display {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: #000;
}

/* Field */
#field-wrapper {
    border: 3px inset #999;
    margin: 4px 0;
    border-radius: 2px;
    overflow: auto;
    max-width: 100vw;
    max-height: calc(100vh - 220px);
    max-height: calc(100dvh - 220px);
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}

#field {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
}

#touch-hint {
    font-size: 11px;
    color: #888;
    padding: 4px 0 8px;
}

/* Modal */
#modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

#modal-overlay.hidden {
    display: none;
}

#modal {
    background: #e8e8e8;
    border: 1px solid #999;
    border-radius: 8px;
    padding: 20px;
    min-width: 260px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

#modal-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
    color: #333;
}

#modal-content {
    font-size: 14px;
    color: #444;
    margin-bottom: 16px;
    line-height: 1.6;
}

#modal-content input[type="number"],
#modal-content input[type="text"] {
    width: 100%;
    padding: 6px 8px;
    margin: 4px 0;
    border: 1px solid #aaa;
    border-radius: 4px;
    font-size: 14px;
    background: #fff;
    -webkit-user-select: text;
    user-select: text;
}

#modal-content label {
    display: block;
    margin-top: 8px;
    font-size: 13px;
    color: #555;
}

#modal-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

#modal-buttons button {
    padding: 8px 20px;
    border: 1px solid #999;
    border-radius: 4px;
    background: #d0d0d0;
    font-size: 14px;
    cursor: pointer;
    color: #333;
}

#modal-buttons button:active {
    background: #bbb;
}

#modal-buttons button.primary {
    background: #4a90d9;
    color: #fff;
    border-color: #3a7bc8;
}

/* Install banner */
#install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #333;
    color: #fff;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    z-index: 300;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

#install-banner.hidden {
    display: none;
}

#install-banner button {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
}

/* Mobile adjustments for luba-face (title wraps to 2 lines) */
@media (max-width: 499px) {
    #luba-face {
        margin-left: -30px;
        margin-top: -20px;
    }
}

/* Scale adjustments for larger screens */
@media (min-width: 500px) {
    #title { font-size: 26px; }
    #subtitle { font-size: 10px; }
    #luba-face { width: 108px; }
}

/* ── Co-op UI ─────────────────────────────────────────────── */

#room-code-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: #ddeeff;
    border: 1px solid #99aacc;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    letter-spacing: 0.5px;
    margin: 2px 0;
}

#room-code-banner.hidden { display: none; }

#room-code-text {
    font-weight: bold;
    color: #334;
}

#room-code-copy {
    font-size: 11px;
    padding: 2px 8px;
    cursor: pointer;
    border: 1px solid #99aacc;
    border-radius: 3px;
    background: #c8ddf8;
    color: #334;
}

#room-code-copy:active { background: #a8bde0; }

#player-strip {
    display: flex;
    gap: 10px;
    padding: 4px 10px;
    background: #d8d8d8;
    border: 1px inset #aaa;
    border-radius: 2px;
    flex-wrap: wrap;
    justify-content: center;
    font-size: 11px;
    width: fit-content;
    max-width: 100%;
    margin: 2px 0;
}

#player-strip.hidden { display: none; }

.player-entry { display: inline-flex; gap: 4px; align-items: center; color: #333; }
.player-score { color: #006; font-weight: bold; }

#coop-toast {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.72);
    color: #fff;
    padding: 7px 16px;
    border-radius: 20px;
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 400;
    white-space: nowrap;
}

#coop-toast.visible { opacity: 1; }
