/* Site interaction layer: the Calendar page's approved patterns carried to
   every other page (docs/interaction-patterns/README.md). Driven by
   scripts/siteExperience.js; nothing here changes a page that loads without
   that script, because every rule below hangs off .sx-ready or a class the
   script adds. Tokens come from styles.css. */

/* ---- Header: a hairline of light along its lower edge once the page has moved ---- */

.sx-ready .site-header.is-scrolled {
  box-shadow: 0 1px 0 rgba(255, 255, 255, .07), 0 8px 28px rgba(0, 0, 0, .18);
}

/* ---- Context panel ---- */

/* The sentinel is the panel's top margin: once it leaves the space under the
   header, the panel is stuck. */
.sx-panel-sentinel { height: 0; }

.sx-panel {
  position: sticky;
  top: var(--sx-header-height, 0px);
  z-index: 40;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  transition: background-color 240ms var(--ease-out), border-color 240ms var(--ease-out), box-shadow 240ms var(--ease-out);
}

.sx-panel.is-stuck {
  border-color: transparent;
  background: rgba(252, 252, 252, .96);
  box-shadow: 0 1px 0 var(--line);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  backdrop-filter: saturate(1.2) blur(10px);
}

/* A short paper fade so rows pass under the panel instead of butting against it. */
.sx-panel::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  height: 16px;
  background: linear-gradient(var(--paper), rgba(252, 252, 252, 0));
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms var(--ease-out);
}

.sx-panel.is-stuck::after { opacity: 1; }

.sx-panel-inner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0 1.25rem;
  min-height: 52px;
}

/* A panel inside a page's own .wrap (profiles) already sits in the column. */
.wrap .sx-panel .sx-panel-inner { padding-inline: 0; }

.sx-panel-title {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 14rem;
  min-height: 44px;
  cursor: pointer;
  text-align: left;
}

.sx-panel-title:hover { color: var(--orange-dark); }
.sx-panel-title:focus-visible { outline: 3px solid var(--orange); outline-offset: -3px; }

.sx-panel-nav {
  position: relative;
  display: flex;
  gap: 0 .25rem;
  min-width: 0;
  /* The fade mask eats the first 14px, so the row starts .9rem early and the
     first label carries that much padding: its first letter is never clipped. */
  margin-left: -.9rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 14px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 14px), transparent);
}

.sx-panel-nav::-webkit-scrollbar { display: none; }
.sx-panel-nav[hidden] { display: none; }

.sx-panel-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 .7rem;
  scroll-margin-left: .9rem;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  transition: color 200ms var(--ease-out);
}

.sx-panel-link:hover, .sx-panel-link[aria-current="true"] { color: var(--ink); }
.sx-panel-link:focus-visible { outline: 3px solid var(--orange); outline-offset: -3px; }

/* One indicator slides between links rather than each link drawing its own. */
.sx-panel-indicator {
  position: absolute;
  bottom: 6px;
  left: 0;
  height: 2px;
  width: 0;
  border-radius: 1px;
  background: var(--orange);
  opacity: 0;
  pointer-events: none;
  transition: transform 320ms var(--ease-out), width 320ms var(--ease-out), opacity 200ms var(--ease-out);
}

/* Team minimap on the rosters: a colour bar per team, raised while its
   drivers are on screen. */
.sx-panel-swatch {
  display: block;
  width: 14px;
  height: 6px;
  border-radius: 1px;
  background: var(--team-colour, var(--tc-unknown));
  transform-origin: 50% 100%;
  transition: transform 220ms var(--ease-out), opacity 220ms var(--ease-out);
}

.sx-panel-link[aria-current="true"] .sx-panel-swatch,
.sx-panel-link:hover .sx-panel-swatch { transform: scaleY(1.8); }

.sx-panel-status {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sx-panel-status[hidden] { display: none; }

.sx-panel-link:first-of-type { padding-left: .9rem; }

/* With section links (or the standings tabs) in the panel, the page title
   would only repeat the h1 beside them, so the links take the whole row. */
.sx-panel.has-tabs .sx-panel-link { padding: 0 .9rem; }
.sx-panel.has-nav .sx-panel-title,
.sx-panel.has-tabs .sx-panel-title { display: none; }
.sx-panel.has-nav .sx-panel-inner,
.sx-panel.has-tabs .sx-panel-inner { grid-template-columns: minmax(0, 1fr) auto; }

/* The profile page's own in-page nav is carried by the panel. */
.sx-ready .profile-nav.sx-adopted { display: none; }

/* Anything jumped to lands clear of the header and the panel. */
.sx-ready main [id] { scroll-margin-top: var(--sx-sticky-offset, 160px); }

@media (max-width: 860px) {
  .sx-panel-inner { grid-template-columns: minmax(0, 1fr) auto; }
  .sx-panel-title { display: none; }
  .sx-panel-nav { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent); }
}

