:root {
  --ink: #3a2d3f;
  --muted: #7a6a7e;
  --cream: #fff8f0;
  --pink: #ff6f91;
  --soft-pink: #ffd1e3;
  --soft-yellow: #fff0a8;
  --soft-blue: #dff6ff;
  --soft-mint: #d8f5e8;
  --green: #2fbf5b;
  --green-deep: #229447;
  --safeT: env(safe-area-inset-top, 0px);
  --safeB: env(safe-area-inset-bottom, 0px);
  --safeL: env(safe-area-inset-left, 0px);
  --safeR: env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: "Varela Round", "Nunito", "PingFang HK", "PingFang TC",
    "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #ffe3ef 0%, #fff6d6 45%, #dff6ff 100%);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  background: none;
}

.hidden { display: none !important; }

#bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
#bg i {
  position: absolute;
  border-radius: 50%;
  opacity: 0.55;
  animation: float 14s ease-in-out infinite alternate;
}
#bg i:nth-child(1) { width: 34vmin; height: 34vmin; left: -8vmin; top: 8%; background: #ffd1e3; }
#bg i:nth-child(2) { width: 24vmin; height: 24vmin; right: -6vmin; top: 22%; background: #c9f0ff; animation-delay: -3s; }
#bg i:nth-child(3) { width: 18vmin; height: 18vmin; left: 30%; bottom: -6vmin; background: #fff0a8; animation-delay: -6s; }
#bg i:nth-child(4) { width: 12vmin; height: 12vmin; right: 22%; bottom: 12%; background: #d8f5c8; animation-delay: -2s; }
#bg i:nth-child(5) { width: 9vmin; height: 9vmin; left: 12%; bottom: 22%; background: #e7d6ff; animation-delay: -8s; }
#bg i:nth-child(6) { width: 7vmin; height: 7vmin; right: 8%; top: 4%; background: #ffe0c2; animation-delay: -5s; }
@keyframes float {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(3vmin, -4vmin) scale(1.08); }
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(var(--safeT) + 10px) calc(var(--safeR) + 12px) calc(var(--safeB) + 10px) calc(var(--safeL) + 12px);
  text-align: center;
}

/* —— Home —— */
#home { justify-content: center; gap: clamp(6px, 1.5vmin, 14px); }
#home h1 {
  margin: 0;
  font-size: clamp(32px, 9vmin, 56px);
  font-weight: 900;
  color: #ff4d8d;
  text-shadow: 0 3px 0 #fff;
}
.en-title {
  margin: 0;
  font-size: clamp(16px, 3.6vmin, 24px);
  font-weight: 800;
  color: var(--muted);
}
.sub {
  margin: 4px 0 8px;
  font-size: clamp(14px, 3.2vmin, 20px);
  font-weight: 700;
  opacity: 0.85;
  max-width: 22em;
  line-height: 1.4;
}
.buddies {
  display: flex;
  gap: clamp(8px, 3vmin, 20px);
  margin-bottom: 4px;
}
.blob {
  font-size: clamp(36px, 12vmin, 72px);
  animation: hop 1.4s ease-in-out infinite;
  filter: drop-shadow(0 4px 0 rgba(58, 45, 63, 0.08));
}
.blob.b2 { animation-delay: 0.2s; }
.blob.b3 { animation-delay: 0.4s; }
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-14%) rotate(-4deg); }
  60% { transform: translateY(0) scale(1.05, 0.95); }
}

.bigBtn {
  width: clamp(88px, 22vmin, 150px);
  height: clamp(88px, 22vmin, 150px);
  border-radius: 50%;
  background: linear-gradient(#6fe08b, #2fbf5b);
  box-shadow: 0 8px 0 #229447, 0 14px 26px rgba(47, 191, 91, 0.35);
  display: grid;
  place-items: center;
  animation: breathe 1.8s ease-in-out infinite;
  margin-top: 8px;
}
.bigBtn svg { width: 58%; height: 58%; }
.bigBtn:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 #229447;
  animation: none;
}
.bigBtn.small {
  width: auto;
  height: auto;
  border-radius: 999px;
  padding: 0.65em 1.7em;
  font-size: clamp(18px, 4.2vmin, 28px);
  font-weight: 900;
  color: #fff;
  animation: breathe 1.8s ease-in-out infinite;
}
@keyframes breathe {
  50% { transform: scale(1.06); }
}
.startLabel {
  font-size: clamp(16px, 3.4vmin, 26px);
  font-weight: 900;
  color: #2a9d4a;
}

