* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #87ceeb;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
#game { display: block; width: 100vw; height: 100vh; cursor: crosshair; }

/* -------- character select — POLISHED START SCREEN --------
 * Inspired by first-party Nintendo title screens (Kirby, Wind Waker,
 * Animal Crossing): warm sky, clean type, big readable cards, one
 * accent color, subtle motion. No noise, no chromatic aberration,
 * no scanlines — just a friendly start screen that reads instantly.
 */
#select {
  position: fixed; inset: 0; z-index: 5;
  background: linear-gradient(180deg,
    #b0dff5 0%,
    #d8ecf8 50%,
    #fbe9c5 82%,
    #a3d988 100%);
  color: #1f3a3a;
  font-family: "Nunito", "SF Pro Rounded", "Segoe UI", -apple-system, system-ui, sans-serif;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(18px, 3vh, 32px);
  padding: clamp(24px, 6vh, 56px) 24px;
  overflow: hidden;
}

/* rolling-hill silhouette at the bottom for playful depth */
#select .bg-hills {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 24vh; pointer-events: none;
  background:
    radial-gradient(ellipse 60% 100% at 20% 120%, #77bc5a 0 60%, transparent 62%),
    radial-gradient(ellipse 80% 100% at 70% 120%, #6aae4f 0 60%, transparent 62%),
    radial-gradient(ellipse 50% 100% at 95% 130%, #82c964 0 60%, transparent 62%),
    linear-gradient(180deg, transparent 0%, #7abf57 70%);
  z-index: 0;
}
/* a few slow-drifting clouds */
#select .bg-clouds {
  position: absolute; inset: 0; pointer-events: none; z-index: 0;
}
#select .bg-clouds span {
  position: absolute;
  font-size: clamp(32px, 4vw, 54px);
  opacity: 0.85;
  filter: drop-shadow(0 3px 0 rgba(255,255,255,0.6));
  animation: drift 26s linear infinite;
}
#select .bg-clouds span:nth-child(1) { top: 10%; left: -10%; animation-delay: 0s;   }
#select .bg-clouds span:nth-child(2) { top: 22%; left: -10%; animation-delay: -9s;  font-size: clamp(28px, 3.2vw, 42px); }
#select .bg-clouds span:nth-child(3) { top: 6%;  left: -10%; animation-delay: -18s; font-size: clamp(22px, 2.6vw, 34px); opacity: 0.7; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(120vw); } }

/* title block */
#select .title-block {
  position: relative; z-index: 1;
  text-align: center; display: flex; flex-direction: column; align-items: center;
  gap: 6px;
}
#select .title-eyebrow {
  font-size: clamp(11px, 1.2vw, 14px);
  font-weight: 700;
  color: #e74a58;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255,255,255,0.9);
}
#select .title {
  font-size: clamp(32px, 6.2vw, 72px);
  font-weight: 900;
  line-height: 1.02;
  color: #2d4a6a;
  letter-spacing: -0.01em;
  text-shadow:
    0 2px 0 #ffffff,
    0 6px 0 rgba(0,0,0,0.07),
    0 16px 24px rgba(45,74,106,0.18);
  animation: titleBob 4s ease-in-out infinite;
  max-width: 16ch;
}
@keyframes titleBob {
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-3px); }
}
#select .title-emojis {
  font-size: clamp(18px, 2.4vw, 28px);
  letter-spacing: 0.4em;
  margin-top: 2px;
  filter: drop-shadow(0 2px 0 rgba(255,255,255,0.8));
}

/* subtitle — friendly prompt */
#select .subtitle {
  position: relative; z-index: 1;
  font-weight: 800;
  font-size: clamp(14px, 1.8vw, 20px);
  color: #2d4a6a;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(255,255,255,0.85);
  opacity: 0.85;
}

/* Character grid — 4 clean rounded cards */
#select .chars {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: clamp(12px, 1.6vw, 22px);
  width: min(1080px, 92vw);
}
@media (max-width: 720px) {
  #select .chars { grid-template-columns: repeat(2, 1fr); }
}
#select .chars button {
  background: #ffffff;
  border: 3px solid #2d4a6a;
  border-radius: 20px;
  padding: clamp(16px, 2.2vw, 26px) 14px;
  color: #2d4a6a;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow:
    0 6px 0 #2d4a6a,
    0 14px 22px rgba(45,74,106,0.15);
  transition: transform 120ms cubic-bezier(.2,.9,.3,1.4),
              box-shadow 120ms ease-out,
              background 120ms ease-out;
  outline: none;
}
#select .chars button:hover {
  transform: translateY(-4px);
  background: #fffbec;
  box-shadow:
    0 10px 0 #2d4a6a,
    0 18px 26px rgba(45,74,106,0.22);
}
#select .chars button:active {
  transform: translateY(3px);
  box-shadow:
    0 3px 0 #2d4a6a,
    0 6px 10px rgba(45,74,106,0.18);
}
#select .chars button:focus-visible {
  outline: 4px solid #ffd54a;
  outline-offset: 2px;
}
#select .chars .emoji {
  font-size: clamp(56px, 7vw, 80px);
  line-height: 1;
  filter: drop-shadow(0 3px 0 rgba(45,74,106,0.12));
}
#select .chars .hero-name {
  font-size: clamp(18px, 2vw, 26px);
  font-weight: 900;
  color: #2d4a6a;
  margin-top: 2px;
}
#select .chars .hero-tag {
  font-size: clamp(10px, 1.05vw, 13px);
  font-weight: 700;
  color: #e74a58;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* friendly mission hint at the bottom */
