@property --preview-scene {
  syntax: "<color>";
  inherits: true;
  initial-value: #dfe3e2;
}

@property --preview-floor {
  syntax: "<color>";
  inherits: true;
  initial-value: #f5f4f0;
}

:root {
  --ink: #122b33;
  --muted: #60777e;
  --line: #d5e0e1;
  --control: rgba(255, 255, 255, .92);
  --control-hover: #e4efff;
  --accent: #1468d4;
  --stage: #edf4f3;
  --preview-scene: #dfe3e2;
  --preview-floor: #f5f4f0;
  --preview-gradient-size: 92% 64%;
  --preview-gradient-stop: 78%;
  --shadow: 0 12px 28px rgba(31, 64, 72, .14);
  --focus: 0 0 0 4px rgba(20, 104, 212, .18);
}

:root[data-theme="dark"] {
  --ink: #edf6f5;
  --muted: #a3b8bc;
  --line: #30444c;
  --control: rgba(20, 33, 40, .94);
  --control-hover: #173557;
  --accent: #66a8ff;
  --stage: #0c151a;
  --preview-scene: #151616;
  --preview-floor: #252626;
  --preview-gradient-size: 88% 58%;
  --preview-gradient-stop: 72%;
  --shadow: 0 14px 32px rgba(0, 0, 0, .34);
  --focus: 0 0 0 4px rgba(102, 168, 255, .22);
}

* { box-sizing: border-box; }

.direction-cube { position: fixed; z-index: 8; top: 16px; right: calc(var(--debug-dock-offset, 0px) + 16px); width: 116px; color: var(--ink); }
:root[data-public-viewer="true"] .direction-cube { top: 62px; }
.direction-cube[hidden], .cube-labels[hidden], .cube-labels span[hidden] { display: none; }
.direction-cube svg { width: 100%; height: 116px; overflow: visible; }
.direction-cube g { cursor: pointer; outline: none; }
.direction-cube polygon { fill: var(--control); stroke: var(--muted); stroke-width: .6; stroke-linejoin: round; }
.direction-cube g[data-kind="edge"] polygon, .direction-cube g[data-kind="corner"] polygon { fill: var(--line); }
.direction-cube g:hover polygon, .direction-cube g:focus-visible polygon { fill: var(--control-hover); stroke: var(--accent); stroke-width: 1.8; }
.direction-cube button { width: 100%; padding: 7px 5px; border: 1px solid var(--line); border-radius: 6px; background: var(--control); color: var(--ink); font: inherit; font-size: 12px; cursor: pointer; }
.direction-cube button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.cube-labels { position: absolute; top: 0; left: 0; pointer-events: none; }
.cube-labels span { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.cube-labels b { display: block; position: absolute; width: 28px; height: 28px; left: -14px; top: -14px; text-align: center; line-height: 28px; font-size: 19px; font-weight: 600; }
.orientation-panel { position: absolute; z-index: 12; left: 16px; top: 16px; width: min(360px, calc(100% - 32px)); padding: 16px; background: var(--control); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.orientation-panel[hidden] { display: none; }
.orientation-panel h2 { margin: 0 0 10px; font-size: 17px; }
.orientation-panel p { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.orientation-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.orientation-actions button { border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--stage); padding: 8px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.orientation-actions button[aria-pressed="true"], .orientation-actions [data-save]:enabled { border-color: var(--accent); color: var(--accent); }
.orientation-actions button:focus-visible, .orientation-actions a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.orientation-actions button:disabled { opacity: .5; cursor: default; }
.orientation-actions a { font-size: 12px; color: var(--muted); }
.orientation-panel output { display: block; min-height: 36px; padding: 10px 0; font-size: 12px; line-height: 1.5; }
.orientation-panel output[data-state="error"] { color: #bc3d35; }
:root[data-orientation-active] [inert] { opacity: .5; }
:root[data-orientation-active] .part-note-layer { visibility: hidden; }
@media (max-width: 600px) {
  .direction-cube { top: 10px; right: calc(var(--debug-dock-offset, 0px) + 10px); width: 88px; }
  :root[data-public-viewer="true"] .direction-cube { top: 62px; }
  .direction-cube svg { height: 88px; }
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--stage);
  font-family: "Microsoft YaHei UI", "Noto Sans SC", sans-serif;
}

#viewport {
  position: fixed;
  inset: 0;
  bottom: var(--part-note-space, 0px);
  background:
    radial-gradient(
      ellipse var(--preview-gradient-size) at 50% 58%,
      var(--preview-floor) 0%,
      var(--preview-floor) 12%,
      var(--preview-scene) var(--preview-gradient-stop)
    );
  transition:
    --preview-scene 420ms ease,
    --preview-floor 420ms ease;
}

:root[data-background-mode="flat"] #viewport {
  background: var(--preview-scene);
  transition: none;
}

.controls,
.fullscreen-control {
  position: fixed;
  z-index: 2;
  border: 1px solid var(--line);
  background: var(--control);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.controls {
  left: 50%;
  bottom: 22px;
  display: flex;
  gap: 5px;
  padding: 6px;
  border-radius: 14px;
  transform: translateX(-50%);
}

.fullscreen-control {
  right: 22px;
  bottom: 22px;
  min-width: 68px;
  min-height: 42px;
  padding: 9px 14px;
  border-radius: 12px;
}

button {
  min-height: 38px;
  padding: 8px 14px;
  border: 0;
  border-radius: 9px;
  color: var(--ink);
  background: transparent;
  font: 700 13px/1 "Microsoft YaHei UI", sans-serif;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, transform 160ms ease;
}

button:hover {
  color: var(--accent);
  background: var(--control-hover);
}

button.active {
  color: #fff;
  background: var(--accent);
}

button:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

button:active {
  transform: translateY(1px);
}

#status {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--stage);
  font-size: 13px;
}

#status.hidden {
  display: none;
}

