/* --- Global Styles, Themes & Unlocks --- */
:root { --domino-width: 40px; --domino-height: 80px; --highlight-yellow: #FFC700; }
body.theme-green { --brand-bg: #006400; --board-bg: #004d00; --text-color: white; }
body.theme-dark { --brand-bg: #1a1a1a; --board-bg: #0d0d0d; --text-color: #e0e0e0; }
body.theme-wood { --brand-bg: #5c4033; --board-bg: #3e2723; --text-color: #ffecd2; }
body.theme-space { --brand-bg: #222; --board-bg: #111; --text-color: #e0e0e0; background-image: url('space-bg.jpg'); background-size: cover; background-position: center;}
body.theme-ocean { --brand-bg: #003366; --board-bg: #001f3f; --text-color: #a0c0e0; background-image: url('ocean-bg.jpg'); background-size: cover; background-position: center;}
body.theme-desert { --brand-bg: #c2b280; --board-bg: #8b7d54; --text-color: #3b2f2f; background-image: linear-gradient(to bottom, #d2b48c, #a0522d); }
body.theme-lava { --brand-bg: #3a0000; --board-bg: #1a0000; --text-color: #ffaa00; background-image: radial-gradient(circle, #8b0000 0%, #2a0000 100%); }
body.theme-cyber { --brand-bg: #000b18; --board-bg: #00040a; --text-color: #00ffcc; background-image: repeating-linear-gradient(0deg, #000b18, #000b18 2px, #001229 2px, #001229 4px); }
body.theme-synth { --brand-bg: #2b003e; --board-bg: #150020; --text-color: #0ff; background-image: linear-gradient(to bottom, #2b003e 0%, #ff007f 100%); }
body.theme-clouds { --brand-bg: #87CEEB; --board-bg: #E0F7FA; --text-color: #0277BD; background-image: linear-gradient(to bottom, #87CEEB, #ffffff); }

/* Domino Color Classes */
.domino.color-white { background-color: #fff; color: #000; border-color: #000; } 
.domino.color-blue { background-color: #d0e8ff; color: #002244; border-color: #002244; }
.domino.color-red { background-color: #ffd0d0; color: #440000; border-color: #440000; }
.domino.color-gold { background-color: #ffd700; border-color: #b8860b; color: #5c4033; }
.domino.color-purple { background-color: #e0b0ff; color: #330066; border-color: #330066; }
.domino.color-silver { background-color: #e0e0e0; color: #444444; border-color: #444444; }
.domino.color-green { background-color: #c8e6c9; color: #1b5e20; border-color: #1b5e20; }
.domino.color-orange { background-color: #ffe0b2; color: #e65100; border-color: #e65100; }
.domino.color-pink { background-color: #f8bbd0; color: #880e4f; border-color: #880e4f; }
.domino.color-cyan { background-color: #e0ffff; color: #008b8b; border-color: #008b8b; }
.domino.color-black { background-color: #222; color: #fff; border-color: #000; }
.domino.color-rainbow { background-image: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #a1c4fd 100%); color: #333; border-color: #ff6b6b; background-color: #fecfef; }
.domino .pip { background-color: currentColor; }

/* Domino Back Patterns */
.domino.face-down { background-image: none !important; background-color: #555 !important; border-color: #222 !important; } 
.domino.face-down .pip-container { visibility: hidden !important; opacity: 0 !important; }

.domino.face-down.pattern-stripes { background-image: repeating-linear-gradient(45deg, #777, #777 10px, #555 10px, #555 20px) !important; border-color: #444 !important; }
.domino.face-down.pattern-dots { background-image: radial-gradient(circle at 10px 10px, #777 5px, transparent 5px), radial-gradient(circle at 30px 30px, #777 5px, transparent 5px) !important; background-size: 40px 40px !important; border-color: #444 !important; }
.domino.face-down.pattern-diamond { background-image: linear-gradient(45deg, #777 25%, transparent 25%), linear-gradient(-45deg, #777 25%, transparent 25%), linear-gradient(135deg, #777 25%, transparent 25%), linear-gradient(-135deg, #777 25%, #555 25%) !important; background-size: 20px 20px !important; background-position: center !important; border-color: #444 !important; }
.domino.face-down.pattern-checker { background-image: conic-gradient(#777 90deg, transparent 90deg 180deg, #777 180deg 270deg, transparent 270deg) !important; background-size: 20px 20px !important; }
.domino.face-down.pattern-waves { background-image: repeating-radial-gradient(circle at 0 0, transparent 0, #555 10px), repeating-linear-gradient(#777 0, #777 5px, transparent 5px, transparent 10px) !important; }
.domino.face-down.pattern-stars { background-image: radial-gradient(#fff, rgba(255,255,255,.2) 2px, transparent 40px) !important; background-size: 30px 30px !important; background-color: #111 !important; border-color: #000 !important; }
.domino.face-down.pattern-carbon { background-image: repeating-linear-gradient(45deg, #333 0, #333 5px, #222 5px, #222 10px) !important; border-color: #000 !important;}
.domino.face-down.pattern-circuit { background-image: radial-gradient(circle, #555 2px, transparent 2.5px), linear-gradient(to right, #444 1px, transparent 1px), linear-gradient(to bottom, #444 1px, transparent 1px) !important; background-size: 10px 10px !important; }

/* Domino Styles (Materials) */
.domino.style-plastic { }
.domino.style-wood { background-color: #8B4513; border-color: #5A2D0C; color: #2e1a06; box-shadow: inset 0 0 5px rgba(0,0,0,0.5); }
.domino.style-wood .pip { background-color: #2e1a06; } 
.domino.style-glass { background-color: rgba(200, 230, 255, 0.7); border-color: rgba(255,255,255,0.9); color: rgba(0,0,0,0.8); box-shadow: 0 0 15px rgba(255,255,255,0.7) inset, 0 0 5px rgba(0,0,0,0.3); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.domino.style-glass .pip { background-color: rgba(0,0,0,0.8); }
.domino.style-stone { background-image: linear-gradient(45deg, rgba(255,255,255,0.2) 25%, transparent 25%), linear-gradient(-45deg, rgba(0,0,0,0.1) 25%, transparent 25%); background-size: 10px 10px; border-radius: 2px; }
.domino.style-metal { background-image: linear-gradient(135deg, rgba(255,255,255,0.6) 0%, rgba(0,0,0,0.3) 100%); box-shadow: inset 1px 1px 3px rgba(255,255,255,0.8), inset -1px -1px 3px rgba(0,0,0,0.6); border-radius: 4px; }
.domino.style-neon { background-color: transparent !important; box-shadow: 0 0 8px currentColor, inset 0 0 8px currentColor; border: 2px solid currentColor; }
.domino.style-ghost { opacity: 0.6; backdrop-filter: blur(3px); box-shadow: 0 0 10px rgba(255,255,255,0.3); }
.domino.style-obsidian { background-image: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.1), rgba(0,0,0,0.8)); box-shadow: inset 0 0 10px #000; border-color: #111; }

body { 
    font-family: Arial, sans-serif; 
    background-color: var(--brand-bg); 
    color: var(--text-color); 
    margin: 0; 
    overflow: hidden; 
    height: 100vh; 
    height: 100dvh; /* Dynamically adjusts height to exclude address/navigation bars on mobile */
    display: flex; 
    flex-direction: column; 
    transition: background-color 0.5s ease; 
}
.hidden { display: none !important; }

/* --- New Auth Tabs & Links --- */
.auth-tabs { display: flex; justify-content: center; gap: 10px; margin-bottom: 20px; }
.auth-tab { flex: 1; padding: 8px; border: 2px solid #555; background: rgba(0,0,0,0.5); color: #ccc; cursor: pointer; border-radius: 5px; transition: 0.2s; font-weight: bold; }
.auth-tab.active { border-color: var(--highlight-yellow); color: var(--highlight-yellow); background: rgba(255, 199, 0, 0.1); }
.text-link { background: none; border: none; color: white; text-decoration: underline; cursor: pointer; font-size: 0.9rem; padding: 5px; transition: color 0.2s; }
.text-link:hover { color: var(--highlight-yellow); }
#toggle-code-btn:hover, #copy-code-btn:hover { transform: scale(1.2); }

/* --- Top Header & Layout Systems --- */
#game-header { flex: 0 0 60px; background: rgba(0,0,0,0.5); display: flex; justify-content: space-between; align-items: center; padding: 0 20px; box-sizing: border-box; width: 100%; z-index: 100; }
#profile-section { display: flex; align-items: center; gap: 10px; transition: transform 0.2s; }
#profile-section:hover { transform: scale(1.05); }
#avatar { font-size: 30px; background: #fff; border-radius: 50%; padding: 5px; border: 2px solid var(--highlight-yellow); }
.profile-info { display: flex; flex-direction: column; align-items: flex-start; }
.level-container { display: flex; align-items: center; gap: 5px; font-size: 0.8rem; }
.xp-bar-bg { width: 100px; height: 8px; background: #444; border-radius: 4px; overflow: hidden; }
#xp-bar-fill { height: 100%; background: var(--highlight-yellow); width: 0%; transition: width 0.3s; }
.action-btn { font-size: 1.1rem; padding: 10px 20px; margin: 5px; cursor: pointer; border: 2px solid white; background-color: transparent; color: white; border-radius: 8px; transition: 0.3s; }
.action-btn:hover { background-color: white; color: black; }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#menu-system, #game-system { flex: 1 1 auto; width: 100%; display: flex; justify-content: center; align-items: center; position: relative; }
.menu-screen { 
    width: 100%; 
    height: 100%; 
    display: flex; 
    justify-content: center; 
    align-items: center;     /* Centers content vertically on larger desktop screens */
    position: absolute; 
    top: 0; 
    left: 0; 
    overflow-y: auto;        /* Enable vertical scrolling when content overflows */
    box-sizing: border-box;
    padding-bottom: 40px;    /* Extra space at the bottom when scrolled */
}

/* GLOBAL LOGO & MENU ADJUSTMENTS */
#global-logo { position: absolute; top: 8vh; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 15px; pointer-events: none; }
.menu-box { background: rgba(0,0,0,0.6); padding: 40px; border-radius: 10px; text-align: center; border: 2px solid var(--highlight-yellow); max-width: 400px; width: 90%; margin-top: 100px; }
.menu-box input[type="text"], .menu-box input[type="password"], .menu-box input[type="email"], .menu-box input[type="date"] { display: block; margin: 10px auto; padding: 10px; border-radius: 5px; border: none; font-size: 1rem; width: 90%; box-sizing: border-box; }
.player-options { display: flex; flex-direction: column; gap: 10px; }
#lobby-players { list-style: none; padding: 0; font-size: 1.2rem; margin-bottom: 20px; }

.main-game-title { font-size: 3.5rem; color: var(--highlight-yellow); text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 0 4px 10px rgba(0,0,0,0.8); margin-bottom: 5px; margin-top: 0; font-family: 'Arial Black', sans-serif; letter-spacing: 2px; }
#live-players-display { margin-top: 0; margin-bottom: 20px; font-weight: bold; color: limegreen; font-size: 1.1rem; }

/* --- PFP Labels --- */
.player-label-container { display: flex; flex-direction: column; align-items: center; margin-bottom: 5px; cursor: pointer; transition: transform 0.2s; }
.player-label-container:hover { transform: scale(1.1); text-shadow: 0 0 10px var(--highlight-yellow); }
.player-pfp-label { font-size: 1.5rem; background: rgba(0,0,0,0.4); padding: 5px; border-radius: 50%; width: 35px; height: 35px; display: flex; justify-content: center; align-items: center; border: 1px solid var(--highlight-yellow); margin-bottom: -5px; z-index: 2; }
.player-area h2 { margin: 5px 0 10px 0; font-size: 1.2rem; }

/* --- Emoji Picker Box --- */
#emoji-picker-container { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; margin-top: 15px; max-height: 180px; overflow-y: auto; background: rgba(0,0,0,0.6); padding: 10px; border-radius: 8px; border: 1px solid #555; }
.emoji-option { font-size: 1.8rem; cursor: pointer; transition: transform 0.2s; text-align: center; }
.emoji-option:hover { transform: scale(1.3); }
#profile-pfp-display:hover { transform: scale(1.1); box-shadow: 0 0 10px var(--highlight-yellow); }

/* --- Exact Original Game Container Layout --- */
#game-container { display: grid; grid-template-areas: "opponent middle player2" "player info player3"; grid-template-rows: 1fr auto; grid-template-columns: 2fr 5fr 2fr; gap: 1em; width: 98vw; height: 98%; max-width: 1400px; }
#game-container[data-players="2"] { grid-template-areas: "opponent opponent" "middle middle" "player player" "info info"; grid-template-rows: auto 1fr auto auto; grid-template-columns: 1fr 1fr; max-width: 1200px; }

.player-area { text-align: center; padding: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#opponent-area { grid-area: opponent; } #player-2-area { grid-area: player2; }
#player-3-area { grid-area: player3; } #player-area { grid-area: player; }
#game-info { grid-area: info; text-align: center; z-index: 10;} 
#middle-area { grid-area: middle; display: flex; gap: 20px; align-items: center; justify-content: center; min-height: 0; width: 100%; }

/* --- Board & Dominoes --- */
#game-board { background-color: var(--board-bg); border-radius: 10px; flex-grow: 1; min-width: 300px; height: 100%; overflow: hidden; position: relative; border: 2px solid rgba(255,255,255,0.2);}
#chain-container { position: absolute; top: 50%; left: 50%; transform-origin: center center; transition: transform 0.5s ease-out; will-change: transform; transform-style: preserve-3d; }

.hand { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; min-height: calc(var(--domino-height) + 10px); }
.domino { width: var(--domino-width); height: var(--domino-height); border: 1px solid #000; border-radius: 5px; display: flex; flex-direction: column; flex-shrink: 0; box-sizing: border-box; position: absolute; transform-origin: center center; backface-visibility: hidden; outline: 1px solid transparent; }
.domino.in-hand { position: static; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s;}
.domino.in-hand:hover { transform: translateY(-5px) scale(1.05); box-shadow: 0 0 10px rgba(255, 255, 255, 0.7); }

/* --- Boneyard & Flashing & Shuffling --- */
.middle-side-panel { width: 150px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#boneyard-area h2 { font-size: 1.2rem; margin: 0 0 10px 0; z-index: 10; position: relative; text-align: center; }

#boneyard-cluster { position: relative; width: 100%; flex-grow: 1; min-height: 200px; display: flex; justify-content: center; align-items: center; transition: 0.2s; z-index: 5; }
#boneyard-cluster .boneyard-domino { position: absolute; transition: box-shadow 0.2s, filter 0.2s; cursor: pointer; }
#boneyard-cluster .boneyard-domino:hover { box-shadow: 0 0 15px rgba(255, 255, 255, 0.9); z-index: 20; filter: brightness(1.2); }

#shuffle-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; overflow: hidden; }
.shuffling-domino { position: absolute; transition: all 0.35s cubic-bezier(0.25, 1, 0.5, 1); }
.shuffling-domino.clickable { pointer-events: auto; cursor: pointer; }
.shuffling-domino.clickable:hover { box-shadow: 0 0 15px var(--highlight-yellow); z-index: 60; filter: brightness(1.2); }

#boneyard-cluster.flash-boneyard { animation: clusterFlash 1s infinite alternate; }

@keyframes clusterFlash { 
    0% { filter: drop-shadow(0 0 5px var(--highlight-yellow)); } 
    100% { filter: drop-shadow(0 0 25px var(--highlight-yellow)); transform: scale(1.05); } 
}

/* --- Pips --- */
.pip-container { width: 100%; height: 50%; box-sizing: border-box; border-bottom: 1px solid rgba(0,0,0,0.3); padding: var(--pip-padding, 4px); display: grid; grid-template-rows: 1fr 1fr 1fr; grid-template-columns: 1fr 1fr 1fr; grid-template-areas: "top-left . top-right" "middle-left middle-center middle-right" "bottom-left . bottom-right"; }
.pip-container:last-child { border-bottom: none; }
.pip-container.selected-pip { background-color: rgba(255, 199, 0, 0.5); box-shadow: inset 0 0 10px #ff8c00; }
.pip { width: var(--pip-size, 8px); height: var(--pip-size, 8px); border-radius: 50%; align-self: center; justify-self: center; visibility: hidden; background-color: currentColor; }
.pip.top-left { grid-area: top-left; } .pip.top-right { grid-area: top-right; }
.pip.middle-left { grid-area: middle-left; } .pip.middle-center { grid-area: middle-center; }
.pip.middle-right { grid-area: middle-right; } .pip.bottom-left { grid-area: bottom-left; }
.pip.bottom-right { grid-area: bottom-right; }
.pips-1 .middle-center, .pips-2 .top-left, .pips-2 .bottom-right, .pips-3 .top-left, .pips-3 .middle-center, .pips-3 .bottom-right, .pips-4 .top-left, .pips-4 .top-right, .pips-4 .bottom-left, .pips-4 .bottom-right, .pips-5 .top-left, .pips-5 .top-right, .pips-5 .middle-center, .pips-5 .bottom-left, .pips-5 .bottom-right, .pips-6 .top-left, .pips-6 .top-right, .pips-6 .middle-left, .pips-6 .middle-right, .pips-6 .bottom-left, .pips-6 .bottom-right { visibility: visible; }

/* --- Global Chat System --- */
#chat-container { position: fixed; bottom: 10px; right: 10px; width: 300px; background: rgba(0,0,0,0.8); border-radius: 8px; display: flex; flex-direction: column; overflow: hidden; border: 1px solid #555; z-index: 200; }
#chat-header { background: #333; padding: 5px; font-weight: bold; text-align: center; font-size: 14px;}
#chat-messages { height: 150px; overflow-y: auto; padding: 10px; font-size: 14px; display: flex; flex-direction: column; gap: 5px; }
.chat-msg { background: #444; padding: 5px; border-radius: 4px; }
#chat-input-area { display: flex; }
#chat-input { flex-grow: 1; padding: 8px; border: none; outline: none; }
#chat-send { padding: 8px 15px; background: var(--highlight-yellow); border: none; cursor: pointer; font-weight: bold; }

/* --- Modals --- */
.choice-marker { width: 50px; height: 50px; background-color: rgba(255, 255, 0, 0.4); border: 3px dashed var(--highlight-yellow); border-radius: 50%; cursor: pointer; position: absolute; transform: translate(-50%, -50%); animation: pulse 1.5s infinite; z-index: 10; }
@keyframes pulse { 0% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.1); } 100% { transform: translate(-50%, -50%) scale(1); } }
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.8); display: flex; justify-content: center; align-items: center; z-index: 1000; animation: fadeIn 0.3s ease-out; }
.modal-content { background-color: var(--board-bg); padding: 30px 40px; border-radius: 10px; text-align: center; border: 2px solid var(--highlight-yellow); box-shadow: 0 0 20px rgba(0,0,0,0.5); min-width: 300px; max-width: 800px; width: 90%; max-height: 90vh; overflow-y: auto; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Previews */
.preview-box { width: 100%; height: 100px; border: 1px solid #777; margin: 10px auto; background-color: var(--board-bg); background-size: cover; background-position: center; border-radius: 5px; overflow: hidden; display: flex; justify-content: center; align-items: center; position: relative; box-sizing: border-box; transition: background-color 0.3s, background-image 0.3s; }
.preview-box.large-preview { height: 120px; }

.preview-box[data-preview-theme="theme-green"] { background-color: #004d00; background-image: none; }
.preview-box[data-preview-theme="theme-dark"] { background-color: #0d0d0d; background-image: none; }
.preview-box[data-preview-theme="theme-wood"] { background-color: #3e2723; background-image: none; }
.preview-box[data-preview-theme="theme-space"] { background-color: #111; background-image: url('space-bg.jpg'); }
.preview-box[data-preview-theme="theme-ocean"] { background-color: #001f3f; background-image: url('ocean-bg.jpg'); }

.preview-box .domino-preview { width: 30px; height: 60px; border-radius: 3px; display: flex; flex-direction: column; flex-shrink: 0; box-sizing: border-box; border: 1px solid #000; }
.preview-box .domino-preview .pip-container { width: 100%; height: 50%; box-sizing: border-box; border-bottom: 0.5px solid rgba(0,0,0,0.3); padding: 2px; }
.preview-box .domino-preview .pip-container:last-child { border-bottom: none; }
.preview-box .domino-preview .pip { width: 4px; height: 4px; }

.unlock-category-section { margin-bottom: 20px; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.1); }
.unlock-category-section h3 { text-align: left; margin-bottom: 10px; }
.unlocks-scroll-wrapper { width: 100%; overflow-x: auto; white-space: nowrap; padding-bottom: 15px; position: relative; }
.unlocks-bar { display: inline-flex; gap: 10px; padding: 5px 0; position: relative; min-width: 100%; }
.unlock-level-indicator { height: 8px; background-color: #444; border-radius: 4px; margin: 5px 0 10px 0; position: relative; overflow: hidden; }
.unlock-level-indicator-fill { height: 100%; background: var(--highlight-yellow); width: 0%; transition: width 0.3s ease-out; position: absolute; left: 0; top: 0; }

.unlock-item { display: flex; flex-direction: column; align-items: center; justify-content: space-between; width: 80px; height: 120px; padding: 5px; border-radius: 8px; border: 2px solid transparent; background-color: rgba(0,0,0,0.3); cursor: pointer; transition: all 0.2s ease-in-out; position: relative; box-sizing: border-box; white-space: normal; }
.unlock-item:hover { transform: translateY(-3px); box-shadow: 0 4px 8px rgba(0,0,0,0.3); }
.unlock-item.locked { opacity: 0.6; border-color: #666; cursor: not-allowed; }
.unlock-item.unlocked { border-color: #888; }
.unlock-item.selected { border-color: var(--highlight-yellow); background-color: rgba(0,0,0,0.5); box-shadow: 0 0 10px var(--highlight-yellow); }
.unlock-item.unlocked.selected { border-color: limegreen; box-shadow: 0 0 10px limegreen; }
.unlock-item .item-name { font-size: 0.8em; font-weight: bold; text-align: center; margin-bottom: 2px; flex-grow: 0; }
.unlock-item .item-info { font-size: 0.7em; color: #ccc; text-align: center; flex-grow: 0; }
.unlock-item.locked .item-info { color: var(--highlight-yellow); }
.unlock-item.unlocked .item-info { color: limegreen; }

.unlock-item-preview { width: 100%; height: 40px; display: flex; justify-content: center; align-items: center; margin-bottom: 5px; border-radius: 4px; overflow: hidden; background-color: #333; position: relative; }
.domino-preview-micro { width: 25px; height: 50px; border-radius: 3px; border: 1px solid #000; box-sizing: border-box; display: flex; flex-direction: column; position: relative; }
.domino-preview-micro .pip-container { width: 100%; height: 50%; padding: 2px; box-sizing: border-box; border-bottom: 1px solid rgba(0,0,0,0.2); }
.domino-preview-micro .pip-container:last-child { border-bottom: none; }
.domino-preview-micro .pip { width: 4px; height: 4px; background-color: currentColor; }
.theme-preview-mini { width: 100%; height: 100%; background-color: #004d00; background-size: cover; background-position: center; border-radius: 4px; }
.theme-preview-mini[data-preview-theme="theme-dark"] { background-color: #0d0d0d; background-image: none; }
.theme-preview-mini[data-preview-theme="theme-wood"] { background-color: #3e2723; background-image: none; }
.theme-preview-mini[data-preview-theme="theme-space"] { background-color: #111; background-image: url('space-bg.jpg'); }
.theme-preview-mini[data-preview-theme="theme-ocean"] { background-color: #001f3f; background-image: url('ocean-bg.jpg'); }

.buy-selected-item-btn { margin-top: 15px; width: calc(100% - 10px); }

/* --- Uniform Form & Label Alignment --- */
.setting-select {
    padding: 5px;
    border-radius: 5px;
    border: none;
    font-size: 0.9rem;
    margin-left: 5px;
    background: #e0e0e0;
    color: black;
}

.settings-panel label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.settings-panel input[type="checkbox"] {
    margin: 0 5px 0 0;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* ==========================================
   MOBILE RESPONSIVE LAYOUT (Android/iOS)
   ========================================== */
@media (max-width: 768px) {
    #game-header { padding: 0 10px; }
    #player-name { font-size: 0.9rem; }
    .xp-bar-bg { width: 60px; }

    .main-game-title {
        font-size: 2.6rem; 
        margin-top: 10px;
        line-height: 1.1;
        text-align: center;
    }
    
    .menu-screen {
        align-items: flex-start !important; /* Apply top-alignment only on mobile screens */
        padding-bottom: 120px !important;   /* Keep scroll room for dynamic mobile bars and the chat container */
    }

    #global-logo {
        top: 3vh;
        transform: translateX(-50%) scale(1); 
    }

    .menu-box {
        margin-top: 140px; 
        padding: 15px;
        width: 95%;
        box-sizing: border-box;
    }

    /* Stack settings menus vertically to fit screen */
    .settings-panel {
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .settings-panel > div {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    /* Stack labels and dropdowns vertically */
    .settings-panel label {
        display: flex;
        flex-direction: column;
        align-items: flex-start !important;
        width: 100%;
    }

    /* Force dropdowns to fit inside the screen */
    .setting-select {
        width: 100%;
        margin-left: 0 !important;
        margin-top: 5px;
        box-sizing: border-box;
    }

    /* Touch-friendly Horizontal Momentum Scrolling for Settings/Unlocks */
    .unlocks-scroll-wrapper {
        -webkit-overflow-scrolling: touch; /* Momentum scrolling on iOS */
        padding-bottom: 10px;
    }

    .unlock-item {
        width: 75px;
        height: 110px;
        flex-shrink: 0;
    }

    .unlock-item-preview {
        height: 45px;
    }

    /* 4-Player / General Mobile Grid */
    #game-container {
        display: grid !important;
        grid-template-areas: 
            "player2 opponent player3"
            "middle middle middle"
            "player player player"
            "info info info";
        grid-template-rows: auto 1fr auto auto;
        grid-template-columns: 1fr 1fr 1fr;
        height: calc(100vh - 60px);
        width: 100vw;
        padding: 5px;
        gap: 5px;
        box-sizing: border-box;
    }

    /* 2-Player Override Grid */
    #game-container[data-players="2"] {
        grid-template-areas: 
            "opponent opponent opponent"
            "middle middle middle"
            "player player player"
            "info info info";
    }

    /* Stack the game board and boneyard vertically */
    #middle-area {
        flex-direction: column;
        width: 100%;
        height: 100%;
        gap: 5px;
    }

    #game-board {
        width: 100%;
        height: auto;
        min-height: 200px;
    }

    /* Boneyard adjustments to span horizontally beneath the board */
    .middle-side-panel {
        width: 100%;
        min-height: 60px;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
    }

    #boneyard-area h2 {
        font-size: 1rem;
        margin: 0 10px 0 0;
        white-space: nowrap; 
    }

    #boneyard-cluster {
        min-height: 60px;
        width: calc(100% - 100px); 
        flex-direction: row;
    }

    /* Shrink player areas and text to save screen real-estate */
    .player-area {
        padding: 2px;
        justify-content: flex-start;
    }

    .player-area h2 {
        font-size: 0.8rem;
        margin: 2px 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    .player-pfp-label {
        width: 25px;
        height: 25px;
        font-size: 1rem;
    }

    .hand { gap: 4px; }

    /* Keep Chat inside mobile borders */
    #chat-container {
        width: 90vw;
        right: 5vw;
        bottom: 5px;
    }

/* --- Collapsible Chat --- */
    #chat-header {
    	cursor: pointer;
    	user-select: none;
    }
    #chat-container {
    	transition: height 0.3s ease, max-height 0.3s ease;
    }
    #chat-container.collapsed {
    	height: 30px !important;
    }
    #chat-container.collapsed #chat-messages,
    #chat-container.collapsed #chat-input-area {
    	display: none !important;
    }


    /* Ensure modals don't overflow */
    .modal-content {
        padding: 20px 15px;
        width: 95%;
    }
    
    .action-btn {
        font-size: 0.9rem;
        padding: 8px 12px;
    }

    /* Shrink opponents' dominoes inside their hands on mobile */
    .player-area:not(#player-area) {
        --domino-width: 18px;
        --domino-height: 36px;
        --pip-size: 3.5px;
        --pip-padding: 2px;
    }
    .player-area:not(#player-area) .hand {
        gap: 3px;
    }
}