:root {
  color-scheme: dark;
  --bg: #070a18;
  --panel: #11172d;
  --panel-strong: #202a4a;
  --ink: #f4f6ff;
  --muted: #b6bfd8;
  --line: rgba(232, 238, 255, 0.15);
  --accent: #86b7ff;
  --accent-2: #ff7ab8;
  --danger: #ff7892;
  --shadow: 0 24px 60px rgba(5, 7, 20, 0.42);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 16% 10%, rgba(134, 183, 255, 0.2), transparent 26rem),
    radial-gradient(circle at 78% 14%, rgba(255, 122, 184, 0.18), transparent 22rem),
    var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
  min-width: 0;
}

button {
  border: 1px solid var(--line);
  background: #18213c;
  color: var(--ink);
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
}

button:hover {
  border-color: rgba(255, 122, 184, 0.58);
}

.app-shell {
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, #fff 0 8%, transparent 9%),
    radial-gradient(circle at 72% 35%, var(--accent-2) 0 13%, transparent 14%),
    radial-gradient(circle at 48% 72%, var(--accent) 0 18%, transparent 19%),
    #1c2749;
  border: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.3rem, 3vw, 2rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p,
.viewer-hud span,
.panel-section p {
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.1rem;
}

.icon-button.active,
.style-choice.active,
.surface-choice.active {
  color: #080a18;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: rgba(255, 255, 255, 0.28);
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  gap: 16px;
  width: 100%;
  min-width: 0;
  min-height: 0;
}

.viewer-panel,
.control-panel {
  min-width: 0;
  background: rgba(17, 23, 45, 0.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.viewer-panel {
  position: relative;
  overflow: hidden;
  min-height: 0;
  border-radius: 8px;
  background: #030515;
  border-color: rgba(134, 183, 255, 0.22);
}

#molCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.volume-host {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.volume-host canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.bond-hover-tooltip {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid rgba(244, 246, 255, 0.22);
  background: rgba(5, 7, 18, 0.88);
  color: var(--ink);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
  backdrop-filter: blur(10px);
}

.viewer-panel.volume-mode #molCanvas {
  opacity: 0;
  pointer-events: none;
}

.viewer-panel.volume-mode .viewer-hud {
  z-index: 2;
}

.viewer-hud {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.viewer-hud > div {
  display: grid;
  gap: 4px;
}

.viewer-hud strong {
  font-size: clamp(1.4rem, 4vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.control-panel {
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  overflow: auto;
}

.panel-section {
  display: grid;
  gap: 12px;
}

h2 {
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

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

.file-drop,
.data-input-panel {
  display: grid;
  gap: 10px;
  min-height: 0;
  border: 1px dashed rgba(134, 183, 255, 0.5);
  border-radius: 8px;
  background: rgba(134, 183, 255, 0.08);
  color: var(--ink);
}

.data-input-panel {
  padding: 12px;
}

.data-input-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.file-picker-button {
  display: inline-grid;
  place-items: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #18213c;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.file-picker-button:hover {
  border-color: rgba(255, 122, 184, 0.58);
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop span {
  max-width: 100%;
  padding: 0 10px;
  overflow-wrap: anywhere;
}

.file-drop.dragging {
  background: rgba(255, 122, 184, 0.16);
  border-color: var(--accent-2);
}

.paste-data-input {
  width: 100%;
  min-height: 126px;
  max-height: 260px;
  resize: vertical;
  border: 1px solid rgba(134, 183, 255, 0.34);
  border-radius: 8px;
  padding: 10px 12px;
  background: #090d1f;
  color: var(--ink);
  line-height: 1.35;
  scrollbar-color: rgba(134, 183, 255, 0.72) rgba(232, 238, 255, 0.1);
}

.paste-data-input::placeholder {
  color: rgba(182, 191, 216, 0.72);
}

.paste-data-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(134, 183, 255, 0.14);
}

.paste-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.paste-hint {
  font-size: 0.78rem;
  line-height: 1.35;
}

.metadata-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metadata-grid span {
  min-height: 40px;
  padding: 10px;
  border-radius: 8px;
  background: #090d1f;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.sample-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  min-height: 72px;
  text-align: left;
}

.sample-card.active {
  border-color: var(--accent);
  background: #202a4a;
}

.sample-card span {
  color: var(--muted);
  font-size: 0.82rem;
}

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

.style-choice,
.surface-choice {
  padding: 0 10px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
  color: var(--muted);
}

.control-row > span {
  min-width: 0;
}

.polish-control input[type="range"] {
  width: min(220px, 58vw);
}

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

.inline-toggles label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  color: var(--muted);
}

input[type="range"] {
  width: min(190px, 56vw);
  accent-color: var(--accent);
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.orbital-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 8px;
}

.compact-control {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
}

.compact-control input[type="range"] {
  width: 100%;
}

.log-panel {
  display: grid;
  gap: 6px;
  max-height: 220px;
  min-height: 120px;
  overflow-y: scroll;
  overflow-x: hidden;
  padding: 2px 6px 2px 0;
  scrollbar-color: rgba(134, 183, 255, 0.72) rgba(232, 238, 255, 0.1);
  scrollbar-width: thin;
}

.log-panel::-webkit-scrollbar {
  width: 10px;
}

.log-panel::-webkit-scrollbar-track {
  background: rgba(232, 238, 255, 0.08);
  border-radius: 999px;
}

.log-panel::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: 999px;
}

.log-entry {
  display: block;
  width: 100%;
  min-height: 38px;
  max-height: 38px;
  overflow-y: hidden;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090d1f;
  color: var(--muted);
  padding: 7px 12px;
  text-align: left;
  line-height: 1.28;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow-wrap: normal;
  word-break: normal;
}

.log-entry:hover {
  border-color: rgba(255, 122, 184, 0.58);
}

.log-entry.active {
  color: var(--ink);
  border-color: var(--accent);
  min-height: 78px;
  max-height: 180px;
  overflow-y: auto;
  padding: 10px 12px;
  white-space: normal;
  text-overflow: clip;
  overflow-wrap: anywhere;
  resize: vertical;
}

.log-entry.error {
  border-color: rgba(255, 120, 146, 0.58);
  color: var(--danger);
}

select {
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090d1f;
  color: var(--ink);
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #090d1f;
  color: var(--ink);
  padding: 12px;
  line-height: 1.45;
}

.builder-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#applyMolecule {
  background: var(--accent);
  color: #080a18;
  border-color: var(--accent);
}

.secondary-action {
  width: 100%;
  background: #18213c;
  overflow-wrap: anywhere;
  white-space: normal;
}

#statusText.error {
  color: var(--danger);
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .viewer-panel {
    min-height: min(64vh, 560px);
  }

  .control-panel {
    max-height: none;
  }
}

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

  .topbar {
    align-items: flex-start;
  }

  .brand p {
    display: none;
  }

  .viewer-panel {
    min-height: 58vh;
  }

  .viewer-hud {
    align-items: start;
    flex-direction: column;
  }

  .sample-grid {
    grid-template-columns: 1fr;
  }
}
