:root {
  color-scheme: light;
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  color: #24382a;
  background: #c3d6a2;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

#game {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#scene {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud, .controls {
  position: absolute;
  left: max(20px, env(safe-area-inset-left));
  right: max(20px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}

.hud { top: max(20px, env(safe-area-inset-top)); z-index: 1; }
.controls { bottom: max(20px, env(safe-area-inset-bottom)); align-items: end; }

.title-card, .location, .animal-label, .keyboard, #status {
  background: #fff9e9;
  box-shadow: 0 3px 0 #43583a27, 0 8px 28px #374c3020;
}

.title-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 19px 12px 12px;
  border-radius: 23px;
}
.zoo-identity { display: grid; justify-items: start; gap: 8px; }
.share-entry { font-size: 13px; min-height: 44px; }

.title-icon {
  display: grid;
  place-items: center;
  width: 47px;
  height: 47px;
  flex: none;
  border-radius: 15px;
  background: #dce8b4;
  font-size: 24px;
}

.eyebrow {
  color: #596544;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .13em;
  margin: 0 0 2px;
}

h1 {
  font-size: clamp(20px, 4vw, 29px);
  line-height: 1;
  letter-spacing: -.045em;
  margin: 0;
  white-space: nowrap;
}

.location, .animal-label, .keyboard, #status {
  border-radius: 999px;
  font-weight: 750;
  font-size: 13px;
}

.location {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  white-space: nowrap;
  cursor: pointer;
}

.location::-webkit-details-marker { display: none; }

.animal-menu { position: relative; pointer-events: auto; }

#animal-list {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: max-content;
  min-width: 152px;
  max-width: min(320px, calc(100vw - 26px));
  max-height: min(65vh, 350px);
  overflow: auto;
  background: #fff9e9;
  border-radius: 18px;
  padding: 7px;
  box-shadow: 0 3px 0 #43583a27, 0 8px 28px #374c3038;
}

#animal-list button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 7px 11px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 15px;
  font-weight: 750;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}

#animal-list button:hover, #animal-list button[aria-current="true"] { background: #e7ebcb; }
#animal-list button:focus-visible, .location:focus-visible { outline: 2px solid #2d4432; outline-offset: -2px; }

.location svg {
  width: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.animal-label, #heart {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  white-space: nowrap;
}

.animal-label {
  padding: 6px 11px;
  translate: -50% -75%;
  max-width: min(300px, calc(100vw - 32px));
  overflow: hidden;
  text-overflow: ellipsis;
}
.animal-label[data-active="true"] { box-shadow: 0 0 0 2px #90a968, 0 3px 0 #43583a27; }

#heart {
  color: #f16661;
  font-size: 44px;
  text-shadow: 0 3px 0 #fff9e9;
  margin-left: -18px;
}

.movement, .interaction {
  display: grid;
  gap: 10px;
}

.interaction { justify-items: end; }
.animal-tools, .animal-actions { display: flex; flex-wrap: wrap; gap: 9px; justify-content: flex-end; }
.animal-tools { max-width: 330px; }
.animal-actions { align-items: stretch; }

#stick {
  display: grid;
  place-items: center;
  pointer-events: auto;
  touch-action: none;
  width: 90px;
  height: 90px;
  border: 2px solid #f5f3d9d9;
  border-radius: 50%;
  background: #33472d50;
  box-shadow: inset 0 2px 10px #253b3525;
  cursor: grab;
}

#stick:active { cursor: grabbing; }

#knob {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff9e9;
  border: 4px solid #e8eac8;
  box-shadow: 0 3px 0 #34482e60;
  pointer-events: none;
}

.keyboard, #status {
  margin: 0;
  padding: 7px 12px;
  line-height: 1.25;
}

#status { text-align: right; }

#action, #greet {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffda74;
  color: #332d1b;
  border: 0;
  border-radius: 18px;
  padding: 12px 17px 12px 12px;
  min-height: 56px;
  box-shadow: 0 4px 0 #a9813d, 0 9px 24px #34482e35;
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
}
#greet { background: #e2edc5; box-shadow: 0 4px 0 #839a61, 0 9px 24px #34482e25; font-size: 15px; }
#greet:disabled { opacity: .8; cursor: default; }
#greet:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 #839a61; }
#greet:focus-visible { outline: 3px solid #2d4432; outline-offset: 5px; }

#action-icon {
  display: grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  border-radius: 10px;
  background: #fff3be;
}

#action:disabled { cursor: default; opacity: .8; }
#action:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 #a9813d; }
#action:focus-visible { outline: 3px solid #2d4432; outline-offset: 5px; }

#error {
  position: absolute;
  inset: 40% 16px auto;
  max-width: 420px;
  margin: 0 auto;
  background: #fff9e9;
  border-radius: 16px;
  padding: 20px;
}

@media (pointer: coarse) {
  .keyboard { display: none; }
}

