/* CronusDex — pantalla de cronometraje de boxes.
   Barra superior fija, marcador de pilotos, formulario por pasos a la izquierda y tablas a la derecha; una columna en móvil.
   Oscuro por defecto (grafito con acento verde); claro si el sistema lo pide. */
:root {
  --bg: #eef1f4;
  --bg-glow: rgba(11, 138, 76, 0.08);
  --bar: rgba(255, 255, 255, 0.86);
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --sunk: #f1f3f6;
  --ink: #12161c;
  --ink-2: #2b323c;
  --muted: #5d6775;
  --line: #e1e6eb;
  --line-2: #cdd4dc;
  --accent: #0b8a4c;
  --accent-hover: #097a43;
  --accent-soft: rgba(11, 138, 76, 0.10);
  --accent-ink: #ffffff;
  --gold: #a07800;
  --gold-soft: rgba(201, 154, 0, 0.12);
  --good: #1f7a3a;
  --danger: #c0302b;
  --danger-soft: rgba(192, 48, 43, 0.08);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.12);
  --focus: rgba(11, 138, 76, 0.35);
  /* Colores de clase como en el juego */
  --cls-D: #3aa6c9; --cls-C: #d4a90f; --cls-B: #e07a1f; --cls-A: #d43c2c;
  --cls-S1: #8a4fd0; --cls-S2: #2f5fd6; --cls-R: #c2367d; --cls-X: #2f9a52;
  --font-display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --font-body: "Barlow", "Segoe UI", system-ui, sans-serif;
  --font-time: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0f13;
    --bg-glow: rgba(34, 224, 122, 0.08);
    --bar: rgba(14, 18, 23, 0.82);
    --surface: #141920;
    --surface-2: #181e26;
    --sunk: #0f1318;
    --ink: #eef1f5;
    --ink-2: #c9d0da;
    --muted: #8a94a3;
    --line: #222932;
    --line-2: #2f3743;
    --accent: #22e07a;
    --accent-hover: #4ae894;
    --accent-soft: rgba(34, 224, 122, 0.12);
    --accent-ink: #04140b;
    --gold: #f2c94c;
    --gold-soft: rgba(242, 201, 76, 0.12);
    --good: #4cc274;
    --danger: #ff6b66;
    --danger-soft: rgba(255, 107, 102, 0.10);
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
    --focus: rgba(34, 224, 122, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1100px 420px at 50% -180px, var(--bg-glow), transparent 70%) no-repeat, var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.time { font-family: var(--font-time); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
::selection { background: var(--accent-soft); }

/* ───── Tipografía ───── */
h1 {
  margin: 0; font-family: var(--font-display); font-style: italic; font-weight: 700;
  font-size: clamp(32px, 6vw, 44px); line-height: 1; letter-spacing: -0.005em; text-transform: uppercase; text-wrap: balance;
}
h2 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 18px; text-transform: uppercase; letter-spacing: 0.05em; }
h3 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 19px; text-transform: uppercase; letter-spacing: 0.03em; }
h4 { margin: 6px 0 0; font-family: var(--font-display); font-weight: 700; font-size: 16px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
label, .label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }

/* ───── Controles ───── */
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="search"], select {
  width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--sunk); transition: border-color .15s, box-shadow .15s, background .15s;
}
select { padding-right: 34px; appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a94a3' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
input::placeholder { color: var(--muted); opacity: .75; }
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--focus); background: var(--surface); }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 16px; border: 1px solid transparent; border-radius: var(--r-sm); cursor: pointer;
  background: var(--ink); color: var(--bg);
  font-family: var(--font-display); font-weight: 700; font-size: 17px; text-transform: uppercase; letter-spacing: 0.07em;
  transition: background .15s, transform .05s, box-shadow .15s, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px -8px var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.lg { height: 50px; font-size: 19px; width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-2); }
.btn.ghost:hover { border-color: var(--muted); background: var(--sunk); }
.btn.small { height: 34px; padding: 0 12px; font-size: 14px; }
.btn.google { background: var(--surface); color: var(--ink); border-color: var(--line-2); font-family: var(--font-body); text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 15px; }
.btn.google:hover { border-color: var(--muted); }
.iconbtn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: transparent; color: var(--muted); cursor: pointer; }
.iconbtn:hover { color: var(--ink); border-color: var(--muted); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; cursor: pointer; font-size: 13px; justify-self: start; }
.linkbtn:hover { color: var(--accent); text-decoration-color: currentColor; }
.linkbtn.center { justify-self: center; }
.field { display: grid; gap: 6px; min-width: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 12.5px; color: var(--muted); min-height: 1.2em; }
.hint.err, .err { color: var(--danger); }
.msg { padding: 10px 12px; border-radius: var(--r-sm); font-size: 14px; border: 1px solid var(--line); background: var(--sunk); }
.msg.err { background: var(--danger-soft); border-color: var(--danger); color: var(--ink); }
.msg.ok { border-color: var(--good); }
.timein { font-family: var(--font-time); font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
input.timein.big { height: 64px; font-size: 34px; text-align: center; letter-spacing: 0.01em; background: var(--sunk); }

/* ───── Paneles ───── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); min-width: 0; box-shadow: var(--shadow); }
.panel-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.panel-b { padding: 18px; display: grid; gap: 16px; }

/* Control segmentado (acceso y pestañas) */
.seg { display: flex; gap: 4px; padding: 4px; background: var(--sunk); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; border: 0; background: none; height: 36px; padding: 0 14px; border-radius: 7px; cursor: pointer; color: var(--muted);
  font-family: var(--font-display); font-weight: 700; font-size: 16px; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
  transition: background .15s, color .15s;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.tabs-h { padding: 10px; }
.tabs-h .seg { width: 100%; }

/* ───── Marca ───── */
.mark { display: block; flex: none; border-radius: 11px; }
.mark.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.94); opacity: .75; } }

