
/* A pool room is a dark room with a lit table in it. This site commits to that
   world in both themes on purpose - inverting it to a white page would throw
   away the one thing the palette is built from. */
:root, :root[data-theme="dark"], :root[data-theme="light"] {
  /* Drawn from the table itself: slate under tournament cloth, chalk, ivory. */
  --ink:      #081417;
  --slate:    #0C1B20;
  --cloth:    #113039;
  --cloth-hi: #1C4855;
  --chalk:    #62B4CE;
  --chalk-lo: #2F6E82;
  --ivory:    #E9E6DD;
  --muted:    #7D949C;
  --gold:     #D7A23F;
  --loss:     #C97A6D;

  --display: "Bahnschrift", "Arial Narrow", "Helvetica Neue Condensed",
             "Liberation Sans Narrow", "Roboto Condensed", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, "SF Mono", Menlo, monospace;
  --body: "Segoe UI", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;

  --gap: clamp(1.25rem, 4vw, 3rem);
}

* { box-sizing: border-box; }
.num, .rank, .tally b, .readout .side, .scale, .stat b { font-variant-numeric: tabular-nums; }
h1, h2 { text-wrap: balance; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--ivory);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  /* The nap of the cloth, barely there. */
  background-image: repeating-linear-gradient(
    45deg, rgba(255,255,255,.011) 0 1px, transparent 1px 3px);
}

a { color: var(--chalk); }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 var(--gap); }

/* --- rail ------------------------------------------------------------ */
/* The diamonds are the sights inlaid on a table's rail. They mark position
   along a scale, which is exactly what they do here too. */
.rail {
  position: sticky; top: 0; z-index: 20;
  background: rgba(8,20,23,.93);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--cloth-hi);
}
.rail-in { display: flex; align-items: center; gap: 1.25rem; height: 58px; }
.mark {
  font-family: var(--display);
  font-size: 1.4rem; letter-spacing: .22em; text-transform: uppercase;
  font-weight: 700; margin: 0; color: var(--ivory); text-decoration: none;
}
.mark span { color: var(--chalk); }
.nav { margin-left: auto; display: flex; gap: 1.25rem; font-size: .85rem; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a:hover, .nav a:focus-visible { color: var(--chalk); }

.crumbs { padding: 1.25rem 0 0; font-size: .8rem; color: var(--muted); }
.crumbs a { text-decoration: none; }

/* --- hero ------------------------------------------------------------ */
/* Text and proof side by side. The pitch alone left half the screen empty,
   which read as a broken layout rather than restraint. */
.hero {
  padding: clamp(2.5rem, 7vw, 4.5rem) 0 clamp(1.5rem, 4vw, 2.5rem);
  display: grid; gap: clamp(2rem, 5vw, 4rem);
  grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr);
  align-items: center;
  position: relative;
}
/* The lit table in a dark room, suggested rather than drawn. */
.hero::before {
  content: ""; position: absolute; inset: -20% -10% auto 20%;
  height: 120%; pointer-events: none; z-index: -1;
  background: radial-gradient(60% 50% at 70% 40%, rgba(98,180,206,.10), transparent 70%);
}
.hero-text { min-width: 0; }

.peek {
  border: 1px solid var(--cloth-hi); background: var(--slate);
  padding: 1.1rem 1.25rem 1rem; border-radius: 3px;
}
.peek-head {
  font-family: var(--display); text-transform: uppercase; letter-spacing: .16em;
  font-size: .68rem; color: var(--muted); margin: 0 0 .75rem;
}
.peek-row {
  display: grid; grid-template-columns: 1.4rem 1fr auto auto; gap: .7rem;
  align-items: baseline; padding: .5rem 0; text-decoration: none;
  border-bottom: 1px solid rgba(28,72,85,.4); color: var(--ivory);
}
.peek-row:last-of-type { border-bottom: 0; }
.peek-row:hover, .peek-row:focus-visible { color: var(--chalk); }
.peek-rank { font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.peek-name { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peek-cc { font-family: var(--mono); font-size: .68rem; color: var(--muted); }
.peek-rating { font-family: var(--mono); font-size: 1.05rem; font-weight: 600;
  font-variant-numeric: tabular-nums; }
.peek-row:first-of-type .peek-rating { color: var(--gold); }
.peek-more { display: inline-block; margin-top: .85rem; font-size: .78rem;
  color: var(--muted); text-decoration: none; }
.peek-more:hover, .peek-more:focus-visible { color: var(--chalk); }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 2rem; }
}
.hero h1 {
  font-family: var(--display); font-weight: 700;
  font-size: clamp(2.6rem, 9vw, 5.5rem);
  line-height: .94; letter-spacing: -.01em; text-transform: uppercase;
  margin: 0 0 1rem;
}
.hero h1 em { font-style: normal; color: var(--chalk); }
.lede { max-width: 46ch; color: var(--muted); font-size: 1.05rem; margin: 0 0 2rem; }
.lede b { color: var(--ivory); font-weight: 600; }

