/* Scores and times line up in columns. */
.table,
.player-totals,
.stat-cards,
.quali-gap {
  font-variant-numeric: tabular-nums;
}

/* Phones */
/* Notched phones: the site can be installed full screen (viewport-fit=cover). */
body {
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

/* The league name gets a row to itself; the buttons below share the width. */
.league-title {
  flex: 1 1 100%;
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (min-width: 576px) {
  .league-title {
    flex: 1 1 auto;
  }
}

@media (max-width: 575.98px) {
  .league-nav .btn {
    flex: 1 1 auto;
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .league-nav .dropdown {
    flex: 1 1 auto;
    display: flex;
  }

  .league-nav .dropdown .btn {
    flex: 1 1 auto;
  }
}

/* Links in lists and tables are short; widen the touch area without moving
   anything. */
@media (max-width: 767.98px), (pointer: coarse) {
  .list-group-item a:not(.btn),
  .table a:not(.btn),
  .breadcrumb a {
    position: relative;
  }

  .list-group-item a:not(.btn)::after,
  .table a:not(.btn)::after,
  .breadcrumb a::after {
    content: '';
    position: absolute;
    inset: -0.7rem -0.35rem;
  }

  .table-sm {
    --bs-table-cell-padding-y: 0.4rem;
  }

  summary {
    padding-block: 0.5rem;
    cursor: pointer;
  }
}

/* Form controls: big enough to tap, and 16px so iPhones don't zoom in on focus. */
@media (max-width: 767.98px) {
  .form-control,
  .form-select,
  .form-control-sm,
  .form-select-sm {
    min-height: 2.75rem;
    font-size: 1rem;
  }

  .btn-sm:not(.league-nav .btn) {
    min-height: 2.5rem;
  }

  .form-check {
    padding-left: 2rem;
  }

  .form-check .form-check-input {
    width: 1.35rem;
    height: 1.35rem;
    margin-top: 0.2rem;
    margin-left: -2rem;
  }

  .form-check-label {
    padding-block: 0.25rem;
  }
}

/* The five start lights beside the site name. */
.brand-mark {
  width: 1.9rem;
  height: auto;
}

/* League pages */
/* The outline keeps dark team colours (navy, black) visible in dark mode. */
.team-dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  margin-right: 0.25rem;
  box-shadow: 0 0 0 1px var(--bs-border-color-translucent);
}

/* Race page: one score card per player, as many per row as fit. */
.player-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr));
  gap: 0.5rem;
}

.pick-number {
  width: 1.5rem;
}

.season-table td:first-child,
.season-table th:first-child {
  position: sticky;
  left: 0;
  background: var(--bs-body-bg);
}

/* Draft */
.grid-pos {
  width: 2rem;
}

.driver-list .list-group-item {
  cursor: pointer;
  min-height: 2.75rem;
}

/* Keep the pick button in reach under a long driver list on phones. */
.pick-submit {
  position: sticky;
  bottom: 0;
  padding: 0.5rem 0;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  background: var(--bs-body-bg);
}

/* Manage page */
.manage-position {
  width: 2rem;
  justify-content: center;
}

.manage-number {
  width: 6.5rem;
}

.manage-driver {
  width: 2.5rem;
}

/* Stats: one colour per player (services.player_colours) */
.player-colour-0 {
  color: #e10600;
}

.player-colour-1 {
  color: #0072b2;
}

.player-colour-2 {
  color: #009e73;
}

.player-colour-3 {
  color: #e69f00;
}

.player-colour-4 {
  color: #6f42c1;
}

/* Lighter shades that keep their contrast on the dark background. */
[data-bs-theme='dark'] .player-colour-0 {
  color: #ff6b63;
}

[data-bs-theme='dark'] .player-colour-1 {
  color: #56b4e9;
}

[data-bs-theme='dark'] .player-colour-2 {
  color: #3cc9a0;
}

