:root {
  --bg: #f3efe6;
  --panel: #fffdf8;
  --border: rgba(184, 134, 11, 0.22);
  --title: #2c2418;
  --text: #5a4e3c;
  --muted: #8a7a62;
  --gold: #b8860b;
  --gold-deep: #8f6a2a;
  --accent: #b8860b;
  --accent-soft: rgba(201, 148, 74, 0.16);
  --btn-from: #e2bc74;
  --btn-to: #c9944a;
  --ink: #3a3126;
  --display: "Songti SC", "Noto Serif SC", "STSong", "SimSun", serif;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.stars {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 420px at 12% -8%, rgba(226, 188, 116, 0.34), transparent 58%),
    radial-gradient(720px 380px at 96% 8%, rgba(143, 106, 42, 0.12), transparent 52%),
    linear-gradient(165deg, #faf6ee 0%, #f0e8d8 48%, #e7dfd0 100%);
  z-index: -2;
  pointer-events: none;
}

.bg-grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(184, 134, 11, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(184, 134, 11, 0.04) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, #000 35%, transparent 85%);
}

.top-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid rgba(201, 148, 74, 0.18);
  background: linear-gradient(180deg, #ffffff 0%, #fbf8f2 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
  flex: 0 0 auto;
  position: relative;
  z-index: 20;
  overflow: visible;
}

.link-back {
  color: var(--gold);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  height: 2rem;
  padding: 0 0.65rem 0 0.4rem;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  border-radius: 999px;
  border: 1px solid rgba(201, 148, 74, 0.28);
  background: #fff;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.link-back-arrow { font-size: 1.05rem; line-height: 1; }
.link-back:active { background: rgba(201, 148, 74, 0.12); }

.readout {
  text-align: center;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  position: relative;
}

.readout strong {
  font-family: var(--display);
  color: var(--title);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.readout .deg {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  color: var(--gold-deep);
  font: inherit;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  padding: 0.1rem 0.25rem 0.1rem 0.4rem;
  margin: 0;
  border-left: 1px solid rgba(201, 148, 74, 0.28);
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.2;
}

.readout .deg:hover,
.readout .deg:focus-visible {
  background: rgba(201, 148, 74, 0.12);
  outline: none;
}

.deg-pop {
  position: absolute;
  left: 50%;
  top: calc(100% + 0.45rem);
  transform: translateX(-50%);
  z-index: 40;
  min-width: 11.5rem;
  padding: 0.55rem 0.65rem 0.6rem;
  border-radius: 12px;
  background: #fffdf8;
  border: 1px solid rgba(201, 148, 74, 0.28);
  box-shadow: 0 10px 24px rgba(60, 45, 20, 0.14);
}

.deg-pop.hidden { display: none; }

.deg-pop-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.deg-pop-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.deg-input {
  width: 4.2rem;
  border: 1px solid rgba(201, 148, 74, 0.3);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  color: var(--title);
  background: #fff;
}

.deg-input:focus {
  outline: none;
  border-color: var(--gold);
}

.deg-unit {
  color: var(--muted);
  font-size: 0.8rem;
}

.deg-ok {
  margin-left: 0.15rem;
}

.tool-field-sit input[type="range"] {
  width: 110px;
}

.sit-nudge {
  min-width: 1.7rem;
  padding: 0.2rem 0.45rem;
  font-size: 0.85rem;
  line-height: 1;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.92), rgba(250, 245, 235, 0.88));
  border-bottom: 1px solid rgba(201, 148, 74, 0.14);
  flex: 0 0 auto;
}

.toolbar-actions,
.toolbar-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  color: var(--text);
  border-color: rgba(201, 148, 74, 0.28);
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(180deg, var(--btn-from), var(--btn-to));
  box-shadow: 0 6px 16px rgba(201, 148, 74, 0.28);
}

.btn.primary:not(:disabled):active {
  transform: translateY(1px);
}

.btn.soft {
  background: var(--accent-soft);
  border-color: rgba(201, 148, 74, 0.22);
  color: var(--gold-deep);
}

.btn.chip {
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  background: #fff;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.tool-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.55rem 0.28rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(201, 148, 74, 0.16);
  font-size: 0.72rem;
  color: var(--muted);
}

.tool-field span {
  min-width: 1.6em;
  font-weight: 600;
  color: var(--gold-deep);
}

.tool-field input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 92px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(226, 188, 116, 0.55), rgba(201, 148, 74, 0.85));
  outline: none;
}

.tool-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--gold);
  box-shadow: 0 1px 4px rgba(143, 106, 42, 0.25);
  cursor: pointer;
}

.tool-field input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--gold);
  cursor: pointer;
}

.tool-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(201, 148, 74, 0.16);
  font-size: 0.72rem;
  color: var(--gold-deep);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.tool-check input {
  accent-color: var(--gold);
  width: 0.9rem;
  height: 0.9rem;
}

