:root {
  color-scheme: dark;
  --bg: #070b14;
  --bg-2: #0b1220;
  --surface: rgba(17, 26, 41, 0.88);
  --surface-solid: #111a29;
  --surface-raised: #162236;
  --text: #edf5ff;
  --muted: #8f9eb5;
  --accent: #55d6e8;
  --accent-2: #a78bfa;
  --radius: 16px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Space Grotesk", "Inter", ui-sans-serif, system-ui, sans-serif;
  --line: rgba(157, 184, 216, 0.15);
  --line-strong: rgba(157, 184, 216, 0.27);
  --panel-shadow: 0 20px 55px rgba(0, 0, 0, 0.32);
  --control-bg: #0b1321;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  scrollbar-color: #293a52 #080d17;
  scrollbar-width: thin;
}

body {
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background:
    radial-gradient(circle at 14% -8%, rgba(85, 214, 232, 0.09), transparent 33rem),
    radial-gradient(circle at 92% 8%, rgba(167, 139, 250, 0.09), transparent 31rem),
    linear-gradient(155deg, #070b14 0%, #080e19 52%, #070b14 100%);
}

button,
input,
select,
textarea,
output {
  font: inherit;
}

button,
select,
input[type="range"],
input[type="checkbox"] {
  touch-action: manipulation;
}

button {
  color: inherit;
}

h1,
h2,
h3,
h4,
.title {
  margin-top: 0;
  font-family: var(--display);
  letter-spacing: -0.025em;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

[hidden] {
  display: none !important;
}

::selection {
  color: #041015;
  background: rgba(85, 214, 232, 0.88);
}

::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: #2a3b53;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: #3a506e;
  background-clip: padding-box;
}

.app {
  width: 100%;
  max-width: 1600px;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 18px clamp(14px, 2.4vw, 34px) 28px;
}

.app > *,
.workstation,
.workspace,
.workstation-grid,
.viewer-column,
.viewport-column,
.inspector,
.library-panel,
.card,
.row,
.stack {
  min-width: 0;
}

/* Header and compound search */
.app-header,
.workstation-header,
.app > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 4px 0;
}

.brand,
.header-copy,
.header-title {
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark,
.logo-mark {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(85, 214, 232, 0.3);
  border-radius: 13px;
  color: var(--accent);
  background:
    linear-gradient(145deg, rgba(85, 214, 232, 0.13), rgba(167, 139, 250, 0.09)),
    #0d1625;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.05), 0 0 28px rgba(85, 214, 232, 0.08);
}

.app-header h1,
.workstation-header h1,
.app > header h1,
.brand .title {
  margin: 0;
  color: #f5f9ff;
  font-size: clamp(21px, 2.5vw, 30px);
  font-weight: 650;
  line-height: 1.12;
}

.header-copy p,
.brand p,
.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.015em;
}

.header-actions,
.search-bar,
.search-row,
.compound-search {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.search-bar,
.search-row,
.compound-search {
  flex: 1 1 420px;
  max-width: 610px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(10, 17, 29, 0.82);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(16px);
}

#compound-search {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  outline: none;
  color: var(--text);
  background: transparent;
  font-size: 14px;
}

#compound-search::placeholder {
  color: #74869f;
  opacity: 1;
}

#compound-search:focus-visible {
  border-color: rgba(85, 214, 232, 0.55);
  background: rgba(85, 214, 232, 0.035);
  box-shadow: 0 0 0 3px rgba(85, 214, 232, 0.1);
}

#search-btn {
  flex: 0 0 auto;
  min-height: 42px;
}

/* Buttons */
.btn,
button {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  padding: 9px 14px;
  color: #e9f2ff;
  background: linear-gradient(180deg, rgba(27, 40, 60, 0.96), rgba(17, 27, 43, 0.96));
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.035);
  font-weight: 560;
  line-height: 1.25;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease,
    box-shadow 160ms ease, transform 160ms ease, opacity 160ms ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover,
button:hover {
  border-color: rgba(85, 214, 232, 0.42);
  color: #ffffff;
  background: linear-gradient(180deg, rgba(34, 51, 75, 0.98), rgba(20, 33, 51, 0.98));
}

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

