:root {
  --paper: #edf0f1;
  --disc: #e2e7e8;
  --ink: #22242a;
  --ink-soft: #6b7078;
  --marigold: #e5a32e;
}

[data-theme="dark"] {
  --paper: #191b20;
  --disc: #26292f;
  --ink: #e9eaec;
  --ink-soft: #9aa0a8;
}

body,
.plush::before,
.title, .hint, .foot,
.squiggle, .hint .arrow {
  transition: background-color 0.35s ease, color 0.35s ease,
              box-shadow 0.35s ease, stroke 0.35s ease, opacity 0.35s ease;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: ui-rounded, "Nunito", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: grid;
  place-items: center;
  overflow-x: hidden;
  overscroll-behavior: none; /* no pull-to-refresh / rubber-band under the toy */
}

.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2.4vh, 26px);
  padding: clamp(18px, 4vh, 48px) 20px;
  width: 100%;
  min-height: 100svh;
}

/* --- headline --------------------------------------------------------- */

.title {
  position: relative;
  margin: 0;
  /* share the free vertical space with the footer margin below, so the
     title+portrait group stays centred while the footer sits at the bottom */
  margin-top: auto;
  font-weight: 900;
  font-size: clamp(44px, 9.5vw, 108px);
  letter-spacing: -0.03em;
  line-height: 1;
  text-align: center;
}

.squiggle {
  position: absolute;
  left: 50%;
  bottom: -0.16em;
  width: 62%;
  height: 0.14em;
  transform: translateX(-50%);
  stroke: var(--marigold);
  overflow: visible;
}

/* --- stage ------------------------------------------------------------ */

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.plush {
  position: relative;
  width: min(82vw, 58svh, 560px);
  aspect-ratio: 1;
}

/* the disc the face sits on (and peels away from); sized to the photo
   circle: the canvas shows the image at 1/(1+2·pad) = 62.5% of stage */
.plush::before {
  content: "";
  position: absolute;
  inset: 18.75%;
  border-radius: 50%;
  background: var(--disc);
  box-shadow: 0 18px 50px -18px rgba(34, 36, 42, 0.28);
}

.plush img,
.plush canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.plush img {
  object-fit: cover;
  border-radius: 50%;
  /* crop portrait to head+shoulders inside the disc — same crop the
     shader's circle makes, shrunk to the canvas's 62.5% photo size */
  object-position: 50% 38.4%;
  transform: scale(0.625);
}

.plush.is-live img { display: none; }

.plush canvas { display: block; }

/* the invisible button that takes the pointer (and the keyboard) */
.plush-hit {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 50%;
  cursor: grab;
  touch-action: none; /* the face owns every gesture on it — never scrolls the page */
  -webkit-tap-highlight-color: transparent;
}
.plush-hit:active { cursor: grabbing; }
.plush-hit:focus-visible {
  outline: 3px solid var(--marigold);
  outline-offset: 6px;
}

/* subtle life while handled */
.plush.is-stretched { z-index: 2; }

/* the lamp the cord switch turns on: warm light pooling over the portrait */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background:
    radial-gradient(38svh circle at 50% 26%, rgba(255, 209, 128, 0.17), transparent 70%),
    radial-gradient(95svh circle at 50% 42%, rgba(255, 186, 100, 0.07), transparent 75%);
  opacity: 0;
  transition: opacity 0.6s ease;
}
[data-theme="dark"] body::after { opacity: 1; }

/* and the pull bead itself glows like it holds the nightlight */
[data-theme="dark"] .cord-switch .bead circle,
[data-theme="dark"] .cord-switch .bead rect {
  filter: drop-shadow(0 0 5px rgba(255, 210, 120, 0.9));
}

/* --- the idle fly ------------------------------------------------------- */

.fly {
  position: absolute;
  left: 0;
  top: 0;
  width: 15px;
  height: 14px;
  z-index: 6;
  pointer-events: none;
  will-change: transform;
}
.fly svg { display: block; width: 100%; height: 100%; overflow: visible; }
.fly .bd { fill: #1d2026; }
.fly .hd { fill: #14161b; }
.fly .e { fill: #f2f0ea; }
.fly .p { fill: #15161a; }
.fly .lg { stroke: #14161b; stroke-width: 1; stroke-linecap: round; fill: none; }
.fly .w ellipse {
  fill: rgba(222, 230, 244, 0.75);
  stroke: rgba(60, 66, 80, 0.4);
  stroke-width: 0.5;
}
.fly .w { transform-box: fill-box; }
.fly .wl { transform-origin: 90% 90%; animation: wflap 0.1s linear infinite alternate; }
.fly .wr { transform-origin: 10% 90%; animation: wflap 0.1s linear infinite alternate-reverse; }
@keyframes wflap {
  from { transform: rotate(0deg); }
  to   { transform: rotate(16deg); }
}
@media (prefers-reduced-motion: reduce) { .fly { display: none; } }

/* --- pull-cord theme switch ------------------------------------------- */

.cord-switch {
  position: fixed;
  top: 0;
  right: clamp(16px, 5vw, 72px);
  width: 64px;
  padding: 0;
  border: 0;
  background: none;
  cursor: grab;
  touch-action: none;
  z-index: 5;
  -webkit-tap-highlight-color: transparent;
}
.cord-switch:active { cursor: grabbing; }
.cord-switch:focus-visible {
  outline: 3px solid var(--marigold);
  outline-offset: 2px;
  border-radius: 6px;
}
.cord-switch svg { display: block; width: 100%; height: auto; overflow: visible; }
.cord-switch .housing-plate,
.cord-switch .housing-dome { fill: var(--ink); }
.cord-switch .cord {
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
}
.cord-switch .bead circle { fill: var(--marigold); }
.cord-switch .bead rect { fill: var(--marigold); }
.cord-switch .housing-plate,
.cord-switch .housing-dome,
.cord-switch .cord,
.cord-switch .bead circle,
.cord-switch .bead rect {
  transition: fill 0.35s ease, stroke 0.35s ease;
}
@media (max-width: 560px) { .cord-switch { width: 48px; } }

/* --- hint ------------------------------------------------------------- */

.hint {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: clamp(4px, 1.5vh, 14px) 0 0;
  font-family: "Caveat", cursive;
  font-size: clamp(22px, 3vw, 30px);
  color: var(--ink-soft);
  transform: rotate(-2deg);
}

.hint .arrow {
  width: 0.9em;
  height: 0.7em;
  stroke: var(--ink-soft);
  transform: rotate(160deg) scaleX(-1);
  margin-top: 0.1em;
}

/* --- footer ----------------------------------------------------------- */

.foot {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
}
.foot a {
  color: inherit;
  text-decoration: none;
  opacity: 0.55;
}
.foot a:hover { opacity: 0.95; text-decoration: underline; }

/* --- entrance ---------------------------------------------------------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
@keyframes boing {
  0%   { opacity: 0; transform: scale(0.86); }
  55%  { opacity: 1; transform: scale(1.035); }
  75%  { transform: scale(0.985); }
  100% { opacity: 1; transform: scale(1); }
}

.title  { animation: rise 0.5s ease-out both; }
.plush  { animation: boing 0.7s cubic-bezier(0.3, 1.4, 0.5, 1) 0.15s both; }
.hint   { animation: rise 0.5s ease-out 0.45s both; }
.foot   { animation: rise 0.5s ease-out 0.6s both; }

@media (prefers-reduced-motion: reduce) {
  .title, .plush, .hint, .foot { animation: none; }
}
