/* HP tegak: lawan di atas, papan di tengah, dadu di bawah */
.ludo.table {
  height: var(--app-h);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: 'bar' 'seats' 'board' 'control';
  gap: 6px;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
}
.ludo .topbar { grid-area: bar; }
.seats { grid-area: seats; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.ludo .avatar { background: var(--c); color: var(--on-c, #fff); }
.ludo .is-active .avatar { background: var(--c); color: var(--on-c, #fff); }
.ludo .seat.is-active { border-color: var(--c); box-shadow: 0 0 0 1px var(--c); }
.ludo .is-active .avatar::before { background: conic-gradient(var(--c) calc(var(--p) * 360deg), rgba(255, 255, 255, .12) 0); }

.board-wrap {
  grid-area: board;
  min-height: 0;
  min-width: 0;
  display: grid;
  place-items: center;
  position: relative;
  width: 100%;
  height: 100%;
}
#board { display: block; width: 100%; height: 100%; max-width: 100%; max-height: 100%; touch-action: manipulation; }

/* Wadah 3D Three.js */
.board-3d-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  overflow: hidden;
  touch-action: none;
}
.board-3d-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  outline: none;
}
.board-wrap.mode-3d #board {
  display: none !important;
}
.board-wrap.mode-3d .board-3d-container {
  display: block !important;
}
.board-wrap.mode-2d #board {
  display: block !important;
}
.board-wrap.mode-2d .board-3d-container {
  display: none !important;
}

/* Tombol atur ulang sudut kamera di pojok atas wadah 3D */
.btn-cam-reset {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  background: rgba(21, 18, 14, 0.72);
  color: var(--ivory, #f6efdf);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}
.btn-cam-reset:hover {
  background: rgba(21, 18, 14, 0.92);
  border-color: var(--amber, #f2a93b);
  color: var(--amber, #f2a93b);
}
.quad { transition: filter .2s ease; }
.quad.active { filter: brightness(1.18) saturate(1.15); }
.token { transition: transform .1s linear; cursor: default; }
.token-shadow { fill: rgba(0, 0, 0, .28); }
.token-hit { fill: transparent; }
.token-ring { fill: none; stroke: #1c1712; stroke-width: 1.2; opacity: 0; }
.token.movable { cursor: pointer; }
.token.movable .token-ring { opacity: 1; animation: ring .8s ease-in-out infinite alternate; }
@keyframes ring { from { stroke-width: .7; } to { stroke-width: 2.4; } }

.control {
  grid-area: control;
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; align-items: center;
  padding: 10px 12px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
}
.control-main { display: grid; gap: 6px; min-height: 64px; align-content: center; }
.ludo-status { font-weight: 600; font-size: 15px; line-height: 1.3; }
.ludo-status.mine { color: var(--amber); font-weight: 700; }
#rollBtn { width: 100%; }
.control .timer { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.timer-fill { height: 100%; width: 0; background: var(--amber); }
.timer-fill.low { background: var(--danger); }

.die {
  width: 64px; height: 64px; padding: 0; border-radius: 14px; background: var(--ivory);
  box-shadow: 0 4px 0 #bdae90, 0 8px 18px rgba(0, 0, 0, .45);
  transition: transform .15s ease, box-shadow .15s ease;
  user-select: none; -webkit-user-select: none;
}
.die svg { display: block; width: 100%; height: 100%; }
.die circle { fill: var(--pip); }
.die.can { cursor: pointer; outline: 3px solid var(--amber); outline-offset: 2px; }
.die.can:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 6px 0 #bdae90, 0 12px 24px rgba(242, 169, 59, .35);
}
.die.can:active {
  transform: translateY(2px) scale(0.97);
  box-shadow: 0 2px 0 #bdae90, 0 4px 8px rgba(0, 0, 0, .4);
}
.die.old { opacity: .45; }
.die.rolling { animation: diceRoll3D .55s cubic-bezier(0.25, 1, 0.5, 1); }
@keyframes diceRoll3D {
  0% { transform: scale(0.9) rotate(0deg) translateY(0); }
  20% { transform: scale(1.18) rotate(-32deg) translateY(-16px); }
  45% { transform: scale(1.12) rotate(35deg) translateY(-8px); }
  65% { transform: scale(1.06) rotate(-18deg) translateY(-4px); }
  85% { transform: scale(0.96) rotate(6deg) translateY(1px); }
  100% { transform: scale(1) rotate(0deg) translateY(0); }
}
.die.lucky-burst {
  animation: luckyGlow .6s ease-out;
}
@keyframes luckyGlow {
  0% { transform: scale(1.22); box-shadow: 0 0 24px #f2a93b, 0 0 40px #f2a93b; }
  100% { transform: scale(1); box-shadow: 0 4px 0 #bdae90, 0 8px 18px rgba(0, 0, 0, .45); }
}

/* 5–6 pemain di HP: kartu pemain 3 per baris */
.seats.many { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* HP mendatar: papan di kiri, sisanya di kanan */
@media (max-height: 520px) and (orientation: landscape) {
  .ludo.table {
    grid-template-columns: minmax(0, calc(var(--app-h) - 16px)) minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: 'board bar' 'board seats' 'board control';
  }
  .control { align-self: end; }
  .seats { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seats .seat { padding: 4px 8px; }
  .seats .avatar { width: 30px; height: 30px; font-size: 14px; }
}

/* Layar bandar: tiap pemain duduk di samping kandang warnanya */
@media (min-width: 900px) {
  .ludo.table.is-dealer {
    max-width: 1500px; margin: 0 auto; padding: 12px 16px 16px; gap: 12px 24px;
    grid-template-columns: minmax(200px, 1fr) minmax(0, calc(var(--app-h) - 90px)) minmax(200px, 1fr);
    grid-template-rows: auto repeat(3, minmax(0, 1fr));
    grid-template-areas: 'bar bar bar' 'q0 board q1' 'status board die' 'q3 board q2';
  }
  .is-dealer .seats, .is-dealer .control, .is-dealer .control-main { display: contents; }
  .is-dealer .slot { align-self: start; }
  .is-dealer .slot.q2, .is-dealer .slot.q3 { align-self: end; }
  .is-dealer .slot.q0 { grid-area: q0; }
  .is-dealer .slot.q1 { grid-area: q1; }
  .is-dealer .slot.q2 { grid-area: q2; }
  .is-dealer .slot.q3 { grid-area: q3; }
  .is-dealer .seat { padding: 14px; }
  .is-dealer .seat-name { font-size: 18px; }
  .is-dealer .seat-sub { font-size: 15px; }
  .is-dealer .ludo-status {
    grid-area: status; align-self: center;
    font-family: var(--display); font-weight: 800; font-size: 28px; line-height: 1.15;
  }
  .is-dealer .die { grid-area: die; align-self: center; justify-self: center; width: 128px; height: 128px; border-radius: 26px; }
  .is-dealer .timer { display: none; }

  /* Papan segi enam: tiap pemain di dekat kandangnya (kiri atas, atas, kanan atas, kanan bawah, bawah, kiri bawah) */
  .ludo.table.is-dealer.arms-6 {
    gap: 8px 24px;
    grid-template-columns: minmax(200px, 1fr) minmax(0, calc((var(--app-h) - 200px) * .87)) minmax(200px, 1fr);
    grid-template-rows: auto auto repeat(3, minmax(0, 1fr)) auto;
    grid-template-areas: 'bar bar bar' '. q1 .' 'q0 board q2' 'status board die' 'q5 board q3' '. q4 .';
  }
  .is-dealer.arms-6 .slot.q1, .is-dealer.arms-6 .slot.q4 { justify-self: center; width: 260px; align-self: center; }
  .is-dealer .slot.q4 { grid-area: q4; }
  .is-dealer .slot.q5 { grid-area: q5; align-self: end; }
  .is-dealer.arms-6 .slot.q3 { align-self: end; }
  .is-dealer.arms-6 .slot.q2 { align-self: start; }
}
.is-dealer #rollBtn { display: none; }

/* Layar bandar: Sari duduk di tempat tulisan status (kiri tengah). */
@media (min-width: 900px) {
  .ludo.is-dealer:not(.ular) .ludo-status { display: none; }
  .ludo.is-dealer:not(.ular) .host.on {
    position: static; grid-area: status; align-self: center; width: auto; min-width: 0;
  }
  .ludo.is-dealer:not(.ular) .host-figure { width: 120px; }
  .ludo.is-dealer:not(.ular) .host-bubble { margin-bottom: 40px; font-size: 15px; }
}

/* Tombol main otomatis */
.auto-btn { width: 100%; }
.auto-btn[aria-pressed='true'] { background: #2f6fc6; border-color: #2f6fc6; color: #fff; font-weight: 700; }
.is-dealer .auto-btn { display: none; }
.seat-sub .bot { color: #8fb8ff; font-weight: 700; }
