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

:root {
  --bg:      #0e1117;
  --surface: #161b22;
  --border:  #30363d;
  --text:    #e6edf3;
  --muted:   #8b949e;
  --accent:  #58a6ff;
  --accent2: #3fb950;
  --warn:    #d29922;
  --fail:    #f85149;
  --mono:    'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
  --sans:    system-ui, -apple-system, sans-serif;
  --radius:  6px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
}

/* Wide-screen two-column layout */
@media (min-width: 1200px) {
  .app {
    max-width: 1440px;
    flex-direction: row;
    align-items: flex-start;
    gap: 2.5rem;
  }
  .app-left  { flex: 0 0 500px; }
  .app-right { flex: 1; min-width: 0; padding-top: 5rem; }
}

header { margin-bottom: 2rem; }

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

header p {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* ── Attribution & references (collapsible) ── */
.attribution-details {
  margin-top: 2.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1.25rem;
}
.attribution-details > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  width: fit-content;
  transition: color 0.15s;
}
.attribution-details > summary::-webkit-details-marker { display: none; }
.attribution-details > summary::before {
  content: '▶';
  font-size: 0.55rem;
  display: inline-block;
  transition: transform 0.15s;
}
.attribution-details[open] > summary::before { transform: rotate(90deg); }
.attribution-details > summary:hover { color: var(--text); }
.attribution-inner {
  margin-top: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 780px;
}
.attribution-statement {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.65;
}
.attribution-statement a { color: var(--accent); text-decoration: none; }
.attribution-statement a:hover { text-decoration: underline; }
.attribution-statement .byline {
  display: block;
  margin-top: 0.4rem;
  color: var(--text);
  font-size: 0.75rem;
}
.attribution-statement strong { color: var(--text); }
.ref-section-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.55rem;
}
.ref-list {
  margin: 0;
  padding-left: 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.ref-list li {
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.55;
}
.ref-list em  { font-style: italic; color: var(--text); }
.ref-list a   { color: var(--muted); text-decoration: underline; }
.ref-list a:hover { color: var(--accent); }

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

.phase-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  background: #1f2937;
  color: var(--accent);
  border: 1px solid var(--border);
  vertical-align: middle;
  margin-left: 0.5rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.phase-tag a {
  color: inherit;
  text-decoration: none;
}
.phase-tag a:hover { text-decoration: underline; }

/* ── Panels ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.panel-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

/* ── Paste area ── */
#paste-input {
  width: 100%;
  min-height: 130px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.6;
  padding: 0.75rem;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  transition: border-color 0.15s;
  cursor: text;
}
#paste-input:focus { outline: none; border-color: var(--accent); }
#paste-input:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

/* ── Highlight spans ── */
.hl-sg { background: rgba(88,166,255,0.18); border-radius: 2px; outline: 1px solid rgba(88,166,255,0.35); }
.hl-cell,
.hl-cell-a, .hl-cell-b, .hl-cell-c {
  background: rgba(63,185,80,0.18); border-radius: 2px; outline: 1px solid rgba(63,185,80,0.38);
}
.hl-cell-alpha, .hl-cell-beta, .hl-cell-gamma {
  background: rgba(230,155,60,0.18); border-radius: 2px; outline: 1px solid rgba(230,155,60,0.40);
}

/* ── Warnings ── */
#warnings {
  list-style: none;
  display: none;
  padding: 0.75rem 1rem;
  background: #1c1308;
  border: 1px solid #3d2e0c;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
#warnings li { color: var(--warn); font-size: 0.82rem; padding: 0.15rem 0; }
#warnings li::before { content: '⚠ '; }

/* ── Cell + SG row ── */
.parsed-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 600px) { .parsed-row { grid-template-columns: 1fr; } }

/* ── Cell fields ── */
.cell-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.6rem;
}

.field-wrap { display: flex; flex-direction: column; gap: 0.25rem; }
.field-wrap label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.fwl label { color: var(--accent2); }
.fwa label { color: #e69b3c; text-transform: none; font-size: 0.85rem; }

.field-wrap input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  width: 100%;
  transition: border-color 0.15s;
}
.fwl input { border-left: 2px solid rgba(63,185,80,0.55); }
.fwa input { border-left: 2px solid rgba(230,155,60,0.55); }
.field-wrap input:focus { outline: none; border-color: var(--accent); }

