 :root {
  color-scheme: dark;
  --bg: #090b10;
  --panel: rgba(14, 18, 28, 0.86);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f3f6fb;
  --muted: #aab3c2;
  --button: #2f6fed;
  --button-hover: #3f7cff;
  --button-secondary: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
#viewer { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#topbar {
  position: fixed;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: 14px;
  z-index: 10;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.brand { font-weight: 700; white-space: nowrap; margin-right: auto; }
.button {
  appearance: none;
  border: 0;
  background: var(--button);
  color: white;
  padding: 9px 12px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.button:hover { background: var(--button-hover); }
.button.secondary { background: var(--button-secondary); }
.button.secondary:hover { background: rgba(255, 255, 255, 0.16); }
.file-button input { display: none; }
.control { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 14px; white-space: nowrap; }
.control input { width: 120px; }
#speedValue { min-width: 22px; color: var(--text); font-weight: 700; }

.panel {
  position: fixed;
  width: min(520px, calc(100vw - 40px));
  padding: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  z-index: 8;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.hosted-panel {
  left: 20px;
  top: 84px;
}

.help-panel {
  left: 20px;
  bottom: 48px;
  width: min(430px, calc(100vw - 40px));
}

.panel h1 { margin: 0 0 8px; font-size: 21px; }
.panel p { margin: 8px 0; color: var(--muted); line-height: 1.45; }
.grid { display: grid; grid-template-columns: 130px 1fr; gap: 7px 14px; margin: 14px 0; font-size: 14px; }
.grid span:nth-child(odd) { font-weight: 800; }
.grid span:nth-child(even) { color: var(--muted); }
.small { font-size: 13px; }

.hosted-row {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

.hosted-row select,
.hosted-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.32);
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
}

.hosted-row select:disabled {
  color: var(--muted);
}

.hosted-row input::placeholder {
  color: rgba(170, 179, 194, 0.65);
}

#status {
  position: fixed;
  left: 14px;
  bottom: 14px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 8px 12px;
  z-index: 11;
  font-size: 13px;
  max-width: calc(100vw - 28px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.55);
  font: 24px/1 monospace;
  z-index: 7;
  display: none;
  pointer-events: none;
}

body.pointer-locked #crosshair { display: block; }
body.pointer-locked #help, body.pointer-locked #hostedPanel { display: none; }

@media (max-width: 850px) {
  #topbar { align-items: stretch; flex-wrap: wrap; }
  .brand { width: 100%; }
  .control { width: 100%; }
  .control input { flex: 1; }
  .hosted-panel { top: 154px; }
  .hosted-row { flex-direction: column; }
}


.wide-button {
  width: 100%;
}

#modelLibraryDialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  color: var(--text);
  background: transparent;
  width: min(620px, calc(100vw - 32px));
}

#modelLibraryDialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(3px);
}

.dialog-card {
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  background: rgba(14, 18, 28, 0.98);
  padding: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}

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

.dialog-header h2 {
  margin: 0;
  font-size: 20px;
}

.icon-button {
  border: 0;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.dialog-row,
.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.dialog-actions {
  justify-content: flex-end;
}

.model-library-list {
  min-height: 130px;
  max-height: 280px;
  overflow: auto;
  margin: 14px 0;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  padding: 8px;
}

.model-file-option {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 8px;
  border-radius: 10px;
  cursor: pointer;
}

.model-file-option:hover {
  background: rgba(255, 255, 255, 0.08);
}

.model-file-option input {
  flex: 0 0 auto;
}

.model-file-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.model-file-name {
  color: var(--text);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-file-url {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.dialog-label input {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.32);
  color: var(--text);
  padding: 10px;
  font: inherit;
}


.stacked-buttons {
  align-items: stretch;
}

.checkbox-row {
  display: flex;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  margin-top: 12px;
  font-size: 14px;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
}

.upload-progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.upload-progress-wrap progress {
  flex: 1;
  height: 14px;
}

#uploadProgressText {
  color: var(--muted);
  font-size: 13px;
  min-width: 40px;
  text-align: right;
}


/* v8 layout fix: stack the load-model and controls panes so they cannot overlap. */
.hosted-panel,
.help-panel {
  left: 20px;
  width: min(520px, calc(100vw - 40px));
}

.hosted-panel {
  top: 84px;
  bottom: auto;
}

.help-panel {
  top: calc(84px + 260px);
  bottom: auto;
  width: min(430px, calc(100vw - 40px));
}

@media (max-height: 860px) {
  .hosted-panel {
    max-height: 42vh;
    overflow: auto;
  }

  .help-panel {
    top: auto;
    bottom: 48px;
    max-height: 34vh;
    overflow: auto;
  }
}

@media (max-width: 850px) {
  .hosted-panel {
    top: 154px;
    max-height: 38vh;
    overflow: auto;
  }

  .help-panel {
    top: auto;
    bottom: 48px;
    max-height: 30vh;
    overflow: auto;
  }
}

@media (max-height: 700px) {
  .help-panel {
    display: none;
  }

  body:not(.pointer-locked) .hosted-panel {
    max-height: calc(100vh - 190px);
  }
}


/* v9 layout fix: one parent column controls both panes, eliminating overlap entirely. */
#leftPanelStack {
  position: fixed;
  left: 20px;
  top: 84px;
  bottom: 48px;
  width: min(520px, calc(100vw - 40px));
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 8;
  pointer-events: none;
}

#leftPanelStack .panel {
  position: static;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  width: 100%;
  max-height: none;
  overflow: visible;
  pointer-events: auto;
}

#leftPanelStack .hosted-panel {
  flex: 0 0 auto;
}

#leftPanelStack .help-panel {
  flex: 0 1 auto;
  overflow: auto;
}

body.pointer-locked #leftPanelStack {
  display: none;
}

@media (max-height: 860px) {
  #leftPanelStack {
    overflow: auto;
    gap: 14px;
  }

  #leftPanelStack .panel {
    flex: 0 0 auto;
  }

  #leftPanelStack .help-panel {
    max-height: none;
  }
}

@media (max-width: 850px) {
  #leftPanelStack {
    top: 154px;
    bottom: 48px;
    overflow: auto;
    gap: 14px;
  }

  #leftPanelStack .hosted-panel,
  #leftPanelStack .help-panel {
    max-height: none;
  }
}

@media (max-height: 700px) {
  #leftPanelStack .help-panel {
    display: none;
  }

  #leftPanelStack {
    overflow: auto;
  }
}


/* v11 selection fix: explicit selectable rows instead of dialog-contained radio labels. */
.model-library-list .model-file-option {
  width: 100%;
  border: 0;
  appearance: none;
  background: transparent;
  color: inherit;
  text-align: left;
}

.model-library-list .model-file-option.selected {
  background: rgba(47, 111, 237, 0.24);
  outline: 1px solid rgba(47, 111, 237, 0.72);
}

.model-file-selected-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--text);
  font-weight: 800;
  background: rgba(0, 0, 0, 0.24);
}

.model-file-option.selected .model-file-selected-indicator {
  background: var(--button);
  border-color: var(--button);
}


/* v12 dialog fix: dialogs are outside #leftPanelStack; keep them independently clickable. */
#uploadModelDialog,
#modelLibraryDialog,
#uploadModelDialog *,
#modelLibraryDialog * {
  pointer-events: auto;
}
