:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  --stage: #050505;
  --ink: #eeede8;
  --soft: rgba(238, 237, 232, 0.62);
  --muted: rgba(238, 237, 232, 0.36);
  --line: rgba(238, 237, 232, 0.12);
  --listen: #78d7ad;
  --focus: #b9d6e4;
  --photo-aspect: 1.5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--stage);
}

button, input, textarea { font: inherit; }

button, .upload-action, .brand { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible,
.upload-action:focus-within,
.brand:focus-visible {
  outline: 1px solid var(--focus);
  outline-offset: 4px;
}

.lab-shell {
  width: min(1520px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: 22px clamp(18px, 3.6vw, 58px) max(20px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 14px;
}

.lab-header {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.16em;
}

.brand {
  color: var(--ink);
  text-decoration: none;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-size: 18px;
  letter-spacing: 0.24em;
}

.lab-id { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.lab-id i { width: 2px; height: 2px; border-radius: 50%; background: currentColor; }
.lab-nav { display: flex; align-items: center; gap: 18px; }
.lab-nav > a { color: var(--focus); text-decoration: none; }
.lab-nav > a:hover { color: var(--ink); }

.experience {
  position: relative;
  min-height: min(720px, calc(100svh - 172px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: clamp(20px, 3vw, 48px);
}

.stage-copy {
  position: absolute;
  top: clamp(22px, 6vh, 68px);
  left: 0;
  z-index: 4;
  max-width: 410px;
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--soft);
  font-size: 10px;
  letter-spacing: 0.24em;
}

.stage-copy h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-size: clamp(25px, 3vw, 46px);
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: -0.045em;
}

.stage-copy h1 span { color: rgba(238, 237, 232, 0.42); }

.viewer {
  position: relative;
  min-width: 0;
  min-height: 560px;
  display: grid;
  place-items: center;
  isolation: isolate;
}

.field-aura {
  position: absolute;
  width: min(68vw, 850px);
  aspect-ratio: 1.2;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(218, 230, 233, 0.055), rgba(26, 27, 28, 0.025) 46%, transparent 72%);
  filter: blur(34px);
  pointer-events: none;
}

.photo-portal {
  position: relative;
  width: min(74vw, 890px);
  max-width: calc(100% - 56px);
  aspect-ratio: var(--photo-aspect);
  max-height: min(68svh, 640px);
  overflow: visible;
  background: transparent;
  touch-action: none;
  cursor: grab;
}

.photo-portal.is-orbiting { cursor: grabbing; }

#spatial-canvas,
#fallback-image {
  display: block;
  width: 100%;
  height: 100%;
}

#fallback-image {
  object-fit: contain;
  -webkit-mask-image: radial-gradient(ellipse 75% 70% at 50% 50%, #000 52%, transparent 100%);
  mask-image: radial-gradient(ellipse 75% 70% at 50% 50%, #000 52%, transparent 100%);
}

.portal-vignette {
  position: absolute;
  inset: -1px;
  pointer-events: none;
  background:
    linear-gradient(90deg, var(--stage), transparent 8%, transparent 92%, var(--stage)),
    linear-gradient(0deg, var(--stage), transparent 9%, transparent 91%, var(--stage));
  opacity: 0.23;
  mix-blend-mode: multiply;
}

.phase-readout {
  position: absolute;
  left: 0;
  bottom: clamp(18px, 5vh, 52px);
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--muted);
  z-index: 4;
}

.phase-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--soft);
  box-shadow: 0 0 0 5px rgba(238, 237, 232, 0.04);
  transition: background 220ms ease, box-shadow 220ms ease;
}

.viewer.is-listening .phase-dot {
  background: var(--listen);
  box-shadow: 0 0 0 calc(5px + var(--audio-level, 0) * 9px) rgba(120, 215, 173, 0.09);
}

.phase-readout div { display: grid; gap: 3px; }
.phase-readout b { color: var(--ink); font-size: 11px; font-weight: 500; letter-spacing: 0.12em; }
.phase-readout small { font-size: 9px; letter-spacing: 0.05em; }

.pointer-hint {
  position: absolute;
  right: 0;
  bottom: clamp(18px, 5vh, 52px);
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.08em;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 400ms ease, transform 400ms ease;
}

.viewer.is-settled .pointer-hint { opacity: 1; transform: none; }

.orbit-control {
  position: absolute;
  top: clamp(18px, 5vh, 54px);
  right: 0;
  z-index: 5;
  min-height: 34px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 0 0 7px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--soft);
  background: transparent;
  cursor: pointer;
}

.orbit-control span { font-size: 16px; line-height: 1; }
.orbit-control b { font-size: 9px; font-weight: 500; letter-spacing: 0.1em; }
.orbit-control output { min-width: 28px; color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }

.lab-rail {
  align-self: center;
  min-width: 0;
  display: grid;
  gap: 16px;
  padding-left: 24px;
  border-left: 1px solid var(--line);
}