#select .mission {
  position: relative; z-index: 1;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255,255,255,0.85);
  border: 2px solid #2d4a6a33;
  font-size: clamp(12px, 1.4vw, 16px);
  font-weight: 700;
  color: #2d4a6a;
  box-shadow: 0 3px 0 rgba(45,74,106,0.08);
}

/* -------- HUD (hidden until playing) -------- */
#hud, #inventory, #height, #hint { display: none; }
body.playing #hud,
body.playing #inventory,
body.playing #height { display: flex; }

#hud { position: fixed; top: 10px; left: 10px; flex-direction: column; gap: 6px; pointer-events: none; z-index: 2; }
.pill {
  background: rgba(255,255,255,0.9); border: 3px solid #2d4a3e; border-radius: 12px;
  padding: 6px 12px; font-weight: 700; color: #2d4a3e; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}

#inventory {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
  flex-direction: row; gap: 6px; z-index: 2;
}
#inventory .slot {
  width: 52px; height: 52px; border: 3px solid #2d4a3e; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #fff; font-size: 20px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.5); cursor: pointer;
  box-shadow: 0 3px 0 #2d4a3e; position: relative;
}
#inventory .slot.active { outline: 4px solid #ffd700; outline-offset: -2px; }

#height {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%);
  z-index: 2;
}

#hint {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.92); border: 3px solid #2d4a3e; border-radius: 12px;
  padding: 8px 14px; font-weight: 700; color: #2d4a3e; font-size: 13px;
  z-index: 2; text-align: center; max-width: 92vw;
}
body.playing:not(.touch) #hint { display: block; }

/* -------- touch controls -------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
body.playing.touch #touch > * { pointer-events: auto; }

#dpad, #actions, #zcontrols { display: none; }
body.playing.touch #dpad { display: grid; }
body.playing.touch #actions { display: grid; }
body.playing.touch #zcontrols { display: grid; }

#dpad {
  position: fixed; left: 14px; bottom: 14px; width: 180px; height: 180px;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: 4px;
}
#dpad button, #actions button, #zcontrols button {
  background: rgba(255,255,255,0.88); border: 3px solid #2d4a3e; border-radius: 12px;
  font-weight: 800; color: #2d4a3e; cursor: pointer; font-size: 22px;
}
#dpad button:active, #actions button:active, #zcontrols button:active {
  background: #ffd700;
}
#dpad .up    { grid-column: 2; grid-row: 1; }
#dpad .left  { grid-column: 1; grid-row: 2; }
#dpad .right { grid-column: 3; grid-row: 2; }
#dpad .down  { grid-column: 2; grid-row: 3; }

#actions {
  position: fixed; right: 14px; bottom: 14px;
  grid-template-columns: 1fr; gap: 8px;
}
#actions button { padding: 16px 22px; font-size: 18px; }
#actions .place { background: #9ae07a; }
#actions .break { background: #ff9b9b; }

#zcontrols {
  position: fixed; right: 14px; bottom: 190px;
  grid-template-columns: 1fr; gap: 6px;
}
#zcontrols button { width: 56px; height: 46px; font-size: 22px; padding: 0; }

/* -------- win banner -------- */
#win {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: none; align-items: center; justify-content: center; z-index: 10;
}
#win.on { display: flex; }
#win .card {
  background: #fffacd; border: 6px solid #ffd700; border-radius: 24px;
  padding: 28px 32px; text-align: center; max-width: 90%; box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  animation: pop 0.35s cubic-bezier(.2,1.6,.4,1) both;
}
@keyframes pop { 0%{transform:scale(0.6)} 100%{transform:scale(1)} }
#win h2 { font-size: clamp(32px, 7vw, 56px); color: #8b4513; margin-bottom: 8px; }
#win p { font-size: clamp(16px, 3vw, 20px); color: #2d4a3e; margin-bottom: 18px; }
#win button {
  background: #2d4a3e; color: #fff; border: none; border-radius: 12px;
  padding: 12px 24px; font-size: 17px; font-weight: 800; cursor: pointer;
  box-shadow: 0 3px 0 #1a2f25;
}
#win button:active { transform: translateY(2px); box-shadow: 0 1px 0 #1a2f25; }
