:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b1118;
  color: #f4f8fb;
}

* { box-sizing: border-box; }

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

body { background: radial-gradient(circle at 50% 42%, #1c2b37, #0b1118 70%); }

#viewer { position: fixed; inset: 0; }
#viewer canvas { display: block; }
#viewer.is-measuring canvas { cursor: crosshair; }

.loading-screen {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  justify-items: center;
  color: #9fb0bf;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

.viewer-ready .loading-screen,
.viewer-error .loading-mark { display: none; }

.loading-mark {
  width: 34px;
  height: 34px;
  border: 2px solid #2f4354;
  border-top-color: #5ee7ff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.topbar {
  position: fixed;
  z-index: 20;
  top: 18px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  pointer-events: none;
}

.brand,
.tools,
.help,
.status {
  border: 1px solid rgba(198, 222, 238, 0.16);
  background: rgba(10, 18, 25, 0.84);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 10px 14px 10px 10px;
  border-radius: 12px;
}

.brand-mark {
  width: 33px;
  height: 33px;
  margin-right: 10px;
  border-radius: 9px;
  background:
    linear-gradient(135deg, transparent 42%, rgba(255,255,255,.9) 43% 48%, transparent 49%),
    linear-gradient(315deg, #176fc1 0 48%, #5ee7ff 49% 100%);
}

.brand strong,
.brand span { display: block; }
.brand strong { font-size: 0.95rem; line-height: 1.2; }
.brand div > span {
  max-width: min(32vw, 380px);
  margin-top: 2px;
  overflow: hidden;
  color: #98aaba;
  font-size: 0.75rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tools {
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 12px;
  pointer-events: auto;
}

button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d8e3eb;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
button:focus-visible { outline: 2px solid #5ee7ff; outline-offset: 2px; }
button.active { background: #176fc1; color: #fff; }
button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.help {
  position: fixed;
  z-index: 20;
  right: 18px;
  bottom: 18px;
  display: flex;
  gap: 16px;
  padding: 9px 12px;
  border-radius: 9px;
  color: #91a4b4;
  font-size: 0.75rem;
  pointer-events: none;
}

.help b { color: #dfe8ef; font-weight: 600; }

.status {
  position: fixed;
  z-index: 20;
  left: 18px;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(620px, calc(100vw - 36px));
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 9px;
  color: #b8c7d2;
  font-size: 0.8rem;
}

.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #8295a5; }
.status[data-state="loading"] .status-dot { background: #5ee7ff; box-shadow: 0 0 0 4px rgba(94,231,255,.12); }
.status[data-state="ready"] .status-dot { background: #68d391; }
.status[data-state="measuring"] .status-dot { background: #ffcc33; }
.status[data-state="warning"] .status-dot { background: #ffa94d; }
.status[data-state="error"] { color: #ffd4d4; border-color: rgba(255,107,107,.35); }
.status[data-state="error"] .status-dot { background: #ff6b6b; }

.label-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.annotation-label,
.distance-label {
  transform: translate(-50%, -100%);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 7px;
  background: rgba(6, 12, 17, 0.9);
  box-shadow: 0 8px 22px rgba(0,0,0,.35);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1;
  white-space: nowrap;
}

.annotation-label {
  padding: 9px 11px;
  border-color: rgba(255, 204, 51, 0.65);
  color: #ffe384;
  pointer-events: auto;
  text-decoration: none;
}

.annotation-label:hover { background: #176fc1; border-color: #5ee7ff; color: #fff; }
.annotation-label:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.distance-label { padding: 7px 9px; border-color: rgba(94, 231, 255, 0.55); color: #b9f6ff; }

@media (max-width: 700px) {
  .topbar { align-items: flex-start; }
  .brand div > span { max-width: 34vw; }
  button { width: 42px; padding: 0; justify-content: center; font-size: 0; }
  button svg { width: 20px; height: 20px; }
  .help { display: none; }
}

@media (max-width: 430px) {
  .topbar { top: 10px; left: 10px; right: 10px; gap: 8px; }
  .brand { padding-right: 10px; }
  .brand-mark { width: 30px; height: 30px; }
  .brand div > span { max-width: 28vw; }
  .status { left: 10px; right: 10px; bottom: 10px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  .loading-mark { animation: none; }
}