.tally {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1px; font-family: var(--mono);
  background: var(--cloth-hi);
  border: 1px solid var(--cloth-hi); border-radius: 3px; overflow: hidden;
  margin-bottom: 1rem;
}
.tally div { display: flex; flex-direction: column; gap: .2rem;
  background: var(--ink); padding: 1.1rem 1.25rem; }
.tally b { font-size: 1.6rem; font-weight: 600; color: var(--ivory); letter-spacing: -.02em; }
.tally span { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: .66rem; }

.door.primary { background: var(--chalk); border-color: var(--chalk); color: var(--ink); font-weight: 600; }
.door.primary:hover, .door.primary:focus-visible {
  background: var(--ivory); border-color: var(--ivory); color: var(--ink); }

/* --- sections -------------------------------------------------------- */
section { padding: clamp(2rem, 6vw, 3.5rem) 0; border-top: 1px solid var(--cloth); }
.head { display: flex; align-items: baseline; gap: .75rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.head h2 {
  font-family: var(--display); text-transform: uppercase; letter-spacing: .16em;
  font-size: 1rem; font-weight: 700; margin: 0;
}
/* A rail diamond, as a CSS escape: the literal character was mangled once by a
   shell rewrite and shipped as visible garbage. */
.head h2::before { content: "\25C6"; color: var(--chalk); margin-right: .6rem;
  font-size: .7em; vertical-align: .15em; }
.head p { margin: 0; color: var(--muted); font-size: .85rem; }

/* --- matchup (the signature) ----------------------------------------- */
.matchup { background: var(--slate); border: 1px solid var(--cloth); padding: clamp(1.25rem, 4vw, 2rem); }
.picker { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: center; }
.picker select {
  width: 100%; background: var(--cloth); color: var(--ivory);
  border: 1px solid var(--cloth-hi); border-radius: 2px;
  padding: .7rem .8rem; font-family: var(--body); font-size: .95rem;
  appearance: none; cursor: pointer;
}
.picker select:focus-visible { outline: 2px solid var(--chalk); outline-offset: 2px; }
.vs { font-family: var(--display); text-transform: uppercase; letter-spacing: .18em;
  color: var(--muted); font-size: .8rem; }

.readout { display: flex; justify-content: space-between; gap: 1rem;
  margin: 1.75rem 0 .5rem; font-family: var(--mono); }
.readout .side { font-size: 2rem; font-weight: 600; letter-spacing: -.03em; }
.readout .side:last-child { text-align: right; }
.readout .side small { display: block; font-size: .68rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); font-family: var(--body); }
.side-a { color: var(--chalk); }
.side-b { color: var(--gold); }

/* The bead wire: what players actually slide to count a race. */
.wire { position: relative; margin: 1.25rem 0 1rem; padding: 1.1rem 0; }
.wire::before { content: ""; position: absolute; left: 0; right: 0; top: 50%;
  height: 1px; background: var(--cloth-hi); }
.beads { position: relative; display: flex; justify-content: space-between; }
.beads .group { display: flex; gap: 5px; }
.beads .group.b { flex-direction: row-reverse; }
.bead { width: 13px; height: 13px; border-radius: 50%;
  background: var(--chalk); border: 1px solid rgba(0,0,0,.35);
  transition: transform .38s cubic-bezier(.34,1.4,.5,1), opacity .25s; }
.group.b .bead { background: var(--gold); }

.verdict { font-size: .95rem; color: var(--muted); margin: 0; }
.verdict b { color: var(--ivory); font-weight: 600; }
.caveat { margin: 1rem 0 0; font-size: .8rem; color: var(--chalk-lo); }

