:root {
  /* ── Surface hierarchy (cool neutral gray) ── */
  --bg-root: #f4f5f6;
  --bg-soft: #edeff0;
  --bg-base: #fafbfc;
  --bg-raised: #ffffff;
  --bg-elevated: #f0f2f3;
  --bg-overlay: #e6e8ea;

  /* ── Ink & text ── */
  --ink: #1d2228;
  --ink-dim: #494d53;
  --ink-muted: #7a7f86;
  --ink-strong: #111418;

  /* ── Keylines ── */
  --border-subtle: #e1e3e6;
  --border-base: #d3d6d9;
  --border-strong: #bdc0c4;

  /* ── Pine (primary) ── */
  --pine: #2d6a4f;
  --pine-soft: #40916c;
  --pine-light: #b7e4c7;
  --pine-glow: rgba(45, 106, 79, 0.08);
  --pine-glow-strong: rgba(45, 106, 79, 0.16);

  /* ── Amber (accent) ── */
  --amber: #b37400;
  --amber-soft: #d68c00;
  --amber-light: #ffe0a3;
  --amber-glow: rgba(179, 116, 0, 0.10);

  /* ── Semantic colors ── */
  --rose: #b23b48;
  --rose-bg: #fce8ea;
  --sky: #2a6e8a;
  --sky-bg: #e4f0f6;

  /* ── Impact tags ── */
  --tag-high-bg: #fce8ea;
  --tag-high-text: #b23b48;
  --tag-mid-bg: #fff3db;
  --tag-mid-text: #b37400;
  --tag-low-bg: #e6f4ec;
  --tag-low-text: #2d6a4f;
  --tag-mod-bg: #e8eff4;
  --tag-mod-text: #2a6e8a;

  /* ── Shadows ── */
  --shadow-sm: 0 1px 0 var(--border-subtle);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.06);
  --glow-panel: 0 0 0 1px var(--border-subtle), 0 4px 16px rgba(0, 0, 0, 0.02);

  /* ── Radii ── */
  --radius-sm: 4px;
  --radius-md: 7px;
  --radius-lg: 10px;

  /* ── Sidebar width ── */
  --sidebar-w: 280px;

  /* ── Typography (unified larger base) ── */
  --font-mono: "Cascadia Code", "JetBrains Mono", "SF Mono", "Fira Code", "Consolas", monospace;
  --font-body: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-display: "DM Serif Display", "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun", serif;
}

/* ═════════════════════════════════════════
   RESET & BASE
   ═════════════════════════════════════════ */
*,
*::before,
*::after { box-sizing: border-box; margin: 0; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 18px;  /* base: 1rem = 18px on desktop */
}

body {
  min-width: 320px;
  background: var(--bg-root);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
}

body::before {
  content: "";
  position: fixed; inset: 0; z-index: 9999;
  pointer-events: none; opacity: 0.018;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--pine-light); color: var(--ink-strong); }

/* ═════════════════════════════════════════
   TYPOGRAPHY
   ═════════════════════════════════════════ */
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.01em; }

/* ═════════════════════════════════════════
   FORM ELEMENTS
   ═════════════════════════════════════════ */
button, input, select { font-family: inherit; font-size: 0.9rem; }

button {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; height: 38px; padding: 0 18px;
  border: 1px solid var(--border-base); border-radius: var(--radius-sm);
  background: var(--bg-raised); color: var(--ink);
  cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
button:hover { background: var(--bg-soft); border-color: var(--border-strong); }
button:active { transform: translateY(1px); }

button.primary {
  border-color: var(--pine); background: var(--pine); color: #fff; font-weight: 700;
}
button.primary:hover {
  background: var(--pine-soft); border-color: var(--pine-soft);
  box-shadow: 0 0 18px var(--pine-glow-strong);
}

input, select {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border-base); border-radius: var(--radius-sm);
  background: var(--bg-base); color: var(--ink); outline: none;
  font-size: 0.88rem;
  transition: border-color 0.18s, box-shadow 0.18s;
}
input::placeholder { color: var(--ink-muted); opacity: 0.5; }
input:focus, select:focus {
  border-color: var(--pine);
  box-shadow: 0 0 0 3px var(--pine-glow), 0 0 0 1px var(--pine);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238c8472'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px; cursor: pointer;
}

/* ═════════════════════════════════════════
   SHELL
   ═════════════════════════════════════════ */
.shell {
  width: min(1640px, calc(100% - 48px));
  margin: 0 auto; padding: 32px 0 56px;
}

/* ═════════════════════════════════════════
   HEADER
   ═════════════════════════════════════════ */
