:root {
  --material-accent-rgb: 213, 163, 97;
  --material-highlight-rgb: 213, 163, 97;
  --material-panel-rgb: 12, 15, 20;
  color-scheme: dark;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #070a0e;
  color: #f1f3f5;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #070a0e;
}

body {
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  color: inherit;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  isolation: isolate;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  background: #070a0e;
  cursor: grab;
  touch-action: none;
}

#scene:active {
  cursor: grabbing;
}

.intro-overlay {
  --veil-opacity: 1;
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: rgba(7, 10, 14, var(--veil-opacity));
  opacity: 1;
  user-select: none;
  touch-action: none;
}

.intro-overlay[hidden] {
  display: none;
}

.intro-overlay.is-skipping {
  transition: opacity 250ms ease-out;
}

.intro-grain {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #c9975b;
  box-shadow:
    0 0 10px rgba(201, 151, 91, 0.22),
    0 0 28px rgba(201, 151, 91, 0.08);
  opacity: 0.18;
  transform: translate(-50%, -50%);
  animation: introGrainBreath 4.8s ease-in-out infinite;
}

@keyframes introGrainBreath {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(0.86);
    box-shadow:
      0 0 8px rgba(201, 151, 91, 0.16),
      0 0 22px rgba(201, 151, 91, 0.05);
  }

  50% {
    transform: translate(-50%, -50%) scale(1.08);
    box-shadow:
      0 0 12px rgba(201, 151, 91, 0.24),
      0 0 34px rgba(201, 151, 91, 0.09);
  }
}

.intro-copy {
  position: relative;
  width: min(92vw, 900px);
  min-height: 1.5em;
  color: rgba(242, 238, 229, 0.94);
  font-family: "Sha Intro", "Kaiti SC", "STKaiti", "KaiTi", serif;
  font-size: clamp(27px, 4.2vw, 48px);
  font-weight: 400;
  letter-spacing: 0.14em;
  line-height: 1.45;
  text-align: center;
  text-shadow: 0 4px 36px rgba(0, 0, 0, 0.82);
}

.intro-line {
  position: absolute;
  inset: 50% auto auto 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.9em, 4vw, 1.8em);
  width: max-content;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

.intro-overlay.is-reduced .intro-line:first-child {
  transform: translate(-50%, calc(-50% - 0.78em));
}

.intro-overlay.is-reduced .intro-line:nth-child(2) {
  transform: translate(-50%, calc(-50% + 0.78em));
}

.intro-phrase {
  display: inline-block;
  opacity: 0;
  will-change: opacity, filter, transform;
}

.brand,
.status,
.panel,
.technical-note,
.gesture-hint {
  transition: opacity 900ms ease;
}

body.intro-active .brand,
body.intro-active .status,
body.intro-active .panel,
body.intro-active .technical-note,
body.intro-active .gesture-hint {
  opacity: 0;
}

body.intro-active.intro-show-title .brand {
  opacity: 1;
}

body.intro-active.intro-show-controls .status,
body.intro-active.intro-show-controls .panel,
body.intro-active.intro-show-controls .technical-note,
body.intro-active.intro-show-controls .gesture-hint {
  opacity: 1;
}

body.intro-active .panel {
  pointer-events: none;
}

body.intro-active.intro-show-controls .panel {
  pointer-events: auto;
}

.topbar {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  pointer-events: none;
}

.brand {
  pointer-events: auto;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.75);
}

.eyebrow {
  margin: 0 0 4px;
  color: rgb(var(--material-accent-rgb));
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 34px);
  font-weight: 520;
  letter-spacing: -0.025em;
}

.subtitle {
  margin: 6px 0 0;
  color: rgba(241, 243, 245, 0.68);
  font-size: 13px;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: rgba(var(--material-panel-rgb), 0.62);
  color: rgba(241, 243, 245, 0.72);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(14px);
  pointer-events: auto;
}

.status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #72c89a;
  box-shadow: 0 0 12px rgba(114, 200, 154, 0.65);
}

