:root {
  --paper: #f3e7cc;
  --ink: #2a1a12;
  --ink-soft: #6b5040;
  --mustard: #e8b23a;
  --teal: #3f9c96;
  --tomato: #d6452f;
  --ball: #d8e04a;
  --card: #fbf3df;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .24 0 0 0 0 .14 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.4'/%3E%3C/svg%3E");
  font-family: "Patrick Hand", "Comic Sans MS", cursive;
  font-size: 1.15rem;
  padding: 0 16px 40px;
}

header {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 4px;
}
h1 {
  font-family: "Cabin Sketch", "Patrick Hand", cursive;
  font-weight: 700;
  font-size: clamp(1.9rem, 7vw, 3.2rem);
  line-height: 1;
  margin: 0;
  color: var(--tomato);
  text-shadow: 3px 3px 0 var(--mustard);
  transform: rotate(-1.5deg);
}
.music {
  flex: none;
  width: 52px; height: 52px;
  border: 3px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  background: var(--teal);
  color: var(--paper);
  cursor: pointer;
  padding: 6px;
  box-shadow: 3px 3px 0 var(--ink);
}
.music:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.music svg { width: 100%; height: 100%; display: block; }
.music .slash { display: none; stroke: var(--tomato); stroke-width: 4; }
.music[aria-pressed="false"] { background: var(--card); color: var(--ink-soft); }
.music[aria-pressed="false"] .slash { display: block; }

main {
  max-width: 1000px;
  margin: 0 auto;
  display: grid;
  gap: 24px;
}
@media (min-width: 820px) {
  main { grid-template-columns: 1.1fr 1fr; align-items: start; }
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.liesel { width: min(62vw, 300px); height: auto; overflow: visible; margin-bottom: -18px; }
@media (min-width: 820px) { .liesel { width: 340px; } }

/* Liesel animation */
#tail { transform-origin: 224px 326px; animation: wag 1.1s ease-in-out infinite alternate; }
#head { transform-origin: 160px 190px; animation: tilt 6s ease-in-out infinite; }
#tongue { opacity: 0; transition: opacity .2s; }
.eye { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
.sparkle { transform-box: fill-box; transform-origin: center; animation: twinkle 2.4s ease-in-out infinite; }
.sparkle.s2 { animation-delay: -1.2s; }
.running #tail { animation-duration: .16s; }
.running #tongue { opacity: 1; }
.running #head { animation: perk .5s ease-in-out infinite alternate; }
.running .liesel { animation: hop .5s ease-in-out infinite; }

@keyframes wag { from { transform: rotate(-7deg); } to { transform: rotate(9deg); } }
@keyframes tilt { 0%, 60%, 100% { transform: rotate(0); } 70%, 88% { transform: rotate(-7deg); } }
@keyframes perk { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
@keyframes twinkle { 0%, 100% { transform: scale(1) rotate(0); } 50% { transform: scale(.75) rotate(20deg); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* Tennis ball */
.ball {
  position: relative;
  width: min(74vw, 300px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  color: var(--ink);
  filter: drop-shadow(5px 7px 0 rgba(42, 26, 18, .22));
  animation: bob 2.6s ease-in-out infinite;
}
.ball:active { scale: .94; }
.ball:focus-visible { outline: 4px dashed var(--teal); outline-offset: 6px; border-radius: 50%; }
.ball svg { width: 100%; height: 100%; display: block; }
.ball .seams { transform-origin: 130px 130px; }
.running .ball { animation: none; }
.running .ball .seams { animation: roll 1.4s linear infinite; }
.label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.time {
  font-family: "Chewy", "Patrick Hand", cursive;
  font-size: clamp(2.4rem, 13vw, 3.6rem);
  line-height: 1;
  color: var(--ink);
  text-shadow: 2px 2px 0 #fffbea, -2px -2px 0 #fffbea, 2px -2px 0 #fffbea, -2px 2px 0 #fffbea;
  transform: rotate(-4deg);
  font-variant-numeric: tabular-nums;
}
.sub {
  margin-top: 6px;
  font-family: "Chewy", cursive;
  font-size: 1.6rem;
  color: var(--tomato);
  text-shadow: 1px 1px 0 #fffbea, -1px -1px 0 #fffbea;
  min-height: 1.3em;
}
.ball.pop .time { animation: pop .5s ease-out; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-6px) rotate(2deg); } }
@keyframes roll { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: rotate(-4deg) scale(1.5); } 100% { transform: rotate(-4deg) scale(1); } }

/* Stats + log */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  padding: 10px 6px 8px;
  text-align: center;
  box-shadow: 4px 4px 0 var(--teal);
}
.card.c2 { box-shadow: 4px 4px 0 var(--mustard); transform: rotate(1deg); }
.card.c3 { box-shadow: 4px 4px 0 var(--tomato); transform: rotate(-1deg); }
.card .k { display: block; font-size: .95rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }
.card .v { display: block; font-family: "Chewy", cursive; font-size: clamp(1.4rem, 6vw, 1.9rem); line-height: 1.15; }

h2 {
  font-family: "Cabin Sketch", cursive;
  font-size: 1.8rem;
  margin: 26px 0 6px;
  color: var(--teal);
}
.count { font-family: "Patrick Hand", cursive; font-size: 1.1rem; color: var(--ink-soft); }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 2px dashed rgba(42, 26, 18, .3);
}
.list .when { flex: 1; min-width: 0; }
.list .when small { color: var(--ink-soft); font-size: .95rem; }
.list .dur { font-family: "Chewy", cursive; font-size: 1.35rem; }
.list .best .dur { color: var(--tomato); }
.list .best .dur::before { content: "★ "; color: var(--mustard); }
.list .pending { opacity: .6; }
.list .empty { color: var(--ink-soft); border: 0; }
.del {
  flex: none;
  width: 34px; height: 34px;
  border: 2px solid var(--ink-soft);
  border-radius: 50% 45% 55% 50%;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.del:hover { border-color: var(--tomato); color: var(--tomato); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 140%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  opacity: 0;
  pointer-events: none;
  transition: transform .25s, opacity .25s;
  max-width: calc(100vw - 32px);
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
