:root {
  color-scheme: dark;
  --bg: #07090c;
  --surface: #0d1116;
  --surface-raised: #12171d;
  --surface-active: #181e25;
  --line: #26313c;
  --line-strong: #3a4754;
  --muted: #8f9baa;
  --text: #f2f5f7;
  --green: #42d69a;
  --red: #ff5368;
  --yellow: #eecb4d;
  --blue: #57a8ff;
  --cyan: #62d4e8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface-raised);
  color: var(--text);
}

button {
  padding: 8px 12px;
  font-weight: 750;
  cursor: pointer;
}

button:hover,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  border-color: #66788b;
  outline: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.danger {
  border-color: #70323d;
  color: var(--red);
}

small,
label,
nav strong,
.title,
th {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 22px;
}

h2 {
  margin-bottom: 0;
  font-size: 24px;
}

h3 {
  font-size: 21px;
  line-height: 1.2;
}

canvas {
  display: block;
  width: 100%;
  background: #070a0e;
  border: 1px solid #1d2630;
}

article {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login form {
  width: min(420px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--red);
  background: var(--surface);
}

.login h1 {
  margin: 6px 0;
  font-size: 32px;
}

.login p {
  margin-bottom: 24px;
  color: var(--muted);
}

.login label,
dialog label {
  display: grid;
  gap: 6px;
  margin: 14px 0;
}

.login input,
dialog input {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--bg);
  color: var(--text);
}

.login button {
  width: 100%;
  margin-top: 12px;
  background: var(--text);
  color: var(--bg);
}

output {
  display: block;
  margin-top: 10px;
  color: var(--red);
}

header {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

header > div:first-child {
  padding-left: 10px;
  border-left: 3px solid var(--red);
}

header select {
  max-width: 280px;
  padding: 8px;
}

.head-actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.head-actions span {
  padding: 8px;
  border: 1px solid #2b7458;
  border-radius: 3px;
  color: var(--green);
  font-size: 12px;
}

.shell {
  min-height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
}

nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
}

nav strong {
  padding: 0 10px 6px;
}

nav button,
nav a {
  min-height: 0;
  padding: 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
  text-decoration: none;
}

nav button:hover,
nav a:hover {
  color: var(--text);
}

nav button.active {
  padding-left: 8px;
  border-left: 2px solid var(--red);
  background: var(--surface-active);
  color: var(--text);
}

nav hr {
  width: 100%;
  margin: 12px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

main {
  min-width: 0;
  padding: 12px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.context,
.session-context {
  display: grid;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
}

.context {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.session-context {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.context div,
.session-context div {
  min-width: 0;
  padding: 9px 12px;
  border-right: 1px solid var(--line);
}

.context div:last-child,
.session-context div:last-child {
  border-right: 0;
}

.context strong,
.session-context strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: minmax(450px, 1.4fr) minmax(300px, 0.8fr);
  grid-template-areas:
    "inputs call"
    "inputs map"
    "sessions map";
  gap: 12px;
}

.grid article,
#devices article {
  padding: 13px;
}

.inputs {
  grid-area: inputs;
}

.map {
  grid-area: map;
}

.call {
  grid-area: call;
}

.sessions {
  grid-area: sessions;
}

.title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 22px;
  margin-bottom: 12px;
}

.title > span:last-child {
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 2px;
  white-space: nowrap;
}

.title > span.live {
  border-color: #2b7458;
  color: var(--green);
}

.telemetry {
  display: grid;
  grid-template-columns: 160px 90px 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}

.speed b {
  font-size: 76px;
  line-height: 0.8;
}

.speed span {
  margin-left: 6px;
  color: var(--muted);
}

.gear {
  height: 92px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
}

.gear b {
  font-size: 52px;
}

.bars {
  display: grid;
  gap: 5px;
}

.bars label span {
  float: right;
  color: var(--text);
}

.bars i {
  height: 6px;
  background: #202a34;
}

.bars i b {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green);
}

.bars i b.red {
  background: var(--red);
}

.bars i b.yellow {
  background: var(--yellow);
}

#chart {
  height: 280px;
}

.map canvas {
  height: 390px;
}

.call h2 {
  margin: 16px 0 6px;
  font-size: 23px;
}

.call p {
  color: #b5bec8;
}

.scores,
.score-grid {
  display: grid;
  border: 1px solid var(--line);
}

.scores {
  grid-template-columns: repeat(3, 1fr);
}

.score-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 14px;
}

.scores div,
.score-grid div {
  padding: 10px;
  border-right: 1px solid var(--line);
}

.scores div:last-child,
.score-grid div:last-child {
  border-right: 0;
}

.scores b,
.score-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.list {
  display: grid;
  gap: 6px;
}

.list button {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin-top: 3px;
}

.section-head select {
  width: min(520px, 48vw);
  padding: 9px;
}

.compare-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) minmax(220px, 0.7fr);
  gap: 8px;
  margin-bottom: 12px;
}

.compare-toolbar > label,
.compare-result {
  min-width: 0;
  min-height: 68px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
}

.compare-toolbar label {
  display: grid;
  gap: 6px;
}

.compare-toolbar select {
  width: 100%;
  padding: 6px 8px;
}

.compare-result {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 12px;
}

.compare-result small {
  grid-column: 1 / -1;
}

.compare-result strong {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}

.gain {
  color: var(--green);
}

.loss {
  color: var(--red);
}

