:root {
  color-scheme: dark;
  --bg: #070b11;
  --panel: rgba(12, 19, 28, 0.88);
  --panel-strong: rgba(9, 15, 23, 0.96);
  --line: rgba(152, 180, 202, 0.18);
  --line-bright: rgba(176, 206, 228, 0.34);
  --text: #f2f7fa;
  --muted: #8fa2b1;
  --old: #ff9d42;
  --new: #31d3dd;
  --path: #f6de79;
  --success: #73e6b6;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell { width: 100%; height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: relative;
  z-index: 20;
  height: 76px;
  flex: 0 0 76px;
  display: grid;
  grid-template-columns: minmax(270px, 1fr) auto minmax(270px, 1fr);
  align-items: center;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 12, 18, 0.94);
  backdrop-filter: blur(18px);
}

.brand-block { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; position: relative; transform: rotate(45deg); }
.brand-mark span { position: absolute; display: block; border: 1px solid rgba(49, 211, 221, 0.62); }
.brand-mark span:nth-child(1) { inset: 3px; }
.brand-mark span:nth-child(2) { inset: 9px; border-color: rgba(246, 222, 121, 0.8); }
.brand-mark span:nth-child(3) { inset: 15px; background: var(--new); border: 0; box-shadow: 0 0 18px var(--new); }
.eyebrow, .panel-kicker, .loading-kicker { margin: 0; color: #6f8798; font-size: 9px; font-weight: 800; letter-spacing: .19em; }
.brand-block h1 { margin: 3px 0 0; font-size: 17px; line-height: 1.2; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }

.mode-switch {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.025);
}

.mode-button {
  min-width: 62px;
  height: 34px;
  padding: 0 13px;
  border: 0;
  border-radius: 6px;
  color: #91a3b1;
  background: transparent;
  cursor: pointer;
  transition: color .18s ease, background .18s ease, box-shadow .18s ease;
}
.mode-button:hover { color: #e7f0f5; background: rgba(255,255,255,.05); }
.mode-button.is-active { color: #071116; background: var(--new); box-shadow: 0 0 22px rgba(49,211,221,.2); font-weight: 700; }

.top-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }
.status-pill { height: 32px; display: flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; color: #9fb0bd; font-size: 12px; }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #f2bd5c; box-shadow: 0 0 10px #f2bd5c; }
.status-pill.is-ready i { background: var(--success); box-shadow: 0 0 10px var(--success); }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.025); cursor: pointer; }
.icon-button:hover { border-color: var(--line-bright); background: rgba(255,255,255,.06); }
.icon-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: square; }