.btn.primary,
button.primary,
#search-btn,
#load-water {
  border-color: rgba(85, 214, 232, 0.48);
  color: #061318;
  background: linear-gradient(135deg, #69deed, #55d6e8 56%, #78cfea);
  box-shadow: 0 6px 22px rgba(85, 214, 232, 0.13), inset 0 1px rgba(255, 255, 255, 0.35);
  font-weight: 700;
}

.btn.primary:hover,
button.primary:hover,
#search-btn:hover,
#load-water:hover {
  border-color: #9beef7;
  color: #020b0e;
  background: linear-gradient(135deg, #8ae9f4, #65deed);
  box-shadow: 0 8px 28px rgba(85, 214, 232, 0.21);
}

.btn.ghost,
button.ghost {
  border-color: var(--line);
  background: rgba(12, 20, 33, 0.5);
  box-shadow: none;
}

.btn.danger,
button.danger {
  border-color: rgba(251, 113, 133, 0.35);
  color: #fecdd3;
}

.btn.big {
  min-height: 50px;
  padding-inline: 21px;
}

button:disabled,
.btn:disabled,
input:disabled,
select:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

:where(button, .btn, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(85, 214, 232, 0.11);
}

/* Library */
.library-panel,
.library-card,
.library-section {
  margin-bottom: 16px;
  padding: 13px 14px 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(110deg, rgba(17, 26, 41, 0.83), rgba(12, 20, 34, 0.74));
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.025);
  backdrop-filter: blur(18px);
}

.library-heading,
.section-heading,
.inspector-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.library-heading h2,
.section-heading h2,
.inspector-heading h2,
.inspector h2 {
  margin: 0;
  color: #eaf3ff;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0;
}

.library-heading .muted,
.section-heading .muted {
  font-size: 12px;
}

#library {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  gap: 9px;
  margin: 0;
  padding: 2px 2px 8px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 2px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

#library > button,
#library [data-structure] {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  min-width: 116px;
  min-height: 58px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 3px;
  padding: 10px 13px;
  scroll-snap-align: start;
  border-color: rgba(157, 184, 216, 0.16);
  border-radius: 12px;
  text-align: left;
  white-space: nowrap;
  background:
    radial-gradient(circle at 90% 5%, rgba(85, 214, 232, 0.07), transparent 55%),
    rgba(12, 21, 35, 0.92);
}

#library > button::before,
#library [data-structure]::before {
  width: 7px;
  height: 7px;
  margin-bottom: 2px;
  border: 1px solid rgba(85, 214, 232, 0.55);
  border-radius: 50%;
  background: rgba(85, 214, 232, 0.25);
  box-shadow: 11px 3px 0 -1px rgba(167, 139, 250, 0.42);
  content: "";
}

#library > button:hover,
#library [data-structure]:hover {
  border-color: rgba(85, 214, 232, 0.43);
  background-color: rgba(20, 34, 52, 0.96);
}

#library > button.active,
#library > button[aria-pressed="true"],
#library [data-structure].active,
#library [data-structure][aria-pressed="true"] {
  border-color: rgba(85, 214, 232, 0.65);
  color: #dffcff;
  background:
    linear-gradient(135deg, rgba(85, 214, 232, 0.13), rgba(167, 139, 250, 0.08)),
    #102033;
  box-shadow: inset 0 0 0 1px rgba(85, 214, 232, 0.08), 0 5px 20px rgba(0, 0, 0, 0.16);
}

#library small,
#library .formula,
#library .muted {
  color: var(--muted);
  font-size: 11px;
  font-weight: 450;
}

#load-water {
  flex: 0 0 auto;
}

/* Main workstation grid */
.workstation,
.workspace,
.workstation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.viewer-column,
.viewport-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.viewport-panel,
.viewer-panel,
.viewport-wrap {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: #080e19;
  box-shadow: var(--panel-shadow), inset 0 1px rgba(255, 255, 255, 0.03);
}

