* { box-sizing: border-box; }

/* STRICT VIEWPORT LOCKING */
body { 
    font-family: "Lucida Bright", Georgia, serif; 
    background-color: #2d5a27; 
    background-image: radial-gradient(circle, #3a7532 0%, #2d5a27 100%); 
    display: flex; justify-content: center; align-items: center; 
    width: 100vw; 
    height: 100vh; 
    margin: 0; 
    padding: 0;
    overflow: hidden; 
    color: #f4f4f9; 
    border: 12px solid #4a2e15; 
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8); 
}

button, input, th, td { font-family: "Lucida Bright", Georgia, serif; }

#app-container { 
    width: 100%; height: 100%; 
    display: flex; flex-direction: column; justify-content: center; align-items: center; 
    text-align: center;
}
.screen { display: none; width: 100%; }
.screen.active { display: block; }
.hidden { display: none !important; }

h1, h3, label { color: #ffffff; }
h2 { color: #ffd700; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8); font-size: 2.2rem; margin-bottom: 20px; letter-spacing: 1px; }
.gold-title { color: #ffd700; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8); margin-bottom: 40px; font-size: 4rem; letter-spacing: 2px; }

.vertical-stack { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.btn-gold, .secondary { background: linear-gradient(135deg, #ffd700 0%, #daa520 100%); color: #1a1a1a; font-weight: bold; border: 2px solid #b8860b; border-radius: 30px; cursor: pointer; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4); transition: transform 0.2s, filter 0.2s; }
.btn-gold { font-size: 1.2rem; padding: 15px 30px; width: 280px; }
.secondary { font-size: 1.1rem; padding: 12px 25px; width: 220px; margin-top: 10px; }
.btn-gold:hover, .secondary:hover { transform: translateY(-3px); filter: brightness(1.1); }
.button-row { display: flex; justify-content: center; gap: 20px; margin-top: 15px; }
.button-row .secondary { width: 200px; margin: 0; }

.grid-container { display: grid; grid-template-columns: repeat(4, minmax(190px, 1fr)); grid-template-rows: repeat(4, minmax(140px, auto)); gap: 15px; margin: 20px auto; justify-content: center; width: 100%; max-width: 1000px; }
.profile-box { background-color: rgba(0, 0, 0, 0.4); border: 8px solid #4a2e15; border-radius: 12px; padding: 15px; box-shadow: 0 8px 15px rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.profile-box:hover { transform: translateY(-4px); background-color: rgba(0, 0, 0, 0.6); }
.profile-box.empty-box { background-color: rgba(0, 0, 0, 0.1); cursor: default; }
.profile-box.empty-box:hover { transform: none; }
.gold-text { color: #ffd700; margin: 6px 0; text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.9); }

.input-group { margin: 0 auto 25px auto; max-width: 350px; }
.input-group label { display: block; margin-bottom: 10px; font-size: 1.3rem; color: #ffd700; }
.input-group input { width: 100%; padding: 12px; font-size: 1.4rem; background-color: rgba(0, 0, 0, 0.5); border: 2px solid #b8860b; border-radius: 8px; color: #ffd700; text-align: center; }
#selected-profile-name { font-size: 2.8rem; text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.9); margin-bottom: 30px; }

#game-info { display: flex; justify-content: space-between; align-items: center; width: 96vw; max-width: 1300px; margin: 0 auto 10px auto; font-size: 1.2rem; color: #ffd700; text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8); }
#joker-container { display: flex; align-items: center; gap: 10px; }

/* DYNAMIC TABLE SIZING */
.mahjong-table { 
    grid-template-areas: ". p-top ." "p-left center p-right" ". p-bottom ."; 
    display: grid; 
    grid-template-columns: 240px 1fr 240px; 
    grid-template-rows: 140px 1fr 140px; 
    background-color: rgba(0, 0, 0, 0.2); 
    border: 10px solid #4a2e15; border-radius: 12px; 
    box-shadow: inset 0 0 30px rgba(0,0,0,0.6), 0 10px 20px rgba(0,0,0,0.5); 
    width: 96vw; height: 85vh; 
    max-width: 1400px; max-height: 850px; 
    margin: 0 auto; 
    position: relative; 
}

.tile { width: 44px; height: 62px; background: linear-gradient(135deg, #fffff0 0%, #e6e6e6 100%); border: 1px solid #999; border-bottom: 2px solid #144d29; border-radius: 6px; display: flex; flex-direction: column; justify-content: center; align-items: center; cursor: grab; font-family: "Lucida Bright", Georgia, serif; font-weight: bold; box-shadow: 2px 4px 6px rgba(0,0,0,0.4); transition: transform 0.1s; user-select: none; }
.tile:hover { transform: translateY(-5px); border-color: #ffd700; }
.tile:active { cursor: grabbing; }
.tile.drag-over { border: 2px dashed #ffd700; transform: scale(1.05); }

.authentic-tile { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.tile-num { font-size: 1.2rem; }
.tile-suit { font-size: 1.6rem; }

.bot-hand { display: flex; justify-content: center; align-items: center; gap: 2px; z-index: 10; position: relative; }
.bot-hand-horizontal { flex-direction: row; margin: 0; }
.bot-hand-vertical { flex-direction: column; margin: 0; }
.bot-tile { background: #144d29; border: 1px solid #0f3a1f; border-radius: 4px; box-shadow: inset 1px 1px 2px rgba(255,255,255,0.2), 2px 2px 4px rgba(0,0,0,0.5); }
.bot-hand-horizontal .bot-tile { width: 28px; height: 40px; border-bottom: 3px solid #fffff0; }
.bot-hand-vertical .bot-tile { width: 40px; height: 28px; border-right: 3px solid #fffff0; }

/* THE EXPANDED WALL (Pushed Outward) */
.wall-container { position: absolute; display: flex; z-index: 9999; pointer-events: none; } 
.wall-top { top: 15%; left: calc(50% + 20px); transform: translateX(-50%); }
.wall-bottom { bottom: 15%; left: calc(50% - 20px); transform: translateX(-50%); }
.wall-left { left: 18%; top: calc(50% + 20px); transform: translateY(-50%); flex-direction: column; }
.wall-right { right: 18%; top: calc(50% - 20px); transform: translateY(-50%); flex-direction: column; }

.wall-tile { background: #144d29; border: 1px solid #0f3a1f; border-radius: 2px; box-shadow: inset 1px 1px 2px rgba(255,255,255,0.2), 2px 2px 4px rgba(0,0,0,0.5); cursor: pointer; transition: filter 0.2s, transform 0.1s; pointer-events: auto; } 
.wall-tile:hover { filter: brightness(1.5); transform: translateY(-3px); z-index: 10000; position: relative; border-color: #ffd700; }
.wall-top .wall-tile, .wall-bottom .wall-tile { width: 22px; height: 34px; margin: 0; border-bottom: 2px solid #fffff0; }
.wall-left .wall-tile, .wall-right .wall-tile { width: 34px; height: 22px; margin: 0; border-right: 2px solid #fffff0; }

/* FLEXBOX RE-ALIGNMENT FOR SIDE-BY-SIDE NAME TAGS */
.player-top { grid-area: p-top; display: flex; flex-direction: row; align-items: center; justify-content: center; z-index: 5; pointer-events: none; gap: 20px; }
.player-bottom { grid-area: p-bottom; display: flex; flex-direction: row; align-items: center; justify-content: center; z-index: 5; pointer-events: none; gap: 20px; }
.player-left { grid-area: p-left; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 5; pointer-events: none; gap: 15px; }
.player-right { grid-area: p-right; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 5; pointer-events: none; gap: 15px; }

/* STRICT 12-COLUMN DISCARD GRID */
.discard-pile { 
    grid-area: center; display: grid; 
    grid-template-columns: repeat(12, 34px); 
    grid-auto-rows: 50px; gap: 2px; 
    justify-content: center; align-content: center; 
    z-index: 2; pointer-events: auto; 
    width: 100%; height: 100%; padding: 20px;
}
.discard-pile .tile { width: 34px; height: 50px; margin: 0; border-radius: 4px; }

#my-hand, .melds-container { pointer-events: auto; }
#my-hand { display: flex; gap: 4px; z-index: 100; position: relative; }

.melds-container { display: flex; gap: 8px; padding: 6px; background: rgba(0,0,0,0.3); border: 2px dashed rgba(184, 134, 11, 0.5); border-radius: 8px; min-height: 70px; min-width: 130px; justify-content: center; align-items: center; }
.player-left .melds-container, .player-right .melds-container { flex-direction: column; min-height: 130px; min-width: 70px; margin: 0; }
.meld-group { display: flex; gap: 2px; padding: 4px; background: rgba(0,0,0,0.6); border-radius: 6px; border: 1px solid #ffd700; }
.meld-tile { width: 36px; height: 50px; border-bottom: 2px solid #144d29; cursor: default; pointer-events: none; }

.name-tag { position: relative; padding: 6px 12px; background: #1a1a1a; color: #ffd700; border: 2px solid #4a2e15; border-radius: 6px; font-size: 1.1rem; pointer-events: auto; margin: 0; }
.glow-ring { position: absolute; top: -6px; left: -6px; right: -6px; bottom: -6px; z-index: -1; border-radius: 8px; background: conic-gradient(#ffd700 var(--progress, 0%), transparent 0%); box-shadow: 0 0 15px rgba(255, 215, 0, 0.4); }

#dice-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); z-index: 20; border-radius: 12px; display: flex; justify-content: center; align-items: center; gap: 20px; }
.die { width: 60px; height: 60px; background: #fffff0; border-radius: 10px; display: flex; justify-content: center; align-items: center; font-size: 2.5rem; color: #1a1a1a; font-weight: bold; box-shadow: inset -3px -3px 6px rgba(0,0,0,0.2), 0 5px 15px rgba(0,0,0,0.8); }

#action-buttons { position: absolute; right: -80px; bottom: 20%; display: flex; flex-direction: column; gap: 15px; z-index: 1000; pointer-events: auto; }
.action-circle { width: 70px; height: 70px; border-radius: 50%; background: linear-gradient(135deg, #ffd700 0%, #daa520 100%); border: 3px solid #fff; box-shadow: 0 5px 15px rgba(0,0,0,0.6); display: flex; flex-direction: column; justify-content: center; align-items: center; cursor: pointer; color: #1a1a1a; transition: transform 0.2s, filter 0.2s; }
.action-circle:hover { transform: scale(1.1); filter: brightness(1.2); }
.action-circle .hanzi { font-size: 1.8rem; font-weight: bold; line-height: 1; }
.action-circle .pinyin { font-size: 0.8rem; font-weight: bold; margin-top: 2px; }

.tile-face { width: 85%; height: 85%; object-fit: contain; pointer-events: none; }

/* LEAVE TABLE BUTTON PINNED TO BOTTOM LEFT */
#btn-leave { position: fixed; bottom: 20px; left: 20px; z-index: 9999; }