:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  background: #181818;
  color: #f0f0e9;
  --muted: #b8bcad;
  --accent: #d5e2a6;
  --ease: cubic-bezier(.32, .72, 0, 1);
}

* { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
p, h1, h2, dl, dd { margin: 0; }

main {
  width: min(100%, 1216px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto;
  gap: 16px;
}

.masthead, .identity, .controls, .footer-details { display: flex; align-items: center; }
.masthead, .footer-details { justify-content: space-between; }
.identity, .controls { gap: 12px; }
h1 { font-size: 1.25rem; line-height: 1.75rem; letter-spacing: -.026em; }
.identity p { color: var(--muted); font-size: .875rem; line-height: 1.25rem; }

.icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  background: #242621;
  border: 1px solid #3c4036;
  border-radius: 100%;
  transition: background .28s var(--ease), color .28s var(--ease), transform .28s var(--ease);
}

.icon svg, .pet-cue svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.icon:hover { background: #363a2f; }
.icon:active, .help:active { transform: scale(.96); }
.icon[aria-pressed="true"] { color: var(--accent); border-color: #78845b; background: #333c28; }
#sound[aria-pressed="false"] .waves, #sound[aria-pressed="true"] .mute { display: none; }

.habitat {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-width: 0;
  border: 1px solid #444639;
  border-radius: 16px;
  background: #131209;
}

.photograph, canvas, .field, .night-light {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.photograph { object-fit: cover; }
canvas { display: none; }
canvas.ready { display: block; }
.night-light { background: #365b8a; mix-blend-mode: multiply; opacity: 0; pointer-events: none; transition: opacity .8s var(--ease); }
.habitat.night .night-light { opacity: .67; }
.field { background: none; border: 0; padding: 0; touch-action: none; cursor: grab; }
.field:active { cursor: grabbing; }
.field:focus-visible { outline-offset: -5px; border-radius: 15px; }

.scene-hud, .scene-instructions, .pet-cue, .pet-ripple { position: absolute; pointer-events: none; }
.scene-hud { top: 16px; left: 16px; }
.habitat-label, .scene-instructions p {
  width: max-content;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid #eef0cc43;
  background: #121610dc;
  font-size: .875rem;
  line-height: 1.25rem;
}

.habitat-label { display: flex; align-items: center; gap: 8px; }
.habitat-label i, .species-mark { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; }
.night .habitat-label i { background: #b6cfef; }
.scene-instructions { left: 8px; right: 8px; bottom: 16px; display: grid; justify-items: center; text-align: center; }

.pet-cue {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid #f6f1d69c;
  border-radius: 50%;
  background: #131509cf;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity .4s var(--ease);
}

.pet-cue.visible { opacity: 1; }
.pet-ripple { width: 28px; height: 28px; border: 1px solid #eef0bc; border-radius: 50%; opacity: 0; }
.pet-ripple.active { animation: ripple .75s var(--ease); }
@keyframes ripple {
  from { opacity: .8; transform: translate(-50%, -50%) scale(.7); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(2.5); }
}

footer { color: var(--muted); font-size: .875rem; line-height: 1.25rem; }
footer p, .help { display: flex; align-items: center; gap: 8px; }
footer em { font-style: normal; }
.species-mark { display: inline-block; background: #a1aa83; }
.help { min-height: 44px; padding: 0 4px 0 12px; background: transparent; border: none; border-radius: 8px; transition: color .28s var(--ease), transform .28s var(--ease); }
.help:hover { color: var(--accent); }
.help span { width: 20px; height: 20px; text-align: center; border: 1px solid #636958; border-radius: 50%; line-height: 18px; }

dialog { width: min(440px, calc(100% - 32px)); padding: 24px; border: 1px solid #444639; border-radius: 16px; background: #242621; color: inherit; }
dialog::backdrop { background: #0e100cd9; }
.guide-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.guide-header h2 { font-size: 1.5rem; }
.guide-header button { font-size: 1.5rem; }
dl { display: grid; gap: 16px; }
dt { font-weight: 650; margin-bottom: 4px; }
dd { color: var(--muted); line-height: 1.5; }

@media (max-width: 600px) {
  main { padding: 12px; gap: 12px; }
  .identity, .controls { gap: 8px; }
  .scene-hud { top: 12px; left: 12px; }
  .scene-instructions { bottom: 12px; }
}

@media (pointer: coarse) {
  .field { cursor: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .15s !important; transition-duration: .15s !important; }
}

:root {
  color-scheme: light;
  background: #e9ede1;
  color: #272d25;
  --muted: #515b4e;
  --accent: #3b5933;
}

[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

main {
  width: min(100%, 1120px);
  min-height: 0;
  display: block;
  padding: 12px 16px;
}

.habitat {
  width: 100%;
  height: min(calc(100svh - 128px), calc((100vw - 32px) / 1.65));
  min-height: 260px;
  max-height: 710px;
  border-radius: 12px;
}

.icon { background: #f2f4eb; border-color: #a8b39e; }
.icon:hover { background: #dce6d1; }
.icon[aria-pressed="true"] { background: #e2ebd8; color: #35552d; border-color: #68835a; }
.light { position: absolute; inset: 12px 12px auto auto; }

.pet-hand {
  position: absolute;
  z-index: 1;
  width: clamp(94px, 17%, 154px);
  height: auto;
  pointer-events: none;
  opacity: 0;
  transform-origin: 50% 3%;
  transition: opacity .26s var(--ease);
  filter: drop-shadow(2px 8px 9px #17170d75);
  mask-image: linear-gradient(#000 92%, transparent 100%);
}
.pet-hand.visible { opacity: .98; }
.night .pet-hand { filter: brightness(.6) saturate(.64) drop-shadow(2px 8px 9px #10152b91); }
.habitat.petting .field { cursor: none; }
.light, .retry { z-index: 2; }
.retry { position: absolute; top: 12px; left: 12px; border: 0; border-radius: 999px; padding: 8px 12px; }
.scene-instructions, .pet-cue { z-index: 2; color: #f0f0e9; }
.pet-ripple { z-index: 2; }
.scene-instructions p:empty { display: none; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0 0;
}
.spider-picker { display: flex; align-items: center; gap: 8px; }
.swatch {
  flex: none;
  width: 44px;
  height: 44px;
  border: 2px solid transparent;
  border-radius: 50%;
  padding: 2px;
  background: transparent;
  transition: border-color .28s var(--ease);
}
.swatch:hover { border-color: #a1ae96; }
.swatch[aria-pressed="true"] { border-color: #4b6743; }
.swatch img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.proportions { display: flex; flex-wrap: wrap; gap: 12px 24px; padding: 12px 0 0; }
.proportions label { display: flex; align-items: center; gap: 8px; font-size: .875rem; }
.proportions input { width: 110px; accent-color: var(--accent); }
footer { margin-top: 4px; }
.footer-credit {
  text-align: center;
  padding-bottom: 4px;
}
.footer-credit a {
  color: inherit;
  text-underline-offset: 3px;
}
.footer-credit a:hover { color: var(--accent); }
.footer-credit a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.help span { border-color: #828b78; }
dialog { background: #f2f4eb; border-color: #a8b39e; }
dialog::backdrop { background: #0e100caa; }

main:fullscreen, main.expanded {
  width: 100%;
  height: 100%;
  max-width: none;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  background: #e9ede1;
}
main.expanded { position: fixed; inset: 0; z-index: 3; }
main:fullscreen .habitat, main.expanded .habitat { flex: 1; max-height: none; height: auto; min-height: 0; }

@media (max-width: 600px) {
  main { padding: 8px 12px; }
  .habitat { height: min(calc(100svh - 120px), 120vw); }
  .spider-picker, .controls { gap: 4px; }
}

.habitat.dusk .night-light { background: #d5a36d; opacity: .43; }
