:root {
  color-scheme: dark;
  --ink: #f7f2ea;
  --muted: #aab3bd;
  --quiet: #77818c;
  --night: #0b1017;
  --panel: rgba(20, 27, 36, 0.82);
  --line: rgba(255, 255, 255, 0.1);
  --amber: #e8b56a;
  --amber-soft: #ffd9a1;
  --rose: #ef8e86;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--night); }

body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 18% 12%, rgba(70, 88, 111, 0.18), transparent 31rem),
    radial-gradient(circle at 82% 82%, rgba(170, 114, 64, 0.12), transparent 28rem),
    linear-gradient(145deg, #111924 0%, #090d13 56%, #101117 100%);
}

button { font: inherit; }
button:focus-visible { outline: 2px solid var(--amber-soft); outline-offset: 3px; }

.room {
  width: min(1440px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: clamp(1rem, 2.2vw, 2.25rem);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(1rem, 2vw, 1.75rem);
}

.topbar,
.footer-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--amber-soft);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2,
p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(1.55rem, 3.2vw, 2.8rem);
  font-weight: 500;
  letter-spacing: 0.04em;
}

.memory-button,
.footer-note button,
.sound-toggle,
.close-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
}

.memory-button {
  min-height: 46px;
  padding: 0.72rem 1rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.memory-button:hover,
.footer-note button:hover,
.sound-toggle:hover { border-color: rgba(232, 181, 106, 0.48); background: rgba(232, 181, 106, 0.08); }

.companion {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 380px);
  gap: clamp(0.85rem, 1.8vw, 1.5rem);
}

.stage,
.interaction-panel {
  border: 1px solid var(--line);
  border-radius: clamp(1.2rem, 2.2vw, 2rem);
  background: linear-gradient(155deg, rgba(24, 33, 44, 0.88), rgba(11, 16, 23, 0.82));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.35), inset 0 1px rgba(255, 255, 255, 0.035);
}

.stage {
  position: relative;
  min-height: min(70svh, 760px);
  overflow: hidden;
  isolation: isolate;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -3;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(to bottom, transparent 8%, #000 65%);
}

.halo {
  position: absolute;
  width: 58%;
  aspect-ratio: 1;
  left: 20%;
  top: 12%;
  z-index: -2;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 211, 151, 0.22), rgba(230, 173, 94, 0.06) 48%, transparent 72%);
  filter: blur(8px);
  transition: transform 800ms ease, opacity 800ms ease;
}

model-viewer {
  width: 100%;
  height: 100%;
  min-height: inherit;
  display: block;
  background: transparent;
  --poster-color: transparent;
  --progress-bar-color: var(--amber);
  transform-origin: 50% 62%;
  will-change: transform;
}

.loadbar {
  position: absolute;
  left: 25%;
  right: 25%;
  bottom: 8.5rem;
  height: 2px;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}

.loadbar span {
  display: block;
  width: 35%;
  height: 100%;
  background: var(--amber);
  animation: loading 1.4s ease-in-out infinite;
}

.stage.model-loaded .loadbar { opacity: 0; transition: opacity 260ms ease; }

@keyframes loading { 50% { transform: translateX(185%); } }

.floor {
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: 7.2rem;
  height: 16%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(232, 181, 106, 0.15), rgba(8, 12, 17, 0) 68%);
  transform: perspective(440px) rotateX(68deg);
}

.model-state {
  position: absolute;
  left: 1rem;
  top: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  max-width: calc(100% - 2rem);
  padding: 0.55rem 0.72rem;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  color: #d9dfe5;
  background: rgba(7, 11, 16, 0.6);
  backdrop-filter: blur(14px);
  font-size: 0.78rem;
}

.state-dot {
  width: 0.5rem;
  height: 0.5rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 14px rgba(232, 181, 106, 0.8);
}

.stage-copy {
  position: absolute;
  left: 1.25rem;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 3;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 1rem;
  background: linear-gradient(90deg, rgba(8, 12, 17, 0.85), rgba(8, 12, 17, 0.48));
  backdrop-filter: blur(14px);
}

.stage-copy p { margin-bottom: 0.24rem; font-size: clamp(1.02rem, 2vw, 1.32rem); }
.stage-copy span { color: var(--muted); font-size: 0.86rem; }

.interaction-panel {
  align-self: stretch;
  padding: clamp(1rem, 2vw, 1.45rem);
  display: flex;
  flex-direction: column;
}

.panel-heading { display: flex; align-items: center; gap: 0.85rem; margin-bottom: 1.2rem; }
.panel-heading p { margin-bottom: 0.24rem; font-size: 1.15rem; font-weight: 700; }
.panel-heading span:not(.tiny-paw) { color: var(--muted); font-size: 0.86rem; }
.tiny-paw { color: var(--amber); font-size: 1.45rem; }

.actions { display: grid; gap: 0.72rem; }

.action {
  width: 100%;
  min-height: 76px;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  display: flex;
  align-items: center;
  gap: 0.88rem;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 255, 255, 0.034);
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.action:hover { transform: translateY(-2px); border-color: rgba(232, 181, 106, 0.35); background: rgba(232, 181, 106, 0.075); }
.action:active { transform: translateY(0) scale(0.985); }
.action strong,
.action small { display: block; }
.action strong { margin-bottom: 0.18rem; font-size: 0.98rem; }
.action small { color: var(--muted); font-size: 0.78rem; line-height: 1.35; }

