:root {
  --paper: #f4ecd9;
  --paper-bright: #fffaf0;
  --paper-deep: #e7d7ba;
  --ink: #3d372b;
  --ink-soft: #6f644f;
  --sage: #5d7850;
  --sage-deep: #3f5c3e;
  --sage-strong: #506b45;
  --clay: #9a5645;
  --sky-top: #dce8e1;
  --sky-mid: #edf0e4;
  --sky-bottom: #f5eddd;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --ui-shadow:
    0 16px 38px rgba(59, 48, 30, 0.16),
    0 3px 10px rgba(59, 48, 30, 0.09);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
}

body {
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

button {
  font: inherit;
}

.meadow-app {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 78% 8%, rgba(255, 247, 203, 0.95) 0%, rgba(255, 243, 190, 0.65) 7%, transparent 20%),
    radial-gradient(ellipse 105% 28% at 50% 104%, rgba(249, 239, 214, 0.78), transparent 72%),
    linear-gradient(180deg, #7ec1e3 0%, #aedae4 36%, #dfeada 64%, #f4edda 100%);
}

.scene-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
  filter: saturate(1.06) contrast(1.02) brightness(1.0);
}

.scene-canvas:active {
  cursor: grabbing;
}

.scene-canvas.is-hovering-sheep {
  cursor: pointer;
}

.scene-canvas.is-dragging {
  cursor: grabbing;
}

.scene-canvas:focus-visible {
  outline: 3px solid rgba(255, 249, 235, 0.9);
  outline-offset: -10px;
}

.scene-glow {
  position: absolute;
  z-index: 2;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.scene-glow::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 7%;
  width: min(88vw, 1120px);
  height: 16%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(81, 102, 72, 0.17), rgba(81, 102, 72, 0.04) 45%, transparent 72%);
  filter: blur(18px);
  transform: translateX(-50%);
}

.texture-overlay {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  background-image: url("./textures/felt-fiber.png");
  background-size: cover;
  background-position: center;
  opacity: 0.38;
  mix-blend-mode: multiply;
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.45) 26%, #000 62%, #000 100%);
  mask-image: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.45) 26%, #000 62%, #000 100%);
}

.texture-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 42%, transparent 48%, rgba(79, 62, 38, 0.12) 100%);
}

.brand {
  position: absolute;
  z-index: 12;
  top: max(18px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 40px);
  padding: 11px 16px 10px 13px;
  border-radius: 4px 14px 5px 11px;
  background: rgba(255, 249, 235, 0.93);
  box-shadow:
    0 7px 22px rgba(64, 53, 32, 0.12),
    0 1px 3px rgba(64, 53, 32, 0.08);
  transform: rotate(-0.55deg);
  outline: 1px dashed rgba(119, 96, 58, 0.16);
  outline-offset: -6px;
  pointer-events: auto;
}

.brand-mark {
  flex: 0 0 auto;
  width: 31px;
  height: 26px;
  color: #e4d7bd;
}

.brand-mark svg {
  display: block;
  width: 100%;
  height: 100%;
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(21px, 2.15vw, 29px);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: 0.055em;
  color: #383528;
}

.brand p {
  margin: 4px 0 0;
  font-size: 10.5px;
  line-height: 1.25;
  letter-spacing: 0.09em;
  color: #7c705b;
  white-space: nowrap;
}

.prompt {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: max(26px, calc(env(safe-area-inset-bottom) + 18px));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px 9px 11px;
  border-radius: 999px;
  background: rgba(255, 249, 235, 0.94);
  outline: 1px dashed rgba(119, 96, 58, 0.14);
  outline-offset: -5px;
  box-shadow:
    0 10px 30px rgba(57, 46, 27, 0.14),
    0 2px 7px rgba(57, 46, 27, 0.08);
  color: #5b533f;
  font-size: 12.5px;
  letter-spacing: 0.045em;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
  transition:
    opacity 280ms ease,
    translate 280ms ease;
}

.prompt svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  color: #96755c;
}

.prompt__hint {
  margin-left: 2px;
  padding-left: 10px;
  border-left: 1px solid rgba(112, 96, 67, 0.2);
  color: #8c7f68;
  font-size: 11px;
  letter-spacing: 0.03em;
}

.prompt.is-dismissed {
  opacity: 0;
  translate: 0 7px;
}