/* ───── Acceso ───── */
.auth {
  max-width: 440px; margin: 0 auto; display: grid; gap: 22px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(8vh, 32px) 48px;
}
.auth-brand { display: grid; justify-items: center; text-align: center; gap: 12px; }
.auth-brand .lead { margin: 0; color: var(--muted); max-width: 36ch; }
.auth-card { box-shadow: var(--shadow-lg); overflow: hidden; }
.auth-card .seg { margin: 14px 18px 0; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.setup { max-width: 640px; margin: 6vh auto 0; }
.setup code { font-family: var(--font-time); font-size: 13px; background: var(--sunk); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.setup ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

/* ───── Estructura: menú lateral + contenido (escritorio) / cabecera + barra inferior (móvil) ───── */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 248px; z-index: 20;
  display: flex; flex-direction: column; gap: 22px;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 14px calc(16px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px));
  background: var(--surface); border-right: 1px solid var(--line);
}
.sidebar .brand { padding: 0 6px; }
.sidebar .brand-name { font-size: 20px; }
.side-nav { display: grid; gap: 2px; }
.side-nav a {
  display: flex; align-items: center; gap: 12px; height: 42px; padding: 0 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 15px; transition: background .15s, color .15s;
}
.side-nav a svg { flex: none; }
.side-nav a:hover { background: var(--sunk); color: var(--ink); }
.side-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.side-nav a[aria-current="page"]::after { content: ""; margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.side-user { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.side-user:hover, .side-user[aria-current="page"] { background: var(--sunk); }
.side-user .avatar { width: 34px; height: 34px; font-size: 17px; }
.side-user-txt { display: grid; min-width: 0; line-height: 1.2; }
.side-user-txt strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.side-user-txt small { color: var(--muted); font-size: 12px; }
.content { margin-left: 248px; min-width: 0; }

.bottombar { display: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.avatar-btn { display: inline-flex; border-radius: 50%; }
.avatar-btn .avatar { width: 32px; height: 32px; font-size: 16px; }

/* Páginas */
.page { display: grid; gap: 18px; min-width: 0; animation: rise .2s ease-out; }
.page-h { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.page-title { font-size: clamp(30px, 4vw, 40px); }
.page-sub { margin: 6px 0 0; color: var(--muted); }
.page-select { width: auto; min-width: 200px; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 22px; align-items: start; }
#homeNear .near-row:first-child { padding-top: 0; }
#homeNear .near-row:last-child { padding-bottom: 0; }
#homeNear > p { margin: 0; }

/* Inicio: botón "Nuevo tiempo" (arriba en escritorio, flotante en el móvil) */
.new-lap { gap: 8px; padding-inline: 18px 20px; }
.fab { display: none; }
@media (max-width: 900px) {
  .page-h .new-lap { display: none; }
  .fab {
    display: grid; place-items: center; position: fixed; z-index: 40; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    width: 60px; height: 60px; border: 0; border-radius: 50%; cursor: pointer; color: var(--accent-ink); background: var(--accent);
    box-shadow: 0 10px 28px -6px var(--accent), 0 2px 6px rgba(0, 0, 0, .3); transition: transform .15s;
  }
  .fab:active { transform: scale(.92); }
  #panel-home { padding-bottom: 76px; }
}

/* Aviso al guardar un tiempo */
.lap-result {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 14px; align-items: center; padding: 14px 16px;
  border: 1px solid var(--line-2); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow); animation: pop .35s cubic-bezier(.2, 1.4, .4, 1);
}
.lr-ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--sunk); color: var(--muted); }
.lr-txt { display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.lr-txt strong { font-family: var(--font-display); font-size: 22px; line-height: 1.1; text-transform: uppercase; letter-spacing: .02em; }
.lr-txt span { font-size: 14px; color: var(--muted); }
.lr-time { font-size: 20px; font-weight: 700; }
.lr-x { font-size: 20px; line-height: 1; border: 0; }
.lap-result.steal { border-color: var(--accent); background: linear-gradient(100deg, var(--accent-soft), transparent 70%), var(--surface); }
.lap-result.steal .lr-ico { background: var(--accent); color: var(--accent-ink); }
.lap-result.steal strong { color: var(--accent); }
.lap-result.record { border-color: color-mix(in srgb, var(--gold) 60%, var(--line)); background: linear-gradient(100deg, var(--gold-soft), transparent 70%), var(--surface); }
.lap-result.record .lr-ico { background: var(--gold-soft); color: var(--gold); }
.lap-result.record strong { color: var(--gold); }
.lap-result.tie .lr-ico, .lap-result.pb .lr-ico { background: var(--accent-soft); color: var(--accent); }
@keyframes pop { from { transform: scale(.96) translateY(6px); opacity: 0; } }
@media (max-width: 600px) {
  .lap-result { grid-template-columns: auto minmax(0, 1fr) auto; padding: 12px; gap: 10px 12px; }
  .lr-time { grid-column: 2; grid-row: 2; font-size: 17px; }
  .lr-x { grid-column: 3; grid-row: 1; }
  .lr-ico { width: 40px; height: 40px; }
  .lr-txt strong { font-size: 19px; }
}

/* Hoja "Nuevo tiempo": panel a la derecha en escritorio, desde abajo en el móvil */
.sheet {
  position: fixed; inset: 0 0 0 auto; margin: 0; width: min(520px, 100vw); height: 100dvh; max-height: 100dvh; max-width: 100vw; padding: 0;
  border: 0; border-left: 1px solid var(--line-2); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
  flex-direction: column; overflow: hidden;
}
.sheet[open] { display: flex; animation: slide-l .25s cubic-bezier(.2, .8, .3, 1); }
.sheet::backdrop { background: rgba(5, 7, 10, .55); backdrop-filter: blur(2px); }
.sheet-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex: none;
  background: linear-gradient(90deg, var(--accent-soft), transparent 60%), var(--surface); }
.sheet-h h2 { font-size: 24px; }
.sheet-b { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 16px; align-content: start; }
@keyframes slide-l { from { transform: translateX(40px); opacity: 0; } }
@keyframes slide-u { from { transform: translateY(60px); opacity: 0; } }
@media (max-width: 600px) {
  .sheet { inset: auto 0 0 0; width: 100vw; height: auto; max-height: 94dvh; border-left: 0; border-top: 1px solid var(--line-2); border-radius: 18px 18px 0 0; }
  .sheet[open] { animation-name: slide-u; }
  .sheet-h { padding: 12px 14px; }
  .sheet-b { padding-inline: 14px; }
}

/* Atajos "Repetir" dentro de la hoja */
.repeat { display: grid; gap: 8px; padding-bottom: 16px; border-bottom: 1px dashed var(--line-2); }
.repeat .step-h::before { content: "↻"; counter-increment: none; font-size: 15px; }
.rep-list { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.rep {
  flex: 0 0 auto; max-width: 210px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: center; text-align: left;
  padding: 9px 11px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--surface-2); color: var(--ink); cursor: pointer; font: inherit;
  transition: border-color .15s, background .15s;
}
.rep:hover { border-color: var(--accent); background: var(--accent-soft); }
.rep strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rep .rep-car { grid-column: 1; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rep .pi { grid-column: 2; grid-row: 1 / span 2; }
.home-side { display: grid; gap: 10px; min-width: 0; }
.home-side .section-h { margin: 0; }
.home-side .board { grid-template-columns: minmax(0, 1fr); }
.narrow { max-width: 520px; }
#duelBody > .scroll, #statsBody > .scroll { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
#statsBody > .bars, #duelBody > .empty, .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card > h3 { margin-bottom: 12px; }
/* Inicio: "Desde tu última visita" */
.home-sum .stat .v small { font-size: .5em; }
.news-card.alert { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); box-shadow: inset 3px 0 0 var(--accent), var(--shadow); }
.news-h { display: flex; align-items: baseline; gap: 6px 12px; flex-wrap: wrap; margin-bottom: 4px; }
.news-h h3 { margin: 0; }
.news-h .muted { font-size: 13px; }
.news-h .linkbtn { margin-left: auto; }
.news-t { margin: 12px 0 2px; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.news-t.lost { color: var(--accent); }
.news-none, .news-foot { margin: 8px 0 0; font-size: 13.5px; }
.news .feed-row .race-btn { grid-column: 2 / -1; justify-self: start; margin-top: 0; }
.news .feed-row.back .time:first-child { text-decoration: line-through; color: var(--muted); }

/* Cara a cara */
.duel-hero {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px 16px; padding: 20px 22px;
  background: radial-gradient(400px 140px at 50% 0, var(--accent-soft), transparent 70%), var(--surface);
}
.dh-side { display: flex; align-items: center; gap: 12px; min-width: 0; }
.dh-side.right { justify-content: flex-end; text-align: right; }
.dh-side .muted { font-size: 13px; }
.dh-name { font-family: var(--font-display); font-weight: 700; font-size: 22px; text-transform: uppercase; letter-spacing: .02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dh-score { font-family: var(--font-display); font-weight: 700; font-size: 56px; line-height: 1; white-space: nowrap; }
.tug { grid-column: 1 / -1; height: 10px; border-radius: 999px; overflow: hidden; display: flex; gap: 2px; background: var(--sunk); }
.tug i { display: block; height: 100%; }
.tug i:last-child { flex: 1; }
.dh-foot { grid-column: 1 / -1; text-align: center; color: var(--ink-2); font-weight: 600; }
.duel-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.splits { display: grid; gap: 10px; }
.split { display: grid; grid-template-columns: minmax(90px, 150px) minmax(0, 1fr) auto; gap: 12px; align-items: center; font-size: 14px; }
.split .lbl { display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.split .track { height: 10px; border-radius: 999px; overflow: hidden; display: flex; gap: 2px; background: var(--sunk); }
.split .track i { display: block; height: 100%; }
.split .n { font-family: var(--font-display); font-weight: 700; font-size: 17px; white-space: nowrap; }
.feed { display: grid; }
.feed-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.feed-row:last-child { border-bottom: 0; }
.feed-row .avatar { width: 30px; height: 30px; font-size: 15px; box-shadow: none; }
.feed-row .what { display: grid; gap: 3px; min-width: 0; font-size: 14px; }
.feed-row .sub { color: var(--muted); font-size: 12.5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.feed-t { display: grid; justify-items: end; gap: 2px; font-size: 13px; }
.feed-t .time:first-child { font-weight: 700; font-size: 15px; }
@media (max-width: 600px) {
  .duel-hero { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); padding: 16px 14px; gap: 10px; }
  .dh-side { flex-direction: column; text-align: center; gap: 6px; }
  .dh-side.right { flex-direction: column-reverse; text-align: center; }
  .dh-name { font-size: 18px; }
  .dh-score { font-size: 42px; }
  .split { grid-template-columns: 1fr auto; }
  .split .track { grid-column: 1 / -1; grid-row: 2; }
}
#statsBody > .empty { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
#statsBody > h4, #duelBody > h4 { margin: 8px 0 -6px; }
#duelBody > p { margin: -6px 0 0; }

@media (max-width: 960px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .home-side .board { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}
@media (min-width: 901px) { .topbar { display: none; } }
@media (max-width: 900px) {
  .sidebar { display: none; }
  .content { margin-left: 0; }
  /* En móvil la navegación va arriba, fija bajo la cabecera (abajo la tapaba la etiqueta de Netlify) */
  .bottombar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; top: calc(61px + env(safe-area-inset-top, 0px)); z-index: 19;
    padding: 4px max(6px, env(safe-area-inset-right, 0px)) 4px max(6px, env(safe-area-inset-left, 0px));
    background: var(--bar); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .bottombar a {
    position: relative; display: grid; justify-items: center; gap: 2px; padding: 5px 2px 7px;
    color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; -webkit-tap-highlight-color: transparent;
  }
  .bottombar a svg { width: 20px; height: 20px; }
  .bottombar a[aria-current="page"] { color: var(--accent); }
  .bottombar a[aria-current="page"]::after { content: ""; position: absolute; left: 22%; right: 22%; bottom: -5px; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); }
  .content .wrap { padding-top: 84px; }
  .page-select { width: 100%; }
}

/* ───── Barra superior ───── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bar); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-in {
  max-width: 1200px; margin: 0 auto; height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { font-family: var(--font-display); font-style: italic; font-weight: 700; font-size: 22px; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dex { color: var(--accent); }
.brand-tag {font-family: var(--font-display); font-weight: 700; font-size: 12px; letter-spacing: .08em; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted); }
.me { display: flex; align-items: center; gap: 8px; flex: none; }
.me-chip { padding: 4px 10px 4px 4px; border-radius: 999px; background: var(--sunk); border: 1px solid var(--line); font-size: 14px; max-width: 160px; }
@media (max-width: 560px) {
  .brand-name { font-size: 19px; }
  .brand-tag, .me-chip > span:last-child { display: none; }
  .me-chip { padding: 3px; }
}

/* ───── Avatares ───── */
.avatar {
  --c: var(--muted);
  width: 26px; height: 26px; border-radius: 50%; flex: none; display: inline-grid; place-items: center;
  background: var(--c); color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 14px; line-height: 1;
  box-shadow: 0 0 0 2px var(--surface);
}
.avatar.lg { width: 44px; height: 44px; font-size: 22px; }
.avatar.md { width: 40px; height: 40px; font-size: 19px; }
.avatar.xl { width: 88px; height: 88px; font-size: 40px; }
.avatar.has-photo { background-size: cover; background-position: center; background-color: var(--c); }
.avatar[data-user], .who-chip[data-user], .pilot[data-user] { cursor: pointer; }
.who-chip[data-user]:hover > span:last-child { text-decoration: underline; text-underline-offset: 3px; }

/* Marcos: un anillo alrededor del avatar (técnica de máscara para que el centro quede libre) */
.avatar[data-frame] { position: relative; box-shadow: none; }
.avatar[data-frame]::before {
  content: ""; position: absolute; inset: -4px; border-radius: 50%; padding: 3px; pointer-events: none;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}
.avatar.lg[data-frame]::before, .avatar.md[data-frame]::before { inset: -5px; padding: 4px; }
.avatar.xl[data-frame]::before { inset: -7px; padding: 6px; }
.avatar[data-frame="bronze"]::before { background: conic-gradient(#8a4b22, #d99a6c, #8a4b22, #c4794a, #8a4b22); }
.avatar[data-frame="silver"]::before { background: conic-gradient(#8e98a5, #f2f5f8, #8e98a5, #d7dde4, #8e98a5); }
.avatar[data-frame="gold"]::before { background: conic-gradient(#a57a00, #ffe27a, #a57a00, #f5c518, #a57a00); }
.avatar[data-frame="checker"]::before { background: repeating-conic-gradient(#f4f4f4 0 25%, #111 0 50%) 0 0 / 8px 8px; }
.avatar[data-frame="carbon"]::before { background: repeating-linear-gradient(45deg, #1b1f24 0 3px, #3a414b 3px 6px); box-shadow: inset 0 0 0 1px #5d6672; }
.avatar[data-frame="fire"]::before { background: conic-gradient(#ff3d00, #ffb300, #ff6d00, #ffd54f, #ff3d00); animation: spin 3s linear infinite; }
.avatar[data-frame="neon"]::before { background: conic-gradient(#00e5ff, #d500f9, #00e676, #ffea00, #00e5ff); filter: drop-shadow(0 0 4px #00e5ff); animation: spin 5s linear infinite; }
.avatar[data-frame="crown"]::before { background: conic-gradient(#ffe27a, #f5c518, #fff6c9, #c99a00, #ffe27a); filter: drop-shadow(0 0 5px rgba(245, 197, 24, .7)); }
.avatar[data-frame="crown"]::after { content: "♛"; position: absolute; top: -0.85em; left: 50%; transform: translateX(-50%); font-size: .55em; color: #f5c518; text-shadow: 0 1px 2px rgba(0,0,0,.5); line-height: 1; }
@keyframes spin { to { transform: rotate(1turn); } }
.rank .avatar[data-frame]::before, .lap .avatar[data-frame]::before, td .avatar[data-frame]::before, .who-chip .avatar[data-frame]::before { inset: -3px; padding: 2px; }
.who-chip { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; vertical-align: middle; }
.who-chip > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .avatar, .lap .avatar, td .avatar { width: 20px; height: 20px; font-size: 12px; box-shadow: none; }

/* ───── Contenido ───── */
.wrap {
  max-width: 1180px; margin: 0 auto; display: grid; gap: 22px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 30px 56px;
}
.section-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.section-h .muted { font-size: 13px; }

/* Marcador */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.board .pilot {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 14px 18px 14px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.board .pilot::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--c); }
.board .pilot.lead { border-color: color-mix(in srgb, var(--gold) 55%, var(--line)); background: linear-gradient(90deg, var(--gold-soft), transparent 60%), var(--surface); }
.board .pos-n { font-family: var(--font-display); font-weight: 700; font-size: 15px; color: var(--muted); width: 14px; text-align: center; }
.board .pinfo { min-width: 0; }
.board .name { font-family: var(--font-display); font-weight: 700; font-size: 21px; text-transform: uppercase; letter-spacing: .02em; display: flex; align-items: center; gap: 6px; min-width: 0; }
.board .name { overflow: hidden; white-space: nowrap; }
.board .sub { color: var(--muted); font-size: 13px; }
.board .big { font-family: var(--font-display); font-weight: 700; font-size: 44px; line-height: .9; text-align: right; display: grid; justify-items: end; }
.board .big small { font-family: var(--font-body); font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.you, .leader { font-family: var(--font-body); font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 2px 6px; border-radius: 999px; flex: none; }
.you { background: var(--sunk); color: var(--muted); border: 1px solid var(--line); }
.leader { background: var(--gold-soft); color: var(--gold); border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent); }
.empty-board { grid-column: 1 / -1; display: grid; gap: 2px; padding: 18px; border: 1px dashed var(--line-2); border-radius: var(--r-lg); color: var(--muted); background: var(--surface); }
.empty-board strong { color: var(--ink); font-family: var(--font-display); font-size: 18px; text-transform: uppercase; letter-spacing: .04em; }

/* Rejilla principal */
.main { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 22px; align-items: start; }
.side { position: sticky; top: calc(76px + env(safe-area-inset-top, 0px)); }
@media (max-width: 960px) { .main { grid-template-columns: minmax(0, 1fr); } .side { position: static; } }

.tabpanel { padding: 4px 18px 18px; display: grid; gap: 16px; min-width: 0; }
.tabpanel > *, #duelBody, #statsBody { min-width: 0; display: grid; gap: 16px; }
@media (max-width: 600px) { .tabpanel { padding: 4px 12px 14px; } }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar > * { flex: 1 1 180px; min-width: 0; }
.toolbar > .toggle, .toolbar > .btn { flex: 0 0 auto; }
.toggle { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; font-weight: 500; text-transform: none; letter-spacing: 0; cursor: pointer; white-space: nowrap; color: var(--ink-2); }

/* ───── Formulario por pasos ───── */
.steps { counter-reset: step; gap: 20px; }
.step { display: grid; gap: 10px; min-width: 0; }
.step-h { display: flex; align-items: center; gap: 10px; }
.step-h, .step-h label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--ink-2); }
.step-h::before {
  counter-increment: step; content: counter(step);
  width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-family: var(--font-display); font-size: 14px; letter-spacing: 0;
}
.step + .step { padding-top: 18px; border-top: 1px solid var(--line); }

.kinds { display: flex; flex-wrap: wrap; gap: 6px; }
.kind-btn {
  height: 32px; padding: 0 11px; border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; cursor: pointer;
  font-family: var(--font-display); font-weight: 700; font-size: 14.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2);
  transition: background .15s, border-color .15s, color .15s;
}
.kind-btn:hover { border-color: var(--muted); color: var(--ink); }
.kind-btn span { color: var(--muted); font-weight: 600; margin-left: 3px; font-variant-numeric: tabular-nums; }
.kind-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.kind-btn[aria-pressed="true"] span { color: inherit; opacity: .7; }

.picker { display: grid; gap: 10px; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 36px; }
.classes { display: flex; flex-wrap: wrap; gap: 5px; }
.cls-btn { min-width: 34px; height: 28px; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--r-sm); padding: 0 8px; cursor: pointer; font-family: var(--font-display); font-weight: 700; font-size: 14px; color: var(--ink-2); box-shadow: inset 0 -2px 0 var(--k); }
.cls-btn:hover { border-color: var(--k); }
.cls-btn[aria-pressed="true"] { background: var(--k); border-color: var(--k); color: #fff; box-shadow: none; }
.results { border: 1px solid var(--line); border-radius: var(--r); max-height: 300px; overflow-y: auto; background: var(--surface); }
.results button {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; width: 100%;
  text-align: left; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer;
}
.results button:last-child { border-bottom: 0; }
.results button:hover, .results button.active { background: var(--accent-soft); }
.results .nm { font-weight: 600; overflow-wrap: anywhere; }
.results .meta { font-size: 12.5px; color: var(--muted); }
.results .group { position: sticky; top: 0; padding: 7px 12px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); }
.results .none { padding: 14px 12px; color: var(--muted); font-size: 14px; }
.chosen { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 12px 14px; border: 1px solid var(--accent); border-radius: var(--r); background: var(--accent-soft); }
.chosen .nm { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.chosen .meta { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 2px; }

.pi { display: inline-flex; align-items: stretch; border-radius: 4px; overflow: hidden; font-family: var(--font-display); font-weight: 700; font-size: 13px; line-height: 1; vertical-align: middle; white-space: nowrap; border: 1px solid var(--k, var(--muted)); }
.pi b { background: var(--k, var(--muted)); color: #fff; padding: 3px 5px; }
.pi i { font-style: normal; padding: 3px 6px; background: var(--surface); color: var(--ink); }
.pi-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pi-row input { width: 96px; flex: none; text-align: center; }
.pi-row .pi { font-size: 17px; }
.add-circuit { display: grid; gap: 8px; padding: 12px; border: 1px dashed var(--line-2); border-radius: var(--r); background: var(--surface-2); }

.toast { padding: 12px 14px; border-radius: var(--r); font-size: 14px; background: var(--gold-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--gold) 60%, transparent); animation: rise .25s ease-out; }
@keyframes rise { from { transform: translateY(4px); opacity: 0; } }

/* ───── Récords ───── */
.circuit { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.circuit-h { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 11px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.circuit-h h3 { min-width: 0; overflow-wrap: anywhere; }
.circuit-h small { color: var(--muted); font-size: 12.5px; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
th { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); white-space: nowrap; background: var(--surface); }
.num { text-align: right; }
td.car { min-width: 180px; }
td.car .nm { font-weight: 600; margin-bottom: 4px; }
.rank { display: grid; gap: 5px; min-width: 220px; }
.rank div { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 14px; }
.rank div.first .time { font-weight: 700; color: var(--ink); }
.rank .rk-who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pi-mini { flex: none; font-family: var(--font-time); font-size: 11px; color: var(--muted); padding: 1px 5px; border: 1px solid var(--line); border-radius: 4px; }
.pi-mini::before { content: "PI "; opacity: .7; }
.rank .pos { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; font-weight: 600; }
.rank .gap { color: var(--muted); font-size: 13px; }
.rank .mine .who-chip > span:last-child { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.tag { display: inline-block; padding: 2px 7px; border-radius: 999px; font-family: var(--font-body); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; vertical-align: 1px; white-space: nowrap; }
.tag.rec { background: var(--gold-soft); color: var(--gold); border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent); }
.tag.pb { border: 1px solid var(--line-2); color: var(--muted); }
.tag.tuned { border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent); color: var(--accent); background: var(--accent-soft); }

/* Nivel 1: filtros y tarjetas de circuitos */
.rec-filters { display: grid; gap: 12px; }
.kind-btn[style*="--kc"]::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--kc); margin-right: 6px; vertical-align: 1px; }
.kind-btn[aria-pressed="true"]::before { background: currentColor; }
@media (max-width: 600px) {
  /* En móvil los tipos van en una fila que se desliza de lado, sin salirse de la página */
  .kinds-scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -18px; padding: 0 18px 2px; scrollbar-width: none; }
  .kinds-scroll::-webkit-scrollbar { display: none; }
  .kinds-scroll .kind-btn { flex: none; }
}
#recIndex { display: grid; gap: 18px; min-width: 0; }
#recIndex[hidden] { display: none; }
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(270px, 100%), 1fr)); gap: 12px; }
.cgrid > .empty { grid-column: 1 / -1; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.ccard {
  position: relative; display: grid; gap: 8px; align-content: start; min-width: 0; padding: 14px 16px 14px 19px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.ccard::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kc); }
.ccard:hover { border-color: var(--line-2); transform: translateY(-1px); }
.cc-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.cc-h h3 { min-width: 0; overflow-wrap: anywhere; font-size: 18px; }
.kind-tag { flex: none; display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
  color: var(--kc); border: 1px solid color-mix(in srgb, var(--kc) 55%, transparent); background: color-mix(in srgb, var(--kc) 12%, transparent); }
.cc-best { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.cc-best .time { font-family: var(--font-time); font-size: 22px; font-weight: 700; color: var(--ink); }
.cc-k { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.cc-who { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14px; min-width: 0; }
.cc-who .avatar { width: 20px; height: 20px; font-size: 12px; box-shadow: none; }
.cc-car { color: var(--ink-2); min-width: 0; overflow-wrap: anywhere; }
.cc-meta { font-size: 12.5px; color: var(--muted); }
.cc-meta strong { color: var(--ink-2); }
.cc-mine { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: center; font-size: 13px; color: var(--ink-2); padding-top: 8px; border-top: 1px solid var(--line); }
.cc-mine.none { grid-template-columns: 1fr; color: var(--muted); }
.cc-mine .bar { height: 6px; border-radius: 3px; background: var(--sunk); overflow: hidden; }
.cc-mine .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.cc-empty { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 14px; }

/* Nivel 2: un circuito */
#recDetail { display: grid; gap: 18px; min-width: 0; }
#recDetail[hidden] { display: none; }
#recDetail .page-h .kind-tag { margin-bottom: 6px; }
#recDetail .page-title { overflow-wrap: anywhere; }
.back { display: inline-flex; align-items: center; gap: 4px; justify-self: start; font-size: 14px; font-weight: 600; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--accent); }
.stat .v small { font-size: .55em; color: var(--muted); }
.stat .d .who-chip { vertical-align: middle; }
.race-btn { display: flex; align-items: center; gap: 6px; margin-top: 10px; height: 30px; padding: 0 10px; font-size: 13px; white-space: nowrap; }
.race-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
/* Aviso en Inicio cuando el coche y el PI vienen copiados de Récords */
.copy-note { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 10px 12px; font-size: 14px; line-height: 1.5;
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent); border-radius: var(--r); background: var(--accent-soft); animation: rise .25s ease-out; }
.copy-note > div { min-width: 0; overflow-wrap: anywhere; }
.copy-note .muted { font-size: 13px; }
.copy-note .linkbtn { flex: none; }
.all-laps { margin-top: 8px; font-size: 13px; }
.all-laps summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.all-laps summary:hover { color: var(--accent); }
.all-laps > div { display: grid; gap: 3px; margin-top: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-2); }
.all-laps > div > div { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: baseline; }
.all-laps .time { font-family: var(--font-time); }
.al-who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.al-date { color: var(--muted); font-size: 12px; }

/* En móvil cada coche se apila: el coche arriba y su clasificación debajo, a todo el ancho */
@media (max-width: 600px) {
  .circuit table, .circuit tbody, .circuit tr, .circuit td { display: block; }
  .circuit thead { display: none; }
  .circuit tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .circuit tr:last-child { border-bottom: 0; }
  .circuit td { padding: 0; border: 0; }
  .circuit td.car { min-width: 0; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .circuit td.car .nm { margin: 0 4px 0 0; }
  .circuit .race-btn { margin: 0 0 0 auto; }
  .circuit td.num { display: none; }
  .circuit .rank { min-width: 0; }
  .circuit .pi-mini { display: none; }
}

/* ───── Historial ───── */
.lap { display: grid; grid-template-columns: 92px minmax(0, 1fr) auto auto; gap: 14px; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.lap:last-child { border-bottom: 0; }
.lap .date { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.lap .what { min-width: 0; display: grid; gap: 4px; }
.lap .what strong { overflow-wrap: anywhere; font-weight: 600; }
.lap .what .sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.lap > .time { font-size: 17px; font-weight: 700; text-align: right; }
.del { background: none; border: 1px solid transparent; border-radius: var(--r-sm); color: var(--muted); cursor: pointer; padding: 5px 9px; font-size: 13px; white-space: nowrap; }
.del:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.del.edit:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.lap-actions { display: flex; gap: 2px; }

/* Tiempos editados: marca visible y el original guardado debajo */
.tag.edited { background: var(--accent-soft); color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent); }
.edited-date { display: grid; gap: 4px; justify-items: start; }
.lap.is-edited { box-shadow: inset 3px 0 0 var(--accent); padding-left: 12px; }
.edit-mark { flex: none; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.edit-hist { font-size: 12.5px; color: var(--muted); }
.edit-hist summary { cursor: pointer; width: fit-content; }
.edit-hist summary:hover { color: var(--ink); }
.edit-hist ol { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 4px; }
.edit-hist li .time { color: var(--ink-2); }
.lap.editing { background: var(--surface-2); border-radius: var(--r); padding: 12px; grid-template-columns: 92px minmax(0, 1fr); }
.lap.editing > span { display: none; }
.edit-grid { display: grid; grid-template-columns: 150px 90px minmax(0, 1fr); gap: 10px; margin: 6px 0 2px; }
.edit-grid label { display: grid; gap: 5px; }
.edit-grid input.timein { font-size: 18px; text-align: center; }
@media (max-width: 560px) {
  .lap.editing { grid-template-columns: minmax(0, 1fr); }
  .edit-grid { grid-template-columns: 1fr 90px; }
  .edit-grid .wide { grid-column: 1 / -1; }
  .lap-actions { flex-direction: column; }
}
.confirm { display: flex; gap: 6px; align-items: center; font-size: 13px; white-space: nowrap; }
.confirm button { border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--r-sm); padding: 4px 10px; cursor: pointer; }
.confirm .yes { background: var(--danger); border-color: var(--danger); color: #fff; }
@media (max-width: 560px) {
  .lap { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; }
  .lap .date { grid-column: 1 / -1; }
}

/* ───── Estadísticas ───── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
@media (max-width: 600px) { .stat { padding: 12px; } .stat .v { font-size: 26px; } .stat .v .time { font-size: 19px; } }
.stat { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 4px; align-content: start; min-width: 0; background: var(--surface-2); }
.stat .k { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.stat .v { font-family: var(--font-display); font-weight: 700; font-size: 32px; line-height: 1.05; overflow-wrap: anywhere; }
.stat .v .time { font-size: 24px; }
.stat .d { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
/* ───── Estadísticas ───── */
.stats-hero { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stats-hero .stat { background: var(--surface); box-shadow: var(--shadow); }
.stat .d .bar { display: block; height: 6px; margin-top: 6px; border-radius: 3px; background: var(--sunk); overflow: hidden; }
.stat .d .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.card-sub { margin: -6px 0 12px; font-size: 13.5px; }
.clink { color: var(--ink); font-weight: 600; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
.clink:hover { color: var(--accent); text-decoration-color: currentColor; }
table.dom th, table.dom td { padding: 9px 12px; }
table.dom th.num { text-align: center; }
table.dom th .avatar { display: block; margin: 0 auto 4px; width: 24px; height: 24px; font-size: 13px; box-shadow: none; }
.dom-name { display: block; max-width: 90px; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--ink-2); }
table.dom td.num { text-align: center; font-family: var(--font-display); font-weight: 700; font-size: 17px; }
table.dom td.dom-top { color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); box-shadow: inset 0 -3px 0 var(--c); }
table.dom tr.total td { border-top: 2px solid var(--line-2); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; font-size: 13px; }
table.dom tr.total td.num { font-size: 17px; }
.near { display: grid; }
.near-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.near-row:last-child { border-bottom: 0; }
.near-row .what { display: grid; gap: 3px; min-width: 0; font-size: 14px; overflow-wrap: anywhere; }
.near-row .sub { color: var(--muted); font-size: 12.5px; }
.near-gap { font-weight: 700; font-size: 15px; color: var(--accent); white-space: nowrap; }
.near-row .race-btn { grid-column: 1 / -1; justify-self: start; margin-top: 4px; }

.bars { display: grid; gap: 9px; }
.brow { display: grid; grid-template-columns: minmax(90px, 200px) minmax(0, 1fr) 70px; gap: 12px; align-items: center; font-size: 14px; }
.brow .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .track { height: 12px; background: var(--sunk); border-radius: 999px; display: flex; overflow: hidden; gap: 2px; }
.brow .track i { display: block; height: 100%; }
.brow .n { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }

/* ───── Perfil: foto, marcos e insignias ───── */
.profile-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.profile-grid > .panel:first-child { grid-row: span 2; }
@media (max-width: 960px) { .profile-grid { grid-template-columns: minmax(0, 1fr); } .profile-grid > .panel:first-child { grid-row: auto; } }
.photo-row { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.photo-row .avatar.xl { margin: 8px; }
.photo-actions { display: grid; gap: 8px; justify-items: start; }
.photo-actions small { font-size: 12px; }
.frames { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.frame-opt {
  position: relative; display: grid; justify-items: center; gap: 8px; padding: 14px 6px 10px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface-2); cursor: pointer; color: var(--ink-2); transition: border-color .15s, background .15s;
}
.frame-opt small { font-size: 12px; font-weight: 600; text-align: center; }
.frame-opt:hover:not(:disabled) { border-color: var(--muted); }
.frame-opt.on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.frame-opt:disabled { cursor: not-allowed; }
.frame-opt:disabled .avatar { filter: grayscale(1); opacity: .45; }
.frame-opt .lock { font-style: normal; font-size: 10.5px; color: var(--muted); text-align: center; line-height: 1.2; }
.frame-opt .lock::before { content: "🔒 "; }
.badges { display: grid; gap: 8px; }
.badge { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); }
.badge:not(.got) { opacity: .75; }
.badge strong { display: block; font-size: 14px; }
.badge small { display: block; color: var(--muted); font-size: 12.5px; }
.badge .prog { display: block; height: 6px; margin: 6px 0 3px; border-radius: 999px; background: var(--sunk); overflow: hidden; }
.badge .prog i { display: block; height: 100%; background: var(--accent); }
.medal { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; }
.medal.tier-b { background: linear-gradient(135deg, #8a4b22, #d99a6c); }
.medal.tier-s { background: linear-gradient(135deg, #7d8794, #e3e8ee); color: #2b323c; }
.medal.tier-g { background: linear-gradient(135deg, #a57a00, #ffe27a); color: #3a2c00; }
.medal.locked { background: var(--sunk); color: var(--muted); border: 1px dashed var(--line-2); }
.badges.compact { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; margin-top: 8px; }
.badges.compact .badge { padding: 7px 9px; gap: 8px; align-items: center; }
.badges.compact .badge small { display: none; }
.badges.compact .medal { width: 26px; height: 26px; }

/* ───── Tarjeta de visita ───── */
.pcard {
  width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line-2); border-radius: 18px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); overflow: auto;
}
.pcard::backdrop { background: rgba(5, 7, 10, .6); backdrop-filter: blur(3px); }
.pcard[open] { animation: rise .2s ease-out; }
.pc-banner { height: 92px; background: radial-gradient(120% 140% at 0% 0%, var(--c), transparent 70%), linear-gradient(135deg, color-mix(in srgb, var(--c) 55%, #000), var(--sunk)); }
.pc-head { display: flex; align-items: flex-end; gap: 14px; padding: 0 20px; margin-top: -46px; }
.pc-head .avatar.xl { box-shadow: 0 0 0 4px var(--surface); }
.pc-head .avatar.xl[data-frame] { box-shadow: none; }
.pc-name { min-width: 0; padding-bottom: 4px; }
.pc-name h2 { font-size: 26px; letter-spacing: .02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.pc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 18px 20px 4px; }
.pc-stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; display: grid; gap: 2px; }
.pc-stat span { font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.pc-stat strong { font-family: var(--font-display); font-size: 26px; line-height: 1; }
.pc-favs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px 20px 0; font-size: 14px; }
.pc-favs .wide { grid-column: 1 / -1; }
.pc-favs > div > div { margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pc-badges { padding: 16px 20px 0; }
.pc-actions { display: flex; gap: 8px; padding: 18px 20px 20px; }
.pc-actions .btn { flex: 1; }
@media (max-width: 600px) {
  .pcard { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 18px 18px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .pc-stats { grid-template-columns: repeat(3, 1fr); padding-inline: 14px; }
  .pc-favs, .pc-badges, .pc-actions { padding-inline: 14px; }
  .pc-head { padding: 0 14px; }
}

/* ───── Varios ───── */
.empty { padding: 36px 16px; text-align: center; color: var(--muted); display: grid; gap: 6px; justify-items: center; }
.empty::before {
  content: ""; width: 44px; height: 44px; border-radius: 50%; margin-bottom: 6px;
  background: var(--accent-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='%2322e07a' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='13' r='8'/%3E%3Cpath d='M12 13l3-3M10 2h4'/%3E%3C/svg%3E") center no-repeat;
}
.empty strong { color: var(--ink); font-family: var(--font-display); font-size: 21px; text-transform: uppercase; letter-spacing: 0.03em; }
.empty p { margin: 0; max-width: 46ch; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatches button { width: 32px; height: 32px; border-radius: 50%; border: 0; cursor: pointer; background: var(--sw); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px transparent; transition: box-shadow .15s; }
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }

@media (prefers-reduced-motion: reduce) { *, *::before { transition: none !important; animation: none !important; } }
