:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141414;
  --ink: #f2f2f2;
  --muted: #8d8d8d;
  --faint: #808080;
  --surface: #1c1c1c;
  --lime: #c6ff2e;
  --lime-ink: #141414;
  --lime-muted: #3a4a12;
  --danger: #f07070;
  --thumb: #222;
  --drawer: #1a1a1a;
  --backdrop: rgba(0, 0, 0, 0.55);
  --grab: #2a2a2a;
  --disabled: #3a3a3a;
  --leader-face: #d8f07a;
  --logo-on-lime: #fff;
  --accent: #c6ff2e;
  --font: Inter, system-ui, -apple-system, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pad: 20px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f4ef;
  --ink: #141414;
  --muted: #5a5a5a;
  --faint: #6b6b6b;
  --surface: #fff;
  --lime: #326600;
  --lime-ink: #ffffff;
  --lime-muted: #e4eed0;
  --danger: #9a1d1d;
  --thumb: #e6e4de;
  --drawer: #ffffff;
  --backdrop: rgba(20, 20, 20, 0.4);
  --grab: #d4d1ca;
  --disabled: #c5c3bd;
  --leader-face: #f6f4ef;
  --logo-on-lime: #fff;
  --accent: #326600;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app {
  width: min(680px, 100%);
  margin: 0 auto;
  padding: 22px var(--pad) 64px;
}