#viewport {
  position: relative;
  isolation: isolate;
  width: 100%;
  max-width: 100%;
  height: 48vh;
  min-height: 340px;
  max-height: 620px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 19px;
  background:
    radial-gradient(circle at 50% 38%, rgba(28, 54, 79, 0.38), transparent 55%),
    linear-gradient(160deg, #0a1220, #070b14 75%);
  box-shadow: var(--panel-shadow), inset 0 1px rgba(255, 255, 255, 0.035);
}

.viewport-panel #viewport,
.viewer-panel #viewport,
.viewport-wrap #viewport {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

#viewport::after {
  position: absolute;
  z-index: 2;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.2), inset 0 0 0 1px rgba(255, 255, 255, 0.018);
  content: "";
  pointer-events: none;
}

#viewport canvas {
  position: absolute;
  z-index: 0;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  outline: none;
  touch-action: none;
}

#viewport canvas:focus-visible {
  outline: 2px solid rgba(85, 214, 232, 0.8);
  outline-offset: -3px;
}

.viewport-hud,
.viewport-top,
.viewport-bottom,
.viewport-toolbar {
  position: absolute;
  z-index: 4;
  right: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.viewport-hud > *,
.viewport-top > *,
.viewport-bottom > *,
.viewport-toolbar > * {
  pointer-events: auto;
}

.viewport-top,
.viewport-hud {
  top: 12px;
}

.viewport-bottom,
.viewport-toolbar {
  bottom: 12px;
}

.glass,
.hud,
.viewport-hud > *,
.viewport-top > *,
.viewport-bottom > * {
  border: 1px solid rgba(157, 184, 216, 0.17);
  border-radius: 11px;
  background: rgba(9, 16, 28, 0.72);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(12px);
}

/* Loading */
#loading {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  padding: 20px;
  color: #dff9fc;
  background: rgba(7, 11, 20, 0.7);
  font-family: var(--display);
  font-size: 13px;
  font-weight: 550;
  letter-spacing: 0.02em;
  text-align: center;
  backdrop-filter: blur(8px);
}

#loading::before {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(85, 214, 232, 0.17);
  border-top-color: var(--accent);
  border-right-color: var(--accent-2);
  border-radius: 50%;
  content: "";
  animation: lattice-spin 850ms linear infinite;
}

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

/* Structure summary and badges */
.structure-summary,
.structure-info,
.model-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(17, 26, 41, 0.72);
}

.structure-summary h2,
.structure-info h2,
#structure-name {
  margin: 0;
  color: #f3f8ff;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 620;
  letter-spacing: -0.015em;
}

#formula {
  color: #c9f8ff;
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: 0.035em;
}

#source,
.badge,
.chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 24px;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid rgba(85, 214, 232, 0.19);
  border-radius: 999px;
  color: #a9dce5;
  background: rgba(85, 214, 232, 0.065);
  font-size: 11px;
  font-weight: 550;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.badge.violet,
.chip.violet {
  border-color: rgba(167, 139, 250, 0.25);
  color: #d2c3fd;
  background: rgba(167, 139, 250, 0.08);
}

.stats,
.structure-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 15, 26, 0.54);
}

.stat b {
  display: block;
  color: #f4f8ff;
  font-family: var(--display);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.stat span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

#atom-count,
#bond-count {
  color: #f3f8ff;
  font-variant-numeric: tabular-nums;
}

#status {
  display: block;
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

#status:empty {
  display: none;
}

#status.error,
#status[data-error="true"] {
  color: #fda4af;
}

/* Inspector */
.inspector,
aside.inspector,
section.inspector {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 13px;
  padding: 16px;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 20px 20px 14px 14px;
  background:
    linear-gradient(160deg, rgba(21, 32, 50, 0.94), rgba(13, 22, 36, 0.94)),
    var(--surface-solid);
  box-shadow: var(--panel-shadow), inset 0 1px rgba(255, 255, 255, 0.035);
  backdrop-filter: blur(20px);
}

.inspector .card,
.inspector section {
  min-width: 0;
  padding: 0 0 13px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.inspector .card:last-child,
.inspector section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.inspector h3,
.control-group-title {
  margin: 0 0 9px;
  color: #b8c8dd;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.105em;
  text-transform: uppercase;
}

.inspector .stack {
  gap: 11px;
}

.inspector .row,
.form-row,
.control-row,
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  min-height: 40px;
}

