:root {
  --r: 12px; /* border radius */
  --event-log-panel-width: 20rem;
  --event-log-gap: 1rem;
  --portrait-tv-event-log-height: 30vh;
  --page-min-width: 980px;
  --mobile-toolbar-height: 2rem;
  --mobile-labels-height: 1.5rem;
}

html {
  font-size: var(--app-font-size, clamp(14px, 1.5vw, 20px));
}

body {
  height: 100%;
  padding: 0;
  margin: 0;
  font-family: 'Iosevka Web', monospace;
  background-color: #f4f4f4;
  color: #333;
  overflow: hidden;
}


.page {
  position: relative;
}

.title {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas:
    'name name name'
    'start subtitle clock';
  align-items: center;
  column-gap: 0.45rem;
  row-gap: 0.42rem;
  padding-top: 0.58rem;
  padding-bottom: 0.12rem;
  margin-bottom: 0.35rem;
}

#competitionName {
  grid-area: name;
}

#comp_time {
  grid-area: start;
  justify-self: start;
  font-size: 1.35rem;
  font-weight: 700;
  color: #666;
}

#competitionSubtitle {
  grid-area: subtitle;
  justify-self: center;
  font-size: 1.17rem;
}

#time {
  grid-area: clock;
  justify-self: end;
  font-size: 1.35rem;
  line-height: 1;
  font-weight: 800;
}

.event_log {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--event-log-panel-width);
  display: flex;
  flex-direction: column;
  border-radius: 0;
  background: #f4f4f4;
  box-shadow: none;
  overflow: visible;
  z-index: 40;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
}

.event_log_tab {
  appearance: none;
  position: absolute;
  right: -1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.1rem;
  height: 3rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
  background: #c62828;
  color: #fff;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  z-index: 1;
}

.event_log_close {
  appearance: none;
  position: absolute;
  right: -1.1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.1rem;
  height: 3rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 0;
  background: #c62828;
  color: #fff;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  z-index: 1;
}

.event_log_title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.7rem;
  font-weight: bold;
  background: hsl(242, 100%, 90%);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.event_log_toggle {
  display: none;
}

.event_log_items {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.35rem 0.55rem;
}

.event_log.is-collapsed .event_log_items {
  display: none;
}

.event_log.is-collapsed {
  width: 0;
  min-width: 0;
  overflow: visible;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  border-radius: 0;
}

.event_log.is-collapsed .event_log_title {
  display: none;
}

.event_log.is-collapsed .event_log_tab {
  right: -1.1rem;
}

.event_log.is-collapsed .event_log_close {
  display: none;
}

.event_log:not(.is-collapsed) .event_log_tab {
  display: none;
}

.event_log_item {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  padding: 0.18rem 0;
  font-size: 0.88rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.event_log_item:last-child {
  border-bottom: none;
}

.event_log_line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2rem 3.5rem 1.5rem;
  gap: 0.24rem;
  align-items: baseline;
}

.event_log_line_primary {
  grid-template-columns: 2.6rem minmax(0, 1fr) 4.8rem;
}

.event_log_line_secondary {
  grid-template-columns: 2.6rem minmax(0, 1fr) 4.8rem;
  color: inherit;
  font-size: 0.88rem;
}

.event_log_prefix {
  display: inline-block;
  white-space: nowrap;
  text-align: center;
  justify-self: end;
  width: 2.5rem;
  padding: 0.08rem 0.35rem;
  border-radius: 0.28rem;
  font-weight: bold;
  font-size: 0.84rem;
  line-height: 1.1;
  transform: translateY(-3px);
  color: #fff;
  background-color: transparent;
  box-sizing: border-box;
}

.event_log_prefix.prefix-fill-blue {
  background-color: #0b57d0;
}

.event_log_prefix.prefix-fill-red {
  background-color: #c62828;
}

.event_log_prefix.prefix-outline-red {
  background-color: #fff;
  box-shadow: inset 0 0 0 3px #c62828;
  color: #c62828;
}

.event_log_prefix.prefix-outline-blue {
  background-color: #fff;
  box-shadow: inset 0 0 0 3px #0b57d0;
  color: #0b57d0;
}

.event_log_prefix.prefix-fill-green {
  background-color: #15803d;
}

.event_log_name {
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  font-weight: bold;
  text-transform: uppercase;
  font-size: 1.08rem;
}

.event_log_point {
  font-weight: bold;
  white-space: nowrap;
  width: 2rem;
  font-size: 1.2rem;
}

.event_log_time {
  white-space: nowrap;
  text-align: right;
  width: 4.8rem;
}

.event_log_team_name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: normal;
}

.event_log_sub_point,
.event_log_loss {
  white-space: nowrap;
}

.event_log_sub_point {
  width: 2.6rem;
  font-weight: bold;
  text-align: center;
}

.event_log_loss {
  width: 4.8rem;
  text-align: right;
}

body.display-portrait-tv.has-event-log .page {
  width: min(1280px, 99%);
  margin-left: auto;
  margin-right: auto;
  transform: none;
  padding-bottom: calc(var(--portrait-tv-event-log-height) + 3rem);
  box-sizing: border-box;
}