[data-bs-theme='dark'] .player-colour-3 {
  color: #f5b841;
}

[data-bs-theme='dark'] .player-colour-4 {
  color: #b99cf0;
}

.player-dot {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: currentColor;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.5rem;
}

/* Season chart: scrolls sideways on phones rather than shrinking the text. */
.chart-scroll {
  overflow-x: auto;
}

.line-chart {
  display: block;
  width: 100%;
  min-width: 32rem;
  height: auto;
  font-size: 13px;
}

.line-chart .grid {
  stroke: var(--bs-border-color);
}

.line-chart text {
  fill: var(--bs-secondary-color);
}

.line-chart polyline {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.line-chart circle {
  fill: currentColor;
}

.line-chart .series-name {
  fill: currentColor;
  font-weight: 600;
}

/* Shared responsive shell and content rhythm. */
:root {
  --page-gutter: 1rem;
  --section-gap: 1.5rem;
}

.site-shell {
  width: calc(100% - 2 * var(--page-gutter));
  max-width: 90rem;
  margin-right: auto;
  margin-left: auto;
  min-width: 0;
}

main.site-shell {
  padding-top: 0.75rem;
  padding-bottom: 2rem;
}

main.site-shell > .alert {
  margin-bottom: 1rem;
}

.navbar > .site-shell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}

.navbar-brand {
  min-width: 0;
  flex-shrink: 1;
  white-space: normal;
  overflow-wrap: anywhere;
}

.navbar-collapse,
.navbar-nav,
.navbar-nav .nav-item {
  min-width: 0;
}

.navbar-nav .nav-link,
.navbar-nav .dropdown-toggle {
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  white-space: normal;
  overflow-wrap: anywhere;
}

.league-heading {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  min-width: 0;
}

.league-title {
  flex: 1 1 100%;
  overflow-wrap: anywhere;
}

.league-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.league-actions .btn {
  min-height: 2.5rem;
}

.season-dashboard {
  display: grid;
  gap: var(--section-gap);
  margin-bottom: var(--section-gap);
  min-width: 0;
}

.season-dashboard > *,
.season-races {
  min-width: 0;
}

.season-standings .list-group-item {
  min-height: 2.75rem;
  gap: 0.75rem;
}

.season-standings .ms-2 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.season-chart-frame {
  max-width: 50rem;
  min-width: 0;
}

.season-table {
  min-width: 38rem;
}

.season-table th:not(:first-child) {
  min-width: 7.5rem;
  max-width: 13rem;
  white-space: normal;
  overflow-wrap: anywhere;
  vertical-align: bottom;
}

.season-table td:first-child,
.season-table th:first-child {
  min-width: 10rem;
  z-index: 1;
}

/* Bound account and notification forms on dashboard-sized screens. */
.account-page,
.account-entry-panel {
  width: 100%;
  max-width: 40rem;
  margin-right: auto;
  margin-left: auto;
  min-width: 0;
}

.account-page-wide {
  max-width: 56rem;
}

.account-entry-shell {
  width: calc(100% - 2 * var(--page-gutter));
  max-width: 90rem;
  margin: 0 auto;
}

.manage-account-page .card {
  max-width: 100%;
  min-width: 0;
}

.manage-page form,
.manage-page form > div {
  min-width: 0;
}

.manage-page .form-select,
.manage-page .form-control {
  max-width: 100%;
  min-width: 0;
}

.account-page h1,
.account-page h2,
.account-entry-panel h1,
.account-entry-panel h2 {
  overflow-wrap: anywhere;
}

.stat-cards > *,
.season-standings .list-group-item {
  min-width: 0;
}

.stat-cards > * {
  overflow-wrap: anywhere;
}

