:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #553b2b;
  background: #efe0c6;
  --glass: #fff9edea;
  --line: #8d654480;
  --accent: #885827;
}

* { box-sizing: border-box; }
body { margin: 0; }
button { color: inherit; font: inherit; }

button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  --inset: clamp(12px, 2.1vw, 29px);
  --top: max(var(--inset), env(safe-area-inset-top));
  --bottom: max(var(--inset), calc(env(safe-area-inset-bottom) + 9px));
}

.scene {
  position: absolute;
  z-index: 0;
  inset: 0;
  margin: 0;
  background: #e6ccaa url("assets/living-room-wide.jpg") center / cover no-repeat;
}

.pet-area {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.stage {
  position: absolute;
  isolation: isolate;
  top: 45%;
  left: 51%;
  width: min(119svh, 108vw);
  aspect-ratio: 3 / 2;
  transform: translate(-50%, -50%);
  user-select: none;
  touch-action: none;
  -webkit-user-select: none;
}

.bird-art,
.frames,
.frames img,
.feather-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.bird-art {
  /* Keep the original toes and contact area over the complete hand. */
  mask-image: linear-gradient(to bottom, #000 86%, transparent 94%),
              linear-gradient(to bottom, #000 76%, transparent 83%),
              linear-gradient(to right, #000 58%, transparent 73%);
  mask-composite: intersect, add;
}

.perch-hand {
  position: absolute;
  top: 69.3%;
  left: 24.5%;
  width: 106.5%;
  height: auto;
  pointer-events: none;
}

.frames img { display: block; }
.stage:has(.feather-canvas:not([hidden])) .frames { opacity: 0; }
.frame-reaction {
  opacity: 0;
  transition: opacity 145ms ease-in-out;
}

.stage[data-reaction="squint"] .frame-squint,
.stage[data-reaction="tilt"] .frame-tilt,
.stage[data-reaction="puff"] .frame-puff { opacity: 1; }

.stage[data-on-bird="true"] { cursor: grab; }
.stage[data-petting="true"] { cursor: grabbing; }

.pet-zone {
  position: absolute;
  appearance: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: inherit;
}

.pet-zone:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px #835727;
}

.forehead { left: 39.5%; top: 14.8%; width: 20.8%; height: 23.8%; }
.left-cheek { left: 36.6%; top: 32.7%; width: 9%; height: 14.6%; }
.right-cheek { left: 54.5%; top: 32.7%; width: 9%; height: 14.6%; }
.belly { left: 36.1%; top: 48.7%; width: 26%; height: 27.8%; }

.head-notes {
  position: absolute;
  z-index: 1;
  top: 27%;
  left: 59%;
  pointer-events: none;
}

.note-burst {
  display: block;
  width: clamp(50px, 7vw, 76px);
  height: 64px;
  color: #fff1be;
  font: 700 clamp(23px, 3vw, 35px)/1 Georgia, serif;
  text-shadow: 0 1px 3px #64401b, 0 0 9px #80502199;
}

.note-burst span {
  position: absolute;
  bottom: 0;
  left: 0;
  opacity: 0;
  animation: head-note-float .74s linear both;
}

.note-burst span:nth-child(2) {
  left: 24%;
  color: #fff9e3;
  animation-delay: .47s;
}

.note-burst span:nth-child(3) {
  left: 10%;
  animation-delay: .94s;
}

@keyframes head-note-float {
  0% { transform: translate(-3px, 5px) scale(.55); opacity: 0; }
  20% { opacity: 1; }
  54% { opacity: 1; }
  100% { transform: translate(8px, -42px) scale(1.24); opacity: 0; }
}

@keyframes head-note-fade {
  0%, 100% { opacity: 0; }
  20%, 54% { opacity: 1; }
}

.language-picker select,
.sound,
.plumage,
figcaption {
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: 0 3px 12px #5e3a2020;
}

figcaption {
  position: absolute;
  left: 50%;
  bottom: max(10%, var(--bottom));
  width: max-content;
  max-width: calc(100% - 38px);
  margin: 0;
  padding: 8px 15px;
  transform: translateX(-50%);
  border-radius: 13px 16px 14px 15px;
  color: #5a3c27;
  font-size: .9375rem;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

figcaption:empty { opacity: 0; }

figcaption::before {
  content: "";
  position: absolute;
  top: -5px;
  left: calc(50% - 4px);
  width: 8px;
  height: 8px;
  border: solid var(--line);
  border-width: 1px 0 0 1px;
  border-radius: 2px 0 0 0;
  background: inherit;
  transform: rotate(45deg);
}

.controls {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: max(var(--inset), env(safe-area-inset-left));
  transform: translateY(-50%);
}

.plumage {
  position: relative;
  margin: 0;
  min-width: 0;
  padding: 7px 5px;
  border-radius: 40px;
}

.plumage legend,
.swatch input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
}

.swatches { display: flex; flex-direction: column; gap: 7px; }
.swatch { position: relative; cursor: pointer; }

.swatch-card {
  display: grid;
  place-items: center;
  width: 49px;
  height: 49px;
  border: 1px solid #aa815d62;
  border-radius: 50%;
  background: #fffbf3;
  transition: background-color 140ms ease, transform 140ms ease;
}

.swatch:hover .swatch-card { transform: translateY(-2px); }

.swatch input:checked + .swatch-card {
  border-color: #96592b;
  background: #f2c181;
  box-shadow: 0 0 0 1px #96592b;
}

.swatch input:focus-visible + .swatch-card {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.swatch-photo {
  width: 37px;
  height: 37px;
  border-radius: 50%;
  background-color: #efe0c6;
  background-repeat: no-repeat;
  background-size: 340%;
  background-position: 50% 43%;
}

.photo-blue { background-image: url("assets/blue-idle.jpg"); }
.photo-peach { background-image: url("assets/peach-idle.jpg"); }
.photo-violet { background-image: url("assets/violet-idle.jpg"); }

.quick-controls {
  position: absolute;
  z-index: 1;
  top: var(--top);
  right: max(var(--inset), env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
}

.language-picker { position: relative; }

.language-picker::after {
  content: "";
  position: absolute;
  top: calc(50% - 4px);
  right: 14px;
  width: 6px;
  height: 6px;
  border: solid #795036;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
  pointer-events: none;
}

.language-picker select {
  display: block;
  appearance: none;
  min-height: 44px;
  padding: 0 29px 0 13px;
  border-radius: 24px;
  font: 600 .94rem/1.2 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #67452f;
  cursor: pointer;
}

.sound {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: #795036;
  cursor: pointer;
}

.sound[aria-checked="true"] { background: #f6ddb2; }

.speaker-icon {
  position: relative;
  width: 21px;
  height: 20px;
}

.speaker-icon::before,
.speaker-icon::after {
  content: "";
  position: absolute;
}

.speaker-icon::before {
  inset: 2px auto 2px 0;
  width: 12px;
  background: currentColor;
  clip-path: polygon(0 31%, 36% 31%, 100% 0, 100% 100%, 36% 69%, 0 69%);
}

.speaker-icon::after {
  top: 5px;
  right: 0;
  width: 8px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-radius: 50%;
}

.sound[aria-checked="false"] .speaker-icon::after {
  top: 1px;
  right: 4px;
  width: 2px;
  height: 19px;
  border: 0;
  border-radius: 2px;
  background: currentColor;
  box-shadow: -2px 0 #fff9ed;
  transform: rotate(-37deg);
}

.watermark {
  position: absolute;
  z-index: 1;
  bottom: var(--bottom);
  left: max(var(--inset), env(safe-area-inset-left));
  color: #fff2dc;
  font: italic 500 clamp(.78rem, 1.5vw, .95rem)/1.2 Georgia, serif;
  letter-spacing: .03em;
  text-shadow: 0 1px 2px #4a321d;
  opacity: .68;
  pointer-events: none;
  user-select: none;
}

.storage-note {
  position: absolute;
  z-index: 2;
  top: calc(var(--top) + 67px);
  right: var(--inset);
  margin: 0;
  padding: 6px 9px;
  border-radius: 9px;
  background: var(--glass);
  color: #754422;
  font-size: .8125rem;
}

@media (max-width: 700px) and (orientation: portrait) {
  .scene { background-image: url("assets/living-room-tall.jpg"); }
  .stage { top: 43%; left: 54%; width: min(105svh, 207vw); }
  .head-notes { top: 23%; left: 60%; }
  .app { --inset: 10px; }
  .sound { width: 45px; height: 45px; }
  .swatch-card { width: 44px; height: 44px; }
  .swatch-photo { width: 34px; height: 34px; }
  figcaption { font-size: .875rem; }
}

@media (max-height: 500px) and (orientation: landscape) {
  figcaption { padding: 5px 11px; }
  .swatch-card { width: 37px; height: 37px; }
  .swatch-photo { width: 28px; height: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::after { transition: none !important; }
  .swatch:hover .swatch-card { transform: none; }
  .note-burst span { animation-name: head-note-fade; }
}
