/* Pista de atletismo: la pantalla entera es el color del tramo y se vacía con el tiempo;
   abajo, un carril por ronda (8 carriles = 8 rondas). Se lee a tres metros. */
@font-face { font-family: "Sofia XC"; src: url(fonts/sofia-xc-800.woff2) format("woff2"); font-weight: 800; font-display: swap; }
:root {
  --tartan: #b9361f; --tartan-h: #8f2614;
  --agua: #1b6596;   --agua-h: #124a70;
  --tiza: #f0b429;   --tiza-h: #d1960f;
  --fondo: #eceff1; --placa: #fff; --tinta: #16212b; --tenue: #566572; --linea: #cdd5da;
  --num: "Sofia XC", "Avenir Next Condensed", "Arial Narrow", sans-serif;
  --txt: -apple-system, system-ui, "Segoe UI", sans-serif;
  --izq: max(20px, env(safe-area-inset-left, 0px));
  --der: max(20px, env(safe-area-inset-right, 0px));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --fondo: #111a22; --placa: #1b2731; --tinta: #eaf0f3; --tenue: #9db0bd; --linea: #33434f; color-scheme: dark; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--fondo); }
html[data-corre] { overflow: hidden; }
html[data-corre="work"] { background: var(--tartan-h); }
html[data-corre="rest"], html[data-corre="setRest"], html[data-corre="fin"] { background: var(--agua-h); }
html[data-corre="prep"] { background: var(--tiza-h); }
body { margin: 0; font: 17px/1.4 var(--txt); color: var(--tinta); background: transparent; overscroll-behavior: none; }
p, h1, h2, ol, fieldset { margin: 0; padding: 0; border: 0; list-style: none; }
button, input, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; -webkit-user-select: none; user-select: none; }
:focus-visible { outline: 3px solid var(--tiza); outline-offset: 2px; }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

