:root {
  --bg: #FFF7FA; --card: #FFFFFF; --ink: #17111A; --ink2: #4D4552; --ink3: #8E8594; --line: #F0E3EA;
  --accent: #E0157A; --accent-soft: #FCE4F0; --accent-ink: #FFFFFF; --ok: #1FA25A; --warn: #D98A00; --bad: #E5484D;
  --muro: #FFF0D6; --r: 18px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B0A0D; --card: #17141A; --ink: #F6F1F4; --ink2: #CFC6CD; --ink3: #8F8691; --line: #2A2430;
    --accent: #FF4FA3; --accent-soft: #3A1229; --accent-ink: #0B0A0D; --muro: #2E2410; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B0A0D; --card: #17141A; --ink: #F6F1F4; --ink2: #CFC6CD; --ink3: #8F8691; --line: #2A2430;
  --accent: #FF4FA3; --accent-soft: #3A1229; --accent-ink: #0B0A0D; --muro: #2E2410; color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 84px; }
h1, h2, h3 { margin: 0; letter-spacing: -.015em; }
p { margin: 6px 0; }
.muted { color: var(--ink3); } .small { font-size: 13.5px; } .center { text-align: center; }
.wrap { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 40px); }

.hero { padding: 8px 4px 18px; }
.eyebrow { font-size: 12.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.hero h1 { font-size: 30px; line-height: 1.12; margin: 8px 0 10px; }
.hero p { color: var(--ink2); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 16px; margin-bottom: 14px; }
.step { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step b { flex: none; width: 26px; height: 26px; border-radius: 99px; display: grid; place-items: center; font-size: 13.5px; background: var(--accent-soft); color: var(--accent); }
.step h2 { font-size: 18px; }

.kms { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.km { position: relative; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-weight: 650; font-size: 15px; font-variant-numeric: tabular-nums; }
.km.muro { background: var(--muro); }
.km.wide { grid-column: span 2; font-size: 14px; }
.km.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.km .dots { position: absolute; left: 0; right: 0; bottom: 4px; display: flex; justify-content: center; gap: 2px; }
.km .dots i { width: 4px; height: 4px; border-radius: 9px; background: var(--accent); opacity: .7; }
.km.sel .dots i { background: var(--accent-ink); }
.kmnote { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); color: var(--ink); font-size: 14.5px; min-height: 42px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12.5px; color: var(--ink3); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--muro); border: 1px solid var(--line); }
.legend span.d::before { width: 5px; height: 5px; border-radius: 9px; background: var(--accent); border: 0; vertical-align: 1px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 0 20px; border-radius: 99px; font-weight: 700; background: var(--accent); color: var(--accent-ink); width: 100%; }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn.line { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 8px; } .row > * { flex: 1; }
.rec { display: flex; flex-direction: column; gap: 10px; }
.recbig { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 16px; background: var(--bg); border: 1px solid var(--line); }
.dot-rec { width: 14px; height: 14px; border-radius: 99px; background: var(--bad); animation: pulse 1s infinite; flex: none; }
@keyframes pulse { 50% { opacity: .3; } }
.meter { flex: 1; height: 8px; border-radius: 9px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .08s; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
audio { width: 100%; height: 44px; }
.or { text-align: center; color: var(--ink3); font-size: 13px; margin: 14px 0 8px; }
.err { color: var(--bad); font-size: 14px; margin-top: 10px; }
.ok-big { text-align: center; padding: 30px 10px; }
.ok-big .emoji { font-size: 52px; }
.ok-big h2 { font-size: 26px; margin: 10px 0 6px; }
.foot { text-align: center; color: var(--ink3); font-size: 12.5px; margin-top: 18px; }

/* Modo carrera */
.pill { display: inline-block; font-size: 11.5px; font-weight: 750; letter-spacing: .05em; padding: 4px 9px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14.5px; }
.checklist li:first-child { border-top: 0; }
.checklist li > span:first-child { flex: none; }
.stat { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .k { flex: none; min-width: 58px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.list .n { flex: 1; min-width: 0; }
.iconbtn { flex: none; width: 38px; height: 38px; border-radius: 99px; display: grid; place-items: center; background: var(--bg); border: 1px solid var(--line); }
details summary { cursor: pointer; font-weight: 650; }
.race { text-align: center; padding-top: 10px; }
.race .big { font-size: 84px; font-weight: 800; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.race .unit { font-size: 22px; color: var(--ink3); font-weight: 700; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0; }
.grid3 div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; }
.grid3 b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; }
.grid3 span { font-size: 12px; color: var(--ink3); }
.now { background: var(--accent); color: var(--accent-ink); border-radius: var(--r); padding: 16px; margin-bottom: 14px; text-align: left; }
.now .lbl { font-size: 12px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; opacity: .85; }
.now .who { font-size: 22px; font-weight: 800; margin-top: 2px; }
.gps { font-size: 13px; }
.gps.ok { color: var(--ok); } .gps.warn { color: var(--warn); } .gps.bad { color: var(--bad); }
.lock { position: fixed; inset: 0; z-index: 50; background: #000; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; user-select: none; -webkit-user-select: none; touch-action: none; }
.lock .big { font-size: 96px; font-weight: 800; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.lock .hint { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 30px); color: #888; font-size: 14px; text-align: center; padding: 0 20px; }
.lock .ring { width: 74px; height: 74px; border-radius: 99px; border: 3px solid #333; display: grid; place-items: center; font-size: 26px; }
.lock .ring.hold { border-color: #FF4FA3; transition: border-color 1.5s; }
.lock .playing { color: #FF4FA3; font-weight: 700; font-size: 18px; min-height: 26px; }

/* Directo */
.live-link { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.live-link > span:first-child { font-size: 26px; }
.live-link > span:nth-child(2) { flex: 1; }
.live-link > span:last-child { font-size: 24px; color: var(--ink3); }
a.btn { text-decoration: none; }
.map { height: 380px; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); margin-bottom: 8px; background: var(--card); z-index: 0; }
.course { margin-top: 12px; }
.course summary { font-size: 14.5px; color: var(--accent); }
.course img { display: block; width: 100%; border-radius: 12px; margin-top: 10px; border: 1px solid var(--line); }
.zone { font-size: 16px; margin: 0 0 10px; text-align: center; }

.toggle { display: flex; align-items: center; gap: 10px; margin: 10px 0 4px; font-size: 15px; font-weight: 600; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.plan li { padding: 8px 0; font-size: 14px; }
.plan li.hi { background: var(--accent-soft); margin: 0 -10px; padding: 8px 10px; border-radius: 10px; border-top-color: transparent; }
.plan .h { flex: none; font-variant-numeric: tabular-nums; color: var(--ink3); font-size: 13px; }
.kmlbl { background: #fff; color: #17111A; border: 2px solid #6B7280; border-radius: 99px; font: 700 11px/1 -apple-system, system-ui, sans-serif; padding: 3px 6px; white-space: nowrap; transform: translate(-50%, -50%); }
.kmlbl.cesar { border-color: #E0157A; color: #E0157A; }
.kmlbl.end { background: #17111A; color: #fff; border-color: #17111A; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.seg button { min-height: 44px; border-radius: 11px; font-weight: 700; font-size: 14px; color: var(--ink2); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.km.taken { opacity: .45; text-decoration: line-through; cursor: not-allowed; }
.km.focus { background: var(--line); cursor: not-allowed; }
.km .tick { position: absolute; top: 2px; right: 5px; font-size: 10px; color: var(--accent); text-decoration: none; }
.legend span.t::before { background: var(--bg); opacity: .5; }
.legend span.f::before { background: var(--line); }
.laps { margin-top: 10px; }
.km.passed { opacity: .3; cursor: not-allowed; }
.warn { background: #FFF4D6; border-color: #F2D28A; color: #3A2A00; font-size: 14.5px; }
.racenow { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; color: var(--ink); }
.install summary { font-weight: 700; font-size: 16px; color: var(--ink); }
.install h4 { margin: 12px 0 4px; font-size: 14px; }
.install ol { margin: 4px 0; padding-left: 20px; font-size: 14.5px; }
.install li { margin: 4px 0; }

/* Navegación inferior */
body.has-tabbar .wrap { padding-bottom: calc(env(safe-area-inset-bottom) + 96px); }
#tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(3, 1fr); padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px); background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); }
#tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 12px; color: var(--ink3); text-decoration: none; font-size: 12px; font-weight: 700; }
#tabbar a span { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .7; }
#tabbar a.on { color: var(--accent); background: var(--accent-soft); }
#tabbar a.on span { filter: none; opacity: 1; }
.hint { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.hint summary { list-style: none; display: flex; justify-content: space-between; align-items: center; font-weight: 700; cursor: pointer; }
.hint summary::-webkit-details-marker { display: none; }
.hint .x { color: var(--ink3); font-size: 14px; padding: 2px 6px; }
.hint p { margin: 8px 0 2px; color: var(--ink2); }
.who { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.who input[type=text], .who #nombre { flex: 1; }
.who .toggle { margin: 0; flex: none; font-size: 14px; }
#msgcard textarea { margin: 12px 0; }
.laps a { color: var(--accent); }
input:disabled { opacity: .45; }
.linkbtn { color: var(--accent); font-weight: 700; text-decoration: underline; font-size: inherit; }
.kmlbl.cesar { cursor: pointer; }