.selection-layer {
  position: absolute;
  z-index: 30;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.selection-halo {
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  width: 86px;
  height: 32px;
  border: 2px solid rgba(255, 245, 208, 1);
  border-radius: 50%;
  background: rgba(255, 244, 204, 0.1);
  box-shadow:
    0 0 0 4px rgba(255, 243, 208, 0.12),
    0 0 22px rgba(255, 228, 156, 0.36),
    inset 0 0 8px rgba(255, 251, 226, 0.34);
  opacity: 0.92;
  pointer-events: none;
  transform: translate3d(-999px, -999px, 0) translate(-50%, -50%);
  will-change: transform, width, height;
}

.selection-halo::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(255, 246, 218, 0.4);
  border-radius: inherit;
}

.selection-halo.is-visible {
  display: block;
  animation: halo-breathe 2600ms ease-in-out infinite;
}

@keyframes halo-breathe {
  0%,
  100% {
    opacity: 0.82;
    box-shadow:
      0 0 0 4px rgba(255, 243, 208, 0.1),
      0 0 18px rgba(255, 228, 156, 0.28),
      inset 0 0 7px rgba(255, 251, 226, 0.28);
  }
  50% {
    opacity: 1;
    box-shadow:
      0 0 0 6px rgba(255, 243, 208, 0.15),
      0 0 26px rgba(255, 228, 156, 0.42),
      inset 0 0 9px rgba(255, 251, 226, 0.4);
  }
}

.name-tag {
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  align-items: center;
  gap: 6px;
  width: max-content;
  max-width: 150px;
  padding: 5px 11px 5px 8px;
  border-radius: 999px;
  background: rgba(255, 249, 236, 0.97);
  box-shadow:
    0 6px 18px rgba(53, 43, 25, 0.13),
    0 1px 4px rgba(53, 43, 25, 0.08);
  color: #4a4231;
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: auto;
  transform-origin: 50% 100%;
}

.name-tag.is-visible {
  display: inline-flex;
  animation: tag-in 220ms cubic-bezier(0.2, 0.8, 0.25, 1) both;
}

.name-tag__puff {
  position: relative;
  display: inline-block;
  width: 12px;
  height: 9px;
  border-radius: 60% 45% 55% 50%;
  background: #e7dac1;
  box-shadow: 4px -2px 0 -1px #e7dac1, 2px 2px 0 -1px #d5c4a6;
}

.toolbar-shell {
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  pointer-events: auto;
  transform-origin: 50% 100%;
}

.toolbar-shell.is-visible {
  display: block;
  animation: toolbar-in 260ms cubic-bezier(0.18, 0.85, 0.24, 1) both;
}

.toolbar {
  --button-size: 56px;
  display: flex;
  align-items: stretch;
  gap: 1px;
  padding: 6px;
  border-radius: 17px;
  background: rgba(255, 249, 236, 0.985);
  box-shadow:
    0 16px 38px rgba(59, 48, 30, 0.17),
    0 3px 10px rgba(59, 48, 30, 0.09);
  touch-action: manipulation;
}

.toolbar button {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: var(--button-size);
  height: 51px;
  margin: 0;
  padding: 4px 2px 3px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #574c39;
  cursor: pointer;
  transition:
    background-color 150ms ease,
    color 150ms ease,
    transform 150ms ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.toolbar button svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 150ms ease;
}

.toolbar button span {
  font-size: 10.5px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  color: #675b45;
  transition: color 150ms ease;
}

.toolbar button[data-action="copy"] {
  margin-left: 3px;
}

.toolbar button[data-action="delete"] {
  color: var(--clay);
}

.toolbar button[data-action="delete"] span {
  color: var(--clay);
}

.toolbar button:hover {
  background: #f1e4cb;
}

.toolbar button:hover svg {
  transform: translateY(-1px);
}

.toolbar button:active {
  transform: translateY(1px) scale(0.965);
}

.toolbar button.is-active {
  background: var(--sage-strong);
  color: #fff9eb;
}

.toolbar button.is-active span {
  color: #fff9eb;
}

.toolbar button.is-active svg {
  stroke: #fff9eb;
}

.toolbar button.is-disabled {
  opacity: 0.38;
  pointer-events: none;
}

.toolbar button:focus-visible {
  outline: 2px solid var(--sage-deep);
  outline-offset: 1px;
}

.toolbar button.is-active:focus-visible {
  outline-color: #fff9eb;
  outline-offset: -3px;
}

