:root {
  color-scheme: light;
  --paper: #f3eee4;
  --ink: #26392b;
  --muted: #4e5847;
  --line: #b7bba4;
  --selected: #dce0c8;
  --hover: #e9e9d8;
  --mat: #797e58;
  --ivory: #fff8e9;
  --serif: Georgia, 'Times New Roman', serif;
}
:root[data-night] {
  color-scheme: dark;
  --paper: #1a2424;
  --ink: #f2edda;
  --muted: #c3caad;
  --line: #596455;
  --selected: #465444;
  --hover: #364437;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, select:focus-visible, summary:focus-visible, .stage:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
}
[hidden] { display: none !important; }

.page {
  width: min(100% - clamp(28px, 2.6vw, 68px), 1480px);
  margin-inline: auto;
  padding-block: clamp(19px, 3.2vw, 36px) 30px;
}
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 13px;
}
.wordmark {
  font-size: clamp(22px, 2.5vw, 34px);
  font-weight: 700;
  letter-spacing: -.035em;
}
.sound:disabled { cursor: wait; opacity: .65; }

.zoo {
  display: grid;
  grid-template-columns: minmax(208px, .21fr) minmax(0, 1fr);
  align-items: start;
  gap: clamp(18px, 1.5vw, 32px);
  margin-top: clamp(26px, 5vh, 76px);
}
.chooser { container-type: inline-size; }
h1 {
  margin: 4px 0 0;
  font-size: clamp(39px, 18.5cqi, 64px);
  line-height: .98;
  letter-spacing: -.055em;
  overflow-wrap: normal;
}
h1 span { display: block; }
.instructions {
  max-width: 25ch;
  margin: 24px 0 29px;
  color: var(--muted);
  font-size: clamp(18px, 1.6vw, 23px);
  line-height: 1.36;
}
.animals { display: grid; gap: 9px; }
.instructions[data-alternate] { display: grid; }
.instructions[data-alternate] > span, .instructions[data-alternate]::after { grid-area: 1 / 1; }
.instructions[data-alternate]::after { content: attr(data-alternate); visibility: hidden; }
.animal {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  min-height: 80px;
  gap: clamp(8px, 1vw, 14px);
  padding: 9px 12px;
  border: 1px solid transparent;
  border-bottom-color: var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}
