:root {
  --bg: #14111c;
  --panel: rgba(20, 16, 30, .92);
  --gold: #f0be28;
  --text: #eee6d8;
  --muted: #9a92a8;
  --accent: #3fc7dc;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
#stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
canvas#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0d0b12;
  display: block;
  box-shadow: 0 0 40px rgba(0,0,0,.6);
}

/* ------- bar atas (suara, layar penuh) */
#wrap { position: relative; }
#topbar {
  position: absolute; top: 4px; right: 6px;
  display: flex; gap: 6px; z-index: 30;
}
#topbar button {
  background: rgba(0,0,0,.45); color: #fff; border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px; font-size: 16px; width: 34px; height: 30px; cursor: pointer; padding: 0;
}
#topbar button:active { background: rgba(255,255,255,.2); }

/* ------- kontrol sentuh */
#touch { display: none; position: fixed; inset: 0; pointer-events: none; z-index: 20; }
body.touch #touch { display: block; }
#touch .pad, #touch .digs {
  position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); pointer-events: none;
}
#touch .pad { left: max(12px, env(safe-area-inset-left)); width: 168px; height: 168px; }
#touch .digs { right: max(12px, env(safe-area-inset-right)); display: flex; gap: 14px; }
.tb {
  pointer-events: auto; position: absolute;
  width: 56px; height: 56px; border-radius: 14px;
  border: 2px solid rgba(255,255,255,.35); background: rgba(255,255,255,.14);
  color: #fff; font-size: 22px; touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tb.active, .tb:active { background: rgba(240,190,40,.55); border-color: var(--gold); }
.tb.up { left: 56px; top: 0; } .tb.left { left: 0; top: 56px; }
.tb.right { left: 112px; top: 56px; } .tb.down { left: 56px; top: 112px; }
.tb.dig { position: static; width: 74px; height: 74px; border-radius: 50%; font-size: 20px; background: rgba(63,199,220,.22); }

/* ------- lapisan menu */
#overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(8,6,12,.55); z-index: 25;
}
#overlay[hidden] { display: none; }
.panel {
  background: var(--panel); border: 2px solid rgba(240,190,40,.5); border-radius: 14px;
  padding: 22px 28px; max-width: 92vw; max-height: 92vh; overflow: auto; text-align: center;
  min-width: 300px; box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.panel[hidden] { display: none; }
/* ------- layar pembuka: hero + kredit */
.panel.title { padding: 18px 26px 14px; }
.title-row { display: flex; align-items: center; gap: 22px; }
#hero { height: 250px; width: auto; image-rendering: auto; filter: drop-shadow(0 8px 12px rgba(0,0,0,.6)); animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.title-main { text-align: center; }
.credit {
  display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,.12); font-size: 12px; color: var(--muted); line-height: 1.6; text-align: left;
}
.credit img { height: 64px; width: auto; }
.credit b { color: var(--text); }
.credit a { color: var(--accent); text-decoration: none; }
@media (max-width: 640px), (max-height: 520px) {
  #hero { height: 150px; }
  .title-row { gap: 12px; }
  .credit { font-size: 11px; }
  .credit img { height: 44px; }
}
@media (max-width: 480px) { #hero { display: none; } }

h1 { margin: 0 0 6px; font-size: 44px; letter-spacing: 4px; color: var(--gold); text-shadow: 3px 3px 0 #7a4a10; line-height: 1; }
h1 span { color: var(--accent); text-shadow: 3px 3px 0 #135a66; margin-left: 10px; }
h2 { margin: 0 0 12px; color: var(--gold); letter-spacing: 2px; }
.sub { margin: 4px 0 14px; color: var(--muted); }
.about { font-size: 12px; color: var(--muted); line-height: 1.5; margin: -6px 0 8px; max-width: 420px; }
.about + .about { margin-top: -2px; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 13px; }
.btns { display: flex; flex-direction: column; gap: 8px; align-items: center; margin: 10px 0; }
button { font: inherit; cursor: pointer; }
.btns button, #score-form button {
  background: #2a2438; color: var(--text); border: 2px solid rgba(255,255,255,.2);
  border-radius: 10px; padding: 8px 18px; min-width: 200px; letter-spacing: 1px;
}
.btns button.big, #score-form button.big { background: var(--gold); color: #2a1a00; border-color: #fff3c0; font-weight: 700; font-size: 18px; }
.btns button:hover { filter: brightness(1.15); }
.help { font-size: 12px; color: var(--muted); line-height: 1.7; margin: 10px 0 0; }
#level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 6px 0 12px; }
#level-grid button {
  background: #2a2438; color: var(--text); border: 2px solid rgba(255,255,255,.2); border-radius: 8px;
  padding: 10px 0; font-weight: 700;
}
#level-grid .set-title { grid-column: 1 / -1; color: var(--gold); letter-spacing: 2px; font-size: 12px; margin: 6px 0 -2px; text-align: left; }
#level-grid .set-title:first-child { margin-top: 0; }
#level-grid button.done { border-color: var(--gold); color: var(--gold); }
#level-grid button:disabled { opacity: .35; cursor: default; }
#score-list { text-align: left; margin: 0 0 10px; padding-left: 28px; min-width: 260px; max-height: 50vh; overflow: auto; }
#score-list li { padding: 3px 0; border-bottom: 1px dashed rgba(255,255,255,.08); }
#score-list b { color: var(--gold); float: right; }
#score-form { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; flex-wrap: wrap; }
#score-form input {
  font: inherit; padding: 8px 12px; border-radius: 10px; border: 2px solid rgba(255,255,255,.25);
  background: #1a1524; color: var(--text); width: 180px; text-align: center; font-size: 16px;
}
#score-form button { min-width: 140px; }
#score-form[hidden] { display: none; }
#ios-hint {
  position: fixed; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.8); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 13px; z-index: 40;
}
#ios-hint[hidden] { display: none; }

@media (orientation: portrait) {
  body.touch #stage { align-items: flex-start; padding-top: max(8px, env(safe-area-inset-top)); }
}

@media (max-height: 520px) {
  .panel { padding: 12px 18px; }
  h1 { font-size: 30px; }
  .help, .about { display: none; }
  .btns { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .btns button { min-width: 140px; padding: 6px 12px; }
}