.topbar {
  display: flex; flex-wrap: wrap; justify-content: space-between;
  align-items: flex-start; gap: 20px;
  margin-bottom: 28px; padding-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.title-block { max-width: 920px; }

.title-block::before {
  content: ""; display: block; width: 48px; height: 3px;
  margin-bottom: 14px; border-radius: 99px;
  background: linear-gradient(90deg, var(--pine), var(--pine-soft));
}

h1 {
  color: var(--ink-strong);
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  line-height: 1.14; font-weight: 650; letter-spacing: -0.015em;
}
h1 span.grain { color: var(--pine); }

.lead {
  margin-top: 8px; color: var(--ink-dim);
  font-size: 0.92rem; line-height: 1.7;
  white-space: nowrap;
}

.top-actions { display: flex; gap: 10px; flex-shrink: 0; align-items: center; }

/* ── Language switch button ── */
.lang-btn {
  height: 38px; min-width: 48px; padding: 0 14px;
  border: 1px solid var(--border-base); border-radius: var(--radius-sm);
  background: var(--bg-raised); color: var(--ink);
  cursor: pointer; font-weight: 600; font-size: 0.85rem;
  white-space: nowrap; transition: background 0.15s, border-color 0.15s;
  font-family: var(--font-mono);
}
.lang-btn:hover { background: var(--bg-soft); border-color: var(--pine); color: var(--pine); }

/* ═════════════════════════════════════════
   MAIN GRID: SIDEBAR + CONTENT
   ═════════════════════════════════════════ */
.main-grid {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 20px; align-items: start;
}

/* ── Sidebar toggle (hidden on desktop) ── */
.sidebar-toggle { display: none; }

/* ═════════════════════════════════════════
   SIDEBAR
   ═════════════════════════════════════════ */
.sidebar {
  position: sticky; top: 20px;
  display: flex; flex-direction: column; gap: 0;
  border: 1px solid var(--border-base); border-radius: var(--radius-lg);
  background: var(--bg-raised); box-shadow: var(--glow-panel); overflow: hidden;
}

.sidebar-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px 14px; border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}
.sidebar-head h3 {
  font-size: 0.82rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim);
}
.sidebar-count {
  font-family: var(--font-mono); font-size: 0.82rem; font-weight: 700;
  color: var(--pine); background: var(--pine-light);
  padding: 3px 12px; border-radius: 99px;
}

.filter-group {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-subtle);
}
.filter-group:last-child { border-bottom: none; }

.filter-group-title {
  margin-bottom: 13px; color: var(--ink-muted);
  font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.09em;
}

.filter-group label {
  display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px;
}
.filter-group label:last-child { margin-bottom: 0; }

.filter-group label span {
  color: var(--ink-dim); font-size: 0.78rem; font-weight: 500;
}

.pos-range {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px;
}
.pos-range label { margin-bottom: 0; }

/* ═════════════════════════════════════════
   CONTENT AREA
   ═════════════════════════════════════════ */
.content-area {
  min-width: 0; display: flex; flex-direction: column; gap: 14px;
}

/* ── Quick search ── */
.quick-search {
  padding: 18px; border: 1px solid var(--border-base);
  border-radius: var(--radius-lg); background: var(--bg-raised);
  box-shadow: var(--glow-panel);
}
.quick-search label {
  display: block; margin-bottom: 10px; color: var(--pine);
  font-size: 0.78rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.search-line { display: flex; gap: 10px; }
.search-line input {
  flex: 1; font-family: var(--font-mono);
  font-size: 0.95rem; letter-spacing: 0.02em;
}
.search-line button { flex-shrink: 0; }

/* ── Stats ── */
.stats {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0; border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); overflow: hidden;
  background: var(--bg-raised); box-shadow: var(--shadow-sm);
}
.stats div {
  position: relative; min-height: 82px; padding: 16px 18px;
  border-right: 1px solid var(--border-subtle); background: var(--bg-raised);
  transition: background 0.2s;
}
.stats div:last-child { border-right: none; }
.stats div:hover { background: var(--bg-soft); }

.stats div::after {
  content: ""; position: absolute; bottom: 0; left: 18px;
  width: 28px; height: 2px; border-radius: 99px;
  background: var(--pine-soft); opacity: 0;
  transition: opacity 0.25s, width 0.25s;
}
.stats div:hover::after { opacity: 1; width: 42px; }

.stats span {
  display: block; color: var(--ink-muted);
  font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
}
.stats strong {
  display: block; margin-top: 10px; color: var(--ink-strong);
  font-size: 1.75rem; line-height: 1; font-weight: 700;
  font-family: var(--font-mono); letter-spacing: -0.02em;
}

/* ═════════════════════════════════════════
   KARYOTYPE
   ═════════════════════════════════════════ */
