:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171614;
  --bg-deep: #0e0e0d;
  --panel: rgba(27, 26, 24, 0.9);
  --panel-solid: #1b1a18;
  --ink: #f0ede6;
  --muted: #aaa49b;
  --faint: #77736d;
  --line: rgba(232, 226, 215, 0.14);
  --line-strong: rgba(232, 226, 215, 0.28);
  --accent: #b86856;
  --accent-soft: rgba(184, 104, 86, 0.14);
  --signal: #8fa1ad;
  --pending: #c58a63;
  --topbar: linear-gradient(180deg, rgba(14, 14, 13, 0.96), rgba(14, 14, 13, 0.76));
  --body-glow: rgba(71, 68, 63, 0.62);
  --grid-line: rgba(214, 207, 195, 0.08);
  --button-surface: rgba(38, 36, 33, 0.76);
  --button-selected: rgba(63, 68, 72, 0.74);
  --glass-surface: rgba(24, 23, 21, 0.78);
  --readout-surface: rgba(14, 14, 13, 0.72);
  --loading-surface: rgba(14, 14, 13, 0.84);
  --card-surface: rgba(14, 14, 13, 0.58);
  --logo-groove: #68635c;
  --logo-shadow: rgba(0, 0, 0, 0.76);
  --logo-highlight: rgba(255, 255, 255, 0.2);
  --khaki: #d9c9a6;
  --wood: #5b4637;
  --display: "Avenir Next Condensed", "Arial Narrow", "PingFang TC", sans-serif;
  --sans: "Avenir Next", "PingFang TC", system-ui, sans-serif;
  --mono: "SFMono-Regular", Menlo, Consolas, monospace;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #ece9e2;
  --bg-deep: #d9d5cd;
  --panel: rgba(247, 244, 237, 0.92);
  --panel-solid: #f4f1ea;
  --ink: #252421;
  --muted: #716d66;
  --faint: #928d84;
  --line: rgba(37, 36, 33, 0.14);
  --line-strong: rgba(37, 36, 33, 0.26);
  --accent: #a65242;
  --accent-soft: rgba(166, 82, 66, 0.12);
  --signal: #637985;
  --pending: #9b6747;
  --topbar: linear-gradient(180deg, rgba(247, 244, 237, 0.97), rgba(247, 244, 237, 0.82));
  --body-glow: rgba(255, 252, 244, 0.86);
  --grid-line: rgba(52, 49, 44, 0.08);
  --button-surface: rgba(255, 252, 245, 0.76);
  --button-selected: rgba(213, 218, 220, 0.78);
  --glass-surface: rgba(247, 244, 237, 0.8);
  --readout-surface: rgba(247, 244, 237, 0.74);
  --loading-surface: rgba(236, 233, 226, 0.88);
  --card-surface: rgba(255, 252, 245, 0.66);
  --logo-groove: #8e8980;
  --logo-shadow: rgba(51, 48, 43, 0.34);
  --logo-highlight: rgba(255, 255, 255, 0.88);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(78% 92% at 38% 42%, var(--body-glow), transparent 66%),
    linear-gradient(145deg, var(--bg) 0%, var(--bg-deep) 100%);
  font-family: var(--sans);
  overflow: hidden;
  transition: color 180ms ease, background-color 180ms ease;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.utility-label {
  margin: 0;
  color: var(--muted);
  font: 600 0.65rem/1 var(--mono);
  letter-spacing: 0.18em;
}