.animal:last-child { border-bottom-color: transparent; }
.animal:hover { background: var(--hover); border-radius: 12px; }
.animal[aria-pressed="true"] {
  border-color: transparent;
  border-radius: 12px;
  background: var(--selected);
}
.animal::after {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  margin-left: auto;
  border-radius: 50%;
  background: var(--ink);
  content: '';
  visibility: hidden;
}
.animal[aria-pressed="true"]::after { visibility: visible; }
.portrait {
  width: clamp(50px, 5vw, 72px);
  aspect-ratio: 1;
  flex: 0 0 auto;
  border-radius: 50%;
  background-color: #9b9c78;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}
.animal-text { display: grid; min-width: 0; gap: 2px; }
.animal-text strong { font-size: clamp(20px, 11cqi, 28px); line-height: 1; }
.animal-text span { font-size: clamp(15px, 1.5vw, 20px); color: var(--muted); overflow-wrap: anywhere; }

@media (min-width: 821px) {
  .zoo {
    grid-template-areas: "intro scene" "animals scene";
    grid-template-rows: auto 1fr;
    row-gap: 0;
  }
  .chooser { grid-area: intro; }
  .viewer { grid-area: scene; }
  .animals { grid-area: animals; }
  .instructions { margin-block: 15px 13px; }
  .animals { gap: 3px; }
  .animal { min-height: 52px; gap: 9px; padding: 4px 8px; }
  .portrait { width: clamp(39px, 3.45vw, 51px); }
  .animal-text strong { font-size: clamp(20px, 1.83vw, 27px); }
  .animal-text span { font-size: clamp(15px, 1.2vw, 18px); }
}

.viewer { min-width: 0; }
.stage {
  position: relative;
  isolation: isolate;
  aspect-ratio: 1517 / 935;
  overflow: hidden;
  border-radius: clamp(13px, 1.7vw, 24px);
  background: var(--mat) url('assets/cushion.jpg') center / cover no-repeat;
  box-shadow: 0 1px 0 rgba(39, 42, 24, .17);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.stage[data-contact] { cursor: none; }
.stage::before {
  position: absolute;
  z-index: 4;
  inset: 0;
  background: linear-gradient(145deg, #a6bed8 1%, #899eb7 25%, #4e668a 26%, #748eb2 36%, #536989 37%, #33466a 82%);
  mix-blend-mode: multiply;
  opacity: 0;
  content: '';
  pointer-events: none;
}
:root[data-night] .stage::before { opacity: .82; }
.stage::after {
  position: absolute;
  z-index: 1;
  inset: 63% 0 0;
  background: linear-gradient(transparent, #17201551);
  content: '';
  pointer-events: none;
}
.body, .hand, .scene-caption, .stage-state { position: absolute; pointer-events: none; }
.body {
  inset: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 3px 3px #2123167a) drop-shadow(1px 12px 14px #20221851);
}
.hand {
  z-index: 2;
  top: 0;
  left: 0;
  height: auto;
  opacity: 0;
  transform-origin: 0 0;
  filter: drop-shadow(
    calc(1px + 4px * var(--hand-lift, 0))
    calc(3px + 7px * var(--hand-lift, 0))
    calc(2.5px + 5px * var(--hand-lift, 0))
    rgb(33 29 25 / calc(.46 - .24 * var(--hand-lift, 0)))
  );
  will-change: transform, opacity;
}
.raccoon-paws {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: url('assets/raccoon-paws.png') center / 100% 100% no-repeat;
}
.scene-caption {
  z-index: 5;
  bottom: clamp(14px, 2.2vw, 35px);
  left: clamp(16px, 2.5vw, 39px);
  color: var(--ivory);
  font-size: clamp(26px, 3.2vw, 45px);
  line-height: 1;
  text-shadow: 0 2px 12px #141b12db, 0 1px 4px #141b12;
}
.stage-state {
  z-index: 6;
  top: 45%;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 30px);
  margin: 0;
  padding: 10px 14px;
  transform: translate(-50%, -50%);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  text-align: center;
}
.scene-tools {
  --tool-size: 44px;
  --tool-icon-size: 21px;
  --tool-gap: 8px;
  --coat-check-size: 17px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--tool-gap);
  padding-block: 8px;
}
.scene-actions {
  position: relative;
  display: flex;
  gap: var(--tool-gap);
  margin-inline-start: auto;
}
.tool-icon {
  width: var(--tool-icon-size);
  height: var(--tool-icon-size);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.scene-button {
  display: grid;
  place-items: center;
  width: var(--tool-size);
  height: var(--tool-size);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.scene-button:hover, .scene-button[aria-pressed="true"], .scene-tools details[open] > summary {
  background: var(--selected);
}
.scene-tools summary { list-style: none; }
.scene-tools summary::-webkit-details-marker { display: none; }
.sound-on, .expand-close,
.sound[aria-pressed="true"] .sound-off, .expand[aria-pressed="true"] .expand-open {
  display: none;
}
.sound[aria-pressed="true"] .sound-on, .expand[aria-pressed="true"] .expand-close {
  display: inline;
}
.scene-panel {
  position: absolute;
  z-index: 8;
  bottom: calc(100% + 9px);
  inset-inline-end: 0;
  width: min(235px, 90vw);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 7px 22px #111a1a2b;
  font-size: 15px;
}
.coat-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tool-gap);
}
.coat-swatch {
  position: relative;
  width: var(--tool-size);
  height: var(--tool-size);
  padding: 2px;
  border: 2px solid transparent;
  border-radius: 50%;
  background: transparent;
}
.coat-swatch:hover { border-color: var(--line); }
.coat-swatch[aria-pressed="true"] { border-color: var(--ink); }
.coat-texture {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--mat) center / 880% auto no-repeat;
}
.stage[data-animal="panda"] + .scene-tools .coat-texture { background-position: 41% center; }
.coat-check {
  position: absolute;
  inset-inline-end: -3px;
  inset-block-end: -3px;
  display: none;
  width: var(--coat-check-size);
  height: var(--coat-check-size);
  place-items: center;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font: bold 10px/1 system-ui, sans-serif;
}
.coat-swatch[aria-pressed="true"] .coat-check { display: grid; }
.proportions-panel label { display: flex; justify-content: space-between; gap: 7px; }
.proportions-panel output { color: var(--muted); }
.proportions-panel input { display: block; width: 100%; height: 28px; margin: 0 0 6px; accent-color: var(--ink); }
.reset-size { padding: 5px 0; border: 0; background: none; text-decoration: underline; text-underline-offset: 2px; }

.viewer.is-expanded {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 100%;
  height: 100%;
  padding: 9px;
  background: var(--paper);
}
:root[data-expanded] { overflow: hidden; }
.viewer.is-expanded .stage {
  width: min(100%, calc((100dvh - 81px) * 1.62246));
  height: auto;
  max-height: none;
  margin: 0;
}
.viewer.is-expanded .scene-tools { justify-content: center; }
@media (pointer: coarse) {
  .viewer.is-expanded { --expanded-toolbar-space: 81px; }
}
@media (orientation: landscape) and (pointer: coarse) {
  .viewer.is-expanded .stage { width: min(100%, calc((100dvh - var(--expanded-toolbar-space)) * 2)); aspect-ratio: 2; }
}
@media (orientation: portrait) and (pointer: coarse) {
  .viewer.is-expanded {
    inset: 0 auto auto 0;
    width: 100dvh !important;
    height: 100dvw !important;
    transform: translateX(100dvw) rotate(90deg);
    transform-origin: top left;
  }
  .viewer.is-expanded .stage { width: min(100%, calc((100dvw - var(--expanded-toolbar-space)) * 2)); aspect-ratio: 2; }
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.script-note { margin: 0 18px 20px; }

@media (min-width: 821px) and (max-height: 790px) {
  .page { padding-top: 14px; }
  .masthead { padding-bottom: 7px; }
  .wordmark { font-size: clamp(22px, 2.25vw, 30px); }
  .zoo { margin-top: 16px; }
}
@media (min-width: 961px), (min-width: 821px) and (height > 500px) {
  .page { max-width: 1220px; padding-top: 16px; }
  .masthead { padding-bottom: 10px; }
  .zoo {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "intro" "animals" "scene";
    grid-template-rows: auto auto auto;
    gap: 14px;
    margin-top: 18px;
  }
  .chooser { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 26px; }
  h1 { margin: 0; font-size: 36px; }
  h1 span { display: inline; }
  .instructions { max-width: none; margin: 0; font-size: 18px; }
  .animals {
    grid-auto-flow: column;
    grid-auto-columns: minmax(86px, 1fr);
    gap: 4px;
    padding-block: 2px;
    overflow-x: auto;
  }
  .animal {
    position: relative;
    display: grid;
    justify-items: center;
    align-content: start;
    gap: 6px;
    padding: 8px 0 7px;
    border-color: transparent;
    border-radius: 12px;
    text-align: center;
  }
  .animal:focus-visible { outline-offset: -2px; }
  .animal::after {
    position: absolute;
    top: 39px;
    left: calc(50% + 10px);
    width: 13px;
    height: 13px;
    border: 2px solid var(--selected);
  }
  .portrait { width: 43px; }
  .animal-text strong { font-size: 18px; }
  .animal-text span { font-size: 14px; }
  .viewer:not(.is-expanded) .stage {
    width: 100%;
    height: clamp(240px, calc(100dvh - 320px), 680px);
    aspect-ratio: auto;
  }
}
@media (max-width: 820px) {
  .page { width: calc(100% - 36px); }
  .zoo { grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 28px; }
  .chooser { display: grid; }
  h1 { font-size: clamp(36px, 7.8vw, 53px); }
  h1 span { display: inline; }
  .instructions { max-width: none; margin: 8px 0 0; font-size: 17px; }
  .animals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .animal { min-height: 60px; border-bottom-color: transparent; padding: 5px 9px; }
  .animal-text strong { font-size: clamp(20px, 5.25vw, 23px); }
  .portrait { width: 45px; }
  .stage { max-height: 62svh; }
}
@media (max-width: 620px) {
  .viewer:not(.is-expanded) .stage { width: calc(100% + 22px); margin-inline: -11px; aspect-ratio: 1.56; }
}
@media (max-width: 520px) {
  .page { padding-top: 12px; }
  .masthead { padding-bottom: 8px; }
  .zoo { margin-top: 16px; gap: 12px; }
  .scene-tools { --tool-gap: 4px; }
  .animal { min-height: 57px; }
  .portrait { width: 39px; }
  .animal::after { width: 8px; height: 8px; }
}
@media (max-width: 365px) {
  .page { width: calc(100% - 28px); }
  .animal { position: relative; gap: 7px; padding-inline: 5px; }
  .animal::after {
    position: absolute;
    left: 30px;
    top: calc(50% + 6px);
    box-shadow: 0 0 0 2px var(--selected);
  }
  .portrait { width: 34px; }
  .viewer:not(.is-expanded) .stage { width: calc(100% + 14px); margin-inline: -7px; }
}
@media (max-width: 339px) {
  .animal { gap: 4px; padding-inline: 3px; }
  .viewer:not(.is-expanded) .scene-tools { position: relative; }
  .viewer:not(.is-expanded) .scene-actions { position: static; margin-inline-start: 0; }
  .viewer:not(.is-expanded) .proportions-panel { inset-inline: 0 auto; }
}
@media (max-width: 960px) and (orientation: landscape) and (max-height: 500px) {
  .page { padding-top: 8px; }
  .masthead { padding-bottom: 5px; }
  .zoo {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    grid-template-areas: "intro scene" "animals animals";
    gap: 12px;
    margin-top: 10px;
  }
  .chooser { grid-area: intro; }
  .viewer { grid-area: scene; }
  .animals { grid-area: animals; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  h1 { font-size: clamp(29px, 5vw, 36px); }
  .viewer:not(.is-expanded) .stage { width: 100%; max-height: 65svh; margin: 0; aspect-ratio: 2; }
  .scene-tools { --tool-gap: 4px; }
}