@media (max-width: 620px) {
  .sx-panel-inner { min-height: 48px; }
  .sx-panel-status { display: none; }
  .sx-panel-link { padding: 0 .55rem; }
  .sx-panel-nav.has-swatches .sx-panel-link-label { display: none; }
  .sx-panel-nav.has-swatches { gap: 0; justify-content: space-between; -webkit-mask-image: none; mask-image: none; }
  .sx-panel-nav.has-swatches .sx-panel-link { flex: 1 1 0; justify-content: center; padding: 0; }
  .sx-panel-nav.has-swatches .sx-panel-swatch { width: 100%; max-width: 28px; }
  .sx-panel-nav.has-swatches + .sx-panel-indicator, .sx-panel-nav.has-swatches .sx-panel-indicator { display: none; }
}

/* ---- Reveal: pending rows and cards wait invisibly until they enter ---- */

.sx-motion [data-sx-reveal="pending"] { opacity: 0; }

/* Rows animate with a transform; never let them anchor the scroll position. */
.sx-ready .table tbody tr,
.sx-ready .roster-item,
.sx-ready .guide-card,
.sx-ready .profile-metrics > div,
.sx-ready .rw-session-list > li { overflow-anchor: none; }

/* ---- Hover detail: spotlight, finish bar, accent growth ---- */

.sx-spot { position: relative; }

.sx-spot::before,
.sx-spot::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

/* The glow takes the row's own team colour where it has one (drivers, teams),
   and the brand orange elsewhere. color-mix keeps the tint at 14%, so a dark
   team colour never turns the row muddy. */
.sx-spot::before {
  z-index: 0;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(260px circle at var(--sx-spot-x, 50%) var(--sx-spot-y, 50%), var(--sx-glow, rgba(255, 107, 0, .12)), transparent 70%);
  opacity: 0;
  transition: opacity 260ms var(--ease-out);
}

@supports (color: color-mix(in srgb, red, transparent)) {
  /* Inherits from the row (rosters, standings) or the page (a driver's or
     team's profile), so every hover carries that team's colour. */
  .sx-spot { --sx-glow: color-mix(in srgb, var(--team-colour, var(--orange)) 16%, transparent); }
}

.sx-spot::after {
  z-index: 1;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--team-colour, var(--orange));
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 320ms var(--ease-out);
}

.sx-spot > * { position: relative; z-index: 1; }

.sx-spot:focus-within::after { transform: scaleX(1); }

/* Roster rows: the name eases right and the rank darkens; the row's padding
   no longer changes on hover, so nothing around the pointer jumps. */
.sx-ready .roster-item { transition: background-color 220ms var(--ease-out); }
.sx-ready .roster-item, .sx-ready .roster-item:hover { padding: clamp(1rem, 3vw, 1.5rem); }
@media (max-width: 900px) { .sx-ready .roster-item, .sx-ready .roster-item:hover { padding: 1.25rem; } }
@media (max-width: 620px) { .sx-ready .roster-item, .sx-ready .roster-item:hover { padding: 1rem; } }
.sx-ready .roster-rank { position: relative; transition: transform 260ms var(--ease-out), color 200ms var(--ease-out); }
.sx-ready .roster-item .roster-identity h3 { transition: transform 260ms var(--ease-out); }
.sx-ready .roster-item::after { background: var(--team-colour, var(--orange)); }

/* Guides: a quiet lift of the title instead of a growing card. */
.sx-ready .guide-story-grid .guide-card h3 { transition: color 200ms var(--ease-out), transform 260ms var(--ease-out); }
.sx-ready .guide-story-grid .guide-card:hover { padding-left: 0; }

/* Tables: the team accent grows, the row takes a wash of the team colour and
   the value darkens towards it. */
.sx-ready .table tbody tr td { transition: background-color 180ms var(--ease-out), box-shadow 220ms var(--ease-out), color 180ms var(--ease-out); }
.sx-ready .table .accent-row:hover td:first-child { box-shadow: inset 6px 0 0 var(--team-colour, var(--tc-unknown)); }
.sx-ready .table tbody tr:hover td.num,
.sx-ready .table tbody tr:hover td.cell-end { color: var(--orange-dark); }
@supports (color: color-mix(in srgb, red, transparent)) {
  .sx-ready .table .accent-row:hover td { background-color: color-mix(in srgb, var(--team-colour, var(--orange)) 8%, transparent); }
  .sx-ready .table .accent-row:hover td.num,
  .sx-ready .table .accent-row:hover td.cell-end { color: color-mix(in srgb, var(--team-colour, var(--orange)) 62%, var(--ink)); }
}

