/* css/modes/race.css — Kapsejlads (js/modes/race.js). Everything is scoped to .race-* classes. */

/* ---- flag / standings panel: top-right on desktop, under the HUD on phones */
.race-panel {
  position: absolute; z-index: 21; right: calc(var(--safe-r, 0px) + 12px); top: calc(var(--safe-t) + 12px);
  width: 200px; padding: 10px 12px 10px; border-radius: 16px; color: #fff; pointer-events: none;
  background: rgba(13, 19, 33, .7); border: 1px solid var(--glass-border, rgba(255,255,255,.12));
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 8px 24px rgba(0,0,0,.28);
  animation: rpIn .5s var(--ease-pop, ease-out) both .2s;
}
.race-panel.pulse { animation: rpPulse .6s var(--ease-pop, ease-out); }
.rp-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.rp-head > span { font-size: .62rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; color: var(--primary, #ffb547); white-space: nowrap; }
.rp-clock { font-size: 1.9rem; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; letter-spacing: .02em; }
.rp-clock.hot { color: #ffd25e; animation: rpHot .5s ease-in-out infinite alternate; }
.rp-leg { font-size: 1.05rem; font-weight: 900; }
.rp-leg.beat { color: #9fe7ff; } .rp-leg.run { color: #ffd25e; } .rp-leg.reach { color: #7dffb5; } .rp-leg.done { color: var(--good, #3ee08f); }
.rp-lap { margin-top: 2px; font-size: .7rem; font-weight: 900; color: #ffd25e; letter-spacing: .04em; }
.rp-shift { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; margin-top: 4px; padding: 2px 6px; border-radius: 8px; background: rgba(255,255,255,.06); font-size: .7rem; font-weight: 800; }
.rp-shift span { color: rgba(255,255,255,.6); white-space: nowrap; }
.rp-shift b { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rp-shift.lift { background: rgba(62,224,143,.18); } .rp-shift.lift b { color: #7dffb5; }
.rp-shift.header { background: rgba(255,154,61,.2); } .rp-shift.header b { color: #ffb38a; }
.rp-flags { display: flex; gap: 8px; margin: 8px 0 6px; min-height: 40px; }
.rp-flags.x { margin: 0 0 6px; min-height: 0; }
.rp-flag { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rp-flag i { font-style: normal; font-size: .58rem; font-weight: 800; color: rgba(255,255,255,.75); white-space: nowrap; }
.rp-flag.up .race-flagsvg { animation: flagUp .6s var(--ease-pop, ease-out) both, flagWave 1.4s ease-in-out infinite .6s; transform-origin: left center; }
.rp-flag.off { opacity: .28; filter: grayscale(.7); }
.race-flagsvg { width: 42px; height: 30px; display: block; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.rp-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.rp-steps span { text-align: center; font-size: .62rem; font-weight: 900; padding: 3px 0; border-radius: 8px; background: rgba(255,255,255,.08); color: rgba(255,255,255,.5); white-space: nowrap; }
.rp-steps span.on { background: linear-gradient(180deg, #ffc65c, #ff7a3d); color: #1d2433; }
.rp-steps span.go.on { background: var(--good, #3ee08f); }
.rp-list { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.rp-row { display: flex; align-items: center; gap: 7px; font-size: .82rem; font-weight: 800; padding: 3px 6px; border-radius: 9px; background: rgba(255,255,255,.04); }
.rp-row b { width: 16px; text-align: right; font-variant-numeric: tabular-nums; color: rgba(255,255,255,.7); }
.rp-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-row.me { background: linear-gradient(90deg, rgba(255,181,71,.35), rgba(255,122,61,.15)); }
.rp-row.me b { color: #ffd25e; }
.rp-row.fin span { color: #b9ffd8; }
.race-dot { flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid rgba(255,255,255,.7); vertical-align: -1px; margin-right: 2px; }
.race-x { font-style: normal; font-size: .66rem; font-weight: 900; color: #fff; background: var(--bad, #ff4d5e); border-radius: 6px; padding: 1px 5px; }
.race-pen { font-style: normal; font-weight: 900; color: #ff9a3d; }
.race-ok { font-style: normal; font-weight: 900; color: var(--good, #3ee08f); }
.rp-pen { margin-top: 6px; font-size: .74rem; font-weight: 900; color: #ffb38a; }
.rp-pen i { display: block; height: 6px; margin-top: 3px; border-radius: 9px; background: rgba(255,255,255,.14); overflow: hidden; }
.rp-pen b { display: block; height: 100%; background: linear-gradient(90deg, #ffb547, #ff4d5e); transition: width .2s; }

/* ---- rule card (fouls / mark touch / right of way) */
.race-card {
  position: absolute; z-index: 22; left: 50%; top: calc(var(--safe-t) + 78px); transform: translate(-50%, -12px) scale(.9);
  display: flex; align-items: center; gap: 10px; max-width: min(380px, 70vw); padding: 9px 14px 9px 10px; border-radius: 16px;
  background: rgba(13, 19, 33, .82); border: 2px solid rgba(255,255,255,.15); color: #fff; pointer-events: none;
  opacity: 0; transition: opacity .25s, transform .35s var(--ease-pop, ease-out);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.race-card.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.race-card.bad { border-color: var(--bad, #ff4d5e); }
.race-card.good { border-color: var(--good, #3ee08f); }
.race-card.warn { border-color: #ffd25e; }
.rc-ico { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--bad, #ff4d5e); color: #fff; }
.race-card.good .rc-ico { background: var(--good, #3ee08f); color: #0d1321; }
.race-card.warn .rc-ico { background: #ffd25e; color: #0d1321; }
.rc-ico .ico { width: 20px; height: 20px; }
.rc-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rc-txt b { font-size: .95rem; font-weight: 900; line-height: 1.15; }
.rc-txt span { font-size: .78rem; font-weight: 800; color: #ffd25e; text-transform: uppercase; letter-spacing: .06em; }

/* ---- extra buttons: fast-forward only before the gun, penalty turn only while owed */
.play-layer.race-go .kc [data-btn="ff"] { display: none; }
.play-layer.race-layer:not(.race-pen) .kc [data-btn="turn"] { display: none; }
.play-layer.race-pen .kc [data-btn="turn"] { animation: penBtn .9s ease-in-out infinite; }
.play-layer.race-done .kc { opacity: .35; pointer-events: none; }

/* ---- live finish board */
.race-board {
  position: absolute; z-index: 25; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 32px)); max-height: calc(100% - var(--safe-t) - var(--safe-b) - 120px); display: flex; flex-direction: column; gap: 8px;
  padding: 14px 14px 12px; border-radius: 18px; color: #fff; background: rgba(13, 19, 33, .86); border: 1px solid rgba(255,255,255,.14);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); box-shadow: 0 16px 40px rgba(0,0,0,.45);
  animation: rbIn .6s var(--ease-pop, ease-out) both .5s;
}
.rb-head { display: flex; align-items: center; gap: 8px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; font-size: .78rem; color: var(--primary, #ffb547); }
.rb-head .ico { width: 18px; height: 18px; }
.rb-list { overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.rb-row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 10px; background: rgba(255,255,255,.05); font-weight: 800; font-size: .88rem; animation: rbRow .4s var(--ease-pop, ease-out) both; }
.rb-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-row em { font-style: normal; font-variant-numeric: tabular-nums; color: rgba(255,255,255,.85); }
.rb-row em small { color: rgba(255,255,255,.45); font-weight: 700; }
.rb-row.me { background: linear-gradient(90deg, rgba(255,181,71,.38), rgba(255,122,61,.16)); }
.rb-next { align-self: center; min-height: 44px; }
.race-medal { flex: none; display: inline-grid; place-items: center; min-width: 24px; height: 24px; border-radius: 50%; font-size: .78rem; font-weight: 900; background: rgba(255,255,255,.12); color: #fff; }
.pod.p1 .race-medal { background: linear-gradient(180deg, #ffe17a, #f2a81d); color: #3b2a00; box-shadow: 0 0 10px rgba(255,210,94,.6); }
.pod.p2 .race-medal { background: linear-gradient(180deg, #f1f4f8, #aeb7c4); color: #222b38; }
.pod.p3 .race-medal { background: linear-gradient(180deg, #f3b98a, #b56a35); color: #2e1606; }

/* ---- results table on the results screen */
.race-rtable { width: 100%; grid-column: 1 / -1; margin: 4px 0 2px; text-align: left; }
.race-rt-head { display: flex; align-items: center; gap: 6px; font-size: .7rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; color: var(--primary, #ffb547); margin-bottom: 4px; }
.race-rt-head .ico { width: 16px; height: 16px; }
.race-rtable table { width: 100%; border-collapse: separate; border-spacing: 0 3px; font-size: .84rem; }
.race-rtable th { font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim, rgba(255,255,255,.6)); text-align: center; padding: 0 4px; }
.race-rtable td { padding: 4px 6px; text-align: center; font-weight: 800; background: rgba(255,255,255,.05); font-variant-numeric: tabular-nums; white-space: nowrap; }
.race-rtable td:first-child { border-radius: 10px 0 0 10px; } .race-rtable td:last-child { border-radius: 0 10px 10px 0; }
.race-rtable .l { text-align: left; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.race-rtable td small { color: var(--text-dim, rgba(255,255,255,.55)); font-weight: 700; }
.race-rtable tr.me td { background: linear-gradient(90deg, rgba(255,181,71,.32), rgba(255,122,61,.14)); }
.race-rtable tr { animation: rbRow .4s var(--ease-pop, ease-out) both; }
.race-rt-series { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 6px; font-size: .82rem; font-weight: 900; color: #ffd25e; }
.race-rt-series .ico { width: 18px; height: 18px; }

@keyframes rpIn { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
@keyframes rpPulse { 0% { transform: scale(1); } 35% { transform: scale(1.07); box-shadow: 0 0 0 4px rgba(255,181,71,.45); } 100% { transform: scale(1); } }
@keyframes rpHot { from { transform: scale(1); } to { transform: scale(1.1); } }
@keyframes flagUp { from { transform: translateY(14px) scaleX(.3); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes flagWave { 0%, 100% { transform: skewY(0); } 50% { transform: skewY(-4deg) scaleX(.96); } }
@keyframes penBtn { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,77,94,.0); } 50% { box-shadow: 0 0 0 6px rgba(255,77,94,.55); } }
@keyframes rbIn { from { opacity: 0; transform: translate(-50%, -40%) scale(.85); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes rbRow { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }

/* phones (portrait): panel tucks under the HUD on the right, card on the left */
@media (max-width: 560px) {
  .race-panel { top: calc(var(--safe-t) + 128px); right: calc(var(--safe-r, 0px) + 8px); width: 148px; padding: 7px 9px; border-radius: 14px; }
  .rp-clock { font-size: 1.45rem; }
  .rp-flags { gap: 5px; margin: 5px 0 4px; min-height: 34px; }
  .race-flagsvg { width: 34px; height: 24px; }
  .rp-steps span { font-size: .55rem; }
  .rp-row { font-size: .72rem; padding: 2px 5px; gap: 5px; }
  .race-card { top: calc(var(--safe-t) + 128px); left: calc(var(--safe-l, 0px) + 8px); transform: translate(0, -12px) scale(.9); max-width: calc(100vw - 180px); padding: 7px 10px 7px 8px; }
  .race-card.show { transform: none; }
  .rc-ico { width: 28px; height: 28px; } .rc-txt b { font-size: .8rem; } .rc-txt span { font-size: .66rem; }
  .race-rtable table { font-size: .76rem; } .race-rtable .l { max-width: 120px; }
}
/* landscape phones: compact panel in the top-right corner */
@media (orientation: landscape) and (max-height: 520px) {
  .race-panel { top: calc(var(--safe-t) + 8px); width: 150px; padding: 6px 9px; }
  .rp-clock { font-size: 1.3rem; }
  .rp-flags { min-height: 0; margin: 4px 0; }
  .race-flagsvg { width: 30px; height: 21px; }
  .rp-list .rp-row:nth-child(n+4):not(.me) { display: none; }
  .race-card { top: calc(var(--safe-t) + 64px); }
}

/* ---- extra buttons (spol frem / laylines / strafrunde) sit under the pause button, clear of the flag panel */
.race-layer .kc .kc-extras,
.race-layer .kc.kc-landscape .kc-extras { right: auto; left: calc(var(--safe-l, 0px) + 12px); top: calc(var(--safe-t) + 66px); flex-direction: row; align-items: flex-start; }
.race-layer .kc .kc-extra b { display: none; }
.race-layer .kc .kc-extra { padding: 0 10px; min-width: 48px; height: 48px; }
@media (min-width: 900px) and (min-height: 600px) {
  .race-layer .kc .kc-extras { left: calc(var(--safe-l, 0px) + 12px); top: calc(var(--safe-t) + 66px); }
}
@media (max-width: 560px) and (orientation: portrait) {
  .race-layer .kc .kc-extras, .race-layer .kc.kc-landscape .kc-extras { top: calc(var(--safe-t) + 128px); left: calc(var(--safe-l, 0px) + 8px); }
  .race-card { top: calc(var(--safe-t) + 184px); }
}

/* short landscape screens: keep the finish board clear of the HUD strip and the coach bubble */
@media (max-height: 520px) {
  .race-board { top: calc(50% + 34px); max-height: calc(100% - var(--safe-b, 0px) - 96px); padding: 10px 12px; gap: 6px; }
  .rb-row { padding: 3px 8px; font-size: .82rem; }
}
.race-rtable tr.me td { background: rgba(255,181,71,.26); }