/* @preview-extension:styles */

.viewer-heading, .viewer-hint, .model-toggle { display: none; }

:root[data-model-controls="true"] {
  --viewer-control-ink: #1d2a34;
  --viewer-control-muted: #455a68;
  --viewer-control-line: #cad7df;
  --viewer-control-surface: #f5f8faed;
  --control-shadow: 0 8px 24px #344c5c13;
  --toggle-surface: #cbd6de;
  --toggle-line: #c5d1da;
}

:root[data-model-controls="true"][data-theme="dark"] {
  --viewer-control-ink: #eff4f7;
  --viewer-control-muted: #b7c9d2;
  --viewer-control-line: #2c424f;
  --viewer-control-surface: #0b151dee;
  --control-shadow: 0 8px 24px #00000040;
  --toggle-surface: #25343d;
  --toggle-line: #2a3b46;
}

:root[data-public-viewer="true"] {
  --ink: #1d2a34;
  --muted: #455a68;
  --line: #cad7df;
  --stage: #d1dce3;
  --control: #f5f8faed;
  --accent: #ba4419;
  --control-hover: #cbd6de;
  --control-shadow: 0 8px 24px #344c5c13;
  --toggle-surface: #cbd6de;
  --toggle-line: #c5d1da;
}

:root[data-public-viewer="true"] body,
:root[data-public-viewer="true"] button {
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}

:root[data-public-viewer="true"][data-theme="dark"] {
  --ink: #eff4f7;
  --muted: #b7c9d2;
  --line: #2c424f;
  --stage: #15232b;
  --control: #0b151dee;
  --control-hover: #25343d;
  --control-shadow: 0 8px 24px #00000040;
  --toggle-surface: #25343d;
  --toggle-line: #2a3b46;
}

