/* 工具箱「精灵展示」的盒子窗口布局。
   与查看器自己的 styles.css（全屏画布 + 右侧栏）是两套东西：
   这里要的是旧版页面那种带标题、圆角舞台、下方控件卡片的盒子，PC 与手机都能用。
   类名沿用 toolshell 的 --shell-* 变量，所以浅色/深色主题都跟工具箱走。 */

.pet-viewer-self,
.pet-viewer-self *,
.pet-viewer-self *::before,
.pet-viewer-self *::after {
  box-sizing: border-box;
}

.pet-viewer-self {
  --pet-blue: var(--shell-accent);
  --pet-ink: var(--shell-text);
  --pet-muted: var(--shell-muted);
  --pet-card: var(--shell-panel);
  --pet-line: var(--shell-line);
  --pet-field: var(--shell-panel-soft);
  background: transparent;
}

.pet-viewer-main {
  min-width: 0;
  padding: 0;
}

/* ── 盒子 ───────────────────────────────────────────── */

.pet-viewer-wrap {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.pet-stage-card {
  overflow: hidden;
  border: 1px solid var(--pet-line);
  border-radius: 14px;
  background: var(--pet-card);
  box-shadow: 0 10px 28px rgba(20, 40, 70, 0.08);
}

.pet-stage-heading {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 20px;
  color: var(--pet-ink);
  background: var(--pet-card);
}

.pet-stage-kicker {
  display: block;
  margin-bottom: 3px;
  color: var(--pet-blue);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.12em;
}

.pet-stage-heading h1 {
  margin: 0;
  font-size: clamp(24px, 2.6vw, 30px);
  line-height: 1.1;
}

.pet-stage-heading p {
  margin: 5px 0 0;
  color: var(--pet-muted);
  font-size: 13px;
}

.pet-stage-badge {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 999px;
  color: var(--shell-on-accent, #fff);
  background: var(--shell-accent);
  font-size: 12.5px;
  font-weight: 650;
}

.pet-stage-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 异色切换：同一只模型换一套贴图。按下时整颗按钮变金，看得出正在看异色。 */
.pet-shiny-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid color-mix(in srgb, var(--shell-accent) 45%, transparent);
  border-radius: 999px;
  color: var(--pet-blue);
  background: color-mix(in srgb, var(--shell-accent) 8%, var(--pet-card));
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.pet-shiny-toggle i { font-size: 12px; }
.pet-shiny-toggle:hover { background: color-mix(in srgb, var(--shell-accent) 16%, var(--pet-card)); }

.pet-shiny-toggle[aria-pressed="true"] {
  color: #4a3506;
  border-color: #d9a53c;
  background: linear-gradient(150deg, #f7d98b, #eebb52);
  box-shadow: 0 2px 8px rgba(180, 130, 30, .28);
}

.pet-shiny-toggle:disabled { opacity: .45; cursor: not-allowed; }
.pet-shiny-toggle[hidden] { display: none; }

.pet-stage {
  position: relative;
  min-height: clamp(360px, 52vh, 560px);
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(circle at 50% 76%, rgba(255, 255, 255, 0.6), transparent 30%),
    linear-gradient(180deg, #6aace4 0%, #86c0ee 68%, #7cb2e2 100%);
}

.pet-stage-pattern {
  position: absolute;
  z-index: 1;
  inset: -16% -12% 12%;
  opacity: 0.22;
  pointer-events: none;
  transform: rotate(-8deg) scale(1.1);
  background-image: radial-gradient(circle at 18% 32%, rgba(255, 255, 255, .88) 0 2.5%, transparent 2.7%),
    radial-gradient(circle at 68% 18%, rgba(255, 255, 255, .62) 0 3%, transparent 3.2%),
    radial-gradient(circle at 83% 70%, rgba(255, 255, 255, .72) 0 2%, transparent 2.2%),
    repeating-linear-gradient(128deg, transparent 0 56px, rgba(255, 255, 255, .44) 58px 62px, transparent 64px 118px);
  background-size: 270px 210px, 310px 230px, 230px 260px, 210px 210px;
  animation: pet-pattern-drift 18s linear infinite;
}

@keyframes pet-pattern-drift {
  to { background-position: 270px -210px, -310px 230px, 230px 260px, 210px -210px; }
}

/* 舞台中央的圆环徽记，和旧版一致：给空背景一点纵深，不挡住模型 */
.pet-stage-emblem {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: min(46%, 360px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  transform: translate(-50%, -51%);
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 20px rgba(255, 255, 255, 0.055);
  pointer-events: none;
}

#view {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
  cursor: grab;
  touch-action: none;
}

#view:active { cursor: grabbing; }

.pet-stage-tip {
  position: absolute;
  z-index: 3;
  right: 12px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(14, 40, 70, 0.28);
  backdrop-filter: blur(3px);
  font-size: 11.5px;
  pointer-events: none;
}

/* 舞台右上角的快捷按钮：复位视角 / 随机动作，手机不用滚到控件区 */
.pet-stage-tools {
  position: absolute;
  z-index: 3;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 7px;
}

.pet-stage-tools button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(14, 40, 70, 0.34);
  backdrop-filter: blur(3px);
  font-size: 14px;
}

.pet-stage-tools button:hover {
  background: rgba(14, 40, 70, 0.5);
}

/* 状态行贴在盒子下方，不挤占舞台 */
#status {
  margin: 8px 2px 0;
  color: var(--pet-muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* 没有要说的就别占一行：加载完成且无异色提示时整行收起 */
#status:empty { display: none; }

/* ── 控件卡片 ───────────────────────────────────────── */

.pet-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px 0 28px;
  align-items: start;
}

.pet-control-card {
  border: 1px solid var(--pet-line);
  border-radius: 12px;
  background: var(--pet-card);
  overflow: hidden;
}

.pet-control-card > summary,
.pet-control-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  color: var(--pet-ink);
  font-weight: 650;
  font-size: 14.5px;
}

.pet-control-card > summary {
  cursor: pointer;
  list-style: none;
}

.pet-control-card > summary::-webkit-details-marker { display: none; }

.pet-control-card > summary::after {
  content: "\f078";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  font-size: 11px;
  color: var(--pet-muted);
  transition: transform .18s ease;
}

.pet-control-card[open] > summary::after { transform: rotate(180deg); }

.pet-control-card > summary small,
.pet-control-title small {
  font-weight: 400;
  color: var(--pet-muted);
  font-size: 12px;
}

.pet-control-body {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 0 16px 16px;
}

/* 一行一个设置项：左边标签，右边控件 */
.pet-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--pet-muted);
  font-size: 13px;
}