body.display-portrait-tv .event_log {
  top: auto;
  left: 0;
  right: 0;
  bottom: 0;
  width: auto;
  height: var(--portrait-tv-event-log-height);
  border-right: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

body.display-portrait-tv .event_log_tab {
  left: 50%;
  right: auto;
  top: auto;
  bottom: 0.5rem;
  transform: none;
  width: 3rem;
  height: 1.1rem;
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  margin-left: -1.5rem;
}

body.display-portrait-tv .event_log_close {
  left: 50%;
  right: auto;
  top: -1.55rem;
  transform: none;
  width: 3rem;
  height: 1.1rem;
  border-left: 1px solid rgba(0, 0, 0, 0.08);
  margin-left: -1.5rem;
}

body.display-portrait-tv .event_log_title {
  padding: 0.35rem 0.65rem;
}

body.display-portrait-tv .event_log_items {
  flex: 1;
  height: 100%;
  padding: 0.45rem 0.7rem;
  column-count: 2;
  column-gap: 1rem;
  column-fill: auto;
  overflow-y: auto;
}

body.display-portrait-tv .event_log_item {
  break-inside: avoid;
  margin: 0 0 0.32rem;
}

body.display-portrait-tv .event_log.is-collapsed {
  height: 0;
  min-height: 0;
  border-top: 0;
  background: transparent;
  overflow: visible;
}

body.display-portrait-tv .event_log:not(.is-collapsed) .event_log_tab {
  display: none;
}

body.display-portrait-tv .event_log.is-collapsed .event_log_close {
  display: none;
}

.page {
  height: 100dvh;
  width: min(1280px, 99%);
  margin: 0 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.has-event-log .page {
  width: min(
    1280px,
    max(calc(99% - var(--event-log-panel-width)), var(--page-min-width))
  );
  margin-left: auto;
  margin-right: auto;
  transform: translateX(calc(var(--event-log-panel-width) / 2));
}

.leader-row {
  position: sticky;
  background-color: #f4f4f4;
  top: 0;
  z-index: 10;
  transition: box-shadow 0.2s ease;
  border-radius: 12px;
}

.leader-row.has-behind {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.leader-row.has-behind::after {
  content: '';
  position: absolute;
  left: 0.35rem;
  right: 0.35rem;
  bottom: -0.28rem;
  height: 0.55rem;
  pointer-events: none;
  border-radius: 0 0 10px 10px;
}

.class_section_header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.45rem 0.5rem 0.25rem;
  margin-top: 0.55rem;
  border-top: 1px solid rgba(0, 0, 0, 0.14);
  font-weight: bold;
  letter-spacing: 0.03em;
}

.class_section_header_first {
  margin-top: 0;
  border-top: 0;
}

.class_section_name {
  min-width: 0;
}

.class_section_count {
  color: #666;
  font-size: 0.88rem;
}

.sentinel {
  height: 1px;
}

.sticky_leader_header {
  display: none;
}

h1 {
  text-align: center;
  margin-bottom: 0px;
  margin-top: 10px;
}

h2 {
  text-align: center;
  margin-top: 5px;
  margin-bottom: 10px;
  font-weight: normal;
  color: #555;
}

.toolbar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#themeToggleBtn {
  position: absolute;
  top: 0.45rem;
  right: 0.15rem;
  width: 2.9rem;
  height: 1.15rem;
  border: 0;
  border-radius: 999px;
  padding: 0;
  background: linear-gradient(
    135deg,
    hsl(242, 100%, 84%) 0%,
    hsl(242, 100%, 76%) 100%
  );
  box-shadow:
    inset 0 0 0 1.5px rgba(84, 107, 212, 0.45),
    0 0.4rem 1rem rgba(18, 11, 58, 0.14);
  cursor: pointer;
  color: transparent;
  font-size: 0;
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
  z-index: 18;
}

#themeToggleBtn::before {
  content: '';
  position: absolute;
  inset: 0.1rem;
  border-radius: 999px;
  background: hsl(242, 100%, 94%);
  box-shadow: inset 0 0 0 1px rgba(120, 145, 235, 0.28);
}

#themeToggleBtn::after {
  content: '☀';
  position: absolute;
  top: 0.05rem;
  left: 0.05rem;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  color: hsl(242, 42%, 26%);
  background: linear-gradient(
    180deg,
    hsl(242, 100%, 90%) 0%,
    hsl(242, 100%, 82%) 100%
  );
  box-shadow: 0 0.12rem 0.35rem rgba(34, 31, 87, 0.2);
  transition:
    transform 0.22s ease,
    background 0.22s ease,
    color 0.22s ease;
}

#themeToggleBtn.is-dark {
  background: linear-gradient(
    135deg,
    hsl(254, 57%, 38%) 0%,
    hsl(254, 57%, 29%) 100%
  );
}

