:root {
  --af3d-bar-height: 66px;
  --af3d-black: #111111;
  --af3d-panel: rgba(20, 20, 20, 0.95);
  --af3d-line: rgba(255, 255, 255, 0.16);
  --af3d-text: #f5f2eb;
  --af3d-muted: #b7b4ad;
  --af3d-accent: #df7f2f;
  --af3d-accent-strong: #f0903d;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #111;
  color: var(--af3d-text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
select { font: inherit; }

.af3d-bar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 100000;
  height: var(--af3d-bar-height);
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 7px 12px;
  background: linear-gradient(180deg, #151515, #0c0c0c);
  border-bottom: 1px solid var(--af3d-line);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

.af3d-brand {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  min-width: 205px;
  gap: 10px;
  padding-right: 13px;
  border-right: 1px solid var(--af3d-line);
}

.af3d-brand img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 9px;
}

.af3d-brand-copy {
  display: grid;
  gap: 3px;
  white-space: nowrap;
}

.af3d-brand-copy strong {
  font-size: 12px;
  letter-spacing: 0.13em;
}

.af3d-brand-copy span {
  color: var(--af3d-muted);
  font-size: 11px;
}

.af3d-tools {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #555 transparent;
}

.tool-button {
  flex: 0 0 auto;
  min-width: 67px;
  height: 51px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--af3d-text);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.tool-button img {
  width: 21px;
  height: 21px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.tool-button span { font-size: 11px; white-space: nowrap; }
.tool-button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); border-color: var(--af3d-line); }
.tool-button:active:not(:disabled) { transform: translateY(1px); }
.tool-button:focus-visible { outline: 2px solid var(--af3d-accent); outline-offset: -2px; }
.tool-button.primary { background: #2a211a; border-color: rgba(223, 127, 47, 0.55); }
.tool-button[aria-pressed="true"] { background: #2a211a; border-color: var(--af3d-accent); }
.tool-button.primary img { filter: invert(57%) sepia(94%) saturate(1432%) hue-rotate(338deg) brightness(98%) contrast(91%); }
.tool-button.finish {
  background: var(--af3d-accent);
  border-color: var(--af3d-accent-strong);
  color: #111;
  font-weight: 700;
}
.tool-button.finish > span:first-child { font-size: 18px; line-height: 16px; }
.tool-button[hidden] { display: none; }
.tool-button:disabled { cursor: wait; opacity: 0.35; }
.tool-button.compact { min-width: 42px; width: 42px; }
.tool-button.compact span { font-size: 23px; font-weight: 300; }
.tool-button.compact svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.cloud-status {
  flex: 0 0 auto;
  align-self: center;
  max-width: 170px;
  padding: 7px 10px;
  border: 1px solid var(--af3d-line);
  border-radius: 999px;
  color: #bde8cb;
  background: rgba(33, 91, 57, 0.35);
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
}

.cloud-status.loading { color: #f4d5b6; background: rgba(126, 69, 22, 0.35); }
.cloud-status.error { color: #ffd4d4; background: rgba(130, 30, 30, 0.45); }

.potree_container {
  position: absolute;
  inset: 0;
}

#potree_render_area {
  top: var(--af3d-bar-height) !important;
  background: radial-gradient(circle at 50% 42%, #31363a 0%, #151719 62%, #0a0b0c 100%);
}

#potree_sidebar_container {
  top: var(--af3d-bar-height) !important;
  height: calc(100% - var(--af3d-bar-height)) !important;
  z-index: 0;
}

#potree_sidebar_container #sidebar_header { padding-top: 8px; }
#potree_sidebar_container #potree_branding { display: none; }
#potree_render_area .potree_menu_toggle { display: none !important; }

.loading-panel {
  position: fixed;
  inset: var(--af3d-bar-height) 0 0 0;
  z-index: 90000;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 35%, #32363a 0%, #131416 68%, #090909 100%);
  transition: opacity 300ms ease, visibility 300ms ease;
}

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

.loading-card {
  width: min(430px, calc(100vw - 40px));
  padding: 30px;
  text-align: center;
  border: 1px solid var(--af3d-line);
  border-radius: 18px;
  background: rgba(11, 11, 11, 0.78);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}

.loading-card > img { width: 84px; height: 84px; object-fit: contain; border-radius: 14px; }
.loading-card h1 { margin: 17px 0 7px; font-size: 21px; font-weight: 620; }
.loading-card p { margin: 0; color: var(--af3d-muted); font-size: 14px; line-height: 1.5; }

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

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

.hint {
  position: fixed;
  z-index: 11000;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 8px 13px;
  border: 1px solid var(--af3d-line);
  border-radius: 999px;
  background: rgba(12, 12, 12, 0.78);
  color: #e8e5df;
  font-size: 11px;
  white-space: normal;
  text-align: center;
  line-height: 1.4;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.help-dialog {
  width: min(560px, calc(100vw - 28px));
  max-height: min(720px, calc(100vh - 28px));
  padding: 0;
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  background: #181818;
  color: var(--af3d-text);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.7);
}

.help-dialog::backdrop { background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(3px); }
.help-dialog form { position: relative; padding: 28px; }
.dialog-logo { width: 56px; height: 56px; border-radius: 10px; object-fit: contain; }
.help-dialog h2 { margin: 13px 0 20px; font-size: 23px; }
.help-dialog dl { display: grid; gap: 0; margin: 0; }
.help-dialog dl div { display: grid; grid-template-columns: 110px 1fr; gap: 14px; padding: 11px 0; border-top: 1px solid var(--af3d-line); }
.help-dialog dt { color: #fff; font-weight: 650; }
.help-dialog dd { margin: 0; color: var(--af3d-muted); line-height: 1.45; }
.help-note { padding: 12px; border-radius: 9px; background: #24201c; color: #e8c8ab; font-size: 12px; line-height: 1.5; }
.dialog-close { position: absolute; right: 14px; top: 10px; border: 0; background: none; color: #fff; font-size: 30px; cursor: pointer; }
.dialog-button { width: 100%; padding: 11px 16px; border: 0; border-radius: 9px; background: var(--af3d-accent); color: #111; font-weight: 700; cursor: pointer; }

@media (max-width: 980px) {
  .af3d-brand { min-width: auto; padding-right: 9px; }
  .af3d-brand-copy { display: none; }
  .cloud-status { display: none; }
}

@media (max-width: 600px) {
  .af3d-bar { gap: 6px; padding-inline: 7px; }
  .af3d-brand img { width: 44px; height: 44px; }
  .tool-button { min-width: 58px; padding-inline: 5px; }
  .tool-button span { font-size: 10px; }
  .hint { bottom: 9px; overflow: hidden; text-overflow: ellipsis; }
  .help-dialog dl div { grid-template-columns: 1fr; gap: 3px; }
}