.pet-field > span { flex: 0 0 auto; }

.pet-field select,
.pet-field input[type="search"],
.pet-field input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 62%;
}

.pet-field-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--pet-muted);
  font-size: 13px;
}

.pet-viewer-self select,
.pet-viewer-self input[type="search"],
.pet-viewer-self input[type="range"],
.pet-viewer-self input[type="file"],
.pet-viewer-self button {
  font: inherit;
  color: var(--shell-text);
  background: var(--pet-field);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 9px;
}

.pet-viewer-self select:hover,
.pet-viewer-self input:hover { border-color: var(--pet-line); }

.pet-viewer-self button { cursor: pointer; }

.pet-viewer-self button:disabled { opacity: .5; cursor: default; }

.pet-viewer-self input[type="search"] { width: 100%; }

.pet-viewer-self :where(button, summary, input, select):focus-visible {
  outline: 2px solid var(--pet-blue);
  outline-offset: 2px;
}

.pet-button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.pet-button-row button { flex: 1 1 auto; }

#pet-meta {
  margin: 2px 0 0;
  color: var(--pet-muted);
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

#pet-meta .live { color: #d9822b; }
#pet-meta .art { color: #4a86c5; }

#chain {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

#chain .chain-title {
  flex: 1 0 100%;
  font-size: 12px;
  color: var(--pet-muted);
}

#chain button {
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--pet-line);
}

#chain button.live::before { content: "✦ "; color: #e08a2e; }
#chain button.art::before { content: "◌ "; color: #6f9fd0; }
#chain button.none::before { content: "· "; color: var(--pet-muted); }
#chain button:disabled { opacity: .45; }

#color-preview {
  display: flex;
  height: 20px;
  border-radius: 6px;
  overflow: hidden;
  margin: 2px 0;
}

