/* ====== Reset & latar halaman ====== */
html, body {
  margin: 0;
  height: 100%;
  background: #15161e;            /* latar gelap di sekitar kanvas */
  overflow: hidden;              /* cegah scroll saat main */
  font-family: 'Trebuchet MS', Verdana, sans-serif;
}

/* ====== Pembungkus penengah ====== */
#game-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ====== Panggung (bingkai seukuran kanvas) ======
   Ukuran dihitung eksplisit dari tinggi/lebar layar dengan rasio 9:16.
   container-type: size -> mengaktifkan unit cqw/cqh untuk overlay,
   sehingga teks overlay ikut menskala bersama kanvas. */
#stage {
  --h: min(96vh, calc(96vw * 16 / 9));
  height: var(--h);
  width: calc(var(--h) * 9 / 16);
  position: relative;
  container-type: size;
  border-radius: 8px;
  overflow: hidden;              /* rapikan sudut untuk kanvas + overlay */
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.55);
}

/* ====== Kanvas game ====== */
canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #4cc3e0;           /* warna langit (terlihat sebelum render) */
  image-rendering: pixelated;    /* jaga ketajaman pixel-art saat diperbesar */
  image-rendering: crisp-edges;
  touch-action: manipulation;    /* hilangkan delay sentuh di mobile */
  cursor: pointer;
}

/* ====== Dasar overlay ====== */
.overlay {
  position: absolute;
  color: #fff;
  font-family: inherit;
}
/* Penyembunyian yang pasti menang atas display:flex/block di bawah */
.overlay[hidden] { display: none !important; }

/* ====== Mini leaderboard (pojok kanan atas, layar awal) ====== */
#mini-board {
  top: 3cqw;
  right: 3cqw;
  width: 44cqw;                  /* ~158px pada lebar logis 360 */
  background: rgba(0, 0, 0, 0.34);
  border-radius: 3cqw;
  padding: 2.5cqw 3cqw;
  pointer-events: none;          /* murni tampilan, tak menghalangi input */
  display: block;
}
#mini-board h2 {
  margin: 0 0 1.5cqw;
  font-size: 4.4cqw;
  text-align: center;
}
#mini-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
#mini-list li {
  display: flex;
  align-items: baseline;
  gap: 1.6cqw;
  font-size: 3.8cqw;
  line-height: 1.55;
}
#mini-list .rk { width: 4.5cqw; flex: none; color: #ffd24a; font-weight: 700; }
/* TRIM nama panjang: potong dgn ellipsis supaya tak melebihi lebar panel */
#mini-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#mini-list .sc { flex: none; font-weight: 700; }
#mini-list .muted { justify-content: center; opacity: 0.8; }

/* ====== Layar penuh (start & game over) ====== */
.overlay.screen {
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 20, 0.45);
  pointer-events: auto;
}
.panel {
  width: 80cqw;
  box-sizing: border-box;
  padding: 6cqw 6cqw 5cqw;
  background: rgba(0, 0, 0, 0.5);
  border: 0.6cqw solid rgba(255, 255, 255, 0.16);
  border-radius: 4cqw;
  text-align: center;
}
.panel h1 {
  margin: 0 0 1.5cqw;
  font-size: 9cqw;
  color: #ffd24a;
  letter-spacing: 0.5px;
  text-shadow: 0 0.6cqw 0 rgba(0, 0, 0, 0.4);
}
.panel .sub { margin: 0 0 4cqw; font-size: 4cqw; opacity: 0.85; }

/* Input nama */
#name-input {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 3.5cqw;
  padding: 3.2cqw;
  font-size: 5cqw;
  font-family: inherit;
  text-align: center;
  border: none;
  border-radius: 2.5cqw;
  outline: none;
}

/* Tombol */
.panel button {
  font-family: inherit;
  font-weight: 700;
  font-size: 4.6cqw;
  color: #3a2a10;
  background: #ffd24a;
  border: none;
  border-radius: 2.5cqw;
  padding: 3.2cqw 5cqw;
  cursor: pointer;
  transition: transform 0.06s ease, filter 0.12s ease;
}
.panel button:hover { filter: brightness(1.06); }
.panel button:active { transform: translateY(1px) scale(0.98); }
.panel button.ghost {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

/* Baris skor di game over */
.score-row {
  display: flex;
  justify-content: center;
  gap: 8cqw;
  margin: 0 0 3cqw;
}
.score-row .label { display: block; font-size: 3.4cqw; opacity: 0.8; }
.score-row .big { display: block; font-size: 8cqw; font-weight: 700; color: #ffd24a; }

/* Judul & daftar leaderboard di game over */
.board-title { margin: 1cqw 0 2cqw; font-size: 4.6cqw; }
ol.board {
  margin: 0 0 2cqw;
  padding: 0;
  list-style: none;
  text-align: left;
  max-height: 30cqh;             /* batasi tinggi -> daftar panjang bisa di-scroll */
  overflow-y: auto;
  overscroll-behavior: contain;  /* cegah scroll halaman ikut tergeser */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.4) transparent;
}
ol.board::-webkit-scrollbar { width: 2cqw; }
ol.board::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.35); border-radius: 2cqw; }
ol.board li {
  display: flex;
  align-items: baseline;
  gap: 2cqw;
  font-size: 4.2cqw;
  line-height: 1.7;
  padding: 0 1cqw;
  border-radius: 1.5cqw;
}
ol.board li:nth-child(odd) { background: rgba(255, 255, 255, 0.06); }
ol.board .rk { width: 8cqw; flex: none; color: #ffd24a; font-weight: 700; }
ol.board .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ol.board .sc { flex: none; font-weight: 700; }
ol.board .muted { justify-content: center; opacity: 0.8; padding: 2cqw 0; }

/* Baris milik pemain: di-highlight & "sticky" menempel di bawah saat
   peringkatnya jauh sehingga tetap terlihat tanpa harus scroll. */
ol.board li.me {
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: #ffd24a;           /* solid (menutup baris di belakang saat menempel) */
  color: #3a2a10;
  font-weight: 700;
  box-shadow: 0 -0.6cqw 1.6cqw rgba(0, 0, 0, 0.4);
}
ol.board li.me .rk,
ol.board li.me .sc { color: #3a2a10; }
ol.board li.me.pinned { border-top: 0.4cqw dashed rgba(58, 42, 16, 0.45); }

/* Pesan status kecil (mis. gagal kirim / belum dikonfigurasi) */
.msg { min-height: 3.6cqw; margin: 1cqw 0 0; font-size: 3.4cqw; color: #ffb3a7; }

/* Baris tombol game over */
.btn-row { display: flex; gap: 3cqw; justify-content: center; margin-top: 3cqw; }
.btn-row button { flex: 1; }

/* Footer di dalam popup: promo kelas + kredit */
.footer { margin-top: 4cqw; }

/* CTA promo kelas (tujuan utama: ajak ikut kelas) */
.promo {
  margin: 0 0 2cqw;
  font-size: 3.2cqw;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.88);
}
.promo a {
  display: inline-block;
  margin-left: 1cqw;
  padding: 0.8cqw 2.4cqw;
  background: #ffd24a;
  color: #3a2a10;
  font-weight: 700;
  border-radius: 2cqw;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.12s ease;
}
.promo a:hover { filter: brightness(1.08); }

/* Kredit (ngelink ke Instagram) */
.credit {
  display: block;
  font-size: 3.2cqw;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: color 0.12s ease;
}
.credit:hover { color: #ffd24a; text-decoration: underline; }
