:root {
    --board-size: 95vmin;
    --sidebar-width: 100%;
    --tap-target: 44px;
    --tap-target-small: 36px;
    --piece-scale: 0.75;
    --splat-scale: 0.85;
    --controls-height: 120px;
    --message-height: 2.6em;
}

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

body { 
    font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Arial, sans-serif; 
    background: #eaddcf; 
    color: #3e2723; 
    min-height: 100vh; 
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start; 
    touch-action: manipulation; overflow-y: auto; overflow-x: hidden; padding-bottom: 50px;
}

body.intro-active {
    overflow: auto;
}

body.intro-active #lobby-overlay {
    display: none;
}
body.lobby-open #game-header {
    display: none;
}

body.mode-6p:not(.lobby-open) {
    --board-size: 115vmin;
}

body.modal-open {
    overflow: hidden;
}

body.mode-6p:not(.lobby-open) #board-container {
    margin: 6px auto;
}


/* --- LOBBY STYLES --- */
#lobby-overlay { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background:
        radial-gradient(circle at 15% 10%, rgba(255, 240, 224, 0.08), transparent 55%),
        radial-gradient(circle at 85% 0%, rgba(255, 210, 180, 0.12), transparent 50%),
        linear-gradient(160deg, #2b1a16 0%, #3b241e 55%, #2b1a16 100%);
    z-index: 2000; 
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start; 
    overflow-y: auto; overflow-x: hidden; padding: 20px; pointer-events: none;
    font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", sans-serif;
}

/* --- INTRO --- */
.intro-overlay {
    position: fixed;
    inset: 0;
    background: #ffffff;
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
}
.intro-overlay.is-active {
    display: flex;
}
.intro-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #ffffff;
}
.intro-skip {
    position: absolute;
    right: 20px;
    bottom: 20px;
    padding: 10px 16px;
    border-radius: 999px;
    border: none;
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    min-height: var(--tap-target);
    min-width: var(--tap-target);
}
.intro-skip:hover {
    background: rgba(0, 0, 0, 0.9);
}
.intro-prompt {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    font-size: 0.85em;
    letter-spacing: 1px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.intro-overlay.needs-interaction .intro-prompt {
    opacity: 1;
    pointer-events: auto;
}

.tutorial-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(24, 15, 12, 0.8);
    z-index: 3500;
    padding: 20px;
}
.tutorial-overlay.is-active {
    display: flex;
}
.tutorial-card {
    width: min(92vw, 420px);
    background: rgba(62, 39, 35, 0.98);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 18px;
    padding: 22px;
    text-align: center;
    color: #fff;
    box-shadow: 0 18px 40px rgba(0,0,0,0.45);
}
.tutorial-step {
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.7em;
    color: rgba(215, 204, 200, 0.85);
    margin-bottom: 8px;
}
.tutorial-card h2 {
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 10px;
}
.tutorial-card p {
    color: #d7ccc8;
    font-size: 0.95em;
    margin-bottom: 16px;
}
.tutorial-actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}
.tutorial-actions .modal-btn {
    flex: 1;
}
.tutorial-skip {
    margin-top: 12px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    font-size: 0.8em;
}
.lobby-shell {
    width: min(100%, 1020px);
    display: flex;
    flex-direction: column;
    gap: 18px;
    pointer-events: auto;
}

.lobby-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 0 4px;
}
.lobby-mark {
    font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Arial, sans-serif;
    font-size: clamp(2rem, 4vw, 2.8rem);
    letter-spacing: 5px;
    text-transform: uppercase;
    color: #f5ede5;
}
.lobby-tagline {
    font-size: 0.85em;
    letter-spacing: 4px;
    text-transform: uppercase;
    color: rgba(255, 227, 200, 0.75);
}

.lobby-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    width: 100%;
}
@media (min-width: 900px) {
    .lobby-grid {
        grid-template-columns: 1.15fr 0.85fr;
        grid-template-areas:
            "start rooms"
            "players actions"
            "install install";
    }
    .lobby-start { grid-area: start; }
    .lobby-rooms { grid-area: rooms; }
    .lobby-players { grid-area: players; }
    .lobby-actions { grid-area: actions; }
    .lobby-install { grid-area: install; }
}