.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.65rem 0.75rem 0.85rem;
}

.stage {
  position: relative;
  height: 100%;
  border-radius: 20px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 78% 62% at 50% 42%, rgba(255, 255, 255, 0.95), rgba(219, 235, 249, 0.8) 58%, rgba(186, 214, 240, 0.6)),
    linear-gradient(165deg, #ecf4fb, #cfe3f4);
  border: 1px solid rgba(120, 160, 200, 0.25);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 14px 36px rgba(60, 90, 130, 0.12);
}

.stage-frame {
  position: absolute;
  inset: 10px;
  border-radius: 14px;
  border: 1px solid rgba(184, 134, 11, 0.12);
  pointer-events: none;
  z-index: 1;
}

#view3d {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  position: relative;
  z-index: 0;
}

.empty-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.25rem 1rem;
  z-index: 2;
  background:
    radial-gradient(ellipse 55% 45% at 50% 38%, rgba(255, 252, 245, 0.55), transparent 70%);
}

.empty-panel.is-hidden {
  display: none;
}

.empty-hero {
  width: min(380px, 100%);
  text-align: center;
  animation: heroIn 0.55s ease both;
}

@keyframes heroIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty-art {
  margin: 0 auto 0.85rem;
  width: min(260px, 78vw);
}

.iso-house {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 10px 18px rgba(120, 90, 40, 0.12));
}

.iso-roof,
.iso-wall-l,
.iso-wall-r,
.iso-floor {
  transform-origin: 140px 100px;
  animation: floatHouse 4.8s ease-in-out infinite;
}

.iso-scan {
  stroke-dasharray: 140;
  stroke-dashoffset: 140;
  animation: scanDraw 2.8s ease-in-out infinite;
}

.iso-dot {
  animation: pulseDot 2.4s ease-in-out infinite;
}
.iso-dot.d2 { animation-delay: 0.35s; }
.iso-dot.d3 { animation-delay: 0.7s; }

@keyframes floatHouse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes scanDraw {
  0% { stroke-dashoffset: 140; opacity: 0.2; }
  35% { stroke-dashoffset: 0; opacity: 1; }
  70% { stroke-dashoffset: 0; opacity: 0.85; }
  100% { stroke-dashoffset: -40; opacity: 0.15; }
}

@keyframes pulseDot {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.25); }
}

.empty-kicker {
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  color: var(--gold-deep);
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.empty-title {
  font-family: var(--display);
  color: var(--title);
  font-size: clamp(1.25rem, 4.5vw, 1.55rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 0.55rem;
}

.empty-desc {
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--muted);
  margin: 0 auto 1.15rem;
  max-width: 18.5rem;
}

.empty-upload {
  min-width: 9.5rem;
  padding: 0.62rem 1.35rem;
  font-size: 0.88rem;
}

.stage-hint {
  position: absolute;
  left: 50%;
  bottom: 0.85rem;
  transform: translateX(-50%);
  z-index: 3;
  margin: 0;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 252, 245, 0.72);
  border: 1px solid rgba(201, 148, 74, 0.18);
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  pointer-events: none;
}

.stage-hint[hidden] { display: none !important; }

.status-toast {
  position: absolute;
  left: 50%;
  bottom: 2.4rem;
  transform: translateX(-50%);
  z-index: 4;
  padding: 0.48rem 0.95rem;
  border-radius: 999px;
  background: rgba(44, 36, 24, 0.86);
  color: #f8f1e4;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  pointer-events: none;
  white-space: nowrap;
  animation: toastIn 0.22s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.help-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(40, 32, 20, 0.42);
  display: grid;
  place-items: center;
  padding: 1rem;
  backdrop-filter: blur(3px);
}

.help-mask.hidden { display: none; }

.help-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, #fffdf8, #faf4e8);
  border-radius: 16px;
  padding: 1.2rem 1.2rem 1.05rem;
  border: 1px solid rgba(201, 148, 74, 0.22);
  box-shadow: 0 18px 40px rgba(60, 45, 20, 0.18);
}

.help-card h2 {
  font-family: var(--display);
  font-size: 1.05rem;
  color: var(--title);
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}

.help-card ul {
  padding-left: 1.1rem;
  margin-bottom: 0.8rem;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text);
}

.help-note {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 0.95rem;
}

.help-card .btn {
  width: 100%;
}

@media (max-width: 640px) {
  .toolbar { padding: 0.5rem 0.55rem; gap: 0.5rem; }
  .tool-field input[type="range"] { width: 76px; }
  .stage-wrap { padding: 0.45rem 0.5rem 0.65rem; }
  .stage { border-radius: 16px; }
  .empty-desc br { display: none; }
}
