:root {
  color-scheme: light;
  --ink: #172520;
  --muted: #60716a;
  --line: rgba(31, 61, 50, 0.15);
  --panel: rgba(247, 251, 248, 0.88);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --green: #26734d;
  --green-soft: #e0f0e7;
  --blue: #267f9c;
  --amber: #bd7a24;
  --shadow: 0 20px 55px rgba(37, 64, 53, 0.17);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: #dce9e3;
}

button,
input { font: inherit; }

#viewport {
  position: fixed;
  inset: 0;
  touch-action: none;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(1.08);
  -webkit-backdrop-filter: blur(16px) saturate(1.08);
}

.hero {
  position: fixed;
  z-index: 5;
  top: 18px;
  left: 18px;
  width: min(470px, calc(100vw - 36px));
  padding: 18px 20px 16px;
  border-radius: 18px;
  pointer-events: none;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #31a46c;
  box-shadow: 0 0 0 5px rgba(49, 164, 108, 0.12);
}

h1 {
  margin: 8px 0 5px;
  font-size: clamp(25px, 3.2vw, 40px);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.stats div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(31, 61, 50, 0.1);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.67);
}

.stats strong,
.stats span { display: block; }

.stats strong {
  font-size: 17px;
  line-height: 1;
  white-space: nowrap;
}

.stats span {
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  position: fixed;
  z-index: 6;
  top: 18px;
  right: 18px;
  display: grid;
  gap: 8px;
  width: min(480px, calc(100vw - 36px));
  padding: 10px;
  border-radius: 16px;
}

.tool-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.tool-row + .tool-row {
  padding-top: 8px;
  border-top: 1px solid rgba(31, 61, 50, 0.1);
}

.tool-label {
  flex: 0 0 38px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.state-chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 26px;
  padding: 5px 8px;
  border: 1px solid rgba(38, 115, 77, 0.2);
  border-radius: 999px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 9px;
  font-weight: 900;
  white-space: nowrap;
}

.vent-open-chip::before {
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: #31a46c;
  box-shadow: 0 0 0 4px rgba(49, 164, 108, 0.11);
  content: "";
}

button {
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid rgba(31, 61, 50, 0.14);
  border-radius: 9px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: 140ms ease;
}

button:hover {
  border-color: rgba(38, 115, 77, 0.42);
  transform: translateY(-1px);
  background: white;
}

button.active,
button.accent {
  border-color: var(--green);
  color: white;
  background: var(--green);
}

button.is-off {
  opacity: 0.48;
  text-decoration: line-through;
}

.range-wrap {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 8px;
  min-width: 110px;
  margin-left: 2px;
}

.range-wrap span {
  min-width: 34px;
  color: var(--green);
  font-size: 11px;
  font-weight: 900;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
  cursor: pointer;
}

.insulation-row .range-wrap span { color: var(--amber); }
.insulation-row input[type="range"] { accent-color: var(--amber); }

.geometry-panel {
  position: fixed;
  z-index: 5;
  left: 18px;
  bottom: 18px;
  width: min(445px, calc(100vw - 36px));
  max-height: min(490px, 58vh);
  overflow: auto;
  padding: 15px 17px 14px;
  border-radius: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading h2 {
  margin: 4px 0 0;
  font-size: 17px;
  line-height: 1.15;
}

.verified-badge {
  flex: 0 0 auto;
  padding: 5px 8px;
  border: 1px solid rgba(38, 115, 77, 0.2);
  border-radius: 99px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 10px;
  font-weight: 900;
}

#profileSvg {
  display: block;
  width: 100%;
  height: 142px;
  margin: 8px 0 4px;
  overflow: visible;
}

.arc-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.arc-metrics div {
  padding: 8px;
  border-radius: 10px;
  background: rgba(224, 240, 231, 0.72);
}

.arc-metrics span,
.arc-metrics strong { display: block; }

.arc-metrics span {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.2;
}

.arc-metrics strong {
  margin-top: 4px;
  font-size: 12px;
  white-space: nowrap;
}

.arc-table {
  width: 100%;
  margin-top: 9px;
  border-collapse: collapse;
  font-size: 10px;
}

.arc-table th,
.arc-table td {
  padding: 6px 5px;
  border-top: 1px solid rgba(31, 61, 50, 0.1);
  text-align: right;
  white-space: nowrap;
}

.arc-table th:first-child,
.arc-table td:first-child { text-align: left; }

.arc-table th {
  color: var(--muted);
  font-weight: 700;
}

.method-note {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.status {
  position: fixed;
  z-index: 5;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(440px, calc(100vw - 36px));
  padding: 10px 13px;
  border-radius: 12px;
  color: #1e4f3a;
  font-size: 11px;
  font-weight: 800;
}

.status-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--green);
}

.hint {
  position: fixed;
  z-index: 4;
  right: 22px;
  bottom: 62px;
  color: rgba(23, 37, 32, 0.67);
  font-size: 10px;
  pointer-events: none;
}

body.inside-view .geometry-panel {
  opacity: 0;
  transform: translateY(18px) scale(0.98);
  pointer-events: none;
}

.load-error {
  position: fixed;
  z-index: 20;
  inset: 50% auto auto 50%;
  width: min(510px, calc(100vw - 36px));
  padding: 20px;
  border-radius: 16px;
  transform: translate(-50%, -50%);
  background: var(--panel-strong);
}

.load-error p {
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.load-error code {
  color: #8b3e2f;
  font-size: 11px;
}

@media (max-width: 980px) {
  .hero { width: min(420px, calc(50vw - 24px)); }
  .toolbar { width: min(450px, calc(50vw - 24px)); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .geometry-panel { max-height: 45vh; }
}

@media (max-width: 720px) {
  .hero {
    top: 10px;
    left: 10px;
    width: calc(100vw - 20px);
    padding: 13px 14px;
  }

  h1 { font-size: 24px; }
  .subtitle { font-size: 11px; }
  .stats { display: none; }

  .toolbar {
    top: auto;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    max-height: min(46vh, 330px);
    overflow-y: auto;
    padding: 8px;
  }

  .tool-row {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .tool-row::-webkit-scrollbar { display: none; }
  .layer-row { display: flex; }
  .tool-label { flex-basis: 32px; }
  button { flex: 0 0 auto; }

  .range-wrap {
    flex: 0 0 128px;
    min-width: 128px;
  }

  .state-chip {
    min-height: 30px;
    padding-inline: 9px;
  }

  .geometry-panel {
    top: 124px;
    bottom: auto;
    left: 10px;
    width: min(350px, calc(100vw - 20px));
    max-height: min(250px, 36vh);
    padding: 11px 12px;
  }

  #profileSvg { height: 105px; }
  .arc-metrics { grid-template-columns: repeat(2, 1fr); }
  .arc-table,
  .method-note { display: none; }
  .status,
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}