.lobby-card {
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 18px;
    padding: 18px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.25);
    color: #f2e7dd;
    text-align: left;
}
.lobby-card-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}
.lobby-card-header h2 {
    font-size: 1.1em;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #f9f4ef;
}
.lobby-card-header p {
    font-size: 0.9em;
    color: rgba(245, 228, 210, 0.8);
}
.lobby-helper,
.lobby-helper-strong,
.lobby-helper-small {
    color: rgba(245, 228, 210, 0.9);
}
.lobby-helper {
    font-size: 0.95em;
    margin-bottom: 12px;
}
.lobby-helper-strong {
    font-size: 1em;
    margin-bottom: 8px;
}
.lobby-helper-small {
    font-size: 0.85em;
    margin-top: 10px;
    color: rgba(245, 228, 210, 0.65);
}
.lobby-action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}
.lobby-history .btn-base {
    width: 100%;
    max-width: 100%;
    margin: 6px 0;
    background: #5d4037;
    color: #fff;
}
.history-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
    color: rgba(245, 228, 210, 0.85);
    font-size: 0.9em;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.history-toggle-icon {
    font-size: 1.2em;
    transition: transform 0.2s ease;
}
.history-toggle.is-open .history-toggle-icon {
    transform: rotate(45deg);
}
.history-panel {
    display: none;
    margin-top: 12px;
}
.history-panel.active {
    display: block;
}
.lobby-join,
.lobby-identity {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.lobby-join button,
.lobby-action-buttons button {
    width: 100%;
}
#lobby-msg {
    margin-bottom: 12px;
    font-style: italic;
    color: rgba(245, 228, 210, 0.75);
}
.lobby-install .lobby-card-header h2 {
    font-size: 0.95em;
}
.lobby-install .lobby-card-header p {
    font-size: 0.85em;
    color: rgba(245, 228, 210, 0.65);
}
.install-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.03);
    color: rgba(245, 228, 210, 0.85);
    font-size: 0.9em;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.install-toggle-icon {
    font-size: 1.2em;
    transition: transform 0.2s ease;
}
.install-toggle.is-open .install-toggle-icon {
    transform: rotate(45deg);
}
.install-panel {
    display: none;
    margin-top: 12px;
}
.install-panel.active {
    display: block;
}
.install-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.install-label {
    font-size: 0.8em;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(245, 228, 210, 0.6);
    margin-bottom: 2px;
}
.install-text {
    font-size: 0.9em;
    color: rgba(245, 228, 210, 0.85);
}
.lobby-fineprint {
    text-align: center;
    font-size: 0.75em;
    color: rgba(245, 228, 210, 0.6);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin: 8px 0 4px;
}
.lobby-fineprint a {
    color: rgba(245, 228, 210, 0.8);
    text-decoration: none;
}
.lobby-fineprint a:hover {
    text-decoration: underline;
}

/* LOBBY SECTIONS */
.lobby-section {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 15px;
    text-align: center;
    width: 100%;
    opacity: 0;
    transform: translateY(8px) scale(0.98);
    animation: lobbyRise 0.35s ease forwards;
}
.lobby-section:nth-child(1) { animation-delay: 0ms; }
.lobby-section:nth-child(2) { animation-delay: 60ms; }
.lobby-section:nth-child(3) { animation-delay: 120ms; }
.lobby-section:nth-child(4) { animation-delay: 180ms; }
.lobby-section:nth-child(5) { animation-delay: 240ms; }

