/* ===========================================================
   style.css — 大道至简：暖纸色 / 月光深色沉浸式双栏舞台
   左侧无背景无边框 3D 立姿犬群展示栏 + 最大化主画布 + 底部真实毛发纹理选择器
   =========================================================== */

:root {
  color-scheme: light;
  --paper: #fbf5ec;
  --ink: #413024;
  --edge: #d9cfc1;
  --focus: #925b36;
  --hover: #eee5d9;
  --muted: #756456;
  --mark: #413024;
  --cloth: #dfd0ba;
  --control: rgba(251, 245, 236, 0.82);
  --gap: clamp(7px, 0.66vw, 13px);
  --lineup-w: clamp(68px, 6.8vw, 92px);
  font-family: "PingFang SC", "Hiragino Sans GB", "Hiragino Maru Gothic ProN", "Noto Sans SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #101722;
  --ink: #dfebf3;
  --focus: #b4d9fa;
  --edge: #526276;
  --hover: #293546;
  --mark: #425c75;
  --muted: #a0afbf;
  --cloth: #303e50;
  --control: rgba(18, 29, 43, 0.82);
}

* { box-sizing: border-box; }
body { margin: 0; -webkit-tap-highlight-color: transparent; }

main {
  padding: var(--gap) var(--gap) max(var(--gap), env(safe-area-inset-bottom));
  margin: auto;
  max-width: 1980px;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
button[hidden] { display: none; }
button:focus-visible, #stage:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- 双栏最大化舞台网格（左栏 3D 小狗 + 右栏最大化画布与底栏） ---------- */
#viewer {
  position: relative;
  display: grid;
  grid-template-columns: var(--lineup-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  column-gap: var(--gap);
  align-items: stretch;
  /* 补入左栏宽度使右侧 #stage 保持与单栏时完全相同的最大面积，绝不浪费空间 */
  max-width: min(100%, calc((100svh - 90px) * 1.62246 + var(--lineup-w) + var(--gap)));
  margin: auto;
}

/* ---------- 左侧 3D 动态站立犬种栏（极简无背景、无边框、无卡片、纵向滚动） ---------- */
.breed-lineup {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  min-height: 0;
  max-height: calc(100svh - 90px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  padding: 2px 0;
  margin: 0;
  background: transparent;
  border: 0;
  overflow-y: auto;
  overflow-x: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior: contain;
}
.breed-lineup::-webkit-scrollbar {
  display: none;
}

.breed-stand {
  position: relative;
  flex: 0 0 auto;
  width: var(--lineup-w);
  aspect-ratio: 420 / 360;
  padding: 0;
  margin: 0;
  background: transparent;
  border: 0;
  border-radius: 12px;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}
.breed-stand canvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.breed-stand:active {
  transform: scale(0.95);
}

/* 跨栏跑入动画桥接层 */
#transition-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  pointer-events: none;
}

/* ---------- 主画布 ---------- */
.playfield {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
}

#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1517 / 935;
  max-height: calc(100svh - 90px);
  overflow: hidden;
  border-radius: clamp(12px, 1.32vw, 25px);
  background: var(--cloth);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#scene,
#walk3d {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}
#scene[hidden],
#walk3d[hidden] {
  display: none;
}

#stage:not([data-ready="true"]) #scene,
#stage:not([data-ready="true"]) #walk3d { visibility: hidden; }
#stage[data-over="true"] { cursor: default; }
#stage[data-pressed="true"] { cursor: none; }
#stage[data-scene="walk"][data-pressed="true"] { cursor: default; }
#stage[data-scene="walk"][data-petting="true"] { cursor: pointer; }

#retry {
  position: absolute;
  z-index: 2;
  bottom: 14px;
  left: 14px;
  background: var(--paper);
}

/* ---------- 画布右上角月光切换 ---------- */
#theme {
  position: absolute;
  z-index: 2;
  top: max(9px, env(safe-area-inset-top));
  right: max(9px, env(safe-area-inset-right));
  background-color: var(--control);
  box-shadow: inset 0 0 0 1px var(--edge);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#theme svg { width: 21px; height: 21px; stroke-width: 1.65; }
:root[data-theme="dark"] #theme .moon,
:root:not([data-theme="dark"]) #theme .sun { display: none; }
@media (hover: hover) {
  #theme:hover { background-color: var(--paper); }
}

/* ---------- 底栏：圆形真实毛发纹理毛色选择器 + 极简工具栏 ---------- */
.toolbar, .choices, .tools {
  display: flex;
  align-items: center;
}
.toolbar {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  justify-content: space-between;
  gap: 6px 14px;
  padding: 8px 0 0;
}

.choices {
  min-width: 0;
  max-width: 100%;
  justify-content: flex-start;
  gap: clamp(5px, 0.8vw, 12px);
  overflow-x: auto;
  scrollbar-width: none;
}
.choices::-webkit-scrollbar { display: none; }

.choices button {
  --size: clamp(46px, 5.6vw, 58px);
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  width: var(--size);
  aspect-ratio: 1;
  padding: 3px;
  display: grid;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 50%;
  transition: border-color 0.16s ease, transform 0.16s ease;
}
.choices button:active { transform: scale(0.95); }