/* Header */
.top {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand h1 { min-width: 0; }
.brand-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
  margin-left: 8px;
}
.theme-toggle {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--accent); }
.theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }
.brand h1 {
  margin: 0;
  font-weight: 800;
  font-size: clamp(1.75rem, 8vw, 2.1rem);
  letter-spacing: -0.05em;
  line-height: 1;
  white-space: nowrap;
}
.brand h1 span { color: var(--accent); }
.brand h1 a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: inherit;
}
.about-link {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 4px 0 8px;
}
.about-link:hover, .about-link:focus-visible { color: var(--ink); }
.nav-link {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.nav-link:hover, .nav-link:focus-visible { color: var(--ink); }
.sub {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
  max-width: 22em;
}

.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 0 0;
  min-height: 44px;
}
.date-nav button {
  width: 44px;
  height: 44px;
  font-size: 26px;
  font-weight: 500;
  color: var(--ink);
}
.date-nav button:disabled {
  color: var(--disabled);
  cursor: default;
}
.date-nav .date-label {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Underline sort tabs */
.sortbar {
  display: flex;
  gap: 14px;
  margin: 0 calc(0px - var(--pad)) 8px;
  padding: 0 var(--pad);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.sortbar::-webkit-scrollbar { display: none; }
.sortbar button {
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 0 8px;
  min-height: 44px;
  min-width: 44px;
  text-align: center;
  border-bottom: 2px solid transparent;
}
.sortbar button[aria-pressed="true"] {
  color: var(--ink);
  border-bottom-color: var(--lime);
}

/* Race sheet rows */
.board { display: flex; flex-direction: column; }
.row {
  display: grid;
  grid-template-columns: 28px 36px minmax(0, 1fr) auto;
  column-gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: 8px 0;
  cursor: pointer;
}
.row.top {
  background: var(--lime);
  color: var(--lime-ink);
  margin: 4px calc(0px - var(--pad)) 8px;
  padding: 16px var(--pad);
  min-height: 88px;
}
.rank {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: left;
}
.row.top .rank {
  color: var(--lime-ink);
  font-size: 20px;
  font-weight: 800;
}
.thumb {
  width: 36px;
  height: 36px;
  background: var(--thumb);
  overflow: hidden;
  flex-shrink: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.row.top .thumb {
  width: 44px;
  height: 44px;
  background: var(--logo-on-lime);
  border-radius: 50%;
}
.main { min-width: 0; }
.name {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row.top .name {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.03em;
  white-space: normal;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.hunter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-sizing: border-box;
  min-height: 44px;
  max-width: 100%;
  width: fit-content;
  margin: -10px 0 -8px;
  padding: 10px 8px 10px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.row.top .hunter { color: var(--lime-muted); }
.hunter:hover, .hunter:focus-visible { color: var(--ink); }
.row.top .hunter:hover, .row.top .hunter:focus-visible { color: var(--lime-ink); }
.hunter-empty { min-height: 0; padding: 0; margin: 0; }
.hunter-face {
  position: relative;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--thumb);
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.row.top .hunter-face { background: var(--leader-face); }
.hunter-face img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}
.hunter-fallback {
  font-size: 9px;
  font-weight: 700;
  color: var(--faint);
  line-height: 1;
}
.hunter-handle {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  pointer-events: none;
}

.side {
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 0;
}
.votes {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.03em;
  white-space: nowrap;
}
.votes .unit {
  font-size: 0.62em;
  font-weight: 700;
  letter-spacing: 0;
  margin-left: 0.04em;
}
.row.top .votes {
  font-size: 28px;
  letter-spacing: -0.04em;
  color: var(--lime-ink);
}
.meta {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row.top .meta { color: var(--lime-muted); }

@media (prefers-reduced-motion: no-preference) {
  .tick {
    animation: tick-flash 0.85s var(--ease);
  }
  .row.top .tick,
  .row.top .votes.tick,
  .row.top .meta.tick,
  .row.top .rank.tick {
    animation-name: tick-flash-leader;
  }
}
@keyframes tick-flash {
  from { color: var(--accent); }
}
@keyframes tick-flash-leader {
  from { opacity: 0.55; }
}


/* Hunters tab: large hunter photo is primary, small product logo sits with the name */
.row.hunter-row {
  grid-template-columns: 28px 48px minmax(0, 1fr) auto;
  column-gap: 10px;
  min-height: 72px;
}
.row.hunter-row .thumb.hunter-photo,
.row.hunter-row.top .thumb.hunter-photo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--thumb);
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}
.row.hunter-row.top .thumb.hunter-photo { background: var(--leader-face); }
.row.hunter-row .thumb.hunter-photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}
.row.hunter-row .thumb.hunter-photo .hunter-fallback {
  font-size: 16px;
  font-weight: 700;
  color: var(--faint);
  line-height: 1;
}
.row.hunter-row.top .thumb.hunter-photo .hunter-fallback { color: var(--lime-ink); }
[data-theme="light"] .row.top .hunter-face .hunter-fallback,
[data-theme="light"] .row.hunter-row.top .thumb.hunter-photo .hunter-fallback {
  color: #141414;
}
.row.hunter-row .rank,
.row.hunter-row.top .rank {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.row.hunter-row.top .rank { color: var(--lime-ink); }
.row.hunter-row .product {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.3;
  min-width: 0;
}
.row.hunter-row.top .product { color: var(--lime-muted); }
.row.hunter-row .product-logo {
  width: 22px;
  height: 22px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--thumb);
}
.row.hunter-row.top .product-logo { background: var(--logo-on-lime); }
.row.hunter-row .product-name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row.hunter-row .name {
  display: flex;
  align-items: center;
  min-width: 0;
}
.row.hunter-row .hunter-name-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  max-width: 100%;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row.hunter-row .name-empty {
  color: var(--muted);
  font-weight: 600;
}
.row.hunter-row.top .name-empty { color: var(--lime-muted); }

.delta { font-weight: 700; }
.delta.up { color: var(--accent); }
.row.top .delta.up, .row.top .delta.down { color: var(--lime-ink); }
.delta.down { color: var(--danger); }

.d-hunter { margin-top: 4px; }
.d-hunter .hunter { min-height: 44px; margin: 0; padding: 10px 8px 10px 0; color: var(--muted); }
.d-hunter .hunter-face { width: 20px; height: 20px; }

/* Refresh line only takes space when there is a message */
.refresh-status {
  margin: 0;
  padding: 0;
  min-height: 0;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: transparent;
}
.refresh-status.is-on {
  padding: 8px 0 10px;
  min-height: calc(13px * 1.4 + 18px);
  color: var(--muted);
}
.refresh-status.is-on.is-error { color: var(--ink); }

/* Empty / loading */
.state {
  min-height: calc(100dvh - 200px);

  padding: 28px 0;
  margin: 12px 0 8px;
}
.state h2 {
  margin: 0 0 8px;
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.04em;
  line-height: 1.15;
}
.state p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 36em;
}
.state .accent {
  display: block;
  margin-top: 14px;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
}

/* Detail drawer — bottom sheet on a phone, same 680px column on desktop */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: var(--backdrop);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s var(--ease);
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: min(680px, 100%);
  margin-inline: auto;
  z-index: 50;
  background: var(--drawer);
  padding: 12px 20px calc(28px + env(safe-area-inset-bottom, 0px));
  max-height: min(88dvh, 720px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(110%);
  transition: transform 0.45s var(--ease);
}
.drawer.open { transform: translateY(0); }
.drawer .grab {
  width: 40px; height: 4px;
  background: var(--grab);
  margin: 0 auto 14px;
}
.drawer-head {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
}
.drawer-head .thumb {
  width: 56px; height: 56px;
  background: var(--thumb);
  overflow: hidden;
  flex-shrink: 0;
}
.drawer-title { min-width: 0; }
.drawer-head h2 {
  margin: 0;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.03em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.drawer-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.close-btn {
  min-width: 44px; min-height: 44px;
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 6px;
}
.chart-card { margin: 8px 0 16px; }
.chart-card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.chart-wrap {
  width: 100%;
  aspect-ratio: 640 / 200;
  height: auto;
  max-height: 200px;
  color: var(--accent);
}
.chart-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
.detail-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
}
.detail-stats > div { min-width: 0; }
.detail-stats b {
  display: block;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.detail-stats span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.links a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  width: fit-content;
}
.links a:hover { color: var(--accent); }

/* Footer */
.footer {
  margin-top: 36px;
  padding-top: 8px;
  color: var(--faint);
  font-size: 0.8rem;
  line-height: 1.6;
}
.footer a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.site-visits { margin: 0 0 6px; color: var(--faint); }

/* About */
.about-copy { margin: 28px 0 8px; }
.about-copy h2 {
  margin: 28px 0 10px;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.about-copy h2:first-child { margin-top: 0; }
.about-copy p {
  margin: 0 0 12px;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
  max-width: 38em;
}
.about-copy a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.about-copy a:hover { color: var(--accent); }
.about-copy strong { color: var(--accent); font-weight: 700; }
.about-copy code {
  font-family: inherit;
  font-size: 0.95em;
  color: var(--muted);
}

/* Comment pulse */
.pulse-intro { padding: 4px 0 12px; }
.pulse-lede {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--ink);
  max-width: 36em;
}
.pulse-note { margin: 0; font-size: 11px; color: var(--muted); font-weight: 500; }
.pulse-state { padding: 16px 0; margin: 0; min-height: 0; }
.pulse-status {
  margin: 3px 0 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row.top .pulse-status { color: var(--lime-muted); }
.pulse-status .chev { margin-left: 6px; font-size: 10px; }
.pulse-panel {
  padding: 4px 0 16px 38px;
  border-bottom: 1px solid var(--grab);
  margin-bottom: 4px;
}
.row.top + .pulse-panel { margin-top: -4px; }
.pulse-sec { margin: 10px 0 0; }
.pulse-sec h4 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.pulse-love h4 { color: var(--accent); }
.pulse-flags h4 { color: var(--danger); }
.pulse-sec ul { margin: 0; padding: 0 0 0 16px; }
.pulse-sec li {
  font-size: 14px;
  line-height: 1.45;
  margin: 2px 0;
  color: var(--ink);
}
.pulse-empty { margin: 4px 0 0; font-size: 14px; line-height: 1.45; color: var(--muted); }
.pulse-foot { margin: 12px 0 0; font-size: 11px; color: var(--faint); font-weight: 500; }
@media (min-width: 640px) {
  .pulse-panel { padding-left: 84px; }
}

@media (min-width: 640px) {
  .app { --pad: 24px; padding: 32px var(--pad) 80px; }
  .name { font-size: 16px; }
  .drawer { padding-left: 24px; padding-right: 24px; }
}

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