html, body {
  margin: 0;
  height: 100%;
  background: #24331f;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
}

/* A portrait column: full width on a phone, centered on a desktop. */
#app {
  position: relative;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  width: min(100vw, calc(100dvh * 0.5625));
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: #5f8a4c;
}

#game {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: block;
}

#pause-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 6px);
  left: calc(env(safe-area-inset-left) + 8px);
  width: 36px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 11px;
}

#home-ui {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  text-align: center;
}
#play-btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 40px;
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  color: #3a2d1f;
  background: #fffaf0;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}
#play-btn:active { transform: translateY(2px); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22); }

#home-ui .links {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 10px;
}
#home-ui .links button {
  border: 0;
  background: none;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Practice day: a hint bubble near the top of the field, with an animated hand. */
#hint {
  position: absolute;
  left: 50%;
  z-index: 5;
  width: min(86%, 320px);
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}
#hint.hidden { display: none; }
#hint-text {
  margin: 0;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(255, 250, 240, 0.95);
  color: #3a2d1f;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}
/* The hand sits on the field (placed from game.js), next to the creature or on a tile to tap. */
#hint-hand {
  position: absolute;
  z-index: 5;
  width: 60px;
  height: 60px;
  margin: -30px 0 0 -30px;
  font-size: 46px;
  line-height: 60px;
  text-align: center;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3));
}
#hint-hand:empty { display: none; }
#hint-hand.swipe { animation: hint-swipe 4.8s ease-in-out infinite; }
#hint-hand.hold { animation: hint-hold 2.2s ease-in-out infinite; }
#hint-hand.tap { animation: hint-tap 1.1s ease-in-out infinite; }

/* On a computer: the four arrow keys, with the up key pressing (or held down). */
#hint-hand.keys {
  display: grid;
  grid-template-columns: repeat(3, 30px);
  grid-template-rows: 30px 30px;
  gap: 4px;
  justify-content: center;
  width: 104px;
  height: 64px;
  margin: -32px 0 0 -52px;
  font-size: 15px;
  font-weight: 800;
  line-height: 30px;
  filter: none;
  animation: none;
}
#hint-hand .key {
  border-radius: 7px;
  background: #fffaf0;
  color: #3a2d1f;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
#hint-hand .key.up { grid-area: 1 / 2; }
#hint-hand .key.left { grid-area: 2 / 1; }
#hint-hand .key.down { grid-area: 2 / 2; }
#hint-hand .key.right { grid-area: 2 / 3; }
/* The keys press in turn, matching the swipes: up, right, down, left. */
#hint-hand.swipe .key { animation: key-turn 4.8s ease-in-out infinite; }
#hint-hand.swipe .key.right { animation-delay: 1.2s; }
#hint-hand.swipe .key.down { animation-delay: 2.4s; }
#hint-hand.swipe .key.left { animation-delay: 3.6s; }
#hint-hand.hold .key.up { animation: key-hold 2.2s ease-in-out infinite; }
@keyframes key-turn {
  0%, 25%, 100% { transform: none; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3); background: #fffaf0; }
  6%, 18% { transform: translateY(3px); box-shadow: 0 0 0 rgba(0, 0, 0, 0.3); background: #ffe27a; }
}
@keyframes key-hold {
  0%, 100% { transform: none; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3); background: #fffaf0; }
  15%, 85% { transform: translateY(3px); box-shadow: 0 0 0 rgba(0, 0, 0, 0.3); background: #ffe27a; }
}
/* Swipes up, right, down and left in turn. */
@keyframes hint-swipe {
  0% { transform: translate(0, 18px); opacity: 0; }
  4% { opacity: 1; }
  18% { transform: translate(0, -18px); opacity: 1; }
  23% { transform: translate(0, -18px); opacity: 0; }
  25% { transform: translate(-18px, 0); opacity: 0; }
  29% { opacity: 1; }
  43% { transform: translate(18px, 0); opacity: 1; }
  48% { transform: translate(18px, 0); opacity: 0; }
  50% { transform: translate(0, -18px); opacity: 0; }
  54% { opacity: 1; }
  68% { transform: translate(0, 18px); opacity: 1; }
  73% { transform: translate(0, 18px); opacity: 0; }
  75% { transform: translate(18px, 0); opacity: 0; }
  79% { opacity: 1; }
  93% { transform: translate(-18px, 0); opacity: 1; }
  98%, 100% { transform: translate(-18px, 0); opacity: 0; }
}
}
@keyframes hint-hold {
  0% { transform: translateY(18px); opacity: 0; }
  12% { transform: translateY(18px); opacity: 1; }
  35% { transform: translateY(-14px) scale(0.92); opacity: 1; }
  85% { transform: translateY(-14px) scale(0.92); opacity: 1; }
  100% { transform: translateY(-14px); opacity: 0; }
}
@keyframes hint-tap {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(0.82); }
}
#hint-skip {
  margin-top: 2px;
  padding: 6px 12px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