.viewer-shell { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: radial-gradient(circle at 50% 35%, #182633 0%, #091019 46%, #05080d 100%); }
#sceneCanvas { display: block; width: 100%; height: 100%; outline: 0; cursor: grab; }
#sceneCanvas:active { cursor: grabbing; }

.loading-overlay { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: radial-gradient(circle at center, rgba(19,32,43,.96), rgba(5,9,14,.99)); transition: opacity .55s ease, visibility .55s ease; }
.loading-overlay.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-card { width: min(440px, calc(100vw - 38px)); padding: 38px 42px; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg, rgba(17,28,39,.96), rgba(8,14,22,.96)); box-shadow: var(--shadow); }
.loading-symbol { width: 42px; height: 42px; position: relative; margin-bottom: 24px; transform: rotate(45deg); }
.loading-symbol span { position: absolute; inset: 0; border: 1px solid rgba(49,211,221,.72); animation: loadingPulse 1.8s ease-in-out infinite; }
.loading-symbol span:nth-child(2) { inset: 8px; animation-delay: .18s; border-color: rgba(246,222,121,.85); }
.loading-symbol span:nth-child(3) { inset: 16px; animation-delay: .36s; background: var(--new); border: 0; }
@keyframes loadingPulse { 0%,100% { opacity: .25; transform: scale(.9); } 50% { opacity: 1; transform: scale(1.04); } }
.loading-card h2 { margin: 6px 0 5px; font-size: 25px; }
.loading-note { margin: 0 0 26px; color: var(--muted); font-size: 12px; }
.load-row { margin-top: 16px; }
.load-label { display: flex; justify-content: space-between; margin-bottom: 7px; color: #b2c0ca; font-size: 12px; }
.load-label b { color: var(--text); font-variant-numeric: tabular-nums; }
.progress-track { height: 3px; overflow: hidden; background: rgba(255,255,255,.09); }
.progress-track i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--new), #8af4e4); transition: width .18s linear; }
.load-row:first-of-type .progress-track i { background: linear-gradient(90deg, var(--old), #ffd56f); }
.loading-stage { margin: 22px 0 0; min-height: 18px; color: #688090; font-size: 11px; }

.view-label { position: absolute; z-index: 5; top: 22px; display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 7px; background: rgba(8,13,20,.72); backdrop-filter: blur(10px); pointer-events: none; transition: opacity .2s ease; }
.view-label--left { left: 22px; }
.view-label--right { left: calc(50% + 22px); }
.view-label small { display: block; color: #718797; font-size: 8px; font-weight: 800; letter-spacing: .16em; }
.view-label strong { display: block; margin-top: 2px; font-size: 12px; }
.label-dot { width: 8px; height: 8px; border-radius: 50%; }
.label-dot--old { background: var(--old); box-shadow: 0 0 12px var(--old); }
.label-dot--new { background: var(--new); box-shadow: 0 0 12px var(--new); }

.split-control { position: absolute; inset: 0; z-index: 8; display: none; pointer-events: none; }
.split-control.is-visible { display: block; }
.split-control input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; pointer-events: auto; }
.split-line { position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; background: rgba(255,255,255,.8); box-shadow: 0 0 18px rgba(255,255,255,.28); transform: translateX(-.5px); }
.split-line span { position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; display: grid; place-items: center; transform: translate(-50%,-50%); border: 1px solid rgba(255,255,255,.78); border-radius: 50%; color: #071016; background: #f7fbfd; font-weight: 900; box-shadow: 0 8px 24px rgba(0,0,0,.3); }

.legend-card { position: absolute; z-index: 6; left: 22px; bottom: 92px; width: 174px; padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); box-shadow: 0 14px 38px rgba(0,0,0,.22); backdrop-filter: blur(14px); }
.legend-row { display: flex; align-items: center; gap: 9px; margin-top: 9px; color: #bbc7d0; font-size: 11px; }
.swatch { width: 18px; height: 3px; border-radius: 2px; }
.swatch--old { background: var(--old); }
.swatch--new { background: var(--new); }
.swatch--path { height: 2px; background: var(--path); box-shadow: 0 0 8px rgba(246,222,121,.55); }
.gesture-help { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 8px; margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--line); color: #607786; font-size: 9px; }
.gesture-help span:last-child { grid-column: 1 / -1; }

.metrics-panel { position: absolute; z-index: 10; top: 20px; right: 20px; width: 326px; max-height: calc(100% - 112px); overflow: auto; padding: 20px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); box-shadow: var(--shadow); backdrop-filter: blur(18px); transition: transform .3s ease, opacity .3s ease; scrollbar-width: thin; }
.metrics-panel.is-collapsed { transform: translateX(calc(100% + 30px)); opacity: 0; pointer-events: none; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; }
.panel-heading h2 { margin: 5px 0 0; font-size: 19px; }
.panel-close { width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 6px; color: #8095a4; background: transparent; cursor: pointer; font-size: 18px; line-height: 1; }
.metric-comparison { margin-top: 18px; padding: 9px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metric-head, .metric-line { display: grid; grid-template-columns: 1.05fr .8fr .8fr; align-items: center; gap: 8px; min-height: 31px; }
.metric-head { color: #5f7585; font-size: 9px; letter-spacing: .08em; }
.metric-line span { color: #8499a8; font-size: 11px; }
.metric-line b { text-align: right; color: #e5edf2; font-size: 11px; font-variant-numeric: tabular-nums; }
.metric-line b:nth-child(2) { color: #d3a16f; }
.success { color: var(--success) !important; }
.result-callout { display: flex; align-items: center; gap: 15px; margin-top: 15px; padding: 14px; border: 1px solid rgba(49,211,221,.18); border-radius: 8px; background: linear-gradient(115deg, rgba(49,211,221,.12), rgba(49,211,221,.025)); }
.result-number { color: var(--new); font-size: 29px; font-weight: 750; letter-spacing: -.04em; white-space: nowrap; }
.result-number small { font-size: 14px; }
.result-callout strong, .result-callout span { display: block; }
.result-callout strong { font-size: 12px; }
.result-callout span { margin-top: 4px; color: #78909f; font-size: 9px; }
.result-callout .result-number > span { display: inline; margin: 0; color: inherit; font-size: inherit; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.detail-grid div { padding: 10px; border: 1px solid rgba(152,180,202,.1); border-radius: 7px; background: rgba(255,255,255,.018); }
.detail-grid span, .detail-grid strong { display: block; }
.detail-grid span { color: #6e8493; font-size: 9px; }
.detail-grid strong { margin-top: 5px; color: #d9e4ea; font-size: 10px; }
.scope-note { margin-top: 15px; padding-top: 13px; border-top: 1px solid var(--line); }
.scope-note span { color: #879baa; font-size: 10px; font-weight: 700; }
.scope-note p { margin: 7px 0 0; color: #687e8d; font-size: 9px; line-height: 1.65; }
.metrics-reopen { position: absolute; z-index: 9; top: 22px; right: 22px; display: none; height: 34px; padding: 0 13px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-strong); cursor: pointer; }
.metrics-reopen.is-visible { display: block; }

.view-toolbar { position: absolute; z-index: 12; left: 50%; bottom: 22px; display: flex; align-items: center; gap: 4px; transform: translateX(-50%); padding: 5px; border: 1px solid var(--line); border-radius: 9px; background: rgba(8,14,21,.9); box-shadow: 0 16px 40px rgba(0,0,0,.28); backdrop-filter: blur(16px); }
.toolbar-group { display: flex; gap: 2px; }
.tool-button { height: 31px; padding: 0 11px; border: 0; border-radius: 5px; color: #8599a8; background: transparent; cursor: pointer; font-size: 10px; white-space: nowrap; }
.tool-button:hover { color: #edf4f7; background: rgba(255,255,255,.055); }
.tool-button.is-active { color: #eaf9fa; background: rgba(49,211,221,.14); }
.tool-button--toggle span::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border: 1px solid #66808f; border-radius: 50%; }
.tool-button--toggle.is-active span::before { border-color: var(--new); background: var(--new); box-shadow: 0 0 8px var(--new); }
.toolbar-divider { width: 1px; height: 20px; margin: 0 3px; background: var(--line); }

.overlay-control { position: absolute; z-index: 9; left: 50%; bottom: 73px; display: flex; align-items: center; gap: 10px; min-width: 300px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; opacity: 0; transform: translate(-50%,8px); pointer-events: none; background: rgba(8,14,21,.9); transition: opacity .2s, transform .2s; }
.overlay-control.is-visible { opacity: 1; transform: translate(-50%,0); pointer-events: auto; }
.overlay-control span { color: #879aa8; font-size: 10px; white-space: nowrap; }
.overlay-control input { flex: 1; accent-color: var(--old); }
.overlay-control b { min-width: 30px; color: var(--old); font-size: 10px; }

.toast { position: absolute; z-index: 40; left: 50%; top: 20px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 7px; opacity: 0; transform: translate(-50%,-8px); color: #cdd9e0; background: var(--panel-strong); pointer-events: none; transition: .24s ease; font-size: 11px; }
.toast.is-visible { opacity: 1; transform: translate(-50%,0); }
.webgl-error { position: absolute; z-index: 50; inset: 0; padding-top: 18vh; text-align: center; background: #080d13; }
.webgl-error p { color: var(--muted); }

@media (max-width: 1100px) {
  .topbar { grid-template-columns: minmax(220px,1fr) auto auto; }
  .status-pill { display: none; }
  .metrics-panel { width: 292px; }
  .legend-card { display: none; }
}

@media (max-width: 820px) {
  .topbar { height: 112px; flex-basis: 112px; grid-template-columns: 1fr auto; grid-template-rows: 62px 50px; padding: 0 13px; }
  .mode-switch { grid-column: 1 / -1; justify-self: center; align-self: start; }
  .mode-button { min-width: 54px; padding: 0 8px; font-size: 11px; }
  .metrics-panel { top: 12px; right: 12px; width: min(326px, calc(100vw - 24px)); }
  .view-toolbar { bottom: 13px; width: calc(100% - 20px); justify-content: center; overflow-x: auto; }
  .view-label { top: 12px; }
  .view-label--left { left: 12px; }
  .view-label--right { left: calc(50% + 12px); }
  .overlay-control { bottom: 62px; }
}

@media (max-width: 560px) {
  .brand-block h1 { font-size: 14px; }
  .eyebrow { display: none; }
  .top-actions { gap: 4px; }
  .mode-button { min-width: 0; }
  .view-toolbar .toolbar-divider,
  .view-toolbar #gridToggle,
  .view-toolbar #rotateToggle { display: none; }
  .view-label { padding: 7px 9px; }
  .view-label strong { font-size: 10px; }
}
