:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-muted: #f1f3f4;
  --text: #151719;
  --muted: #686f77;
  --border: #dde1e5;
  --border-strong: #c7cdd3;
  --accent: #167a63;
  --accent-strong: #0f674f;
  --accent-muted: #e4f3ef;
  --danger: #b42318;
  --success: #157347;
  --track: #1f2933;
  --track-inner: #ffffff;
  --track-footprint: #9ca3af;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101214;
  --surface: #171a1d;
  --surface-muted: #202428;
  --text: #eef0f2;
  --muted: #9aa1a9;
  --border: #2b3035;
  --border-strong: #3b4249;
  --accent: #4fc3a1;
  --accent-strong: #4fc3a1;
  --accent-muted: #173229;
  --danger: #ff8a80;
  --success: #6ee7a8;
  --track: #8da2b5;
  --track-inner: #101214;
  --track-footprint: #6f7b87;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-screen[hidden],
.app-shell[hidden] {
  display: none;
}

.auth-card {
  display: grid;
  width: min(100%, 430px);
  gap: 24px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.12);
}

.auth-card h1 {
  margin: 4px 0 0;
  font-size: 1.5rem;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-form,
.auth-form label {
  display: grid;
  gap: 8px;
}

.auth-form {
  gap: 16px;
}

.auth-form label[hidden] {
  display: none;
}

.auth-form label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.auth-form input,
.search-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 11px;
}

.primary-button {
  min-height: 42px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  cursor: pointer;
  font-weight: 700;
}

.auth-links,
.header-actions,
.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.auth-links button,
.text-button {
  padding: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.82rem;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

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

.visibility-badge,
.driver-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: 3px 7px;
  font-size: 0.68rem;
  font-weight: 650;
}

.file-row-meta {
  display: flex;
  gap: 6px;
  padding: 0 10px 8px 48px;
  flex-wrap: wrap;
}

.file-status-row {
  display: grid;
  gap: 6px;
  padding: 0 10px 4px 53px;
}

.file-status-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 650;
  line-height: 1.35;
}

.file-status-row.ready .file-status-label {
  color: var(--success);
}

.file-status-row.error .file-status-label {
  color: var(--danger);
}

.file-status-row.active .file-status-label {
  color: var(--accent);
}

.file-status-progress {
  position: relative;
  width: 100%;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.file-status-progress::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -45%;
  width: 45%;
  border-radius: inherit;
  background: var(--accent);
  animation: file-status-progress 1.1s ease-in-out infinite;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) minmax(260px, 340px);
  grid-template-areas: "rail main laps";
  height: 100vh;
  min-height: 100vh;
  position: relative;
  transition: grid-template-columns 180ms ease;
}

.app-shell.lap-panel-collapsed {
  grid-template-columns: 76px minmax(0, 1fr) 76px;
  grid-template-areas: "rail main laps";
}

.app-rail {
  grid-area: rail;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 14px 8px;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 84%, var(--bg));
}

.rail-brand {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  align-self: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-size: 0.76rem;
  font-weight: 850;
}

.rail-button {
  display: grid;
  min-width: 0;
  min-height: 56px;
  place-items: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
}

.rail-button:hover,
.rail-button:focus-visible {
  border-color: var(--border);
  background: var(--surface-muted);
  color: var(--text);
}

.rail-button.active {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  color: var(--accent-strong);
}

.rail-button[hidden] {
  display: none;
}

.rail-button-logout {
  margin-top: auto;
}

.rail-icon {
  position: relative;
  display: block;
  width: 20px;
  height: 20px;
  color: currentColor;
}

.rail-icon::before,
.rail-icon::after {
  content: "";
  position: absolute;
}

.rail-icon-files::before {
  left: 3px;
  right: 3px;
  bottom: 3px;
  height: 7px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 2px 2px 4px 4px;
}

.rail-icon-files::after {
  left: 9px;
  top: 2px;
  width: 0;
  height: 11px;
  border-left: 2px solid currentColor;
  box-shadow: 0 0 0 0 currentColor;
}

.rail-icon-files {
  background:
    linear-gradient(45deg, transparent 47%, currentColor 48% 54%, transparent 55%) 5px 3px / 7px 7px no-repeat,
    linear-gradient(-45deg, transparent 47%, currentColor 48% 54%, transparent 55%) 8px 3px / 7px 7px no-repeat;
}

.rail-icon-laps::before {
  left: 2px;
  top: 4px;
  width: 14px;
  height: 10px;
  border: 2px solid currentColor;
  border-radius: 50%;
  transform: rotate(-18deg);
}

.rail-icon-laps::after {
  right: 2px;
  top: 1px;
  width: 2px;
  height: 13px;
  background: currentColor;
  box-shadow: 4px 2px 0 -1px currentColor;
}

.rail-icon-lap-details {
  border: 2px solid currentColor;
  border-radius: 3px;
}

.rail-icon-lap-details::before {
  inset: 5px 0 auto 0;
  height: 2px;
  background: currentColor;
  box-shadow: 0 5px 0 currentColor;
}

.rail-icon-lap-details::after {
  top: 0;
  bottom: 0;
  left: 6px;
  width: 2px;
  background: currentColor;
  box-shadow: 6px 0 0 currentColor;
}

.rail-icon-corners::before {
  left: 2px;
  top: 4px;
  width: 14px;
  height: 12px;
  border: 2px solid currentColor;
  border-right: 0;
  border-bottom: 0;
  border-radius: 12px 0 0 0;
  transform: rotate(-28deg);
}