/* Back to the Charkade lobby. Only on the home map. */
#exit-btn {
  display: none;
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  left: calc(env(safe-area-inset-left) + 10px);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

#settings-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  right: calc(env(safe-area-inset-right) + 10px);
  width: 34px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  padding: 0;
  display: none;
}
#settings-btn svg { display: block; margin: 0 auto; }

/* Home map: hide the pause button, show the Play and exit buttons. */
#app.home #pause-btn { display: none; }
#app.home #home-ui, #app.home #exit-btn, #app.home #settings-btn { display: block; }

#overlay {
  z-index: 10;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 20, 40, 0.35);
}
#overlay.hidden { display: none; }
#overlay .card {
  min-width: 240px;
  max-width: 340px;
  background: #fffaf0;
  color: #3a2d1f;
  border-radius: 20px;
  padding: 22px 22px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  text-align: center;
}
#overlay h1 { margin: 0 0 10px; font-size: 28px; }
#overlay p { margin: 8px 0; font-size: 15px; line-height: 1.4; }
#overlay .small { font-size: 13px; color: #7a6a58; }
.pop-icon { width: 0.6em; height: 1.1em; vertical-align: -0.15em; }
#overlay button {
  margin-top: 12px;
  border: 0;
  border-radius: 999px;
  padding: 12px 30px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  color: #fffaf0;
  background: #3a2d1f;
}
#overlay .switch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 6px 0;
  font-size: 16px;
  font-weight: 700;
}
#overlay .switch input { width: 22px; height: 22px; accent-color: #3a2d1f; }
/* End-of-day cards. Win: warm and bouncy, with confetti. Lose: charred, with smoke. */
#overlay .card { position: relative; overflow: hidden; }
#overlay .art { position: relative; width: 120px; height: 110px; margin: -4px auto 0; }
#overlay .art canvas { width: 120px; height: 110px; }
#overlay .cheer { font-size: 18px; font-weight: 800; }

#overlay .card.win { background: linear-gradient(#fff8e8, #ffe8f1); }
#overlay .card.win h1 { color: #c2477a; }
#overlay .card.win .cheer { color: #c2477a; }
#overlay .card.win .hero { animation: hero-bounce 0.9s ease-in-out infinite; }
#overlay .card.win button:not(.secondary) { background: #c2477a; }
@keyframes hero-bounce {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  15% { transform: translateY(0) scale(1.08, 0.92); }
  45% { transform: translateY(-14px) scale(0.95, 1.05); }
}
#overlay .heart {
  position: absolute;
  left: 50%;
  top: 30px;
  color: #ff6f91;
  font-size: 18px;
  font-style: normal;
  opacity: 0;
  animation: heart-rise 2.4s ease-out infinite;
}
#overlay .heart:nth-of-type(1) { margin-left: -46px; }
#overlay .heart:nth-of-type(2) { margin-left: 30px; animation-delay: 0.8s; }
#overlay .heart:nth-of-type(3) { margin-left: -8px; animation-delay: 1.6s; font-size: 14px; }
@keyframes heart-rise {
  0% { transform: translateY(20px) scale(0.6); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translateY(-34px) scale(1.1); opacity: 0; }
}
#overlay .confetti {
  position: absolute;
  top: -12px;
  width: 7px;
  height: 11px;
  border-radius: 2px;
  pointer-events: none;
  animation: confetti-fall 3s linear infinite;
}
@keyframes confetti-fall {
  0% { top: -12px; opacity: 1; }
  85% { opacity: 1; }
  100% { top: 105%; opacity: 0; margin-left: 24px; rotate: 540deg; }
}

