/* ═══════════════════════════════════════════════════════════════════
   FISPOINTS – Alpine FIS Points Calculator  |  style.css
   ═══════════════════════════════════════════════════════════════════ */

/* ── Reset / base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-bg:          #f2f4f7;
  --clr-surface:     #ffffff;
  --clr-header-bg:   #0d1b2a;   /* deep navy – alpine night sky */
  --clr-header-fg:   #e8f0fe;
  --clr-accent:      #1565c0;   /* FIS blue */
  --clr-accent-lt:   #e8f0fe;
  --clr-border:      #dce1e9;
  --clr-text:        #1a1a2e;
  --clr-text-muted:  #5f6b7c;

  --clr-gold:        #f9c319;
  --clr-gold-bg:     #fffbeb;
  --clr-silver:      #a0a8b0;
  --clr-silver-bg:   #f5f6f7;
  --clr-bronze:      #c87533;
  --clr-bronze-bg:   #fdf3ee;

  --clr-points-bg:   #e8f5e9;   /* light green – top 10 */
  --clr-points-fg:   #1b5e20;
  --clr-dnf-bg:      #fce4ec;
  --clr-dnf-fg:      #880e4f;
  --clr-dsq-bg:      #fff3e0;
  --clr-dsq-fg:      #e65100;
  --clr-dns-bg:      #f5f5f5;
  --clr-dns-fg:      #757575;
  --clr-live:        #e53935;

  --radius:          8px;
  --shadow:          0 1px 4px rgba(0,0,0,.12);
  --font:            'Segoe UI', system-ui, -apple-system, sans-serif;
  --emoji-font:      'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif;
}

html, body {
  font-family: var(--font);
  font-size:   15px;
  color:       var(--clr-text);
  background:  var(--clr-bg);
  min-height:  100vh;
}