#color-preview span { flex: 1; }

#color-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px 0;
}

.color-card {
  padding: 3px;
  display: grid;
  gap: 3px;
  font-size: 10px;
  color: var(--pet-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
}

/* 色卡名字（浅蓝蓝、浅绿青…）必须一行显示，两行会把格子撑歪。
   工具箱的 shell.css 会给 button 定字号，这里连字号一起写在 span 上，压过那条规则。 */
.color-card > span:last-child {
  display: block;
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  line-height: 1.25;
}

.color-card.active {
  border-color: #ecc46a;
  background: color-mix(in srgb, var(--shell-accent) 8%, transparent);
}

.color-card-swatch {
  border-radius: 7px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.color-card-swatch svg { width: 11px; height: 11px; }
.color-card-swatch svg:nth-child(2) { width: 16px; height: 16px; }

/* 动作按钮：两列，限高内滚 */
#clips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  max-height: 230px;
  overflow-y: auto;
  padding-right: 2px;
}

#clips section {
  grid-column: 1 / -1;
  display: contents;
}

#clips h3 {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--pet-muted);
}

#clips button {
  font-size: 12px;
  padding: 6px 8px;
  text-align: left;
  border: 1px solid var(--pet-line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#clips button.active {
  color: var(--shell-on-accent, #fff);
  background: var(--shell-accent);
  border-color: transparent;
}

.pet-viewer-self .hint {
  margin: 0;
  color: var(--pet-muted);
  font-size: 11.5px;
  line-height: 1.5;
}

.pet-viewer-self details > summary {
  cursor: pointer;
  color: var(--pet-muted);
  font-size: 12.5px;
}

.pet-viewer-self details[open] > summary { margin-bottom: 6px; }

.pet-viewer-self [hidden] { display: none !important; }

#voice-label {
  color: var(--pet-muted);
  font-size: 11.5px;
}

/* ── 平板：舞台在上、控件单列，舞台跟着滚 ───────────── */
@media (max-width: 900px) {
  .pet-viewer-wrap {
    width: 100%;
  }

  .pet-stage-shell {
    position: sticky;
    z-index: 20;
    top: calc(var(--shell-mobilebar-offset, 0px) + 6px);
    padding-bottom: 6px;
    background: var(--shell-bg, transparent);
  }

  .pet-stage-heading {
    padding: 12px 14px 10px;
  }

  .pet-stage-heading h1 { font-size: 21px; }
  .pet-stage-heading p { font-size: 11.5px; }
  .pet-stage-kicker { display: none; }

  .pet-stage {
    min-height: 0;
    height: min(42svh, 360px);
  }

  #view { min-height: 0; height: 100%; }

  .pet-controls {
    display: block;
    padding: 4px 0 24px;
  }

  .pet-control-card {
    margin-top: 10px;
  }

  .pet-control-card > summary,
  .pet-control-title { padding: 12px 14px; }

  .pet-control-body { padding: 0 14px 14px; }

  .pet-field select,
  .pet-field input[type="search"],
  .pet-field input[type="range"] { max-width: 58%; }

  #clips { max-height: 200px; }
}

@media (max-width: 420px) {
  .pet-stage { height: 38svh; min-height: 260px; }
  .pet-stage-tip { display: none; }
  .pet-field { font-size: 12.5px; }
  #clips { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .pet-stage-pattern { animation: none; }
}

/* 切换精灵时的加载层。一个包十几 MB，没反馈会被当成卡死而反复点。 */
#loading {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 30, 52, 0.44);
  backdrop-filter: blur(2px);
}

.loading-card {
  width: min(280px, 74%);
  padding: 13px 15px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 30px rgba(12, 40, 70, 0.24);
  color: #12324f;
}

.loading-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}

.loading-line b {
  font-size: 12px;
  font-weight: 600;
  color: #4d6b87;
  font-variant-numeric: tabular-nums;
}

.loading-bar {
  height: 5px;
  margin: 9px 0 7px;
  border-radius: 999px;
  background: #dbe6f2;
  overflow: hidden;
}

.loading-bar i {
  display: block;
  width: 2%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4a9bd8, #7bc4f0);
  transition: width 0.16s linear;
}

#loading-stage { font-size: 11.5px; color: #5c7893; }