/* --- board ----------------------------------------------------------- */
.controls { display: flex; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.controls input, .controls select {
  background: var(--slate); color: var(--ivory); border: 1px solid var(--cloth);
  border-radius: 2px; padding: .55rem .75rem; font-family: var(--body); font-size: .9rem;
}
.controls input { flex: 1; min-width: 200px; }
.controls input::placeholder { color: var(--muted); }
.controls input:focus-visible, .controls select:focus-visible {
  outline: 2px solid var(--chalk); outline-offset: 1px; border-color: var(--chalk-lo); }

.scroller { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 540px; }
thead th { text-align: left; font-family: var(--display); text-transform: uppercase;
  letter-spacing: .14em; font-size: .68rem; font-weight: 700; color: var(--muted);
  padding: .5rem .6rem; border-bottom: 1px solid var(--cloth-hi); white-space: nowrap; }
tbody td { padding: .6rem; border-bottom: 1px solid rgba(28,72,85,.35); }
tbody tr:hover { background: rgba(28,72,85,.18); }
.rank { font-family: var(--mono); color: var(--muted); width: 3.2rem; font-size: .85rem; }
.rank.top { color: var(--gold); }
.who { font-weight: 500; }
.who a { text-decoration: none; color: var(--ivory); }
.who a:hover, .who a:focus-visible { color: var(--chalk); text-decoration: underline; }
.cc { font-family: var(--mono); font-size: .72rem; color: var(--muted); letter-spacing: .06em;
  white-space: nowrap; }
/* A hairline keeps white flags (Japan, England) from dissolving into the page. */
.flag {
  width: 20px; height: 14px; object-fit: cover; vertical-align: -2px;
  margin-right: .45rem; border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(233,230,221,.16);
}
.peek-cc .flag { margin-right: .35rem; }
.where .flag { width: 24px; height: 17px; vertical-align: -3px; margin-right: .5rem; }
.num { font-family: var(--mono); text-align: right; white-space: nowrap; }
.rating { font-size: 1.05rem; font-weight: 600; letter-spacing: -.02em; }
.dot { display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--gold); margin-left: .4rem; vertical-align: .18em; }
.reach { color: var(--muted); }
tr.penned .reach { color: var(--gold); }
.trend { color: var(--muted); font-size: .85rem; }
.trend.up { color: var(--chalk); }
.trend.down { color: var(--loss); }
.empty { padding: 2rem .6rem; color: var(--muted); }

/* --- player page ------------------------------------------------------ */
.profile { padding: clamp(1.75rem, 5vw, 3rem) 0 1rem; }
.profile h1 { font-family: var(--display); text-transform: uppercase;
  font-size: clamp(2rem, 6vw, 3.4rem); line-height: 1; letter-spacing: -.01em;
  margin: 0 0 .35rem; }
.profile .where { color: var(--muted); font-size: .9rem; margin: 0 0 1.75rem; }
.stats { display: grid; gap: 1.25rem 2rem;
  grid-template-columns: repeat(auto-fit, minmax(7rem, max-content));
  align-items: stretch; }
/* Rows rather than a flex column, so every label sits on the same baseline even
   though the rating beside them is twice the size. */
.stat { display: grid; grid-template-rows: 1fr auto; gap: .1rem; }
.stat b { font-family: var(--mono); font-size: 1.6rem; font-weight: 600; letter-spacing: -.02em; }
.stat span { color: var(--muted); text-transform: uppercase; letter-spacing: .12em;
  font-size: .66rem; }
.stat.hero-stat b { color: var(--chalk); font-size: 2.6rem; }

.games { display: grid; gap: .15rem; font-family: var(--mono); font-size: .85rem; }
.game { display: grid; grid-template-columns: 6rem 3.6rem 1fr; gap: .75rem;
  padding: .35rem 0; align-items: baseline; border-bottom: 1px solid rgba(28,72,85,.25); }
.game .sc { font-weight: 600; }
.game .sc.w { color: var(--chalk); }
.game .sc.l { color: var(--loss); }
.game .opp a { text-decoration: none; }
.game .ev { color: var(--muted); }
.game .dt { color: var(--muted); }
/* --- entering your own results --------------------------------------- */
/* Column labels. Placeholders alone were not enough: they vanish the moment
   someone types, and a row reading "Opponent / you / them" was being read as
   two player pickers. */
