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

:root {
  --bg: #0a0e1a;
  --panel: rgba(16, 22, 44, 0.92);
  --border: rgba(140, 180, 255, 0.4);
  --yellow: #ffd54a;
  --blue: #6ad2ff;
  --text: #f3f6ff;
  --dim: #b7c3e0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #16204a 0%, #070a15 70%);
  color: var(--text);
  font-family: 'Baloo 2', 'Comic Sans MS', 'Segoe UI Rounded', -apple-system,
    BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 18px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------- HUD ---------- */
#hud {
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}
.hud-left { display: flex; flex-direction: column; }
#level-badge {
  font-size: 24px;
  font-weight: 800;
  color: var(--yellow);
}
#chapter-text { font-size: 15px; color: var(--dim); }
.hud-right { display: flex; align-items: center; gap: 8px; }
#star-count {
  font-size: 20px;
  font-weight: 800;
  color: var(--yellow);
  margin-right: 4px;
}
.hud-btn {
  width: 46px;
  height: 46px;
  font-size: 22px;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: rgba(120, 160, 255, 0.12);
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.hud-btn:hover { background: rgba(120, 160, 255, 0.25); }
.hud-btn:active { transform: scale(0.92); }
.hud-btn.off { opacity: 0.4; }

/* ---------- board ---------- */
#board-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
#scene3d {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 0 50px rgba(80, 120, 220, 0.3);
}
#scene3d canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}
#confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

/* ---------- d-pad ---------- */
#dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 0 18px;
}
.dpad-mid { display: flex; gap: 68px; }
.dbtn {
  width: 66px;
  height: 66px;
  font-size: 30px;
  color: #10233f;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--blue), #4aa8ff);
  box-shadow: 0 5px 0 rgba(0, 90, 160, 0.6);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
.dbtn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(0, 90, 160, 0.6);
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 7, 16, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10;
  padding: 20px;
}
.overlay.hidden { display: none; }
@keyframes pop-in {
  0% { transform: scale(0.5) rotate(-4deg); opacity: 0; }
  55% { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}
#win-screen:not(.hidden) .panel,
#final-screen:not(.hidden) .panel {
  animation: pop-in 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes wiggle {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}
#win-title { display: inline-block; animation: wiggle 0.6s ease-in-out 0.3s 2; }
.panel {
  background: var(--panel);
  border: 3px solid var(--border);
  border-radius: 28px;
  padding: 32px 30px;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}
.panel h1 { font-size: 44px; margin-bottom: 14px; }
.panel h2 { font-size: 34px; margin-bottom: 14px; color: var(--yellow); }
.panel .big { font-size: 20px; line-height: 1.5; margin-bottom: 14px; }
.panel .hint-text { font-size: 15px; color: var(--dim); line-height: 1.5; margin-bottom: 18px; }
.big-btn {
  font-family: inherit;
  font-size: 24px;
  font-weight: 800;
  color: #10233f;
  background: linear-gradient(135deg, var(--yellow), #ffb84a);
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(180, 120, 0, 0.55);
  transition: transform 0.1s, box-shadow 0.1s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(180, 120, 0, 0.55); }
.big-btn.secondary {
  color: #10233f;
  background: linear-gradient(135deg, var(--blue), #4aa8ff);
  box-shadow: 0 5px 0 rgba(0, 90, 160, 0.55);
}
.win-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

@media (max-height: 620px) {
  .dbtn { width: 54px; height: 54px; font-size: 24px; }
  .dpad-mid { gap: 56px; }
  #dpad { padding-bottom: 10px; }
}
