/* CouchDB vs MongoDB. One seam down the whole page; time played back, not plotted. */
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("fonts/bricolage.woff2") format("woff2");
  font-weight: 200 800; font-stretch: 75% 100%; font-display: swap;
}
:root {
  color-scheme: light dark;
  --paper: #f4f5f4;
  --paper-2: #e9ebea;
  --ink: #14181a;
  --ink-2: #59666c;
  --rule: #cbd3d2;
  --couch: #c62330;
  --mongo: #1f7d72;
  --couch-ground: #f8e6e8;
  --mongo-ground: #e1efec;
  --font: "Bricolage Grotesque", "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
  --measure: 62ch;
  --gutter: clamp(1rem, 4vw, 3rem);
  --seam: clamp(.7rem, 2.2vw, 1.8rem);   /* breathing room either side of the seam */
  --top-h: 3.4rem;
  --glass: rgba(244, 245, 244, .84);   /* paper you can half see through */
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131719;
    --paper-2: #1d2325;
    --ink: #eaeded;
    --ink-2: #98a5aa;
    --rule: #2c373a;
    --couch: #ef5a66;
    --mongo: #3fb3a4;
    --couch-ground: #1e1114;
    --mongo-ground: #0d1b19;
    --glass: rgba(19, 23, 25, .84);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 1.0625rem; line-height: 1.55;
  font-optical-sizing: auto; -webkit-font-smoothing: antialiased;
}
/* the two worlds and the seam, fixed behind everything */
body::before {
  content: ""; position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: -2;
  background: linear-gradient(90deg, var(--couch-ground) 50%, var(--mongo-ground) 50%);
}
body::after { content: ""; position: fixed; top: 0; bottom: 0; left: calc(50% - 1px); width: 2px; z-index: -1; background: var(--ink); opacity: .55; }
#bg { position: fixed; top: 0; left: 0; z-index: -1; width: 100%; height: 100%; pointer-events: none; }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .15em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: var(--gutter); top: -3rem; background: var(--ink); color: var(--paper); padding: .5rem .75rem; z-index: 20; }
.skip:focus { top: .5rem; }

p { margin: 0 0 1rem; }
ul, ol { padding-left: 1.2rem; }
li { margin-bottom: .45rem; }
code { font-family: var(--mono); font-size: .9em; background: var(--paper-2); padding: .1em .3em; border-radius: 3px; }
pre { margin: 0; overflow-x: auto; }
pre code { display: block; background: none; padding: 0; font-size: .84rem; line-height: 1.55; tab-size: 2; }
.c { color: var(--ink-2); }
.note { color: var(--ink-2); font-size: .95rem; }
strong { font-weight: 650; }
h2 { font-size: clamp(1.7rem, 1.2rem + 1.8vw, 2.5rem); font-weight: 700; letter-spacing: -.025em; line-height: 1.05; font-variation-settings: "wdth" 88; margin: 0 0 1.1rem; }