.dialogue-panel { display: grid; gap: 14px; }

.dialogue-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

.dialogue-head div { display: grid; gap: 6px; }
.dialogue-head span { color: var(--focus); font-size: 8px; letter-spacing: 0.21em; }
.dialogue-head b { font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif; font-size: 17px; font-weight: 400; letter-spacing: 0.04em; }
.dialogue-head output { color: var(--soft); font-size: 10px; font-variant-numeric: tabular-nums; letter-spacing: 0.08em; }

.rebuild-meter { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.rebuild-meter i { height: 1px; background: rgba(238, 237, 232, 0.14); transition: background 800ms ease, box-shadow 800ms ease; }
.rebuild-meter i.is-filled { background: var(--focus); box-shadow: 0 0 12px rgba(185, 214, 228, 0.28); }

.dialogue-log {
  min-height: 188px;
  max-height: 250px;
  padding: 12px 4px 2px 0;
  display: grid;
  align-content: start;
  gap: 15px;
  overflow-y: auto;
  scrollbar-width: thin;
  border-top: 1px solid rgba(238, 237, 232, 0.07);
}

.dialogue-message { display: grid; gap: 5px; animation: dialogue-in 420ms ease both; }
.dialogue-message span { color: var(--muted); font-size: 8px; letter-spacing: 0.14em; }
.dialogue-message p { margin: 0; color: var(--soft); font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif; font-size: 13px; line-height: 1.62; }
.dialogue-message--user { padding-left: 24px; }
.dialogue-message--user span, .dialogue-message--user p { color: rgba(238, 237, 232, 0.46); }
.dialogue-message--focus p { color: var(--ink); }

@keyframes dialogue-in {
  from { opacity: 0; transform: translateY(5px); }
}

.start-dialogue,
.dialogue-form button {
  min-height: 43px;
  border: 0;
  padding: 0 13px;
  color: #090909;
  background: var(--ink);
  cursor: pointer;
  transition: opacity 180ms ease, background 180ms ease;
}

.start-dialogue:disabled,
.dialogue-form button:disabled { opacity: 0.35; cursor: wait; }

.dialogue-form { display: grid; gap: 9px; }
.dialogue-form label { color: var(--muted); font-size: 8px; letter-spacing: 0.12em; }
.dialogue-form textarea {
  width: 100%;
  min-height: 68px;
  resize: vertical;
  border: 1px solid rgba(238, 237, 232, 0.15);
  border-radius: 0;
  padding: 10px 11px;
  color: var(--ink);
  background: rgba(238, 237, 232, 0.025);
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  font-size: 12px;
  line-height: 1.55;
}

.dialogue-form textarea::placeholder { color: rgba(238, 237, 232, 0.24); }
.dialogue-form button { display: flex; align-items: center; justify-content: space-between; }
.dialogue-status { min-height: 14px; margin: 0; color: var(--muted); font-size: 8px; line-height: 1.55; letter-spacing: 0.06em; }

.tuning-disclosure { border-top: 1px solid var(--line); }
.tuning-disclosure summary {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.08em;
  cursor: pointer;
  list-style: none;
}
.tuning-disclosure summary::-webkit-details-marker { display: none; }
.tuning-disclosure summary::after { content: "+"; margin-left: auto; color: var(--soft); font-size: 13px; }
.tuning-disclosure[open] summary::after { content: "−"; }
.tuning-disclosure summary span { margin-right: 10px; color: rgba(238, 237, 232, 0.22); }

.tuning {
  display: grid;
  gap: 17px;
  padding: 12px 0 16px;
}

.tuning-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  padding-bottom: 4px;
}

.tuning-head div { display: grid; gap: 5px; }
.tuning-head span { color: var(--muted); font-size: 8px; letter-spacing: 0.2em; }
.tuning-head b { font-size: 11px; font-weight: 500; letter-spacing: 0.1em; }
.tuning-head output { color: var(--muted); font-size: 9px; letter-spacing: 0.08em; }

.field-control { display: grid; gap: 8px; }
.field-control > span { display: flex; justify-content: space-between; color: var(--soft); font-size: 9px; letter-spacing: 0.08em; }
.field-control output { color: var(--muted); font-variant-numeric: tabular-nums; }

.field-control--signature > span { color: var(--ink); }
.field-control--signature input::-webkit-slider-runnable-track { background: rgba(185, 214, 228, 0.52); }
.field-control--signature input::-webkit-slider-thumb { background: var(--focus); box-shadow: 0 0 0 4px rgba(185, 214, 228, 0.08); }
.field-control--signature input::-moz-range-track { background: rgba(185, 214, 228, 0.52); }
.field-control--signature input::-moz-range-thumb { background: var(--focus); box-shadow: 0 0 0 4px rgba(185, 214, 228, 0.08); }