/* ---- armado ---- */
#armado { max-width: 620px; margin: 0 auto; padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px)); }
#armado::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); background: var(--tartan); z-index: 5; }
.tapa { background: var(--tartan); color: #fff; padding: calc(env(safe-area-inset-top, 0px) + 18px) var(--der) 20px var(--izq); }
.tapa h1 { font-size: 20px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.total { font: 800 132px/.86 var(--num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; margin: 10px 0 14px; }
#tira { display: block; width: 100%; height: 28px; }
#tira .work { fill: #fff; }
#tira .rest, #tira .setRest { fill: #7fc0ea; }
#tira .prep { fill: var(--tiza); }
.resumen { margin-top: 10px; font-size: 15px; }
.cuerpo { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; padding: 22px var(--der) 0 var(--izq); }
.titulo { display: block; font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.ayuda { font-size: 15px; color: var(--tenue); margin-top: 8px; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 calc(-1 * var(--der)) 0 calc(-1 * var(--izq)); padding: 3px var(--der) 3px var(--izq); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; min-height: 44px; padding: 0 16px; border: 1.5px solid var(--linea); border-radius: 6px; background: var(--placa); font-size: 16px; }
.chips button[aria-pressed="true"] { background: var(--tinta); border-color: var(--tinta); color: var(--fondo); }

.campos { display: grid; border-top: 1px solid var(--linea); }
.campo { display: grid; grid-template-columns: minmax(0, 1fr) 52px 74px 52px; align-items: center; min-height: 68px; border-bottom: 1px solid var(--linea); }
.campo label { padding-right: 8px; line-height: 1.25; }
.campo small { display: block; font-size: 14px; color: var(--tenue); }
.campo button { width: 52px; height: 52px; border: 0; border-radius: 6px; background: var(--placa); font: 400 28px/1 var(--txt); padding: 0; }
.campo button:active { background: var(--linea); }
.campo button:disabled { opacity: .3; }
.campo input { width: 100%; height: 52px; border: 0; background: none; text-align: center; font: 800 40px/1 var(--num); font-variant-numeric: tabular-nums; padding: 0; border-radius: 6px; }

textarea, input[id="nombreNuevo"] { width: 100%; border: 1.5px solid var(--linea); border-radius: 6px; background: var(--placa); padding: 12px 14px; font-size: 17px; resize: vertical; display: block; }
::placeholder { color: var(--tenue); opacity: 1; }
.fila { display: flex; flex-wrap: wrap; gap: 10px; }
.btn { min-height: 48px; padding: 0 18px; border: 1.5px solid var(--linea); border-radius: 6px; background: var(--placa); }
.btn.fuerte { background: var(--tinta); border-color: var(--tinta); color: var(--fondo); font-weight: 600; }
.aviso { background: var(--placa); border-radius: 6px; padding: 16px; display: grid; gap: 14px; }
.aviso .titulo { margin: 0; }

.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid var(--linea); border-radius: 6px; overflow: hidden; background: var(--placa); }
.seg label { position: relative; display: grid; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; width: 100%; height: 100%; }
.seg span { display: grid; place-items: center; min-height: 48px; padding: 6px 10px; text-align: center; font-size: 16px; line-height: 1.2; }
.seg input:checked + span { background: var(--tinta); color: var(--fondo); }
.seg input:focus-visible + span { outline: 3px solid var(--tiza); outline-offset: -3px; }
.llave { display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 56px; margin: 8px 0; }
.llave input { appearance: none; -webkit-appearance: none; flex: none; width: 54px; height: 32px; border-radius: 16px; background: var(--linea); position: relative; margin: 0; transition: background .15s; }
.llave input::after { content: ""; position: absolute; width: 26px; height: 26px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform .15s; }
.llave input:checked { background: var(--agua); }
.llave input:checked::after { transform: translateX(22px); }

.semana { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.semana li { display: grid; place-items: center; height: 48px; border-radius: 6px; background: var(--placa); color: var(--tenue); font-size: 15px; position: relative; }
.semana li.hoy { box-shadow: inset 0 0 0 2px var(--tinta); color: var(--tinta); }
.semana li.hecho { background: var(--tartan); color: #fff; font-weight: 600; }

.pie { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px var(--der) calc(12px + env(safe-area-inset-bottom, 0px)) var(--izq); background: var(--fondo); border-top: 1px solid var(--linea); }
.empezar { display: block; width: 100%; max-width: 580px; margin: 0 auto; min-height: 64px; border: 0; border-radius: 6px; background: var(--tartan); color: #fff; font: 800 38px/1 var(--num); }
.empezar:active { background: var(--tartan-h); }

/* ---- corrida ---- */
#corrida, #final {
  position: fixed; inset: 0; color: #fff; display: flex; flex-direction: column; overflow: hidden;
  -webkit-user-select: none; user-select: none;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) var(--der) calc(env(safe-area-inset-bottom, 0px) + 14px) var(--izq);
}
@media (display-mode: standalone) { #corrida, #final { bottom: auto; height: 100vh; } }
#corrida { background: var(--h); }
#corrida[data-tipo="work"] { --c: var(--tartan); --h: var(--tartan-h); }
#corrida[data-tipo="rest"], #corrida[data-tipo="setRest"] { --c: var(--agua); --h: var(--agua-h); }
#corrida[data-tipo="prep"] { --c: var(--tiza); --h: var(--tiza-h); color: #16212b; }
#nivel { position: absolute; inset: 0; background: var(--c); transform-origin: bottom; will-change: transform; }
#corrida > :not(#nivel):not(.confirma) { position: relative; }
.arriba { display: flex; justify-content: space-between; align-items: center; }
#restaTotal { font: 800 40px/1 var(--num); font-variant-numeric: tabular-nums; }
.chico { min-height: 44px; padding: 0 16px; border: 2px solid currentColor; border-radius: 6px; background: none; font-size: 16px; font-weight: 600; }
.centro { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
#fase { font: 800 clamp(44px, 9vmax, 84px)/1 var(--num); }
#cuenta { --t: min(126vw, 50vh); font: 800 var(--t)/.86 var(--num); font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin: .04em 0 .06em; }
#cuenta.largo { font-size: calc(var(--t) * .58); line-height: 1.3; }
#detalle { font-size: 22px; font-weight: 600; min-height: 1.4em; overflow-wrap: anywhere; line-height: 1.25; }
#carriles { display: flex; height: 64px; border-left: 2px solid currentColor; margin-bottom: 14px; }
#carriles li { flex: 1; min-width: 0; border-right: 2px solid currentColor; position: relative; display: grid; place-items: center; font: 800 28px/1 var(--num); overflow: hidden; }
#carriles.apretado li { font-size: 0; border-right-width: 1px; }
#carriles li::before { content: ""; position: absolute; inset: 0; background: #fff; transform: scaleY(var(--p, 0)); transform-origin: bottom; }
#carriles li span { position: relative; }
#carriles li.hecha span, #carriles li.media span { color: #16212b; }
#carriles li.hecha::before { transform: none; }
.mandos { display: grid; grid-template-columns: 84px 1fr 84px; gap: 10px; }
.mandos button, .confirma button { min-height: 84px; border: 0; border-radius: 6px; background: rgb(0 0 0 / .28); color: #fff; font: 800 36px/1 var(--num); display: grid; place-items: center; }
#corrida .mandos svg { width: 36px; fill: currentColor; }
#corrida #pausa { background: #fff; color: #16212b; }
.mandos button:active { opacity: .75; }
.confirma { position: absolute; inset: 0; background: #16212b; color: #fff; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 24px var(--der) 24px var(--izq); }
.confirma p { font: 800 46px/1 var(--num); margin-bottom: 16px; text-wrap: balance; }
.confirma button { background: rgb(255 255 255 / .16); }
.confirma #seguir { background: #fff; color: #16212b; }

#final { background: var(--agua-h); justify-content: center; gap: 12px; }
#final h2 { font: 800 min(44vw, 40vh)/.86 var(--num); }
#final p { font-size: 22px; font-weight: 600; }
#final .mandos { grid-template-columns: 1fr 1fr; margin-top: 28px; }
#final #otraVez { background: #fff; color: #16212b; }

@media (orientation: landscape) and (max-height: 520px) {
  .total { font-size: 84px; }
  #corrida { padding-top: 8px; padding-bottom: 8px; }
  #corrida .centro { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; column-gap: 24px; }
  #cuenta { --t: 50vh; grid-column: 2; grid-row: 1 / 3; align-self: center; }
  #fase { align-self: end; }
  #detalle { align-self: start; }
  #carriles { height: 34px; margin-bottom: 8px; }
  #carriles li { font-size: 20px; }
  .mandos button, .confirma button { min-height: 52px; }
  #corrida .mandos svg { width: 28px; }
  #final { gap: 6px; }
  #final .mandos { margin-top: 12px; }
}
@media (max-height: 600px) and (orientation: portrait) {
  #carriles { height: 44px; }
  .mandos button { min-height: 64px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