@media (max-width: 520px) {
  .hud, .controls {
    left: max(13px, env(safe-area-inset-left));
    right: max(13px, env(safe-area-inset-right));
  }

  .hud { top: max(13px, env(safe-area-inset-top)); }
  .controls { bottom: max(16px, env(safe-area-inset-bottom)); }
  .title-card { gap: 8px; padding: 9px 12px 9px 9px; border-radius: 17px; }
  .title-icon { width: 35px; height: 35px; font-size: 19px; border-radius: 11px; }
  .location { font-size: 12px; padding: 9px 10px; min-height: 44px; }
  #stick { width: 78px; height: 78px; }
  #knob { width: 36px; height: 36px; }
  #action, #greet { font-size: 14px; padding: 9px 11px; min-height: 48px; }
  .interaction { max-width: calc(100vw - 116px); }
  .animal-tools, .animal-actions { gap: 7px; }
  .animal-actions { flex-direction: column; align-items: stretch; }
  .animal-tools { flex-direction: column; align-items: end; }
  #status { max-width: 205px; }
}

.coloring-entry, .coloring-button, #coloring-close, .dialog-close {
  border: 0;
  color: #24382a;
  background: #ecefd0;
  border-radius: 13px;
  min-height: 42px;
  padding: 9px 13px;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.coloring-entry {
  pointer-events: auto;
  background: #fff9e9;
  box-shadow: 0 3px 0 #43583a27;
}

#coloring-dialog, #name-dialog, #share-dialog {
  width: min(530px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: clamp(16px, 4vw, 25px);
  border: 0;
  border-radius: 24px;
  background: #fff9e9;
  color: #24382a;
  box-shadow: 0 16px 60px #20321b56;
  overscroll-behavior: contain;
}

#coloring-dialog::backdrop, #name-dialog::backdrop, #share-dialog::backdrop { background: #26332294; }

.coloring-heading, .coloring-buttons { display: flex; align-items: center; gap: 9px; }
.coloring-heading { justify-content: space-between; }
.coloring-heading h2 { margin: 2px 0 0; font-size: clamp(23px, 5vw, 30px); letter-spacing: -.035em; }
.coloring-heading .eyebrow { font-size: 12px; }
#coloring-close, .dialog-close { min-width: 42px; font-size: 25px; line-height: 1; }
#name-dialog { max-width: 430px; }
.name-label { display: block; margin: 20px 0 8px; font-size: 14px; font-weight: 750; }
#animal-name { width: 100%; padding: 12px; border: 2px solid #cbd7af; border-radius: 13px; background: #fff; color: inherit; font: inherit; font-size: 18px; user-select: text; -webkit-user-select: text; }
#animal-name:focus { outline: 2px solid #718c51; outline-offset: 2px; }
#name-notice { font-size: 14px; line-height: 1.4; min-height: 2.8em; margin: 10px 0; }
#coloring-notice { margin: 11px 0 14px; font-size: 14px; line-height: 1.4; }
.coloring-buttons { flex-wrap: wrap; }
.coloring-actions { margin-top: 12px; justify-content: flex-end; }
.coloring-button.primary { background: #ffda74; }
.coloring-button:disabled { opacity: .55; cursor: wait; }
label.coloring-button { position: relative; display: inline-flex; align-items: center; }
label.coloring-button:focus-within { outline: 2px solid #2d4432; outline-offset: 2px; }
label.coloring-button input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }

#coloring-frame, #coloring-preview {
  display: block;
  margin: 16px auto 0;
  background: #fff;
  box-shadow: 0 0 0 1px #dedac7;
}

#coloring-frame {
  width: min(100%, calc(min(43dvh, 400px) * var(--photo-ratio)));
  position: relative;
}

#coloring-photo { width: 100%; height: auto; display: block; }
#coloring-preview { width: auto; max-width: 100%; max-height: min(43dvh, 400px); }

.coloring-marker {
  position: absolute;
  width: 30px;
  height: 30px;
  padding: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid #fff;
  color: #242e25;
  background: #ffda74dd;
  box-shadow: 0 0 0 1px #273c27;
  font: 800 12px system-ui, sans-serif;
  text-align: center;
  touch-action: none;
  cursor: grab;
}

.coloring-marker:active { cursor: grabbing; }

#share-dialog { max-width: 470px; }
.share-explanation, #share-notice { font-size: 14px; line-height: 1.45; }
.share-formats { display: flex; gap: 9px; margin-top: 16px; }
.share-formats button { flex: 1; }
.share-formats button[aria-pressed="true"] { background: #dce8b4; box-shadow: inset 0 0 0 2px #7f995b; }
#share-link { width: 100%; border: 1px solid #cbd7af; border-radius: 12px; padding: 11px; color: inherit; background: #fff; font: inherit; font-size: 14px; user-select: text; -webkit-user-select: text; }
#share-notice { min-height: 1.45em; margin: 12px 0 0; }
#share-qr { display: block; width: min(260px, 100%); height: auto; margin: 16px auto 0; background: #fff; border-radius: 8px; image-rendering: pixelated; }
