:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #10141b;
  color: #f4f6f8;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #10141b;
}

#lab {
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  box-sizing: border-box;
  padding: var(--safe-area-top) var(--safe-area-right) var(--safe-area-bottom) var(--safe-area-left);
  background: #10141b;
}

@supports (height: 100dvh) {
  #lab {
    bottom: auto;
    height: 100dvh;
  }
}

#toolbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.45rem 1rem;
  padding: 0.55rem 0.8rem;
  box-sizing: border-box;
  background: #171d27;
  border-bottom: 1px solid #303948;
}

.heading {
  min-width: 8rem;
  grid-column: 1;
}

h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

#status {
  margin: 0.2rem 0 0;
  color: #8de0ad;
  font-size: 0.8rem;
  font-weight: 600;
}

#status.recording {
  color: #ffd166;
}

#status.interrupted {
  color: #ff8f8f;
}

.controls {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
}

button {
  min-height: 2.2rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid #5e6a7e;
  border-radius: 0.45rem;
  background: #252e3c;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

button:hover:not(:disabled),
button:focus-visible {
  background: #344157;
  border-color: #a7b8d3;
}

#import-file {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.details {
  grid-column: 1 / -1;
  min-width: 0;
  margin: 0;
  color: #aeb8c8;
  font-size: 0.76rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status.imported {
  color: #91caff;
}

#status.error {
  color: #ff8f8f;
}

#analysis-panel {
  flex: 0 0 auto;
  max-height: 27vh;
  min-height: 0;
  overflow-y: auto;
  background: #131923;
  border-bottom: 1px solid #303948;
  scrollbar-color: #56647a #131923;
}

#analysis-panel[hidden] {
  display: none;
}

#raw-stats > summary {
  min-height: 2rem;
  padding: 0.45rem 0.8rem;
  box-sizing: border-box;
  color: #dce5f2;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
}

.analysis-content {
  padding: 0 0.8rem 0.7rem;
  color: #c7d0df;
  font-size: 0.74rem;
}

.summary-stats,
.contact-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.35rem 0.8rem;
  margin: 0;
}

.summary-stats div,
.contact-stats div {
  min-width: 0;
}

.summary-stats dt,
.contact-stats dt {
  color: #8997aa;
  font-size: 0.68rem;
}

.summary-stats dd,
.contact-stats dd {
  margin: 0.08rem 0 0;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.interval-notes,
.speed-panel p,
.contact-panel p {
  margin: 0.45rem 0;
  color: #9ba9bc;
  line-height: 1.35;
}

.speed-panel,
.contact-panel {
  margin-top: 0.7rem;
}

.speed-panel h2,
.contact-panel h2 {
  margin: 0;
  color: #dce5f2;
  font-size: 0.78rem;
}

#speed-chart {
  display: block;
  width: 100%;
  height: 6.5rem;
  border: 1px solid #2b3544;
  border-radius: 0.3rem;
  background: #0c1118;
}

.chart-axis-labels,
.speed-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.3rem 0.8rem;
  margin-top: 0.22rem;
  color: #8997aa;
  font-size: 0.65rem;
}

.speed-legend {
  justify-content: flex-start;
}

.speed-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.speed-swatch {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}

.contact-note {
  font-weight: 600;
}

#surface-stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #0c1118;
}

#surface {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  background: #0c1118;
}

#imported-view {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0c1118;
  pointer-events: none;
}

#imported-view[hidden] {
  display: none;
}

#imported-label {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  right: 0;
  padding: 0.45rem 0.7rem;
  box-sizing: border-box;
  background: rgb(23 29 39 / 94%);
  color: #dce5f2;
  font-size: 0.68rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

#imported-canvas {
  display: block;
  max-width: calc(100% - 1.5rem);
  max-height: calc(100% - 5rem);
  flex: 0 0 auto;
  background: #111925;
  outline: 1px solid #48566a;
}

@media (max-width: 42rem) {
  #toolbar {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.32rem;
    padding: 0.4rem 0.55rem;
  }

  .heading {
    grid-column: 1;
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    min-width: 0;
  }

  .heading h1 {
    font-size: 0.96rem;
  }

  #status {
    margin: 0;
  }

  .controls {
    grid-column: 1;
    justify-content: flex-start;
    gap: 0.3rem;
  }

  button {
    min-height: 2rem;
    padding: 0.32rem 0.58rem;
    font-size: 0.84rem;
  }

  .details {
    grid-column: 1;
    font-size: 0.69rem;
  }

  #analysis-panel {
    max-height: 30vh;
  }

  #raw-stats > summary {
    padding: 0.38rem 0.55rem;
  }

  .analysis-content {
    padding: 0 0.55rem 0.55rem;
  }

  .summary-stats,
  .contact-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.32rem 0.55rem;
  }

  #imported-label {
    padding: 0.35rem 0.5rem;
    font-size: 0.62rem;
  }
}