.toast {
  position: absolute;
  z-index: 45;
  left: 50%;
  bottom: max(26px, calc(env(safe-area-inset-bottom) + 18px));
  max-width: min(86vw, 360px);
  padding: 10px 17px;
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.975);
  box-shadow:
    0 12px 30px rgba(57, 46, 27, 0.16),
    0 2px 7px rgba(57, 46, 27, 0.08);
  color: #514735;
  font-size: 12.5px;
  line-height: 1.35;
  letter-spacing: 0.03em;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition:
    opacity 200ms ease,
    transform 220ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.noscript-note {
  position: fixed;
  z-index: 90;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--paper-bright);
  box-shadow: var(--ui-shadow);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
}

.scene-loading {
  position: absolute;
  z-index: 50;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #f0eddf;
  color: #6b624f;
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.1em;
  opacity: 1;
  transition: opacity 500ms ease;
  pointer-events: none;
}

.scene-loading.is-hidden {
  opacity: 0;
}

.scene-loading__puff {
  position: relative;
  width: 18px;
  height: 13px;
  border-radius: 60% 45% 55% 50%;
  background: #e6d8bf;
  box-shadow: 5px -3px 0 -1px #e6d8bf, 3px 3px 0 -1px #d1bea0;
  animation: puff-breathe 1600ms ease-in-out infinite;
}

.webgl-fallback {
  position: absolute;
  z-index: 55;
  top: 50%;
  left: 50%;
  width: min(88vw, 390px);
  padding: 22px 24px;
  border-radius: 18px;
  background: rgba(255, 249, 236, 0.98);
  box-shadow: var(--ui-shadow);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.7;
  text-align: center;
  transform: translate(-50%, -50%);
}

.webgl-fallback[hidden] {
  display: none;
}

@keyframes puff-breathe {
  0%,
  100% {
    transform: scale(0.92);
    opacity: 0.72;
  }
  50% {
    transform: scale(1.05);
    opacity: 1;
  }
}

@keyframes tag-in {
  from {
    opacity: 0;
    scale: 0.9;
    translate: 0 4px;
  }
  to {
    opacity: 1;
    scale: 1;
    translate: 0 0;
  }
}

@keyframes toolbar-in {
  from {
    opacity: 0;
    scale: 0.94;
    translate: 0 7px;
  }
  to {
    opacity: 1;
    scale: 1;
    translate: 0 0;
  }
}

@media (max-width: 680px) {
  .meadow-app {
    background:
      radial-gradient(circle at 80% 6%, rgba(255, 247, 203, 0.95) 0%, rgba(255, 243, 190, 0.65) 6%, transparent 18%),
      radial-gradient(ellipse 110% 24% at 50% 104%, rgba(249, 239, 214, 0.72), transparent 72%),
      linear-gradient(180deg, #7ec1e3 0%, #aedae4 36%, #dfeada 64%, #f4edda 100%);
  }

  .brand {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    gap: 8px;
    padding: 9px 13px 9px 10px;
    border-radius: 4px 12px 4px 9px;
  }

  .brand-mark {
    width: 26px;
    height: 22px;
  }

  .brand h1 {
    font-size: 21px;
  }

  .brand p {
    font-size: 9.5px;
    letter-spacing: 0.065em;
  }

  .prompt {
    bottom: max(20px, calc(env(safe-area-inset-bottom) + 14px));
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 7px;
    padding: 8px 14px;
    font-size: 11.5px;
    text-align: center;
    white-space: normal;
  }

  .prompt svg {
    width: 18px;
    height: 18px;
  }

  .prompt__hint {
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 10px;
  }

  .toolbar {
    --button-size: clamp(43px, 10.8vw, 46px);
    padding: 5px;
    gap: 1px;
    border-radius: 15px;
  }

  .toolbar button {
    height: 46px;
    gap: 2px;
    padding: 3px 1px 2px;
    border-radius: 10px;
  }

  .toolbar button svg {
    width: 18px;
    height: 18px;
  }

  .toolbar button span {
    font-size: clamp(9.5px, 2.5vw, 10px);
    letter-spacing: 0;
  }

  .toolbar button[data-action="copy"] {
    margin-left: 2px;
  }

  .name-tag {
    padding: 4px 9px 4px 7px;
    font-size: 12px;
  }

  .toast {
    bottom: max(20px, calc(env(safe-area-inset-bottom) + 14px));
    padding: 9px 15px;
    font-size: 11.5px;
  }

  .scene-glow::before {
    bottom: 12%;
    width: 100vw;
    height: 12%;
  }
}

@media (max-width: 360px) {
  .brand p {
    display: none;
  }

  .toolbar {
    --button-size: 38px;
  }

  .prompt {
    font-size: 11px;
    width: max-content;
    max-width: calc(100vw - 32px);
    border-radius: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