.rail-icon-corners::after {
  right: 3px;
  bottom: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.rail-icon-sectors::before {
  left: 2px;
  top: 3px;
  width: 16px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.rail-icon-sectors::after {
  left: 9px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: currentColor;
  transform: rotate(28deg);
  box-shadow: -5px 6px 0 currentColor;
}

.rail-icon-trace::before {
  left: 2px;
  top: 5px;
  width: 16px;
  height: 12px;
  border: 2px solid currentColor;
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
}

.rail-icon-trace::after {
  left: 9px;
  top: 10px;
  width: 2px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  transform: rotate(45deg);
  transform-origin: 50% 100%;
}

.rail-icon-accel {
  background:
    linear-gradient(90deg, currentColor 0 100%) 2px 9px / 16px 2px no-repeat;
}

.rail-icon-accel::before {
  right: 1px;
  top: 6px;
  width: 7px;
  height: 7px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(45deg);
}

.rail-icon-accel::after {
  left: 2px;
  top: 5px;
  width: 3px;
  height: 10px;
  border-radius: 999px;
  background: currentColor;
}

.rail-icon-logout::before {
  left: 2px;
  top: 3px;
  width: 9px;
  height: 14px;
  border: 2px solid currentColor;
  border-right: 0;
  border-radius: 3px 0 0 3px;
}

.rail-icon-logout::after {
  right: 1px;
  top: 5px;
  width: 11px;
  height: 8px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: skewX(28deg);
}

/* Workspace icons are inline SVGs so each symbol remains crisp and theme-aware. */
svg.rail-icon {
  position: static;
  width: 22px;
  height: 22px;
  overflow: visible;
  background: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.lap-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.lap-panel {
  grid-area: laps;
  border-left: 1px solid var(--border);
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 22px 22px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-header h1,
.track-header h2,
.panel-section h2 {
  margin: 0;
  font-weight: 650;
}

.panel-header h1 {
  font-size: 1.15rem;
}

.track-header h2 {
  font-size: 1.1rem;
}

.panel-section h2 {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.theme-toggle,
.upload-button,
.secondary-button,
.panel-collapse-button,
.panel-restore-button {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
}

.theme-toggle:hover,
.upload-button:hover,
.secondary-button:hover:not(:disabled),
.panel-collapse-button:hover,
.panel-restore-button:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.secondary-button.is-busy {
  cursor: wait;
  opacity: 0.78;
}

.secondary-button.is-busy::after,
.file-loading-indicator {
  content: "";
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: busy-spin 700ms linear infinite;
}

.theme-toggle {
  min-width: 64px;
}

.panel-collapse-button,
.panel-restore-button {
  display: grid;
  place-items: center;
  width: 36px;
  padding: 0;
}

.panel-restore-button {
  position: absolute;
  z-index: 5;
  top: 22px;
  left: 6px;
}

.panel-restore-button[hidden] {
  display: none;
}

.collapse-icon,
.restore-icon {
  position: relative;
  width: 16px;
  height: 16px;
}

.collapse-icon::before,
.restore-icon::before {
  content: "";
  position: absolute;
  top: 3px;
  width: 8px;
  height: 8px;
  border-top: 2px solid currentColor;
  border-left: 2px solid currentColor;
}

.collapse-icon::before {
  left: 4px;
  transform: rotate(-45deg);
}

.restore-icon::before {
  right: 4px;
  transform: rotate(135deg);
}

.lap-panel-header .collapse-icon::before {
  left: 3px;
  transform: rotate(135deg);
}

.panel-section {
  display: grid;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.lap-panel-section {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  height: 100vh;
  min-height: 0;
  padding: 22px;
}

.lap-panel-section h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
}

.lap-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lap-panel-header .panel-collapse-button {
  display: grid;
  width: 32px;
  min-height: 32px;
}

.lap-collapsed-rail {
  display: none;
}

.lap-panel-collapsed .lap-panel {
  align-items: stretch;
  background: color-mix(in srgb, var(--surface) 84%, var(--bg));
}

.lap-panel-collapsed .lap-panel-section {
  display: none;
}

.lap-panel-collapsed .lap-collapsed-rail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
  padding: 14px 8px;
}

.lap-rail-restore-button {
  display: grid;
  min-width: 0;
  min-height: 56px;
  place-items: center;
  gap: 5px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  color: var(--accent);
  cursor: pointer;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.1;
}

.lap-rail-restore-button:hover,
.lap-rail-restore-button:focus-visible {
  border-color: var(--border-strong);
  background: var(--surface-muted);
  color: var(--text);
}

.lap-rail-restore-button .restore-icon {
  position: relative;
  width: 20px;
  height: 20px;
}

.lap-rail-restore-button .restore-icon::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: solid currentColor;
  border-width: 0 0 2px 2px;
  transform: rotate(45deg);
}

.lap-mini-list {
  display: grid;
  gap: 4px;
  align-content: start;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 1px;
}

.lap-mini-item {
  --lap-color: var(--accent);
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1;
}

.lap-mini-item.reference,
.lap-mini-item.compare {
  border-color: var(--lap-color);
  background: color-mix(in srgb, var(--lap-color) 18%, var(--surface));
  box-shadow: inset 3px 0 0 var(--lap-color);
}

.lap-mini-number {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lap-mini-role {
  position: absolute;
  right: 3px;
  bottom: 3px;
  display: grid;
  width: 13px;
  height: 13px;
  place-items: center;
  border-radius: 50%;
  background: var(--lap-color);
  color: var(--surface);
  font-size: 0.5rem;
  font-weight: 850;
}

.lap-mini-empty {
  writing-mode: vertical-rl;
  justify-self: center;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.analytics-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.analytics-tab {
  min-width: 0;
  min-height: 32px;
  padding: 6px 7px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 650;
}

.analytics-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.analytics-panel {
  min-height: 0;
  overflow-y: auto;
}

.analytics-panel:not(.active),
.analytics-panel[hidden] {
  display: none;
}

#lapsPanel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

#lapsPanel[hidden] {
  display: none;
}

.lap-sort-control {
  display: grid;
  gap: 6px;
}

.lap-controls {
  display: grid;
  gap: 10px;
}

.lap-sort-control span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
}

.lap-sort-control select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 7px 10px;
}

.lap-filter-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.lap-filter-control input {
  margin: 0;
}

.lap-selection-summary {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.lap-selection-count {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.lap-selection-chip {
  --lap-color: var(--accent);
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.lap-selection-chip::before {
  content: "";
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: var(--lap-color);
}

.upload-box {
  display: grid;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
  padding: 14px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--surface-muted);
}

.upload-box p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.upload-button {
  width: 100%;
  background: var(--text);
  border-color: var(--text);
  color: var(--surface);
}

.upload-button:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.upload-box.dragging {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.upload-box.uploading {
  border-color: var(--accent);
}

.upload-box.uploading .upload-button {
  cursor: wait;
  opacity: 0.76;
}

.upload-progress {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.upload-progress[hidden] {
  display: none;
}

.upload-progress-header {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
}

.upload-progress-header span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-progress-header strong {
  flex: 0 0 auto;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  font-weight: 650;
}

.upload-progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.upload-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}

.upload-progress.is-processing .upload-progress-bar {
  animation: upload-pulse 900ms ease-in-out infinite alternate;
}

@keyframes upload-pulse {
  from {
    opacity: 0.55;
  }

  to {
    opacity: 1;
  }
}

@keyframes file-status-progress {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(322%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .upload-progress.is-processing .upload-progress-bar,
  .file-status-progress::after,
  .secondary-button.is-busy::after,
  .file-loading-indicator {
    animation: none;
  }
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.file-row {
  --session-color: var(--accent);
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 82%, var(--surface-muted));
}

.file-row:hover {
  border-color: var(--border-strong);
}

.file-row.selected,
.file-row.focused {
  border-color: var(--session-color);
  background: color-mix(in srgb, var(--accent-muted) 58%, var(--surface));
  box-shadow: inset 4px 0 0 var(--session-color);
}

.file-row.is-busy {
  cursor: wait;
}

.file-select-button {
  width: 100%;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.file-select-button:hover:not(:disabled) {
  background: var(--surface-muted);
}

.file-row.selected .file-select-button:hover:not(:disabled),
.file-row.focused .file-select-button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent-muted) 82%, var(--surface));
}

.file-select-button:disabled {
  cursor: not-allowed;
}

.file-select-button.is-busy {
  grid-template-columns: 34px minmax(0, 1fr) 18px;
  cursor: wait;
  background: var(--surface-muted);
}

.file-select-button.selected {
  border-color: var(--session-color);
  background: var(--accent-muted);
}

.file-select-button.overlayed {
  border-color: transparent;
}

.file-select-button.selected.overlayed {
  border-color: var(--session-color);
}

.file-select-button.focused {
  border-color: var(--session-color);
}

.file-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 7px;
  min-width: 0;
  padding: 7px 0 0 44px;
  border-top: 1px solid color-mix(in srgb, var(--border) 76%, transparent);
}

.file-action-button {
  max-width: 100%;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.76rem;
}

.file-action-button:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
  color: var(--text);
}

.file-action-button.danger {
  color: var(--danger);
}

.file-icon {
  width: 34px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--surface-muted);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 700;
}

.selected .file-icon {
  color: var(--session-color);
  border-color: var(--session-color);
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes busy-spin {
  to {
    transform: rotate(360deg);
  }
}

.info-grid {
  display: grid;
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.info-item {
  display: grid;
  grid-template-columns: minmax(92px, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
}

.info-item + .info-item {
  border-top: 1px solid var(--border);
}

.info-item span:first-child {
  color: var(--muted);
  font-size: 0.86rem;
}

.info-item strong {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
  font-size: 0.9rem;
  font-weight: 560;
}

.telemetry-types-item {
  align-items: start;
}

.telemetry-type-list {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.telemetry-type-row {
  display: grid;
  gap: 2px;
  justify-items: end;
  min-width: 0;
}

.telemetry-type-row strong {
  text-align: right;
}

.telemetry-type-row span {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.status-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.status-text[data-type="error"] {
  color: var(--danger);
}

.status-text[data-type="success"] {
  color: var(--success);
}

.lap-list {
  display: grid;
  gap: 6px;
  align-content: start;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.lap-list .empty-state {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.lap-button {
  --lap-color: var(--accent);
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.lap-button:hover {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.lap-button:not(.selected) {
  color: color-mix(in srgb, var(--text) 82%, var(--muted));
}

.lap-title,
.lap-meta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lap-title {
  font-size: 0.9rem;
  font-weight: 650;
}

.lap-meta {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.78rem;
}

.lap-role-badge {
  --lap-color: var(--accent);
  min-height: 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: 2px 7px;
  font-size: 0.68rem;
  font-weight: 750;
  text-transform: uppercase;
}

.lap-role-badge.reference,
.lap-role-badge.compare {
  border-color: var(--lap-color);
  background: color-mix(in srgb, var(--lap-color) 18%, var(--surface));
  color: var(--text);
}

.lap-role-badge.fastest {
  border-color: var(--success);
  background: color-mix(in srgb, var(--success) 14%, var(--surface));
  color: var(--success);
}

.lap-comparison-controls {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  align-items: center;
}

.lap-slot-button {
  --lap-color: #f5c542;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 650;
}

.lap-slot-button:hover,
.lap-slot-button.selected {
  border-color: var(--lap-color);
  color: var(--text);
  background: color-mix(in srgb, var(--lap-color) 18%, var(--surface));
}

.lap-button.reference,
.lap-button.compare {
  border-color: var(--lap-color, var(--accent));
  background: color-mix(in srgb, var(--lap-color) 14%, var(--surface));
  box-shadow: inset 4px 0 0 var(--lap-color);
}

.lap-button.reference {
  --lap-color: #f5c542;
}

.lap-button.compare {
  --lap-color: #00b8d9;
}

.main-panel {
  grid-area: main;
  display: grid;
  grid-auto-rows: max-content;
  gap: 16px;
  height: 100vh;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px;
}

.main-panel.files-view {
  grid-template-rows: max-content;
  overflow-y: auto;
}

.main-panel.lap-detail-view {
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.main-panel.map-only-view .track-card {
  grid-template-rows: auto minmax(420px, calc(100vh - 120px));
}

.file-workspace {
  display: grid;
  grid-template-rows: auto max-content;
  align-content: start;
  gap: 16px;
  min-width: 0;
  min-height: 0;
  overflow: visible;
}

.file-workspace[hidden] {
  display: none;
}

.lap-detail-workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.lap-detail-workspace[hidden] {
  display: none;
}

.lap-detail-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.lap-detail-header h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.lap-detail-theory {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.4fr);
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(92, 124, 255, 0.32);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(92, 124, 255, 0.13), rgba(22, 122, 99, 0.11));
}

.lap-detail-theory[hidden] {
  display: none;
}

.lap-detail-theory-label {
  color: #c6cbd3;
  font-size: 0.82rem;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lap-detail-theory strong {
  color: #ffffff;
  font-size: 1.35rem;
  font-weight: 820;
  font-variant-numeric: tabular-nums;
}

.lap-detail-theory-detail {
  color: #9aa4b5;
  font-size: 0.88rem;
  font-weight: 620;
  text-align: right;
}

[data-theme="light"] .lap-detail-theory {
  background: linear-gradient(135deg, rgba(92, 124, 255, 0.11), rgba(22, 122, 99, 0.09));
}

[data-theme="light"] .lap-detail-theory-label,
[data-theme="light"] .lap-detail-theory strong {
  color: #202631;
}

[data-theme="light"] .lap-detail-theory-detail {
  color: #5f6878;
}

.lap-detail-table-wrap {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.lap-detail-empty {
  margin: 0;
  padding: 28px;
}

.lap-detail-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.lap-detail-table th,
.lap-detail-table td {
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  text-align: center;
  white-space: nowrap;
}

.lap-detail-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #202631;
  color: #c6cbd3;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lap-detail-sort-button {
  display: inline-grid;
  grid-template-columns: minmax(0, auto) 0.9em;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.lap-detail-sort-button:hover,
.lap-detail-sort-button:focus-visible {
  color: #ffffff;
}

.lap-detail-sort-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.lap-detail-sort-button::after {
  content: "";
  width: 0.75em;
  height: 0.75em;
  background:
    linear-gradient(135deg, transparent 47%, #798293 50%, transparent 53%) 0 0 / 100% 50% no-repeat,
    linear-gradient(45deg, transparent 47%, #798293 50%, transparent 53%) 0 100% / 100% 50% no-repeat;
  color: #798293;
  font-size: 0.78rem;
  line-height: 1;
}

.lap-detail-sort-button.active.asc::after {
  background: none;
  width: 0;
  height: 0;
  border-right: 0.34em solid transparent;
  border-left: 0.34em solid transparent;
  border-bottom: 0.52em solid var(--accent);
  color: var(--accent);
}

.lap-detail-sort-button.active.desc::after {
  background: none;
  width: 0;
  height: 0;
  border-right: 0.34em solid transparent;
  border-left: 0.34em solid transparent;
  border-top: 0.52em solid var(--accent);
  color: var(--accent);
}

.lap-detail-table th span {
  display: block;
  grid-column: 1 / 2;
  margin-top: 2px;
  color: #798293;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
}

.lap-detail-table tbody tr {
  background: #0f1117;
}

[data-theme="light"] .lap-detail-table tbody tr {
  background: #ffffff;
}

.lap-detail-table tbody tr:last-child td {
  border-bottom: none;
}

.lap-detail-table th:first-child,
.lap-detail-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: inherit;
}

.lap-detail-table th:first-child {
  z-index: 4;
  background: #202631;
}

.lap-detail-lap {
  color: var(--accent);
  font-weight: 800;
}

.lap-detail-metric-cell {
  font-weight: 760;
}

.lap-detail-sector-cell {
  min-width: 128px;
}

.lap-detail-sector-cell strong,
.lap-detail-sector-cell span {
  display: block;
}

.lap-detail-sector-cell strong {
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 760;
}

.lap-detail-sector-cell span {
  margin-top: 4px;
  color: #798293;
  font-size: 0.78rem;
  font-weight: 650;
}

.lap-detail-metric-cell.fastest,
.lap-detail-sector-cell.fastest {
  background: rgba(34, 197, 94, 0.14);
  color: #22c55e;
}

.lap-detail-sector-cell.fastest strong {
  color: #22c55e;
}

.lap-detail-metric-cell.slowest,
.lap-detail-sector-cell.slowest {
  background: rgba(245, 197, 66, 0.13);
  color: #f5c542;
}

.lap-detail-sector-cell.slowest strong {
  color: #f5c542;
}

.file-workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 2px 0;
}

.file-workspace-header h1,
.file-workspace-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 650;
}

.file-workspace-upload {
  width: auto;
  min-width: 160px;
}

.file-workspace-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.file-workspace-upload-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  overflow: visible;
  border: 0;
  background: transparent;
}

.file-workspace-upload-box p {
  max-width: 220px;
  font-size: 0.78rem;
  line-height: 1.25;
}

.file-workspace-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) repeat(2, minmax(250px, 1fr));
  grid-template-rows: max-content max-content;
  grid-template-areas:
    "library info telemetry"
    "library video status";
  gap: 16px;
  min-width: 0;
  min-height: 0;
  align-items: stretch;
  overflow: visible;
}

.file-workspace-card {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  overflow: visible;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.file-workspace-card h2,
.file-workspace-card h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
}

.file-library-card {
  grid-area: library;
  grid-row: 1 / span 2;
  min-height: 360px;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: stretch;
  overflow: hidden;
}

#fileWorkspaceInfoCard {
  grid-area: info;
}

#fileWorkspaceTelemetryCard {
  grid-area: telemetry;
}

#fileWorkspaceVideoCard {
  grid-area: video;
}

#fileWorkspaceStatusCard {
  grid-area: status;
}

.video-availability {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.video-availability-row {
  display: grid;
  gap: 7px;
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.video-availability-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
}

.video-availability-badge {
  flex: 0 0 auto;
  padding: 3px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.video-availability-badge.ready {
  border-color: color-mix(in srgb, var(--success) 45%, var(--border));
  color: var(--success);
}

.video-availability-badge.active {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--accent);
}

.video-availability-badge.error {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  color: var(--danger);
}

.video-availability-detail {
  line-height: 1.35;
}

.file-library-card .file-list {
  align-content: start;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.file-library-card .file-row {
  align-content: start;
}

.file-library-card .file-select-button {
  min-height: 54px;
}

.file-library-card .file-actions {
  padding: 8px 0 0 44px;
}

.file-library-card .file-action-button {
  min-width: 68px;
}

.tile-info-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  border: 0;
  border-radius: 0;
  overflow: visible;
}

.tile-info-grid .info-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  min-height: 74px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.tile-info-grid .info-item + .info-item {
  border-top: 1px solid var(--border);
}

#fileWorkspaceTelemetry .telemetry-types-item {
  grid-column: 1 / -1;
}

#fileWorkspaceTelemetry .telemetry-type-list {
  grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
  gap: 10px 16px;
}

.tile-info-grid .info-item strong,
.tile-info-grid .telemetry-type-row,
.tile-info-grid .telemetry-type-row strong,
.tile-info-grid .telemetry-type-row span {
  justify-items: start;
  text-align: left;
}

.track-card {
  display: grid;
  grid-template-rows: auto minmax(420px, 62vh);
  gap: 16px;
  min-height: 0;
}

.track-card[hidden],
.analytics-card[hidden] {
  display: none;
}

.analytics-card {
  display: grid;
  grid-template-rows: auto auto;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.analytics-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.analytics-card-header h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
}

.analytics-card .analytics-tabs {
  display: none;
}

.analytics-card .analytics-panel {
  overflow: visible;
}

.track-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.track-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.gate-action-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.map-settings {
  position: relative;
}

.map-settings-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  width: min(260px, calc(100vw - 32px));
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 44px color-mix(in srgb, #000 28%, transparent);
}

.map-settings-menu[hidden] {
  display: none;
}

.map-setting-row {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.map-setting-row:hover,
.map-setting-row:focus-visible {
  background: var(--surface-muted);
}

.map-setting-row[aria-pressed="true"] {
  color: var(--accent);
}

.map-setting-row:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.map-setting-label {
  min-width: 0;
  overflow: hidden;
  color: inherit;
  font-size: 0.84rem;
  font-weight: 560;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-setting-value {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.map-setting-row[aria-pressed="true"] .map-setting-value {
  color: var(--accent);
}

.map-setting-row[aria-pressed="true"] .toggle-indicator {
  border-color: var(--accent);
  background: var(--accent);
}

.map-setting-row[aria-pressed="true"] .toggle-indicator::after {
  opacity: 1;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle-indicator {
  position: relative;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 2px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
}

.toggle-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent);
}

.toggle-button[aria-pressed="true"] .toggle-indicator {
  border-color: var(--accent);
  background: var(--accent);
}

.toggle-button[aria-pressed="true"] .toggle-indicator::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 4px;
  left: 3px;
  top: 3px;
  border-left: 2px solid var(--surface);
  border-bottom: 2px solid var(--surface);
  transform: rotate(-45deg);
}

.button-icon {
  position: relative;
  display: inline-block;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.satellite-icon {
  border: 2px solid currentColor;
  border-radius: 50%;
}

.satellite-icon::before,
.satellite-icon::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.satellite-icon::before {
  width: 2px;
  height: 8px;
  left: 5px;
  top: 2px;
}

.satellite-icon::after {
  width: 8px;
  height: 2px;
  left: 2px;
  top: 5px;
}

.settings-icon,
.settings-icon::before,
.settings-icon::after {
  border: 2px solid currentColor;
  border-radius: 50%;
}

.settings-icon {
  width: 16px;
  height: 16px;
}

.settings-icon::before,
.settings-icon::after {
  content: "";
  position: absolute;
  width: 3px;
  height: 3px;
  background: currentColor;
}

.settings-icon::before {
  left: 4px;
  top: -4px;
}

.settings-icon::after {
  right: -4px;
  bottom: 2px;
}

.gate-icon::before {
  content: "";
  position: absolute;
  width: 3px;
  height: 16px;
  left: 7px;
  top: 0;
  border-radius: 999px;
  background: currentColor;
  transform: rotate(34deg);
}

.overlay-status {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.map-frame {
  position: relative;
  display: grid;
  min-height: 420px;
}

.map-container {
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px),
    var(--surface);
  background-size: 48px 48px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.95rem;
  overflow: hidden;
  position: relative;
}

.map-nav-controls {
  position: absolute;
  z-index: 7;
  right: 12px;
  bottom: 54px;
  display: grid;
  grid-template-columns: 38px;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: 0 6px 20px color-mix(in srgb, #000 18%, transparent);
}

.map-nav-controls[hidden] {
  display: none;
}

.map-nav-button {
  min-width: 0;
  width: 38px;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
}

.map-nav-button:hover,
.map-nav-button:focus-visible {
  border-color: var(--border);
  background: var(--surface-muted);
}

.map-nav-button.wide {
  grid-column: auto;
  font-size: 0.74rem;
}

.map-nav-toggle {
  position: absolute;
  z-index: 8;
  right: 12px;
  bottom: 12px;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 6px 20px color-mix(in srgb, #000 18%, transparent);
}

.map-nav-toggle[hidden] {
  display: none;
}

.map-nav-toggle:hover,
.map-nav-toggle:focus-visible {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.map-nav-toggle-icon {
  position: relative;
  width: 14px;
  height: 14px;
}

.map-nav-toggle-icon::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 5px;
  width: 8px;
  height: 8px;
  border-top: 2px solid currentColor;
  border-left: 2px solid currentColor;
  transform: rotate(45deg);
}

.map-nav-toggle.open .map-nav-toggle-icon::before {
  top: 1px;
  transform: rotate(225deg);
}

.map-container.satellite-mode {
  background: #111820;
}

.map-container svg {
  width: 100%;
  height: 100%;
}

.map-container .track-svg {
  cursor: grab;
  touch-action: none;
}

.map-container .track-svg.map-panning {
  cursor: grabbing;
}

.map-container .track-svg.gate-editing {
  cursor: default;
}

.map-container.side-by-side-mode {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
}

.comparison-map {
  width: 100%;
  height: 100%;
  place-self: stretch;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px),
    var(--surface);
  background-size: 48px 48px;
  overflow: hidden;
}

.satellite-mode .comparison-map {
  background: #111820;
}

.comparison-map-header {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text);
  font-size: 0.8rem;
}

.comparison-map-header strong {
  color: var(--lap-color);
}

.comparison-map-header span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comparison-map svg {
  min-height: 0;
}

.track-svg .satellite-tile {
  pointer-events: none;
}

.track-svg circle {
  fill: var(--surface);
  stroke: var(--accent);
}

.track-svg .track-footprint-image {
  pointer-events: none;
}

.track-svg .gate-line {
  cursor: grab;
  stroke: var(--danger);
}

.track-svg.gate-editing .gate-line {
  cursor: grabbing;
}

.track-svg .speed-lap-segment,
.track-svg .acceleration-lap-segment,
.track-svg .acceleration-lap-casing {
  fill: none;
  pointer-events: none;
}

.track-svg .speed-lap-segment {
  stroke-linecap: round;
}

.track-svg .acceleration-lap-segment,
.track-svg .acceleration-lap-casing {
  stroke-linecap: square;
}

.track-svg .speed-lap-segment,
.track-svg .acceleration-lap-segment {
  stroke-width: 5;
}

.track-svg .acceleration-lap-segment {
  stroke-width: 6;
}

.track-svg .acceleration-lap-casing {
  stroke: rgba(10, 18, 28, 0.82);
  stroke-width: 9;
}

.track-svg .speed-corner-highlight {
  fill: none;
  stroke: #ffffff;
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.72;
  pointer-events: none;
}

.track-svg .sector-highlight {
  fill: none;
  stroke: #ffffff;
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.72;
  pointer-events: none;
}

.track-svg .sector-overlay {
  pointer-events: none;
}

.track-svg .sector-boundary {
  fill: var(--lap-color, var(--accent));
  stroke: var(--surface);
  stroke-width: 3;
}

.track-svg .sector-label circle {
  fill: color-mix(in srgb, var(--surface) 88%, transparent);
  stroke: var(--lap-color, var(--accent));
  stroke-width: 2;
}

.track-svg .sector-label {
  cursor: pointer;
  pointer-events: auto;
}

.track-svg .sector-label.active circle {
  stroke: #f5c542;
  stroke-width: 4;
}

.track-svg .sector-label text {
  fill: var(--text);
  font-size: 9px;
  font-weight: 750;
  text-anchor: middle;
}

.track-svg .corner-marker {
  cursor: pointer;
}

.track-svg .corner-marker circle {
  fill: var(--surface);
  stroke: #ffffff;
  stroke-width: 3;
}

.track-svg .corner-marker.active circle {
  stroke: #f5c542;
  stroke-width: 4;
}

.track-svg .corner-marker text {
  fill: var(--text);
  font-size: 11px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}

.map-placeholder {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.map-placeholder strong {
  font-weight: 560;
}

.speed-analysis-panel {
  display: grid;
  gap: 10px;
  min-width: 0;
  align-content: start;
}

.speed-analysis-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.speed-analysis-header h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
}

.speed-analysis-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.speed-analysis-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
}

.speed-analysis-table th,
.speed-analysis-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.speed-analysis-table th {
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
}

.speed-analysis-table tbody tr {
  cursor: pointer;
}

.speed-analysis-table tbody tr:hover,
.speed-analysis-table tbody tr.active {
  background: var(--surface-muted);
}

.speed-analysis-table tbody tr:last-child td {
  border-bottom: none;
}

.corner-cell {
  color: var(--text);
  font-weight: 700;
}

.speed-value-list {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.speed-value-chip {
  --lap-color: var(--accent);
  display: inline-flex;
  align-items: center;
  min-width: 48px;
  border-left: 3px solid var(--lap-color);
  border-radius: 6px;
  background: color-mix(in srgb, var(--lap-color) 18%, transparent);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  line-height: 1;
  padding: 5px 7px;
}

.speed-value-chip.fastest {
  color: #22c55e;
}

[data-theme="light"] .speed-value-chip.fastest {
  color: #15803d;
}

.speed-value-chip.slowest {
  color: #f87171;
}

[data-theme="light"] .speed-value-chip.slowest {
  color: #dc2626;
}

.corner-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 10px;
  min-width: 0;
}

.corner-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.corner-card:hover,
.corner-card.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
}

.corner-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.corner-card-header strong {
  font-size: 1rem;
  font-weight: 800;
}

.corner-card-header span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.corner-metric {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-muted) 54%, transparent);
}

