* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Nunito', sans-serif;
    background: radial-gradient(circle at top, #2c3e50 0%, #1a252f 100%);
    color: white;
    overflow: hidden;
    display: flex;
    justify-content: center;
    touch-action: none;
}

/* --- HOME SCREEN STYLES --- */
.game-title {
    font-size: 42px;
    color: #f1c40f;
    text-shadow: 2px 4px 6px rgba(0,0,0,0.5);
    margin-top: 0;
    margin-bottom: 25px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#home-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, #2c3e50 0%, #1a252f 100%);
    position: absolute;
    top: 0;
    left: 0;
    z-index: 50;
}

.home-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    background: rgba(255,255,255,0.1);
    padding: 15px 30px;
    border-radius: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
}

.home-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 80%;
    max-width: 300px;
}
/* -------------------------- */

#game-container {
    width: 100vw;
    max-width: 600px; /* Batasi lebar di desktop */
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 15px;
}

#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 12px 20px;
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.1);
}

.stats-wrapper {
    display: flex;
    gap: 12px;
}

.stat {
    font-weight: 900;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 5px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.ai-info, .player-info {
    text-align: center;
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 8px;
    color: #bdc3c7;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.opponents-container {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
    min-height: 40px;
}

.opponent-area {
    background: rgba(0,0,0,0.2);
    padding: 6px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.1);
    transition: all 0.3s;
}

.opponent-area.active-turn {
    background: rgba(46, 204, 113, 0.3);
    border-color: #2ecc71;
    box-shadow: 0 0 15px rgba(46,204,113,0.4);
}

.opponent-area .ai-info {
    margin-bottom: 0;
    font-size: 12px;
}

#board {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: flex-start; /* Ubah agar tidak terpotong jika konten melebihi layar */
    overflow: auto; /* Hidupkan scroll 2D kembali */
    margin: 15px 0;
    background: radial-gradient(circle, #2ecc71 0%, #1e8449 100%);
    border: 6px solid #145a32;
    border-radius: 25px;
    padding: 20px 0;
    box-shadow: inset 0 10px 30px rgba(0,0,0,0.6), 0 10px 20px rgba(0,0,0,0.3);
    scroll-behavior: smooth;
}

#domino-chain {
    display: block; /* Mode berubah dari flex menjadi layout bebas absolut */
    margin: auto; /* Kunci agar tetap di tengah saat muat, tapi aman saat overflow */
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); /* Animasi auto-zoom yang sinematik */
    flex-shrink: 0; /* Mencegah flexbox merusak kalkulasi lebar asli sebelum di-zoom */
    transform-origin: center center; /* Memastikan zoom selalu ditarik dari titik tengah */
}

.hand {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    min-height: 70px;
}

.domino {
    width: 36px;
    height: 72px;
    background: linear-gradient(135deg, #ffffff 0%, #f1f2f6 100%);
    color: #2c3e50;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    text-align: center;
    font-weight: 900;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 2px 4px 6px rgba(0,0,0,0.4), inset 0 -4px 0 #dcdde1;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), left 0.3s, top 0.3s;
    position: relative;
}

.domino:hover {
    transform: translateY(-12px) scale(1.05);
    z-index: 50 !important;
}

#domino-chain .domino {
    cursor: default;
}

#domino-chain .domino:hover {
    transform: scale(1.05);
}

.pip-container {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 3px;
    pointer-events: none;
}

.pip {
    width: 7px;
    height: 7px;
    background-color: #2c3e50;
    border-radius: 50%;
    box-shadow: inset 1px 1px 2px rgba(0,0,0,0.6);
    margin: auto;
}

/* Pengecilan titik dadu khusus untuk kartu di meja */
#domino-chain .pip-container {
    padding: 2px;
}
#domino-chain .pip {
    width: 5.5px;
    height: 5.5px;
}

.domino .divider {
    height: 2px;
    background: #2c3e50;
    width: 80%;
    margin: 0 auto;
    border-radius: 2px;
    opacity: 0.5;
}

#controls {
    text-align: center;
    padding: 10px 0;
}

button {
    padding: 10px 20px;
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 900;
    font-size: 16px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.1s;
    text-transform: uppercase;
}

button:active {
    transform: translateY(4px);
}

.btn-danger {
    background: linear-gradient(to bottom, #e74c3c, #c0392b);
    box-shadow: 0 4px 0 #922b21, 0 5px 15px rgba(0,0,0,0.3);
}

.btn-danger:active { box-shadow: 0 0 0 #922b21; }

.btn-primary {
    background: linear-gradient(to bottom, #3498db, #2980b9);
    box-shadow: 0 4px 0 #1f618d, 0 5px 15px rgba(0,0,0,0.3);
}

.btn-primary:active { box-shadow: 0 0 0 #1f618d; }

.btn-star {
    background: linear-gradient(to bottom, #f1c40f, #f39c12);
    color: #8e44ad;
    box-shadow: 0 4px 0 #b9770e, 0 5px 15px rgba(0,0,0,0.3);
}

.btn-star:active { box-shadow: 0 0 0 #b9770e; }

.btn-secondary {
    background: linear-gradient(to bottom, #95a5a6, #7f8c8d);
    box-shadow: 0 4px 0 #616a6b, 0 5px 15px rgba(0,0,0,0.3);
}

.btn-secondary:active { box-shadow: 0 0 0 #616a6b; }

.hidden { display: none; }

#modal, #start-menu {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 2px solid #5d6d7e;
    width: 85%;
    max-width: 320px;
}

#modal-title {
    margin-top: 0;
    font-size: 28px;
    color: #f1c40f;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#modal-text {
    font-size: 18px;
    margin-bottom: 25px;
}

.modal-content button {
    display: block;
    width: 100%;
    margin: 12px 0;
    padding: 14px;
}

/* Kartu Di Tangan Yang Sedang Dipilih */
.domino.selected {
    transform: translateY(-15px) scale(1.1);
    box-shadow: 0 0 15px #f1c40f, 2px 4px 6px rgba(0,0,0,0.4), inset 0 -4px 0 #dcdde1;
    border: 2px solid #f1c40f;
}

/* Zona Drop Hijau Di Ujung */
.dropzone {
    width: 60px;
    height: 60px;
    background: rgba(46, 204, 113, 0.3);
    border: 3px dashed #2ecc71;
    border-radius: 12px;
    cursor: pointer;
    z-index: 100;
    transition: all 0.2s;
    box-shadow: 0 0 20px rgba(46, 204, 113, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.dropzone::after {
    content: "👇";
    font-size: 24px;
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.dropzone:hover {
    background: rgba(46, 204, 113, 0.6);
    transform: scale(1.1);
}