.panel {
  position: absolute;
  z-index: 4;
  top: 118px;
  left: 24px;
  width: min(330px, calc(100vw - 48px));
  max-height: calc(100vh - 210px);
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(var(--material-panel-rgb), 0.72);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.material-selector {
  display: flex;
  align-items: center;
  min-width: 0;
  margin: -3px 0 17px;
  padding-bottom: 13px;
  overflow-x: auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  color: rgba(241, 243, 245, 0.46);
  font-size: 12px;
  scrollbar-width: none;
  white-space: nowrap;
}

.material-selector::-webkit-scrollbar {
  display: none;
}

.material-selector-title,
.material-selector-divider {
  flex: 0 0 auto;
}

.material-selector-title {
  color: rgba(241, 243, 245, 0.64);
  letter-spacing: 0.08em;
}

.material-selector-divider {
  margin: 0 5px 0 3px;
  color: rgba(var(--material-accent-rgb), 0.5);
}

.material-options {
  display: inline-flex;
  align-items: center;
  min-width: max-content;
}

.material-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.material-option + .material-option::before {
  content: "·";
  margin: 0 5px;
  color: rgba(241, 243, 245, 0.28);
}

.material-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.material-option-label {
  padding: 3px 2px;
  border-radius: 4px;
  color: rgba(241, 243, 245, 0.48);
  transition: color 160ms ease, text-shadow 160ms ease;
}

.material-option:hover .material-option-label {
  color: rgba(241, 243, 245, 0.78);
}

.material-option input:checked + .material-option-label {
  color: #f1f3f5;
  text-shadow:
    0 0 18px rgba(var(--material-accent-rgb), 0.18);
}

.material-option input:focus-visible + .material-option-label {
  outline: 2px solid rgba(var(--material-accent-rgb), 0.78);
  outline-offset: 3px;
}

.control {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.control:last-child {
  margin-bottom: 0;
}

.control-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: rgba(241, 243, 245, 0.76);
  font-size: 12px;
}

output {
  color: #f1f3f5;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: rgb(var(--material-accent-rgb));
}

select,
.button {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.065);
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

select {
  width: 100%;
  padding: 0 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  cursor: pointer;
}

.button:hover {
  border-color: rgba(var(--material-highlight-rgb), 0.54);
  background: rgba(var(--material-highlight-rgb), 0.11);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid rgb(var(--material-accent-rgb));
  outline-offset: 2px;
}

.button.primary {
  border-color: rgba(var(--material-accent-rgb), 0.52);
  background: rgba(var(--material-accent-rgb), 0.17);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 4px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 3px 0 16px;
  color: rgba(241, 243, 245, 0.76);
  font-size: 12px;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 38px;
  height: 22px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-track {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  transition: background 150ms ease, border-color 150ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(241, 243, 245, 0.82);
  transition: transform 150ms ease, background 150ms ease;
}

.switch input:checked + .switch-track {
  border-color: rgba(var(--material-accent-rgb), 0.7);
  background: rgba(var(--material-accent-rgb), 0.46);
}

.switch input:checked + .switch-track::after {
  transform: translateX(16px);
  background: #ffffff;
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid rgb(var(--material-accent-rgb));
  outline-offset: 2px;
}

details {
  margin-top: 15px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: rgba(241, 243, 245, 0.8);
  font-size: 12px;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "＋";
  color: rgb(var(--material-accent-rgb));
  font-size: 15px;
}

details[open] summary::after {
  content: "－";
}

.advanced {
  display: grid;
  gap: 16px;
  padding-top: 17px;
}

.advanced .control {
  margin: 0;
}

.hint {
  margin: 8px 0 0;
  color: rgba(241, 243, 245, 0.49);
  font-size: 11px;
  line-height: 1.55;
}

.warning {
  display: none;
  margin: 4px 0 12px;
  padding: 9px 10px;
  border-left: 2px solid rgb(var(--material-accent-rgb));
  background: rgba(var(--material-accent-rgb), 0.08);
  color: rgba(241, 243, 245, 0.7);
  font-size: 11px;
  line-height: 1.5;
}

.warning.visible {
  display: block;
}

.gesture-hint {
  position: absolute;
  z-index: 2;
  right: 24px;
  bottom: 22px;
  max-width: calc(100vw - 48px);
  color: rgba(241, 243, 245, 0.52);
  font-size: 11px;
  letter-spacing: 0.02em;
  text-align: right;
  text-shadow: 0 2px 14px #000;
  pointer-events: none;
}

.technical-note {
  position: absolute;
  z-index: 2;
  left: 24px;
  bottom: 22px;
  max-width: min(600px, calc(100vw - 48px));
  margin: 0;
  color: rgba(241, 243, 245, 0.46);
  font-size: 11px;
  line-height: 1.6;
  text-shadow: 0 2px 14px #000;
  pointer-events: none;
}

.error {
  position: absolute;
  z-index: 10;
  inset: 50% auto auto 50%;
  display: none;
  width: min(480px, calc(100vw - 48px));
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  background: rgba(var(--material-panel-rgb), 0.95);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
}

.error.visible {
  display: block;
}

.error h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 550;
}

.error p {
  margin: 0;
  color: rgba(241, 243, 245, 0.66);
  font-size: 13px;
  line-height: 1.65;
}

@media (max-width: 720px) {
  .intro-copy {
    width: calc(100vw - 32px);
    font-size: clamp(25px, 8vw, 36px);
    letter-spacing: 0.1em;
  }

  .intro-line {
    gap: 0.8em;
  }

  .topbar {
    padding: 17px;
  }

  .subtitle {
    display: none;
  }

  .status {
    padding: 6px 9px;
  }

  .panel {
    top: auto;
    bottom: 82px;
    left: 16px;
    width: min(310px, calc(100vw - 32px));
    max-height: 46vh;
    padding: 14px;
  }

  .gesture-hint {
    display: none;
  }

  .technical-note {
    left: 16px;
    bottom: 14px;
    max-width: calc(100vw - 32px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }

  .intro-phrase {
    filter: none !important;
    transform: none !important;
  }

  .intro-grain {
    animation: none;
  }
}
