:root {
  --emerald: #1E7A4C;
  --leaf: #4CAF6D;
  --turquoise: #2FC4C9;
  --gold: #F4B93E;
  --bark: #8B5A2B;
  --amber: #C98A3B;
  --mango: #F2722B;
  --dragonfruit: #E84393;
  --banana: #F6E27A;
  --sapphire: #2E6FE0;
  --amethyst: #8E5FE0;
  --shade: #0E3B26;
  --ruin: #A79B8A;
  --cream: #FBF3D9;
  --board-bg: #164a30;
  --board-line: rgba(255,255,255,0.06);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--shade);
  overscroll-behavior: none;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--cream);
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  transition: opacity .35s ease;
}
.screen.hidden { display: none; }

/* ===== Studio splash ===== */
.splash-screen {
  justify-content: center;
  background: radial-gradient(120% 90% at 50% 40%, #0a1a22, #020608 75%);
  cursor: pointer;
  transition: opacity .4s ease;
}
.splash-screen.fade-out { opacity: 0; }
.studio-logo { width: min(80vw, 420px); filter: drop-shadow(0 0 18px rgba(127,232,255,0.35)); }
.studio-name {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  font-size: 34px;
  letter-spacing: 4px;
  fill: #bff3ff;
  opacity: 0.9;
}
.studio-brand {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 6px;
  fill: #7fe8ff;
}
.splash-hint { margin-top: 22px; font-size: 12px; letter-spacing: 2px; opacity: 0.5; text-transform: uppercase; }

/* ===== Backgrounds ===== */
.menu-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(244,185,62,0.25), transparent 60%),
    linear-gradient(180deg, #2c8a5a 0%, #1E7A4C 35%, #12492f 75%, #0E3B26 100%);
}
.menu-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.10) 0, transparent 3%),
    radial-gradient(circle at 80% 15%, rgba(255,255,255,0.08) 0, transparent 2.5%),
    radial-gradient(circle at 60% 35%, rgba(255,255,255,0.07) 0, transparent 2%),
    radial-gradient(circle at 30% 60%, rgba(47,196,201,0.15) 0, transparent 12%);
  animation: driftBg 18s ease-in-out infinite alternate;
}
.menu-bg::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0; height: 40%;
  background: linear-gradient(180deg, transparent, rgba(14,59,38,0.85));
}
@keyframes driftBg {
  from { transform: translateY(0) scale(1); }
  to { transform: translateY(-2%) scale(1.03); }
}

/* Static hand-drawn jungle backdrop, covers the whole play screen */
#game-screen {
  --jb-sky-top: #2f9e63;
  --jb-sky-bot: #0f3c26;
  --jb-mist: #1c5138;
  --jb-trunk: #6b4423;
  --jb-fol-1: #2f8f57;
  --jb-fol-2: #3fae6c;
  --jb-fol-3: #256b40;
  --jb-fol-4: #39a862;
  transition: background 1s ease;
}
.game-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.jungle-bg {
  display: block;
  width: 100%;
  height: 100%;
}
.game-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.18), transparent 18%, transparent 78%, rgba(0,0,0,0.35));
}

/* Seasonal weather — a handful of cheap, GPU-composited CSS elements, decoupled from the game canvas */
.weather-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.weather-item { position: absolute; top: -8%; will-change: transform, opacity; }
.weather-item.snow { border-radius: 50%; background: #ffffff; opacity: .85; animation: weatherFall linear infinite; }
.weather-item.leaf { border-radius: 60% 8% 60% 8%; animation: weatherFall ease-in infinite; }
.weather-item.petal { border-radius: 50% 50% 50% 4px; animation: weatherFall ease-in-out infinite; }
.weather-item.firefly {
  top: auto; border-radius: 50%; background: #fff6b8;
  box-shadow: 0 0 8px 3px rgba(255,246,184,0.75);
  animation: fireflyFloat ease-in-out infinite;
}
@keyframes weatherFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  8% { opacity: .9; }
  92% { opacity: .9; }
  100% { transform: translateY(115vh) rotate(220deg); opacity: 0; }
}
@keyframes fireflyFloat {
  0%, 100% { transform: translate(0, 0); opacity: .3; }
  50% { transform: translate(8px, -14px); opacity: 1; }
}