@keyframes lobbyRise {
    0% { opacity: 0; transform: translateY(10px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Section 1: Header */
.ls-header {
    background: transparent;
    border: none;
    padding: 10px 0;
}
.ls-header h1 {
    color: white; 
    font-size: 2em; 
    margin: 0; 
    text-transform: uppercase; 
    letter-spacing: 2px;
}
.ls-rooms {
    padding: 10px 12px;
}
.rooms-toggle {
    width: 100%;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.25);
    color: #fff;
    padding: 12px 16px;
    border-radius: 14px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}
.rooms-toggle-icon {
    font-size: 1.2em;
    transition: transform 0.2s ease;
}
.rooms-panel {
    margin-top: 10px;
    display: none;
}
.rooms-panel.active {
    display: block;
}
.rooms-toggle.is-open .rooms-toggle-icon {
    transform: rotate(45deg);
}
.room-controls {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
}
.room-label {
    color: #d7ccc8;
    font-size: 0.85em;
    letter-spacing: 1px;
    text-transform: uppercase;
}
#room-input {
    width: 160px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(0,0,0,0.2);
    color: #fff;
    text-align: center;
    text-transform: lowercase;
}
#room-input::placeholder { color: rgba(255,255,255,0.5); }
.room-controls button {
    padding: 9px 12px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    letter-spacing: 0.5px;
    background: #6d4c41;
    color: #fff;
    min-height: var(--tap-target);
    min-width: var(--tap-target);
}
.room-controls button:hover { background: #8d6e63; }
.room-list {
    margin-top: 12px;
    background: rgba(0,0,0,0.18);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 10px;
    text-align: left;
    color: #fff;
}
.room-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9em;
    color: #d7ccc8;
    text-transform: uppercase;
    letter-spacing: 1px;
}
#room-refresh-btn {
    padding: 6px 10px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    background: #2e7d32;
    color: #fff;
    min-height: var(--tap-target);
    min-width: var(--tap-target);
}
#room-list-body {
    display: grid;
    gap: 6px;
    font-size: 0.9em;
    color: #f5f5f5;
}
#room-refresh-hint {
    margin-bottom: 6px;
    font-size: 0.8em;
    color: rgba(255,255,255,0.7);
}
.room-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(0,0,0,0.2);
}
.room-list-item button {
    padding: 4px 8px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    background: #0277bd;
    color: #fff;
    min-height: var(--tap-target);
    min-width: var(--tap-target);
}

.room-name-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 12, 10, 0.7);
    z-index: 2100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
}
.room-name-modal.active {
    opacity: 1;
    pointer-events: all;
}
.room-name-card {
    width: min(90vw, 420px);
    background: rgba(62, 39, 35, 0.98);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 18px;
    padding: 22px;
    text-align: center;
    color: #fff;
    box-shadow: 0 18px 40px rgba(0,0,0,0.45);
}
.room-name-card h2 {
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 6px;
}
.room-name-subtitle {
    color: #d7ccc8;
    font-size: 0.9em;
    margin-bottom: 14px;
}
#room-name-input {
    width: 80%;
    padding: 10px 12px;
    border-radius: 10px;
    border: none;
    text-align: center;
    text-transform: lowercase;
    font-size: 1.1em;
}
.room-name-actions {
    margin-top: 16px;
}

.confirm-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 12, 10, 0.72);
    z-index: 2100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
}
.confirm-modal.active {
    opacity: 1;
    pointer-events: all;
}
.confirm-card {
    width: min(90vw, 380px);
    background: rgba(62, 39, 35, 0.98);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 18px;
    padding: 20px;
    text-align: center;
    color: #fff;
    box-shadow: 0 18px 40px rgba(0,0,0,0.45);
}
.confirm-card h2 {
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 8px;
}
.confirm-message {
    color: #d7ccc8;
    font-size: 0.95em;
    margin-bottom: 14px;
}
.confirm-actions {
    margin-top: 10px;
}

/* Section 2: Identity (Round inputs) */
.ls-identity { }

/* Section 3: Game State (Square slots + Modes) */
.ls-state { }

/* Section 4: Actions (Centered) */
.ls-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(46, 125, 50, 0.2); /* Slight green tint for action area */
    border: 1px solid rgba(46, 125, 50, 0.4);
}

/* Inputs & Color Grid */
#name-input { 
    width: min(70%, 240px);
    padding: 10px;
    margin: 10px 0;
    text-align: center;
    font-size: 1.4em;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(0,0,0,0.25);
    color: #fff;
    text-transform: uppercase;
}
#name-input:disabled { background: #ddd; color: #555; }