/* ── SG panel ── */
#sg-panel { font-family: var(--mono); }
#sg-panel.empty .sg-val { color: var(--muted); }

.sg-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.sg-key {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  width: 4.5rem;
  flex-shrink: 0;
}
.sg-val { font-size: 0.95rem; color: var(--text); }
#sg-symbol { font-size: 1.1rem; color: var(--accent); font-weight: 600; }
#sg-symbol sub { font-size: 0.65em; }

#sg-input {
  margin-left: auto;
  width: 11ch;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
  outline: none;
  transition: border-color 0.15s;
  flex-shrink: 0;
}
#sg-input:focus { border-color: var(--accent); color: var(--text); }
#sg-input::placeholder { color: var(--border); }

/* ── Search button ── */
.search-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

#search-btn {
  background: var(--accent);
  color: #0e1117;
  border: none;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 1.5rem;
  cursor: pointer;
  transition: opacity 0.15s;
}
#search-btn:disabled { opacity: 0.35; cursor: not-allowed; }
#search-btn:not(:disabled):hover { opacity: 0.85; }

.sibling-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-family: var(--sans);
  font-weight: 500;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.sibling-btn:hover {
  color: var(--text);
  border-color: var(--muted);
  background: var(--border);
}
.sibling-btn img { display: block; flex-shrink: 0; }

/* ── Results area ── */
#results-placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 3.5rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.6;
}
#results-placeholder.has-results {
  border: none;
  border-radius: 0;
  padding: 0;
  text-align: left;
  background: transparent;
}

/* ── Results header ── */
.results-header {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
  margin-bottom: 0.75rem;
  padding: 0 0.1rem;
}

/* ── Hit list ── */
.hit-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.hit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.hit-details { display: block; }

.hit-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.875rem;
  cursor: pointer;
  list-style: none;
}
.hit-summary::-webkit-details-marker { display: none; }
.hit-summary::after {
  content: '▶';
  font-size: 0.5rem;
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.15s;
}
details[open] .hit-summary::after { transform: rotate(90deg); }
.hit-summary:hover { background: rgba(255,255,255,0.03); }

.hit-id {
  font-family: var(--mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  flex-shrink: 0;
}
.hit-id:hover { text-decoration: underline; }

.hit-title {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hit-dist {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  flex-shrink: 0;
  cursor: help;
}

/* ── Hit detail body ── */
.hit-detail-body {
  border-top: 1px solid var(--border);
  padding: 0.6rem 0.875rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.hit-detail-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  font-size: 0.78rem;
}

.hit-detail-key {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
  min-width: 6.5rem;
  white-space: nowrap;
}

.hit-detail-val {
  color: var(--text);
  font-family: var(--mono);
}

.hit-detail-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
}
.hdc-l { color: var(--accent2); }
.hdc-a { color: #e69b3c; }

/* ── Relationship badges ── */
.badge {
  display: inline-block;
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-identical      { background: rgba(63,185,80,0.15);   color: var(--accent2); border-color: rgba(63,185,80,0.4);   }
.badge-enantiomorph   { background: rgba(88,166,255,0.12);  color: var(--accent);  border-color: rgba(88,166,255,0.35); }
.badge-screw-mismatch { background: rgba(210,153,34,0.12);  color: var(--warn);    border-color: rgba(210,153,34,0.35); }
.badge-same-system    { background: rgba(139,148,158,0.10); color: var(--muted);   border-color: rgba(139,148,158,0.3); }
.badge-unrelated      { background: rgba(248,81,73,0.10);   color: var(--fail);    border-color: rgba(248,81,73,0.3);   }

/* ── Novel / empty-result state ── */
.novel-state { padding: 1.5rem 0; }
.novel-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent2);
  margin-bottom: 0.4rem;
}
.novel-sub {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.6;
}

/* ── Search error ── */
.search-error { font-size: 0.82rem; color: var(--fail); }

/* ── Advanced parameters panel ── */
.adv-search {
  margin-bottom: 1rem;
  padding: 0;
  border-color: var(--border);
}

.adv-summary {
  list-style: none;
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
}
.adv-summary::-webkit-details-marker { display: none; }
.adv-summary::before {
  content: '▶';
  display: inline-block;
  margin-right: 0.5rem;
  font-size: 0.6rem;
  transition: transform 0.15s;
  vertical-align: middle;
}
details[open] .adv-summary::before { transform: rotate(90deg); }
.adv-summary:hover { color: var(--text); }

.adv-body {
  padding: 0 1.25rem 1.1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.adv-group { flex: 1; min-width: 200px; }

.adv-group-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.adv-tol-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.45rem;
}
.adv-tol-name {
  font-size: 0.75rem;
  color: var(--muted);
  width: 3.5rem;
  flex-shrink: 0;
}
.adv-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}
.adv-tol-val {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text);
  width: 4.5rem;
  text-align: right;
  flex-shrink: 0;
}