.quality {
  justify-self: end;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-size: 11px;
  font-weight: 800;
}

.quality.clean {
  border-color: #287453;
  color: var(--green);
}

.quality.rejected {
  border-color: #7d3540;
  color: var(--red);
}

.workbench-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.7fr);
  grid-template-areas:
    "trace side"
    "corners corners"
    "laps laps";
  gap: 12px;
  align-items: start;
}

.lap-trace-panel {
  grid-area: trace;
  padding: 13px;
}

.workbench-side {
  grid-area: side;
  display: grid;
  gap: 12px;
  min-width: 0;
}

.workbench-side article,
.corner-panel,
.lap-table-panel {
  padding: 13px;
}

.corner-panel {
  grid-area: corners;
}

.lap-table-panel {
  grid-area: laps;
}

.trace-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: -2px 0 9px;
  color: #b7c0ca;
  font-size: 11px;
  font-weight: 700;
}

.trace-legend span::before {
  content: "";
  display: inline-block;
  width: 20px;
  height: 2px;
  margin: 0 6px 3px 0;
  background: currentColor;
}

.trace-legend .white {
  color: var(--text);
}

.trace-legend .blue {
  color: var(--blue);
}

.trace-legend .green {
  color: var(--green);
}

.trace-legend .red {
  color: var(--red);
}

#archive-chart {
  height: 430px;
}

.trace-cursor {
  width: 100%;
  height: 22px;
  margin: 9px 0 5px;
  padding: 0;
  accent-color: var(--blue);
}

.trace-readout {
  display: grid;
  grid-template-columns: repeat(7, minmax(70px, 1fr));
  border: 1px solid var(--line);
  background: var(--surface-raised);
}

.trace-readout div {
  min-width: 0;
  padding: 8px;
  border-right: 1px solid var(--line);
}

.trace-readout div:last-child {
  border-right: 0;
}

.trace-readout strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.driver-brief {
  border-top: 2px solid var(--red);
}

.driver-brief h3 {
  margin-bottom: 8px;
}

.driver-brief > p {
  margin-bottom: 14px;
  color: #b7c0ca;
  line-height: 1.45;
}

.priorities {
  display: grid;
  gap: 8px;
}

.priorities > div {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 9px;
  padding: 9px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--yellow);
  background: var(--surface-raised);
}

.priorities > div > b {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--yellow);
}

.priorities p {
  margin: 0;
  color: #b7c0ca;
  font-size: 12px;
  line-height: 1.35;
}

.priorities p strong {
  display: block;
  margin-bottom: 3px;
  color: var(--text);
  font-size: 13px;
}

.priorities p span {
  display: block;
}

#archive-map {
  height: 280px;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

td {
  color: #c5cdd5;
  font-size: 13px;
}

th {
  background: #0a0e13;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr.selected {
  background: #15202a;
}

tbody tr:hover {
  background: var(--surface-raised);
}

td button {
  min-height: 28px;
  padding: 4px 8px;
  border-color: var(--line);
  color: var(--blue);
}

td.gain,
td.loss {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

dialog {
  width: min(520px, 90vw);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

dialog::backdrop {
  background: #000a;
}

dialog form {
  display: grid;
}

pre {
  padding: 12px;
  border: 1px solid var(--green);
  background: var(--bg);
  color: var(--green);
  white-space: pre-wrap;
  word-break: break-all;
}

code {
  color: var(--yellow);
}

@media (max-width: 1120px) {
  .shell {
    grid-template-columns: 165px minmax(0, 1fr);
  }

  .session-context {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .session-context div:nth-child(3) {
    border-right: 0;
  }

  .session-context div:nth-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .workbench-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "trace"
      "side"
      "corners"
      "laps";
  }

  .workbench-side {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.7fr);
  }
}

@media (max-width: 760px) {
  header {
    height: auto;
    align-items: flex-start;
    padding: 10px 12px;
  }

  .head-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .head-actions select {
    display: none;
  }

  .shell {
    display: block;
  }

  nav {
    position: sticky;
    top: 0;
    z-index: 3;
    flex-direction: row;
    overflow-x: auto;
    padding: 6px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
  }

  nav strong,
  nav hr,
  nav a {
    display: none;
  }

  nav button {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  main {
    padding: 8px;
  }

  .context,
  .session-context {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .context div,
  .session-context div,
  .session-context div:nth-child(3) {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .context div:nth-child(even),
  .session-context div:nth-child(even) {
    border-right: 0;
  }

  .context div:nth-last-child(-n + 2),
  .session-context div:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .grid {
    display: block;
  }

  .grid article {
    margin-bottom: 8px;
  }

  .telemetry {
    grid-template-columns: minmax(0, 1fr) 80px;
  }

  .bars {
    grid-column: 1 / -1;
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .section-head select {
    width: 100%;
    min-width: 0;
  }

  .compare-toolbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .workbench-side {
    grid-template-columns: minmax(0, 1fr);
  }

  #archive-chart {
    height: 340px;
  }

  .trace-readout {
    grid-template-columns: repeat(4, minmax(70px, 1fr));
  }

  .trace-readout div:nth-child(4) {
    border-right: 0;
  }

  .trace-readout div:nth-child(-n + 4) {
    border-bottom: 1px solid var(--line);
  }

  .score-grid {
    grid-template-columns: repeat(3, minmax(80px, 1fr));
  }

  .table-scroll {
    margin: 0 -13px -13px;
  }
}