.color-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 10px; }
.color-btn { 
    width: 45px; height: 45px; border-radius: 50%; 
    border: 3px solid rgba(255,255,255,0.2); 
    cursor: pointer; transition: transform 0.2s; 
}
.color-btn:hover:not(:disabled) { transform: scale(1.1); border-color: white; }
.color-btn.selected { transform: scale(1.2); border-color: white; box-shadow: 0 0 10px gold; z-index: 2; }
.color-btn:disabled { opacity: 0.3; cursor: not-allowed; filter: grayscale(80%); }

/* Tracker Slots (SQUARES) */
#ready-tracker { 
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin: 15px 0 25px 0; /* Extra bottom margin for bot buttons */
    width: 100%;
    justify-items: center;
}
.tracker-slot { 
    width: 50px; height: 50px; 
    border-radius: 8px; /* Square with rounded corners */
    border: 2px dashed rgba(255,255,255,0.3); 
    display: flex; align-items: center; justify-content: center; 
    font-size: 1.2em; color: white; 
    position: relative; 
    transition: all 0.3s;
}

.tracker-slot.ghost-slot {
    opacity: 0.35;
    border-style: dashed;
    background: transparent;
    box-shadow: none;
}

.tracker-upcoming {
    grid-column: span 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    position: relative;
    width: 100%;
    justify-items: center;
}

.tracker-upcoming-banner {
    position: absolute;
    bottom: -16px;
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 8px;
    font-size: 0.6em;
    letter-spacing: 1px;
    text-transform: uppercase;
    background: rgba(93, 64, 55, 0.7);
    color: #f5f5f5;
    border-radius: 999px;
    border: 1px dashed rgba(255,255,255,0.5);
    white-space: nowrap;
}
.tracker-slot.joined { border-style: solid; opacity: 0.8; }
.tracker-slot.ready { opacity: 1; box-shadow: 0 0 10px white; border-color: white; font-weight: bold; }
.tracker-slot.light-bg { color: #3e2723; }
.tracker-slot.light-bg.ready { box-shadow: 0 0 10px rgba(62, 39, 35, 0.6); border-color: #5d4037; }

.kick-btn { 
    position: absolute; top: -8px; right: -8px; 
    background: #c62828; color: white; border-radius: 50%; 
    width: 20px; height: 20px; font-size: 12px; 
    border: 2px solid white; cursor: pointer; 
    display: flex; align-items: center; justify-content: center; 
    font-weight: bold; z-index: 10; 
}

.add-bot-btn { 
    position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); 
    background: #2e7d32; color: white; border-radius: 4px; 
    font-size: 10px; padding: 3px 6px; cursor: pointer; 
    border: none; white-space: nowrap; z-index: 10; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Mode Buttons */
#mode-selector {
    display: flex; justify-content: center; gap: 5px; width: 100%; margin-top: 10px;
}
.mode-btn {
    width: 0; opacity: 0; padding: 0; margin: 0; font-size: 0;
    overflow: hidden; border: none; color: white; border-radius: 8px;
    cursor: pointer; white-space: nowrap;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.mode-btn.visible {
    width: 32%; min-width: 80px; opacity: 1; padding: 12px 5px; font-size: 0.85em; font-weight: bold;
}

/* Action Buttons */
#ready-btn, #start-btn, #claim-host-btn, #join-btn {
    width: 100%; max-width: 360px; margin: 8px 0; padding: 14px; 
    font-size: 1.1em; font-weight: bold; color: white; border: none; 
    border-radius: 50px; cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    min-height: var(--tap-target);
}
#ready-btn { background: #0277bd; }
#start-btn { background: #ff6f00; opacity: 0.5; pointer-events: none; }
#start-btn.ready { opacity: 1; pointer-events: all; }
#join-btn { background: #2e7d32; }
#claim-host-btn { background: #7b1fa2; font-size: 1em; padding: 10px; }

/* --- GAME UI STYLES (Unchanged logic, kept distinct) --- */
#game-header { 
    position: relative; width: 100%; padding: 10px 15px; 
    text-align: center; font-weight: 900; font-size: 1.3em; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.1); z-index: 4000; transition: all 0.3s; 
    border-bottom: 2px solid rgba(0,0,0,0.1); background: #d7ccc8; color: #3e2723;
    display: flex; justify-content: space-between; align-items: center;
    flex-shrink: 0; text-transform: uppercase; pointer-events: auto;
}

