:root {
  color-scheme: dark;
  --bg: #070b11;
  --panel: rgba(15, 22, 32, 0.78);
  --card: #111925;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);
  --text: #e9eff7;
  --muted: #93a3b7;
  --accent: #5ad1d6;
  --accent-ink: #04262a;
  --danger: #ff9a8a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --pad-top: env(safe-area-inset-top, 0px);
  --pad-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(120% 85% at 12% 0%, rgba(24, 72, 84, 0.85) 0%, rgba(12, 30, 38, 0) 58%),
    radial-gradient(110% 80% at 92% 100%, rgba(35, 33, 82, 0.7) 0%, rgba(20, 20, 50, 0) 62%),
    linear-gradient(180deg, #081018 0%, #060a10 100%);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

[hidden] {
  display: none !important;
}

#viewport {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
  cursor: grab;
}

#viewport:active {
  cursor: grabbing;
}

body.is-gallery #viewport {
  visibility: hidden;
}

/* ---------- Buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(19, 28, 40, 0.72);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
  padding: 9px 13px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease,
    color 0.15s ease;
  touch-action: manipulation;
}

.btn:hover {
  background: rgba(32, 46, 62, 0.85);
  border-color: var(--border-strong);
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.active,
.btn[aria-pressed="true"] {
  background: rgba(90, 209, 214, 0.16);
  border-color: rgba(90, 209, 214, 0.5);
  color: #d8fbfc;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 600;
}

.btn.primary:hover {
  background: #6fe0e4;
}

.btn.small {
  font-size: 12px;
  padding: 7px 11px;
}

.btn.icon-only {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
}

/* ---------- Top bar ---------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: calc(16px + var(--pad-top)) 18px 0;
  pointer-events: none;
}

.brand {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 64ch;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}

.brand-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.subtitle {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex: none;
  pointer-events: auto;
}

body.is-gallery .brand,
body.is-gallery #btn-models,
body.is-gallery #btn-panel,
body.is-gallery #panel,
body.is-gallery .hint {
  display: none;
}

body.is-gallery .topbar {
  justify-content: flex-end;
}

#btn-qr .qr-label {
  display: none;
}

body.is-gallery #btn-qr {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: auto;
  padding: 9px 13px;
}

body.is-gallery #btn-qr .qr-label {
  display: inline;
  font-size: 12.5px;
}

/* ---------- Gallery ---------- */

.gallery {
  position: fixed;
  inset: 0;
  z-index: 5;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(96px + var(--pad-top)) 24px calc(48px + var(--pad-bottom));
  -webkit-overflow-scrolling: touch;
}

.gallery-inner {
  width: min(980px, 100%);
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

#gallery-title {
  margin: 0;
  font-size: clamp(27px, 4vw, 38px);
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.1;
}

.gallery-subtitle {
  max-width: 64ch;
  margin: 12px 0 0;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--muted);
}

.notice {
  margin: 24px 0 0;
  padding: 12px 14px;
  border: 1px solid rgba(255, 154, 138, 0.35);
  border-radius: 12px;
  background: rgba(255, 154, 138, 0.1);
  color: #ffc8be;
  font-size: 12.5px;
  line-height: 1.55;
}

.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
  margin: 30px 0 0;
  padding: 0;
  list-style: none;
}

.model-card {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 74px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(19, 28, 40, 0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: inherit;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.model-card:hover {
  background: rgba(31, 45, 61, 0.78);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.model-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.05);
}

.card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.card-title {
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.card-arrow {
  flex: none;
  color: var(--muted);
  transition: transform 0.15s ease, color 0.15s ease;
}

.model-card:hover .card-arrow {
  transform: translateX(2px);
  color: var(--text);
}

.gallery-empty {
  margin-top: 30px;
  padding: 22px;
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
}

.gallery-empty h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.gallery-empty p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.gallery-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}

.gallery-note {
  max-width: 72ch;
  margin: 20px 0 0;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--muted);
}

.gallery-note code,
.gallery-empty code,
.notice code {
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 11.5px;
}

/* ---------- Panel ---------- */

.panel {
  position: fixed;
  z-index: 9;
  top: calc(66px + var(--pad-top));
  right: 18px;
  width: min(336px, calc(100vw - 36px));
  max-height: calc(100vh - 86px - var(--pad-top));
  max-height: calc(100dvh - 86px - var(--pad-top));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 16px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(20px) saturate(1.25);
  -webkit-backdrop-filter: blur(20px) saturate(1.25);
  box-shadow: var(--shadow);
  transform-origin: top right;
  transition: opacity 0.18s ease, transform 0.18s ease;
  -webkit-overflow-scrolling: touch;
}

