:root {
  color-scheme: dark;
  font-family: Inter, "Noto Sans TC", "Segoe UI", sans-serif;
  background: #081018;
  color: #edf6fb;
  --border: rgba(139, 171, 191, 0.22);
  --panel: rgba(10, 20, 29, 0.88);
  --muted: #86a0b1;
  --cold: #4fc5ff;
  --hot: #ff7849;
}

* {
  box-sizing: border-box;
}

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

button,
a {
  font: inherit;
}

.app-shell {
  width: 100%;
  height: 100%;
  min-height: 560px;
  background: #081018;
}

.topbar {
  position: relative;
  z-index: 10;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: #0b151e;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 2px solid #58cafa;
  border-radius: 6px;
}

.brand-mark span {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: #58cafa;
  box-shadow: 0 0 14px rgba(88, 202, 250, 0.72);
}

.title-block {
  min-width: 0;
}

.title-block small {
  display: block;
  color: #65c7f1;
  font-size: 10px;
  font-weight: 700;
}

.title-block h1 {
  margin: 2px 0 0;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

.system-state {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #9eb3c1;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.system-state i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #53dea9;
  box-shadow: 0 0 12px rgba(83, 222, 169, 0.78);
}

.system-state span {
  color: #71e2b6;
}

.top-actions {
  display: flex;
  gap: 8px;
  margin-left: 14px;
}

.button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: #d9eaf5;
  background: #0e1a25;
  text-decoration: none;
  cursor: pointer;
}

.button:hover,
.button:focus-visible {
  border-color: #5bcafa;
  outline: none;
  background: #132432;
}

.button-download {
  color: #65d7ff;
}

.button-explode {
  color: #ffcc76;
}

.button-explode[aria-pressed="true"] {
  border-color: rgba(255, 183, 71, 0.78);
  color: #fff4d8;
  background: #4a3214;
  box-shadow: inset 0 0 0 1px rgba(255, 188, 81, 0.14), 0 0 18px rgba(255, 151, 47, 0.1);
}

.viewer {
  position: relative;
  height: calc(100% - 68px);
  overflow: hidden;
  background:
    linear-gradient(rgba(36, 78, 99, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(36, 78, 99, 0.08) 1px, transparent 1px),
    radial-gradient(circle at 50% 42%, #122635 0, #09131c 42%, #060c12 76%);
  background-size: 48px 48px, 48px 48px, auto;
}

.canvas-host,
.canvas-host canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #b7ccda;
  background: rgba(5, 11, 16, 0.9);
  transition: opacity 220ms ease;
}

.loading.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loading span {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(79, 197, 255, 0.18);
  border-top-color: var(--cold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.metric-card {
  position: absolute;
  top: 22px;
  z-index: 5;
  width: 230px;
  padding: 17px 18px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.metric-card-left {
  left: 20px;
  border-top: 2px solid var(--cold);
}

.metric-card-right {
  right: 20px;
  border-top: 2px solid var(--hot);
}

.alarm-toast {
  position: absolute;
  top: 184px;
  right: 20px;
  z-index: 14;
  width: min(330px, calc(100% - 40px));
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 28px;
  gap: 11px;
  align-items: start;
  padding: 14px;
  border: 1px solid rgba(255, 85, 85, 0.64);
  border-left: 3px solid #ff4242;
  border-radius: 7px;
  background: rgba(36, 10, 14, 0.94);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35), 0 0 24px rgba(255, 42, 42, 0.16);
  backdrop-filter: blur(12px);
  animation: alarm-enter 260ms ease-out;
}

.alarm-toast[hidden] {
  display: none;
}

.alarm-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 111, 111, 0.58);
  border-radius: 50%;
  color: #fff;
  background: #c7252d;
  box-shadow: 0 0 18px rgba(255, 45, 55, 0.48);
  font-size: 21px;
  font-weight: 800;
}

.alarm-copy {
  min-width: 0;
}

.alarm-copy span {
  display: block;
  color: #ff8b8b;
  font-size: 10px;
  font-weight: 800;
}

.alarm-copy strong {
  display: block;
  margin-top: 3px;
  color: #fff0f0;
  font-size: 14px;
  line-height: 1.35;
}

.alarm-copy p {
  margin: 6px 0 0;
  color: #d6a9ad;
  font-size: 11px;
  line-height: 1.5;
}

.alarm-toast button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  color: #d5a7aa;
  background: transparent;
  cursor: pointer;
  font-size: 21px;
  line-height: 1;
}

.alarm-toast button:hover,
.alarm-toast button:focus-visible {
  color: #fff;
  outline: none;
}

.explode-legend {
  position: absolute;
  top: 184px;
  left: 20px;
  z-index: 13;
  width: 224px;
  padding: 14px 15px;
  border: 1px solid rgba(255, 193, 100, 0.34);
  border-left: 3px solid #ffb547;
  border-radius: 7px;
  background: rgba(8, 17, 24, 0.93);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateX(-12px);
  pointer-events: none;
  transition: opacity 240ms ease, transform 240ms ease;
}

.explode-legend.is-visible {
  opacity: 1;
  transform: translateX(0);
}

.explode-legend small {
  display: block;
  color: #ffbb56;
  font-size: 9px;
  font-weight: 800;
}