/* The source SVG is 640 × 260. Cap its rendered size so labels stay legible. */
.chart-scroll {
  max-width: 50rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.line-chart {
  width: 100%;
  max-width: 50rem;
  min-width: 32rem;
  height: auto;
}

@media (min-width: 48rem) {
  :root {
    --page-gutter: 1.5rem;
  }
}

@media (min-width: 75rem) {
  :root {
    --section-gap: 1.75rem;
  }

  .league-title {
    flex: 1 1 auto;
  }

  .season-dashboard-has-chart {
    grid-template-columns: minmax(20rem, 23rem) minmax(0, 1fr);
    align-items: start;
    column-gap: 1.5rem;
  }

  .season-standings ol {
    margin-bottom: 0 !important;
  }

  .season-chart-frame {
    width: 100%;
  }

  .season-races {
    margin-top: 0.5rem;
  }
}

@media (hover: hover) and (pointer: fine) {
  .driver-list .list-group-item:hover {
    background-color: var(--bs-tertiary-bg);
  }
}
/* Race draft workspace: compare the active picker with the board on wide screens. */
.race-draft-workspace {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 1.5rem;
  align-items: start;
}

.race-draft-workspace > *,
.race-picker,
.race-board {
  min-width: 0;
}

.race-draft-closed {
  grid-template-columns: minmax(0, 1fr);
}

.race-picker > .card {
  margin-bottom: 0 !important;
}

.race-picker .pick-submit {
  position: sticky;
  z-index: 2;
  bottom: 0;
  margin: .5rem -.75rem -.75rem;
  padding: .65rem .75rem calc(.65rem + env(safe-area-inset-bottom, 0px));
  background: var(--bs-body-bg);
  border-top: 1px solid var(--bs-border-color);
  box-shadow: 0 -0.35rem .75rem rgb(0 0 0 / 8%);
}

.pick-submit-button {
  width: 100%;
}

.driver-choice {
  display: grid;
  grid-template-columns: 1.25rem 1.7rem .5rem minmax(0, 1fr) max-content;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: .5rem;
  row-gap: .15rem;
  min-height: 44px;
  padding: .4rem .6rem;
}

.driver-choice > .driver-radio {
  grid-column: 1;
  grid-row: 1 / span 2;
  justify-self: center;
  margin: 0;
}

.driver-choice > .grid-pos {
  grid-column: 2;
  grid-row: 1 / span 2;
  text-align: right;
}

.driver-choice > .team-dot {
  grid-column: 3;
  grid-row: 1 / span 2;
}

.driver-choice > .driver-code {
  grid-column: 4;
  grid-row: 1;
}

.driver-choice > .driver-name {
  grid-column: 4 / -1;
  grid-row: 2;
  min-width: 0;
  overflow-wrap: anywhere;
}

.driver-choice > .quali-gap {
  grid-column: 5;
  grid-row: 1;
  justify-self: end;
  white-space: nowrap;
}

.driver-choice > .driver-penalty {
  grid-column: 4 / -1;
  grid-row: 3;
  justify-self: start;
  display: inline-flex;
  flex-wrap: wrap;
  gap: .25rem;
  max-width: 100%;
}

.driver-penalty > .badge {
  white-space: normal;
}

/* Grid penalties the penalty watch found, above the draft (race page). */
.reported-penalty + .reported-penalty {
  margin-top: .35rem;
}

.reported-penalty-actions {
  display: inline-flex;
  gap: .25rem;
  margin-left: .25rem;
  vertical-align: middle;
}

.driver-choice > .constructor-name {
  display: none;
}

.driver-choice:has(.driver-radio:focus-visible) {
  outline: 2px solid var(--bs-primary);
  outline-offset: -2px;
}

@media (min-width: 1200px) {
  .race-draft-workspace {
    gap: 2rem;
  }

  .pick-submit-button {
    width: auto;
  }

  .race-picker .pick-submit {
    position: static;
    margin: .5rem 0 0;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  .driver-choice {
    grid-template-columns: 1.25rem 1.7rem .5rem auto minmax(0, 1fr) max-content;
  }

  .driver-choice > .driver-name {
    grid-column: 5;
    grid-row: 1;
  }

  .driver-choice > .driver-penalty {
    grid-column: 4;
    grid-row: 2;
  }

  .driver-choice > .quali-gap {
    grid-column: 6;
  }

  .driver-choice > .constructor-name {
    display: inline;
    grid-column: 5 / -1;
    grid-row: 2;
    min-width: 0;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 1199.98px) {
  .race-draft-workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
  }
}

@media (max-width: 359.98px) {
  .driver-choice {
    column-gap: .35rem;
    padding-inline: .45rem;
  }
}

@media (max-height: 500px) {
  .race-picker .pick-submit {
    position: static;
    margin: .5rem 0 0;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
}

.driver-choice > .grid-pos {
  width: auto;
}

.driver-choice > .team-dot {
  margin-right: 0;
}

.pick-form .btn-group .btn,
.pick-submit-button {
  min-height: 44px;
}

.pick-form .btn-group .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.race-picker .driver-choice:focus-within,
.race-picker .btn-check + label {
  scroll-margin-block: 6rem;
}

/* Completed drafts: compare all three rounds within the desktop shell. */
.race-rounds,
.race-round {
  min-width: 0;
}

@media (min-width: 75rem) {
  .race-draft-closed .race-rounds {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.25rem;
    align-items: start;
  }

  .race-draft-closed .race-round h3 {
    min-height: 2.5rem;
    margin-top: 0 !important;
    margin-bottom: 0.5rem;
    line-height: 1.4;
  }

  .race-draft-closed .picks-table {
    width: 100%;
    table-layout: fixed;
  }

  .race-draft-closed .picks-table td {
    padding: 0.5rem 0.25rem;
    overflow-wrap: anywhere;
  }

  .race-draft-closed .picks-table .pick-number {
    width: 1.25rem;
  }

  .race-draft-closed .round-player {
    width: 22%;
  }

  .race-draft-closed .round-driver {
    width: 35%;
  }

  .race-draft-closed .round-driver-name {
    display: block !important;
    margin-top: 0.1rem;
  }

  .race-draft-closed .round-detail {
    white-space: normal !important;
  }

  .race-draft-closed .round-detail > span {
    display: block;
    white-space: nowrap;
  }

  .race-draft-closed .picks-table td:last-child {
    width: 4.25rem;
  }
}


/* Draft analytics: compact tables and a bounded trend on wider screens. */
.draft-stats-page .text-muted.small {
  max-width: 85ch;
}

.draft-stats-overview,
.draft-metric-grid {
  display: grid;
  gap: 1.5rem;
  align-items: start;
  min-width: 0;
}

.draft-stats-overview > *,
.draft-metric-grid > *,
.draft-trend {
  min-width: 0;
}

.draft-stats-overview:not(.has-chart) {
  max-width: 48rem;
}

.draft-trend,
.draft-stats-overview > .table-responsive,
.draft-metric-grid > section {
  max-width: 50rem;
}

.draft-trend .line-chart {
  min-width: 40rem;
}

.draft-stats-page table {
  min-width: 0;
}

.draft-stats-overview table {
  min-width: 32rem;
}

.draft-stats-page td:first-child,
.draft-stats-page th {
  white-space: normal;
  overflow-wrap: anywhere;
}

.draft-stats-page td:first-child {
  min-width: 10rem;
  max-width: 18rem;
}

.draft-pick-breakdown table {
  min-width: 48rem;
}

.draft-stats-page .list-group-item > span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.draft-stats-page .list-group-item > span:last-child {
  flex-shrink: 0;
}

@media (min-width: 75rem) {
  .draft-trend .line-chart {
    min-width: 32rem;
  }

  .draft-stats-overview.has-chart,
  .draft-metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.draft-stats-page td.text-end {
  white-space: nowrap;
}
