:root {
  color-scheme: light;
  --paper: #cee4ec;
  --paper-light: #dbecf0;
  --paper-edge: #bdd8e3;
  --ivory: #fbf3e3;
  --blush: #f1d3c6;
  --ink: #8b3833;
  --ink-soft: #754541;
  --rule: #a0524b80;
  --shadow: #38596e28;
  --sky: #233454b8;
  --blue: #34567d6b;
  --snow-blue: #46648525;
  --star: #ffedcb;
  --lamp-spill: #f8c27343;
  --rabbit-paper: #f6ecdb;
  --hamster-paper: #f9ead5;
  --font: 'Palatino Linotype', 'Book Antiqua', Palatino, Georgia, serif;
  --hand: 'Segoe Print', 'Bradley Hand', 'Apple Chancery', var(--font);
  --scene-ratio: 1105 / 1347;
  --dusk: 1.65s;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: radial-gradient(ellipse at 48% 37%, var(--paper-light), var(--paper) 67%, var(--paper-edge) 140%);
  font-family: var(--font);
}
body::before {
  position: fixed;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  content: '';
  background: url('assets/paper.svg');
  mix-blend-mode: multiply;
  opacity: .20;
}
button { color: inherit; font: inherit; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.definitions { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.world {
  --globe-width: min(594px, calc((100svh - 133px) * .82), calc(100vw - 63px));
  position: relative;
  display: grid;
  grid-template-areas: 'scene' 'controls';
  align-content: center;
  justify-items: center;
  gap: 18px;
  min-height: 100vh;
  min-height: 100svh;
  padding: 24px 15px;
  overflow: hidden;
}
.scene { grid-area: scene; position: relative; width: max(194px, var(--globe-width)); aspect-ratio: var(--scene-ratio); margin: 0; container-type: inline-size; }
.contact-shadow {
  position: absolute;
  inset: auto 5% -1.6%;
  height: 4%;
  background: radial-gradient(ellipse, var(--shadow), transparent 70%);
  filter: blur(3px);
  pointer-events: none;
}
.globe {
  --tilt: 0deg;
  --slide: 0px;
  --lift: 0px;
  --fit: 1;
  position: absolute;
  inset: 0;
  transform: translate(var(--slide), var(--lift)) rotate(var(--tilt)) scale(var(--fit));
  transform-origin: 50% 50%;
  user-select: none;
  -webkit-user-select: none;
  container-type: inline-size;
}
.globe-art, .night-art, .night-art img, .night-sky, .stars, .globe-residents, .snow, .still-snow, .glass-touch {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.in-glass { clip-path: url('#glass'); }
.night-art, .night-sky, .stars, .lamplight { opacity: 0; transition: opacity var(--dusk) ease-in-out; }
.night-art img { filter: brightness(.73) saturate(.73); }
.night-sky { background: linear-gradient(173deg, var(--sky) 5%, var(--blue) 47%, var(--snow-blue) 78%); }
.stars { fill: var(--star); }
.lamplight { position: absolute; left: 62.986%; top: 45.286%; width: 15.023%; height: 13.660%; pointer-events: none; }
.lamplight::before { content: ''; position: absolute; inset: 22% -25% -38%; background: radial-gradient(ellipse at 49% 55%, var(--lamp-spill), transparent 72%); }
.lamplight img { position: relative; display: block; width: 100%; height: 100%; }
[data-light='night'] :is(.night-art, .night-sky) { opacity: 1; }
[data-light='night'] .stars { opacity: .88; transition-delay: .25s; }
[data-light='night'] .lamplight { opacity: .94; }

.companion {
  position: absolute;
  z-index: 5;
  display: grid;
  place-items: end center;
  width: max(var(--animal-width), 44px);
  height: max(var(--animal-height), 44px);
  transform: translateX(-50%);
  border: 0;
  border-radius: 42%;
  padding: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.companion.rabbit { --animal-width: 11%; --animal-height: 13.9%; --eye-ink: var(--rabbit-paper); left: 4.3%; bottom: 3.4%; }
.companion.hamster { --animal-width: 9%; --animal-height: 9.3%; --eye-ink: var(--hamster-paper); left: 95%; bottom: 2.8%; }
.companion:active { cursor: grabbing; }
.companion.is-held { opacity: 0; }
.globe-residents { z-index: 3; }
.globe-residents > .companion { pointer-events: auto; }
.companion.rabbit[data-place='inside'] { left: 38.2%; bottom: 28.5%; }
.companion.hamster[data-place='inside'] { left: 72.1%; bottom: 32.6%; }
.animal-art { display: block; position: absolute; bottom: 0; height: min(100%, 17cqw); transform-origin: 50% 97%; pointer-events: none; }
.animal-art img { display: block; height: 100%; }
.hamster .animal-art { height: min(100%, 11.2cqw); }
.rabbit[data-place='inside'] .animal-art { height: 10.6cqw; }
.hamster[data-place='inside'] .animal-art { height: 6.83cqw; }
.globe-residents > .companion[data-physics] {
  left: var(--body-x);
  top: var(--body-y);
  bottom: auto;
  transform: translate(-50%, -50%) rotate(var(--body-angle));
}
.globe-residents > .companion[data-physics] .animal-art { bottom: 50%; translate: 0 50%; }
.globe-residents > .companion[data-physics] .animal-ground { display: none; }
[data-light='night'] .globe-residents .animal-art { filter: brightness(.77) saturate(.79); }
.globe-residents .animal-art { transition: filter var(--dusk) ease; }
.animal-ground { position: absolute; left: -4%; right: -8%; bottom: -7%; height: 19%; background: radial-gradient(ellipse, var(--shadow), transparent 72%); pointer-events: none; }
[data-place='inside'] .animal-ground { left: 23%; right: 23%; bottom: -4%; height: 10%; }
.blink { position: absolute; display: block; width: 9%; height: 5.8%; border-radius: 50%; background: var(--eye-ink); opacity: 0; }
.blink::after { position: absolute; content: ''; inset: 44% 14% 25%; border-top: 1px solid var(--ink-soft); border-radius: 50%; transform: rotate(-9deg); }
.rabbit .blink { left: 71%; top: 45.1%; }
.hamster .blink { left: 27.1%; top: 30.7%; }
.drag-companion { position: fixed; z-index: 8; top: 0; left: 0; pointer-events: none; }
.drag-companion .animal-art, .drag-companion .animal-art img { inset: 0; width: 100%; height: 100%; }
.drag-companion .animal-art { transform-origin: 53% 78%; }
.drag-companion.is-gripped .animal-art { animation: held-shiver .29s linear infinite; }
.drag-companion.rabbit { --shiver-x: .72px; --shiver-angle: 1.45deg; }
.drag-companion.hamster { --shiver-x: .53px; --shiver-angle: 1.12deg; }
.drag-companion .blink { display: none; }
.held-rabbit-art {
  position: absolute;
  top: 0;
  left: -12.4183%;
  width: 118.9542%;
  height: 100%;
  background: url('assets/rabbit-ears.webp') no-repeat 0% 0% / 1800% 100%;
}
@keyframes held-shiver {
  0%, 100% { transform: translateX(0) rotate(0); }
  14% { transform: translateX(var(--shiver-x)) rotate(var(--shiver-angle)); }
  29% { transform: translateX(calc(var(--shiver-x) * -.8)) rotate(calc(var(--shiver-angle) * -.8)); }
  47% { transform: translateX(calc(var(--shiver-x) * .42)) rotate(calc(var(--shiver-angle) * .72)); }
  65% { transform: translateX(calc(var(--shiver-x) * -.54)) rotate(calc(var(--shiver-angle) * -.56)); }
  84% { transform: translateX(calc(var(--shiver-x) * .64)) rotate(calc(var(--shiver-angle) * .33)); }
}

.snow, .still-snow { z-index: 3; }
.still-snow {
  opacity: 0;
  background:
    radial-gradient(circle at 39% 26%, var(--ivory) 0 1px, transparent 1.6px),
    radial-gradient(circle at 54% 16%, var(--ivory) 0 1px, transparent 1.5px),
    radial-gradient(circle at 58% 39%, var(--ivory) 0 1.2px, transparent 1.9px),
    radial-gradient(circle at 78% 32%, var(--ivory) 0 1.2px, transparent 1.9px),
    radial-gradient(circle at 28% 40%, var(--ivory) 0 1px, transparent 1.7px),
    radial-gradient(circle at 33% 56%, var(--ivory) 0 1.1px, transparent 1.8px);
}
.glass-touch { z-index: 2; pointer-events: auto; cursor: grab; touch-action: none; }
.glass-touch:active { cursor: grabbing; }
.hotspot {
  position: absolute;
  z-index: 5;
  width: max(11%, 44px);
  height: max(9%, 44px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  transform: translate(-50%, -50%);
  cursor: pointer;
  touch-action: manipulation;
}
.hotspot.window { top: 52.2%; left: 70.7%; }
.hotspot:focus-visible { box-shadow: 0 0 0 3px var(--ivory); outline-offset: 1px; }
.plaque {
  position: absolute;
  z-index: 5;
  display: grid;
  place-items: center;
  top: 87.8%;
  left: 49%;
  width: 29%;
  min-height: 44px;
  transform: translate(-50%, -50%);
  font-size: clamp(14px, 4.35cqw, 24px);
  font-style: italic;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}

.controls { grid-area: controls; z-index: 2; display: grid; justify-items: center; gap: 3px; }
.hint { margin: 0; color: var(--ink-soft); font-size: 15px; line-height: 1.15; font-style: italic; transition: opacity .7s ease, visibility .7s; }
.hint.dismissed { opacity: 0; visibility: hidden; }
.tools { display: flex; align-items: center; gap: 11px; }
.tool-rule { height: 17px; width: 1px; background: var(--rule); }
.tool { display: inline-flex; align-items: center; min-height: 44px; gap: 7px; padding: 3px 6px; border: 0; border-radius: 3px; background: none; color: var(--ink-soft); cursor: pointer; touch-action: manipulation; font-size: 15px; }
.dial { display: grid; width: 31px; height: 31px; place-items: center; border: 1px solid var(--rule); border-radius: 46% 52% 47% 51%; transition: background-color .25s ease; }
.dial svg { grid-area: 1 / 1; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.15; stroke-linecap: round; stroke-linejoin: round; }
.dial .sun, [data-light='night'] .dial .moon { opacity: 0; }
[data-light='night'] .dial .sun { opacity: 1; }
.dial .sun, .dial .moon { transition: opacity .35s ease; }
.tool[aria-pressed='true'] .dial { background: var(--ivory); }
@media (hover: hover) {
  .tool:hover .dial { background: var(--ivory); }
}

@media (max-width: 650px) {
  .world { --globe-width: min(440px, calc(100vw - 47px), calc((100svh - 121px) * .82)); gap: 16px; }
}
@media (orientation: landscape) and (max-height: 535px) {
  .world {
    --globe-width: min(calc((100svh - 34px) * .82), 56vw);
    grid-template-areas: 'scene controls';
    grid-template-columns: auto auto;
    justify-content: center;
    align-items: center;
    column-gap: clamp(40px, 8vw, 90px);
    padding: 15px 26px;
  }
  .scene { align-self: center; width: max(146px, var(--globe-width)); }
}
@media (prefers-reduced-motion: reduce) {
  :root { --dusk: .35s; }
  .still-snow { opacity: .55; }
  .drag-companion.is-gripped .animal-art { animation: none; }
  .stars { transition-delay: 0s !important; }
  .hint { transition-duration: .25s; }
}
