:root {
  --green-1: #34d17a;
  --green-2: #0b8f5a;
  --bg-1: #aef0c8;
  --bg-2: #7fd6f5;
  --ink: #133a2a;
  --card: #ffffff;
  --shadow: 0 18px 40px rgba(8, 40, 24, 0.28);
  --font: 'Baloo 2', 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  /* Block arrow-key / swipe scroll. */
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(circle at 30% 15%, var(--bg-2), transparent 55%),
              linear-gradient(160deg, var(--bg-1), #ffe8a3 90%);
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.back-link {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  z-index: 50;
  text-decoration: none;
  font-weight: 700;
  font-size: 1rem;
  color: var(--green-2);
  background: rgba(255, 255, 255, 0.85);
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(8, 40, 24, 0.18);
  backdrop-filter: blur(4px);
}
.back-link:hover { background: #fff; }

.stage {
  width: min(94vw, 94vh, 620px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}

.hud-pill {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 800;
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  box-shadow: 0 6px 16px rgba(8, 40, 24, 0.16);
  white-space: nowrap;
}
.best-pill { color: var(--green-2); }

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 26px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #d7f6e3;
  touch-action: none;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(160deg, rgba(11, 143, 90, 0.78), rgba(127, 214, 245, 0.78));
  backdrop-filter: blur(3px);
  transition: opacity 0.25s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.card {
  background: var(--card);
  border-radius: 26px;
  padding: clamp(18px, 5vw, 34px);
  text-align: center;
  box-shadow: 0 20px 44px rgba(8, 40, 24, 0.3);
  max-width: 92%;
  animation: pop 0.32s cubic-bezier(0.22, 1.3, 0.4, 1);
}

@keyframes pop {
  from { transform: scale(0.82) translateY(10px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.title {
  font-family: var(--font);
  font-weight: 800;
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  margin: 0 0 4px;
  color: var(--green-2);
  letter-spacing: 0.5px;
}
.title.small { font-size: clamp(1.6rem, 7vw, 2.2rem); }

.subtitle {
  margin: 0 0 16px;
  font-size: clamp(0.95rem, 4vw, 1.15rem);
  font-weight: 600;
  opacity: 0.85;
}

.wiggle { display: inline-block; animation: wiggle 1.4s ease-in-out infinite; }
@keyframes wiggle {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(10deg); }
}

.big-emoji {
  font-size: clamp(3rem, 14vw, 4.6rem);
  line-height: 1;
  margin-bottom: 4px;
  animation: bob 1.6s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.mode-toggle {
  display: flex;
  gap: 10px;
  margin: 0 0 18px;
  justify-content: center;
  flex-wrap: wrap;
}

.mode-btn {
  flex: 1 1 130px;
  min-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  background: #eef6f1;
  border: 3px solid transparent;
  border-radius: 18px;
  padding: 12px 10px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
}
.mode-btn small { font-weight: 600; font-size: 0.72rem; opacity: 0.7; }
.mode-btn:hover { transform: translateY(-2px); }
.mode-btn.is-active {
  background: #d4f6e2;
  border-color: var(--green-1);
  box-shadow: 0 6px 14px rgba(52, 209, 122, 0.35);
}

.play-btn {
  font-family: var(--font);
  font-weight: 800;
  font-size: clamp(1.3rem, 5vw, 1.7rem);
  color: #fff;
  background: linear-gradient(180deg, var(--green-1), var(--green-2));
  border: none;
  border-radius: 999px;
  padding: 14px 42px;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(11, 143, 90, 0.45);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.play-btn:hover { transform: translateY(-3px) scale(1.03); }
.play-btn:active { transform: translateY(0) scale(0.98); }

.best-line { margin: 14px 0 4px; font-weight: 600; opacity: 0.8; }
.best-line strong { color: var(--green-2); }
.score-big { font-size: 1.4rem; font-weight: 800; margin: 6px 0; }
.score-big strong { color: var(--green-2); font-size: 1.7rem; }

.hint {
  margin: 8px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.6;
}

.new-best { animation: sparkle 0.8s ease; color: #f6a700 !important; }
.new-best strong { color: #f6a700 !important; }
@keyframes sparkle {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.18); }
}

.swipe-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(19, 58, 42, 0.78);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 9px 18px;
  border-radius: 999px;
  pointer-events: none;
  transition: opacity 0.4s ease;
  animation: floaty 1.8s ease-in-out infinite;
}
.swipe-hint.hidden { opacity: 0; }
@keyframes floaty {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
  .wiggle, .big-emoji, .swipe-hint, .card { animation: none; }
  .play-btn, .mode-btn { transition: none; }
}