a { color: var(--clr-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ─────────────────────────────────────────────────────────── */
.app-header {
  background: var(--clr-header-bg);
  color:      var(--clr-header-fg);
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  position:   sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1280px;
  margin:    0 auto;
  padding:   0 1.25rem;
  height:    58px;
  display:   flex;
  align-items: center;
  justify-content: space-between;
}
.header-brand {
  display:     flex;
  align-items: baseline;
  gap:         .6rem;
}
.logo-ski    { font-size: 1.6rem; }
.app-title   { font-size: 1.35rem; font-weight: 700; letter-spacing: .04em; }
.app-subtitle{
  font-size:  .8rem;
  color:      rgba(232,240,254,.6);
  display:    none;
}
@media (min-width: 540px) { .app-subtitle { display: inline; } }

.header-status {
  display:     flex;
  align-items: center;
  gap:         .6rem;
}

/* Pulsing live dot */
.live-dot {
  width:  10px; height: 10px;
  border-radius: 50%;
  background: #4caf50;
  box-shadow: 0 0 0 0 rgba(76,175,80,.6);
}
.live-dot.active {
  animation: pulse 1.8s infinite;
}
.live-dot.error { background: #e53935; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0   rgba(76,175,80,.6); }
  70%  { box-shadow: 0 0 0 8px rgba(76,175,80,0);  }
  100% { box-shadow: 0 0 0 0   rgba(76,175,80,0);  }
}

.refresh-countdown {
  font-size: .75rem;
  color:     rgba(232,240,254,.55);
  min-width: 60px;
  text-align: right;
}

/* ── Controls bar ────────────────────────────────────────────────────── */
.controls-bar {
  background:  var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  box-shadow:  var(--shadow);
}
.controls-inner {
  max-width:  1280px;
  margin:     0 auto;
  padding:    .7rem 1.25rem;
  display:    flex;
  flex-wrap:  wrap;
  gap:        .75rem;
  align-items: center;
}
.control-group {
  display:    flex;
  flex-direction: column;
  gap:        .25rem;
}
.control-label {
  font-size:  .7rem;
  font-weight: 600;
  color:      var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.race-select {
  min-width:  260px;
  max-width:  420px;
  padding:    .42rem .6rem;
  border:     1px solid var(--clr-border);
  border-radius: var(--radius);
  background: var(--clr-surface);
  font:       inherit;
  font-size:  .9rem;
  color:      var(--clr-text);
  cursor:     pointer;
}
.race-select:focus { outline: 2px solid var(--clr-accent); outline-offset: 1px; }

.race-state-legend {
  display:        flex;
  flex-direction: column;
  gap:            .08rem;
}
.race-control-inline {
  display:        flex;
  flex-direction: row;
  align-items:    center;
  gap:            .5rem;
}
.control-label-row {
  display:        flex;
  flex-direction: column;
  gap:            .15rem;
  align-self:     flex-end;
}
.rsl-item {
  display:    flex;
  align-items: center;
  gap:        .2rem;
  font-size:  .58rem;
  color:      var(--clr-text-muted);
  line-height: 1;
}
.rsl-dot  { display: inline-block; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.dot-green  { background: #4caf50; }
.dot-orange { background: #ff9800; }
.dot-red    { background: #e53935; }
.dot-gray   { background: #9e9e9e; }

.penalty-input {
  width:    90px;
  padding:  .42rem .6rem;
  border:   1px solid var(--clr-border);
  border-radius: var(--radius);
  font:     inherit;
  font-size: .9rem;
  color:    var(--clr-text);
}
.penalty-input:focus { outline: 2px solid var(--clr-accent); outline-offset: 1px; }
.penalty-input::placeholder { color: var(--clr-text-muted); }

.control-group { flex-direction: row; align-items: center; gap: .4rem; }
.control-group label { align-self: center; }

/* Buttons */
.btn {
  padding:       .42rem .85rem;
  border:        none;
  border-radius: var(--radius);
  background:    var(--clr-accent);
  color:         #fff;
  font:          inherit;
  font-size:     .85rem;
  font-weight:   600;
  cursor:        pointer;
  white-space:   nowrap;
  transition:    background .15s, transform .1s;
}
.btn:hover  { background: #0d47a1; }
.btn:active { transform: scale(.97); }
.btn-sm     { padding: .36rem .65rem; }
.btn-outline {
  background: transparent;
  border:     1px solid var(--clr-accent);
  color:      var(--clr-accent);
}
.btn-outline:hover { background: var(--clr-accent-lt); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Race info banner ─────────────────────────────────────────────────── */
.race-info {
  background:   linear-gradient(135deg, #0d1b2a 0%, #1a3a5c 100%);
  color:        var(--clr-header-fg);
  border-bottom: 2px solid var(--clr-accent);
}
.race-info.hidden { display: none; }
.race-info-inner {
  max-width: 1280px;
  margin:    0 auto;
  padding:   .65rem 1.25rem;
  display:   flex;
  flex-wrap: wrap;
  gap:       1.2rem;
}
.race-info-block {
  display:       flex;
  flex-direction: column;
  gap:           .1rem;
}
.race-info-label {
  font-size:  .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color:      rgba(232,240,254,.5);
}
.race-info-value {
  font-size:  .95rem;
  font-weight: 600;
  color:      var(--clr-header-fg);
}
.penalty-badge {
  background:  rgba(255,255,255,.12);
  padding:     .15rem .5rem;
  border-radius: 4px;
  color:       var(--clr-gold);
  font-variant-numeric: tabular-nums;
}

/* Source badge */
.badge-official   { background: #1b5e20; color: #a5d6a7; padding: .2rem .55rem; border-radius: 12px; font-size: .75rem; font-weight: 700; }
.badge-calculated { background: #e65100; color: #ffcc80; padding: .2rem .55rem; border-radius: 12px; font-size: .75rem; font-weight: 700; }
.badge-live       { background: var(--clr-live); color: #fff; padding: .2rem .55rem; border-radius: 12px; font-size: .75rem; font-weight: 700; }

/* ── Formula details ──────────────────────────────────────────────────── */
.formula-details {
  max-width:    1280px;
  margin:       .75rem auto 0;
  padding:      0 1.25rem;
}
.formula-details summary {
  cursor:     pointer;
  font-size:  .82rem;
  font-weight: 600;
  color:      var(--clr-text-muted);
  padding:    .45rem 0;
  user-select: none;
}
.formula-details summary:hover { color: var(--clr-accent); }
.formula-body {
  background:   var(--clr-surface);
  border:       1px solid var(--clr-border);
  border-radius: var(--radius);
  padding:      1rem 1.25rem;
  font-size:    .85rem;
  line-height:  1.6;
  margin-bottom: .5rem;
}
.formula-body p { margin-bottom: .75rem; }
.formula-body code {
  background:  var(--clr-bg);
  padding:     .15em .4em;
  border-radius: 4px;
  font-size:   .9em;
}
.fval-table {
  border-collapse: collapse;
  font-size: .85rem;
  margin-top: .5rem;
}
.fval-table th, .fval-table td {
  border:  1px solid var(--clr-border);
  padding: .3rem .7rem;
  text-align: left;
}
.fval-table th { background: var(--clr-bg); font-weight: 700; }

/* ── Formula two-column layout ───────────────────────────────────────── */
.formula-columns {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}
.formula-left  { flex: 0 0 auto; min-width: 0; }
.formula-right { flex: 1 1 280px; min-width: 0; }
@media (max-width: 700px) {
  .formula-columns { flex-direction: column; }
  .formula-right   { width: 100%; }
}

/* ── Calculation summary panel ───────────────────────────────────────── */
.calc-summary {
  background:    var(--clr-bg);
  border:        1px solid var(--clr-border);
  border-radius: var(--radius);
  padding:       .75rem 1rem;
  font-size:     .82rem;
  line-height:   1.5;
}
.calc-title {
  font-size:   .88rem;
  font-weight: 700;
  margin:      0 0 .5rem;
  color:       var(--clr-text);
}
.calc-meta {
  display:        flex;
  flex-direction: column;
  gap:            .2rem;
  margin-bottom:  .6rem;
  color:          var(--clr-text-muted);
}
.calc-meta strong { color: var(--clr-text); }
.calc-subtitle {
  font-weight:   600;
  margin:        .5rem 0 .3rem;
}
.calc-table {
  border-collapse: collapse;
  width:           100%;
  font-size:       .80rem;
}
.calc-table th, .calc-table td {
  border:  1px solid var(--clr-border);
  padding: .2rem .45rem;
  text-align: left;
}
.calc-table th         { background: var(--clr-surface); font-weight: 700; }
.calc-table td.num-col { text-align: right; font-variant-numeric: tabular-nums; }
.calc-avg {
  margin-top: .45rem;
  font-size:  .82rem;
}
.calc-warning {
  color:      var(--clr-text-muted);
  font-size:  .78rem;
  margin-top: .3rem;
}
.calc-empty {
  color:       var(--clr-text-muted);
  font-style:  italic;
}

/* ── Main content ─────────────────────────────────────────────────────── */
.main-content {
  max-width: 1280px;
  margin:    .75rem auto 2rem;
  padding:   0 1.25rem;
}

/* Loading */
.loading-state {
  text-align: center;
  padding:    3rem 1rem;
  color:      var(--clr-text-muted);
}
.loading-state.hidden { display: none; }
.spinner {
  width:  36px; height: 36px;
  margin: 0 auto .75rem;
  border: 3px solid var(--clr-border);
  border-top-color: var(--clr-accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Error */
.error-box {
  background:   #fce4ec;
  border:       1px solid #f48fb1;
  border-radius: var(--radius);
  padding:      .75rem 1rem;
  color:        #880e4f;
  margin-bottom: .75rem;
}
.error-box.hidden { display: none; }

/* Placeholder */
.placeholder {
  text-align:  center;
  padding:     4rem 1rem;
  color:       var(--clr-text-muted);
}
.placeholder-icon { font-size: 3rem; display: block; margin-bottom: .75rem; }

/* Legend */
.legend {
  display:   flex;
  flex-wrap: wrap;
  gap:       .5rem;
  margin-bottom: .65rem;
  font-size: .78rem;
}
.legend-item {
  display:    inline-flex;
  align-items: center;
  gap:        .35rem;
  padding:    .18rem .55rem;
  border-radius: 4px;
  font-weight: 600;
}
.legend-gold   { background: var(--clr-gold-bg);   color: #7b5e00; border: 1px solid var(--clr-gold);   }
.legend-silver { background: var(--clr-silver-bg); color: #424242; border: 1px solid var(--clr-silver); }
.legend-bronze { background: var(--clr-bronze-bg); color: #5d2e00; border: 1px solid var(--clr-bronze); }
.legend-points { background: var(--clr-points-bg); color: var(--clr-points-fg); border: 1px solid #a5d6a7; }
.legend-dnf    { background: var(--clr-dnf-bg);    color: var(--clr-dnf-fg);    border: 1px solid #f48fb1; }

/* Results table */
.results-wrapper.hidden { display: none; }
.table-scroll { overflow-x: auto; }

.results-table {
  width:          100%;
  border-collapse: collapse;
  font-size:      .88rem;
  background:     var(--clr-surface);
  border-radius:  var(--radius);
  overflow:       hidden;
  box-shadow:     var(--shadow);
}
.results-table th {
  background:     var(--clr-header-bg);
  color:          rgba(232,240,254,.85);
  font-weight:    700;
  font-size:      .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding:        .55rem .65rem;
  white-space:    nowrap;
  text-align:     left;
}
.results-table th.num { text-align: right; }
.results-table td {
  padding:       .5rem .65rem;
  border-bottom: 1px solid var(--clr-border);
  white-space:   nowrap;
  vertical-align: middle;
}
.results-table td.num     { text-align: right; font-variant-numeric: tabular-nums; }
.results-table td.name    { font-weight: 600; }
.results-table td.nation  { font-size: 1.1rem; color: var(--clr-text-muted); }
.results-table td.fis-pts {
  text-align: right;
  white-space: nowrap;
  vertical-align: middle;
}

/* Nation flag styling */
.nation-flag {
  display: inline-block;
  font-size: 1.2rem;
  line-height: 1;
  letter-spacing: 0;
  font-family: var(--emoji-font);
  font-weight: normal;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.nation-code {
  display: inline-block;
  min-width: 2.5em;
  padding: 0.1em 0.25em;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  background: var(--clr-accent-lt);
  border: 1px solid var(--clr-accent);
  border-radius: 3px;
  color: var(--clr-accent);
}

.nation-missing {
  display: inline-block;
  width: 1.5em;
  text-align: center;
  color: var(--clr-text-muted);
}
.pts-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  min-width: 5rem;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
  line-height: 1.5;
  transition: filter .15s;
}

.results-table td.fis-list-pts {
  text-align: right;
  font-size: .85rem;
  color: var(--clr-text-muted);
  font-variant-numeric: tabular-nums;
}

/* PR column – places gained/lost */
.pr-col {
  width: 3.5rem;
}
.pr-cell {
  text-align: center;
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--clr-text-muted);
}
.pr-up   { color: #1b7a2f; }
.pr-down { color: #c0392b; }
.pr-even { color: var(--clr-text-muted); font-weight: 400; }

/* Row coloring */
.results-table tbody tr:last-child td { border-bottom: none; }
.results-table tbody tr:hover { filter: brightness(.97); }

.row-gold    { background: var(--clr-gold-bg);   }
.row-silver  { background: var(--clr-silver-bg); }
.row-bronze  { background: var(--clr-bronze-bg); }
.row-points  { background: var(--clr-points-bg); }
.row-dnf     { background: var(--clr-dnf-bg); color: var(--clr-dnf-fg); opacity: .8; }
.row-dsq     { background: var(--clr-dsq-bg); color: var(--clr-dsq-fg); opacity: .8; }
.row-dns     { background: var(--clr-dns-bg); color: var(--clr-dns-fg); opacity: .75; }
.row-live-running { background: #e8f5e9; font-weight: 600; }
.row-live-gate    { background: #fff8e1; color: var(--clr-text-muted); }

/* Medal icons in rank cell */
.medal { font-size: 1rem; }

/* FIS points coloring in the points cell */
/* pts-* classes kept for potential fallback use */

/* Results count footer */
.results-count {
  margin-top: .5rem;
  font-size:  .78rem;
  color:      var(--clr-text-muted);
  text-align: right;
}

/* ── Footer ─────────────────────────────────────────────────────────── */
.app-footer {
  border-top: 1px solid var(--clr-border);
  background: var(--clr-surface);
  padding:    .75rem 1.25rem;
  display:    flex;
  flex-wrap:  wrap;
  gap:        1.5rem;
  justify-content: center;
  font-size:  .78rem;
  color:      var(--clr-text-muted);
}

/* ── Utility ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ════════════════════════════════════════════════════════════════════
   LIVE RACE PANEL  (on-course racer + start queue)
   ════════════════════════════════════════════════════════════════════ */
.live-panel {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-left: 3px solid var(--clr-live);
  border-radius: var(--radius);
  margin-bottom: .75rem;
  overflow: hidden;
}
.lp-header {
  background: #fff0f0;
  padding: .35rem .75rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .8rem;
}
.lp-run  { font-weight: 700; color: var(--clr-live); text-transform: uppercase; letter-spacing: .05em; }
.lp-msg  { color: var(--clr-text-muted); font-style: italic; }
.lp-body {
  display: flex;
  gap: 0;
  flex-wrap: wrap;
}

/* On-course card */
.lp-on-course {
  padding: .6rem .9rem;
  border-right: 1px solid var(--clr-border);
  min-width: 180px;
  flex: 0 0 auto;
}
.lp-oc-label { font-size: .7rem; font-weight: 700; color: var(--clr-live); text-transform: uppercase; margin-bottom: .2rem; }
.lp-oc-bib   { font-size: .68rem; font-weight: 700; color: var(--clr-text-muted); }
.lp-oc-name  { font-size: .95rem; font-weight: 700; color: var(--clr-text); }
.lp-oc-meta  { display: flex; gap: .5rem; font-size: .75rem; color: var(--clr-text-muted); margin-top: .15rem; }
.lp-oc-time  { font-size: 1.15rem; font-weight: 700; color: var(--clr-text); margin-top: .3rem; display: flex; align-items: baseline; gap: .35rem; }
.lp-diff     { font-size: .8rem; font-weight: 600; }
.lp-diff-fast { color: #1b5e20; }
.lp-diff-slow { color: #b71c1c; }
.lp-in-gate   { opacity: .65; }
.lp-in-gate .lp-oc-label { color: var(--clr-text-muted); }

/* Last finisher bar */
.lp-last-finisher-bar {
  display:     flex;
  align-items: center;
  gap:         .45rem;
  margin:      .4rem .75rem;
  padding:     .4rem .65rem;
  border:      1px solid var(--clr-accent);
  border-radius: 6px;
  background:  var(--clr-surface);
  font-size:   .88rem;
  flex-wrap:   wrap;
  width:       calc(100% - 1.5rem);
  flex-basis:  100%;
  order:       10;
}
.lp-lf-label  { font-size: .72rem; font-weight: 700; text-transform: uppercase; color: var(--clr-text-muted); flex-shrink: 0; }
.lp-lf-rank   { font-size: .78rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--clr-accent); flex-shrink: 0; min-width: 1.4rem; }
.lp-lf-name   { font-size: .88rem; font-weight: 700; color: var(--clr-text); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lp-lf-time      { font-size: .88rem; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--clr-accent); margin-left: auto; }
.lp-lf-dnf       { border-color: #e53935; }
.lp-lf-dsq       { border-color: #ff8f00; }
.lp-lf-dnf-time  { color: #e53935 !important; }

/* Queue */
.lp-queue      { padding: .5rem .75rem; flex: 1; min-width: 200px; }
.lp-queue-label { font-size: .7rem; font-weight: 700; color: var(--clr-text-muted); text-transform: uppercase; margin-bottom: .25rem; }
.lp-queue-row  { display: flex; align-items: center; gap: .5rem; padding: .15rem 0; font-size: .8rem; color: var(--clr-text-muted); border-bottom: 1px solid var(--clr-border); }
.lp-queue-row:last-child { border-bottom: none; }
.lp-queue-first { color: var(--clr-text); font-weight: 600; }
.lp-r1pos      { font-size: .68rem; font-weight: 700; color: var(--clr-accent); min-width: 1.6rem; text-align: right; }
.lp-bib        { font-size: .7rem; color: var(--clr-text-muted); min-width: 1.8rem; text-align: right; }
.lp-queue-first .lp-bib { color: var(--clr-accent); font-weight: 700; }
.lp-qname      { flex: 1; }
.lp-nation     { font-size: 1rem; color: var(--clr-text-muted); display: inline-block; }
.lp-nation .nation-flag {
  display: inline-block;
  font-size: 1.1rem;
  line-height: 1;
}
.lp-run1       { font-size: .72rem; }
.lp-int-split  { font-size: .72rem; color: var(--clr-text-muted); margin-top: .1rem; display: flex; gap: .3rem; align-items: baseline; }
.lp-int-rank   { font-size: .68rem; font-weight: 700; color: var(--clr-accent); }
/* border-left color is set via inline style (green=P1, red=other) */
.lp-just-finished  { border-left: 3px solid transparent; }
.lp-fin-rank   { font-size: .7rem; font-weight: 700; color: #4caf50; margin-right: .1rem; }
.lp-qrun1      { font-size: .72rem; margin-left: auto; color: var(--clr-accent); }

/* ════════════════════════════════════════════════════════════════════
   MOBILE OPTIMISATIONS  (≤ 639 px)
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 639px) {

  /* ── Base ─────────────────────────────────────────────────────── */
  html { font-size: 14px; }

  /* ── Header ───────────────────────────────────────────────────── */
  .header-inner  { height: 50px; padding: 0 .9rem; }
  .app-title     { font-size: 1.1rem; }
  .app-subtitle  { display: none !important; }
  .refresh-countdown { min-width: 40px; font-size: .7rem; }

  /* ── Controls bar ─────────────────────────────────────────────── */
  .controls-inner {
    flex-direction: column;
    align-items:    stretch;
    padding:  .6rem .9rem;
    gap: .5rem;
  }
  .control-group  { align-items: center; }
  .control-label  { min-width: 58px; flex-shrink: 0; font-size: .67rem; }
  /* Prevent iOS Safari from zooming on focus */
  .race-select    { flex: 1; min-width: 0; max-width: 100%; font-size: 16px; }
  .penalty-input  { font-size: 16px; }
  .btn            { min-height: 40px; }
  .btn-outline    { flex: 1; }

  /* ── Race info banner ─────────────────────────────────────────── */
  .race-info-inner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 1rem;
    row-gap:    .35rem;
    padding:  .55rem .9rem;
  }
  .race-info-label { font-size: .58rem; }
  .race-info-value { font-size: .82rem; }

  /* ── Formula details ─────────────────────────────────────────── */
  .formula-details { padding: 0 .6rem; }
  .formula-body    { font-size: .78rem; padding: .65rem .8rem; }
  .fval-table      { font-size: .75rem; }

  /* ── Main content ─────────────────────────────────────────────── */
  .main-content { padding: 0 .45rem; margin-top: .5rem; }

  /* ── Legend ───────────────────────────────────────────────────── */
  .legend      { gap: .3rem; font-size: .7rem; }
  .legend-item { padding: .12rem .4rem; }

  /* ── Results table ────────────────────────────────────────────── */
  /*  Remove overflow:hidden so position:sticky on first column works  */
  .results-table { overflow: visible; border-radius: 0; font-size: .78rem; }

  .table-scroll {
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Scroll-shadow hint: covers fade left/right + edge shadows */
    background:
      linear-gradient(to right, var(--clr-surface) 8px, transparent 40px),
      linear-gradient(to left,  var(--clr-surface) 8px, transparent 40px) 100%,
      radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.10), transparent),
      radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.10), transparent) 100%;
    background-color: var(--clr-surface);
    background-repeat: no-repeat;
    background-size: 40px 100%, 40px 100%, 12px 100%, 12px 100%;
    background-attachment: local, local, scroll, scroll;
  }

  /* Hide least-useful columns on mobile */
  .results-table .fis-code,
  .results-table .run-split { display: none; }

  /* Compact cell padding */
  .results-table th,
  .results-table td  { padding: .4rem .42rem; }
  .results-table th  { font-size: .63rem; letter-spacing: .04em; }

  /* Sticky rank column */
  .results-table th:first-child,
  .results-table td:first-child {
    position:   sticky;
    left:       0;
    z-index:    2;
    box-shadow: 2px 0 5px rgba(0,0,0,.08);
  }
  /* Explicit bg colours so rows don't bleed through the sticky cell */
  .results-table thead th:first-child    { background: var(--clr-header-bg); }
  .results-table tbody tr td:first-child { background: var(--clr-surface); }
  .row-gold    td:first-child { background: var(--clr-gold-bg);    }
  .row-silver  td:first-child { background: var(--clr-silver-bg);  }
  .row-bronze  td:first-child { background: var(--clr-bronze-bg);  }
  .row-points  td:first-child { background: var(--clr-points-bg);  }
  .row-dnf     td:first-child { background: var(--clr-dnf-bg);     }
  .row-dsq     td:first-child { background: var(--clr-dsq-bg);     }
  .row-dns     td:first-child { background: var(--clr-dns-bg);     }

  /* Constrain athlete name column so table doesn't blow out */
  .results-table td.name {
    max-width: 120px;
    overflow:  hidden;
    text-overflow: ellipsis;
  }

  /* Compact FIS points pill */
  .pts-pill { min-width: 4rem; padding: 2px 6px; font-size: .75rem; }

  /* Results footer */
  .results-count { font-size: .7rem; }

  /* ── App footer ───────────────────────────────────────────────── */
  .app-footer {
    flex-direction: column;
    align-items:    center;
    gap:     .4rem;
    font-size: .74rem;
    padding: .6rem .9rem;
    /* Notch / home-indicator safe area on iOS */
    padding-bottom: calc(.6rem + env(safe-area-inset-bottom, 0px));
  }
}