/* ---------- top bar: brand, the two controls that drive every number, nav */
.top {
  position: sticky; top: 0; z-index: 10; min-height: var(--top-h);
  display: flex; align-items: center; gap: .6rem 1.4rem; flex-wrap: wrap;
  padding: .45rem var(--gutter);
  background: var(--glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule); font-size: .9rem;
}
.brand { font-weight: 800; text-decoration: none; letter-spacing: -.03em; font-size: 1.1rem; font-variation-settings: "wdth" 80; }
.brand .couch { color: var(--couch); } .brand .mongo { color: var(--mongo); }
.top label { display: flex; align-items: center; gap: .45rem; color: var(--ink-2); }
select { max-width: 100%; font: inherit; font-size: .9rem; color: var(--ink); background: var(--paper-2); border: 1px solid var(--rule); border-radius: 4px; padding: .25rem .5rem; }
.speed { display: flex; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; }
.speed label { position: relative; cursor: pointer; }
.speed span { display: block; padding: .25rem .6rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.speed label + label { border-left: 1px solid var(--rule); }
.speed input:checked + span { background: var(--ink); color: var(--paper); }
.speed input { position: absolute; opacity: 0; top: 0; left: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.speed input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: -2px; }
.top nav { display: flex; gap: 1rem; flex-wrap: wrap; margin-left: auto; }
.top nav a { text-decoration: none; color: var(--ink-2); white-space: nowrap; }
.top nav a:hover { color: var(--ink); }
.credits { margin: 0; padding: .4rem var(--gutter); text-align: center; font-size: .85rem; color: var(--ink-2); background: var(--glass); border-bottom: 1px solid var(--rule); }
.credits a { color: var(--ink); font-weight: 600; white-space: nowrap; }

/* ---------- hero: names on the seam, then the first race, in real time */
main > * { scroll-margin-top: calc(var(--top-h) + .5rem); }
.hero { min-height: calc(100vh - var(--top-h)); min-height: calc(100svh - var(--top-h)); display: grid; grid-template-rows: 1fr auto auto; padding: clamp(1.5rem, 5vh, 4rem) 0 2.5rem; }
.names { display: grid; grid-template-columns: 1fr 1fr; align-items: end; margin: 0; }
.names span {
  display: block; font-size: clamp(2.4rem, 9.6vw, 9.6rem); font-weight: 800; letter-spacing: -.01em; line-height: .86;
  font-variation-settings: "wdth" 90;
}
.names .couch { text-align: right; padding-right: var(--seam); color: var(--couch); }
.names .mongo { text-align: left; padding-left: var(--seam); color: var(--mongo); }
.names small { display: block; font-size: clamp(.9rem, .7rem + .8vw, 1.25rem); font-weight: 400; letter-spacing: 0; line-height: 1.6; color: var(--ink-2); font-variation-settings: "wdth" 100; font-variant-numeric: tabular-nums; }
.hero .race { margin-top: clamp(1.5rem, 6vh, 4rem); }
.hero .race .n { font-size: clamp(2rem, 7vw, 6.5rem); }
.hero .race .fill { height: clamp(1.4rem, 4vw, 3.4rem); }
.hero .race h3 { font-size: clamp(1.05rem, 1rem + .6vw, 1.5rem); }
.hero .race .tally { font-size: clamp(1rem, .9rem + .5vw, 1.3rem); }
.hero .race h3 span { color: var(--ink-2); }
.hero .lede { grid-column: 1 / -1; text-align: center; max-width: 34ch; margin: clamp(1.5rem, 5vh, 3rem) auto 0; padding: 0 var(--gutter); font-size: clamp(1.05rem, .95rem + .6vw, 1.4rem); line-height: 1.35; color: var(--ink-2); }

/* ---------- a race: two lanes growing outward from the seam, counters at the far ends */
.race { display: grid; grid-template-columns: 1fr 1fr; align-items: center; row-gap: .35rem; margin: 1.4rem 0; }
.race h3, .race .tally { grid-column: 1 / -1; justify-self: center; max-width: 100%; text-align: center; margin: 0; padding: .15em .6em; background: var(--paper); border-radius: 4px; }
.race h3 { font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; }
.race h3 button { font: inherit; font-size: .8rem; color: var(--ink-2); background: none; border: 1px solid var(--rule); border-radius: 4px; padding: .1rem .5rem; margin-left: .6rem; cursor: pointer; vertical-align: middle; }
.race h3 button:hover { color: var(--ink); border-color: var(--ink); }
.lane { display: flex; align-items: center; gap: .6rem; min-width: 0; --p: 0; --nw: clamp(6rem, 4rem + 4vw, 9.5rem); }
.hero .lane { --nw: clamp(8rem, 24vw, 25rem); }
.lane.couch { justify-content: flex-end; padding-right: var(--seam); }
.lane.mongo { justify-content: flex-end; padding-left: var(--seam); flex-direction: row-reverse; } /* row-reverse: flex-end is the left edge, so the fill leaves the seam */
.fill { flex: 0 0 auto; width: calc(var(--p) * (100% - var(--nw) - .6rem)); height: 1.6rem; border-radius: 3px; }
.lane.couch .fill { background: var(--couch); border-radius: 3px 0 0 3px; }
.lane.mongo .fill { background: var(--mongo); border-radius: 0 3px 3px 0; }
.race:not([data-unit="ms"]) .fill { transition: width .7s cubic-bezier(.2, .7, .2, 1); }
.n { font-size: clamp(1.25rem, 1rem + 1.4vw, 2.4rem); font-weight: 700; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; flex: 0 0 auto; min-width: var(--nw); }
.lane.couch .n { text-align: right; } .lane.mongo .n { text-align: left; }
.n small { font-size: .5em; font-weight: 500; color: var(--ink-2); letter-spacing: 0; margin-left: .15em; }
.lane.couch .n { color: var(--couch); } .lane.mongo .n { color: var(--mongo); }
.lane.na .n { color: var(--ink-2); font-size: 1rem; font-weight: 500; }
.tally { color: var(--ink-2); font-size: .95rem; min-height: 1.5em; }
.tally b { color: var(--ink); font-weight: 650; }
.tally:empty { visibility: hidden; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .fill { transition: none !important; } }

/* ---------- bridges: prose on paper across both worlds */
.bridge { background: var(--paper); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: clamp(2.5rem, 6vw, 5rem) var(--gutter); margin: clamp(2rem, 5vw, 4rem) 0; text-align: center; }
.bridge ul, .bridge ol { list-style-position: inside; padding-left: 0; }
.bridge pre { text-align: left; }
.bridge + .bridge { margin-top: calc(-1 * clamp(2rem, 5vw, 4rem) - 1px); }
.bridge .in { max-width: var(--measure); margin: 0 auto; }
.bridge .in.wide { max-width: 76rem; }
.in.wide > :is(p, ol, ul) { max-width: var(--measure); margin-inline: auto; }
.claim { margin-inline: auto; font-size: clamp(1.45rem, 1.1rem + 1.9vw, 2.7rem); font-weight: 600; letter-spacing: -.03em; line-height: 1.12; font-variation-settings: "wdth" 85; max-width: 24ch; margin-bottom: 1.4rem; }
.claim .couch { color: var(--couch); } .claim .mongo { color: var(--mongo); }

/* ---------- verdict: each side gets its own column */
.wins { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin: 0 0 .5rem; }
.wins > div { padding: 0 var(--seam); }
.wins .couch { text-align: right; padding-left: var(--gutter); }
.wins .mongo { text-align: left; padding-right: var(--gutter); }
.wins h2 { font-size: clamp(1.4rem, 1rem + 1.6vw, 2.3rem); }
.wins .couch h2 { color: var(--couch); } .wins .mongo h2 { color: var(--mongo); }
.wins ul { list-style: none; padding: 0; margin: 0; max-width: 36ch; }
.wins .couch ul { margin-left: auto; }
.wins li { margin-bottom: .9rem; }
.wins li b { display: block; font-weight: 650; }

/* ---------- experiments live on the split */
.exp { display: grid; grid-template-columns: 1fr 1fr; padding: clamp(2rem, 5vw, 4rem) 0 1rem; }
.exp > * { grid-column: 1 / -1; }
.exp header { text-align: center; padding: 0 var(--gutter); max-width: var(--measure); margin: 0 auto 1rem; }
.exp header h2, .exp header p { width: -webkit-fit-content; width: fit-content; max-width: 100%; margin-inline: auto; background: var(--paper); padding: .15em .5em; border-radius: 4px; }
.exp header h2 { font-size: clamp(1.6rem, 1.2rem + 1.8vw, 2.6rem); }
.exp header h2 i { font-style: normal; color: var(--ink-2); font-weight: 400; font-variant-numeric: tabular-nums; margin-right: .35em; }
.exp header p { color: var(--ink-2); }
.pair { display: grid; grid-template-columns: 1fr 1fr; margin: 1rem 0 .6rem; }
.pane { margin: 0; min-width: 0; position: relative; }
.pane.couch { padding: 0 var(--seam) 0 var(--gutter); }
.pane.mongo { padding: 0 var(--gutter) 0 var(--seam); }
.pane figcaption { font-weight: 650; font-size: .95rem; margin-bottom: .45rem; }
.pane.couch figcaption { color: var(--couch); text-align: right; }
.pane.mongo figcaption { color: var(--mongo); }
.pane pre { position: relative; background: var(--glass); border: 1px solid var(--rule); padding: .9rem 1rem; border-radius: 6px; }
.copy { position: absolute; top: .5rem; right: .5rem; font: inherit; font-size: .75rem; color: var(--ink-2); background: var(--paper); border: 1px solid var(--rule); border-radius: 4px; padding: .15rem .5rem; cursor: pointer; }
.copy:hover { color: var(--ink); }
.obs { max-width: var(--measure); margin: .6rem auto 0; padding: 0 var(--gutter); }
.note { text-align: center; }
.obs summary { cursor: pointer; color: var(--ink-2); font-size: .95rem; padding: .3rem 0; text-align: center; }
.obs summary:hover { color: var(--ink); }
.obs ul { margin: .6rem 0 0; background: var(--glass); border: 1px solid var(--rule); border-radius: 6px; padding: 1rem 1rem 1rem 2.2rem; }

/* ---------- comparison table, feature on the seam */
.scroll { overflow-x: auto; }
.compare { border-collapse: collapse; width: 100%; font-size: .95rem; }
.compare th, .compare td { padding: .8rem 1rem; vertical-align: top; text-align: left; border-bottom: 1px solid var(--rule); }
.compare thead th { font-weight: 700; font-size: 1.05rem; }
.compare thead th.couch { color: var(--couch); text-align: right; }
.compare thead th.mongo { color: var(--mongo); }
.compare thead th:nth-child(2), .compare tbody th { text-align: center; border-left: 2px solid var(--ink); border-right: 2px solid var(--ink); }
.compare tbody th { font-weight: 600; width: 16%; }
.compare td { width: 42%; }
.compare td[data-label="CouchDB"] { text-align: right; }
sup a { text-decoration: none; color: var(--ink-2); padding-left: .1em; }
.footnotes { font-size: .875rem; color: var(--ink-2); margin-top: 1.2rem; }

/* ---------- every number */
#numbers { border-collapse: collapse; font-size: .875rem; font-variant-numeric: tabular-nums; margin-top: .6rem; white-space: nowrap; }
#numbers th, #numbers td { text-align: right; padding: .3rem .7rem; border-bottom: 1px solid var(--rule); }
#numbers th:first-child, #numbers td:first-child { text-align: left; }
#numbers td.couch { color: var(--couch); } #numbers td.mongo { color: var(--mongo); }

/* ---------- reproduce, explorer, footer */
#reproduce pre { background: var(--paper-2); padding: 1rem 1.1rem; border-radius: 6px; margin: 0 0 1rem; position: relative; }
.controls { display: flex; justify-content: center; gap: .8rem 1.6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.2rem; font-size: .95rem; }
.controls label { display: flex; align-items: center; gap: .5rem; color: var(--ink-2); max-width: 100%; }
.controls select { min-width: 0; }   /* a long option list must shrink, not push the page sideways */
.chart { max-width: 56rem; margin: 0 auto; }
.bridge details { margin-top: 1.4rem; }
#numbers-section .scroll { display: inline-block; max-width: 100%; }
.chart figcaption { font-weight: 600; font-size: .95rem; margin-bottom: .4rem; }
.chart canvas { width: 100% !important; }
footer { padding: 1.5rem var(--gutter) 3rem; color: var(--ink-2); font-size: .9rem; text-align: center; }
footer p { max-width: var(--measure); margin: 0 auto; }

/* ---------- narrow screens: the seam stays, the code stacks */
@media (max-width: 720px) {
  .pair { grid-template-columns: 1fr; gap: 1rem; }
  .pane.couch, .pane.mongo { padding: 0 var(--gutter); }
  .pane.couch figcaption { text-align: left; }
  .wins { grid-template-columns: 1fr; }
  .wins .couch { text-align: center; padding: 0 var(--gutter) 1.5rem; }
  .wins .mongo { text-align: center; }
  .wins ul { margin-inline: auto; }
  .wins .couch ul { margin-left: 0; }
  .wins .mongo { padding: 0 var(--gutter); }
  .compare thead { display: none; }
  .compare, .compare tbody, .compare tr, .compare th, .compare td { display: block; width: auto; }
  .compare tr { display: flex; flex-direction: column; padding: .8rem 0; border-bottom: 1px solid var(--rule); }
  .compare tbody th { order: -1; width: auto; text-align: left; border: 0; padding: 0 0 .4rem; font-size: 1.05rem; }
  .compare td, .compare td[data-label="CouchDB"] { text-align: left; border: 0; padding: .2rem 0 .3rem .9rem; border-left: 3px solid; }
  .compare td[data-label="CouchDB"] { border-color: var(--couch); }
  .compare td[data-label="MongoDB"] { border-color: var(--mongo); }
  .compare td::before { content: attr(data-label); display: block; font-size: .8rem; font-weight: 600; }
  .compare td[data-label="CouchDB"]::before { color: var(--couch); }
  .compare td[data-label="MongoDB"]::before { color: var(--mongo); }
  .lane { --nw: 5rem; } .hero .lane { --nw: 8.5rem; }
  .fill { height: 1.2rem; }
  .n { font-size: 1.1rem; }
  .hero .race .n { font-size: clamp(1.6rem, 9vw, 2.6rem); }
  .top { gap: .5rem .9rem; font-size: .85rem; }
  .top nav { margin-left: 0; gap: .9rem; flex-wrap: nowrap; overflow-x: auto; width: 100%; scrollbar-width: none; }
  .top nav::-webkit-scrollbar { display: none; }
  select { font-size: 1rem; }   /* under 16px iOS zooms the page when a select opens */
}
.file { margin-top: .6rem; }
.file summary { cursor: pointer; color: var(--ink-2); padding: .3rem 0; }
.file summary:hover { color: var(--ink); }
.file[open] summary { margin-bottom: .6rem; }