.karyotype {
  padding: 18px; border: 1px solid var(--border-base);
  border-radius: var(--radius-lg); background: var(--bg-raised);
  box-shadow: var(--glow-panel);
}
.karyo-head {
  display: flex; justify-content: space-between;
  align-items: baseline; margin-bottom: 16px;
}
.karyo-head h3 {
  color: var(--ink-dim); font-size: 0.78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.karyo-hint { color: var(--ink-muted); font-size: 0.76rem; }

.karyo-strip { display: flex; gap: 6px; align-items: flex-end; height: 72px; }

.karyo-bar {
  flex: 1; position: relative; min-width: 0;
  border-radius: 3px 3px 0 0; background: var(--pine-soft);
  opacity: 0.55; transition: opacity 0.2s, transform 0.2s; cursor: pointer;
}
.karyo-bar:hover { opacity: 1; transform: scaleY(1.08); transform-origin: bottom; }
.karyo-bar.highlight {
  opacity: 1; background: var(--amber-soft);
  box-shadow: 0 0 8px var(--amber-glow);
}

.karyo-bar::after {
  content: attr(data-label); position: absolute; bottom: -22px;
  left: 50%; transform: translateX(-50%);
  font-size: 0.62rem; color: var(--ink-muted);
  font-family: var(--font-mono); white-space: nowrap;
}
.karyo-bar:hover::before {
  content: attr(data-tip); position: absolute; top: -30px;
  left: 50%; transform: translateX(-50%);
  padding: 4px 10px; border-radius: 3px;
  background: var(--ink-strong); color: #fff;
  font-size: 0.68rem; font-family: var(--font-mono);
  white-space: nowrap; z-index: 5; pointer-events: none;
}

/* ═════════════════════════════════════════
   RESULT HEAD
   ═════════════════════════════════════════ */
.result-head {
  display: flex; justify-content: space-between;
  gap: 16px; align-items: center;
}
.result-head h2 { color: var(--ink-strong); font-size: 1.2rem; font-weight: 600; }
#resultHint { margin-top: 4px; color: var(--ink-dim); font-size: 0.82rem; }

.count {
  display: flex; align-items: center; justify-content: center;
  min-width: 76px; height: 46px; padding: 0 18px;
  border-radius: var(--radius-sm); background: var(--bg-soft);
  border: 1px solid var(--border-subtle); color: var(--pine);
  font-size: 1.3rem; font-weight: 700; font-family: var(--font-mono);
}

/* ═════════════════════════════════════════
   LOCUS DETAIL CARD
   ═════════════════════════════════════════ */
.locus-card {
  padding: 18px; border: 1px solid var(--amber-light);
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(179, 116, 0, 0.04), rgba(179, 116, 0, 0.01));
}
.hidden { display: none !important; }

.locus-card h3 {
  margin-bottom: 14px; color: var(--amber);
  font-size: 0.95rem; font-family: var(--font-mono); letter-spacing: 0.02em;
}
.locus-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px;
}
.locus-grid > div {
  min-width: 0; padding: 10px 12px;
  border-left: 2px solid var(--amber-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: rgba(179, 116, 0, 0.03);
}
.locus-grid span {
  display: block; color: var(--ink-muted);
  font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.locus-grid strong {
  display: block; margin-top: 6px; color: var(--ink);
  font-size: 0.82rem; font-weight: 500;
  overflow-wrap: anywhere; line-height: 1.5;
}

/* ═════════════════════════════════════════
   CHARTS — 2×2 grid
   ═════════════════════════════════════════ */
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.cards article {
  padding: 18px; border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); background: var(--bg-soft);
}
.cards h3 {
  margin-bottom: 14px; color: var(--ink-dim);
  font-size: 0.76rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.07em;
}

/* ── Bar rows ── */
.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 175px) 1fr 52px;
  gap: 10px; align-items: center; min-height: 30px; padding: 3px 0;
}
.bar-label {
  color: var(--ink-dim); font-size: 0.78rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-value {
  color: var(--ink-muted); font-size: 0.72rem;
  font-family: var(--font-mono); text-align: right;
}
.bar-track {
  height: 7px; border-radius: 99px;
  background: var(--bg-overlay); overflow: hidden;
}
.bar-fill {
  height: 100%; min-width: 3px; border-radius: inherit;
  background: var(--pine); transition: width 0.35s ease;
}
.bar-fill.high     { background: var(--rose); }
.bar-fill.moderate { background: var(--amber-soft); }
.bar-fill.low      { background: var(--sky); }

.chrom-bars {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px;
}

/* ═════════════════════════════════════════
   TABLE — improved variant-info wrapping
   ═════════════════════════════════════════ */
.table-head {
  display: flex; justify-content: space-between;
  gap: 16px; align-items: center;
}
#tableStatus { color: var(--ink-dim); font-size: 0.82rem; }

.pager {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink-dim); font-size: 0.8rem; font-family: var(--font-mono);
}
.pager button { height: 32px; padding: 0 14px; font-size: 0.8rem; }