/* ===== Loading screen ===== */
#loading-screen { justify-content: center; background: radial-gradient(120% 100% at 50% 30%, #1E7A4C, #0E3B26 80%); }
.vine-frame { position: relative; padding: 40px 20px; text-align: center; }
.vine { position: absolute; top: -20px; width: 10px; height: 140%; border-radius: 6px;
  background: repeating-linear-gradient(180deg, var(--leaf) 0 14px, var(--emerald) 14px 28px);
  animation: sway 3.2s ease-in-out infinite; }
.vine-left { left: 6px; transform-origin: top center; }
.vine-right { right: 6px; transform-origin: top center; animation-delay: .6s; }
@keyframes sway { 0%,100% { transform: rotate(-4deg);} 50% { transform: rotate(4deg);} }
.logo { position: relative; z-index: 1; margin: 0; line-height: 0.95; text-align: center; }
.logo .logo-line {
  display: block;
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--amber);
  -webkit-text-stroke: 3px #5c3416;
  text-shadow: 0 4px 0 #5c3416, 0 8px 14px rgba(0,0,0,0.45);
}
.logo .logo-accent { color: var(--gold); -webkit-text-stroke: 3px #7a4a12; text-shadow: 0 4px 0 #7a4a12, 0 0 24px rgba(244,185,62,0.7), 0 8px 14px rgba(0,0,0,0.45); }
.logo.small .logo-line { font-size: 34px; }
.firefly { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: #fff6b8; box-shadow: 0 0 10px 4px rgba(255,246,184,0.8); animation: flit 5s ease-in-out infinite; }
.f1 { top: 10%; left: 8%; animation-delay: 0s; }
.f2 { top: 70%; right: 6%; animation-delay: 1.4s; }
.f3 { top: 40%; left: 85%; animation-delay: 2.6s; }
@keyframes flit { 0%,100% { transform: translate(0,0); opacity:.4;} 50% { transform: translate(10px,-16px); opacity:1;} }
.loading-bar { width: 70%; max-width: 320px; height: 14px; border-radius: 8px; background: rgba(0,0,0,0.35); border: 2px solid var(--bark); overflow: hidden; margin-top: 30px; }
.loading-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--leaf), var(--gold)); transition: width .2s linear; }
.loading-label { margin-top: 12px; opacity: .8; font-size: 14px; }

/* ===== Menu screen ===== */
#menu-screen { justify-content: center; gap: 14px; }
.mascot-menu { font-size: 84px; margin-top: 8px; animation: bob 2.6s ease-in-out infinite; filter: drop-shadow(0 8px 10px rgba(0,0,0,0.35)); z-index: 1; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg);} 50% { transform: translateY(-10px) rotate(2deg);} }
.menu-stats { display: flex; gap: 12px; z-index: 1; }
.stat-chip { background: rgba(0,0,0,0.28); border: 2px solid var(--amber); border-radius: 20px; padding: 6px 14px; font-weight: 700; font-size: 14px; }
.menu-toggles { display: flex; gap: 10px; margin-top: 6px; z-index: 1; }

/* ===== Buttons ===== */
.btn {
  z-index: 1;
  border: none;
  border-radius: 16px;
  padding: 14px 30px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  color: var(--cream);
  letter-spacing: .5px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.35), 0 8px 16px rgba(0,0,0,0.25);
  transform: translateY(0);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,0.35); }
