*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0a08;
  --bg-2: #13110d;
  --card: rgba(255,255,255,0.035);
  --card-hover: rgba(255,255,255,0.065);
  --line: rgba(255,255,255,0.08);
  --line-strong: rgba(255,255,255,0.14);
  --text: #f4f1ea;
  --muted: rgba(244,241,234,0.58);
  --faint: rgba(244,241,234,0.36);
  --gold: #c9a227;
  --gold-2: #b07230;
  --gold-soft: rgba(201,162,39,0.14);
  --live: #ff4d4d;
  --ok: #3ecf8e;
  --radius: 14px;
  --topbar-h: 60px;
  --gutter: 16px;
}

html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  background: radial-gradient(ellipse 120% 60% at 50% -10%, #241809 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  font-family: 'Roboto', system-ui, -apple-system, sans-serif;
  font-size: 15px; line-height: 1.4;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.mono { font-family: 'Roboto Mono', ui-monospace, monospace; }

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: rgba(11,10,8,0.82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { height: 22px; width: auto; display: block; }
.brand-sub {
  font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold);
  padding-left: 12px; border-left: 1px solid var(--line-strong); white-space: nowrap;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--card); transition: background .15s;
}
.icon-btn:hover { background: var(--card-hover); }
.icon-btn svg { width: 18px; height: 18px; }

.app { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 var(--gutter) 40px; }
.foot { text-align: center; color: var(--faint); font-size: 0.75rem; padding: 24px var(--gutter) calc(24px + env(safe-area-inset-bottom)); }
.foot a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }

/* ── Home ────────────────────────────────────────────────── */
.hero { padding: 40px 0 20px; text-align: center; }
.hero h1 { font-size: clamp(1.7rem, 5vw, 2.8rem); font-weight: 900; letter-spacing: -0.02em; line-height: 1.1; }
.hero h1 em { font-style: normal; color: var(--gold); }
.hero p { color: var(--muted); margin-top: 8px; }

.search {
  position: relative; max-width: 620px; margin: 24px auto 0;
}
.search svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--faint); pointer-events: none; }
.search input {
  width: 100%; height: 52px; padding: 0 44px 0 46px; border-radius: 26px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--line-strong); color: var(--text);
  font: inherit; font-size: 1rem; outline: none; transition: border-color .15s, background .15s;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { border-color: var(--gold); background: rgba(255,255,255,0.08); }
.search .clear { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; border-radius: 50%; color: var(--muted); display: none; }
.search.has-value .clear { display: grid; place-items: center; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 18px 0 4px; justify-content: center; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 14px; border-radius: 999px; font-size: 0.8rem; font-weight: 500;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); white-space: nowrap; transition: all .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--gold); border-color: var(--gold); color: #1a1205; }