#overlay .card.lose { background: #2f2622; color: #f3e9dc; }
#overlay .card.lose .cheer { color: #ffb36b; }
#overlay .card.lose button:not(.secondary) { background: #f3e9dc; color: #2f2622; }
#overlay .card.lose button.secondary { color: #bfae9c; }
#overlay .puff {
  position: absolute;
  left: 50%;
  top: 40px;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  border-radius: 50%;
  background: rgba(150, 140, 130, 0.5);
  opacity: 0;
  animation: puff-rise 2.6s ease-out infinite;
}
#overlay .puff:nth-of-type(2) { animation-delay: 0.9s; margin-left: -2px; }
#overlay .puff:nth-of-type(3) { animation-delay: 1.8s; margin-left: -20px; }
@keyframes puff-rise {
  0% { transform: translateY(10px) scale(0.5); opacity: 0; }
  20% { opacity: 0.8; }
  100% { transform: translateY(-50px) scale(1.8); opacity: 0; }
}

/* Character picker */
#overlay .chars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}
#overlay button.char {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 6px 4px 8px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: #f1e7d3;
  color: #3a2d1f;
  font-size: 13px;
}
#overlay button.char canvas { width: 64px; height: 64px; }
#overlay button.char.on { border-color: #3a2d1f; background: #fff; }
#overlay button.char.locked { opacity: 0.6; font-size: 12px; cursor: default; }
#overlay button.char.locked canvas { filter: brightness(0) opacity(0.35); }
#overlay .prize { font-weight: 700; }
#overlay button.secondary {
  display: block;
  margin: 8px auto 0;
  padding: 6px 16px;
  font-size: 15px;
  font-weight: 600;
  color: #7a6a58;
  background: none;
}
#overlay button.secondary:empty { display: none; }

/* Dev menu (dev.js): only on localhost, the home network, or with ?dev */
#dev-btn {
  position: absolute;
  left: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 60;
  border: 0;
  border-radius: 8px;
  padding: 4px 8px;
  font: 700 11px ui-monospace, monospace;
  color: #fff;
  background: rgba(20, 20, 30, 0.55);
}
#dev-panel {
  position: absolute;
  left: 8px;
  right: 8px;
  top: calc(44px + env(safe-area-inset-top));
  max-width: 420px;
  max-height: 78%;
  overflow: auto;
  z-index: 60;
  padding: 10px 12px 12px;
  border-radius: 12px;
  background: rgba(20, 20, 30, 0.94);
  color: #fff;
  font: 14px system-ui, sans-serif;
}
#dev-panel.hidden { display: none; }
#dev-panel h4 { margin: 12px 0 6px; font-size: 13px; color: #ffd84a; }
#dev-panel h4 span, #dev-panel .dev-note { font-weight: 400; color: #bbb; font-size: 12px; }
#dev-panel .dev-note { margin: 0 0 6px; }
#dev-panel .dev-head { display: flex; justify-content: space-between; align-items: center; }
#dev-panel .dev-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
#dev-panel button, #dev-panel select {
  border: 0;
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  color: #fff;
  background: #3a3a50;
}
#dev-panel button.on { background: #c98a1a; }
#dev-panel select { flex: 1; }
#dev-panel input[type=range] { width: 100%; margin: 4px 0 8px; }
#dev-panel label { display: block; margin: 4px 0; font-size: 13px; }