.form-row > label,
.control-row > label,
.setting-row > label,
.field > label,
.inspector label {
  color: #c2cfe0;
  font-size: 13px;
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 6px;
}

.field + .field {
  margin-top: 2px;
}

select,
.field select,
.field input:not([type="range"]):not([type="checkbox"]),
.inspector input:not([type="range"]):not([type="checkbox"]) {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 8px 32px 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  color: #e9f2ff;
  background-color: var(--control-bg);
  font-size: 14px;
  cursor: pointer;
}

select:hover,
.field input:hover {
  border-color: rgba(85, 214, 232, 0.35);
}

select:focus-visible,
.field input:focus-visible {
  border-color: var(--accent);
}

select option {
  color: #edf5ff;
  background: #101a2a;
}

/* Switch checkboxes retain generous label-row hit areas. */
#cell-toggle,
#surface-toggle,
#contour-toggle {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 28px;
  min-height: 28px;
  margin: 7px 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid #34465f;
  border-radius: 999px;
  outline: none;
  background: #111c2c;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

#cell-toggle::before,
#surface-toggle::before,
#contour-toggle::before {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #8798ae;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  content: "";
  transition: transform 180ms ease, background-color 180ms ease;
}

#cell-toggle:checked,
#surface-toggle:checked,
#contour-toggle:checked {
  border-color: rgba(85, 214, 232, 0.72);
  background: rgba(85, 214, 232, 0.24);
  box-shadow: 0 0 16px rgba(85, 214, 232, 0.09);
}

#cell-toggle:checked::before,
#surface-toggle:checked::before,
#contour-toggle:checked::before {
  background: var(--accent);
  transform: translateX(20px);
}

/* Ranges and adjacent output labels */
.range-row,
.slider-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

input[type="range"] {
  width: 100%;
  min-width: 0;
  height: 32px;
  min-height: 32px;
  margin: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  outline: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 5px;
  border: 1px solid rgba(157, 184, 216, 0.12);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(85, 214, 232, 0.42), rgba(167, 139, 250, 0.32));
}

input[type="range"]::-moz-range-track {
  width: 100%;
  height: 5px;
  border: 1px solid rgba(157, 184, 216, 0.12);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(85, 214, 232, 0.42), rgba(167, 139, 250, 0.32));
}

input[type="range"]::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  margin-top: -8px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid #b8f4fb;
  border-radius: 50%;
  background: #183247;
  box-shadow: 0 0 0 4px rgba(85, 214, 232, 0.09), 0 3px 8px rgba(0, 0, 0, 0.35);
  transition: box-shadow 150ms ease, transform 150ms ease;
}

input[type="range"]::-moz-range-thumb {
  width: 17px;
  height: 17px;
  border: 2px solid #b8f4fb;
  border-radius: 50%;
  background: #183247;
  box-shadow: 0 0 0 4px rgba(85, 214, 232, 0.09), 0 3px 8px rgba(0, 0, 0, 0.35);
}

input[type="range"]:hover::-webkit-slider-thumb {
  box-shadow: 0 0 0 6px rgba(85, 214, 232, 0.13), 0 3px 8px rgba(0, 0, 0, 0.35);
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.08);
}

output,
#isovalue-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 27px;
  padding: 3px 8px;
  border: 1px solid rgba(167, 139, 250, 0.2);
  border-radius: 8px;
  color: #d9ccff;
  background: rgba(167, 139, 250, 0.07);
  font-family: var(--display);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Atom selection readout */
#atom-info {
  min-width: 0;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid rgba(85, 214, 232, 0.17);
  border-radius: 11px;
  color: #bcd0e4;
  background:
    linear-gradient(105deg, rgba(85, 214, 232, 0.055), transparent),
    rgba(7, 14, 25, 0.62);
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

#atom-info:empty {
  display: none;
}

#atom-info b,
#atom-info strong {
  color: #effbff;
  font-family: var(--display);
}

#viewport #atom-info {
  position: absolute;
  z-index: 5;
  right: 12px;
  bottom: 12px;
  max-width: min(320px, calc(100% - 24px));
  background: rgba(8, 16, 28, 0.8);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