#game-area {
    display: flex; flex-direction: column; align-items: center;
    width: 100%; max-width: 100%; flex-grow: 1;
}

#board-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
}

#sidebar {
    display: flex; flex-direction: column; align-items: center;
    width: var(--sidebar-width); margin-bottom: 10px; transition: all 0.3s ease;
}

@media (min-aspect-ratio: 1.2/1) {
    :root { --board-size: 80vh; --controls-height: 110px; --message-height: 2.4em; }
    body.mode-6p:not(.lobby-open) { --board-size: 88vh; }
    body { justify-content: center; padding-bottom: 0; overflow: hidden; }
    #game-area { flex-direction: row; justify-content: center; align-items: center; gap: 40px; height: calc(100vh - 60px); }
    #sidebar { width: 350px; order: 2; margin-bottom: 0; background: rgba(255,255,255,0.2); padding: 20px; border-radius: 15px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
    #board-stack { order: 1; width: auto; }
    #board-container { margin: 0 !important; }
}

#menu-btn { font-size: 1.2em; cursor: pointer; text-shadow: 0 1px 2px rgba(0,0,0,0.2); transition: transform 0.2s; user-select: none; pointer-events: auto; }
#menu-btn { background: transparent; border: none; padding: 6px 10px; border-radius: 999px; line-height: 1; color: inherit; }
.header-spacer { display: inline-block; width: 32px; }
.header-actions { display: inline-flex; gap: 6px; align-items: center; }
.menu-btn { display: inline-flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; min-width: 32px; }
.menu-line { width: 18px; height: 2px; background: currentColor; border-radius: 2px; display: block; }
#menu-btn:focus-visible { outline: 2px solid #5d4037; outline-offset: 2px; }
#menu-btn:hover { transform: scale(1.05); }

#main-menu { position: absolute; top: 100%; background: rgba(234, 221, 207, 0.9); padding: 15px; border-radius: 0 0 10px 10px; box-shadow: 0 6px 16px rgba(0,0,0,0.25); z-index: 2600; border: 2px solid #5d4037; border-top: none; width: 200px; text-align: left; right: 10px; opacity: 0; transform: translateY(6px); visibility: hidden; pointer-events: none; transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#main-menu.is-open { opacity: 1; transform: translateY(0); visibility: visible; pointer-events: auto; transition: opacity 0.18s ease, transform 0.18s ease; }
#main-menu button { background: #a1887f; color: white; border: none; padding: 10px 20px; border-radius: 5px; font-weight: bold; cursor: pointer; font-size: 0.9em; width: 100%; margin-bottom: 10px; }
#menu-stats { background: #5d4037 !important; }
#menu-restart { background: #c62828 !important; }

