:root {
  --paper: #f3ecdf;
  --card: #fffaf3;
  --ink: #211c17;
  --muted: #5c534a;
  --rule: #e0d3c2;
  --tomato: #9d3426;
  --tomato-soft: #f4ddd6;
  --sage: #1b683e;
  --gold: #8a5a18;
  --cols: 3rem minmax(0, 1.55fr) 9.2rem 4.6rem 4.2rem 4.8rem 3.6rem 2.6rem;
  color-scheme: light;
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141210;
    --card: #1e1a16;
    --ink: #f4ece2;
    --muted: #cbbfab;
    --rule: #3a322b;
    --tomato: #f0a396;
    --tomato-soft: #3c2420;
    --sage: #8ed0ae;
    --gold: #e4c07a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

::selection { background: var(--tomato-soft); }

.wrap {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding-bottom: 64px;
}

h1, h2, h3, .domain, .leader .ld {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
}

a { color: inherit; }

.skip {
  position: absolute;
  left: 12px;
  top: 8px;
  transform: translateY(-150%);
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
}

.skip:focus { transform: none; }

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mast {
  padding: 22px 0 16px;
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  margin: 16px 0 18px;
}

.mast-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mast-top p { margin: 0; }

h1 {
  margin: 10px 0 8px;
  font-size: clamp(2.05rem, 4.4vw, 3.35rem);
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 0.98;
}

.lede {
  margin: 0;
  max-width: 62ch;
  font-size: 1.02rem;
}

.tally {
  margin: 12px 0 0;
  color: var(--gold);
  font-size: 13px;
}

.leaders {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 16px;
}

.leader {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 8px 8px 4px;
  min-width: 0;
}

.leader h3 {
  margin: 0 0 6px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.leader ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

.leader button {
  display: flex;
  gap: 6px;
  width: 100%;
  padding: 3px 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  min-height: 28px;
  border-radius: 6px;
}

.leader .n {
  font-family: ui-sans-serif, system-ui, sans-serif;
  color: var(--tomato);
  font-size: 12px;
  font-weight: 650;
  width: 0.8rem;
  flex: none;
}

.leader .ld {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 12.5px;
  line-height: 1.25;
  overflow-wrap: break-word;
}

.leader button:hover .ld { color: var(--tomato); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 8px 0;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(10px);
}

.search { flex: 1 1 220px; min-width: 0; }

.search input,
.sortlab select,
.views,
.chip,
.texty,
#copy {
  border: 1px solid var(--rule);
  background: var(--card);
  color: inherit;
  border-radius: 10px;
}

.search input,
.sortlab select {
  min-height: 40px;
  padding: 8px 12px;
  width: 100%;
}

.sortlab {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.sortlab select { width: auto; }

.views {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
}

.views button {
  border: 0;
  background: transparent;
  color: inherit;
  border-radius: 8px;
  min-height: 34px;
  padding: 6px 10px;
  cursor: pointer;
}

.views button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.badge {
  display: inline-block;
  min-width: 1.1em;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--tomato-soft);
  color: var(--tomato);
  font-size: 12px;
}

.views button[aria-pressed="true"] .badge {
  background: transparent;
  color: inherit;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 8px;
}

.chip {
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.countline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 28px;
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

#copy {
  min-height: 32px;
  padding: 4px 10px;
  cursor: pointer;
}

.headrow { display: none; }

.sites { min-height: 40vh; }

.site {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "rank who star"
    "stats stats stats"
    "extra extra extra";
  gap: 2px 10px;
  align-items: start;
  padding: 11px 4px;
  border-bottom: 1px solid var(--rule);
}

.rank {
  grid-area: rank;
  color: var(--tomato);
  font-weight: 700;
  font-size: 1.12rem;
  line-height: 1.2;
  padding-top: 2px;
}

.who { grid-area: who; min-width: 0; }

.domain {
  display: inline;
  font-size: 1.08rem;
  font-weight: 560;
  letter-spacing: -0.015em;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.domain:hover { color: var(--tomato); text-decoration-color: var(--tomato); }

.market {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 1px;
}

.stats {
  grid-area: stats;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 4px;
  font-size: 13px;
}

.visits b { font-weight: 650; }

.visits small,
.extra {
  color: var(--muted);
  font-size: 12px;
}

.visits small { display: block; font-weight: 450; line-height: 1.3; }

.extra {
  grid-area: extra;
  margin: 2px 0 0;
}

.star {
  grid-area: star;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.star svg { width: 18px; height: 18px; }

.star path { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }

.star[aria-pressed="true"] { color: var(--tomato); }

.star[aria-pressed="true"] path { fill: var(--tomato); stroke: var(--tomato); }

.up { color: var(--sage); font-weight: 650; }

.down { color: var(--tomato); font-weight: 650; }

.flat { color: var(--muted); }

.empty {
  margin: 18px 0;
  padding: 22px 16px;
  border: 1px dashed var(--rule);
  border-radius: 12px;
  background: var(--card);
}

.empty p { margin: 0; }

.texty {
  margin-top: 12px;
  min-height: 36px;
  padding: 6px 12px;
  cursor: pointer;
}

footer {
  margin-top: 28px;
  color: var(--muted);
  font-size: 13.5px;
}

footer a { text-underline-offset: 2px; }

summary { cursor: pointer; color: var(--ink); }

details p { max-width: 72ch; }

.src { margin-top: 14px; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--tomato);
  outline-offset: 2px;
}

@media (hover: hover) {
  .site:hover { background: color-mix(in srgb, var(--card) 70%, transparent); }
}

@media (min-width: 960px) {
  .headrow,
  .site {
    display: grid;
    grid-template-columns: var(--cols);
    grid-template-areas: none;
    column-gap: 10px;
    align-items: center;
  }

  .headrow { margin-bottom: 2px; }

  .headrow button {
    background: none;
    border: 0;
    padding: 4px 0 8px;
    min-height: 0;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: right;
    cursor: pointer;
    border-radius: 0;
  }

  .headrow button:first-child,
  .headrow button:nth-child(2) { text-align: left; }

  .headrow button[aria-sort="ascending"],
  .headrow button[aria-sort="descending"] { color: var(--ink); }

  .rank, .who, .star, .stats, .extra { grid-area: auto; }

  .site { padding: 9px 4px; }

  .site .stats {
    display: contents;
  }

  .num { text-align: right; }

  .visits { text-align: right; }

  .extra { grid-column: 2 / -1; margin: 0 0 4px; }

  .star { justify-self: end; }
}

@media (max-width: 959px) {
  .leaders {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 8px;
    padding-bottom: 6px;
  }

  .leader {
    flex: 0 0 186px;
    scroll-snap-align: start;
  }
}

@media (max-width: 640px) {
  .wrap { width: min(1120px, calc(100% - 24px)); }
  .search { flex-basis: 100%; }
  .views { width: 100%; }
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .chip { flex: none; }
  .sortlab { width: 100%; }
  .sortlab select { flex: 1; }
  h1 { font-size: 2.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