/* View and export actions */
.view-actions,
.export-actions,
.inspector-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.view-actions .btn,
.export-actions .btn,
.inspector-actions .btn,
.view-actions button,
.export-actions button,
.inspector-actions button {
  width: 100%;
  min-width: 0;
  padding-inline: 10px;
}

#reset-view,
#save-view,
#export-xyz,
#export-png,
#share {
  white-space: normal;
}

.export-popover,
[popover].export-popover {
  width: min(330px, calc(100vw - 28px));
  margin: auto;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  color: var(--text);
  background: rgba(15, 24, 39, 0.98);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.6);
}

.export-popover::backdrop {
  background: rgba(2, 6, 12, 0.68);
  backdrop-filter: blur(4px);
}

/* Toast feedback */
.toast,
#toast {
  position: fixed;
  z-index: 1000;
  right: 18px;
  bottom: 18px;
  left: auto;
  width: fit-content;
  max-width: min(420px, calc(100vw - 28px));
  min-height: 44px;
  padding: 11px 15px;
  border: 1px solid rgba(85, 214, 232, 0.3);
  border-radius: 12px;
  color: #e9fbff;
  background: rgba(14, 27, 42, 0.96);
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.4), 0 0 25px rgba(85, 214, 232, 0.06);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  backdrop-filter: blur(16px);
  pointer-events: none;
}

.toast:empty,
#toast:empty {
  visibility: hidden;
  opacity: 0;
}

.toast.error,
#toast.error {
  border-color: rgba(251, 113, 133, 0.42);
  color: #ffe4e6;
}

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

.gradient-text {
  color: var(--accent);
  background: linear-gradient(100deg, #75e4f0, #b9a6fc);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Desktop workstation */
@media (min-width: 800px) {
  .app {
    padding-top: 22px;
  }

  .workstation,
  .workspace,
  .workstation-grid {
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 18px;
  }

  #viewport {
    height: clamp(510px, calc(100vh - 245px), 790px);
    height: clamp(510px, calc(100dvh - 245px), 790px);
    min-height: 510px;
    max-height: 790px;
  }

  .inspector,
  aside.inspector,
  section.inspector {
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: 18px;
    overscroll-behavior: contain;
  }
}

@media (min-width: 1180px) {
  .workstation,
  .workspace,
  .workstation-grid {
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 20px;
  }

  .library-panel,
  .library-card,
  .library-section {
    padding-inline: 16px;
  }
}

/* Phone and narrow-tablet bottom-sheet layout */
@media (max-width: 799px) {
  .app {
    padding: 12px 12px 22px;
  }

  .app-header,
  .workstation-header,
  .app > header {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
  }

  .brand-mark,
  .logo-mark {
    width: 38px;
    height: 38px;
  }

  .search-bar,
  .search-row,
  .compound-search {
    width: 100%;
    max-width: none;
    flex-basis: auto;
  }

  .library-panel,
  .library-card,
  .library-section {
    margin-bottom: 12px;
    padding: 11px 10px 10px;
    border-radius: 14px;
  }

  #library {
    margin-inline: -1px;
    padding-bottom: 7px;
  }

  #library > button,
  #library [data-structure] {
    min-width: 108px;
    min-height: 56px;
  }

  .workstation,
  .workspace,
  .workstation-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  #viewport {
    height: 48vh;
    min-height: 340px;
    max-height: 560px;
    border-radius: 16px;
  }

  .viewport-panel,
  .viewer-panel,
  .viewport-wrap {
    border-radius: 16px;
  }

  .inspector,
  aside.inspector,
  section.inspector {
    position: relative;
    max-height: none;
    margin-top: -2px;
    padding: 16px 14px;
    overflow: visible;
    border-top-color: rgba(85, 214, 232, 0.21);
    border-radius: 22px 22px 14px 14px;
    box-shadow: 0 -10px 35px rgba(0, 0, 0, 0.16), var(--panel-shadow);
  }

  .inspector::before {
    align-self: center;
    width: 38px;
    height: 4px;
    margin: -7px 0 1px;
    border-radius: 999px;
    background: rgba(143, 158, 181, 0.3);
    content: "";
  }

  .inspector .row,
  .form-row,
  .control-row,
  .setting-row {
    min-height: 44px;
  }

  select,
  .field select,
  .field input:not([type="range"]):not([type="checkbox"]),
  .inspector input:not([type="range"]):not([type="checkbox"]) {
    min-height: 44px;
    font-size: 16px;
  }

  input[type="range"] {
    height: 40px;
    min-height: 40px;
  }

  .structure-summary,
  .structure-info,
  .model-info {
    padding: 10px 12px;
  }
}