/* Race weekend sessions: the next one counts down, the live one pulses. */
.sx-ready .rw-session-list > li { transition: background-color 220ms var(--ease-out), opacity 220ms var(--ease-out); }
/* Finished sessions step back only while the weekend is still running. */
.sx-ready .rw-session-list:not(.is-complete) > li.is-past { opacity: .62; }
.sx-ready .rw-session-list > li.is-past:hover, .sx-ready .rw-session-list > li.is-past:focus-within { opacity: 1; }
.sx-ready .rw-session-list > li.is-next { box-shadow: inset 3px 0 0 var(--orange); }
.sx-ready .rw-session-list > li.is-live { box-shadow: inset 3px 0 0 #e10600; }
.sx-ready .rw-session-list > li.is-live .rw-session-start strong { color: #e10600; animation: sx-live-pulse 2400ms ease-in-out infinite; }

@keyframes sx-live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

/* ---- Standings: the panel is the Drivers / Constructors switch ---- */

/* The radio inputs still drive which table shows; the panel's tabs select
   them, so the switch follows the reader and the page keeps one control. */
.sx-ready .standings-switch .segmented-control { display: none; }
.sx-ready .standings-panels { margin-top: .5rem; }

/* Pointer hover only where hovering exists, so a tapped row on a phone does not stay lit. */
@media (hover: hover) {
  .sx-spot:hover::before { opacity: 1; }
  .sx-spot:hover::after { transform: scaleX(1); }
  .sx-ready .roster-item:hover .roster-rank { color: var(--ink); }
  .sx-ready .roster-item:hover .roster-identity h3 { transform: translateX(6px); }
  .sx-ready .guide-story-grid .guide-card:hover h3 { color: var(--orange-dark); transform: translateX(6px); }
}

@media (hover: none) {
  .sx-spot::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sx-panel,
  .sx-panel::after,
  .sx-panel-link,
  .sx-panel-indicator,
  .sx-panel-swatch,
  .sx-spot::before,
  .sx-spot::after,
  .sx-ready .roster-rank,
  .sx-ready .roster-item .roster-identity h3,
  .sx-ready .table tbody tr td { transition: none; }
  .sx-ready .rw-session-list > li.is-live .rw-session-start strong { animation: none; }
}

@media print {
  .sx-panel { display: none; }
  .sx-motion [data-sx-reveal="pending"] { opacity: 1; }
}

/* ---- Guides index: the interactive guide leads the page ---- */

.guide-feature {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "kicker arrow" "title arrow" "copy arrow";
  gap: .35rem 1.5rem;
  align-items: center;
  margin-bottom: 1.5rem;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
  transition: border-color 220ms var(--ease-out), box-shadow 260ms var(--ease-out), transform 260ms var(--ease-out);
}

.guide-feature::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(420px circle at 88% 50%, rgba(255, 107, 0, .16), transparent 70%);
  pointer-events: none;
}

.guide-feature > * { position: relative; }
.guide-feature-kicker { grid-area: kicker; color: var(--orange-dark); font-size: var(--text-sm); font-weight: 700; }
.guide-feature-title { grid-area: title; font-size: var(--text-section); font-weight: 800; line-height: 1.2; }
.guide-feature-copy { grid-area: copy; max-width: 56ch; color: var(--muted); font-size: var(--text-sm); line-height: 1.55; }
.guide-feature-arrow {
  grid-area: arrow;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-size: 1.25rem;
  transition: transform 260ms var(--ease-out), background-color 220ms var(--ease-out);
}

@media (hover: hover) {
  .guide-feature:hover { border-color: var(--orange); transform: translateY(-2px); box-shadow: 0 12px 32px rgba(16, 16, 16, .08); }
  .guide-feature:hover .guide-feature-arrow { background: var(--orange); color: #141414; transform: translate(3px, -3px); }
}

.guide-feature:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

@media (max-width: 620px) {
  .guide-feature { grid-template-columns: minmax(0, 1fr); grid-template-areas: "kicker" "title" "copy" "arrow"; padding: 1.25rem; }
  .guide-feature-arrow { justify-self: start; }
}
