:root {
  --ink: #3b2414;
  --coat: #d98f4e;
  --coat-dark: #b8733a;
  --mane: #5c3317;
  --muzzle: #f3c9a0;
  --patch: #fff4e2;
  --pink: #eda7a0;
  --hoof: #3d2a1e;
  --grass: #7cc35b;
  --grass-dark: #4f8f36;
  --bubble: #ffffff;
  --sky-top: #8fd0ff;
  --sky-bottom: #fff1d0;
}

* { box-sizing: border-box; }

html { overflow-x: clip; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 32px;
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 9%, #ffe27a 0 46px, rgb(255 226 122 / 0.35) 47px 70px, transparent 71px),
    linear-gradient(var(--sky-top), var(--sky-bottom) 75%);
  background-attachment: fixed;
}

.intro, .stage, .controls { position: relative; z-index: 1; }

.intro { text-align: center; }

.intro h1 {
  margin: 0;
  font-family: "Chewy", "Fredoka", cursive;
  font-weight: 400;
  font-size: clamp(2.8rem, 10vw, 4.5rem);
  letter-spacing: 0.02em;
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  transform: rotate(-3deg);
}

.intro p {
  margin: 8px 0 0;
  font-size: 1.1rem;
}

/* ---------- stage & speech bubble ---------- */

.stage {
  width: min(540px, 100%);
}

.bubble-zone {
  position: relative;
  height: 170px;
}

.bubble {
  position: absolute;
  right: 6%;
  bottom: 8px;
  max-width: min(360px, 92%);
  padding: 14px 20px;
  background: var(--bubble);
  border: 4px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 6px 0 rgb(59 36 20 / 0.18);
  font-family: "Patrick Hand", "Comic Sans MS", cursive;
  font-size: clamp(1.15rem, 3.8vw, 1.4rem);
  line-height: 1.3;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.3) rotate(-8deg);
  transform-origin: 85% 120%;
  transition: opacity 0.2s, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bubble.is-visible {
  opacity: 1;
  transform: none;
}

/* tail: an ink triangle with a slightly smaller white one on top */
.bubble::before,
.bubble::after {
  content: "";
  position: absolute;
  clip-path: polygon(0 0, 100% 0, 80% 100%);
}

.bubble::before {
  right: 34px;
  bottom: -30px;
  width: 36px;
  height: 30px;
  background: var(--ink);
}

.bubble::after {
  right: 39px;
  bottom: -22px;
  width: 28px;
  height: 26px;
  background: var(--bubble);
}

.bubble-text { margin: 0; }

/* the untyped rest keeps the bubble at its final size while typing */
.bubble-text .rest { color: transparent; }

/* ---------- the horse button ---------- */

.poke {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 24px;
  -webkit-tap-highlight-color: transparent;
}

.poke:focus-visible {
  outline: 4px dashed var(--ink);
  outline-offset: 4px;
}

.horse {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  transition: transform 0.2s;
}

.poke:hover .horse { transform: rotate(-1.5deg); }
.poke:active .horse { transform: scale(0.97); }

