/* Doodle Zoo (DOODLE-ZOO-PLAN.md): a sheet of white paper filling the screen, edged by
   the cave, with the three pens on a rail down the left. */

#doodle {
  position: fixed; inset: 0; z-index: 20; overflow: hidden;
  background: radial-gradient(circle at 30% 20%, #4a3a6e, #241a3a 70%);
  animation: potions-in 0.3s ease;
  --rail: 136px;
  --paper: #ffffff;
  --ink: #1d1a24;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}

.dz-room { position: absolute; inset: 0; }

/* ------------------------------------------------------------- the paper */

.dz-view {
  position: absolute; left: var(--rail); right: 10px;
  top: calc(10px + env(safe-area-inset-top, 0px)); bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  border-radius: 22px; overflow: hidden; background: var(--paper);
  box-shadow: 0 10px 30px rgba(10, 4, 24, 0.5), inset 0 0 0 3px #ffffff;
  touch-action: none; cursor: crosshair;
}
.dz-cam { position: absolute; inset: 0; transform-origin: 0 0; }
.dz-page { position: absolute; }
.dz-scene {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0;
  transition: opacity 0.8s ease; pointer-events: none;
}
.finale .dz-scene { opacity: 1; }
.finale .dz-view { cursor: pointer; }
/* in the finished scene the paper's white goes and the scene fills the whole sheet */
.dz-room.finale .dz-view { background: #8fd6ff; }
.dz-hop, .dz-art, .dz-ink, .dz-over { position: absolute; inset: 0; width: 100%; height: 100%; }
.dz-art, .dz-ink, .dz-over { display: block; pointer-events: none; }
.dz-ink { transition: opacity 0.35s ease; }
.dz-ink.fading { opacity: 0; }

/* the dashed guide: a pale fill, and dashes that march round it */
.dz-guide-fill { fill: #e6f7fb; opacity: 0.55; }
.dz-guide-line {
  fill: none; stroke: #2a9bb0; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 18 16; animation: dz-march 1.1s linear infinite;
}
@keyframes dz-march { to { stroke-dashoffset: -34; } }
.dz-dot { fill: #ffd84a; stroke: #ffffff; stroke-width: 5; filter: drop-shadow(0 0 8px #ffcf3a); }

.dz-eye { transform-box: view-box; animation: dz-blink 4.6s ease-in-out infinite; }
@keyframes dz-blink { 0%, 93%, 100% { scale: 1 1; } 96% { scale: 1 0.08; } }
.dz-pupil { transition: transform 0.12s ease-out; }

.dz-spark { animation: dz-spark 0.7s ease-out forwards; }
@keyframes dz-spark { 0% { scale: 0.2; opacity: 1; } 50% { scale: 1.15; opacity: 1; } 100% { scale: 0.4; opacity: 0; rotate: 40deg; } }
.dz-twinkle { animation: dz-twinkle 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes dz-twinkle { 50% { opacity: 0.35; scale: 0.7; } }

/* the animal comes alive: a happy bounce, over and over, squashing as it lands */
.dz-hop.alive { animation: dz-hop 1.5s ease-in-out infinite; }
@keyframes dz-hop {
  0%, 100% { translate: 0 0; scale: 1 1; }
  12% { translate: 0 0; scale: 1.05 0.94; }
  40% { translate: 0 -5%; scale: 0.97 1.04; }
  62% { translate: 0 0; scale: 1.04 0.96; }
  76% { scale: 1 1; }
}
.dz-hop.alive.jump { animation: dz-jump 0.6s cubic-bezier(.3, 1.4, .5, 1), dz-hop 1.5s ease-in-out 0.6s infinite; }
@keyframes dz-jump { 0% { scale: 1.08 0.9; } 45% { translate: 0 -11%; scale: 0.94 1.08; } 100% { translate: 0 0; scale: 1 1; } }

/* ------------------------------------------------------------ the picker */

.dz-pick {
  position: absolute; left: var(--rail); right: 10px; z-index: 4;
  top: calc(10px + env(safe-area-inset-top, 0px)); bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  border-radius: 22px; background: linear-gradient(180deg, #fff6e8, #ffe6f0);
  display: grid; place-items: center; padding: 60px 16px 14px;
}
.dz-cards {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(8px, 1.8vw, 22px);
  width: min(100%, 980px, (100vh - 120px) * 1.78);
}
.dz-slot { position: relative; }
.dz-slot .dz-card { width: 100%; }
.dz-card {
  aspect-ratio: 4 / 3; padding: 6px; border-radius: 22px; overflow: hidden;
  background: #ffffff; border: 5px solid #ffc46b; box-shadow: 0 8px 18px rgba(90, 40, 60, 0.18);
  display: grid; place-items: center;
}
.dz-slot:nth-child(3n + 2) .dz-card { border-color: #8fd6ff; }
.dz-slot:nth-child(3n) .dz-card { border-color: #ff9ec4; }

/* the "start over" button on a finished card: tap once and it wiggles, tap again to wipe */
.dz-clear {
  position: absolute; right: -8px; top: -8px; width: 48px; height: 48px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; z-index: 2;
  background: radial-gradient(circle at 40% 35%, #ffd0e4, #ff7aa8); border: 3px solid #ffffff;
  box-shadow: 0 3px 8px rgba(90, 40, 60, 0.35);
}
.dz-clear svg { width: 62%; height: 62%; }
.dz-clear path { fill: none; stroke: #ffffff; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.dz-clear.bump { animation: dz-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }
.dz-slot.armed .dz-clear { scale: 1.25; animation: dz-wiggle 0.5s ease-in-out infinite; background: radial-gradient(circle at 40% 35%, #ffb0b0, #f0464f); }
.dz-slot.armed .dz-card { box-shadow: 0 0 0 5px #f0464f, 0 8px 18px rgba(90, 40, 60, 0.18); }
@keyframes dz-wiggle { 25% { rotate: -14deg; } 75% { rotate: 14deg; } }
.dz-slot.wiping .dz-card img { animation: dz-wipe 0.4s ease-in forwards; }
@keyframes dz-wipe { to { opacity: 0; scale: 0.6; rotate: -8deg; filter: blur(4px); } }
.dz-card svg, .dz-card img { width: 100%; height: 100%; object-fit: contain; display: block; }
.dz-card.going { box-shadow: 0 0 0 6px #ffd84a, 0 8px 18px rgba(90, 40, 60, 0.18); }
.dz-card.bump { animation: dz-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }

/* ------------------------------------------------------------- the pens */

.dz-rail {
  position: absolute; left: 0; top: 0; bottom: 0; width: var(--rail); z-index: 5;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 12px;
  padding: 76px 0 12px;
}
.dz-rail.resting .dz-pen, .dz-rail.resting .dz-swatch { opacity: 0.35; pointer-events: none; }

/* each pen lies on its side, its tip toward the paper; the one in her hand slides out */
.dz-pen {
  position: relative; width: 124px; height: 60px; padding: 0; border: 0; background: none;
  translate: -26px 0; transition: translate 0.18s ease;
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, 0.35));
}
.dz-pen[aria-pressed="true"] { translate: 4px 0; }
.dz-pen > span { position: absolute; top: 50%; translate: 0 -50%; }
.dz-barrel {
  left: 6px; width: 84px; height: 44px; border-radius: 10px 4px 4px 10px;
  background: var(--barrel, #222); background-size: 36px 36px;
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.16), inset 0 7px 0 rgba(255, 255, 255, 0.3), 0 0 0 3px #ffffff;
}
.dz-tip {
  left: 86px; width: 34px; height: 36px; background: var(--barrel, #222); background-size: 36px 36px;
  clip-path: polygon(0 0, 100% 42%, 100% 58%, 0 100%);
}
.dz-end { left: 0; width: 14px; height: 50px; border-radius: 8px; background: #f2f0f6; box-shadow: 0 0 0 3px #ffffff; }
.dz-pen-marker .dz-end { background: #f2f0f6; }
.dz-pen-glitter .dz-end { background: linear-gradient(135deg, #fff6b0, #ffc2ef, #b6ecff); }
.dz-pen-pattern .dz-end { background: repeating-linear-gradient(90deg, #ff6f9f 0 4px, #ffd84a 4px 8px); }
/* the eraser: a fat two-tone rubber block, its worn end toward the paper */
.dz-pen-eraser .dz-rubber {
  position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 100px; height: 46px;
  border-radius: 8px 16px 16px 8px; overflow: hidden;
  background: linear-gradient(90deg, #6fc3ff 0 44%, #ff9ec4 44%);
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.14), inset 0 7px 0 rgba(255, 255, 255, 0.35), 0 0 0 3px #ffffff;
}
.dz-pen-eraser .dz-rubber i {
  position: absolute; left: 44%; top: 0; bottom: 0; width: 6px; background: rgba(255, 255, 255, 0.55);
}
.dz-cap-star {
  position: absolute; left: -2px; top: 50%; width: 30px; height: 30px; translate: 0 -50%;
  fill: #fff6b0; stroke: #ffffff; stroke-width: 1.5; filter: drop-shadow(0 0 4px #ffe36b);
}
.dz-pen.bump { animation: dz-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }

.dz-swatch {
  width: 70px; height: 70px; margin-left: 30px; padding: 0; border-radius: 50%;
  background: #ffffff; border: 0; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35); display: grid; place-items: center;
}
.dz-swatch span {
  width: 54px; height: 54px; border-radius: 50%; background: var(--swatch, #222); background-size: 30px 30px;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15);
}
.dz-swatch.bump { animation: dz-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }

.dz-creature { width: 96px; margin: 6px 0 0 18px; pointer-events: none; }
.dz-creature canvas { width: 100%; height: auto; display: block; }
.dz-creature.bump { animation: dz-bump 0.45s cubic-bezier(.3, 1.5, .5, 1); }

/* ------------------------------------------------------------ the popover */

.dz-pop {
  position: absolute; z-index: 8; left: calc(var(--rail) + 8px); top: 50%; translate: 0 -50%;
  padding: 14px; border-radius: 22px; background: #ffffff;
  box-shadow: 0 14px 34px rgba(20, 8, 40, 0.45), 0 0 0 4px #ffd27a;
}
.dz-pop.bump { animation: dz-pop-in 0.25s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes dz-pop-in { from { scale: 0.85; opacity: 0; } }
.dz-grid { display: grid; grid-template-columns: repeat(8, var(--sw, 50px)); gap: 8px; }
.dz-sw {
  width: var(--sw, 50px); height: var(--sw, 50px); padding: 0; border-radius: 12px; border: 0;
  background: var(--c); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.14), inset 0 6px 0 rgba(255, 255, 255, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.dz-sw.on { box-shadow: 0 0 0 4px #ffffff, 0 0 0 7px #1d1a24; }
.dz-rainbow {
  grid-column: 1 / -1; width: 100%;
  background: linear-gradient(90deg, #ff4d4d, #ffb03a, #ffe14d, #6ad65a, #4fc3f7, #6a6ff0, #c86ff0);
}
.dz-pats { display: grid; grid-template-columns: repeat(4, 92px); gap: 12px; }
.dz-pat {
  width: 92px; height: 92px; padding: 0; border-radius: 18px; border: 0;
  background: var(--tile) 0 0 / 46px 46px; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.15);
}
.dz-pat.on { box-shadow: 0 0 0 4px #ffffff, 0 0 0 7px #1d1a24; }
.dz-sw.bump, .dz-pat.bump { animation: dz-bump 0.3s cubic-bezier(.3, 1.5, .5, 1); }

/* -------------------------------------------------------------- buttons */

.dz-round {
  position: absolute; z-index: 6; padding: 0; border-radius: 50%; display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(20, 8, 40, 0.35);
}
.dz-round svg { width: 60%; height: 60%; }
.dz-done, .dz-more {
  right: 22px; top: calc(20px + env(safe-area-inset-top, 0px)); width: 78px; height: 78px;
  background: radial-gradient(circle at 40% 35%, #b6f0a0, #4cb85a); border: 4px solid #eaffe0;
}
.dz-done { opacity: 0.75; }
.dz-done path { fill: none; stroke: #ffffff; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.dz-done.ready { opacity: 1; animation: done-glow 1.8s ease-in-out infinite; }
.dz-more { background: radial-gradient(circle at 40% 35%, #ffe08a, #f0a930); border-color: #fff3c8; animation: done-glow 1.8s ease-in-out infinite; }
.dz-more rect { fill: #ffffff; }
.dz-undo {
  right: 22px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); width: 64px; height: 64px;
  background: radial-gradient(circle at 40% 35%, #d9cdf5, #9a86d0); border: 3px solid #f2ecff;
}
.dz-undo path { fill: none; stroke: #ffffff; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.dz-undo.off { opacity: 0.4; }
.dz-round.bump { animation: dz-bump 0.35s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes dz-bump { 40% { scale: 1.12; } }

/* the title pill sits over the paper's top edge; the back button over the rail */
#doodle .room-title { left: calc(50% + var(--rail) / 2 - 5px); }
#doodle .room-title:active { transform: translateX(-50%) scale(0.95); }

/* ---------------------------------------------------- smaller screens */

@media (max-height: 560px) {
  #doodle { --rail: 104px; }
  .dz-rail { gap: 6px; padding-top: 64px; }
  .dz-pen { width: 100px; height: 46px; translate: -22px 0; }
  .dz-barrel { width: 66px; height: 34px; }
  .dz-tip { left: 68px; width: 28px; height: 28px; }
  .dz-end { height: 38px; }
  .dz-swatch { width: 54px; height: 54px; margin-left: 24px; }
  .dz-swatch span { width: 42px; height: 42px; }
  .dz-creature { display: none; }
  .dz-grid { --sw: 34px; gap: 5px; }
  .dz-pats { grid-template-columns: repeat(4, 62px); gap: 8px; }
  .dz-pat { width: 62px; height: 62px; }
  .dz-done, .dz-more { width: 58px; height: 58px; }
  .dz-undo { width: 50px; height: 50px; }
  .dz-pick { padding-top: 54px; }
  .dz-pen-eraser .dz-rubber { width: 80px; height: 34px; }
  .dz-clear { width: 40px; height: 40px; right: -6px; top: -6px; }
}
@media (max-aspect-ratio: 5/6) {
  /* an upright screen: the pens lie along the bottom instead */
  #doodle { --rail: 10px; }
  .dz-view, .dz-pick { bottom: 120px; }
  .dz-rail { top: auto; bottom: 0; left: 0; right: 0; width: auto; height: 110px; flex-direction: row; align-items: center; padding: 0 12px; }
  .dz-pen { translate: 0 0; width: 100px; }
  .dz-pen[aria-pressed="true"] { translate: 0 -8px; }
  .dz-creature { display: none; }
  .dz-pop { left: 50%; top: auto; bottom: 120px; translate: -50% 0; }
  .dz-grid { --sw: min(44px, 9vw); }
  .dz-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  .dz-undo { bottom: 130px; }
  #doodle .room-title { left: 50%; }
}