#themeToggleBtn.is-dark::after {
  content: '☾';
  transform: translateX(1.75rem);
  color: hsl(240, 28%, 13%);
  background: linear-gradient(180deg, #7773ea 0%, hsl(254, 57%, 42%) 100%);
}

#mobileActiveBtn {
  display: none;
}

#mobileLossToggleBtn {
  display: none;
}

.labels {
  display: grid;
  grid-template-columns: 2.4rem 2.4rem minmax(0, 1fr) 3.3rem 6.9rem 7.4rem 2.9rem 6.5rem;
  padding: 2px 10px;
  margin: 0.4rem 0px;
  background-color: hsl(242, 100%, 80%);
  gap: 0.5rem;
  font-weight: bold;
  position: relative;
  align-items: center;
}

.header {
  display: grid;
  grid-template-columns: 2.4rem 2.4rem minmax(0, 1fr) 3.3rem 6.9rem 7.4rem 2.9rem 6.5rem;
  padding: 2px 10px;
  margin: 0.4rem 0px;
  background-color: hsl(242, 100%, 90%);
  gap: 0.5rem;
  position: relative;
  cursor: pointer;
  font-size: 1.6rem;
  align-items: center;
}

.header_content {
  display: contents;
}


.position_delta {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  min-width: 2rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: bold;
  text-align: center;
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
}

.position_delta_desktop {
  left: -3.3rem;
}

.position_delta_mobile {
  display: none;
  right: -1.8rem;
}

.position_delta.up {
  background-color: #15803d;
}

.position_delta.down {
  background-color: #b91c1c;
}

.position_delta.is-visible {
}

.position {
  width: 2.4rem;
  text-align: right;
}

.team_nr {
  width: 2.4rem;
  text-align: right;
}

