* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; font-family: Arial, Helvetica, sans-serif; }
body { background: #000; color: #fff; }

body.dark-mode { --background: #000000; --surface: #000000; --surface-2: #222222; --text: #ffffff; --secondary: #999999; --border: #333333; }
body.light-mode { --background: #ffffff; --surface: #ffffff; --surface-2: #eeeeee; --text: #000000; --secondary: #666666; --border: #cccccc; color: #000000; }
.hidden { display: none !important; }

body.dark-mode .invertable-img { filter: invert(1); }

/* Global Leaderboard Component Styles */
#global-leaderboard-container { width: 100%; padding: 15px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); text-align: center; }

#lb-title { font-size: 20px; font-weight: bold; letter-spacing: 4px; color: var(--text); margin-bottom: 20px; }
#lb-toggles, #lb-toggles-type { display: flex; justify-content: center; gap: 6px; margin-bottom: 12px; }
#lb-toggles button, #lb-toggles-type button { flex: 1; height: 32px; font-size: 10px; font-weight: bold; letter-spacing: 1px; border: 1px solid var(--border); background: var(--background); color: var(--secondary); cursor: pointer; border-radius: 3px; }
#lb-toggles button.active, #lb-toggles-type button.active { background: var(--surface-2); color: var(--text); border-color: var(--secondary); }

#lb-list { display: flex; flex-direction: column; gap: 4px; text-align: left; min-height: 200px; margin-top: 15px;}
.lb-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px dashed var(--border); font-size: 13px; }
.lb-rank { width: 30px; color: var(--secondary); font-weight: bold; }
.lb-name { flex: 1; padding: 0 5px; font-weight: bold;}
.lb-val { color: var(--secondary); font-family: monospace; font-size: 14px;}

/* Leaderboard Anchors */
#home-lb-anchor { position: absolute; left: 14px; top: 50px; width: 320px; z-index: 20; }
#game-lb-anchor { position: absolute; left: 20px; top: 80px; z-index: 10; width: 280px; }

/* Home screen updated layout */
#home-screen { position: fixed; inset: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: var(--background); z-index: 1000; overflow-y: auto;}
#home-content { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; z-index: 10;}

#home-logo { width: 95px !important; height: 95px !important; max-width: 95px !important; max-height: 95px !important; object-fit: contain; display: block; margin-bottom: 24px; }
body.light-mode #home-logo { filter: invert(1); }
#home-title { font-size: 48px; font-weight: 800; letter-spacing: 8px; color: var(--text); margin-bottom: 38px; }

#home-content button { width: 190px; height: 42px; margin: 5px 0; border: 1px solid var(--border); border-radius: 3px; background: var(--background); color: var(--text); font-size: 10px; font-weight: bold; letter-spacing: 2px; cursor: pointer; }
#home-content button:hover { opacity: 0.65; }
#home-content button:active { transform: scale(0.98); }

#created-by { position: fixed; bottom: 15px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; color: var(--secondary); font-size: 9px; font-weight: bold; letter-spacing: 2px; z-index: 2500; }
#creator-logo { height: 16px !important; width: auto !important; max-width: 120px !important; object-fit: contain; }
body.dark-mode #creator-logo { filter: invert(1); }

#instructions-screen, #shuffling-screen, #gameplay-screen, #scoring-screen, #strategies-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--background); color: var(--text); z-index: 1000; overflow-y: auto; padding: 20px;}
#instructions-content, #strategies-content { width: min(700px, 90%); text-align: center; }
#instructions-title, #strategies-title { font-size: 30px; font-weight: bold; letter-spacing: 5px; margin-bottom: 30px; }

.split-layout { display: flex; align-items: center; justify-content: center; gap: 30px; text-align: left; margin-bottom: 30px; }
.split-layout img { max-width: 150px; height: auto; object-fit: contain; }
#instructions-text, #strategies-text { color: var(--secondary); font-size: 14px; line-height: 1.8; flex: 1; }
#instructions-text strong, #strategies-text strong { color: var(--text); }

.menu-buttons { display: flex; gap: 8px; justify-content: center; margin-top: 25px; }
.menu-buttons button { width: 130px; height: 36px; border: 1px solid var(--border); background: var(--background); color: var(--text); cursor: pointer; font-size: 10px; font-weight: bold; letter-spacing: 1px; border-radius: 3px;}
.menu-buttons button:hover { opacity: 0.65; }

#name-entry-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--background); color: var(--text); z-index: 1000; }
#name-entry-content { width: min(340px, 85%); text-align: center; }
#name-entry-title { font-size: 24px; font-weight: bold; letter-spacing: 4px; margin-bottom: 28px; }
.name-entry-field { margin-bottom: 14px; text-align: left; }
.name-entry-field label { display: block; font-size: 9px; font-weight: bold; letter-spacing: 1px; color: var(--secondary); margin-bottom: 6px; text-align: left;}
.name-entry-field input[type="text"], .dropdown-input { width: 100%; height: 38px; padding: 0 10px; background: var(--background); border: 1px solid var(--border); border-radius: 3px; color: var(--text); font-size: 13px; letter-spacing: 1px; }
.name-entry-field input[type="text"]:focus, .dropdown-input:focus { outline: none; border-color: var(--secondary); }

#name-entry-error { min-height: 14px; color: #c0524a; font-size: 10px; letter-spacing: 0.5px; margin-bottom: 6px; }
.name-entry-buttons { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.name-entry-buttons button { width: 130px; height: 38px; border: 1px solid var(--border); border-radius: 3px; background: var(--background); color: var(--text); cursor: pointer; font-size: 10px; font-weight: bold; letter-spacing: 1px; }
.name-entry-buttons button:hover { opacity: 0.65; }

/* Modal specific */
#highscore-modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.85); color: var(--text); z-index: 5000; }
#highscore-content { width: min(340px, 85%); text-align: center; background: var(--surface); padding: 30px; border: 1px solid var(--border); border-radius: 4px; box-shadow: 0 4px 20px rgba(0,0,0,0.5);}
#highscore-title { font-size: 22px; font-weight: bold; letter-spacing: 3px; margin-bottom: 10px; color: #e6a700; }
#highscore-msg { font-size: 11px; color: var(--secondary); margin-bottom: 25px; }

#queue-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--background); color: var(--text); overflow-y: auto; padding: 30px 0; z-index: 1000; }
#queue-content { display: flex; flex-direction: column; align-items: center; text-align: center; }
#queue-logo { width: 70px !important; height: 70px !important; max-width: 70px !important; max-height: 70px !important; object-fit: contain; margin-bottom: 20px; }
body.light-mode #queue-logo { filter: invert(1); }
#queue-title { font-size: 26px; font-weight: bold; letter-spacing: 5px; }
#queue-message { margin-top: 15px; color: var(--secondary); font-size: 12px; letter-spacing: 1px; }

#queue-dots { height: 25px; margin-top: 5px; font-size: 20px; }
#queue-dots span { animation: dots 1.4s infinite; }
#queue-dots span:nth-child(2) { animation-delay: .2s; }
#queue-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dots { 0%, 60%, 100% { opacity: .15; } 30% { opacity: 1; } }

#lobby-code-row { margin-top: 20px; padding: 15px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); }
#lobby-room-code { font-size: 28px; font-weight: 900; letter-spacing: 6px; color: var(--text); }
#lobby-slots { width: min(300px, 80vw); margin-top: 22px; display: flex; flex-direction: column; gap: 6px; }
.lobby-slot { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; border: 1px solid var(--border); border-radius: 3px; font-size: 11px; letter-spacing: .5px; }
.lobby-slot.me { border-color: var(--secondary); }
.lobby-slot-status { color: var(--secondary); font-size: 9px; font-weight: bold; letter-spacing: 1px; }

#start-game-button { width: 190px; height: 40px; margin-top: 20px; border: 1px solid var(--border); border-radius: 3px; background: var(--background); color: var(--text); cursor: pointer; font-size: 10px; font-weight: bold; letter-spacing: 2px; }
#start-game-button:hover { opacity: 0.65; }
#cancel-queue-button { width: 130px; height: 34px; margin-top: 20px; border: 1px solid var(--border); background: var(--background); color: var(--text); cursor: pointer; }

#game-screen { position: fixed; inset: 0; width: 100%; height: 100%; background: var(--background); color: var(--text); }
#header { position: absolute; top: 0; left: 0; right: 0; height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--border); background: var(--surface); z-index: 100; }
#game-title { display: flex; align-items: center; gap: 10px; transition: opacity 0.2s; cursor: pointer; }
#game-title:hover { opacity: 0.65; }
#game-title span { font-size: 19px; font-weight: 800; letter-spacing: 3px; }
#logo-img { width: 30px !important; height: 30px !important; max-width: 30px !important; max-height: 30px !important; object-fit: contain; display: block; }
body.light-mode #logo-img { filter: invert(1); }

#game-info { position: absolute; left: 50%; transform: translateX(-50%); display: flex; gap: 28px; color: var(--secondary); font-size: 10px; letter-spacing: 1px; }
#game-info strong { color: var(--text); margin-left: 5px; }

/* Fixed Top Buttons */
#top-left-buttons-container { position: fixed; top: 14px; left: 14px; z-index: 2000; display: flex; gap: 6px; }
#top-buttons-container { position: fixed; top: 14px; right: 14px; z-index: 2000; display: flex; gap: 6px; }

#theme-button, #coffee-button, #header-lb-button { height: 29px; padding: 0 11px; border: 1px solid var(--border); border-radius: 3px; background: var(--background); color: var(--text); cursor: pointer; font-size: 10px; font-weight: bold; }
#theme-button:hover, #coffee-button:hover, #header-lb-button:hover { opacity: 0.65; }

#game { position: absolute; top: 60px; left: 0; right: 0; bottom: 0; overflow: hidden; }
.player-area { position: absolute; width: 34%; max-width: 500px; }
.position-top { top: 20px; left: 50%; transform: translateX(-50%); }
.position-bottom { bottom: 20px; left: 50%; transform: translateX(-50%); }
.position-left { left: 20px; top: 50%; transform: translateY(-50%); width: 28%; }
.position-right { right: 20px; top: 50%; transform: translateY(-50%); width: 28%; }

#mass-player-view { position: absolute; top: 20px; left: 20px; right: 20px; bottom: 20px; display: flex; gap: 20px; }
#mass-active-player { flex: 1; display: flex; flex-direction: column; align-items: center; padding-top: 40px; }
#mass-player-list { width: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; padding-right: 10px; border-left: 1px solid var(--border); padding-left: 20px; }
#hover-cards-tooltip { position: fixed; left: 50%; top: 20px; transform: translateX(-50%); width: 350px; z-index: 200; background: var(--background); box-shadow: 0px 4px 15px rgba(0,0,0,0.5); border: 1px solid var(--border); border-radius: 4px; padding: 5px;}

.player-box { width: 100%; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; }
.player-box.me { border-color: var(--secondary); }
.player-box.active { border: 2px solid var(--text); }
.player-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 7px; }
.player-name { font-size: 14px; font-weight: bold; letter-spacing: 1px; }
.player-label { margin-left: 6px; color: var(--secondary); font-size: 9px; }

.player-score { color: var(--secondary); font-size: 13px; font-weight: bold; }
.player-bonus { font-size: 11px; color: var(--secondary); font-weight: bold; }

.cards { width: 100%; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; overflow: visible; }
.card { position: relative; border: 1px solid #222; border-radius: 3px; display: flex; align-items: center; justify-content: center; font-weight: bold; user-select: none; }
.card.crown::after { content: ""; position: absolute; top: -15px; left: 50%; transform: translateX(-50%); width: 18px; height: 18px; background: no-repeat center/contain url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'><path d='M5 16L3 6l5 4 4-6 4 6 5-4-2 10H5zm0 2h14v2H5z'/></svg>"); }
body.dark-mode .card.crown::after { background: no-repeat center/contain url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'><path d='M5 16L3 6l5 4 4-6 4 6 5-4-2 10H5zm0 2h14v2H5z'/></svg>"); }
.player-status { margin-top: 5px; font-size: 9px; font-weight: bold; letter-spacing: 1px; }
.player-status.bust, .player-status.stand { color: var(--secondary); }

#center { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; z-index: 50; pointer-events: none; }

#sp-ingame-stats { margin-bottom: 18px; font-size: 10px; font-weight: bold; letter-spacing: 1.5px; color: var(--secondary); text-transform: uppercase; background: var(--surface-2); padding: 8px 12px; border-radius: 4px; border: 1px solid var(--border); display: inline-block;}
#sp-ingame-stats span { color: var(--text); margin-left: 3px; margin-right: 8px; }

#message { font-size: 22px; font-weight: bold; letter-spacing: 2px; }
#submessage { margin-top: 7px; color: var(--secondary); font-size: 11px; }
#controls { margin-top: 18px; display: flex; justify-content: center; gap: 7px; pointer-events: auto; }
#controls button { width: 90px; height: 36px; border: 1px solid var(--border); background: var(--background); color: var(--text); cursor: pointer; font-size: 11px; font-weight: bold; }
#controls button:disabled { opacity: .25; cursor: not-allowed; }

#shuffle-text { margin-top: 12px; font-size: 12px; font-weight: bold; letter-spacing: 3px; color: var(--text); background: var(--background); padding: 5px; }

#game-state-image { position: fixed; left: 300px; bottom: 15px; width: 150px; height: 150px; z-index: 350; pointer-events: none; }
#state-img { width: 100%; height: 100%; object-fit: contain; }
body.light-mode #state-img { filter: none; }
body.dark-mode #state-img { filter: invert(1); }

/* GAMEOVER / MULTIPLAYER IMAGES */
#gameover-result-img { height: 120px; width: auto; margin: 0 auto 20px; display: block; object-fit: contain; }
body.dark-mode #gameover-result-img { filter: invert(1); }

#gameover-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--background); color: var(--text); z-index: 250; }
#gameover-content { width: min(440px, 85%); text-align: center; }
#gameover-title { font-size: 30px; font-weight: 800; letter-spacing: 5px; margin-bottom: 26px; }
#places-list, #sp-records-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 26px; }
.place-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 3px; font-size: 12px; letter-spacing: .5px; }
.place-row.me { border-color: var(--secondary); }
.place-rank { width: 30px; text-align: left; color: var(--secondary); font-weight: bold; }
.place-name { flex: 1; text-align: left; padding: 0 8px; }
.place-score { color: var(--secondary); }
.gameover-buttons { display: flex; gap: 8px; justify-content: center; }
.gameover-buttons button { width: 155px; height: 40px; border: 1px solid var(--border); border-radius: 3px; background: var(--background); color: var(--text); cursor: pointer; font-size: 10px; font-weight: bold; letter-spacing: 1px; }
.gameover-buttons button:hover { opacity: 0.65; }

@media (max-width: 650px) {
    #home-logo { width: 70px !important; height: 70px !important; max-width: 70px !important; max-height: 70px !important; }
    #home-title { font-size: 30px; letter-spacing: 4px; }
    #game-info { display: none; }
    #game-title span { font-size: 15px; }
    #logo-img { width: 25px !important; height: 25px !important; max-width: 25px !important; max-height: 25px !important; }
    .position-top { top: 10px; }
    .position-bottom { bottom: 20px; }
    .position-left { left: 5px; width: 29%; }
    .position-right { right: 5px; width: 29%; }
    .player-area { width: 42%; }
    .player-box { padding: 6px; }
    .player-name { font-size: 11px; }
    #message { font-size: 16px; }
    #controls { margin-top: 10px; }
    #controls button { width: 70px; height: 32px; font-size: 9px; }
    #created-by { display: none; }
    #mass-player-view { flex-direction: column; top: 70px;}
    #mass-player-list { width: 100%; border-left: none; border-top: 1px solid var(--border); padding-left: 0; padding-top: 10px;}
    .split-layout { flex-direction: column; text-align: center; }
    #sp-ingame-stats { font-size: 8px; padding: 6px 8px; }
}