.table-box {
  overflow: auto; border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); background: var(--bg-base);
}

table {
  width: 100%; min-width: 960px;
  border-collapse: collapse; table-layout: fixed;
}

/* column width allocation */
.col-locus    { width: 12%; }
.col-variant  { width: 21%; }
.col-sample   { width: 14%; }
.col-gene     { width: 18%; }
.col-impact   { width: 8%;  }
.col-freq     { width: 9%;  }
.col-genotype { width: 8%;  }
.col-reads    { width: 10%; }

th, td {
  padding: 11px 10px; border-bottom: 1px solid var(--border-subtle);
  text-align: left; vertical-align: top; font-size: 0.82rem;
  word-break: break-word; overflow-wrap: break-word;
}
th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-elevated); color: var(--ink-muted);
  font-size: 0.72rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border-base);
}

tr:hover td { background: rgba(45, 106, 79, 0.02); }

td strong { display: block; color: var(--ink-strong); }
td .muted {
  display: block; margin-top: 2px;
  color: var(--ink-muted); font-size: 0.76rem;
}

/* variant info tags stack naturally */
td .tag-line {
  display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px;
}

/* ── Tags ── */
.tag {
  display: inline-block; margin: 2px 4px 2px 0; padding: 2px 7px;
  border-radius: 3px; background: var(--bg-overlay); color: var(--ink-dim);
  font-size: 0.66rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  white-space: nowrap;
}
.tag.high {
  background: var(--tag-high-bg); color: var(--tag-high-text);
}
.tag.moderate {
  background: var(--tag-mid-bg); color: var(--tag-mid-text);
}

/* ═════════════════════════════════════════
   RESPONSIVE — PC / PAD / PHONE
   ═════════════════════════════════════════ */

/* ── Tablet & small PC (≤ 1180px) ── */
@media (max-width: 1180px) {
  html { font-size: 15px; }

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

  .sidebar-toggle {
    display: flex; align-items: center; gap: 8px;
    width: 100%; justify-content: center;
    font-weight: 600; font-size: 0.9rem;
  }
  .toggle-icon { font-size: 1.1rem; }

  .sidebar {
    position: static; display: none;
    border-radius: var(--radius-lg);
  }
  .sidebar.open { display: flex; }

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

  .locus-grid { grid-template-columns: repeat(2, 1fr); }

  .chrom-bars { grid-template-columns: 1fr; }

  .table-box { overflow-x: auto; }
  table { min-width: 900px; }
}

/* ── Phone (≤ 680px) ── */
@media (max-width: 680px) {
  html { font-size: 14px; }

  .shell { width: min(100% - 16px, 1640px); padding: 18px 0 28px; }

  .topbar { flex-direction: column; gap: 12px; margin-bottom: 18px; }
  .top-actions { width: 100%; }
  .top-actions button { flex: 1; }

  h1 { font-size: 1.4rem; }
  .lead { font-size: 0.82rem; white-space: normal; }

  .search-line { flex-direction: column; }

  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats div { border-bottom: 1px solid var(--border-subtle); min-height: 68px; }
  .stats strong { font-size: 1.35rem; }

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

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

  .karyo-head { flex-direction: column; gap: 4px; }
  .karyo-strip { height: 92px; }
  .karyo-bar::after { bottom: -24px; font-size: 0.55rem; }

  .sidebar { border-radius: var(--radius-md); }

  .pos-range { grid-template-columns: 1fr; }

  .result-head { flex-direction: column; align-items: flex-start; }

  .table-head { flex-direction: column; gap: 8px; align-items: flex-start; }

  table { min-width: 720px; }
  th, td { padding: 8px 6px; font-size: 0.75rem; }
}

/* ── Very small phone (≤ 400px) ── */
@media (max-width: 400px) {
  html { font-size: 13px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats div { min-height: 60px; padding: 10px 12px; }
  .stats strong { font-size: 1.2rem; }
  .shell { padding: 12px 0 20px; }
}

/* ═════════════════════════════════════════
   SCROLLBAR
   ═════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-soft); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-muted); }

:focus-visible { outline: 2px solid var(--pine); outline-offset: 2px; }

/* ── Fade-up reveal ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.quick-search, .stats, .karyotype, .cards article {
  animation: fadeUp 0.4s ease both;
}
.stats                 { animation-delay: 0.03s; }
.karyotype             { animation-delay: 0.08s; }
.cards article:nth-child(1) { animation-delay: 0.10s; }
.cards article:nth-child(2) { animation-delay: 0.13s; }
.cards article:nth-child(3) { animation-delay: 0.16s; }
.cards article:nth-child(4) { animation-delay: 0.19s; }