#stats-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 6000; display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 0.2s ease, visibility 0s linear 0.2s; }
#stats-overlay.is-open { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity 0.2s ease; }
.modal-content { background: #eaddcf; padding: 25px; border-radius: 15px; max-width: 90%; width: 400px; text-align: center; border: 4px solid #5d4037; color: #3e2723; pointer-events: auto; opacity: 0; transform: translateY(8px) scale(0.98); transition: transform 0.25s ease, opacity 0.25s ease; }
#stats-overlay.is-open .modal-content { opacity: 1; transform: translateY(0) scale(1); }
.stats-table { width: 100%; margin-top: 15px; border-collapse: collapse; }
.stats-table td, .stats-table th { padding: 8px; border-bottom: 1px solid #a1887f; }
.highlight-stat { font-weight: bold; color: #c62828; margin-top: 10px; }

.status { display: flex; justify-content: center; flex-wrap: wrap; width: 95%; max-width: 600px; margin-bottom: 10px; background: rgba(255,255,255,0.4); border-radius: 10px; padding: 5px; border: 1px solid rgba(93, 64, 55, 0.2); gap: 5px; }
.player-status { text-align: center; padding: 5px; border-radius: 8px; transition: all 0.3s; min-width: 55px; position: relative; border: 2px solid transparent; font-size: 0.8em; background-color: rgba(255,255,255,0.2); color: #5d4037; border: 1px dashed rgba(93, 64, 55, 0.3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-status.active { transform: scale(1.1); z-index: 10; box-shadow: 0 4px 8px rgba(0,0,0,0.2); border-style: solid; border-width: 2px; border-color: rgba(0,0,0,0.5); }
.player-status.finished { opacity: 0.9; filter: grayscale(10%); }
.player-status.empty-slot { text-decoration: line-through; opacity: 0.5; }
.player-status strong { display: block; font-size: 1.2em; }

#controls { margin-bottom: 10px; width: 95%; min-height: 80px; height: var(--controls-height); display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 20px; background: rgba(0,0,0,0.05); padding: 10px; border-radius: 15px; }
#message {
    text-align: center;
    font-weight: bold;
    color: #5d4037;
    margin-top: 5px;
    min-height: var(--message-height);
    height: var(--message-height);
    line-height: 1.3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    overflow: hidden;
}
.turn-alert-banner {
    width: 95%;
    margin-top: 8px;
    background: rgba(255, 236, 179, 0.9);
    border: 1px solid rgba(141, 110, 99, 0.6);
    border-radius: 14px;
    padding: 10px 12px;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: #3e2723;
    font-size: 0.9em;
}
.turn-alert-banner.is-visible {
    display: flex;
}
.turn-alert-text {
    line-height: 1.3;
}
.turn-alert-dismiss {
    border: none;
    border-radius: 999px;
    padding: 6px 12px;
    background: #5d4037;
    color: #fff;
    font-weight: bold;
    cursor: pointer;
    min-height: var(--tap-target-small);
}
#dice { font-size: 5em; cursor: pointer; color: #3e2723; width: auto; height: auto; line-height: 1.2; text-align: center; display: flex; align-items: center; justify-content: center; gap: 8px; }
#dice .die-btn,
#dice .sum-btn {
    border: none;
    border-radius: 14px;
    padding: 4px 10px;
    background: rgba(255,255,255,0.9);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    font-size: 0.7em;
    line-height: 1;
    cursor: pointer;
}
#dice .die-btn.is-used {
    opacity: 0.35;
    cursor: default;
}
#dice .die-btn.is-selected,
#dice .sum-btn.is-selected {
    background: #ffca28;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
#dice .sum-btn {
    font-size: 0.4em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

body.mode-6p #dice {
    font-size: 3.2em;
}
#dice.rolling { animation: roll 0.6s ease-in-out; }
@keyframes roll { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.btn-base { display: block; flex-grow: 1; max-width: 250px; padding: 15px; font-size: 1.2em; font-weight: bold; color: white; border: none; border-radius: 50px; cursor: pointer; transition: all 0.2s; box-shadow: 0 4px 6px rgba(0,0,0,0.2); }
#roll-btn { background: #a1887f; cursor: not-allowed; }
#roll-btn.my-turn { background: #2e7d32; cursor: pointer; animation: pulse 1.5s infinite; }
#roll-btn.game-over { background: #d32f2f; cursor: pointer; animation: none; }

#board-container { position: relative; margin: 10px auto; border: 8px solid #5d4037; background: #eaddcf; overflow: hidden; transition: transform 1.5s cubic-bezier(0.25, 1, 0.5, 1); width: var(--board-size); height: var(--board-size); }
#board { display: grid; gap: 0; width: 100%; height: 100%; background: transparent; padding: 1px; position: relative; z-index: 1; }
#board-container::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse at center, rgba(0,0,0,0) 60%, rgba(0,0,0,0.08) 100%),
        repeating-linear-gradient(0deg, rgba(255,255,255,0.03) 0, rgba(255,255,255,0.03) 1px, rgba(0,0,0,0.03) 1px, rgba(0,0,0,0.03) 2px);
    background-size: cover, 3px 3px;
    opacity: 0.35;
}
.cell { background: transparent; position: relative; border-radius: 2px; }
.track { background: #5d4037; border: 1px solid #4e342e; } 
.shortcut { background: #009688; border: 2px solid #004d40; }
.work, .home { background: #8d6e63; border: 1px solid #5d4037; opacity: 0.8; }

.marble { width: calc(100% / var(--grid-cols, 17) * var(--piece-scale, 0.75)); height: auto; aspect-ratio: 1 / 1; border-radius: 50%; position: absolute; z-index: 20; box-shadow: 0 3px 5px rgba(0,0,0,0.4), inset 0 2px 3px rgba(255,255,255,0.6); border: 2px solid rgba(255,255,255,0.8); transition: top 0.5s cubic-bezier(0.25, 1, 0.5, 1), left 0.5s cubic-bezier(0.25, 1, 0.5, 1), transform 0.3s; }
.marble::after { content: ''; position: absolute; top: -75%; left: -75%; width: 250%; height: 250%; border-radius: 50%; background: transparent; z-index: 21; }
.marble[data-color="#ffffff"] { border: 2px solid #999; }
.marble.movable { z-index: 100; cursor: pointer; filter: drop-shadow(0 0 5px gold); }
.marble.movable::after {  border: 2px solid rgba(255,255,255,0.5); opacity: 0; animation: ringPulse 1.5s infinite; }
@keyframes ringPulse { 0% { transform: scale(0.4); opacity: 1; } 100% { transform: scale(1.0); opacity: 0; } }

.ghost-marble { width: calc(100% / var(--grid-cols, 17) * var(--piece-scale, 0.75)); height: auto; aspect-ratio: 1 / 1; border-radius: 50%; position: absolute; z-index: 15; opacity: 0.5; border: 2px dashed rgba(255,255,255,0.8); pointer-events: none; transition: all 0.2s; animation: ghostPulse 1s infinite alternate; }
@keyframes ghostPulse { 0% { transform: scale(0.9); opacity: 0.4; } 100% { transform: scale(1.0); opacity: 0.7; } }
.splat { position: absolute; width: calc(100% / var(--grid-cols, 17) * var(--splat-scale, 0.85)); height: auto; aspect-ratio: 1 / 1; border-radius: 50%; z-index: 10; pointer-events: none; clip-path: polygon(20% 0%, 30% 20%, 50% 0%, 60% 25%, 90% 5%, 80% 40%, 100% 50%, 80% 60%, 95% 85%, 60% 75%, 50% 100%, 40% 75%, 10% 90%, 25% 60%, 0% 50%, 25% 40%); animation: fadeSplat 2s forwards; }
@keyframes fadeSplat { 0% { opacity: 1; transform: scale(0); } 10% { transform: scale(1.5) rotate(10deg); } 100% { opacity: 0; transform: scale(1.5) rotate(20deg); } }

#emoji-bar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.4);
    border: 1px solid rgba(93, 64, 55, 0.2);
    border-radius: 18px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    width: max-content;
    max-width: 100%;
}

#emoji-slot-board,
#emoji-slot-sidebar {
    display: flex;
    justify-content: center;
    width: 100%;
}

#emoji-slot-sidebar {
    margin-top: 10px;
}

.emoji-btn {
    width: var(--tap-target);
    height: var(--tap-target);
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.8);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 2px 2px rgba(255,255,255,0.7), 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.emoji-btn:active {
    transform: scale(0.92);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.25);
}

