:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #181b1f;
  --panel-2: #20242a;
  --line: #333a42;
  --text: #edf2f4;
  --muted: #9ba7b2;
  --accent: #28d093;
  --accent-2: #e7bf4f;
  --danger: #ff6f61;
  --blue: #54a6ff;
  --grid: rgba(255, 255, 255, 0.08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  min-height: 72px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: #14171a;
}

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

p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

a {
  color: #b8d7ff;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
select {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
}

button {
  height: 34px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: #56616d;
}

.lap-card,
.track-panel,
.control-rail,
.chart-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.lap-card {
  padding: 14px;
  min-height: 250px;
}

.small-label,
.section-title {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.lap-card select {
  width: 100%;
  height: 34px;
}

.lap-time {
  margin: 14px 0;
  font-size: 38px;
  line-height: 1;
  font-weight: 800;
}

.primary .lap-time {
  color: var(--accent);
}

.compare .lap-time {
  color: var(--accent-2);
}

.primary-time {
  color: var(--accent);
}

.compare-time {
  color: var(--accent-2);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.metric-grid.compact {
  gap: 6px;
}

.metric-grid.compact .metric {
  padding: 6px;
}

.metric {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #15181c;
}

.metric .tag {
  color: var(--muted);
  font-size: 11px;
}

.metric .value {
  margin-top: 3px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-panel {
  position: relative;
  min-height: 340px;
  padding: 12px;
  overflow: hidden;
}

#track-canvas {
  width: 100%;
  height: 270px;
  display: block;
}

.track-readout {
  position: static;
  display: inline-block;
  max-width: 100%;
  margin-top: 10px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(16, 18, 20, 0.82);
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(680px, 1fr);
  gap: 14px;
  padding: 14px;
}

.control-rail {
  align-self: start;
  position: sticky;
  top: 10px;
  max-height: calc(100vh - 20px);
  overflow: auto;
}

.control-rail > .rail-section {
  padding: 0 14px;
}

.control-rail > .rail-section:first-of-type {
  padding-top: 14px;
}

.control-rail > .rail-section:last-child {
  padding-bottom: 14px;
}

.rail-section + .rail-section {
  margin-top: 20px;
}

.drop-zone {
  display: block;
  position: relative;
  margin: 14px;
  padding: 14px;
  border: 1px dashed #46515c;
  border-radius: 8px;
  background: #15191e;
  color: var(--muted);
  cursor: pointer;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: #17221f;
}

.drop-zone:hover {
  border-color: #64717f;
}

.file-input {
  display: none !important;
}

.drop-title {
  color: var(--text);
  font-weight: 800;
  font-size: 14px;
}

.drop-copy,
.progress-text {
  margin-top: 5px;
  font-size: 12px;
}

.parse-progress {
  margin-top: 12px;
}

.progress-track {
  height: 7px;
  border-radius: 999px;
  background: #0e1114;
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 120ms ease-out;
}

label {
  display: block;
  margin-bottom: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 12px;
}

.toggle-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.toggle-row span {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

select {
  width: 100%;
  height: 32px;
  padding: 0 8px;
}

#add-chart {
  width: 100%;
  background: #1f3a32;
  border-color: #2b6a56;
}

.hidden {
  display: none;
}

.meta-list,
.channel-summary {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.charts-area {
  min-width: 0;
}

.chart-panel {
  margin-bottom: 14px;
  overflow: hidden;
}

.chart-header {
  min-height: 44px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.chart-title {
  font-weight: 800;
  font-size: 14px;
}

.chart-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.chart-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.height-control {
  width: 110px;
  accent-color: var(--accent);
}

.remove-chart {
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--danger);
}

.reset-zoom {
  height: 30px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 12px;
}

.chart-canvas {
  width: 100%;
  height: 260px;
  display: block;
  background: #121519;
  cursor: crosshair;
}

.empty-state {
  margin: 28px auto;
  max-width: 560px;
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1100px) {
  main {
    min-width: 0;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .control-rail {
    position: static;
    max-height: none;
  }
}