@media (max-width: 480px) {
  .app {
    padding-inline: 9px;
  }

  .app-header h1,
  .workstation-header h1,
  .app > header h1,
  .brand .title {
    font-size: 22px;
  }

  .header-copy p,
  .brand p,
  .subtitle {
    font-size: 11px;
  }

  .search-bar,
  .search-row,
  .compound-search {
    gap: 5px;
    padding: 4px;
  }

  #compound-search {
    padding-inline: 9px;
    font-size: 16px;
  }

  #search-btn {
    padding-inline: 12px;
  }

  .structure-summary,
  .structure-info,
  .model-info {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
  }

  .view-actions,
  .export-actions,
  .inspector-actions {
    gap: 7px;
  }

  .toast,
  #toast {
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-width: none;
  }
}

@media (max-width: 350px) {
  .view-actions,
  .export-actions,
  .inspector-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  #library > button,
  #library [data-structure] {
    min-width: 100px;
  }
}

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

  #loading::before {
    animation-duration: 1600ms;
  }
}

/* Viewport-bound workstation: panels scroll internally, never the document. */
html,
body {
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.app > header,
.app-header,
.workstation-header {
  flex: none;
  min-width: 0;
  max-width: 100%;
}

.workstation,
.workspace,
.workstation-grid {
  flex: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  margin-bottom: 0;
  overflow: hidden;
}

.workspace-main {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.library-panel,
.library-card,
.library-section,
.library,
.inspector,
aside.inspector,
section.inspector {
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.viewport,
.viewport-panel,
.viewer-panel,
.viewport-wrap,
#viewport {
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  overflow: hidden;
}

.viewport,
.viewport-panel,
.viewer-panel,
#viewport {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.viewport-bar,
.viewport-panel > header,
.viewer-panel > header,
#viewport > header {
  flex: none;
}

.canvas-wrap,
.canvas-container,
.viewport-canvas,
#viewport {
  flex: 1;
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.viewport canvas,
#viewport canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
}

#atom-info,
.atom-readout,
.atom-info,
.view-hud,
.viewport-hud,
.hud {
  right: 8px;
  left: 8px;
  width: auto;
  max-width: calc(100vw - 16px);
  overflow-wrap: anywhere;
}

.toast,
#toast {
  max-width: calc(100vw - 16px);
  overflow-wrap: anywhere;
}

@media (min-width: 800px) {
  .workstation,
  .workspace,
  .workstation-grid {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: minmax(0, 1fr);
  }

  .workspace-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .library-panel,
  .library-card,
  .library-section {
    margin-bottom: 12px;
  }

  .inspector,
  aside.inspector,
  section.inspector {
    position: relative;
    top: auto;
    max-height: none;
    height: 100%;
  }

  #viewport {
    height: 100%;
    min-height: 0;
    max-height: none;
  }
}

@media (max-width: 799px) {
  .app {
    padding: 12px;
  }

  .workstation,
  .workspace,
  .workstation-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(140px, 1fr) minmax(120px, 1fr);
    gap: 12px;
  }

  .workspace-main {
    display: contents;
  }

  .library-panel,
  .library-card,
  .library-section {
    margin-bottom: 0;
    overflow-x: auto;
    overflow-y: hidden;
  }

  #viewport {
    height: 100%;
    min-height: 0;
    max-height: none;
  }

  .inspector,
  aside.inspector,
  section.inspector {
    position: relative;
    top: auto;
    max-height: none;
    height: 100%;
    margin-top: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .toast,
  #toast {
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    max-width: calc(100vw - 16px);
  }
}
