/* StlViewer - UI chrome. The 3D view itself is painted by WebGL onto #viewport. */

:root {
  --accent: #4c9aff;
  --accent-soft: rgba(76, 154, 255, 0.16);
  --radius: 10px;
  --panel-width: 268px;

  --surface: rgba(20, 24, 31, 0.82);
  --surface-solid: #151920;
  --surface-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.10);
  --text: #e7ecf3;
  --text-dim: #99a4b4;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

html[data-theme="light"] {
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --surface-hover: rgba(10, 20, 40, 0.06);
  --border: rgba(12, 20, 34, 0.13);
  --text: #17202e;
  --text-dim: #5c6879;
  --shadow: 0 12px 34px rgba(15, 25, 45, 0.18);
}

* { box-sizing: border-box; }

/* Overlays below set `display: flex`, which would otherwise beat the `hidden`
   attribute and leave invisible elements eating pointer events. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font: 13px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: #0b0e13;
  -webkit-font-smoothing: antialiased;
}

#viewport {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;   /* pointer events drive the camera, not the page */
  cursor: grab;
}
#viewport:active { cursor: grabbing; }

kbd {
  display: inline-block;
  min-width: 17px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-hover);
  font: inherit;
  font-size: 11px;
  text-align: center;
  color: var(--text-dim);
}

.muted { color: var(--text-dim); }
.small { font-size: 12px; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 52px;
  padding: 0 12px;
  background: linear-gradient(180deg, rgba(8, 10, 14, 0.72), rgba(8, 10, 14, 0));
  pointer-events: none;
}
html[data-theme="light"] .topbar {
  background: linear-gradient(180deg, rgba(245, 247, 250, 0.8), rgba(245, 247, 250, 0));
}
.topbar > * { pointer-events: auto; }

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.topbar__model {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.topbar__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 550;
}
.topbar__meta { color: var(--text-dim); white-space: nowrap; font-size: 12px; }

.topbar__actions { display: flex; align-items: center; gap: 8px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 550;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ buttons */

.btn {
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 120ms ease, background 120ms ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { filter: brightness(0.94); }

.btn--ghost {
  min-width: 32px;
  padding: 7px 10px;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
  backdrop-filter: blur(10px);
}
.btn--ghost:hover { background: var(--surface-hover); filter: none; }

.btn--big { padding: 11px 20px; font-size: 14px; border-radius: 10px; }

.chip {
  padding: 7px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.chip:hover { background: var(--surface-hover); }
.chip--accent { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ------------------------------------------------------------------- panel */

.panel {
  position: fixed;
  top: 60px;
  right: 12px;
  z-index: 15;
  width: var(--panel-width);
  max-height: calc(100vh - 76px);
  overflow-y: auto;
  padding: 6px 14px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  transition: transform 200ms ease, opacity 200ms ease;
  scrollbar-width: thin;
}
body.panel-hidden .panel { transform: translateX(calc(var(--panel-width) + 20px)); opacity: 0; pointer-events: none; }

.panel__group { padding: 10px 0; border-bottom: 1px solid var(--border); }
.panel__group:last-child { border-bottom: 0; padding-bottom: 2px; }

.panel h2 {
  margin: 0 0 9px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.grid { display: grid; gap: 6px; }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid + .grid { margin-top: 6px; }

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}
.field > span { color: var(--text-dim); }

select {
  flex: 0 1 140px;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-solid);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

input[type="color"] {
  width: 42px;
  height: 26px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-solid);
  cursor: pointer;
}

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 0;
  cursor: pointer;
}
.switch input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.switch span { display: flex; align-items: center; gap: 6px; }

/* ------------------------------------------------------------------- stats */

.stats {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 15;
  min-width: 232px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  font-variant-numeric: tabular-nums;
}
.stats__row { display: flex; justify-content: space-between; gap: 18px; padding: 2px 0; }
.stats__row span { color: var(--text-dim); }
.stats__row b { font-weight: 600; }

/* ---------------------------------------------------------------- overlays */

.welcome, .drop, .loading, .help, .fatal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.welcome { background: radial-gradient(ellipse at 50% 42%, rgba(76, 154, 255, 0.10), transparent 62%); }

.welcome__card {
  max-width: 470px;
  padding: 34px 32px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  text-align: center;
}
.welcome__card h1 { margin: 14px 0 10px; font-size: 25px; letter-spacing: -0.3px; }
.welcome__card p { margin: 0 0 18px; color: var(--text-dim); }
.welcome__actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 18px; }

.drop { background: rgba(6, 9, 14, 0.72); backdrop-filter: blur(3px); z-index: 40; }
.drop__inner {
  padding: 46px 62px;
  border: 2px dashed var(--accent);
  border-radius: 18px;
  background: var(--accent-soft);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
}
html[data-theme="light"] .drop { background: rgba(240, 244, 250, 0.75); }
html[data-theme="light"] .drop__inner { color: var(--text); }

.loading { background: rgba(6, 9, 14, 0.55); backdrop-filter: blur(2px); z-index: 45; }
html[data-theme="light"] .loading { background: rgba(240, 244, 250, 0.6); }
.loading__card {
  width: min(380px, 100%);
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  text-align: center;
}
.loading__label {
  margin-bottom: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.loading__bar { height: 6px; border-radius: 999px; background: var(--surface-hover); overflow: hidden; }
.loading__fill { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width 90ms linear; }
.loading__percent { margin-top: 8px; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.loading--indeterminate .loading__fill { animation: sweep 1.1s ease-in-out infinite; }
@keyframes sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.help { background: rgba(6, 9, 14, 0.62); backdrop-filter: blur(3px); z-index: 50; }
html[data-theme="light"] .help { background: rgba(240, 244, 250, 0.7); }
.help__card {
  width: min(470px, 100%);
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 22px 26px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.help__card h2 { margin: 4px 0 10px; font-size: 12px; letter-spacing: 0.9px; text-transform: uppercase; color: var(--text-dim); }
.help dl { display: grid; grid-template-columns: 108px 1fr; gap: 6px 14px; margin: 0 0 18px; }
.help dt { color: var(--text); font-weight: 600; }
.help dd { margin: 0; color: var(--text-dim); }
.help__keys dt { font-weight: 400; }

.fatal { background: #0b0e13; z-index: 60; }
.fatal__box { max-width: 440px; text-align: center; }
.fatal__box h1 { font-size: 20px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 55;
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  transform: translateX(-50%);
}
.toast--error { border-color: rgba(255, 106, 106, 0.55); color: #ff9c9c; }

/* ------------------------------------------------------------------ mobile */

@media (max-width: 720px) {
  .panel {
    top: auto;
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
    max-height: 46vh;
  }
  body.panel-hidden .panel { transform: translateY(120%); }
  .stats { display: none; }
  .topbar__meta, .badge { display: none; }
  .topbar__brand span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
