/* ==========================================================================
   1. GLOBAL RESET & BASE
   ========================================================================== */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, sans-serif; }

body { 
  background: url('background.jpg') center center / cover no-repeat; 
  background-color: #0f172a;
  height: 100vh; width: 100vw; display: flex; justify-content: center; align-items: center; 
  overflow: hidden; color: #f8fafc; 
}

.glass-panel {
  background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.1); box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

/* ==========================================================================
   2. AVATAR SCREEN
   ========================================================================== */
.screen-card {
  background: rgba(15, 23, 42, 0.9); backdrop-filter: blur(16px);
  padding: 32px; border-radius: 24px; width: 90%; max-width: 460px;
  text-align: center; border: 1px solid rgba(255,255,255,0.1); box-shadow: 0 20px 40px rgba(0,0,0,0.6);
}
.logo-title-img { width: 80px; height: 80px; margin-bottom: 10px; border-radius: 20px; }
.logo-title { font-size: 2rem; font-weight: 800; color: #38bdf8; margin-bottom: 4px; }
.logo-title-small { font-size: 1.4rem; font-weight: 800; color: #38bdf8; }
.subtitle { color: #94a3b8; font-size: 0.95rem; margin-bottom: 24px; }

.avatar-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.avatar-card { background: rgba(255,255,255,0.03); border-radius: 16px; padding: 10px; cursor: pointer; border: 2px solid transparent; transition: all 0.2s; }
.avatar-card:hover { transform: translateY(-3px); background: rgba(255,255,255,0.08); }
.avatar-card.selected { border-color: #38bdf8; background: rgba(56,189,248,0.15); box-shadow: 0 0 20px rgba(56,189,248,0.3); }
.avatar-card canvas { width: 100%; height: auto; border-radius: 50%; background: rgba(0,0,0,0.2); }

.input-group input, .input-styled { 
  width: 100%; padding: 14px 16px; border-radius: 12px; border: 2px solid #334155; 
  background: #0f172a; color: #fff; font-size: 1.05rem; text-align: center; outline: none; margin-bottom: 16px; 
}
.input-group input:focus, .input-styled:focus { border-color: #38bdf8; }

/* ==========================================================================
   3. LOBBY SCREEN
   ========================================================================== */
.lobby-layout { width: 100vw; height: 100vh; display: flex; flex-direction: column; padding: 20px; max-width: 900px; }
.lobby-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; background: rgba(15, 23, 42, 0.9); border-radius: 16px; margin-bottom: 20px; border: 1px solid rgba(255,255,255,0.1); }
.btn-create-room { background: #fff; color: #0f172a; padding: 10px 20px; border: none; border-radius: 12px; font-weight: bold; cursor: pointer; transition: all 0.2s; }
.btn-create-room:hover { background: #e2e8f0; transform: translateY(-2px); }

.room-list-container { flex: 1; background: rgba(15, 23, 42, 0.7); border-radius: 16px; padding: 20px; overflow-y: auto; border: 1px solid rgba(255,255,255,0.05); }
.room-list { display: flex; flex-direction: column; gap: 12px; }
.empty-room-msg { text-align: center; color: #94a3b8; margin-top: 40px; font-style: italic; }
.room-item { display: flex; justify-content: space-between; align-items: center; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.1); padding: 16px 20px; border-radius: 12px; transition: all 0.2s; }
.room-item:hover { background: rgba(255,255,255,0.12); transform: translateX(5px); }
.room-info-text h4 { color: #f8fafc; font-size: 1.1rem; margin-bottom: 4px; }
.room-info-text p { color: #94a3b8; font-size: 0.85rem; }
.badge-status { font-weight: bold; padding: 2px 8px; border-radius: 6px; font-size: 0.78rem; display: inline-block; }
.badge-status.menunggu { background: rgba(34,197,94,0.2); color: #4ade80; }
.badge-status.penuh { background: rgba(239,68,68,0.2); color: #f87171; }
.badge-status.bermain { background: rgba(245,158,11,0.2); color: #fbbf24; }
.btn-join { background: #10b981; color: #fff; padding: 10px 20px; border: none; border-radius: 10px; font-weight: bold; cursor: pointer; }
.btn-join:disabled { background: #475569; cursor: not-allowed; opacity: 0.6; }

/* ==========================================================================
   4. MODALS & SCOREBOARD
   ========================================================================== */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.85); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.modal-content { padding: 32px; border-radius: 20px; text-align: center; max-width: 400px; width: 90%; }
.modal-content h3 { font-size: 1.4rem; color: #f8fafc; margin-bottom: 20px; }
.form-group { text-align: left; margin-bottom: 20px; }
.form-group label { display: block; font-size: 0.85rem; color: #94a3b8; margin-bottom: 8px; font-weight: 600; }
.mode-buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.btn-mode { padding: 10px; background: rgba(255,255,255,0.05); color: #fff; border: 1px solid rgba(255,255,255,0.2); border-radius: 10px; font-weight: bold; cursor: pointer; }
.btn-mode.active { background: #38bdf8; border-color: #38bdf8; color: #0f172a; }
.checkbox-group { display: flex; align-items: center; gap: 10px; cursor: pointer; }

.btn-primary { width: 100%; padding: 14px; background: linear-gradient(135deg, #0284c7, #0369a1); color: #fff; border: none; border-radius: 12px; font-weight: bold; font-size: 1.05rem; cursor: pointer; box-shadow: 0 4px 15px rgba(2,132,199,0.4); }
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 10px; }
.btn-secondary { padding: 10px 18px; background: #334155; color: #fff; border: none; border-radius: 10px; cursor: pointer; font-weight: 600; width: 100%; }
.btn-danger { padding: 10px 18px; background: #ef4444; color: #fff; border: none; border-radius: 10px; cursor: pointer; font-weight: 600; }

.score-modal-content { max-width: 460px; width: 92%; animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes popIn { 0% { transform: scale(0.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.surrender-badge { background: rgba(239,68,68,0.2); border: 1px solid #ef4444; color: #f87171; font-weight: bold; padding: 6px 16px; border-radius: 20px; display: inline-block; margin-bottom: 12px; font-size: 0.85rem; }
.winner-announce { font-size: 1.5rem; color: #facc15; margin-bottom: 20px; text-shadow: 0 0 10px rgba(250,204,21,0.3); }
.scoreboard-list { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; text-align: left;}
.scoreboard-item { display: flex; justify-content: space-between; align-items: center; background: rgba(15,23,42,0.6); padding: 10px 16px; border-radius: 10px; border-left: 4px solid #38bdf8; }
.scoreboard-item.rank-1 { border-left-color: #facc15; background: rgba(250,204,21,0.1); }
.scoreboard-item .rank-info { font-weight: bold; font-size: 0.95rem; color: #f8fafc; }
.scoreboard-item .tile-info { font-weight: bold; color: #38bdf8; font-size: 0.9rem; }

/* ==========================================================================
   5. GAME ARENA & DADU 3D SOLID DI TENGAH
   ========================================================================== */
.game-layout-wrapper { display: flex; flex-direction: column; width: 100vw; height: 100vh; padding: 10px; max-width: 800px; margin: 0 auto; }

.board-container { flex: 1; min-height: 0; display: flex; justify-content: center; align-items: center; margin-bottom: 10px; position: relative; }
#boardCanvas { 
  background: #1e293b; border-radius: 12px; 
  box-shadow: 0 10px 40px rgba(0,0,0,0.8);
  object-fit: contain; width: 100%; height: 100%; max-height: 100%; max-width: 100%; aspect-ratio: 1/1; 
}

.waiting-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15,23,42,0.85); backdrop-filter: blur(5px); border-radius: 12px; display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 10; }
.loader-spinner { border: 4px solid rgba(255,255,255,0.1); border-top: 4px solid #38bdf8; border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin-bottom: 16px; }

/* Bottom Control Panel */
.bottom-control-panel { 
  flex: 0 0 auto; display: flex; justify-content: space-between; align-items: flex-end; 
  padding: 10px 16px; z-index: 90; gap: 10px; border-radius: 16px; 
}
.player-roster { display: flex; gap: 8px; flex: 1; overflow-x: auto; padding-bottom: 2px; }

.roster-card { display: flex; flex-direction: column; align-items: center; position: relative; transition: all 0.2s; opacity: 0.6; }
.roster-card.active-turn { opacity: 1; transform: translateY(-4px); }
.roster-card.finished { opacity: 0.4; filter: grayscale(100%); }

.roster-avatar-wrap {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid #0f172a;
  background: #1e293b; display: flex; justify-content: center; align-items: center;
  z-index: 2; position: relative; top: 6px;
}
.roster-card.active-turn .roster-avatar-wrap { border-color: #facc15; box-shadow: 0 0 12px rgba(250,204,21,0.6); }
.roster-avatar-wrap canvas { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

.roster-name-wrap {
  background: #000; color: #fff; font-size: 0.7rem; font-weight: bold;
  padding: 3px 8px; border-radius: 10px; min-width: 60px; text-align: center;
  z-index: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.roster-card.active-turn .roster-name-wrap { color: #facc15; }

/* Action Icon Buttons */
.action-buttons { display: flex; gap: 8px; align-items: center; margin-bottom: 2px; }
.icon-btn { 
  width: 46px; height: 46px; border-radius: 12px; font-size: 1.4rem; 
  display: flex; justify-content: center; align-items: center; 
  border: 1px solid rgba(255,255,255,0.2); cursor: pointer; transition: all 0.2s; 
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.icon-btn:hover:not(:disabled) { transform: translateY(-3px); }
.icon-btn:disabled { background: #334155; opacity: 0.5; cursor: not-allowed; border-color: transparent; filter: grayscale(100%); }

.btn-dice-icon { background: linear-gradient(135deg, #22c55e, #16a34a); text-shadow: 0 2px 4px rgba(0,0,0,0.4); }
.btn-dice-icon.active-roll { box-shadow: 0 0 15px rgba(34,197,94,0.8); border-color: #4ade80; animation: pulse 1s infinite; }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.08); } 100% { transform: scale(1); } }

.btn-chat-icon { background: linear-gradient(135deg, #0284c7, #0369a1); }
.btn-exit-icon { background: linear-gradient(135deg, #ef4444, #dc2626); }

#chatInput { padding: 10px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.15); background: rgba(0,0,0,0.3); color: #fff; font-size: 0.95rem; outline: none; }
#chatInput:focus { border-color: #38bdf8; background: rgba(0,0,0,0.5); }

/* --- CSS DADU 3D SOLID DI TENGAH PERMAINAN --- */
.dice-overlay { 
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
  display: flex; justify-content: center; align-items: center; 
  z-index: 80; pointer-events: none; background: rgba(0,0,0,0.45); backdrop-filter: blur(3px);
}

.scene {
  width: 110px;
  height: 110px;
  perspective: 700px;
}

.cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-22deg) rotateY(45deg);
  transition: transform 1.2s cubic-bezier(0.25, 1, 0.5, 1);
}

.face {
  position: absolute;
  width: 110px;
  height: 110px;
  background: #e74c3c;
  border: 2px solid #c0392b;
  border-radius: 18px;
  box-sizing: border-box;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 12px;
  box-shadow: inset 0 0 15px rgba(0,0,0,0.25), 0 0 10px rgba(0,0,0,0.4);
}

/* Posisi 3D Sisi Dadu */
.front  { transform: rotateY(  0deg) translateZ(55px); }
.back   { transform: rotateY(180deg) translateZ(55px); }
.right  { transform: rotateY( 90deg) translateZ(55px); }
.left   { transform: rotateY(-90deg) translateZ(55px); }
.top    { transform: rotateX( 90deg) translateZ(55px); }
.bottom { transform: rotateX(-90deg) translateZ(55px); }

/* Titik Dot Dadu */
.dot {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: #ffffff;
  align-self: center;
  justify-self: center;
  box-shadow: inset 1px 1px 3px rgba(0,0,0,0.4);
}

.f1 .dot1 { grid-area: 2 / 2; }

.f2 .dot1 { grid-area: 1 / 1; }
.f2 .dot2 { grid-area: 3 / 3; }

.f3 .dot1 { grid-area: 1 / 1; }
.f3 .dot2 { grid-area: 2 / 2; }
.f3 .dot3 { grid-area: 3 / 3; }

.f4 .dot1 { grid-area: 1 / 1; }
.f4 .dot2 { grid-area: 1 / 3; }
.f4 .dot3 { grid-area: 3 / 1; }
.f4 .dot4 { grid-area: 3 / 3; }

.f5 .dot1 { grid-area: 1 / 1; }
.f5 .dot2 { grid-area: 1 / 3; }
.f5 .dot3 { grid-area: 2 / 2; }
.f5 .dot4 { grid-area: 3 / 1; }
.f5 .dot5 { grid-area: 3 / 3; }

.f6 .dot1 { grid-area: 1 / 1; }
.f6 .dot2 { grid-area: 1 / 3; }
.f6 .dot3 { grid-area: 2 / 1; }
.f6 .dot4 { grid-area: 2 / 3; }
.f6 .dot5 { grid-area: 3 / 1; }
.f6 .dot6 { grid-area: 3 / 3; }