.topbar {
  position: fixed;
  z-index: 20;
  inset: 0 0 auto;
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-lockup h1 {
  margin: 3px 0 0;
  font: 750 1.65rem/0.95 var(--display);
  letter-spacing: 0.03em;
}

.brand-mark {
  width: 39px;
  height: 39px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.brand-mark svg {
  width: 34px;
  height: 34px;
  display: block;
  fill: none;
  stroke-linecap: round;
}

.logo-groove-shadow,
.logo-groove-highlight,
.logo-groove-core {
  fill: none;
}

.logo-groove-shadow {
  stroke: var(--logo-shadow);
  stroke-width: 3.2;
  transform: translate(-0.55px, -0.55px);
}

.logo-groove-highlight {
  stroke: var(--logo-highlight);
  stroke-width: 3.2;
  transform: translate(0.55px, 0.65px);
}

.logo-groove-core {
  stroke: var(--logo-groove);
  stroke-width: 2.5;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--glass-surface);
  cursor: pointer;
  font: 600 0.65rem/1 var(--mono);
  letter-spacing: 0.08em;
}

.theme-icon {
  width: 14px;
  height: 14px;
  display: block;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
  transform: rotate(-28deg);
}

.release-stamp {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font: 600 0.65rem/1 var(--mono);
  letter-spacing: 0.14em;
}

.release-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 4px rgba(143, 161, 173, 0.13);
}

.studio-shell {
  position: fixed;
  inset: 74px 0 0;
}

.viewer-panel,
.viewer-stage {
  position: absolute;
  inset: 0;
}

.viewer-stage::before {
  position: absolute;
  inset: 0 382px 0 0;
  content: "";
  pointer-events: none;
  opacity: 0.2;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: radial-gradient(circle at 48% 48%, black, transparent 72%);
}

#viewer {
  position: absolute;
  inset: 0 382px 0 0;
  width: calc(100% - 382px);
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

#viewer:active {
  cursor: grabbing;
}

.viewer-title-block {
  position: absolute;
  z-index: 3;
  top: 28px;
  left: 30px;
  max-width: 28rem;
  pointer-events: none;
}

.viewer-title-block h2 {
  margin: 9px 0 4px;
  font: 760 clamp(2.7rem, 5vw, 5.8rem)/0.84 var(--display);
  letter-spacing: -0.04em;
}

.viewer-title-block p:last-child {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
  letter-spacing: 0.04em;
}

.viewer-actions {
  position: absolute;
  z-index: 4;
  top: 28px;
  right: 406px;
  display: flex;
  gap: 8px;
}

.quiet-button,
.motion-toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass-surface);
  color: var(--muted);
  cursor: pointer;
  backdrop-filter: blur(12px);
  font-size: 0.76rem;
}

.motion-toggle.is-on {
  border-color: rgba(239, 91, 63, 0.56);
  color: #ff8b73;
  background: rgba(53, 24, 19, 0.78);
}

.motion-icon {
  height: 14px;
  display: flex;
  align-items: end;
  gap: 2px;
}

.motion-icon i {
  width: 2px;
  height: 7px;
  border-radius: 2px;
  background: currentColor;
}

.motion-icon i:nth-child(2) {
  height: 13px;
}

.motion-icon i:nth-child(3) {
  height: 9px;
}

.motion-toggle.is-on .motion-icon i {
  animation: pulse-bar 0.65s ease-in-out infinite alternate;
}

.motion-toggle.is-on .motion-icon i:nth-child(2) {
  animation-delay: -0.23s;
}

.motion-toggle.is-on .motion-icon i:nth-child(3) {
  animation-delay: -0.41s;
}

@keyframes pulse-bar {
  to { transform: scaleY(0.42); }
}

.viewer-hint,
.source-mark {
  position: absolute;
  z-index: 3;
  bottom: 79px;
  margin: 0;
  color: var(--faint);
  font: 0.62rem/1 var(--mono);
  letter-spacing: 0.1em;
  pointer-events: none;
}

.viewer-hint {
  left: 30px;
}

.source-mark {
  right: 406px;
}

.viewer-readout {
  position: absolute;
  z-index: 3;
  right: 382px;
  bottom: 0;
  left: 0;
  min-height: 58px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  background: var(--readout-surface);
  backdrop-filter: blur(12px);
}

.viewer-readout > div {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  border-right: 1px solid var(--line);
}

