/* RACE DAY screen (see screens/raceday.js). Everything is scoped under .app-screen--raceday. */

/* The map must stay visible and draggable: the root itself is transparent and click-through;
   only the header, the card catch taps. `html` raises specificity above the
   shell's generic .app-screen rule regardless of load order. */
html .app-screen--raceday {
  background: transparent;
  pointer-events: none;
  font-family: var(--font-family);
  color: #fff;
}

.app-screen--raceday .rd {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;   /* header at the top, card at the bottom */
  height: 100%;
  padding-left: env(safe-area-inset-left, 0px);    /* iPhone landscape: clear of the notch */
  padding-right: env(safe-area-inset-right, 0px);
  pointer-events: none;
}

.app-screen--raceday button {
  font-family: var(--font-family);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app-screen--raceday button:focus-visible {
  outline: 3px solid #f9e243;
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ header */

.app-screen--raceday .rd-header {
  box-sizing: border-box;
  pointer-events: auto;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 12px;
  background: #006D4F;
  border-bottom: 2px solid #fff;
  color: #fff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

.app-screen--raceday .rd-top {
  display: flex;
  align-items: flex-start;   /* the bar's top edge lines up with the top of the layers button */
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
}

/* progress bar with the facts line under it; fills the row left of the layers button */
.app-screen--raceday .rd-progress {
  flex: 1 1 auto;
  min-width: 0;
}

.app-screen--raceday .rd-layers {
  flex: none;
  width: 44px;
  height: 44px;
  margin-left: auto;
  border: 2px solid #fff;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: none;            /* phones only: desktop keeps the layer box in the corner */
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

html.app-compact .app-screen--raceday .rd-layers { display: flex; }

.app-screen--raceday .rd-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.35);   /* separates progress from the big numbers */
}

.app-screen--raceday .rd-stat { min-width: 0; }
.app-screen--raceday .rd-stat--togo { text-align: right; }

.app-screen--raceday .rd-big {
  font-size: 40px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.app-screen--raceday .rd-stat--done .rd-big { color: #f9e243; }
.app-screen--raceday .rd-stat--togo .rd-big { color: #fff; }

.app-screen--raceday .rd-big-unit {
  font-size: 0.42em;
  white-space: pre;
  letter-spacing: 0.04em;
}

.app-screen--raceday .rd-stat-label {
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #d3f0e6;
}

.app-screen--raceday .rd-bar {
  height: 10px;
  margin-top: 0;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}

.app-screen--raceday .rd-bar-fill {
  width: 0;
  height: 100%;
  border-radius: 5px;
  background: #f9e243;
  transition: width 0.6s ease;
}

.app-screen--raceday .rd-facts {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 12px;
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #d3f0e6;
}

/* timer strip: the phone's own (unofficial) time on the left, MY RACE on the right */
.app-screen--raceday .rd-timer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.35);
}

.app-screen--raceday .rd-time-box {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.app-screen--raceday .rd-time {
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.app-screen--raceday .rd-time-label {
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: 0.06em;
  color: #d3f0e6;
}

.app-screen--raceday .rd-myrace {
  flex: none;
  min-height: 36px;
  padding: 0 14px;
  border: 2px solid #fff;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.app-screen--raceday .rd-myrace:active { background: #f9e243; color: #0b1526; }
.app-screen--raceday .rd-myrace { display: inline-flex; align-items: center; gap: 6px; padding-right: 10px; }
.app-screen--raceday .rd-chevron {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.2s ease;
}
.app-screen--raceday .rd-myrace.open .rd-chevron { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .app-screen--raceday .rd-chevron { transition: none; } }

/* ------------------------------------------------------------------ MY RACE panel */

/* folds out of the bottom of the header, under the timer strip */
.app-screen--raceday .rd-myrace.open { background: #f9e243; color: #0b1526; border-color: #f9e243; }

.app-screen--raceday .rd-race-panel {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.35);
}

.app-screen--raceday .rd-sheet-note { margin: 0 0 4px; font-size: 13px; line-height: 1.35; color: #d3f0e6; }

.app-screen--raceday .rd-sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  padding: 0 12px;
  border: 2px solid #fff;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.06em;
  text-align: left;
  cursor: pointer;
}
.app-screen--raceday .rd-sheet-row--quiet { border-color: rgba(255, 255, 255, 0.5); background: transparent; font-weight: normal; }
.app-screen--raceday .rd-sheet-pick span { white-space: nowrap; }
/* END and RESET side by side */
.app-screen--raceday .rd-sheet-actions { display: flex; gap: 8px; }
.app-screen--raceday .rd-sheet-actions .rd-sheet-row { justify-content: center; text-align: center; }
.app-screen--raceday .rd-sheet-select {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 60%;
  min-height: 34px;
  border: none;
  border-radius: 8px;
  background: #fff;
  color: #0b1526;
  font: inherit;
  font-size: 14px;
  font-weight: normal;
  letter-spacing: 0;
}

/* ------------------------------------------------------------------ bottom group */

.app-screen--raceday .rd-bottom {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 12px 12px;
  pointer-events: none;   /* the gaps around the card stay click-through */
}

.app-screen--raceday .rd-card {
  box-sizing: border-box;
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 12px 14px 14px;
  border: 3px solid #f9e243;
  border-radius: 16px;
  background: #0b1526;
  color: #fff;
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

.app-screen--raceday .rd-card:disabled { cursor: default; opacity: 1; color: #fff; }
.app-screen--raceday .rd-card:not(:disabled):active { background: #122a46; }

.app-screen--raceday .rd-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.app-screen--raceday .rd-card-label {
  font-size: 15px;
  line-height: 1.1;
  color: #d3dcee;
  letter-spacing: 0.04em;
}

.app-screen--raceday .rd-card-dist {
  font-size: 34px;
  line-height: 1;
  color: #f9e243;
  letter-spacing: 0.04em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.app-screen--raceday .rd-card-name {
  margin-top: 4px;
  font-size: 32px;
  line-height: 1.05;
  letter-spacing: 0.04em;
  color: #fff;
  overflow-wrap: anywhere;
}

.app-screen--raceday .rd-card-detail {
  margin-top: 6px;
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: 0.04em;
  color: #d3dcee;
  overflow-wrap: anywhere;
}

.app-screen--raceday .rd-card-off {
  margin-top: 8px;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0.04em;
  color: #f9e243;
}

/* START MY RACE: the one card meant to be pressed, so it is a button in the logo's yellow */
.app-screen--raceday .rd-card.rd-card--go { background: #f9e243; border-color: #f9e243; }
.app-screen--raceday .rd-card.rd-card--go:not(:disabled):active { background: #ffe96a; }
.app-screen--raceday .rd-card--go .rd-card-label,
.app-screen--raceday .rd-card--go .rd-card-detail { color: #0b1526; }
.app-screen--raceday .rd-card--go .rd-card-name { color: #0b1526; font-weight: bold; }

/* Finished: the badge beside FINISHED and what the runner got through */
.app-screen--raceday .rd-card.rd-card--finish {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 12px;
  align-items: center;
}
.app-screen--raceday .rd-card--finish > :not(.rd-card-badge) { grid-column: 1; }
/* NORTHSIDE NEMESIS 2027 runs the full width above the badge, so the big badge doesn't wrap it */
.app-screen--raceday .rd-card--finish > .rd-card-top { grid-column: 1 / -1; }
.app-screen--raceday .rd-card-badge {
  grid-column: 2;
  grid-row: 2 / span 3;
  width: 112px;
  height: 112px;
}
.app-screen--raceday .rd-card--finish .rd-card-name { color: #f9e243; font-weight: bold; font-size: 40px; }
.app-screen--raceday .rd-card-stats {
  margin-top: 6px;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0.04em;
  color: #fff;
  font-weight: bold;
  white-space: pre-line;   /* staircases on one line, distance and climb on the next */
}
.app-screen--raceday .rd-card--finish .rd-card-detail { font-size: 13px; }

/* Finished: the donate link under the card, outlined in the card's yellow */
.app-screen--raceday .rd-donate {
  box-sizing: border-box;
  display: block;
  padding: 10px 12px;
  border: 2px solid #f9e243;
  border-radius: 12px;
  background: #0b1526;
  color: #f9e243;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-align: center;
  text-decoration: none;
  pointer-events: auto;
}
.app-screen--raceday .rd-donate:hover { background: #122a46; }

.app-screen--raceday [hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .app-screen--raceday .rd-bar-fill { transition: none; }
}

/* ------------------------------------------------------------------ narrow phones */

@media (max-width: 400px) {
  .app-screen--raceday .rd-big { font-size: 36px; }
  .app-screen--raceday .rd-card-name { font-size: 28px; }
  /* FINISHED on one line beside the 112px badge */
  .app-screen--raceday .rd-card--finish .rd-card-name { font-size: 36px; }
  .app-screen--raceday .rd-card-dist { font-size: 30px; }
  .app-screen--raceday .rd-facts { font-size: 13px; }
}

/* Landscape phones: very little height, so everything (stats and the next-staircase card) sits
   in one scrollable column on the left and the map has the rest of the screen to itself. */
@media (max-height: 499px) {
  html.app-compact .app-screen--raceday .rd {
    justify-content: flex-start;
    width: 46%;
    max-width: 360px;
    background: #006D4F;
    border-right: 2px solid #fff;
    box-shadow: 3px 0 10px rgba(0, 0, 0, 0.35);
    overflow-y: auto;
    overscroll-behavior: contain;
    pointer-events: auto;
  }
  html.app-compact .app-screen--raceday .rd-header { flex: none; border-bottom: none; box-shadow: none; padding-bottom: 12px; }
  html.app-compact .app-screen--raceday .rd-bottom { flex: none; padding: 0 14px 12px; pointer-events: auto; }
  /* not a card here: a plain section under a rule, set apart from the stats above it */
  html.app-compact .app-screen--raceday .rd-card {
    padding: 12px 0 0;
    border: none;
    border-top: 2px solid rgba(255, 255, 255, 0.45);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  /* the START MY RACE button and the finish badge stay, sized for the narrow column */
  html.app-compact .app-screen--raceday .rd-card.rd-card--go {
    margin-top: 12px;
    padding: 8px 12px 10px;
    border: 3px solid #f9e243;
    border-radius: 12px;
    background: #f9e243;
  }
  .app-screen--raceday .rd-card-badge { width: 72px; height: 72px; }
  .app-screen--raceday .rd-card--finish .rd-card-name { font-size: 26px; }
  .app-screen--raceday .rd-card-stats { font-size: 14px; }
  .app-screen--raceday .rd-big { font-size: 30px; }
  .app-screen--raceday .rd-card { padding: 8px 12px 10px; }
  .app-screen--raceday .rd-card-name { font-size: 22px; }
  .app-screen--raceday .rd-card-dist { font-size: 24px; }
}

/* The shortest landscape phones (568x320): tighter type so the column needs little or no scrolling */
@media (max-height: 359px) {
  html.app-compact .app-screen--raceday .rd-header { padding: 6px 12px 8px; }
  html.app-compact .app-screen--raceday .rd-top { min-height: 36px; }
  html.app-compact .app-screen--raceday .rd-big { font-size: 24px; }
  html.app-compact .app-screen--raceday .rd-time { font-size: 18px; }
  html.app-compact .app-screen--raceday .rd-facts { font-size: 11px; }
  html.app-compact .app-screen--raceday .rd-bottom { padding: 0 12px 8px; }
  html.app-compact .app-screen--raceday .rd-card { padding: 8px 0 0; }
  html.app-compact .app-screen--raceday .rd-card-label { font-size: 11px; }
  html.app-compact .app-screen--raceday .rd-card-name { font-size: 17px; }
  html.app-compact .app-screen--raceday .rd-card-dist { font-size: 18px; }
  html.app-compact .app-screen--raceday .rd-card-detail { font-size: 12px; }
}

/* ------------------------------------------------------------------ desktop: 420px panel */

html:not(.app-compact) .app-screen--raceday {
  background: #0b1526;
  pointer-events: auto;
  overflow-y: auto;
}

html:not(.app-compact) .app-screen--raceday .rd {
  justify-content: flex-start;   /* stacked: header, card */
  height: auto;
  min-height: 100%;
  pointer-events: auto;
}

html:not(.app-compact) .app-screen--raceday .rd-header {
  padding-top: 12px;
  box-shadow: none;
}

html:not(.app-compact) .app-screen--raceday .rd-bottom {
  gap: 14px;
  padding: 16px 14px 18px;
  pointer-events: auto;
}

html:not(.app-compact) .app-screen--raceday .rd-card { box-shadow: none; }
