:root {
  --bg: #0f1117;
  --panel: #1a1d27;
  --ink: #e7e9ee;
  --muted: #9aa0ad;
  --accent: #5b8cff;
  --accent-2: #ff8c5b;
  --error: #ff6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Geist", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

header, main, footer { max-width: 880px; margin: 0 auto; padding: 1rem 1.25rem; }
header h1 { margin: 0.4rem 0 0.2rem; font-size: 2rem; letter-spacing: -0.5px; }
header p { color: var(--muted); margin: 0; }

section { background: var(--panel); border-radius: 12px; padding: 1.25rem; margin-bottom: 1rem; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.75rem; }
textarea, select, input {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.6rem 0.7rem;
  background: #0d0f16;
  color: var(--ink);
  border: 1px solid #2a2f3d;
  border-radius: 8px;
  font: inherit;
}
textarea { resize: vertical; font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }

.row { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.row > label { flex: 1 1 160px; margin-bottom: 0; }

button, .btn-upload {
  padding: 0.65rem 1.1rem;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
button:hover, .btn-upload:hover { filter: brightness(1.1); }

/* Data source: example dataset / upload / column picker on one aligned grid. */
.source-grid {
  display: grid;
  grid-template-columns: 4fr 3fr 3fr;   /* ~40% / 30% / 30% */
  gap: 1rem;
  margin-bottom: 1rem;
}
.source-cell { display: flex; flex-direction: column; min-width: 0; }
.source-cell > label { margin-bottom: 0; }   /* caption; the control adds its own 0.3rem top gap */
/* Upload trigger shares the button style above; these only make it fill its cell. */
.btn-upload { display: block; width: 100%; margin-top: 0.3rem; text-align: center; }
.filename {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.4rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Keep the three controls on one row down to small windows; stack only on phones. */
@media (max-width: 420px) {
  .source-grid { grid-template-columns: 1fr; }
}

.error { color: var(--error); margin: 0.75rem 0 0; }

/* Bottom-cell tabs. Underline-style nav above the result panels. */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid #2a2f3d;
  margin-bottom: 1.25rem;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 0.55rem 0.9rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}
.tab:hover { color: var(--ink); filter: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel-empty { color: var(--muted); font-size: 0.9rem; padding: 1rem 0; margin: 0; }
/* Method controls now live at the top of the Compress panel. */
.compress-row { margin-bottom: 0.5rem; }
/* Breathing room between the method description and the results below it. */
#compress-output { margin-top: 1.5rem; }

/* Download the compressed bytes / decompressed series the browser already holds.
   Secondary style: outlined, lighter than the primary Compress button. */
.download-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid #2a2f3d;
}
.btn-secondary:hover { background: #0d0f16; filter: none; }

/* Benchmark tab. Method picker: a wrapping grid of compact checkbox chips. */
.method-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin-top: 0.3rem;
}
.method-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0;
  color: var(--ink);
  font-size: 0.85rem;
  cursor: pointer;
}
.method-check input { width: auto; margin: 0; }
#bench-methods, #bench-bounds { margin-bottom: 1rem; }
#bench-output { margin-top: 1.5rem; }

/* Lossless results table: matches the dark stat-card palette. */
.bench-table {
  width: 100%;
  border-collapse: collapse;
  background: #0d0f16;
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.9rem;
}
.bench-table th, .bench-table td {
  padding: 0.55rem 0.7rem;
  text-align: right;
  border-bottom: 1px solid #2a2f3d;
}
.bench-table th { color: var(--muted); font-weight: 600; }
.bench-table th:first-child, .bench-table td:first-child { text-align: left; }
.bench-table tbody tr:last-child td { border-bottom: 0; }
.bench-table tbody td:nth-child(2) { color: var(--accent); font-weight: 600; }

/* Plot range picker: two compact index inputs + a hint, above the chart. */
.plot-range { margin-bottom: 1rem; }
.plot-range > label { flex: 0 0 130px; }
.hint { flex: 1 1 auto; color: var(--muted); font-size: 0.8rem; }
.method-desc { margin: 0.25rem 0 0; line-height: 1.4; }

/* Four stats on one row. Width is distributed by content: the size pair needs the
   most room; compression ratio and execution time are short, so they get the least. */
.stats { display: flex; gap: 0.75rem; flex-wrap: nowrap; margin-bottom: 1rem; }
.stats > div {
  flex: 1 1 0;
  min-width: 0;
  background: #0d0f16;
  border-radius: 8px;
  padding: 0.8rem 0.65rem;
  text-align: center;
}
.stats > div:nth-child(2) { flex-grow: 2.2; }   /* size (orig → compressed) */
.stats > div:nth-child(3) { flex-grow: 1.3; }   /* max error */
.stats span {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stats small { color: var(--muted); font-size: 0.72rem; }

@media (max-width: 560px) {
  .stats { flex-wrap: wrap; }
  .stats > div, .stats > div:nth-child(2), .stats > div:nth-child(3) { flex: 1 1 45%; }
}

footer { color: var(--muted); font-size: 0.9rem; }
footer a { color: var(--accent); text-decoration: none; }

/* ------------------------------------------------------------------ */
/* Hover/focus hints. Add `data-tip="..."` to any non-replaced element */
/* (label, button, div) and a styled bubble appears above it on hover  */
/* or keyboard focus. Pure CSS, no JS. Put `data-tip` on a wrapping    */
/* <label>/<div>, never on a bare <input>/<select>/<textarea> —        */
/* pseudo-elements do not render on those replaced elements.           */
/* ------------------------------------------------------------------ */
[data-tip] { position: relative; }
[data-tip]:hover::after,
[data-tip]:focus-within::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 240px;
  padding: 0.5rem 0.65rem;
  background: #0d0f16;
  color: var(--ink);
  border: 1px solid #2a2f3d;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
  white-space: normal;
  text-align: left;
  z-index: 20;
  pointer-events: none;
}
/* Little arrow connecting the bubble to its element. */
[data-tip]:hover::before,
[data-tip]:focus-within::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #2a2f3d;
  z-index: 20;
  pointer-events: none;
}