.readout-label {
  color: var(--faint);
  font: 0.6rem/1 var(--mono);
  letter-spacing: 0.08em;
}

.viewer-readout strong {
  overflow: hidden;
  font-size: 0.77rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loading-state {
  position: absolute;
  z-index: 10;
  inset: 0 382px 0 0;
  display: grid;
  place-content: center;
  gap: 12px;
  color: var(--muted);
  background: var(--loading-surface);
  transition: opacity 220ms ease, visibility 220ms ease;
  font: 0.68rem/1 var(--mono);
  letter-spacing: 0.1em;
}

.loading-rule {
  width: 180px;
  height: 2px;
  overflow: hidden;
  background: var(--line);
}

.loading-rule i {
  width: 0;
  height: 100%;
  display: block;
  background: var(--accent);
  transition: width 180ms ease;
}

.loading-state.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.loading-state.is-error {
  color: #ff9c88;
}

.control-panel {
  position: absolute;
  z-index: 12;
  inset: 0 0 0 auto;
  width: 382px;
  overflow: auto;
  padding: 20px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(22px);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.control-section + .control-section {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.section-kicker {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-kicker span {
  color: var(--accent);
  font: 600 0.58rem/1 var(--mono);
  letter-spacing: 0.16em;
}

.section-kicker strong {
  font: 650 0.95rem/1 var(--display);
  letter-spacing: 0.04em;
}

.scene-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.scene-button,
.part-button,
.color-button {
  border: 1px solid var(--line);
  background: var(--button-surface);
  cursor: pointer;
}

.scene-button {
  min-height: 62px;
  padding: 11px 12px;
  border-radius: 9px;
  text-align: left;
}

.scene-button span,
.scene-button small {
  display: block;
}

.scene-button span {
  font: 650 0.87rem/1.2 var(--sans);
}

.scene-button small {
  margin-top: 5px;
  color: var(--faint);
  font: 0.55rem/1 var(--mono);
  letter-spacing: 0.08em;
}

.scene-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(239, 91, 63, 0.12);
}

.part-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.part-button {
  min-width: 0;
  min-height: 50px;
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 7px;
  text-align: left;
}

.part-button::before {
  width: 5px;
  height: 5px;
  content: "";
  border-radius: 50%;
  background: var(--part-color, var(--khaki));
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05);
}

.part-button-copy {
  min-width: 0;
}

.part-name,
.part-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.part-name {
  font-size: 0.75rem;
  font-weight: 620;
}

.part-meta {
  margin-top: 3px;
  color: var(--faint);
  font: 0.48rem/1 var(--mono);
  letter-spacing: 0.05em;
}

.part-button-index {
  color: var(--faint);
  font: 0.5rem/1 var(--mono);
}

.part-button[aria-pressed="true"] {
  border-color: var(--signal);
  background: var(--button-selected);
}

.color-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.scope-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card-surface);
}

.scope-controls[hidden] {
  display: none;
}

.scope-controls button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.7rem;
}

.scope-controls button[aria-pressed="true"] {
  color: var(--ink);
  background: var(--button-selected);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.color-button {
  overflow: hidden;
  padding: 0;
  border-radius: 9px;
  text-align: left;
}

.color-slab {
  height: 52px;
  display: block;
  border-bottom: 1px solid var(--line);
}

.color-copy {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
}

.color-name,
.color-finish {
  display: block;
}

.color-name {
  font-size: 0.75rem;
  font-weight: 650;
}

.color-finish {
  margin-top: 3px;
  color: var(--faint);
  font-size: 0.58rem;
}

.status-tag {
  color: var(--signal);
  font: 0.48rem/1 var(--mono);
  white-space: nowrap;
}

.status-tag--pending {
  color: var(--pending);
}

.color-button[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--panel-solid), 0 0 0 3px var(--ink);
}

.palette-note {
  margin: 11px 0 0;
  color: var(--faint);
  font-size: 0.63rem;
  line-height: 1.6;
}