.team_name {
  font-weight: bold;
  display: block;
  width: auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team_name_wrap {
  display: inline-block;
  position: relative;
  width: auto;
  min-width: 0;
}

.last_split_wrap {
  display: inline-block;
  position: relative;
  width: 3.3rem;
}

.country {
  text-align: center;
  min-width: 2.6rem;
  margin-right: auto;
}

.last_split {
  width: 3.3rem;
  text-align: center;
  font-weight: bold;
}

.total {
  width: 6.9rem;
  font-weight: bold;
  text-align: right;
}

.loss {
  width: 7.4rem;
  text-align: right;
}

.loss_sub_pos {
  display: block;
  width: 1.8rem;
  text-align: right;
  flex: 0 0 1.8rem;
}

.loss_sub_name {
  display: block;
  width: auto;
  text-align: left;
  flex: 1 1 auto;
  min-width: 0;
  margin-left: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub_pos {
  width: 2.9rem;
  text-align: right;
}

.subclass {
  width: auto;
}

.subclass_label {
  width: auto;
  text-align: left;
}

.desktop_toggle_switch {
  width: 2.9rem;
  height: 1.15rem;
  border: 0;
  border-radius: 999px;
  padding: 0;
  position: relative;
  background: linear-gradient(
    135deg,
    hsl(242, 100%, 84%) 0%,
    hsl(242, 100%, 76%) 100%
  );
  box-shadow:
    inset 0 0 0 1.5px rgba(84, 107, 212, 0.45),
    0 0.15rem 0.45rem rgba(18, 11, 58, 0.12);
  color: transparent;
  font-size: 0;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  overflow: hidden;
}

.labels_overlay_toggle {
  position: absolute;
  top: 50%;
  right: 0.35rem;
  transform: translateY(-50%);
  z-index: 19;
}

.desktop_toggle_switch::before {
  content: '';
  position: absolute;
  inset: 0.1rem;
  border-radius: 999px;
  background: hsl(242, 100%, 94%);
  box-shadow: inset 0 0 0 1px rgba(120, 145, 235, 0.28);
}

.desktop_toggle_switch::after {
  content: '−';
  position: absolute;
  top: 0.05rem;
  left: 0.05rem;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.86rem;
  font-weight: 700;
  color: hsl(242, 42%, 26%);
  background: linear-gradient(
    180deg,
    hsl(242, 100%, 90%) 0%,
    hsl(242, 100%, 82%) 100%
  );
  box-shadow: 0 0.12rem 0.35rem rgba(34, 31, 87, 0.2);
  transition:
    transform 0.22s ease,
    background 0.22s ease,
    color 0.22s ease;
}

.desktop_toggle_switch.is-details::after {
  content: '≡';
  transform: translateX(1.75rem);
}

.members {
  display: grid;
  grid-template-columns: repeat(3, minmax(290px, 1fr));
  gap: 10px;
  margin: 0 0.4rem;
}

.stage {
  display: grid;
  align-items: start;
  border-radius: var(--r);
  align-content: center;
}

.stage_bg {
  background-repeat: no-repeat;
  background-color: #fff;
  border-radius: var(--r);
  box-shadow: 1px 2px 4px rgba(0, 0, 0, 0.1);
}

.stage_data {
  height: 1rem;
  overflow: visible;
  position: relative;
  width: 6.9rem;
  color: #666;
  text-align: end;
  top: 0rem;
  margin-left: auto;
  line-height: 1.6rem;
}

.stage_grid_data {
  display: none;
  visibility: hidden;
  background-color: hsl(242, 100%, 96%);
  text-align: right;
  padding-right: 5px;
}

.leg_diff {
  display: flex;
}

.stage_behind {
  display: flex;
}

.stage_time {
  text-align: right;
  width: 4.5rem;
  margin-left: 0.1rem;
  gap: 0;
}

.stage_place {
  width: 2.4rem;
  text-align: center;
  font-weight: bold;
}

.no_result {
  display: none;
  visibility: hidden;
}

.legs {
  display: flex;
  flex-direction: column;
  grid-template-rows: 1fr;
  padding: 0.4rem;

  row-gap: 10px;
}

.legs34 {
  flex-direction: column-reverse;
}

.legs5 {
  display: grid;
  grid-template-rows: 1fr;
}

.leg {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reverse {
  flex-direction: column-reverse;
}

.line::before {
  position: relative;
  content: '';
  display: block;
  margin: 0 0 0 0;
  width: 63%;
  border-bottom: 1px solid #aaa;
  filter: drop-shadow(1px 2px 2px rgb(62, 62, 62));
  top: 0.2rem;
}

.line_full::before {
  position: relative;
  content: '';
  display: block;
  margin: 0 auto;
  width: 95%;
  border-bottom: 1px solid #aaa;
  filter: drop-shadow(1px 2px 2px rgb(62, 62, 62));
  top: 6px;
}

.leg:first-child:last-child::after {
  content: none;
  padding-bottom: 10px;
}

.leg:first-child.last-child {
  padding-bottom: 10px;
}

.runner {
  display: flex;
  padding: 0px 0;
  margin-left: 0 0rem;
  gap: 4px;
}

.bib {
  display: inline-block;
  text-align: left;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  width: 1.6rem;
}

.bib-blue .bib {
  color: blue;
}

.bib-red .bib {
  color: red;
}

.bib-green .bib {
  color: #15803d;
}

.name {
  text-transform: uppercase;
  font-weight: bold;
}

.in_forest {
  font-weight: bold;
}

.finished {
  color: #555;
}

.not_started {
  color: #aaa;
}

.live_data {
  display: flex;
  justify-content: flex-start;
  margin: 0 0rem;
  text-align: start;
  padding: 0px 0;
  color: #666;
  gap: 4px;
}

.station {
  display: inline-block;
  width: 1.6rem;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  text-align: left;
  min-height: calc(1rem + 4px);
}
.split {
  display: inline-block;
  width: 4rem;
}

.place {
  display: inline-block;
  width: 1.8rem;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  text-align: right;
}

.behind {
  display: inline-block;
  width: 4.6rem;
  text-align: end;
}

.team_split {
  margin-left: auto;
  display: inline-flex;
}

.team_behind {
  font-style: italic;
  color: #999;
}

.red {
  color: red;
  font-weight: bold;
}

.green {
  color: green;
}

.leg_split {
  display: inline-block;
  width: 6rem;
  text-align: right;
}

.hidden {
  display: none;
}

.splits {
  display: flex;
  flex-direction: row;
  gap: 1.45rem;
}

.radio {
  display: flex;
  flex-direction: row;
  gap: 4px;
  font-style: italic;
  color: #999;
}

.radio-updated {
  animation: radio-update-fade 5s ease-out both;
}

@keyframes radio-update-fade {
  0% {
    color: #b91c1c;
    background-color: rgba(185, 28, 28, 0.16);
  }
  100% {
    color: #999;
    background-color: transparent;
  }
}

.radio.placeholder {
  min-height: calc(1rem + 4px);
}

.split_cp {
  width: 1.6rem;
  font-weight: bold;
}

.notvisible {
  visibility: hidden;
}

.split_loss {
  display: none;
  visibility: hidden;
}

@media (max-width: 910px) {
  #mobileActiveBtn {
    display: inline-block;
  }

  #mobileLossToggleBtn {
    display: inline-block;
  }

  .event_log {
    top: auto;
    left: 50%;
    right: auto;
    bottom: env(safe-area-inset-bottom, 0px);
    width: 390px;
    height: calc(6.8rem + env(safe-area-inset-bottom, 0px));
    max-height: calc(6.8rem + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    border-right: 0;
    border-top: 3px solid rgba(0, 0, 0, 0.12);
  }

  .event_log.is-collapsed {
    bottom: env(safe-area-inset-bottom, 0px);
  }

  .event_log_tab {
    position: fixed;
    top: auto;
    left: 50%;
    right: auto;
    bottom: calc(0.2rem + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    width: 3rem;
    height: 1.1rem;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-bottom: 0;
    font-size: 0.75rem;
    line-height: 1;
    padding-bottom: 0.1rem;
  }

  .event_log.is-collapsed .event_log_tab {
    left: 50%;
    right: auto;
    bottom: calc(0.2rem + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
  }

  .event_log_close {
    position: fixed;
    top: auto;
    left: 50%;
    right: auto;
    bottom: calc(6.3rem + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    width: 3rem;
    height: 1.1rem;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-bottom: 0;
    font-size: 0.75rem;
    line-height: 1;
    padding-bottom: 0.1rem;
  }

  .event_log_title {
    display: none;
  }

  .event_log_items {
    padding: 0.12rem 0.55rem calc(0.08rem + env(safe-area-inset-bottom, 0px));
  }

  .event_log_item {
    gap: 0.03rem;
    padding: 0.06rem 0;
    font-size: 0.93rem;
  }

  .event_log_line {
    grid-template-columns: minmax(0, 1fr) 2.2rem 4rem 1.8rem;
    gap: 0.19rem;
    line-height: 1.05;
  }

  .event_log_line_secondary {
    font-size: 0.93rem;
  }

  .page {
    width: 390px;
    margin-right: auto;
    margin-left: auto;
    transform: none;
  }

  body.has-event-log .page {
    width: 390px;
    margin-right: auto;
    margin-left: auto;
    transform: none;
  }

  .title {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      'name name'
      'start clock'
      'subtitle subtitle';
    align-items: center;
    column-gap: 0.45rem;
    row-gap: 0.28rem;
    padding-top: 0.58rem;
    padding-bottom: 0.12rem;
    margin-bottom: 0.35rem;
  }

  #competitionName {
    grid-area: name;
    width: 100%;
    box-sizing: border-box;
    padding: 0 3.25rem;
  }

  #comp_time {
    grid-area: start;
    justify-self: start;
    font-size: 1.35rem;
    font-weight: 700;
    color: #666;
  }

  #competitionSubtitle {
    grid-area: subtitle;
    justify-self: center;
    text-align: center;
    font-size: 1rem;
  }

  #time {
    grid-area: clock;
    justify-self: end;
    font-size: 1.35rem;
    line-height: 1;
    font-weight: 800;
  }

  h1 {
    font-size: 1.4rem;
    margin-top: 0.35rem;
    margin-bottom: 0;
  }

  h2 {
    font-size: 1.17rem;
    margin-top: 0;
    margin-bottom: 0;
  }

  .toolbar {
    position: sticky;
    top: 0;
    z-index: 17;
    display: flex;
    justify-content: stretch;
    gap: 0;
    padding: 0;
    flex-wrap: nowrap;
    background-color: #f4f4f4;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  }

  .labels_overlay_toggle {
    position: static;
    top: auto;
    right: auto;
    z-index: auto;
    transform: none;
  }

  .toolbar .toolbar_main {
    flex: 1 1 0;
    min-width: 0;
    height: 2rem;
    padding: 0;
    font-size: 0.88rem;
    line-height: 1;
    border: 0;
    background: hsl(242, 100%, 92%);
    color: #333;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.45),
      inset 0 -1px 0 rgba(0, 0, 0, 0.08);
    appearance: none;
    -webkit-appearance: none;
    position: relative;
  }

  .toolbar .toggle_dual {
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.08rem;
    white-space: nowrap;
  }

  .toolbar .toggle_dual .is-active {
    font-weight: 700;
  }

  .toolbar .toggle_sep {
    opacity: 0.65;
    font-weight: 400;
  }

  .toolbar .toolbar_main:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 0.28rem;
    right: 0;
    bottom: 0.28rem;
    width: 1px;
    background: rgba(0, 0, 0, 0.12);
  }

  .toolbar .toolbar_main:active {
    background: hsl(242, 100%, 84%);
    box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.12);
  }

  .toolbar .toolbar_main:disabled {
    opacity: 0.45;
    cursor: default;
    box-shadow: none;
  }

  .labels {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2px;
    margin: 0;
    padding-left: 5px;
    position: sticky;
    top: var(--mobile-toolbar-height);
    z-index: 16;
  }

  .labels .last_split {
    display: none;
    visibility: hidden;
    text-align: center;
  }

  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 5px;
    gap: 2px;
    margin: 0;
    padding-left: 5px;
    font-size: unset;
  }

  .position_delta {
    min-width: 1.4rem;
    padding: 0 0.15rem;
    font-size: 0.78rem;
  }

  .position_delta_desktop {
    display: none;
  }

  .position_delta_mobile {
    display: block;
    right: auto;
    left: -2.4rem;
  }

  .position {
    width: 1.7rem;
    text-align: right;
  }

  .leader-row {
    position: relative;
    top: auto;
    z-index: auto;
  }

  .sticky_leader_header {
    display: none;
    position: sticky;
    top: calc(var(--mobile-toolbar-height) + var(--mobile-labels-height));
    z-index: 15;
    height: 0;
    overflow: visible;
    pointer-events: none;
  }

  .sticky_leader_header.is-visible {
    display: block;
  }

  .sticky_leader_header .header {
    position: absolute;
    left: 0;
    right: 0;
    margin: 0;
    pointer-events: auto;
  }

  .leader-row.has-behind {
    box-shadow: none;
  }

  .leader-row.has-behind::after {
    content: none;
  }

  body.theme-light .sticky_leader_header.is-visible .header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -0.18rem;
    height: 0.42rem;
    pointer-events: none;
    background: linear-gradient(
      to bottom,
      rgba(119, 115, 234, 0.58) 0,
      rgba(119, 115, 234, 0.58) 2px,
      rgba(244, 244, 244, 0) 100%
    );
  }

  body.theme-dark .sticky_leader_header.is-visible .header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -0.18rem;
    height: 0.42rem;
    pointer-events: none;
    background: linear-gradient(
      to bottom,
      rgba(122, 129, 214, 0.82) 0,
      rgba(122, 129, 214, 0.82) 2px,
      rgba(17, 17, 17, 0) 100%
    );
  }

  .team_nr {
    text-align: right;
    width: 1.7rem;
  }

  .team_name {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    margin-right: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .team_name_wrap {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    margin-right: auto;
  }

  .club {
    display: none;
    visibility: hidden;
  }

  .club_wrap {
    display: none;
    visibility: hidden;
  }

  .country {
    display: none;
    visibility: hidden;
    margin-right: 0;
  }

  .last_split {
    width: 2.5rem;
    text-align: center;
    margin-right: 0px;
  }

  .last_split_wrap {
    flex: 0 0 2.5rem;
    width: 2.5rem;
  }

  .total {
    flex: 0 0 4rem;
    width: 4rem;
    display: block;
    box-sizing: border-box;
    text-align: right;
  }

  .loss {
    flex: 0 0 calc(6.4rem + 2px);
    width: calc(6.4rem + 2px);
    display: block;
    box-sizing: border-box;
    text-align: right;
  }

  .loss_subclass_mode {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    white-space: nowrap;
  }

  .sub_pos {
    display: none;
    visibility: hidden;
  }

  .subclass {
    display: none;
    visibility: hidden;
  }

  .subclass_label {
    display: none;
    visibility: hidden;
  }

  .members {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    margin: 0;
  }

  .finished {
    background-color: #f9f9f9;
    --img: none;
    --ofs: none;
    --sz: none;
    background-position: none;
    background-size: none;
    background-repeat: none;
  }

  .stage_bg {
    background-color: #f9f9f9;
    border-radius: 0px;
    box-shadow: none;
  }

  .stage_data {
    display: none;
    visibility: hidden;
  }

  .stage_grid_data {
    display: flex;
    justify-content: right;
    visibility: visible;
    gap: 2px;
    padding-top: 1px;
    padding-bottom: 1px;
    color: #163a7a;
  }

  .stage_name {
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    margin-right: auto;
    margin-left: calc(1.6rem + 5px + 4px);
  }
  .stage_delta {
    display: inline-block;
    width: 6rem;
    margin-right: 4px;
  }

  .station {
    width: 1.8rem;
  }

  .stage_time {
    all: unset;
    display: inline-block;
    width: 4rem;
  }

  .stage_place {
    display: inline-block;
    width: 1.8rem;
    text-align: right;
    font-weight: normal;
  }

  .stage_behind {
    all: unset;
    display: inline-block;
    width: 4.6rem;
  }

  .splits {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .split_loss {
    display: inline-flex;
    visibility: visible;
    gap: 2px;
  }

  .split_cp {
    width: 1.8rem;
  }

  .split_t {
    width: 4rem;
  }

  .split_pos {
    width: 1.8rem;
    text-align: right;
  }

  .split_b {
    width: 4.6rem;
    text-align: right;
  }

  .radio {
    gap: 2px;
  }

  .legs {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    gap: 0;
  }

  .legs34 {
    flex-direction: column;
  }

  .legs5 {
  }

  .legs > .leg:nth-child(odd) {
    background-color: #eee;
  }

  .leg {
    display: flex;
    justify-content: right;
    padding: 1px 5px 1px 5px;
    margin: 0;
    flex-direction: row;
  }

  .reverse {
    flex-direction: row;
  }

  .line::before {
    content: none;
  }

  .line::after {
    content: none;
  }

  .leg:first-child::after {
    content: none;
  }

  .runner {
    margin-right: auto;
    margin-top: 0;
  }

  .live_data {
    display: flex;
    text-align: right;
    padding-top: 0px;
    margin-left: 0px;
    padding-bottom: 0px;
    gap: 2px;
  }

  .team_split {
    display: none;
    visibility: hidden;
  }

  .leg_split {
    display: none;
    visibility: hidden;
  }

  .line_full::after {
    content: none;
  }

  .bib {
    color: #555;
    text-shadow: #999 1px 0px 1px;
    margin-top: 0px;
    text-align: center;
  }
  .hidden {
    display: none;
  }

  .hide_in_grid {
    display: none;
    visibility: hidden;
  }

  .notvisible {
    display: none;
  }
}

/* ---------------------------
   Dark mode (auto)
--------------------------- */
@media (prefers-color-scheme: dark) {
  body {
    background-color: #111;
    color: #e6e6e6;
  }

  .event_log {
    background: #111;
    box-shadow: none;
    border-right-color: rgba(255, 255, 255, 0.1);
  }

  .event_log_title {
    background: hsl(254, 57%, 32%);
    border-bottom-color: rgba(255, 255, 255, 0.08);
  }

  .event_log_tab {
    background: hsl(254, 57%, 32%);
    box-shadow: none;
    border-right-color: rgba(255, 255, 255, 0.1);
    border-left-color: rgba(255, 255, 255, 0.1);
    border-top-color: rgba(255, 255, 255, 0.1);
  }

  .event_log_close {
    background: hsl(254, 57%, 32%);
    box-shadow: none;
    border-right-color: rgba(255, 255, 255, 0.1);
    border-left-color: rgba(255, 255, 255, 0.1);
    border-top-color: rgba(255, 255, 255, 0.1);
  }

  .event_log {
    border-top-color: rgba(255, 255, 255, 0.18);
  }

  .event_log_item {
    border-bottom-color: rgba(255, 255, 255, 0.07);
  }



  .leader {
    background-color: #111;
  }

  .leader-row {
    background-color: #111;
  }

  .leader.has-behind {
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
  }

  h2 {
    color: #b5b5b5;
  }

  .labels {
    background-color: hsl(240, 28%, 13%);
  }

  .header {
    background-color: hsl(254, 57%, 32%);
    margin-top: 5px;
  }


  .stage_bg {
    background-color: #1a1a1a;
  }

  .stage_data {
    color: #999;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
  }

  .stage_grid_data {
    background-color: hsl(242, 30%, 20%);
    color: rgb(124, 150, 235);
  }

  .line::after,
  .line_full::after {
    border-bottom: 1px solid #444;
    filter: drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.8));
  }

  .not_started {
    color: #777;
  }

  .live_data {
    color: #a8a8a8;
  }

  .radio {
    color: #666;
  }

  .finished {
    color: #ccc;
  }

  .in_forest {
    color: #fff;
  }

  /* bib colors: keep meaning, but soften brightness on dark */
  .bib-blue .bib {
    color: #6aa9ff;
  }

  .bib-red .bib {
    color: #ff6a6a;
  }

  .bib-green .bib {
    color: #4ade80;
  }

  @media (max-width: 910px) {
    .finished {
      background-color: #151515;
    }

    .stage_bg {
      background-color: #151515;
    }

    .legs > .leg:nth-child(odd) {
      background-color: #222;
    }

    .bib {
      color: #cfcfcf;
      text-shadow: rgba(0, 0, 0, 0.8) 1px 0px 1px;
    }
  }
}