.panel.is-closed {
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  pointer-events: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -16px;
  padding: 12px 16px 8px;
  background: linear-gradient(180deg, rgba(15, 22, 32, 0.98) 65%, rgba(15, 22, 32, 0));
}

.panel h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-section {
  padding: 16px 0 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.panel-head + .panel-section {
  border-top: none;
  padding-top: 4px;
}

.footer-section {
  padding-bottom: 0;
}

.row-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 11.5px;
  line-height: 1.5;
}

.note {
  margin: 12px 0 0;
}

/* ---------- Model summary ---------- */

.model-summary {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.model-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-meta {
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.swatch {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  cursor: pointer;
  border-radius: 50%;
}

.swatch input[type="color"] {
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

.swatch input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.swatch input[type="color"]::-webkit-color-swatch {
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
}

.swatch input[type="color"]::-moz-color-swatch {
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
}

.tag {
  flex: none;
  padding: 2px 7px;
  border: 1px solid rgba(90, 209, 214, 0.4);
  border-radius: 999px;
  color: #9ce9ec;
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-shadow: none;
}

/* ---------- Range inputs ---------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}

input[type="range"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--thumb, var(--accent));
  border: 2px solid #0a0f16;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--thumb, var(--accent));
  border: 2px solid #0a0f16;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 999px;
}

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

.slider-row span {
  flex: none;
  width: 76px;
}

.slider-row input {
  flex: 1;
}

.slider-row .value {
  flex: none;
  width: 36px;
  text-align: right;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* ---------- View grid / segmented ---------- */

.view-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.view-grid .btn {
  width: 100%;
}

.segmented {
  display: flex;
  gap: 6px;
}

.segmented .btn {
  flex: 1;
  padding-left: 4px;
  padding-right: 4px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.check input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 10, 15, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.loading-card {
  width: min(320px, 100%);
  padding: 24px 26px;
  text-align: center;
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text);
}

.progress {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ---------- QR modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 11, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  width: min(360px, 100%);
  padding: 24px;
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 600;
}

.qr-holder {
  width: min(280px, 68vw);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 10px;
  border-radius: 14px;
  background: #fff;
}

.qr-holder svg {
  display: block;
  width: 100%;
  height: 100%;
}

.qr-url {
  margin: 14px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
  word-break: break-all;
  user-select: text;
  -webkit-user-select: text;
}

.warning {
  margin: 12px 0 0;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid rgba(255, 154, 138, 0.35);
  background: rgba(255, 154, 138, 0.1);
  color: var(--danger);
  font-size: 11.5px;
  line-height: 1.5;
  text-align: left;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Misc ---------- */

.hint {
  position: fixed;
  z-index: 8;
  left: 50%;
  bottom: calc(20px + var(--pad-bottom));
  max-width: calc(100vw - 40px);
  margin: 0;
  padding: 9px 15px;
  transform: translateX(-50%);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(13, 20, 29, 0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

body.hint-dismissed .hint {
  opacity: 0;
  transform: translate(-50%, 6px);
}

.dropzone {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 24px;
  outline: 2px dashed rgba(90, 209, 214, 0.7);
  outline-offset: -16px;
  background: rgba(90, 209, 214, 0.08);
  color: #c8fbfc;
  font-size: 14px;
  letter-spacing: 0.01em;
  pointer-events: none;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(64px + var(--pad-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: rgba(20, 30, 42, 0.94);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
  animation: toast-in 0.18s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 6px);
  }
}

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
  .topbar {
    padding: calc(12px + var(--pad-top)) 14px 0;
    gap: 10px;
  }

  .brand h1 {
    font-size: 13.5px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions .btn {
    padding: 8px 10px;
    font-size: 12px;
  }

  .btn.icon-only {
    width: 32px;
    height: 32px;
  }

  body.has-model #btn-qr {
    display: none;
  }

  .gallery {
    padding: calc(84px + var(--pad-top)) 16px calc(44px + var(--pad-bottom));
  }

  #gallery-title {
    font-size: 27px;
  }

  .gallery-subtitle {
    font-size: 13.5px;
  }

  .model-grid {
    grid-template-columns: 1fr;
    margin-top: 24px;
  }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 78vh;
    max-height: 78dvh;
    padding-bottom: calc(14px + var(--pad-bottom));
    border-radius: 22px 22px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    transform-origin: bottom center;
  }

  .panel.is-closed {
    transform: translateY(12px) scale(0.99);
  }

  .panel-head {
    padding-top: 12px;
  }

  .panel-head::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 38px;
    height: 4px;
    margin-left: -19px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
  }

  .hint {
    font-size: 11px;
    padding: 8px 13px;
  }
}

@media (max-height: 520px) {
  .hint {
    display: none;
  }
}

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