/* shapes */
.grass { fill: var(--grass); stroke: var(--grass-dark); stroke-width: 4; }
.tufts { fill: none; stroke: var(--grass-dark); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.shadow { fill: rgb(30 60 20 / 0.28); }

.strand { fill: none; stroke: var(--mane); stroke-width: 12; stroke-linecap: round; }
.strand--outline { stroke: var(--ink); stroke-width: 20; }

.leg-line { fill: none; stroke: var(--coat); stroke-width: 20; stroke-linecap: round; stroke-linejoin: round; }
.leg--far .leg-line { stroke: var(--coat-dark); }
.leg-line--outline,
.leg--far .leg-line--outline { stroke: var(--ink); stroke-width: 28; }
.hoof { fill: var(--hoof); stroke: var(--ink); stroke-width: 4; }
.sock { fill: none; stroke: #fff; stroke-width: 20; }
.sock--stripes { stroke: #e2475d; stroke-dasharray: 5 5; }

.body, .neck, .head-shape, .ear-outer { fill: var(--coat); }
.body, .head-shape, .ear-outer, .jaw-shape, .muzzle, .mane, .forelock, .tooth, .eye-white {
  stroke: var(--ink);
  stroke-width: 4.5;
  stroke-linejoin: round;
}
.patch { fill: var(--patch); }
.ink-line { fill: none; stroke: var(--ink); stroke-width: 4.5; stroke-linecap: round; }
.mane, .forelock { fill: var(--mane); }
.ear-inner { fill: var(--pink); }
.muzzle, .jaw-shape { fill: var(--muzzle); }
.mouth { fill: #6b1f24; }
.tongue { fill: #e86f7f; }
.tooth { fill: #fffdf3; stroke-width: 3.5; }
.nostril { fill: var(--ink); }
.eye-white { fill: #fff; }
.pupil { fill: #1d120a; }
.glint { fill: #fff; }
.brow { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linecap: round; }
.flower circle { fill: #fff; stroke: var(--ink); stroke-width: 2.5; }
.flower .flower-center { fill: #ffc93c; }

/* ---------- pivots ---------- */

.horse-root { transform-box: fill-box; transform-origin: 50% 100%; }
.shadow { transform-box: fill-box; transform-origin: center; }
.leg { transform-box: fill-box; transform-origin: 50% 0; }
.eye { transform-box: fill-box; transform-origin: center; }
.tail { transform-box: view-box; transform-origin: 104px 210px; }
.head { transform-box: view-box; transform-origin: 352px 100px; }
.jaw { transform-box: view-box; transform-origin: 410px 146px; transition: transform 70ms ease-out; }
.ear--floppy { transform-box: view-box; transform-origin: 397px 42px; }
.eye--big .pupil-spin { transform-box: view-box; transform-origin: 366px 64px; }
.eye--small .pupil-spin { transform-box: view-box; transform-origin: 402px 52px; }

/* ---------- idle life ---------- */

.horse-root { animation: breathe 3.2s ease-in-out infinite; }
.tail { animation: sway 2.6s ease-in-out infinite; }
.eye { animation: blink 4.8s infinite; }
.eye--small { animation-delay: 0.14s; } /* blinks a hair late, naturally */
.ear--floppy { animation: twitch 6s ease-in-out infinite; }

@keyframes breathe {
  50% { transform: scale(1.012, 1.02); }
}

@keyframes sway {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(5deg); }
}

@keyframes blink {
  0%, 93%, 100% { transform: scaleY(1); }
  96% { transform: scaleY(0.1); }
}

@keyframes twitch {
  0%, 86%, 100% { transform: rotate(0); }
  89% { transform: rotate(-14deg); }
  92% { transform: rotate(8deg); }
  95% { transform: rotate(-4deg); }
}

/* ---------- poked! ---------- */

.is-poked .horse-root { animation: hop 1s ease-in-out; }
.is-poked .shadow { animation: shadow-hop 1s ease-in-out; }
.is-poked .tail { animation: wag 0.2s ease-in-out 5; }
.is-poked .leg--front { animation: kick-front 0.33s ease-in-out 3; }
.is-poked .leg--back { animation: kick-back 0.33s ease-in-out 3; }
.is-poked .leg--far { animation-delay: 0.16s; }
.is-poked .pupil-spin { animation: googly 0.9s cubic-bezier(0.2, 0.7, 0.3, 1); }
.is-poked .eye--small .pupil-spin { animation-direction: reverse; }

.is-neighing .head { animation: neigh 0.1s ease-in-out infinite alternate; }
.is-talking .head { animation: bob 0.36s ease-in-out infinite alternate; }
.is-talking .brow { animation: brow 0.3s ease-in-out infinite alternate; }

@keyframes hop {
  0%   { transform: none; }
  10%  { transform: scale(1.05, 0.92); }
  25%  { transform: translate(-8px, -46px) rotate(-7deg) scale(0.96, 1.05); }
  40%  { transform: scale(1.07, 0.9); }
  55%  { transform: translate(12px, -28px) rotate(6deg); }
  70%  { transform: scale(1.03, 0.97); }
  85%  { transform: translate(-3px, -6px) rotate(-2deg); }
  100% { transform: none; }
}

@keyframes shadow-hop {
  25% { transform: scale(0.65); }
  40% { transform: scale(1.05); }
  55% { transform: scale(0.75); }
  70% { transform: scale(1); }
  85% { transform: scale(0.92); }
}

@keyframes wag {
  0%, 100% { transform: rotate(-18deg); }
  50% { transform: rotate(16deg); }
}

@keyframes kick-front {
  50% { transform: rotate(-22deg); }
}

@keyframes kick-back {
  50% { transform: rotate(18deg); }
}

@keyframes googly {
  to { transform: rotate(720deg); }
}

/* head thrown back, shaking */
@keyframes neigh {
  from { transform: rotate(-10deg); }
  to { transform: rotate(-6deg); }
}

@keyframes bob {
  from { transform: rotate(-3deg); }
  to { transform: rotate(3deg); }
}

@keyframes brow {
  to { transform: translateY(-5px); }
}

/* ---------- footer ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 20px;
  margin-top: 20px;
  font-size: 1.05rem;
}

.voice-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.voice-picker select {
  appearance: none;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  padding: 8px 38px 8px 16px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1.5 1.5l4.5 4.5 4.5-4.5' fill='none' stroke='%233b2414' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 14px center;
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}

.voice-picker select:focus-visible { outline: 3px dashed var(--ink); outline-offset: 3px; }

/* ---------- clouds ---------- */

.cloud {
  position: fixed;
  left: 0;
  width: 120px;
  height: 40px;
  background: #fff;
  border-radius: 40px;
  opacity: 0.9;
  animation: drift 70s linear infinite;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: inherit;
}

.cloud::before { width: 50px; height: 50px; top: -24px; left: 16px; }
.cloud::after { width: 64px; height: 64px; top: -34px; left: 44px; }

.cloud--one { top: 14%; }
.cloud--two { top: 32%; scale: 0.7; animation-duration: 95s; animation-delay: -50s; }

@keyframes drift {
  from { transform: translateX(-180px); }
  to { transform: translateX(calc(100vw + 40px)); }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .horse, .horse * , .cloud { animation: none !important; }
  .jaw { transition: none; }
  .bubble { transform: none; transition: opacity 0.2s; }
}
