/* ============================================================
   Petualangan Ular Tangga 3D — tampilan untuk anak-anak
   Font besar, tombol besar, warna cerah, kontras tinggi.
   ============================================================ */

:root {
  --p1: #ff5d5d;
  --p2: #4aa8ff;
  --p3: #ffc93c;
  --p4: #5fd68a;
  --ink: #23304a;
  --ink-soft: #5a6b8c;
  --paper: #fffdf6;
  --shadow: 0 8px 0 rgba(35, 48, 74, 0.18), 0 14px 30px rgba(35, 48, 74, 0.22);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI Rounded", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: #7ecbff;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------------- Layar overlay ---------------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 32, 56, 0.55);
  backdrop-filter: blur(6px);
  z-index: 20;
  animation: fade-in 0.25s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  0% { transform: scale(0.8) translateY(20px); opacity: 0; }
  60% { transform: scale(1.03); opacity: 1; }
  100% { transform: scale(1) translateY(0); }
}

.panel {
  background: var(--paper);
  border-radius: 28px;
  padding: 22px 24px 26px;
  width: min(520px, 100%);
  max-height: 94vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: var(--shadow);
  border: 4px solid #fff;
  animation: pop-in 0.32s cubic-bezier(.2,1.3,.4,1);
}

.title {
  font-size: clamp(28px, 7vw, 42px);
  line-height: 1.05;
  margin: 4px 0 6px;
  color: #ff6b35;
  text-shadow: 0 3px 0 #ffd9c7;
}
.title span { color: #2a9d8f; text-shadow: 0 3px 0 #c8ece7; }

.subtitle {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 16px;
}

h2 { font-size: 26px; margin: 4px 0 14px; }

.field { margin-bottom: 16px; text-align: left; }
.field > label {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.hint { font-size: 13px; color: var(--ink-soft); margin: 8px 0 0; text-align: center; }

/* ---------------- Chip pilihan ---------------- */
.chip-row { display: flex; gap: 10px; }
.chip {
  flex: 1;
  padding: 12px 6px;
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  background: #eef3fb;
  border: 3px solid transparent;
  border-radius: 18px;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
  line-height: 1.1;
}
.chip:hover { transform: translateY(-2px); }
.chip.is-on {
  background: #fff2cf;
  border-color: #ffb703;
  box-shadow: 0 4px 0 #ffb703;
}

/* ---------------- Slot pemain ---------------- */
.slot-list { display: flex; flex-direction: column; gap: 8px; }
.slot {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f2f6fc;
  border-radius: 16px;
  padding: 8px 10px;
}
.slot-dot {
  width: 30px; height: 30px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.slot input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: 2px solid #dbe4f2;
  border-radius: 12px;
  padding: 8px 10px;
}
.slot-kind {
  font: inherit;
  font-size: 20px;
  padding: 6px 12px;
  border-radius: 12px;
  border: 2px solid #dbe4f2;
  background: #fff;
  cursor: pointer;
}

/* ---------------- Tombol ---------------- */
.btn {
  display: block;
  width: 100%;
  font: inherit;
  font-weight: 800;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}
.btn:active { transform: translateY(3px); }

.btn-big {
  font-size: 22px;
  padding: 16px;
  color: #fff;
  background: linear-gradient(#ffb43c, #ff8b1f);
  box-shadow: 0 6px 0 #d96f0d;
  margin-top: 6px;
}
.btn-big:active { box-shadow: 0 2px 0 #d96f0d; }

.btn-ghost {
  font-size: 17px;
  padding: 12px;
  margin-top: 10px;
  color: var(--ink-soft);
  background: #eef3fb;
}

.btn-online {
  background: linear-gradient(#5aa9ff, #2f7fe0);
  box-shadow: 0 6px 0 #1f5fac;
}
.btn-online:active { box-shadow: 0 2px 0 #1f5fac; }

.rules { text-align: left; font-size: 16px; line-height: 1.7; padding-left: 20px; margin: 0 0 18px; }
.rules li { margin-bottom: 6px; }

/* ---------------- Formulir online ---------------- */
.text-input {
  width: 100%;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: 2px solid #dbe4f2;
  border-radius: 14px;
  padding: 12px 14px;
}
.code-input {
  text-align: center;
  font-size: 30px;
  letter-spacing: 8px;
  text-transform: uppercase;
}

.or-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
}
.or-line::before, .or-line::after {
  content: '';
  flex: 1;
  height: 2px;
  background: #e6ecf7;
  border-radius: 2px;
}

.form-error {
  min-height: 20px;
  margin: 10px 0 0;
  font-size: 14px;
  font-weight: 700;
  color: #e05555;
}

/* ---------------- Ruang tunggu ---------------- */
.room-code {
  background: #fff2cf;
  border: 3px dashed #ffb703;
  border-radius: 18px;
  padding: 14px 10px;
  margin-bottom: 10px;
}
.room-code span {
  font-size: clamp(36px, 12vw, 54px);
  font-weight: 800;
  letter-spacing: 10px;
  color: #d96f0d;
}
.lobby-name {
  flex: 1;
  text-align: left;
  font-weight: 800;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button { pointer-events: auto; }

/* kartu pemain + banner giliran ditumpuk vertikal supaya tidak pernah bertindihan */
.top-stack {
  position: absolute;
  top: 10px; left: 10px; right: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.players-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.pcard {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 253, 246, 0.92);
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
  border: 3px solid transparent;
  transition: transform 0.2s, border-color 0.2s;
}
.pcard.is-turn { border-color: #ffb703; transform: scale(1.07); }
.pcard-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; }
.pcard-name { font-weight: 800; font-size: 14px; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard-pos { font-size: 13px; font-weight: 700; color: var(--ink-soft); }

.turn-banner {
  text-align: center;
  font-size: clamp(18px, 4.5vw, 24px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 8px rgba(0,0,0,.45);
  pointer-events: none;
}

.bottom-bar {
  position: absolute;
  left: 0; right: 0; bottom: 18px;
  display: flex;
  justify-content: center;
  padding: 0 16px;
}
.btn-roll {
  width: auto;
  min-width: 220px;
  font-size: 22px;
  padding: 16px 30px;
  color: #fff;
  background: linear-gradient(#5ad06f, #2fae4a);
  box-shadow: 0 6px 0 #1e8a37;
  animation: nudge 1.8s ease-in-out infinite;
}
.btn-roll:active { box-shadow: 0 2px 0 #1e8a37; }
.btn-roll:disabled {
  filter: grayscale(0.7) brightness(1.1);
  animation: none;
  cursor: default;
  opacity: 0.65;
}
@keyframes nudge {
  0%, 88%, 100% { transform: translateY(0); }
  93% { transform: translateY(-6px); }
}

.corner-tools {
  position: absolute;
  right: 10px; bottom: 90px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tool {
  width: 46px; height: 46px;
  font-size: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(255,253,246,.92);
  box-shadow: 0 4px 10px rgba(0,0,0,.2);
  cursor: pointer;
}

.toast {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  background: rgba(255, 253, 246, 0.96);
  border-radius: 22px;
  padding: 16px 26px;
  font-size: clamp(18px, 4.6vw, 26px);
  font-weight: 800;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 88vw;
  animation: pop-in 0.3s cubic-bezier(.2,1.3,.4,1);
}

/* ---------------- Kuis ---------------- */
.panel-quiz { padding-top: 18px; }
.quiz-reason {
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 14px;
  background: #eef7ff;
}
.quiz-reason.is-snake { background: #ffeaea; }
.quiz-reason.is-ladder { background: #eafbf0; }
.quiz-reason.is-star { background: #fff5d6; }

.quiz-timer {
  height: 12px;
  background: #e6ecf7;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}
#quiz-timer-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #5fd68a, #ffc93c, #ff6b6b);
  transform-origin: left;
}

.quiz-question {
  font-size: clamp(19px, 4.4vw, 25px);
  margin: 6px 0 16px;
  line-height: 1.35;
}

/* Satu pilihan per baris: jawaban kesehatan berupa kalimat, bukan angka. */
.quiz-options { display: grid; grid-template-columns: 1fr; gap: 9px; }
.qopt {
  font: inherit;
  font-size: clamp(15px, 3.6vw, 18px);
  font-weight: 700;
  line-height: 1.35;
  padding: 13px 16px;
  border-radius: 16px;
  border: none;
  text-align: left;
  color: var(--ink);
  background: #eef3fb;
  box-shadow: 0 4px 0 #cfdaea;
  cursor: pointer;
  transition: transform 0.1s;
  overflow-wrap: anywhere;
}
.qopt:active { transform: translateY(3px); box-shadow: 0 1px 0 #cfdaea; }
.qopt:disabled { cursor: default; color: var(--ink); }
.qopt.correct { background: #b6f2c9; box-shadow: 0 4px 0 #67c98a; }
.qopt.wrong { background: #ffc4c4; box-shadow: 0 4px 0 #e07d7d; }
.qopt.dim { opacity: 0.45; }

.quiz-feedback {
  margin-top: 14px;
  min-height: 30px;
  font-size: 19px;
  font-weight: 800;
}

/* ---------------- Menang ---------------- */
.panel-win { padding-top: 10px; }
.win-emoji { font-size: 64px; animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-10px) rotate(4deg); } }
.win-board { margin: 8px 0 16px; }
.win-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  background: #f2f6fc;
  border-radius: 14px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-weight: 800;
  font-size: 16px;
}
.win-row .rank { width: 28px; flex: 0 0 auto; text-align: left; }
.win-row .dot { width: 18px; height: 18px; border-radius: 50%; flex: 0 0 auto; }
.win-row .who {
  flex: 1 1 auto;
  min-width: 82px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.win-row .score { flex: 0 0 auto; color: var(--ink-soft); font-size: 14px; }

/* ---------------- Layar sempit ---------------- */
@media (max-width: 420px) {
  .panel { padding: 18px 16px 20px; border-radius: 22px; }
  /* kartu pemain dirampingkan supaya tetap muat satu baris */
  .players-bar { gap: 5px; }
  .pcard { padding: 4px 8px 4px 4px; gap: 5px; border-width: 2px; }
  .pcard-dot { width: 18px; height: 18px; }
  .pcard-name { font-size: 12px; max-width: 48px; }
  .pcard-pos { font-size: 11px; }
  /* skor pindah ke baris sendiri supaya nama tidak terpotong */
  .win-row .score { flex-basis: 100%; padding-left: 38px; }
  .quiz-options { gap: 8px; }
  .qopt { padding: 12px 13px; border-radius: 14px; }
  .quiz-reason { font-size: 15px; padding: 9px; }
  .btn-roll { min-width: 180px; font-size: 19px; padding: 14px 22px; }
  .corner-tools { bottom: 80px; }
}