.btn-wood { background: linear-gradient(180deg, var(--amber), var(--bark)); border: 2px solid #5c3416; }
.btn-leaf { background: linear-gradient(180deg, var(--leaf), var(--emerald)); border: 2px solid #12492f; font-size: 15px; padding: 10px 22px; }
.btn-big { font-size: 22px; padding: 18px 44px; }
.icon-btn {
  z-index: 1;
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(180deg, var(--amber), var(--bark));
  border: 2px solid #5c3416;
  color: var(--cream);
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.3);
}
.icon-btn.small { width: 38px; height: 38px; font-size: 15px; position: absolute; top: 10px; left: 10px; z-index: 5; }
.icon-btn.season-badge { left: auto; right: 10px; font-size: 18px; }
.icon-btn:active { transform: translateY(3px); box-shadow: none; }

/* ===== Game screen ===== */
#game-screen { justify-content: flex-start; }
.hud {
  position: relative;
  z-index: 2;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 12px 4px;
}
.wood-panel {
  background: linear-gradient(180deg, var(--amber), var(--bark));
  border: 2px solid #5c3416;
  border-radius: 14px;
  padding: 6px 12px;
  min-width: 82px;
  text-align: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}
.panel-label { display: block; font-size: 10px; letter-spacing: 1.5px; opacity: .8; }
.panel-value { display: block; font-size: 22px; font-weight: 900; color: var(--gold); text-shadow: 0 2px 0 rgba(0,0,0,0.3); }
.combo-panel { transition: transform .15s ease; }
.combo-panel.pulse { transform: scale(1.18); }
.moves-panel .panel-value { font-size: 20px; }

.objective-banner {
  position: relative;
  z-index: 2;
  margin: 2px auto 0;
  width: fit-content;
  max-width: 90%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, var(--leaf), var(--emerald));
  border: 2px solid #12492f;
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 3px 0 rgba(0,0,0,0.3);
}
.objective-banner.hidden { display: none; }
.objective-progress { color: var(--gold); font-weight: 900; }

.mascot-dock {
  position: absolute;
  top: 70px;
  right: 4px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  pointer-events: none;
}
.mascot { font-size: 40px; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.35)); transition: transform .25s ease; }
.mascot.cheer { animation: cheer .5s ease; }
@keyframes cheer { 0% { transform: scale(1) rotate(0);} 30% { transform: scale(1.35) rotate(-10deg);} 60% { transform: scale(1.2) rotate(8deg);} 100% { transform: scale(1) rotate(0);} }
.speech-bubble {
  margin-top: 4px;
  background: var(--cream);
  color: #3a2a12;
  font-weight: 800;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 12px;
  border: 2px solid var(--bark);
  max-width: 140px;
  text-align: center;
  position: relative;
  animation: popIn .25s ease;
}
.speech-bubble.hidden { display: none; }
@keyframes popIn { from { transform: scale(.5); opacity: 0;} to { transform: scale(1); opacity: 1;} }

.board-wrap {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-height: 0;
}
#board {
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45), inset 0 0 0 4px #0b2c1c;
  touch-action: none;
}
#board.shake { animation: shake .3s ease; }
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-6px,3px); }
  40% { transform: translate(6px,-3px); }
  60% { transform: translate(-4px,2px); }
  80% { transform: translate(4px,-2px); }
}

.tray {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  gap: 4vw;
  width: 100%;
  padding: 6px 12px calc(env(safe-area-inset-bottom, 0px) + 14px);
}
.tray-slot {
  width: 26vw;
  max-width: 120px;
  aspect-ratio: 1;
  background: radial-gradient(circle at 50% 30%, rgba(255,255,255,0.06), transparent 70%);
  border: 2px dashed rgba(255,255,255,0.18);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tray-canvas { width: 100%; height: 100%; touch-action: none; }
.tray-canvas.dragging { visibility: hidden; }

#drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}

/* ===== Overlays ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(6,20,13,0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.overlay.hidden { display: none; }
.stone-tablet {
  background: linear-gradient(180deg, #cabfa9, #a79b8a);
  color: #2c2013;
  border-radius: 20px;
  border: 4px solid #6b5a3e;
  padding: 26px 24px;
  width: min(86vw, 360px);
  text-align: center;
  box-shadow: 0 14px 30px rgba(0,0,0,0.5);
}
.stone-tablet h2 { margin: 0 0 12px; font-size: 22px; }
.stone-tablet p { font-size: 14px; line-height: 1.5; margin: 0 0 12px; }
.stone-tablet .btn { display: block; width: 100%; margin: 10px auto 0; }
.mascot-big { font-size: 64px; margin: 6px 0; }
.final-score { font-size: 20px; font-weight: 800; color: #1E7A4C; }
.new-best { color: #c9761a; font-weight: 800; }
.new-best.hidden { display: none; }

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: rgba(20,20,10,0.85);
  color: var(--cream);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid var(--amber);
  transition: opacity .3s ease;
}
.toast.hidden { opacity: 0; pointer-events: none; }

@media (min-width: 620px) {
  #board { max-width: 520px; max-height: 520px; }
  .tray-slot { width: 110px; }
}