:root[data-public-viewer="true"] #viewport,
:root[data-debug-inspector="true"][data-debug-theme-background="true"][data-theme="light"][data-background="soft"] #viewport {
  background:
    radial-gradient(ellipse 82% 78% at 50% 61%, #f8fafc 0%, #eaf0f4 40%, rgba(220, 231, 238, 0) 85%),
    linear-gradient(165deg, #d9e3ea 0%, #d2dee6 68%, #c8d5df 100%);
}

:root[data-public-viewer="true"][data-theme="dark"] #viewport,
:root[data-debug-inspector="true"][data-debug-theme-background="true"][data-theme="dark"][data-background="slate"] #viewport {
  background:
    radial-gradient(ellipse 84% 82% at 50% 61%, #2d4149 0%, #25363f 32%, rgba(18, 30, 39, 0) 84%),
    linear-gradient(180deg, #15232b 0%, #18272f 65%, #14222a 100%);
}

:root[data-public-viewer="true"][data-background="green-screen"] #viewport { background: #00ff00; }
:root[data-public-viewer="true"][data-background="slate"] #viewport { background: #263238; }

:root[data-public-viewer="true"] .viewer-heading {
  position: fixed;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  top: 20px;
  left: 22px;
  right: 66px;
  min-height: 32px;
  pointer-events: none;
}

.viewer-title { display: flex; align-items: center; gap: 9px; font-size: 16px; font-weight: 650; }
.viewer-title svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; color: var(--muted); }
.view-state { margin-left: auto; padding: 4px 8px; color: var(--muted); background: color-mix(in srgb, var(--control-hover) 40%, transparent); border: 1px solid color-mix(in srgb, var(--line) 50%, transparent); border-radius: 5px; font-size: 12px; white-space: nowrap; }

:root[data-public-viewer="true"] .fullscreen-control {
  top: 16px;
  right: 16px;
  bottom: auto;
  min-width: 40px;
  width: 40px;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  backdrop-filter: none;
  font-size: 0;
  font-weight: 500;
}

:root[data-public-viewer="true"] .controls { bottom: calc(22px + var(--part-note-space, 0px)); }

:root[data-model-controls="true"] .controls {
  align-items: center;
  width: max-content;
  max-width: calc(100% - 24px);
  gap: 16px;
  padding: 6px 15px 6px 6px;
  border-radius: 12px;
  color: var(--viewer-control-ink);
  border-color: var(--viewer-control-line);
  background: var(--viewer-control-surface);
  box-shadow: var(--control-shadow);
}

:root[data-model-controls="true"] .controls button { font-family: "Segoe UI", "Microsoft YaHei", sans-serif; }

:root[data-model-controls="true"] #completeBtn,
:root[data-model-controls="true"] #explodeBtn { display: none; }

:root[data-model-controls="true"] .model-toggle {
  display: block;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 132px;
  height: 39px;
  padding: 0;
  border-radius: 7px;
  border: 1px solid #a73b13;
  background: #bf4618;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: inset 0 1px #ffffff26;
}

.toggle-base-label, .toggle-fill, .toggle-fill > span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.toggle-base-label[data-fill-state="exploded"], .toggle-fill { background: #fff; color: #2b3b45; box-shadow: inset 0 0 0 1px #dfe6eb; border-radius: 6px; }
.toggle-fill { clip-path: circle(0px at 50% 50%); pointer-events: none; }
:root[data-theme="dark"] .toggle-base-label[data-fill-state="exploded"],
:root[data-theme="dark"] .toggle-fill { background: #314d60; color: #f4f9fd; box-shadow: inset 0 0 0 1px #597587; }
:root[data-model-controls="true"] .toggle-base-label[data-fill-state="exploded"],
:root[data-model-controls="true"] .toggle-fill { background: var(--toggle-surface); color: var(--viewer-control-ink); box-shadow: inset 0 0 0 1px var(--toggle-line); }
.toggle-fill[data-fill-state="complete"],
:root[data-model-controls="true"] .toggle-fill[data-fill-state="complete"],
:root[data-theme="dark"] .toggle-fill[data-fill-state="complete"] { background: #bf4618; color: #fff; box-shadow: inset 0 1px #ffffff26; }
.model-toggle:disabled { cursor: progress; opacity: .7; }
:root[data-model-controls="true"] #resetBtn { position: relative; width: 66px; min-width: 66px; padding: 0 0 0 16px; color: var(--viewer-control-muted); font-size: 0; }
:root[data-model-controls="true"] #resetBtn::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 1px; background: var(--viewer-control-line); }
:root[data-model-controls="true"] #resetBtn::after,
:root[data-public-viewer="true"] .fullscreen-control::after { content: ""; display: block; width: 18px; height: 18px; margin: auto; background: var(--viewer-control-muted); mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9a8 8 0 1 1-.3 6M4 4v5h5'/%3E%3C/svg%3E") center / contain no-repeat; }
:root[data-public-viewer="true"] .fullscreen-control::after { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='M8 4H4v4m12-4h4v4M4 16v4h4m12-4v4h-4'/%3E%3C/svg%3E"); }
:root[data-public-viewer="true"] .viewer-hint { position: fixed; display: block; right: 22px; bottom: calc(30px + var(--part-note-space, 0px)); margin: 0; color: var(--muted); font-size: 11px; text-align: right; pointer-events: none; }

@media (max-width: 560px) {
  :root[data-public-viewer="true"] .viewer-heading { top: 16px; left: 16px; right: 56px; gap: 8px; }
  :root[data-public-viewer="true"] .viewer-title { font-size: 14px; }
  :root[data-public-viewer="true"] .viewer-title svg { width: 16px; height: 16px; }
  :root[data-public-viewer="true"] .view-state { font-size: 11px; padding-inline: 5px; }
  :root[data-public-viewer="true"] .fullscreen-control { top: 12px; right: 8px; min-width: 40px; }
  :root[data-public-viewer="true"] .controls { bottom: calc(16px + var(--part-note-space, 0px)); }
  :root[data-public-viewer="true"] .viewer-hint { width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

.part-note-layer {
  position: fixed;
  z-index: 1;
  pointer-events: none;
  color: #000;
}
.part-note-layer[data-theme="dark"] { color: #fff; }
.part-note-layer[hidden], .part-note-text [hidden] { display: none; }
.part-note-layer svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.part-note-layer polyline { fill: none; stroke: var(--part-line-color, #008bba); stroke-width: 1.25; vector-effect: non-scaling-stroke; }
.part-note-text {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: auto;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: clamp(12px, 1.4vw, 15px);
  line-height: 1.65;
}
.part-note-text strong { flex: none; font-size: clamp(15px, 1.8vw, 22px); line-height: 1.35; }
.part-note-body { min-height: 0; overflow-y: auto; white-space: pre-wrap; overscroll-behavior: contain; }
.part-note-body:focus-visible { outline: 1px solid currentColor; outline-offset: -1px; }
.part-note-layer[data-mobile="true"] svg { display: none; }
.part-note-layer[data-mobile="true"] .part-note-text { font-size: 14px; }
.part-note-layer[data-mobile="true"] strong { font-size: 17px; }

:root[data-thumbnail="true"] .controls,
:root[data-thumbnail="true"] .fullscreen-control {
  display: none;
}

@media (max-width: 560px) {
  .controls {
    bottom: 14px;
    gap: 2px;
    padding: 4px;
  }

  .controls button {
    padding: 8px 10px;
  }

  .fullscreen-control {
    right: 14px;
    bottom: 14px;
    min-width: 58px;
    padding-inline: 10px;
  }


}

@media (prefers-reduced-motion: reduce) {
  button {
    transition-duration: .01ms;
  }
}