.section { margin-top: 32px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2 { font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.section-head .count { color: var(--faint); font-size: 0.78rem; }
.more-btn { display: block; margin: 14px auto 0; padding: 9px 18px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: 0.82rem; }
.more-btn:hover { color: var(--text); background: var(--card); }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.grid.live { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

.show-card {
  position: relative; display: flex; gap: 14px; align-items: center;
  padding: 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line);
  transition: background .15s, border-color .15s, transform .15s; min-width: 0;
}
.show-card:hover { background: var(--card-hover); border-color: var(--line-strong); }
.show-card:active { transform: scale(0.99); }
.show-card.is-live { border-color: rgba(201,162,39,0.35); background: linear-gradient(135deg, rgba(201,162,39,0.12), rgba(255,255,255,0.02)); padding: 18px; }
.show-card.is-canceled { opacity: 0.5; }
.show-logo {
  flex: none; width: 56px; height: 56px; border-radius: 12px; background: #fff; display: grid; place-items: center; overflow: hidden;
}
.show-card.is-live .show-logo { width: 68px; height: 68px; }
.show-logo img { max-width: 86%; max-height: 86%; object-fit: contain; }
.show-logo .initials { color: #1a1205; font-weight: 900; font-size: 1.1rem; }
.show-body { min-width: 0; flex: 1; }
.show-name { font-weight: 700; font-size: 0.98rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.show-card.is-live .show-name { font-size: 1.08rem; }
.show-meta { color: var(--muted); font-size: 0.8rem; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.show-desc { color: var(--gold); font-size: 0.74rem; margin-top: 4px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flag { display: inline-block; width: 18px; height: 13px; border-radius: 2px; object-fit: cover; vertical-align: -2px; box-shadow: 0 0 0 1px rgba(255,255,255,0.12); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 6px;
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap;
}
.badge.live { background: rgba(255,77,77,0.14); color: var(--live); }
.badge.live::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--live); animation: pulse 1.4s infinite; }
.badge.final { background: rgba(62,207,142,0.12); color: var(--ok); }
.badge.soon { background: var(--card-hover); color: var(--muted); }
.badge.cancel { background: rgba(255,255,255,0.08); color: var(--muted); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ── Show page ───────────────────────────────────────────── */
.show-hero {
  display: flex; gap: 18px; align-items: center; padding: 24px 0 18px;
}
.show-hero .show-logo { width: 84px; height: 84px; border-radius: 16px; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85rem; padding-top: 16px; }
.back-link:hover { color: var(--text); }
.back-link svg { width: 16px; height: 16px; }
.show-hero h1 { font-size: clamp(1.3rem, 3.5vw, 2rem); font-weight: 900; line-height: 1.15; letter-spacing: -0.01em; }
.show-hero .show-meta { font-size: 0.88rem; margin-top: 6px; }
.show-hero .show-desc { font-size: 0.82rem; white-space: normal; }

.days {
  position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top)); z-index: 20;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity;
  padding: 10px var(--gutter); margin: 0 calc(var(--gutter) * -1);
  background: rgba(11,10,8,0.9); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.days::-webkit-scrollbar { display: none; }
.day {
  flex: none; scroll-snap-align: start; min-width: 66px; padding: 8px 12px; border-radius: 12px; text-align: center;
  border: 1px solid var(--line); background: var(--card); transition: all .15s; position: relative;
}
.day:hover { background: var(--card-hover); }
.day .dow { font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.day .dnum { font-size: 1.3rem; font-weight: 900; line-height: 1.1; }
.day .dmon { font-size: 0.66rem; text-transform: uppercase; color: var(--faint); letter-spacing: 0.08em; }
.day.today::after { content: ''; position: absolute; top: 6px; right: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--live); }
.day.active { background: var(--gold); border-color: var(--gold); color: #1a1205; }
.day.active .dow, .day.active .dmon { color: rgba(26,18,5,0.7); }

.split { display: grid; grid-template-columns: 1fr; gap: 20px; padding-top: 18px; }
@media (min-width: 960px) {
  .split { grid-template-columns: minmax(340px, 420px) 1fr; align-items: start; }
  .split .panel { position: sticky; top: calc(var(--topbar-h) + 84px); max-height: calc(100vh - var(--topbar-h) - 100px); overflow: auto; }
}

.day-title { font-size: 0.78rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: 12px; }
.comps { display: flex; flex-direction: column; gap: 10px; }
.comp {
  display: grid; grid-template-columns: 62px 1fr auto; gap: 12px; align-items: center; text-align: left; width: 100%;
  padding: 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line);
  transition: background .15s, border-color .15s;
}
.comp:hover { background: var(--card-hover); }
.comp.active { border-color: var(--gold); background: var(--gold-soft); }
.comp.not-class { opacity: 0.6; cursor: default; }
.comp-time { text-align: center; }
.comp-time .t { font-family: 'Roboto Mono', monospace; font-weight: 700; font-size: 1.05rem; }
.comp-time .n { font-size: 0.68rem; color: var(--faint); margin-top: 2px; letter-spacing: 0.06em; }
.comp-time .t2 { font-family: 'Roboto Mono', monospace; font-size: 0.72rem; color: var(--muted); }
.comp-body { min-width: 0; }
.comp-sponsor { font-weight: 700; font-size: 0.95rem; line-height: 1.25; }
.comp-name { color: var(--muted); font-size: 0.78rem; margin-top: 3px; line-height: 1.3; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.tag { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em; padding: 2px 7px; border-radius: 5px; background: rgba(255,255,255,0.07); color: var(--muted); }
.tag.gold { background: var(--gold-soft); color: var(--gold); }
.comp-arrow { color: var(--faint); }
.comp-arrow svg { width: 18px; height: 18px; display: block; }

/* ── Results panel ───────────────────────────────────────── */
.panel { border-radius: var(--radius); background: var(--bg-2); border: 1px solid var(--line); min-height: 200px; }
.panel-placeholder { display: grid; place-items: center; text-align: center; color: var(--faint); padding: 80px 24px; min-height: 360px; }
.panel-placeholder svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: 0.5; }
@media (max-width: 959px) {
  .split .panel { display: none; }
  .split .panel.open {
    display: block; position: fixed; inset: 0; z-index: 50; border-radius: 0; border: 0; overflow: auto;
    background: var(--bg); animation: slideIn .22s ease-out;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.panel-open { overflow: hidden; }
}
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.res-head {
  position: sticky; top: 0; z-index: 2; padding: 16px 18px 14px; border-bottom: 1px solid var(--line);
  background: rgba(19,17,13,0.95); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
@media (max-width: 959px) { .res-head { padding-top: calc(12px + env(safe-area-inset-top)); background: rgba(11,10,8,0.95); } }
.res-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.res-close { display: none; align-items: center; gap: 6px; color: var(--muted); font-size: 0.88rem; padding: 6px 0; }
.res-close svg { width: 18px; height: 18px; }
@media (max-width: 959px) { .res-close { display: inline-flex; } }
.res-title { font-size: 1.15rem; font-weight: 900; line-height: 1.2; margin-top: 8px; }
.res-sub { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.res-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pill-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: 0.76rem; font-weight: 500;
  border: 1px solid var(--line-strong); color: var(--muted); transition: all .15s;
}
.pill-link:hover { color: var(--text); border-color: var(--gold); }
.pill-link svg { width: 14px; height: 14px; }
.updated { font-size: 0.7rem; color: var(--faint); margin-top: 10px; }

.res-list { list-style: none; }
.res-row {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
  padding: 11px 18px; border-bottom: 1px solid var(--line);
}
.res-row:last-child { border-bottom: 0; }
.res-rank { font-family: 'Roboto Mono', monospace; font-weight: 700; font-size: 1.1rem; text-align: center; }
.res-rank.st { font-size: 0.7rem; color: var(--muted); }
.res-row.p1 .res-rank { color: #e8c547; }
.res-row.p2 .res-rank { color: #cfd4da; }
.res-row.p3 .res-rank { color: #d6925a; }
.res-row.p1 { background: linear-gradient(90deg, rgba(232,197,71,0.10), transparent 60%); }
.res-who { min-width: 0; }
.res-rider { font-weight: 700; font-size: 0.95rem; display: flex; align-items: center; gap: 8px; min-width: 0; }
.res-rider .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res-rider .last { text-transform: uppercase; }
.res-horse { color: var(--muted); font-size: 0.8rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res-horse .hnr { color: var(--faint); font-family: 'Roboto Mono', monospace; font-size: 0.72rem; margin-right: 6px; }
.res-score { text-align: right; font-family: 'Roboto Mono', monospace; }
.res-score .f { font-weight: 700; font-size: 1rem; }
.res-score .tm { color: var(--muted); font-size: 0.78rem; }
.res-score .stt { color: var(--live); font-weight: 700; font-size: 0.82rem; }
.res-rank.st-order { color: var(--muted); font-size: 0.95rem; }
.res-details { color: var(--faint); font-size: 0.72rem; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res-group { padding: 10px 18px; font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); background: rgba(255,255,255,0.02); border-bottom: 1px solid var(--line); }

/* ── Loading ─────────────────────────────────────────────── */
.skel { border-radius: var(--radius); background: linear-gradient(90deg, var(--card) 0%, rgba(255,255,255,0.07) 50%, var(--card) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--gold); animation: spin .8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 600px) {
  .hero { padding-top: 28px; }
  .chips { justify-content: flex-start; margin: 0 calc(var(--gutter) * -1); padding-left: var(--gutter); padding-right: var(--gutter); }
  .grid, .grid.live { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
  .show-hero { gap: 14px; padding-top: 16px; }
  .show-hero .show-logo { width: 64px; height: 64px; }
  .comp { grid-template-columns: 54px 1fr auto; padding: 12px; gap: 10px; }
  .res-row { padding: 10px 14px; gap: 10px; grid-template-columns: 36px 1fr auto; }
}
