:root {
  --orange: #f47a16;
  --orange-2: #ff9b32;
  --black: #050505;
  --black-2: #101010;
  --black-3: #181818;
  --white: #fffaf1;
  --muted: #b8b1a8;
  --line: rgba(255, 250, 241, 0.14);
  --line-strong: rgba(255, 250, 241, 0.28);
  --good: #f7f7f2;
  --warn: #ffb14f;
  --bad: #ff634f;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--black);
  color: var(--white);
  font-family: Inter, Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

body {
  background:
    linear-gradient(90deg, rgba(244, 122, 22, 0.12), transparent 34%),
    linear-gradient(180deg, #050505 0%, #111 48%, #070707 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0.68rem 0.82rem;
  background: var(--orange);
  color: #090604;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--orange-2);
}

button.secondary {
  background: #191919;
  color: var(--white);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 88px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 14px max(18px, 3vw);
  background: rgba(5, 5, 5, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.logo {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.title-block {
  min-width: 0;
}

.eyebrow {
  color: var(--orange-2);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 3.2vw, 3.35rem);
  line-height: 1;
  font-weight: 950;
}

h2 {
  font-size: 1.05rem;
  line-height: 1.1;
  font-weight: 900;
}

p {
  color: var(--muted);
  margin-top: 0.35rem;
  font-size: 0.9rem;
}

.save-status {
  color: var(--orange-2);
  font-size: 0.8rem;
  font-weight: 900;
  white-space: nowrap;
}

.save-status::before {
  content: " / ";
  color: var(--muted);
  font-weight: 700;
}

.top-actions,
.button-row,
.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.shell {
  width: min(1720px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 18px 0 42px;
  display: grid;
  gap: 14px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  min-height: 86px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 250, 241, 0.055), rgba(255, 250, 241, 0.022));
}

.metric .label,
.label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.metric .value {
  margin-top: 0.45rem;
  color: var(--white);
  font-size: clamp(1.35rem, 2.2vw, 2.5rem);
  line-height: 0.95;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.metric .note {
  color: var(--orange-2);
  margin-top: 0.4rem;
  font-size: 0.78rem;
  font-weight: 800;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 16, 16, 0.88);
  overflow: hidden;
}

.panel-head {
  min-height: 68px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head.compact {
  min-height: 60px;
}

.controls label,
.check {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.84rem;
  font-weight: 800;
}

input,
select,
textarea {
  color: var(--white);
  background: #060606;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--orange);
}

.controls input {
  width: 88px;
  padding: 0.5rem;
}

.controls select,
.search {
  padding: 0.55rem 0.6rem;
}

.chart-wrap {
  position: relative;
  height: 330px;
  padding: 12px;
}

.chart-wrap.large {
  height: 500px;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.tooltip {
  position: absolute;
  z-index: 5;
  min-width: 178px;
  padding: 9px 10px;
  border-radius: 7px;
  background: rgba(5, 5, 5, 0.94);
  border: 1px solid var(--orange);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.42);
  pointer-events: none;
  font-size: 0.82rem;
  line-height: 1.35;
}

.hidden {
  display: none;
}

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

.timeline {
  padding: 12px 14px;
  display: flex;
  min-height: 76px;
  align-items: stretch;
  overflow-x: auto;
  scrollbar-color: var(--orange) #070707;
}

.timeline-seg {
  flex: 0 0 var(--seg-basis);
  min-width: 86px;
  border: 0;
  border-right: 2px solid #050505;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 8px 10px;
  color: #050505;
  text-align: left;
  font-size: 0.74rem;
  font-weight: 950;
  overflow: hidden;
  white-space: normal;
}

.timeline-seg:hover,
.timeline-seg:focus {
  outline: 2px solid var(--white);
  outline-offset: -3px;
}

.timeline-driver,
.timeline-laps {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-driver {
  white-space: nowrap;
}

.timeline-laps {
  font-size: 0.68rem;
  font-weight: 900;
}

.alloc-table-wrap,
.table-wrap {
  overflow: auto;
}

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

th,
td {
  padding: 0.62rem 0.72rem;
  border-bottom: 1px solid rgba(255, 250, 241, 0.08);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--orange-2);
  font-size: 0.74rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  user-select: none;
}

.lap-table th {
  cursor: pointer;
}

td {
  color: var(--white);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.alloc-table input {
  width: 100%;
  padding: 0.42rem 0.48rem;
}

.alloc-table input[type="color"] {
  width: 44px;
  height: 34px;
  padding: 2px;
}

.alloc-table button {
  padding: 0.42rem 0.52rem;
  background: #222;
  color: var(--white);
}

#allocationJson {
  width: calc(100% - 28px);
  min-height: 80px;
  margin: 12px 14px 0;
  padding: 10px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

.bottom {
  padding: 10px 14px 14px;
}

.stat-table {
  padding: 0 14px 14px;
}

.stat-row {
  display: grid;
  grid-template-columns: minmax(104px, 1fr) repeat(6, minmax(58px, 0.58fr));
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 250, 241, 0.08);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.status-pit_no_time,
.status-placeholder_no_time {
  color: var(--warn);
}

.status-safety_car {
  color: var(--bad);
  font-weight: 900;
}

.safety-row {
  background: rgba(255, 99, 79, 0.08);
}

.delta-fast {
  color: var(--orange-2);
  font-weight: 900;
}

.selected-row {
  background: rgba(244, 122, 22, 0.14);
}

@media (max-width: 1100px) {
  .metrics,
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    grid-template-columns: auto 1fr;
  }

  .top-actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .metrics,
  .grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap.large {
    height: 420px;
  }

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

  .stat-row {
    grid-template-columns: 1fr 1fr;
  }
}
