:root {
  color-scheme: dark;
  --ink: #f5f2e8;
  --muted: #b4bbc0;
  --panel: rgba(13, 20, 26, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --gold: #f5b923;
  --gold-bright: #ffd469;
  --green: #7bd6a0;
}

* {
  box-sizing: border-box;
}

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

body {
  background: #080c10;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
  font: inherit;
}

#viewer-shell {
  position: relative;
  isolation: isolate;
}

#potree_render_area {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 35%, #28353d 0%, #11181e 50%, #070a0d 100%);
}

#potree_render_area canvas {
  display: block;
  touch-action: none;
}

.topbar {
  position: absolute;
  z-index: 10;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.brand,
.live-pill,
.survey-card,
.controls,
.help-panel,
.loading-panel,
.error-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.3);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 8px 16px 8px 8px;
  border-radius: 18px;
}

.brand img {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
}

.brand div {
  min-width: 0;
  padding-left: 10px;
}

.eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--gold-bright);
  font-size: 0.66rem;
  font-weight: 750;
  letter-spacing: 0.13em;
  line-height: 1.2;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  overflow: hidden;
  font-size: clamp(0.94rem, 2.3vw, 1.08rem);
  font-weight: 720;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 650;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 14px var(--gold);
}

.live-pill.ready .status-dot {
  background: var(--green);
  box-shadow: 0 0 14px var(--green);
}

.survey-card {
  position: absolute;
  z-index: 8;
  top: 105px;
  left: max(16px, env(safe-area-inset-left));
  display: grid;
  gap: 3px;
  padding: 14px 16px;
  border-radius: 16px;
  pointer-events: none;
}

.survey-card strong {
  font-size: 0.96rem;
}

.survey-card > span:last-child {
  color: var(--muted);
  font-size: 0.72rem;
}

.controls {
  position: absolute;
  z-index: 15;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  gap: 5px;
  padding: 6px;
  border-radius: 18px;
}

.controls button {
  display: grid;
  min-width: 66px;
  min-height: 58px;
  place-items: center;
  gap: 2px;
  padding: 6px 10px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  cursor: pointer;
}

.controls button:hover,
.controls button:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.09);
}

.controls button:active {
  transform: translateY(1px);
}

.controls button > span {
  color: var(--gold-bright);
  font-size: 1.35rem;
  line-height: 1;
}

.controls small {
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 650;
  white-space: nowrap;
}

.loading-panel,
.error-panel {
  position: absolute;
  z-index: 30;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  width: min(380px, calc(100% - 32px));
  gap: 14px;
  padding: 18px;
  border-radius: 20px;
  transform: translate(-50%, -50%);
  transition: opacity 280ms ease, visibility 280ms ease;
}

.loading-panel.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.loading-panel div:last-child,
.error-panel {
  display: grid;
  gap: 4px;
}

.loading-panel span,
.error-panel span {
  color: var(--muted);
  font-size: 0.8rem;
}

.spinner {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

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

.help-panel {
  position: absolute;
  z-index: 40;
  top: 50%;
  left: 50%;
  width: min(560px, calc(100% - 32px));
  padding: 24px;
  border-radius: 24px;
  transform: translate(-50%, -50%);
}

.help-panel h2 {
  max-width: 420px;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 20px 0;
}

.help-grid div {
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
}

.help-grid span,
.help-panel p {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 1.4rem;
}

.error-panel {
  text-align: center;
}

.error-panel button {
  justify-self: center;
  margin-top: 10px;
  padding: 10px 16px;
  border: 1px solid rgba(245, 185, 35, 0.45);
  border-radius: 999px;
  background: rgba(245, 185, 35, 0.12);
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
  }

  .brand {
    max-width: calc(100% - 54px);
  }

  .brand img {
    width: 42px;
    height: 42px;
    border-radius: 10px;
  }

  .brand {
    padding: 6px 12px 6px 6px;
  }

  .brand .eyebrow {
    font-size: 0.57rem;
  }

  .live-pill {
    width: 42px;
    height: 42px;
    justify-content: center;
    padding: 0;
  }

  .live-pill #status-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .survey-card {
    top: auto;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 76px);
    padding: 10px 12px;
  }

  .survey-card > span:last-child {
    display: none;
  }

  .controls {
    right: 50%;
    width: calc(100% - 32px);
    justify-content: space-between;
    transform: translateX(50%);
  }

  .controls button {
    min-width: 0;
    flex: 1;
    padding-inline: 5px;
  }

  .help-grid {
    grid-template-columns: 1fr;
    max-height: 46vh;
    overflow-y: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