.coat {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background-color: #e3d9ca;
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 1px #33281e3b;
}
:root[data-theme="dark"] .coat {
  box-shadow: inset 0 0 0 1px #b8c9df48;
}

.choices button[aria-pressed="true"] {
  border-color: var(--ink);
}
.choices button[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--mark) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4 8 2.7 2.8 5.3-5.6' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E") center/100% no-repeat;
}

.tools {
  position: relative;
  gap: 3px;
  flex: none;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  padding: 10px;
  transition: background-color 0.16s ease;
}
.icon-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: hover) {
  .icon-button:hover { background-color: var(--hover); }
  .choices button:hover:not([aria-pressed="true"]) { border-color: #bbaa98; }
}

#sound[aria-checked="false"] .waves,
#sound[aria-checked="true"] .muted { display: none; }
#sound[aria-checked="true"],
#walk-toggle[aria-checked="true"],
#proportions-toggle[aria-expanded="true"] { background: var(--hover); }
#walk-toggle[aria-checked="false"] .home-icon,
#walk-toggle[aria-checked="true"] .walk-icon { display: none; }

/* 遛狗模式下鼠标引导俯视场景内的主人行走与转身，保持清晰柔和指针 */
#stage[data-scene="walk"] { cursor: default; }
#stage[data-scene="walk"][data-petting="true"] { cursor: pointer; }
#stage[data-scene="walk"] button { cursor: pointer; }

/* ---------- 体格浮层 ---------- */
#proportions-panel {
  position: absolute;
  z-index: 5;
  bottom: calc(100% + 8px);
  right: 0;
  width: 264px;
  max-width: calc(100vw - 24px);
  padding: 7px 9px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--edge);
  border-radius: 16px;
  box-shadow: 0 4px 18px #21170c24;
}
.proportion-row {
  position: relative;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 3px;
}
.proportion-row::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 2px;
  height: 5px;
  transform: translateX(-50%);
  border-radius: 1px;
  background: var(--muted);
  pointer-events: none;
}
.proportion-row svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
  pointer-events: none;
}
#proportions-panel input {
  display: block;
  min-width: 0;
  width: 100%;
  height: 42px;
  margin: 0;
  accent-color: var(--focus);
  touch-action: none;
  cursor: pointer;
}
#proportions-panel input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-radius: 4px;
}

.sr, .symbols {
  position: absolute;
  overflow: hidden;
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  margin: 0;
}

/* ---------- 全屏与移动端横屏响应式适配 ---------- */
#viewer:fullscreen, #viewer.is-full {
  background: var(--paper);
  width: 100%;
  height: 100%;
  padding: var(--gap);
  max-width: none;
  align-content: center;
}
#viewer.is-full { position: fixed; inset: 0; z-index: 9; }
.is-full-page { overflow: hidden; }
#viewer:fullscreen #stage, #viewer.is-full #stage {
  width: 100%;
  max-height: calc(100dvh - 86px);
  min-height: 0;
}
#viewer:fullscreen .breed-lineup, #viewer.is-full .breed-lineup {
  max-height: calc(100dvh - 86px);
}

@media (min-width: 526px) {
  .tools { margin-inline-start: auto; }
}
@media (max-width: 680px) {
  :root { --lineup-w: clamp(54px, 13vw, 66px); }
  #stage { aspect-ratio: 1.50; }
}
@media (max-width: 525px) and (orientation: portrait) {
  .toolbar { flex-direction: column; justify-content: center; gap: 4px; grid-column: 1 / -1; }
  .choices { gap: 5px; flex-wrap: wrap; justify-content: center; max-width: 100%; }
  #viewer:not(.landscape) .choices button { --size: clamp(44px, 12.5vw, 52px); }
  #viewer:not(.landscape) #proportions-panel { right: 50%; transform: translateX(50%); }
}

#viewer.landscape {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 9;
  margin: 0;
  max-width: none;
  width: 100vw; width: 100dvw;
  height: 100vh; height: 100dvh;
  background: var(--paper);
  display: grid;
  grid-template-columns: var(--lineup-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  padding: max(var(--gap), env(safe-area-inset-top)) max(var(--gap), env(safe-area-inset-right)) max(var(--gap), env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left));
}
.landscape .playfield {
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
}
.landscape .breed-lineup {
  max-height: 100%;
}
#viewer.landscape #stage {
  --top-crop: 0.1;
  aspect-ratio: 2 / 1;
  width: min(100cqw, 200cqh);
  max-height: none;
}
.landscape .toolbar { flex-flow: row nowrap; justify-content: space-between; gap: 6px; padding: 4px 0 0; }
.landscape .choices { gap: clamp(4px, 0.7vw, 8px); }
.landscape .choices button { --size: clamp(42px, 5.5vw, 46px); }

@media (orientation: portrait) {
  #viewer:not(.landscape) .toolbar { flex-wrap: wrap; }
  #viewer.landscape {
    width: 100vh; width: 100dvh;
    height: 100vw; height: 100dvw;
    transform-origin: 0 0;
    transform: translateX(100vw) rotate(90deg);
    transform: translateX(100dvw) rotate(90deg);
    padding: max(var(--gap), env(safe-area-inset-right)) max(var(--gap), env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left)) max(var(--gap), env(safe-area-inset-top));
  }
}