.field-control input {
  width: 100%;
  height: 12px;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.field-control input::-webkit-slider-runnable-track { height: 1px; background: rgba(238, 237, 232, 0.24); }
.field-control input::-webkit-slider-thumb { width: 8px; height: 8px; margin-top: -3.5px; appearance: none; border: 0; border-radius: 50%; background: var(--ink); }
.field-control input::-moz-range-track { height: 1px; background: rgba(238, 237, 232, 0.24); }
.field-control input::-moz-range-thumb { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--ink); }

.tuning-note {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.6;
}

.control-dock {
  min-height: 60px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.primary-action,
.audio-action,
.compare-action,
.upload-action {
  min-height: 48px;
  border: 0;
  border-radius: 0;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--soft);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color 180ms ease, background 180ms ease;
}

.primary-action { color: var(--ink); background: rgba(238, 237, 232, 0.075); }
.primary-action span { font-size: 16px; line-height: 1; }
.audio-action[aria-pressed="true"] { color: var(--listen); background: rgba(120, 215, 173, 0.055); }
.compare-action[aria-pressed="true"] { color: var(--ink); background: rgba(238, 237, 232, 0.075); }
.upload-action { position: relative; }
.upload-action input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.audio-glyph { height: 12px; display: inline-flex; align-items: center; gap: 2px; }
.audio-glyph i { width: 1px; height: 5px; display: block; background: currentColor; transition: height 120ms ease; }
.audio-glyph i:nth-child(2) { height: 10px; }
.audio-action[aria-pressed="true"] .audio-glyph i:nth-child(1) { height: calc(5px + var(--audio-level, 0) * 7px); }
.audio-action[aria-pressed="true"] .audio-glyph i:nth-child(2) { height: calc(8px + var(--audio-level, 0) * 6px); }
.audio-action[aria-pressed="true"] .audio-glyph i:nth-child(3) { height: calc(4px + var(--audio-level, 0) * 9px); }

.method-note {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  color: rgba(238, 237, 232, 0.28);
  font-size: 8px;
  letter-spacing: 0.06em;
}

@media (hover: hover) {
  .primary-action:hover,
  .audio-action:hover,
  .compare-action:hover,
  .upload-action:hover { color: var(--ink); background: rgba(238, 237, 232, 0.055); }
  .orbit-control:hover { color: var(--ink); }
  .start-dialogue:hover, .dialogue-form button:hover { background: #fff; }
}

@media (max-width: 920px) {
  .lab-shell { grid-template-rows: auto auto auto auto; }
  .experience { min-height: auto; grid-template-columns: 1fr; gap: 8px; }
  .stage-copy { position: relative; top: auto; margin: 28px 0 2px; }
  .viewer { min-height: 520px; }
  .photo-portal { width: min(100%, 780px); max-width: 100%; }
  .lab-rail { padding: 18px 0 4px; border-left: 0; border-top: 1px solid var(--line); }
  .dialogue-panel { grid-template-columns: minmax(0, 1fr) minmax(240px, .72fr); column-gap: 24px; }
  .dialogue-head, .rebuild-meter, .dialogue-log { grid-column: 1; }
  .start-dialogue, .dialogue-form, .dialogue-status { grid-column: 2; }
  .start-dialogue, .dialogue-form { grid-row: 1 / span 3; align-self: end; }
  .dialogue-status { grid-row: 4; }
  .tuning-disclosure { margin-top: 4px; }
  .tuning {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 15px 18px;
    padding: 16px 0 4px;
  }
  .tuning-head, .tuning-note { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .lab-shell { padding: 17px 14px max(16px, env(safe-area-inset-bottom)); gap: 10px; }
  .lab-id span:first-child { display: none; }
  .stage-copy { margin-top: 22px; }
  .stage-copy h1 { font-size: clamp(26px, 8.6vw, 38px); }
  .viewer { min-height: 390px; }
  .photo-portal { width: calc(100% + 8px); max-width: calc(100% + 8px); }
  .orbit-control { top: 8px; right: 2px; }
  .phase-readout { left: 2px; bottom: 8px; }
  .pointer-hint { display: none; }
  .lab-rail { padding-top: 15px; }
  .dialogue-panel { grid-template-columns: 1fr; }
  .dialogue-head, .rebuild-meter, .dialogue-log, .start-dialogue, .dialogue-form, .dialogue-status { grid-column: 1; grid-row: auto; }
  .dialogue-log { min-height: 150px; max-height: 220px; }
  .tuning { grid-template-columns: 1fr 1fr; gap: 14px 18px; }
  .control-dock { grid-template-columns: 1fr 1fr; }
  .method-note { display: grid; gap: 5px; line-height: 1.45; }
}

@media (max-height: 760px) and (min-width: 921px) {
  .experience { min-height: 540px; }
  .viewer { min-height: 520px; }
  .stage-copy { top: 22px; }
  .photo-portal { max-height: 500px; }
  .lab-rail { gap: 11px; }
  .dialogue-log { min-height: 138px; max-height: 170px; }
  .tuning { gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .pointer-hint { display: none; }
  * { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