.adv-checks {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.adv-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  color: var(--text);
  cursor: pointer;
}
.adv-check input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Debug panel ── */
#debug-panel {
  border-style: dashed;
  border-color: #3a2e00;
  background: #0c0a00;
}
#debug-panel .panel-label { color: var(--warn); }

.debug-group { margin-bottom: 1rem; }
.debug-group:last-child { margin-bottom: 0; }

.debug-group-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.debug-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
}

.debug-btn-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 18rem;
}

.debug-btn {
  background: #1c1500;
  border: 1px solid #3a2e00;
  border-radius: var(--radius);
  color: var(--warn);
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.debug-btn:hover { background: #2a2000; border-color: var(--warn); }

.debug-note {
  font-size: 0.66rem;
  color: var(--muted);
  line-height: 1.45;
  padding: 0 0.15rem;
}

/* ── Index provenance ── */
.provenance {
  margin-top: 2.5rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
  text-align: center;
}

/* ── Help tooltips ── */
.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.875rem;
  height: 0.875rem;
  border-radius: 50%;
  background: rgba(139,148,158,0.12);
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
  border: 1px solid rgba(139,148,158,0.22);
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
  font-family: var(--sans);
  transition: background 0.1s, color 0.1s;
}
.tip:hover, .tip:focus {
  background: rgba(139,148,158,0.25);
  color: var(--text);
  outline: none;
}

#tip-box {
  position: fixed;
  z-index: 9999;
  background: #1c2128;
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.72rem;
  line-height: 1.55;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-width: 260px;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
#tip-box[hidden] { display: none; }

.adv-check-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ── Help button ── */
#help-btn {
  position: fixed;
  top: 1.1rem;
  right: 1.25rem;
  z-index: 200;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#help-btn:hover { background: var(--border); color: var(--text); border-color: var(--muted); }

@keyframes help-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(88,166,255,0.6); border-color: var(--accent); color: var(--accent); }
  70%  { box-shadow: 0 0 0 8px rgba(88,166,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(88,166,255,0); }
}
#help-btn.pulsing { animation: help-pulse 1.1s ease-out 3; }

/* ── Help modal ── */
#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
#help-overlay[hidden] { display: none; }

.help-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.75rem 2rem 2rem;
  position: relative;
}

.help-close {
  position: absolute;
  top: 0.75rem;
  right: 0.875rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.3rem;
}
.help-close:hover { color: var(--text); }

.help-modal h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.help-modal h3 {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 1.25rem 0 0.4rem;
}
.help-modal p {
  font-size: 0.82rem;
  line-height: 1.65;
  color: #ccd6e0;
}
.help-modal a {
  color: var(--accent);
  text-decoration: none;
}
.help-modal a:hover { text-decoration: underline; }
.help-modal code {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: rgba(139,148,158,0.1);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.help-badges {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0;
}
.help-badges li {
  font-size: 0.82rem;
  line-height: 1.55;
  color: #ccd6e0;
  padding-left: 1rem;
  position: relative;
}
.help-badges li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--muted);
}
.help-badges li strong { color: var(--text); }
