:root {
  color-scheme: light dark;

  --paper: #faf9f5;
  --plate: #ffffff;
  --ink: #1a1916;
  --ink-2: #56534a;
  --ink-3: #857f71;
  --rule: #ddd8c9;
  --rule-strong: #b9b2a0;
  --loose: #a8442c;
  --tight: #2c5f7a;
  --mark: #f0ead6;

  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14140f;
    --plate: #1c1b16;
    --ink: #ece8dc;
    --ink-2: #a9a394;
    --ink-3: #7d776a;
    --rule: #35332b;
    --rule-strong: #514d42;
    --loose: #dc8464;
    --tight: #74aac9;
    --mark: #2a2820;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--paper); }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.02rem, 0.97rem + 0.25vw, 1.16rem);
  line-height: 1.6;
  text-rendering: optimizeLegibility;
}

.page {
  max-width: 39rem;
  margin: 0 auto;
  padding: clamp(2rem, 7vw, 5rem) 1.15rem clamp(3rem, 9vw, 6rem);
}

h1 {
  font-size: clamp(1.7rem, 1.35rem + 1.5vw, 2.5rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 1.3rem;
}

h2 {
  font-family: var(--sans);
  font-size: 0.79rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 3.2rem 0 1rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
}

p { margin: 0 0 1.05rem; }
p:last-child { margin-bottom: 0; }

.lede { font-size: 1.1em; color: var(--ink-2); }

.formula {
  font-family: var(--mono);
  font-size: 0.98rem;
  color: var(--ink);
  padding: 0.85rem 0 0.85rem 1rem;
  margin: 1.4rem 0;
  border-left: 3px solid var(--rule-strong);
}

var, code {
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.9em;
}

code {
  background: var(--mark);
  padding: 0.05em 0.3em;
  border-radius: 2px;
}

.loose-word { color: var(--loose); }
.tight-word { color: var(--tight); }

/* ---------- the specimen ---------- */

.specimen { margin: 1.6rem 0 0; }

.plate {
  background: var(--plate);
  border: 1px solid var(--rule);
  padding: clamp(0.9rem, 3vw, 1.5rem);
  overflow-x: auto;
}

/* Without the script this is an ordinary justified paragraph:
   the greedy result the text is talking about. */
#specimen-body {
  margin: 0;
  text-align: justify;
  hyphens: none;
  -webkit-hyphens: none;
}

.specimen.live #specimen-body {
  text-align: left;
  width: max-content;
}

.line { display: flex; align-items: stretch; gap: 10px; }

.gauge {
  position: relative;
  flex: 0 0 16px;
  width: 16px;
}

.gauge::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--rule);
}

.bar {
  position: absolute;
  top: 50%;
  height: 7px;
  margin-top: -3.5px;
  border-radius: 1px;
}

.bar.loose { background: var(--loose); }
.bar.tight { background: var(--tight); }
.bar.clipped.loose { border-right: 3px solid var(--ink); }
.bar.clipped.tight { border-left: 3px solid var(--ink); }

.line .text {
  display: block;
  width: var(--measure, auto);
  white-space: pre;
}

/* The measuring stick. It lives inside the paragraph so that it inherits the
   very font the lines are set in, and is parked outside the visible area. */
.ruler {
  position: absolute;
  left: -9999px;
  top: 0;
  white-space: pre;
  visibility: hidden;
  pointer-events: none;
  word-spacing: normal;
}

.note {
  font-family: var(--sans);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 0.7rem 0 0;
}

.specimen.live .nojs { display: none; }

/* ---------- the panel ---------- */

.panel {
  font-family: var(--sans);
  margin-top: 1.5rem;
  border: 1px solid var(--rule);
  background: var(--plate);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1.4rem;
  align-items: center;
  padding: 0.95rem 1rem;
  border-bottom: 1px solid var(--rule);
}

.group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.group-label,
.width-control label {
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
}

.choice { display: inline-flex; align-items: center; gap: 0.32rem; }

.panel label { font-size: 0.86rem; color: var(--ink); }
.panel .width-control label { font-size: 0.76rem; color: var(--ink-3); }

.width-control {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1 1 15rem;
  min-width: 12rem;
}

input[type="range"] { flex: 1 1 auto; min-width: 6rem; accent-color: var(--ink); }
input[type="radio"], input[type="checkbox"] { accent-color: var(--ink); }

output {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink-2);
  min-width: 4.2em;
  text-align: right;
}

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

/* ---------- scoreboard ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.8rem;
}

caption {
  text-align: left;
  padding: 0.8rem 1rem 0.5rem;
  color: var(--ink-3);
  font-size: 0.76rem;
  line-height: 1.45;
}

th, td { padding: 0.4rem 0.5rem; text-align: right; }
th:first-child, td:first-child { text-align: left; padding-left: 1rem; }
th:last-child, td:last-child { padding-right: 1rem; }

thead th {
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
  border-bottom: 1px solid var(--rule-strong);
  white-space: nowrap;
}

tbody td { border-bottom: 1px solid var(--rule); }
tbody tr:last-child td { border-bottom: 0; }
tbody .worst, tbody .total, tbody .rows { font-family: var(--mono); }

tbody tr[aria-current="true"] td { background: var(--mark); font-weight: 600; }

#summary {
  padding: 0 1rem 0.9rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-2);
  margin: 0;
}

/* ---------- sources ---------- */

.sources {
  margin-top: 3.4rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.76rem;
  line-height: 1.55;
  color: var(--ink-2);
}

.sources h2 { margin-top: 0; border-top: 0; padding-top: 0; }
.sources ol { margin: 0.4rem 0 0; padding-left: 1.15rem; }
.sources li { margin-bottom: 0.45rem; }

a { color: inherit; text-underline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 30rem) {
  .controls { gap: 0.8rem 1rem; }
  .group { flex-wrap: wrap; }
  table { font-size: 0.75rem; }
  th, td { padding: 0.38rem 0.35rem; }
}