.corner-metric-label {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 750;
  text-transform: uppercase;
}

.corner-metric-values {
  display: grid;
  gap: 4px;
}

.corner-metric-value {
  --lap-color: var(--accent);
  min-width: 0;
  overflow: hidden;
  border-left: 3px solid var(--lap-color);
  border-radius: 5px;
  background: color-mix(in srgb, var(--lap-color) 16%, transparent);
  color: var(--text);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  line-height: 1;
  padding: 5px 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.corner-metric-delta {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.corner-metric-delta.gain {
  color: var(--success);
}

.corner-metric-delta.loss {
  color: var(--danger);
}

.corner-metric-delta.even {
  color: var(--muted);
}

.corner-metric-bar {
  position: relative;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.corner-metric-bar::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--delta-width, 0%);
  border-radius: inherit;
  background: currentColor;
}

.sectors-panel {
  display: grid;
  gap: 10px;
  min-width: 0;
  align-content: start;
}

.sector-analysis-table td {
  font-variant-numeric: tabular-nums;
}

.sector-gain {
  color: var(--success);
  font-weight: 700;
}

.sector-loss {
  color: var(--danger);
  font-weight: 700;
}

.speed-trace-panel {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
}

.acceleration-panel {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
}

.analytics-card .speed-trace-panel {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(140px, 1fr);
}

.analytics-card .speed-trace-panel .speed-analysis-header {
  grid-column: 1;
}

.analytics-card .speed-trace-panel .speed-trace-chart {
  grid-column: 1;
  grid-row: 3;
  height: 100%;
  min-height: 140px;
}

.analytics-card .speed-trace-legend {
  grid-column: 1;
  grid-row: 2;
}

.analytics-card .acceleration-panel {
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: auto;
  overflow: visible;
}

.analytics-card .acceleration-panel .speed-analysis-header,
.analytics-card .acceleration-actions,
.analytics-card .acceleration-stats-table,
.analytics-card .acceleration-panel .speed-trace-legend,
.analytics-card .acceleration-panel .empty-state {
  grid-column: 1;
}

.analytics-card .acceleration-actions {
  grid-row: auto;
}

.analytics-card .acceleration-panel .speed-trace-chart {
  grid-column: 1;
  grid-row: auto;
  height: auto;
  min-height: 180px;
}

.analytics-card .acceleration-panel .speed-trace-legend {
  grid-row: auto;
}

.analytics-card .acceleration-stats-table {
  grid-row: auto;
}

.acceleration-actions {
  display: flex;
  justify-content: flex-end;
}

.acceleration-stats-table td {
  font-variant-numeric: tabular-nums;
}

.speed-trace-chart {
  width: 100%;
  min-height: 180px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.speed-trace-axis {
  fill: none;
  stroke: var(--border-strong);
  stroke-width: 1.5;
}

.speed-trace-line {
  fill: none;
  stroke: var(--lap-color);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.speed-trace-line.compare {
  stroke-dasharray: 6 4;
}

.acceleration-smoothed-line {
  stroke-width: 3.5;
}

.speed-trace-corner {
  stroke: var(--border-strong);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}

.speed-trace-cursor {
  stroke: var(--accent);
  stroke-width: 2;
  pointer-events: none;
}

.speed-trace-cursor-label {
  font-size: 11px;
  font-weight: 700;
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.speed-trace-label {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.telemetry-map-cursor {
  pointer-events: none;
}

.telemetry-map-cursor circle:first-child {
  fill: none;
  stroke: var(--lap-color, var(--accent));
  stroke-width: 3;
  opacity: 0.35;
}

.telemetry-map-cursor circle:last-child {
  fill: var(--lap-color, var(--accent));
  stroke: var(--surface);
  stroke-width: 2;
}

.speed-trace-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.speed-trace-legend span {
  --lap-color: var(--accent);
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: min(260px, 100%);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-left: 3px solid var(--lap-color);
  border-radius: 6px;
  background: color-mix(in srgb, var(--lap-color) 14%, transparent);
  padding: 4px 8px;
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 650;
  line-height: 1.2;
}

.speed-trace-legend .trace-note {
  border-left-color: var(--border-strong);
  background: var(--surface-muted);
  color: var(--muted);
  font-weight: 560;
}

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

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

.video-player-grid.dual {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.video-player-section,
.dynamics-calibration-card {
  min-width: 0;
}

.video-player-section {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #080a0d;
}

.video-player-header {
  display: flex;
  gap: 10px;
  align-items: baseline;
  min-width: 0;
  margin: 0 2px 8px;
  color: #fff;
}

.video-player-header strong {
  flex: 0 0 auto;
  border-left: 4px solid var(--lap-color, var(--accent));
  padding-left: 8px;
}

.video-player-header span {
  overflow: hidden;
  color: rgb(255 255 255 / 0.7);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-stage {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  background: #050608;
}

.telemetry-video {
  display: block;
  width: 100%;
  max-height: calc(100vh - 255px);
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #050608;
}

.video-track-overlay {
  position: absolute;
  top: clamp(10px, 2vw, 20px);
  right: clamp(10px, 2vw, 20px);
  display: grid;
  justify-items: end;
  gap: 4px;
  width: clamp(130px, 25%, 260px);
  pointer-events: none;
}

.video-current-lap {
  margin: 0;
  border: 1px solid rgb(255 255 255 / 0.4);
  border-radius: 999px;
  background: rgb(5 6 8 / 0.72);
  padding: 4px 10px;
  color: #fff;
  font-size: clamp(0.75rem, 1.4vw, 0.95rem);
  font-weight: 750;
  line-height: 1.1;
  text-shadow: 0 1px 2px rgb(0 0 0 / 0.8);
  font-variant-numeric: tabular-nums;
}

.video-track-overlay-svg {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 5 / 3;
  overflow: visible;
  background: transparent;
  filter: drop-shadow(0 2px 5px rgb(0 0 0 / 0.55));
}

.video-player-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.video-shared-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
}

.video-shared-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.video-sync-status {
  margin: 8px 0 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.video-jump-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  padding: 0 6px 8px;
}

.video-jump-groups h3,
.dynamics-calibration-card h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.dynamics-calibration-card h4 {
  margin: 18px 0 8px;
  font-size: 0.88rem;
}

.video-calibration-toggle {
  display: grid;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}

.video-calibration-toggle:hover,
.video-calibration-toggle[aria-expanded="true"] {
  border-color: var(--border-strong);
  color: var(--text);
}

.video-track-line-casing,
.video-track-line {
  vector-effect: non-scaling-stroke;
}

.video-track-line-casing {
  stroke: rgb(0 0 0 / 0.72);
  stroke-width: 10;
}

.video-track-line {
  stroke: rgb(255 255 255 / 0.88);
  stroke-width: 5;
}

.video-position-halo {
  fill: color-mix(in srgb, var(--accent) 30%, transparent);
  stroke: #fff;
  stroke-width: 6;
  vector-effect: non-scaling-stroke;
}

.video-position-dot {
  fill: var(--accent);
  stroke: #111820;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.video-jump-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.video-jump-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface-muted);
  color: var(--text);
  cursor: pointer;
}

.video-jump-button.has-corner-winner {
  border-color: var(--corner-winner-color);
  background: color-mix(in srgb, var(--corner-winner-color) 24%, var(--surface-muted));
  box-shadow: inset 0 -3px 0 var(--corner-winner-color);
  font-weight: 720;
}

.dynamics-calibration-card {
  margin: 0 6px 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
}

.dynamics-calibration-card[hidden] {
  display: none;
}

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

.dynamics-calibration-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.video-speed-unit-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(100px, 160px);
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.dynamics-calibration-controls select,
.video-speed-unit-control select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

@media (max-width: 960px) {
  .video-workspace-grid {
    grid-template-columns: 1fr;
  }

  .video-player-grid.dual {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "rail"
      "main"
      "laps";
    height: auto;
  }

  .app-shell.lap-panel-collapsed {
    grid-template-columns: 1fr;
    grid-template-areas:
      "rail"
      "main"
      "laps";
  }

  .app-rail {
    position: sticky;
    top: 0;
    z-index: 30;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .rail-brand,
  .rail-button {
    flex: 0 0 auto;
  }

  .rail-button-logout {
    margin-top: 0;
    margin-left: auto;
  }

  .lap-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  .lap-panel {
    border-left: none;
  }

  .lap-panel-collapsed .lap-collapsed-rail {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto;
    align-items: center;
  }

  .lap-panel-collapsed .lap-mini-list {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .lap-panel-collapsed .lap-mini-item {
    width: 34px;
    flex: 0 0 34px;
  }

  .lap-mini-empty {
    writing-mode: horizontal-tb;
  }

  .lap-panel-section {
    height: auto;
    min-height: auto;
    padding: 18px 22px;
  }

  .track-card {
    min-height: auto;
  }

  .main-panel {
    height: auto;
    grid-template-rows: auto auto;
  }

  .main-panel.files-view {
    grid-template-rows: auto;
  }

  .main-panel.lap-detail-view {
    grid-template-rows: auto;
    overflow: visible;
  }

  .file-workspace {
    min-height: auto;
    overflow: visible;
  }

  .lap-detail-workspace {
    min-height: 520px;
  }

  .lap-detail-theory {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .lap-detail-theory-detail {
    text-align: left;
  }

  .file-workspace-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "library"
      "info"
      "telemetry"
      "video"
      "status";
    overflow: visible;
  }

  .file-library-card {
    grid-row: auto;
  }

  .file-library-card .file-list {
    max-height: 420px;
  }

  .map-container {
    min-height: 420px;
  }

  .analytics-card {
    min-height: 260px;
  }
}

@media (max-width: 640px) {
  .panel-header,
  .panel-section,
  .lap-panel-section {
    padding-left: 16px;
    padding-right: 16px;
  }

  .main-panel {
    padding: 16px;
  }

  .file-workspace-header {
    align-items: stretch;
    flex-direction: column;
  }

  .file-workspace-actions,
  .file-workspace-upload-box {
    width: 100%;
  }

  .file-workspace-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .file-workspace-upload-box {
    align-items: stretch;
    flex-direction: column;
  }

  .file-workspace-upload {
    width: 100%;
  }

  .map-container.side-by-side-mode {
    grid-template-columns: 1fr;
  }

  .track-header {
    display: block;
  }

  .map-container {
    min-height: 340px;
  }

  .analytics-card-header {
    align-items: stretch;
    flex-direction: column;
  }

  .analytics-card .analytics-tabs {
    width: 100%;
  }

  .analytics-card .speed-trace-panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .analytics-card .speed-trace-panel .speed-analysis-header,
  .analytics-card .speed-trace-chart,
  .analytics-card .speed-trace-legend {
    grid-column: 1;
    grid-row: auto;
  }

}
