:root {
  color-scheme: light;
  --bg: #eef2f7;
  --bg-soft: #f8fafc;
  --surface: #ffffff;
  --surface-strong: #f9fbff;
  --text: #172033;
  --muted: #667085;
  --border: #d7deea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --success-soft: #dcfce7;
  --warning-soft: #fef3c7;
  --danger-soft: #fee2e2;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.10);
  --radius: 18px;
  --radius-sm: 12px;
  --max-width: 1180px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.16), transparent 32rem),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 48%, #e9edf5 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(37, 99, 235, 0.035) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(37, 99, 235, 0.035) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, transparent 72%);
}

a { color: inherit; }

.app-shell {
  width: min(100% - 2rem, var(--max-width));
  margin: 0 auto;
  padding: 1.25rem 0 2.5rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(215, 222, 234, 0.85);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.07);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #0f172a);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.22);
}

.brand-title {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.15;
  font-weight: 800;
}

.brand-subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.nav-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav-links a {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 0.75rem;
  border-radius: 999px;
  color: #344054;
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: none;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.nav-links a:active { transform: translateY(1px); }

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, 0.7fr);
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1rem;
}

.hero-card,
.panel,
.metric-card,
.gauge-box,
.link-card {
  border: 1px solid rgba(215, 222, 234, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.hero-card {
  padding: clamp(1.25rem, 4vw, 2rem);
  overflow: hidden;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.9rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.02;
  letter-spacing: -0.06em;
}

.page-intro {
  max-width: 68ch;
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.12rem);
  line-height: 1.6;
}

.status-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  align-self: flex-start;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: var(--success-soft);
  color: #166534;
  font-weight: 800;
  font-size: 0.86rem;
}

.status-dot {
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.16);
}

.grid {
  display: grid;
  gap: 1rem;
}

.quick-links {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 1rem;
}

.link-card {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 170px;
  padding: 1.25rem;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.link-card:hover {
  transform: translateY(-3px);
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 22px 45px rgba(15, 23, 42, 0.15);
}

.link-icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: 16px;
  background: var(--primary-soft);
  font-size: 1.5rem;
}

.link-card h2,
.panel h2,
.metric-card h2 {
  margin: 0;
  font-size: 1.12rem;
  letter-spacing: -0.02em;
}

.link-card p,
.panel p,
.metric-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.gauge-container {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.gauge-box {
  min-width: 0;
  padding: 1rem;
  text-align: center;
}

.gauge-box h2,
.gauge-box h3 {
  margin: 0 0 0.75rem;
}

.gauge-chart {
  min-height: 235px;
}

.field-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  margin-top: 0.35rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-soft);
  color: #334155;
  font-weight: 800;
  font-size: 0.98rem;
}

.telemetry-list {
  display: grid;
  gap: 0.65rem;
  text-align: left;
}

.telemetry-row {
  display: flex;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
}

.telemetry-row span:first-child {
  color: var(--muted);
  font-size: 0.9rem;
}

.telemetry-row span:last-child {
  font-weight: 800;
  text-align: right;
  word-break: break-word;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1rem 0;
}

button,
.button-link {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.22);
  transition: background 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

button:hover,
.button-link:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

button:active,
.button-link:active { transform: translateY(0); }

.subtle-status {
  color: var(--muted);
  font-size: 0.92rem;
}

.panel {
  padding: 1rem;
}

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr)) auto;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: left;
}

.input-group label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

input[type="datetime-local"] {
  width: 100%;
  min-height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.chart-card {
  overflow: hidden;
}

#chart {
  width: 100%;
  min-height: 440px;
}

.footer-note {
  margin-top: 1rem;
  color: var(--muted);
  text-align: center;
  font-size: 0.86rem;
}

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; }
  .gauge-container { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 1rem, var(--max-width));
    padding-top: 0.5rem;
  }

  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 0.75rem;
    border-radius: 16px;
  }

  .brand-mark {
    width: 2.25rem;
    height: 2.25rem;
  }

  .nav-links {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 0.45rem;
  }

  .nav-links a {
    justify-content: center;
    padding: 0.65rem 0.45rem;
    font-size: 0.84rem;
    background: var(--bg-soft);
  }

  .quick-links,
  .gauge-container,
  .controls {
    grid-template-columns: 1fr;
  }

  .hero-card,
  .status-card,
  .panel,
  .gauge-box,
  .link-card {
    border-radius: 16px;
  }

  .gauge-chart { min-height: 210px; }
  #chart { min-height: 360px; }
}

@media (max-width: 420px) {
  .nav-links a span.nav-label { display: none; }
  .link-card { min-height: auto; }
  .telemetry-row { flex-direction: column; }
  .telemetry-row span:last-child { text-align: left; }
}

/* Lap timing table */
.lap-panel {
  margin-bottom: 1rem;
}

.lap-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.lap-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.lap-current-card {
  min-width: 180px;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  text-align: right;
}

.lap-current-card span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lap-current-card strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 1.2rem;
}

.lap-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.lap-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
  text-align: left;
}

.lap-table th,
.lap-table td {
  padding: 0.72rem 0.8rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.lap-table th {
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lap-table td {
  font-size: 0.92rem;
  font-weight: 700;
}

.lap-table tbody tr:hover {
  background: rgba(37, 99, 235, 0.06);
}

.lap-table .empty-cell {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.lap-table tr.fastest-lap {
  background: #16a34a;
  color: #fff;
}

.lap-table tr.fastest-lap td,
.lap-table tr.fastest-lap strong {
  color: #fff;
}

.lap-table tbody tr.fastest-lap {
  background: #16a34a;
  color: #fff;
}

@media (max-width: 700px) {
  .gauge-container {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
  }

  .gauge-box {
    padding: 0.65rem 0.45rem;
  }

  .gauge-chart {
    min-height: 165px;
  }

  .field-label {
    min-height: 2rem;
    padding: 0.35rem 0.55rem;
    font-size: 0.86rem;
  }

  .lap-header {
    flex-direction: column;
  }

  .lap-current-card {
    width: 100%;
    text-align: left;
  }

  .lap-table {
    min-width: 780px;
  }
}

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


/* Auth / sign-in */
.auth-chip {
  display: inline-flex;
  align-items: center;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.auth-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: min(100%, 560px);
  padding: clamp(1.25rem, 4vw, 2rem);
  border: 1px solid rgba(215, 222, 234, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 1.25rem;
}

.auth-card h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3rem);
}

.auth-card .page-intro {
  margin-top: 0.9rem;
  line-height: 1.55;
}

.auth-actions {
  display: flex;
  width: 100%;
  margin-top: 1.25rem;
}

.auth-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.auth-error {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: #7f1d1d;
}

.auth-error ul {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
}

.auth-error li + li {
  margin-top: 0.35rem;
}

.lap-table tbody tr.fastest-lap,
.lap-table tbody tr.fastest-lap:hover {
  background: #16a34a;
  color: #fff;
}

.lap-table tbody tr.fastest-lap td,
.lap-table tbody tr.fastest-lap strong {
  color: #fff;
}

@media (max-width: 700px) {
  .auth-chip {
    justify-content: center;
    max-width: none;
  }

  .auth-shell {
    min-height: 100vh;
    place-items: start center;
    padding-top: 1rem;
  }

  .auth-button {
    width: 100%;
  }
}
