:root {
  --bg1: #bfe3f0;
  --bg2: #8ecae6;
  --panel: #f7fbfd;
  --ink: #1e3a48;
  --muted: #5a7a88;
  --accent: #ff8a5b;
  --accent-2: #ffb37a;
  --divider: #6fb2cf;
  --gold: #f4c430;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: linear-gradient(180deg, #7ec8ee 0%, #a7dbf2 45%, #c8ecfb 62%) fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; user-select: none;
}
/* Two drifting cloud layers (each 200% wide; the pattern repeats every 50% so a
   translateX(-50%) loop is seamless). Different speeds/sizes give parallax. */
body::before, #app::before {
  content: "";
  position: fixed; top: 0; left: 0; width: 200%;
  z-index: -1; pointer-events: none;
}
/* near clouds — bigger, brighter, faster */
body::before {
  height: 66%;
  background:
    radial-gradient(90px 44px at 8% 22%,  rgba(255,255,255,.95), transparent 70%),
    radial-gradient(120px 54px at 21% 34%, rgba(255,255,255,.85), transparent 70%),
    radial-gradient(80px 40px at 39% 15%,  rgba(255,255,255,.9), transparent 70%),
    radial-gradient(90px 44px at 58% 22%,  rgba(255,255,255,.95), transparent 70%),
    radial-gradient(120px 54px at 71% 34%, rgba(255,255,255,.85), transparent 70%),
    radial-gradient(80px 40px at 89% 15%,  rgba(255,255,255,.9), transparent 70%);
  animation: clouds 55s linear infinite;
}
/* far clouds — smaller, fainter, slower */
#app::before {
  height: 48%;
  background:
    radial-gradient(60px 26px at 14% 12%, rgba(255,255,255,.6), transparent 70%),
    radial-gradient(70px 30px at 33% 26%, rgba(255,255,255,.5), transparent 70%),
    radial-gradient(50px 22px at 46% 8%,  rgba(255,255,255,.55), transparent 70%),
    radial-gradient(60px 26px at 64% 12%, rgba(255,255,255,.6), transparent 70%),
    radial-gradient(70px 30px at 83% 26%, rgba(255,255,255,.5), transparent 70%),
    radial-gradient(50px 22px at 96% 8%,  rgba(255,255,255,.55), transparent 70%);
  animation: clouds 105s linear infinite;
}
@keyframes clouds { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) {
  body::before, #app::before { animation: none; }
}
/* grassy hill along the bottom */
body::after {
  content: "";
  position: fixed; left: -10%; right: -10%; bottom: 0;
  height: 26vh;
  background: radial-gradient(120% 100% at 50% 100%, #8fd36a 0%, #79c157 55%, #6ab24c 100%);
  border-top-left-radius: 50% 40px;
  border-top-right-radius: 50% 40px;
  z-index: -1; pointer-events: none;
}
#app {
  max-width: 480px; margin: 0 auto; min-height: 100%;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 10px calc(env(safe-area-inset-bottom) + 6px);
}

/* HUD */
#hud {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 10px; margin: 4px 0 6px;
  background: var(--panel); border: 2px solid var(--divider);
  border-radius: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 30px; height: 30px; border-radius: 8px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .5px; color: var(--accent); }
.hud-right { display: flex; align-items: center; gap: 6px; }
.stat {
  background: #eaf5fa; border: 1px solid var(--divider);
  padding: 4px 8px; border-radius: 999px; font-weight: 800; font-size: 13px;
  display: flex; align-items: center; gap: 3px;
}
.stat-icon { font-size: 12px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 9px;
  border: 1px solid var(--divider); background: #eaf5fa; color: var(--ink);
  font-size: 16px; font-weight: 800; cursor: pointer;
}

/* level bar */
#levelbar {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; margin-bottom: 6px; font-size: 13px; font-weight: 700;
}
.progress {
  flex: 1; height: 12px; background: #eaf5fa;
  border: 1px solid var(--divider); border-radius: 999px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width .25s ease;
}
.progress-text { color: var(--muted); font-size: 11px; min-width: 64px; text-align: right; }
.next { display: flex; align-items: center; gap: 4px; }
.next-cap { color: var(--muted); font-size: 11px; }
.next-orb {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; box-shadow: inset 0 -2px 0 rgba(0,0,0,.15);
}

/* board */
main { flex: 1; display: flex; align-items: center; justify-content: center; }
#board {
  width: 100%; max-width: 420px; aspect-ratio: 400 / 640;
  background: transparent; /* the glass jar is drawn on the canvas over the sky */
  touch-action: none;
}

/* controls */
#controls { padding: 10px 4px 4px; margin-top: 6px; border-top: 3px solid var(--divider); }
#message { text-align: center; min-height: 18px; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.control-row { display: flex; gap: 12px; justify-content: center; }
.chain {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 1px; margin-top: 8px; font-size: 17px; line-height: 1;
}
.chain i { color: var(--muted); font-style: normal; font-size: 11px; margin: 0 1px; }
.btn {
  border: none; border-radius: 12px; padding: 13px 20px;
  font-size: 15px; font-weight: 800; color: var(--ink);
  background: #eaf5fa; box-shadow: 0 2px 0 rgba(0,0,0,.15); cursor: pointer;
}
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--divider); box-shadow: none; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
#bomb-btn.armed { background: var(--accent); color: #fff; outline: 3px solid var(--gold); }

/* overlays */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(14,42,56,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.overlay.hidden { display: none; }
.panel {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 2px solid var(--divider); border-radius: 18px; padding: 22px;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.panel h2 { margin: 0 0 10px; font-size: 24px; color: var(--accent); }
.panel p { color: var(--ink); font-size: 14px; line-height: 1.4; }
.btncol { display: flex; flex-direction: column; gap: 8px; }
.tut-img {
  display: block; width: 190px; height: 190px; margin: 0 auto 12px;
  border-radius: 16px; border: 2px solid var(--divider);
  background: #eaf5fa; object-fit: cover;
}
.tut-text { text-align: left; min-height: 70px; font-size: 15px; line-height: 1.45; }
.tut-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.tut-progress { color: var(--muted); font-size: 13px; }

/* toasts */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: var(--panel); color: var(--ink); border: 2px solid var(--divider);
  padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 40;
}
.toast.hidden { display: none; }
.toast.update { bottom: auto; top: 10px; display: flex; align-items: center; gap: 10px; }
.toast-btn { background: var(--accent); color: #fff; border: none; border-radius: 999px; padding: 4px 12px; font-weight: 800; cursor: pointer; }