.entry-head {
  display: grid; grid-template-columns: 1fr 4.5rem auto 4.5rem 2rem;
  gap: .6rem; margin-bottom: .5rem;
  font-family: var(--display); text-transform: uppercase; letter-spacing: .12em;
  font-size: .62rem; color: var(--muted);
}
.entry-head span:nth-child(2), .entry-head span:nth-child(4) { text-align: center; }
.entry {
  display: grid; grid-template-columns: 1fr 4.5rem auto 4.5rem 2rem;
  gap: .6rem; align-items: center; margin-bottom: .6rem;
}
.entry input {
  background: var(--cloth); color: var(--ivory); border: 1px solid var(--cloth-hi);
  border-radius: 2px; padding: .6rem .7rem; font-family: var(--body); font-size: .95rem;
  min-width: 0;
}
.entry input[type="number"] { font-family: var(--mono); text-align: center; }
.entry input:focus-visible { outline: 2px solid var(--chalk); outline-offset: 1px; }
.entry .dash { color: var(--muted); text-align: center; }
.entry .drop {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 1.3rem; line-height: 1; padding: .2rem;
}
.entry .drop:hover, .entry .drop:focus-visible { color: var(--loss); }
#add { margin: .4rem 0 1.5rem; cursor: pointer; font-family: var(--body); }
#yardsticks { margin-top: 1rem; }
#yardsticks .sc { color: var(--chalk); }

@media (max-width: 620px) {
  .entry { grid-template-columns: 1fr 3.5rem auto 3.5rem 1.6rem; gap: .4rem; }
}

.bio { color: var(--ivory); font-size: .95rem; margin: -1.25rem 0 1.75rem;
  padding-left: .9rem; border-left: 2px solid var(--cloth-hi); }
.bio .src { color: var(--muted); font-size: .8rem; text-decoration: none; margin-left: .4rem; }
.bio .src:hover, .bio .src:focus-visible { color: var(--chalk); }

.simbar { display: block; height: 3px; background: var(--chalk);
  margin: .25rem 0 0 auto; border-radius: 2px; }
#results { margin-top: 1.25rem; }
#run { border: 0; cursor: pointer; font-family: var(--body); }
#run:disabled { opacity: .5; cursor: default; }

.bestwin { font-size: .95rem; color: var(--muted); margin: 1.25rem 0 0; }
.bestwin b { color: var(--ivory); font-weight: 600; }

/* Three obvious things to do, rather than three things we built. */
.doors { display: flex; flex-wrap: wrap; gap: .6rem; margin: 0 0 2rem; }
.door {
  display: inline-block; padding: .6rem 1.1rem;
  border: 1px solid var(--cloth-hi); border-radius: 2px;
  color: var(--ivory); text-decoration: none; font-size: .9rem;
  background: var(--slate);
}
.door:hover, .door:focus-visible { border-color: var(--chalk); color: var(--chalk); }

.prose { max-width: 62ch; }
.prose p { margin: 0 0 1rem; }
.prose h2 { font-family: var(--display); text-transform: uppercase; letter-spacing: .12em;
  font-size: .95rem; margin: 2rem 0 .75rem; }
.prose code { font-family: var(--mono); font-size: .85em; color: var(--chalk); }

/* --- scale explainer -------------------------------------------------- */
.scale { display: grid; gap: .1rem; font-family: var(--mono); font-size: .85rem; }
.scale-row { display: grid; grid-template-columns: 5.5rem 1fr 4rem; gap: .75rem;
  align-items: center; padding: .45rem 0; border-bottom: 1px solid rgba(28,72,85,.3); }
.scale-row span:first-child { color: var(--muted); }
.bar { height: 7px; background: var(--cloth); position: relative; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--chalk); display: block; }
.scale-row span:last-child { text-align: right; }

footer { border-top: 1px solid var(--cloth); padding: 2.5rem 0 3.5rem;
  color: var(--muted); font-size: .85rem; margin-top: 2rem; }
footer p { margin: 0 0 .6rem; max-width: 62ch; }

@media (max-width: 620px) {
  .picker { grid-template-columns: 1fr; }
  .vs { text-align: center; }
  .readout .side { font-size: 1.5rem; }
  .nav { gap: .9rem; font-size: .8rem; }
  .game { grid-template-columns: 5rem 3.2rem 1fr; gap: .5rem; font-size: .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
