:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --ink: #151923;
  --muted: #5f6b78;
  --line: #d8e1ea;
  --accent: #007f73;
  --accent-soft: #dff4ef;
  --coral: #d86f45;
  --blue: #376fb7;
  --danger: #a33a3a;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.1);
  --radius: 8px;
  --max-width: 1280px;
  --plot-bg: #fbfcfd;
  --plot-grid: #e8edf2;
  --plot-grid-soft: #eef2f5;
  --plot-text: #64717f;
  --plot-axis: #d8e1ea;
  --plot-trace: #007f73;
  --plot-trace-alt: #376fb7;
  --plot-peak: rgba(216, 111, 69, 0.62);
  --plot-peak-text: #9a4a24;
  --plot-cursor: rgba(21, 25, 35, 0.35);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111419;
  --surface: #1a1f27;
  --surface-2: #232a35;
  --ink: #f5f7fb;
  --muted: #b5bfcb;
  --line: #323b48;
  --accent: #45c7b5;
  --accent-soft: #143a36;
  --coral: #ff9b70;
  --blue: #8fb6ff;
  --danger: #ff9b70;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  --plot-bg: #151a21;
  --plot-grid: #28313d;
  --plot-grid-soft: #222a35;
  --plot-text: #aeb9c7;
  --plot-axis: #3a4350;
  --plot-trace: #45c7b5;
  --plot-trace-alt: #8fb6ff;
  --plot-peak: rgba(255, 155, 112, 0.62);
  --plot-peak-text: #ffbd9d;
  --plot-cursor: rgba(245, 247, 251, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(90deg, rgba(0, 127, 115, 0.07), transparent 34%),
    linear-gradient(180deg, rgba(216, 111, 69, 0.07), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

a {
  color: inherit;
}

button,
select,
input {
  font: inherit;
}

button,
.file-loader,
.app-header nav a,
.theme-toggle {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
  min-height: 38px;
  padding: 0.55rem 0.75rem;
  text-decoration: none;
}

button:hover,
.file-loader:hover,
.app-header nav a:hover,
.theme-toggle:hover {
  border-color: var(--accent);
}

select:focus-visible,
.file-loader:focus-within {
  outline: 3px solid color-mix(in srgb, var(--accent), transparent 78%);
  outline-offset: 1px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem max(1rem, calc((100vw - var(--max-width)) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface), transparent 8%);
  backdrop-filter: blur(16px);
}

.brand,
.app-header nav {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand,
.app-header a {
  text-decoration: none;
}

.brand span {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  font-weight: 900;
}

.app-shell {
  width: min(var(--max-width), calc(100% - 2rem));
  margin: 0 auto;
  padding: 3.2rem 0 5rem;
}

.viewer-hero,
.panel,
.plot-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), transparent 2%);
  box-shadow: var(--shadow);
}

.viewer-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.2rem;
  align-items: end;
  margin-bottom: 1rem;
  padding: 1rem;
}

.hero-copy {
  max-width: 790px;
}

.eyebrow {
  margin: 0 0 0.7rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.65rem;
  font-size: clamp(2.15rem, 5vw, 4rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0.6rem;
  font-size: 1.08rem;
}

.hero-copy p:last-child,
#plotSubtitle,
.cursor-readout,
.format-control span,
.meta-list dt,
.table-header p,
.empty,
.stat span {
  color: var(--muted);
}

.hero-copy p:last-child {
  margin-bottom: 0;
  max-width: 72ch;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
  justify-content: flex-end;
}

.format-control {
  display: grid;
  gap: 0.28rem;
  min-width: 170px;
}

.format-control span {
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.format-control select,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0 0.7rem;
}

.file-loader {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.file-loader input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(250px, 305px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.sidebar,
.workspace {
  min-width: 0;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 1rem;
}

.workspace {
  display: grid;
  gap: 0.9rem;
}

.panel {
  padding: 1rem;
}

.trace-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.stat {
  min-width: 0;
  border: 1px solid color-mix(in srgb, var(--line), transparent 22%);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 0.6rem;
}

.stat span {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
}

.stat strong {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 44px 44px;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.meta-list {
  margin: 0;
}

.meta-list div {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 0.65rem;
  padding: 0.52rem 0;
  border-top: 1px solid var(--line);
}

.meta-list div:first-child {
  border-top: 0;
}

.meta-list dt,
.meta-list dd {
  font-size: 0.78rem;
}

.meta-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.plot-panel {
  overflow: hidden;
}

.plot-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

#plotSubtitle {
  margin: 0.2rem 0 0;
  font-size: 0.86rem;
}

.cursor-readout {
  align-self: start;
  min-width: 160px;
  text-align: right;
  font-size: 0.78rem;
}

canvas {
  display: block;
  width: 100%;
  height: min(55vh, 560px);
  min-height: 340px;
  background: var(--plot-bg);
  cursor: crosshair;
}

.tabs {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.tab {
  background: color-mix(in srgb, var(--surface), transparent 8%);
}

.tab.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.table-panel {
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--line);
}

.table-header p {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
}

.table-wrap {
  overflow: auto;
  max-height: 44vh;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 0.65rem;
  text-align: left;
  font-size: 0.78rem;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--ink);
}

td {
  color: var(--muted);
}

tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-2), transparent 50%);
}

td.number {
  font-variant-numeric: tabular-nums;
}

.empty {
  padding: 1.5rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.22rem 0.5rem;
  font-size: 0.72rem;
  color: #ffffff;
  background: var(--accent);
}

.warning {
  color: var(--danger);
}

.source-credit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  border: 1px solid color-mix(in srgb, var(--line), transparent 18%);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), transparent 20%);
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0.75rem 1rem;
  text-align: center;
}

.source-credit span {
  color: var(--coral);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.source-credit p {
  margin: 0;
}

.source-credit a {
  color: var(--accent);
  font-weight: 900;
  text-decoration: none;
}

.source-credit a:hover {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

@media (max-width: 980px) {
  .viewer-hero,
  .layout {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .trace-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .plot-header {
    flex-direction: column;
  }

  .cursor-readout {
    text-align: left;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding-top: 2.5rem;
  }

  .top-actions,
  .tabs {
    width: 100%;
  }

  .top-actions > *,
  .tab {
    flex: 1 1 auto;
  }

  .format-control {
    min-width: 0;
  }

  .trace-stats {
    grid-template-columns: 1fr 1fr;
  }

  .layout {
    gap: 0.8rem;
  }

  canvas {
    min-height: 300px;
  }
}