.selection-card {
  min-height: 74px;
  display: flex;
  align-items: center;
  gap: 13px;
  margin-top: 20px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-surface);
}

.selection-chip {
  width: 43px;
  height: 43px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 50%;
  box-shadow: inset 0 0 0 3px rgba(5, 13, 11, 0.16);
}

.selection-value,
.selection-note {
  margin: 0;
}

.selection-value {
  margin-top: 5px;
  font-size: 0.83rem;
  font-weight: 650;
}

.selection-note {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.61rem;
}

@media (max-width: 1040px) {
  .control-panel {
    width: 340px;
  }

  #viewer,
  .viewer-stage::before,
  .loading-state {
    right: 340px;
  }

  #viewer {
    width: calc(100% - 340px);
  }

  .viewer-actions,
  .source-mark {
    right: 360px;
  }

  .viewer-readout {
    right: 340px;
  }
}

@media (max-width: 820px) {
  :root {
    --mobile-topbar-height: 62px;
  }

  body {
    overflow: auto;
  }

  .topbar {
    height: var(--mobile-topbar-height);
    padding: 0 14px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-lockup h1 {
    font-size: 1.25rem;
  }

  .release-stamp {
    padding: 7px 9px;
    font-size: 0.56rem;
  }

  .studio-shell {
    position: relative;
    inset: auto;
    height: auto;
    min-height: 100vh;
    padding-top: var(--mobile-topbar-height);
  }

  .viewer-panel {
    position: sticky;
    inset: auto;
    top: var(--mobile-topbar-height);
    z-index: 13;
    background:
      radial-gradient(90% 120% at 45% 48%, var(--body-glow), transparent 68%),
      linear-gradient(145deg, var(--bg) 0%, var(--bg-deep) 100%);
  }

  .viewer-stage {
    position: relative;
    inset: auto;
    height: clamp(320px, 52vh, 440px);
    height: clamp(320px, 52svh, 440px);
    min-height: 0;
  }

  #viewer,
  .viewer-stage::before,
  .loading-state {
    inset: 0;
  }

  #viewer {
    width: 100%;
    height: 100%;
  }

  .viewer-title-block {
    top: 20px;
    left: 16px;
  }

  .viewer-title-block h2 {
    font-size: 2.75rem;
  }

  .viewer-title-block p:last-child {
    margin-top: 8px;
    font-size: 0.68rem;
  }

  .viewer-actions {
    top: 18px;
    right: 14px;
    flex-direction: column;
    align-items: end;
  }

  .viewer-hint {
    bottom: 66px;
    left: 16px;
  }

  .source-mark {
    right: 16px;
    bottom: 66px;
  }

  .viewer-readout {
    right: 0;
    min-height: 54px;
  }

  .viewer-readout > div {
    display: block;
    padding: 10px 12px;
  }

  .viewer-readout strong {
    display: block;
    margin-top: 5px;
    font-size: 0.68rem;
  }

  .control-panel {
    position: relative;
    z-index: 1;
    inset: auto;
    width: 100%;
    max-height: none;
    padding: 20px 16px 32px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .part-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 430px) {
  .utility-label {
    font-size: 0.56rem;
  }

  .brand-lockup {
    gap: 9px;
  }

  .brand-lockup h1 {
    font-size: 1.08rem;
  }

  .release-stamp {
    gap: 5px;
    padding: 6px 8px;
    letter-spacing: 0.08em;
  }

  .theme-toggle {
    width: 34px;
    justify-content: center;
    padding: 0;
    font-size: 0;
  }

  .viewer-title-block h2 {
    font-size: 2.25rem;
  }

  .quiet-button {
    width: 40px;
    justify-content: center;
    padding: 0;
    font-size: 0;
  }

  .quiet-button span {
    font-size: 1rem;
  }

  .viewer-hint {
    max-width: 58%;
    line-height: 1.35;
  }

  .part-list {
    grid-template-columns: 1fr 1fr;
  }
}

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