* {
  box-sizing: border-box;
}

/* Kotak yang digeser ke tepi tidak boleh memunculkan scrollbar: papan akan bergeser */
html,
body {
  overflow: hidden;
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  background: #111;
  color: #3d3528;
  font-family: "Segoe UI", system-ui, sans-serif;
}

/* Kamera memenuhi layar seperti cermin, papan di atasnya */
#camera {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  transform: scaleX(-1);
}

main {
  position: relative;
  z-index: 1;
  width: min(100vw - 32px, 100vh - 32px);
}

#hand-overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}

#hand-cursor {
  position: fixed;
  top: -14px;
  left: -14px;
  z-index: 2;
  width: 28px;
  height: 28px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

#hand-cursor.pinching {
  border-color: #2ee6a6;
  background: rgba(46, 230, 166, 0.7);
}

#hand-cursor[hidden] {
  display: none;
}

/* Video kemenangan tampil: tidak ada kursor tangan, rangka tangan, maupun pointer mouse */
.won,
.won * {
  cursor: none;
}

.won #hand-cursor,
.won #hand-overlay {
  display: none;
}

#mode-dialog {
  width: min(100vw - 32px, 420px);
  padding: 24px;
  border: 0;
  border-radius: 14px;
  background: #faf6ee;
  color: #2b2b2b;
}

#mode-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

#mode-dialog h2 {
  margin: 0 0 16px;
  font-size: 1.5rem;
  text-align: center;
}

#mode-dialog button {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #2b2b2b;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

#mode-dialog button + button {
  margin-top: 10px;
}

#mode-dialog button:hover {
  background: #e6e6e6;
}

#mode-dialog #camera-on {
  background: #2b2b2b;
  color: #fff;
}

#mode-dialog #camera-on:hover {
  background: #4a4a4a;
}

#mode-dialog strong,
#mode-dialog span {
  display: block;
}

#mode-dialog strong {
  font-size: 1.1rem;
}

#mode-dialog span {
  margin-top: 4px;
  font-size: 0.9rem;
  line-height: 1.4;
}

#board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.cell {
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  transition: box-shadow 0.1s;
}

.cell.target {
  box-shadow: 0 0 0 4px #2ee6a6;
}

.tile {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  font-size: clamp(2rem, 12vw, 3.5rem);
  font-weight: 700;
  cursor: grab;
  user-select: none;
  /* Agar geser di layar sentuh tidak ikut menggulir halaman */
  touch-action: none;
}

/* Agak tembus agar tangan tetap terlihat di belakang kotak */
.camera-on .tile:not(.dragging):not([data-value="32"]) {
  opacity: 0.8;
}

.tile img,
.tile video {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  object-fit: cover;
  pointer-events: none;
}

/* Video kemenangan menutupi seluruh layar */
.tile video.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 10;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  pointer-events: auto;
}

/* Foto orang dipotong dari atas agar kepala tidak terpotong */
.tile[data-value="1"] img,
.tile[data-value="2"] img {
  object-position: top;
}

/* Nampan melebar, jadi ditampilkan utuh */
.tile[data-value="8"] img {
  object-fit: contain;
}

.tile.dragging {
  position: relative;
  z-index: 1;
  cursor: grabbing;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.tile.merged {
  animation: pop 0.2s ease-out;
}

/* Tertahan transparan selama delay-nya, lalu muncul membesar */
.tile.spawn {
  animation: spawn 0.25s ease-out backwards;
}

.tile[data-value="1"],
.tile[data-value="2"],
.tile[data-value="4"],
.tile[data-value="8"] { background: #fffdf8; }

@keyframes pop {
  50% { transform: scale(1.15); }
}

@keyframes spawn {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile.merged,
  .tile.spawn {
    animation: none;
  }
}