.action-icon {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 0.85rem;
  display: grid;
  place-items: center;
  color: var(--amber-soft);
  background: rgba(232, 181, 106, 0.1);
  font-size: 1.25rem;
}
.action-icon.heart { color: #ffaaa4; background: rgba(239, 142, 134, 0.1); }
.treat-icon { transform: rotate(45deg); }

.sound-row {
  margin-top: auto;
  padding-top: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.sound-toggle { min-height: 42px; padding: 0.56rem 0.7rem; border-radius: 0.75rem; font-size: 0.78rem; }
.sound-toggle[aria-pressed="false"] { color: var(--quiet); }
.shortcut-hint { color: var(--quiet); font-size: 0.76rem; }

.footer-note { color: var(--quiet); font-size: 0.78rem; }
.footer-note p { margin-bottom: 0; }
.footer-note button { padding: 0.48rem 0.7rem; border-radius: 0.6rem; white-space: nowrap; }

.treat {
  position: absolute;
  left: 50%;
  bottom: 18%;
  z-index: 4;
  color: #f2b45f;
  opacity: 0;
  transform: translate(-50%, 0) rotate(45deg) scale(0.5);
  text-shadow: 0 0 18px rgba(242, 180, 95, 0.8);
  pointer-events: none;
}

.stage.is-treating .treat { animation: toss 1.5s cubic-bezier(.2,.7,.2,1) both; }
@keyframes toss {
  0% { opacity: 0; transform: translate(-220px, 120px) rotate(0) scale(0.6); }
  30% { opacity: 1; }
  68% { opacity: 1; transform: translate(15px, -120px) rotate(320deg) scale(1); }
  100% { opacity: 0; transform: translate(40px, 20px) rotate(520deg) scale(0.3); }
}

.particle {
  position: absolute;
  left: 50%;
  top: 42%;
  color: #ffaaa4;
  font-size: var(--size, 1rem);
  pointer-events: none;
  animation: float-up 1.8s ease-out forwards;
}

@keyframes float-up {
  from { opacity: 0; transform: translate(var(--x, 0), 35px) scale(0.5) rotate(0); }
  20% { opacity: 1; }
  to { opacity: 0; transform: translate(var(--x, 0), -150px) scale(1.15) rotate(var(--r, 15deg)); }
}

.stage.is-petting .halo { transform: scale(1.12); opacity: 1; }
.stage.is-resting .halo { transform: scale(0.82); opacity: 0.52; }

dialog {
  width: min(960px, calc(100% - 2rem));
  max-height: calc(100svh - 2rem);
  padding: clamp(1rem, 3vw, 1.75rem);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 1.35rem;
  color: var(--ink);
  background: #121923;
  box-shadow: 0 35px 110px rgba(0, 0, 0, 0.62);
}

dialog::backdrop { background: rgba(2, 4, 7, 0.72); backdrop-filter: blur(8px); }
.dialog-head { display: flex; justify-content: space-between; gap: 1rem; align-items: start; margin-bottom: 1.15rem; }
.dialog-head h2 { margin-bottom: 0; font-size: clamp(1.25rem, 3vw, 2rem); }
.close-button { width: 42px; height: 42px; flex: 0 0 auto; border-radius: 50%; font-size: 1.6rem; line-height: 1; }

.memory-grid { display: grid; grid-template-columns: minmax(220px, 0.64fr) minmax(0, 1.36fr); gap: 1rem; align-items: stretch; }
.memory-grid figure { margin: 0; min-width: 0; display: flex; flex-direction: column; }
.memory-grid img { width: 100%; min-height: 0; flex: 1; object-fit: cover; border-radius: 1rem; background: #0b1017; }
.memory-original img { max-height: 62svh; object-position: center; }
.memory-grid figcaption { padding-top: 0.55rem; color: var(--muted); font-size: 0.82rem; }
.about-dialog { max-width: 650px; }
.about-dialog > p { color: #d2d8de; line-height: 1.8; }
.about-dialog .credit { color: var(--quiet); font-size: 0.8rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 20;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(15, 21, 29, 0.92);
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.42);
  opacity: 0;
  transform: translate(-50%, 1rem);
  pointer-events: none;
  transition: 220ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .room { padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
  .companion { grid-template-columns: 1fr; }
  .stage { min-height: 58svh; }
  .interaction-panel { padding: 0.9rem; }
  .panel-heading { margin-bottom: 0.8rem; }
  .actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action { min-height: 78px; }
  .sound-row { padding-top: 0.9rem; }
}

@media (max-width: 560px) {
  .room { padding: 0.85rem; gap: 0.85rem; }
  .topbar { align-items: flex-end; }
  .eyebrow { font-size: 0.72rem; letter-spacing: 0.13em; }
  h1 { max-width: 12ch; font-size: 1.65rem; }
  .memory-button { min-width: 46px; padding: 0.68rem; font-size: 0; }
  .memory-button span { font-size: 1.1rem; }
  .stage { min-height: 52svh; border-radius: 1.25rem; }
  .model-state { font-size: 0.72rem; }
  .stage-copy { left: 0.85rem; right: 0.85rem; bottom: 0.85rem; padding: 0.85rem; }
  .actions { gap: 0.55rem; }
  .action { min-height: 86px; padding: 0.68rem; align-items: flex-start; gap: 0.58rem; }
  .action-icon { width: 36px; height: 36px; border-radius: 0.7rem; }
  .action small { font-size: 0.72rem; }
  .shortcut-hint { display: none; }
  .footer-note { align-items: flex-start; }
  .memory-grid { grid-template-columns: 1fr; }
  .memory-grid img { max-height: none; }
}

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