body.theme-dark {
  background-color: #111;
  color: #e6e6e6;
}

body.theme-dark .event_log {
  background: #111;
  border-right-color: rgba(255, 255, 255, 0.1);
  border-top-color: rgba(255, 255, 255, 0.18);
}

body.theme-dark #themeToggleBtn::before {
  background: hsl(242, 24%, 21%);
  box-shadow: inset 0 0 0 1px rgba(122, 129, 214, 0.22);
}

body.theme-dark .desktop_toggle_switch {
  background: linear-gradient(
    135deg,
    hsl(254, 57%, 38%) 0%,
    hsl(254, 57%, 29%) 100%
  );
}

body.theme-dark .desktop_toggle_switch::before {
  background: hsl(242, 24%, 21%);
  box-shadow: inset 0 0 0 1px rgba(122, 129, 214, 0.22);
}

body.theme-dark .desktop_toggle_switch::after {
  color: hsl(240, 28%, 13%);
  background: linear-gradient(180deg, #7773ea 0%, hsl(254, 57%, 42%) 100%);
}

body.theme-dark .event_log_title {
  background: hsl(254, 57%, 32%);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

body.theme-dark .event_log_tab,
body.theme-dark .event_log_close {
  background: #c62828;
  color: #fff;
  border-right-color: rgba(255, 255, 255, 0.1);
  border-left-color: rgba(255, 255, 255, 0.1);
  border-top-color: rgba(255, 255, 255, 0.1);
}

body.theme-dark .event_log_item {
  border-bottom-color: rgba(255, 255, 255, 0.07);
}


body.theme-dark .leader,
body.theme-dark .leader-row {
  background-color: #111;
}

body.theme-dark .leader-row.has-behind {
  box-shadow: 0 0.35rem 0.8rem rgba(0, 0, 0, 0.5);
}

body.theme-dark .leader-row.has-behind::after {
  background: linear-gradient(
    to bottom,
    rgba(122, 129, 214, 0.7) 0,
    rgba(122, 129, 214, 0.7) 2px,
    rgba(17, 17, 17, 0) 100%
  );
}

body.theme-dark h2 {
  color: #b5b5b5;
}

body.theme-dark .labels {
  background-color: hsl(240, 28%, 13%);
}

body.theme-dark .header {
  background-color: hsl(254, 57%, 32%);
  margin-top: 5px;
}


body.theme-dark .stage_bg {
  background-color: #1a1a1a;
}

body.theme-dark .stage_data {
  color: #999;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
}

body.theme-dark .stage_grid_data {
  background-color: hsl(242, 30%, 20%);
  color: rgb(124, 150, 235);
}

body.theme-dark .line::after,
body.theme-dark .line_full::after {
  border-bottom: 1px solid #444;
  filter: drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.8));
}