#emoji-stream {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1200;
    overflow: hidden;
}

.emoji-float {
    position: absolute;
    font-size: 28px;
    transform: translate(0, 0) scale(0.9);
    opacity: 1;
    animation: emojiFloat var(--emoji-duration, 1800ms) ease-out forwards;
    will-change: transform, opacity;
}

@keyframes emojiFloat {
    0% { transform: translate(0, 0) scale(0.9); opacity: 1; }
    80% { opacity: 0.85; }
    100% { transform: translate(var(--emoji-drift, 0px), calc(var(--emoji-rise, 160px) * -1)) scale(1.2); opacity: 0; }
}

#shortcut-modal { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0); width: 80%; max-width: 300px; background: rgba(62, 39, 35, 0.95); border: 2px solid #d7ccc8; border-radius: 15px; padding: 20px; text-align: center; z-index: 500; box-shadow: 0 0 20px rgba(0,0,0,0.5); transition: transform 0.3s; pointer-events: none; opacity: 0; color: white; }
#shortcut-modal.active { transform: translate(-50%, -50%) scale(1); pointer-events: all; opacity: 1; }
.shortcut-target-options { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
#shortcut-target-modal { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0); width: 85%; max-width: 320px; background: rgba(62, 39, 35, 0.95); border: 2px solid #d7ccc8; border-radius: 15px; padding: 20px; text-align: center; z-index: 520; box-shadow: 0 0 20px rgba(0,0,0,0.5); transition: transform 0.3s; pointer-events: none; opacity: 0; color: white; }
#shortcut-target-modal.active { transform: translate(-50%, -50%) scale(1); pointer-events: all; opacity: 1; }
.modal-btn { padding: 10px 20px; border: none; border-radius: 5px; font-weight: bold; cursor: pointer; margin: 5px; font-size: 1.1em; }
.btn-yes { background: #2e7d32; color: white; }
.btn-no { background: #c62828; color: white; }

@media (max-width: 600px) {
    :root {
        --board-size: 98vmin;
        --piece-scale: 0.9;
        --splat-scale: 0.95;
        --controls-height: 130px;
        --message-height: 3em;
    }

    #menu-btn {
        min-width: var(--tap-target);
        min-height: var(--tap-target);
        padding: 8px 12px;
    }

    .menu-btn {
        min-width: var(--tap-target);
        min-height: var(--tap-target);
    }

    #main-menu button,
    .modal-btn {
        min-height: var(--tap-target);
    }

    .mode-btn.visible {
        min-height: var(--tap-target);
        padding: 12px 8px;
    }

    #ready-tracker {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 8px;
    }

    .tracker-slot {
        width: min(46px, 18vw);
        height: auto;
        aspect-ratio: 1 / 1;
    }

    .tracker-upcoming {
        gap: 8px;
    }

    .tracker-upcoming-banner {
        bottom: -14px;
        font-size: 0.55em;
    }

    .marble::after {
        width: 320%;
        height: 320%;
        top: -110%;
        left: -110%;
    }

    .kick-btn {
        width: var(--tap-target-small);
        height: var(--tap-target-small);
        font-size: 14px;
        top: -10px;
        right: -10px;
    }

    .add-bot-btn {
        font-size: 12px;
        padding: 6px 10px;
        bottom: -30px;
        min-height: var(--tap-target-small);
    }
}

#target-pop { position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%) scale(0); background: rgba(198, 40, 40, 0.95); color: white; padding: 30px; border-radius: 50px; font-size: 2em; font-weight: 900; text-transform: uppercase; box-shadow: 0 10px 30px rgba(0,0,0,0.3); z-index: 1000; text-shadow: 0 2px 5px rgba(0,0,0,0.4); pointer-events: none; transition: transform 0.4s; text-align: center; border: 4px solid white; }
#target-pop.active { transform: translate(-50%, -50%) scale(1); animation: shake 0.5s infinite; }
#target-pop span { display: block; font-size: 0.5em; font-weight: normal; margin-top: 5px; opacity: 0.9; }

#lightning-pop { position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%) scale(0); background: rgba(255, 179, 0, 0.95); color: #3e2723; padding: 30px; border-radius: 50px; font-size: 2em; font-weight: 900; text-transform: uppercase; box-shadow: 0 10px 30px rgba(0,0,0,0.3); z-index: 1001; text-shadow: 0 2px 5px rgba(0,0,0,0.2); pointer-events: none; transition: transform 0.4s; text-align: center; border: 4px solid white; }
#lightning-pop.active { transform: translate(-50%, -50%) scale(1); animation: shake 0.5s infinite; }
@keyframes shake { 0%, 100% { transform: translate(-50%, -50%) rotate(0deg); } 25% { transform: translate(-50%, -50%) rotate(-5deg); } 75% { transform: translate(-50%, -50%) rotate(5deg); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(46, 125, 50, 0.7); } 70% { box-shadow: 0 0 0 15px rgba(46, 125, 50, 0); } 100% { box-shadow: 0 0 0 0 rgba(46, 125, 50, 0); } }

@media (prefers-reduced-motion: reduce) {
    .lobby-section {
        animation: none;
        opacity: 1;
        transform: none;
    }

    #main-menu,
    #stats-overlay,
    .modal-content {
        transition: none;
    }
}