.pill {
  background: #fff;
  border-radius: 999px;
  padding: 0.4em 1em;
  font-size: clamp(14px, 3vmin, 18px);
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(58, 45, 63, 0.12);
  min-height: 40px;
  min-width: 44px;
}
.pill.wide {
  margin-top: 10px;
  min-width: 10em;
}
.pill:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(58, 45, 63, 0.12); }

/* —— Play —— */
#play {
  justify-content: flex-start;
  gap: 0;
  padding-top: calc(var(--safeT) + 6px);
  padding-bottom: calc(var(--safeB) + 6px);
}
.playTop {
  flex: 0 0 auto;
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.progress {
  font-size: clamp(15px, 3.4vmin, 22px);
  font-weight: 900;
  background: rgba(255, 255, 255, 0.8);
  padding: 0.3em 0.9em;
  border-radius: 999px;
  box-shadow: 0 2px 0 rgba(58, 45, 63, 0.08);
}
.titleBlock {
  flex: 0 0 auto;
  margin: 2px 0 4px;
}
.titleZh {
  font-size: clamp(22px, 5.5vmin, 36px);
  font-weight: 900;
  color: var(--ink);
  line-height: 1.15;
}
.titleEn {
  font-size: clamp(13px, 2.8vmin, 18px);
  font-weight: 700;
  color: var(--muted);
}

.stageWrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: min(560px, 92vw);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
#stage {
  width: 100%;
  height: 100%;
  max-height: min(58vh, 560px);
  touch-action: none;
  filter: drop-shadow(0 8px 18px rgba(58, 45, 63, 0.12));
}
#stage .stageBg {
  fill: rgba(255, 255, 255, 0.72);
}
#shapeFill {
  cursor: pointer;
  transition: fill 0.12s ease;
}
#shapeStroke {
  pointer-events: none;
}

.paletteWrap {
  flex: 0 0 auto;
  width: 100%;
  max-width: 560px;
  padding-top: 6px;
}
.palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(6px, 1.8vmin, 12px);
  padding: 4px 0 8px;
}
.swatch {
  width: clamp(40px, 9.5vmin, 56px);
  height: clamp(40px, 9.5vmin, 56px);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 0 rgba(58, 45, 63, 0.14), inset 0 -3px 0 rgba(0, 0, 0, 0.08);
  position: relative;
  flex: 0 0 auto;
}
.swatch:active { transform: scale(0.92); }
.swatch.selected {
  outline: 4px solid #ff9f1c;
  outline-offset: 2px;
  transform: scale(1.08);
}
.swatch.eraser {
  background: repeating-linear-gradient(
    -45deg,
    #fff,
    #fff 6px,
    #f0e6ee 6px,
    #f0e6ee 12px
  );
}
.swatch.eraser::after {
  content: "橡皮";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(10px, 2.2vmin, 13px);
  font-weight: 900;
  color: var(--ink);
}

.tools {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding-bottom: 2px;
}
.toolBtn {
  background: #fff;
  border-radius: 999px;
  padding: 0.55em 1.2em;
  font-size: clamp(14px, 3.2vmin, 18px);
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(58, 45, 63, 0.12);
  min-height: 44px;
}
.toolBtn.next {
  background: linear-gradient(#6fe08b, #2fbf5b);
  color: #fff;
  box-shadow: 0 4px 0 #229447;
}
.toolBtn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(58, 45, 63, 0.12);
}
.toolBtn.next:active { box-shadow: 0 1px 0 #229447; }

/* —— Done —— */
#done { justify-content: center; gap: clamp(8px, 2vmin, 16px); }
.bigEmoji {
  font-size: clamp(64px, 20vmin, 120px);
  animation: starIn 0.9s cubic-bezier(0.3, 1.6, 0.5, 1);
  line-height: 1;
}
@keyframes starIn {
  from { transform: scale(0) rotate(-180deg); }
  to { transform: scale(1) rotate(0); }
}
#confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
#confetti i {
  position: absolute;
  top: -6vh;
  width: 12px;
  height: 16px;
  border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translate(var(--x), 112vh) rotate(var(--r)); }
}

/* Landscape phone: keep stage usable */
@media (orientation: landscape) and (max-height: 500px) {
  #home .buddies { display: none; }
  #stage { max-height: min(70vh, 360px); }
  .titleZh { font-size: clamp(16px, 4.5vh, 24px); }
  .swatch { width: 36px; height: 36px; }
}