body.theme-dark .not_started {
  color: #777;
}

body.theme-dark .live_data {
  color: #a8a8a8;
}

body.theme-dark .radio {
  color: #666;
}

body.theme-dark .finished {
  color: #ccc;
}

body.theme-dark .in_forest {
  color: #fff;
}

body.theme-dark .bib-blue .bib {
  color: #6aa9ff;
}

body.theme-dark .bib-red .bib {
  color: #ff6a6a;
}

body.theme-dark .bib-green .bib {
  color: #4ade80;
}

body.theme-light {
  background-color: #f4f4f4;
  color: #333;
}

body.theme-light .event_log {
  background: #f4f4f4;
  border-right-color: rgba(0, 0, 0, 0.08);
  border-top-color: rgba(0, 0, 0, 0.12);
}

body.theme-light .event_log_title {
  background: hsl(242, 100%, 90%);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

body.theme-light .event_log_tab,
body.theme-light .event_log_close {
  background: #c62828;
  color: #fff;
  border-right-color: rgba(0, 0, 0, 0.08);
  border-left-color: rgba(0, 0, 0, 0.08);
  border-top-color: rgba(0, 0, 0, 0.08);
}

body.theme-light .event_log_item {
  border-bottom-color: rgba(0, 0, 0, 0.05);
}



body.theme-light .leader,
body.theme-light .leader-row {
  background-color: #f4f4f4;
}

body.theme-light .leader-row.has-behind {
  box-shadow: 0 0.3rem 0.7rem rgba(0, 0, 0, 0.18);
}

body.theme-light .leader-row.has-behind::after {
  background: linear-gradient(
    to bottom,
    rgba(119, 115, 234, 0.42) 0,
    rgba(119, 115, 234, 0.42) 2px,
    rgba(244, 244, 244, 0) 100%
  );
}

body.theme-light h2 {
  color: #555;
}

body.theme-light .labels {
  background-color: hsl(242, 100%, 80%);
}

body.theme-light .header {
  background-color: hsl(242, 100%, 90%);
  margin-top: 0.4rem;
}


body.theme-light .stage_bg {
  background-color: #fff;
}

body.theme-light .stage_data {
  color: #666;
  text-shadow: none;
}

body.theme-light .stage_grid_data {
  background-color: hsl(242, 100%, 96%);
  color: #163a7a;
}

body.theme-light .not_started {
  color: #aaa;
}

body.theme-light .live_data {
  color: #666;
}

body.theme-light .radio {
  color: #999;
}

body.theme-light .finished {
  color: #555;
}

body.theme-light .in_forest {
  color: inherit;
}

@media (max-width: 910px) {
  body.theme-light .toolbar {
    background-color: #f4f4f4;
    border-bottom-color: rgba(0, 0, 0, 0.08);
  }

  body.theme-light .toolbar button {
    background: hsl(242, 100%, 92%);
    color: #333;
  }

  body.theme-light .toolbar button:not(:last-child)::after {
    background: rgba(0, 0, 0, 0.12);
  }

  body.theme-light .toolbar button:active {
    background: hsl(242, 100%, 84%);
  }

  body.theme-light .header {
    margin-top: 0;
  }

  body.theme-light .event_log_tab,
  body.theme-light .event_log_close {
    background: #c62828;
    color: #fff;
    border-right-color: rgba(0, 0, 0, 0.08);
    border-left-color: rgba(0, 0, 0, 0.08);
    border-top-color: rgba(0, 0, 0, 0.08);
  }

  body.theme-light .finished {
    background-color: #f9f9f9;
  }

  body.theme-light .stage_bg {
    background-color: #f9f9f9;
  }

  body.theme-light .legs > .leg:nth-child(odd) {
    background-color: #eee;
  }

  body.theme-light .bib {
    color: #555;
    text-shadow: #999 1px 0px 1px;
  }
}

@media (max-width: 910px) {
  body.theme-dark .toolbar {
    background-color: #111;
    border-bottom-color: rgba(255, 255, 255, 0.08);
  }

  body.theme-dark .toolbar button {
    background: hsl(254, 42%, 28%);
    color: #f2f2f2;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.08),
      inset 0 -1px 0 rgba(0, 0, 0, 0.3);
  }

  body.theme-dark .toolbar button:not(:last-child)::after {
    background: rgba(255, 255, 255, 0.1);
  }

  body.theme-dark .toolbar button:active {
    background: hsl(254, 42%, 22%);
    box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.35);
  }

  body.theme-dark .header {
    margin-top: 0;
  }

  body.theme-dark .event_log_tab,
  body.theme-dark .event_log_close {
    background: #c62828;
    color: #fff;
    border-right-color: rgba(255, 255, 255, 0.14);
    border-left-color: rgba(255, 255, 255, 0.14);
    border-top-color: rgba(255, 255, 255, 0.14);
  }
}