.explode-legend strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
}

.explode-legend ul {
  display: grid;
  gap: 8px;
  margin: 13px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
}

.explode-legend li {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #b9ccd7;
  font-size: 11px;
}

.explode-legend li i {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: #8da3b1;
  box-shadow: 0 0 10px currentColor;
}

.explode-legend .legend-fan { color: #63d2ff; background: #63d2ff; }
.explode-legend .legend-coil { color: #d79a55; background: #d79a55; }
.explode-legend .legend-server { color: #dce8ed; background: #dce8ed; }
.explode-legend .legend-pipe { color: #ff6754; background: linear-gradient(90deg, #3ea8ff 0 50%, #ff6754 50%); }

@keyframes alarm-enter {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: translateX(0); }
}

.metric-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #b8cad6;
  font-size: 12px;
  font-weight: 700;
}

.metric-heading i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.cold-dot {
  background: var(--cold);
  box-shadow: 0 0 12px rgba(79, 197, 255, 0.8);
}

.hot-dot {
  background: var(--hot);
  box-shadow: 0 0 12px rgba(255, 120, 73, 0.8);
}

.metric-card strong {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 9px;
  font-size: 43px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.metric-card-left strong {
  color: #71d1ff;
}

.metric-card-right strong {
  color: #ff9a72;
}

.metric-card strong small {
  font-size: 15px;
}

.metric-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.metric-track {
  height: 4px;
  margin-top: 12px;
  overflow: hidden;
  background: rgba(143, 172, 190, 0.15);
}

.metric-track span {
  display: block;
  width: 70%;
  height: 100%;
  transition: width 400ms ease;
}

.metric-card-left .metric-track span {
  background: var(--cold);
}

.metric-card-right .metric-track span {
  background: var(--hot);
}

.ambient {
  position: absolute;
  top: 238px;
  z-index: 4;
  display: grid;
  gap: 3px;
  color: #7894a7;
  font-size: 10px;
}

.ambient strong {
  color: #b8c9d4;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.ambient-left {
  left: 28px;
}

.ambient-right {
  right: 28px;
  text-align: right;
}

.telemetry {
  position: absolute;
  left: 50%;
  bottom: 22px;
  z-index: 5;
  width: min(820px, calc(100% - 360px));
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: 7px;
  transform: translateX(-50%);
  background: rgba(8, 17, 25, 0.9);
  backdrop-filter: blur(10px);
}

.telemetry article {
  min-width: 0;
  padding: 12px 15px;
  border-right: 1px solid var(--border);
}

.telemetry article:last-child {
  border-right: 0;
}

.telemetry span {
  display: block;
  margin-bottom: 5px;
  color: #7f99aa;
  font-size: 10px;
}

.telemetry strong {
  color: #e4f0f7;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.telemetry small {
  margin-left: 5px;
  color: #7e98a9;
  font-size: 10px;
}

.scene-status {
  position: absolute;
  left: 20px;
  bottom: 22px;
  z-index: 5;
  display: grid;
  gap: 4px;
  color: #7390a3;
  font-size: 10px;
}

.scene-status span:first-child {
  color: #a9c0ce;
}

.hover-label {
  position: absolute;
  z-index: 12;
  max-width: 260px;
  padding: 7px 9px;
  border: 1px solid rgba(89, 201, 245, 0.38);
  border-radius: 4px;
  color: #e7f5fb;
  background: rgba(7, 16, 23, 0.94);
  font-size: 11px;
  pointer-events: none;
}

@media (max-width: 900px) {
  .system-state span,
  .button-download {
    display: none;
  }

  .metric-card {
    width: 174px;
    padding: 12px;
  }

  .metric-card strong {
    font-size: 32px;
  }

  .telemetry {
    width: calc(100% - 32px);
  }

  .scene-status,
  .ambient {
    display: none;
  }
}

@media (max-width: 620px) {
  .app-shell {
    min-height: 640px;
  }

  .topbar {
    height: 58px;
    padding: 0 10px;
  }

  .title-block small,
  .system-state {
    display: none;
  }

  .title-block h1 {
    font-size: 14px;
  }

  .top-actions {
    margin-left: auto;
  }

  .top-actions .button {
    min-height: 32px;
    padding: 0 9px;
    font-size: 11px;
  }

  #reset-view {
    display: none;
  }

  .viewer {
    height: calc(100% - 58px);
  }

  .metric-card {
    top: 10px;
    width: calc(50% - 15px);
  }

  .metric-card-left { left: 10px; }
  .metric-card-right { right: 10px; }

  .metric-card p {
    display: none;
  }

  .alarm-toast {
    top: 148px;
    right: 10px;
    width: calc(100% - 20px);
  }

  .explode-legend {
    top: 148px;
    left: 10px;
    width: 184px;
    padding: 11px 12px;
  }

  .explode-legend ul {
    gap: 6px;
    margin-top: 9px;
    padding-top: 9px;
  }

  .telemetry {
    bottom: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .telemetry article {
    padding: 9px;
  }

  .telemetry article:nth-child(3) {
    border-right: 0;
  }

  .telemetry article:nth-child(n + 4) {
    display: none;
  }
}
