:root {
  color-scheme: dark;
  --bg: #081014;
  --bg-elevated: #101b20;
  --panel: #121f25;
  --panel-strong: #17282f;
  --text: #eaf5f6;
  --muted: #91a6aa;
  --subtle: #5f7378;
  --line: rgba(178, 213, 217, 0.16);
  --line-strong: rgba(178, 213, 217, 0.28);
  --accent: #45d6b5;
  --accent-2: #76a9ff;
  --warn: #f4c26b;
  --danger: #ff7a9a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #edf3f3;
  --bg-elevated: #f8fbfb;
  --panel: #ffffff;
  --panel-strong: #eef5f4;
  --text: #10191c;
  --muted: #587074;
  --subtle: #7a9093;
  --line: rgba(30, 60, 66, 0.14);
  --line-strong: rgba(30, 60, 66, 0.24);
  --shadow: 0 24px 80px rgba(38, 69, 76, 0.12);
}
* { box-sizing: border-box; }
html { height: 100%; overflow: hidden; }
body {
  height: 100%;
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: linear-gradient(180deg, rgba(69, 214, 181, 0.1), transparent 34rem), radial-gradient(circle at 20% 0%, rgba(118, 169, 255, 0.12), transparent 28rem), var(--bg);
  color: var(--text);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.app-shell { display: flex; flex-direction: column; height: 100dvh; min-height: 0; overflow: hidden; padding: 12px 18px 18px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; margin: 0 0 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { display: grid; width: 30px; height: 30px; place-items: center; border: 1px solid var(--line-strong); border-radius: var(--radius); background: linear-gradient(135deg, var(--panel-strong), rgba(69, 214, 181, 0.16)); color: var(--accent); font-size: 0.66rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.08rem, 2vw, 1.28rem); letter-spacing: 0; line-height: 1; }
.brand p, .eyebrow, label, .list-header, .description, .empty-state { color: var(--muted); }
.brand p { margin-top: 2px; font-size: 0.72rem; }
.header-actions { display: flex; gap: 8px; }
.icon-button, .cid-button, .viewer-actions button, .cid-row button, .modal-actions button { border: 1px solid var(--line-strong); background: var(--panel); color: var(--text); border-radius: var(--radius); transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease; }
.icon-button { width: 32px; height: 32px; }
.cid-button { min-width: 48px; height: 32px; padding: 0 10px; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.08em; }
.icon-button:hover, .cid-button:hover, .viewer-actions button:hover, .cid-row button:hover, .modal-actions button:hover { transform: translateY(-1px); border-color: rgba(69, 214, 181, 0.65); }
.cid-row button:disabled { cursor: progress; opacity: 0.62; transform: none; }
.theme-icon { display: block; width: 15px; height: 15px; margin: 0 auto; border: 2px solid currentColor; border-radius: 50%; box-shadow: inset -5px -3px 0 var(--accent); }
:root[data-theme="light"] .theme-icon { box-shadow: inset 0 0 0 5px var(--warn); }
.workspace { position: relative; flex: 1 1 auto; width: 100%; max-width: 1500px; min-height: 0; margin: 0 auto; }
.sidebar, .viewer-panel, .info-panel { border: 1px solid var(--line); border-radius: var(--radius); background: color-mix(in srgb, var(--panel) 92%, transparent); box-shadow: var(--shadow); }
.sidebar {
  position: absolute;
  z-index: 20;
  top: 16px;
  left: 16px;
  width: min(330px, calc(100vw - 44px));
  max-height: calc(100dvh - 88px);
  padding: 16px;
  overflow: hidden;
  opacity: 0.18;
  transform: translateX(-78%);
  backdrop-filter: blur(18px);
  transition: opacity 180ms ease, transform 180ms ease, background-color 180ms ease;
}
.sidebar:hover,
.sidebar:focus-within {
  opacity: 1;
  transform: translateX(0);
}
.search-wrap, .select-wrap { display: grid; gap: 8px; margin-bottom: 14px; }
label, .eyebrow, .list-header { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase; }
input, select { width: 100%; min-height: 42px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg-elevated); color: var(--text); outline: none; padding: 0 12px; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(69, 214, 181, 0.14); }
.list-header { display: flex; justify-content: space-between; margin: 16px 0 10px; }
.peptide-list { display: grid; gap: 8px; max-height: calc(100dvh - 330px); overflow: auto; padding-right: 3px; }
.peptide-card { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elevated); color: var(--text); padding: 12px; text-align: left; }
.peptide-card:hover, .peptide-card.active { border-color: rgba(69, 214, 181, 0.65); background: color-mix(in srgb, var(--panel-strong) 82%, var(--accent) 8%); }
.peptide-card strong { display: block; margin-bottom: 5px; font-size: 0.98rem; }
.peptide-card > span:not(.peptide-tags):not(.peptide-cid) { display: -webkit-box; overflow: hidden; color: var(--muted); font-size: 0.86rem; line-height: 1.45; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.peptide-card .peptide-cid { display: block; margin-top: -2px; color: var(--subtle); font-size: 0.72rem; font-weight: 760; letter-spacing: 0.04em; }
.peptide-card .peptide-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.peptide-card .peptide-tags em { display: inline-flex; max-width: 100%; min-height: 22px; align-items: center; border: 1px solid var(--line); border-radius: 999px; background: color-mix(in srgb, var(--panel) 78%, transparent); color: var(--muted); padding: 3px 7px; font-size: 0.7rem; font-style: normal; font-weight: 720; overflow-wrap: anywhere; }
.peptide-card .peptide-tags em { cursor: pointer; transition: border-color 160ms ease, color 160ms ease, background-color 160ms ease; }
.peptide-card .peptide-tags em:hover { border-color: rgba(69, 214, 181, 0.7); color: var(--text); background: color-mix(in srgb, var(--panel-strong) 74%, var(--accent) 18%); }
.viewer-panel { position: relative; height: 100%; min-width: 0; min-height: 0; overflow: hidden; }
.viewer-toolbar {
  position: absolute;
  z-index: 12;
  top: 16px;
  right: 16px;
  left: min(370px, 34vw);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 72%, transparent);
  backdrop-filter: blur(18px);
  opacity: 0.5;
  transition: opacity 180ms ease, background-color 180ms ease;
}
.viewer-toolbar:hover,
.viewer-toolbar:focus-within {
  opacity: 1;
}
h2 { margin-top: 4px; font-size: clamp(1.45rem, 3vw, 2.35rem); letter-spacing: 0; }
.viewer-actions { display: flex; gap: 8px; }
.viewer-actions button { min-width: 74px; min-height: 38px; }
.viewer-stage { position: absolute; inset: 0; min-height: 0; background: linear-gradient(rgba(145, 166, 170, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(145, 166, 170, 0.06) 1px, transparent 1px), radial-gradient(circle at 50% 45%, rgba(69, 214, 181, 0.08), transparent 25rem), #071014; background-size: 32px 32px, 32px 32px, auto, auto; }
:root[data-theme="light"] .viewer-stage { background: linear-gradient(rgba(30, 60, 66, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(30, 60, 66, 0.05) 1px, transparent 1px), radial-gradient(circle at 50% 45%, rgba(69, 214, 181, 0.13), transparent 25rem), #f8fbfb; background-size: 32px 32px, 32px 32px, auto, auto; }
#viewer { position: absolute; inset: 0; }
.viewer-status { position: absolute; left: 16px; bottom: 16px; max-width: min(460px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: var(--radius); background: color-mix(in srgb, var(--panel) 88%, transparent); color: var(--muted); padding: 9px 11px; font-size: 0.86rem; backdrop-filter: blur(12px); }
.viewer-status.ready { color: var(--accent); }
.viewer-status.error { color: var(--danger); }
.details-grid {
  position: absolute;
  z-index: 14;
  right: 16px;
  bottom: 16px;
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(260px, 1.2fr);
  width: min(640px, calc(100% - 390px));
  max-height: min(46vh, 430px);
  gap: 12px;
  overflow: auto;
  opacity: 0.14;
  transform: translateY(calc(100% - 36px));
  transition: opacity 180ms ease, transform 180ms ease;
}
.details-grid:hover,
.details-grid:focus-within {
  opacity: 1;
  transform: translateY(0);
}
.highlight-dock {
  position: absolute;
  z-index: 16;
  left: 16px;
  bottom: 16px;
  width: min(315px, calc(100vw - 44px));
  max-height: min(50vh, 520px);
  overflow: auto;
  opacity: 0.16;
  transform: translateY(calc(100% - 38px));
  transition: opacity 180ms ease, transform 180ms ease, background-color 180ms ease;
}
.highlight-dock:hover,
.highlight-dock:focus-within {
  opacity: 1;
  transform: translateY(0);
}
:root[data-panel-lock] .sidebar:hover,
:root[data-panel-lock] .sidebar:focus-within {
  opacity: 0.18;
  transform: translateX(-78%);
}
:root[data-panel-lock] .viewer-toolbar:hover,
:root[data-panel-lock] .viewer-toolbar:focus-within {
  opacity: 0.5;
}
:root[data-panel-lock] .details-grid:hover,
:root[data-panel-lock] .details-grid:focus-within {
  opacity: 0.14;
  transform: translateY(calc(100% - 36px));
}
:root[data-panel-lock] .highlight-dock:hover,
:root[data-panel-lock] .highlight-dock:focus-within {
  opacity: 0.16;
  transform: translateY(calc(100% - 38px));
}
:root[data-panel-lock] .sidebar,
:root[data-panel-lock] .viewer-toolbar,
:root[data-panel-lock] .details-grid,
:root[data-panel-lock] .highlight-dock {
  pointer-events: none;
}
:root[data-panel-lock="sidebar"] .sidebar,
:root[data-panel-lock="sidebar"] .sidebar:hover,
:root[data-panel-lock="sidebar"] .sidebar:focus-within {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}
:root[data-panel-lock="toolbar"] .viewer-toolbar,
:root[data-panel-lock="toolbar"] .viewer-toolbar:hover,
:root[data-panel-lock="toolbar"] .viewer-toolbar:focus-within {
  opacity: 1;
  pointer-events: auto;
}
:root[data-panel-lock="details"] .details-grid,
:root[data-panel-lock="details"] .details-grid:hover,
:root[data-panel-lock="details"] .details-grid:focus-within {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
:root[data-panel-lock="highlights"] .highlight-dock,
:root[data-panel-lock="highlights"] .highlight-dock:hover,
:root[data-panel-lock="highlights"] .highlight-dock:focus-within {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.highlight-dock .panel-title {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: -15px -15px 12px;
  padding: 12px 15px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  backdrop-filter: blur(18px);
}
.highlight-dock .residue-meta {
  grid-template-columns: 1fr;
}
.highlight-dock .legend {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.highlight-dock .legend-item {
  justify-content: flex-start;
  width: 100%;
  min-height: 30px;
  padding: 5px 9px;
}
.highlight-dock .residue-group {
  margin: 10px 0 0;
}
.info-panel {
  box-shadow: none;
  padding: 15px;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
  backdrop-filter: blur(18px);
}
.info-panel[hidden] { display: none; }
.info-panel.wide { grid-column: 1 / -1; }
.panel-title { margin-bottom: 12px; }
h3 { margin-top: 3px; font-size: 1rem; }
.description { line-height: 1.6; }
.tags, .legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.tag, .legend-item { display: inline-flex; align-items: center; gap: 8px; min-height: 28px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-elevated); color: var(--muted); padding: 5px 10px; font-size: 0.8rem; font-weight: 650; }
.legend-item.active { border-color: var(--accent); color: var(--text); background: color-mix(in srgb, var(--panel-strong) 72%, var(--accent) 16%); }
button.legend-item { cursor: pointer; }
.legend-swatch { width: 10px; height: 10px; border-radius: 50%; }
.residue-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-bottom: 14px; }
.residue-group { flex-basis: 100%; margin: 8px 0 -2px; color: var(--subtle); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.stat { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elevated); padding: 10px; }
.stat dt { margin-bottom: 6px; color: var(--subtle); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.stat dd { margin: 0; overflow-wrap: anywhere; font-size: 1rem; font-weight: 720; }
.empty-state { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 18px; text-align: center; }
.modal-backdrop {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 9, 12, 0.56);
  backdrop-filter: blur(12px);
}
.modal-backdrop[hidden] { display: none; }
.cid-modal {
  width: min(460px, 100%);
  max-height: min(90dvh, 620px);
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: var(--shadow);
  padding: 18px;
}
.cid-form { display: grid; gap: 9px; }
.cid-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.cid-row button { min-height: 42px; padding: 0 14px; font-weight: 800; }
.cid-help { color: var(--muted); font-size: 0.78rem; line-height: 1.5; }
.cid-result {
  min-height: 42px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--muted);
  padding: 11px;
  font-size: 0.86rem;
  line-height: 1.5;
}
.cid-result strong { color: var(--text); }
.cid-result a { color: var(--accent); font-weight: 800; }
.cid-result.error { border-color: rgba(255, 122, 154, 0.5); color: var(--danger); }
.cid-result.ready { border-color: rgba(69, 214, 181, 0.5); color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
.modal-actions button { min-height: 36px; padding: 0 12px; }
@media (max-width: 900px) {
  .app-shell { padding: 10px; }
  .sidebar { top: 12px; left: 12px; max-height: min(42dvh, 320px); }
  .peptide-list { max-height: min(170px, 22dvh); }
  .viewer-toolbar { left: 12px; right: 12px; top: 50px; align-items: flex-start; flex-direction: column; }
  .details-grid { left: auto; right: 12px; bottom: 12px; width: min(58vw, 360px); grid-template-columns: 1fr; max-height: min(42dvh, 340px); }
  .highlight-dock { left: 12px; bottom: 12px; width: min(38vw, 300px); max-height: min(44dvh, 360px); }
}
@media (max-width: 900px) and (hover: none), (max-width: 900px) and (pointer: coarse) {
  .sidebar:hover,
  .sidebar:focus-within {
    opacity: 0.18;
    transform: translateX(-78%);
  }
  .viewer-toolbar:hover,
  .viewer-toolbar:focus-within {
    opacity: 0.5;
  }
  .details-grid:hover,
  .details-grid:focus-within {
    opacity: 0.14;
    transform: translateY(calc(100% - 36px));
  }
  .highlight-dock:hover,
  .highlight-dock:focus-within {
    opacity: 0.16;
    transform: translateY(calc(100% - 38px));
  }
  :root[data-panel-lock="sidebar"] .sidebar {
    opacity: 1;
    transform: translateX(0);
  }
  :root[data-panel-lock="toolbar"] .viewer-toolbar {
    opacity: 1;
  }
  :root[data-panel-lock="details"] .details-grid {
    opacity: 1;
    transform: translateY(0);
  }
  :root[data-panel-lock="highlights"] .highlight-dock {
    opacity: 1;
    transform: translateY(0);
  }
}
@media (max-width: 560px) {
  .topbar { align-items: center; }
  .brand { align-items: center; }
  .brand-mark { width: 28px; height: 28px; }
  .brand p { display: block; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.68rem; }
  .app-shell { padding: 8px; }
  .topbar { margin-bottom: 6px; }
  .sidebar { max-height: min(76dvh, 620px); }
  .peptide-list { max-height: min(430px, 52dvh); }
  .viewer-toolbar { top: 44px; padding: 9px; gap: 8px; }
  h2 { font-size: 1.25rem; }
  .viewer-actions button { min-width: 56px; min-height: 34px; }
  .cid-modal { padding: 14px; }
  .cid-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .details-grid { width: min(54vw, 260px); }
  .highlight-dock { width: min(42vw, 220px); }
  .highlight-dock .residue-meta { display: none; }
}
