:root {
  --paper: #f8f4eb;
  --paper-deep: #eee5d5;
  --ink: #1f2926;
  --muted: #5d655f;
  --line: #c9c0af;
  --line-strong: #928a7d;
  --accent: #6f2030;
  --accent-dark: #511421;
  --accent-soft: #f0dfe1;
  --green: #2f5b4f;
  --gold: #b77b23;
  --white: #fffdf8;
  --error: #9c2525;
  --shadow: 0 18px 48px rgb(31 41 38 / 10%);
  --radius: 0.55rem;
  --content: 76rem;
  --serif: Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scroll-behavior: smooth;
  scroll-padding-top: 5.5rem;
}

body {
  min-width: 18rem;
  margin: 0;
  overflow-x: clip;
  color: var(--ink);
  background:
    linear-gradient(rgb(31 41 38 / 2%) 1px, transparent 1px) 0 0 / 100% 2rem,
    var(--paper);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button:not(:disabled),
select:not(:disabled),
input[type="radio"]:not(:disabled) {
  cursor: pointer;
}

a {
  color: var(--accent-dark);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

a:hover {
  text-decoration-thickness: 0.14em;
}

:focus-visible {
  outline: 3px solid #1675a1;
  outline-offset: 3px;
}

::selection {
  color: var(--white);
  background: var(--accent);
}

h1,
h2,
h3,
p,
figure,
dl,
dd {
  margin-block-start: 0;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

h1 {
  max-width: 16ch;
  margin-block-end: 1rem;
  font-size: clamp(2.5rem, 5vw, 3.8rem);
}

h2 {
  margin-block-end: 0.75rem;
  font-size: clamp(2rem, 4vw, 3.45rem);
}

h3 {
  margin-block-end: 0.55rem;
  font-size: 1.35rem;
}

.no-js .js-only,
.js .no-js-only {
  display: none !important;
}

.no-js .system-switch span,
.no-js .input-shell {
  opacity: 0.62;
}

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

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--white);
  background: var(--ink);
  transform: translateY(-180%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header,
main > section,
.site-footer {
  width: min(calc(100% - 2rem), var(--content));
  margin-inline: auto;
}

.site-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4.8rem;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  gap: 0.65rem;
  color: var(--ink);
  font-weight: 760;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  color: var(--white);
  background: var(--accent);
  border-radius: 50%;
  font-family: var(--serif);
  font-size: 1.15rem;
}

.primary-nav {
  display: flex;
  align-items: center;
  gap: clamp(0.5rem, 2vw, 1.4rem);
}

.primary-nav a,
.nav-action {
  min-height: 2.75rem;
  padding: 0.6rem 0.15rem;
  color: var(--ink);
  background: transparent;
  border: 0;
  font-weight: 650;
  text-decoration: none;
}

.nav-action {
  color: var(--accent-dark);
}

.hero {
  padding-block: clamp(2.5rem, 4vw, 4rem) clamp(4rem, 8vw, 7rem);
}

.hero-heading {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(16rem, 0.65fr);
  align-items: end;
  gap: 1.5rem 4rem;
  margin-bottom: clamp(1.5rem, 3vw, 2.5rem);
}

.hero-heading .eyebrow,
.hero-heading h1 {
  grid-column: 1;
}

.hero-heading .eyebrow {
  align-self: end;
  margin-bottom: -0.2rem;
}

.hero-heading h1 {
  margin-bottom: 0;
}

.hero-deck {
  grid-column: 2;
  grid-row: 1 / span 2;
  max-width: 34rem;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: clamp(1.05rem, 1.7vw, 1.28rem);
}

.eyebrow {
  margin-bottom: 0.55rem;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 820;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(20rem, 5fr);
  overflow: hidden;
  background: var(--white);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}

.converter-column {
  min-width: 0;
  padding: clamp(1.25rem, 4vw, 3rem);
  border-right: 1px solid var(--line);
}

.converter-form fieldset {
  padding: 0;
  margin: 0;
  border: 0;
}

.converter-form {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 0 1.25rem;
}

.converter-form .example-row {
  grid-column: 1 / -1;
}

.converter-form legend,
.converter-form label,
.chart-toolbar label,
.compare-controls label,
.gauge-form label,
.control-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.83rem;
  font-weight: 780;
  letter-spacing: 0.025em;
}

.system-switch {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.system-switch label {
  position: relative;
  min-width: 0;
  margin: 0;
}

.system-switch label + label {
  border-left: 1px solid var(--line);
}

.system-switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.system-switch span {
  display: grid;
  min-height: 3rem;
  padding: 0.5rem 0.35rem;
  place-items: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 730;
  text-align: center;
}

.system-switch input:checked + span {
  color: var(--white);
  background: var(--ink);
}

.system-switch input:focus-visible + span {
  outline: 3px solid #1675a1;
  outline-offset: -3px;
}

.field-note,
.field-error,
.source-credit {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.field-error {
  color: var(--error);
  font-weight: 700;
}

.input-group {
  margin-top: 0;
}

.input-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
}

.input-shell:focus-within {
  outline: 3px solid #1675a1;
  outline-offset: 2px;
}

.input-shell input {
  width: 100%;
  min-height: 4.4rem;
  padding: 0.65rem 1rem;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: clamp(1.8rem, 5vw, 2.65rem);
  font-variant-numeric: tabular-nums;
  font-weight: 720;
}

.input-context {
  min-width: 4.8rem;
  padding: 0.5rem 1rem;
  color: var(--muted);
  border-left: 1px solid var(--line);
  font-size: 0.9rem;
  font-weight: 760;
  text-align: center;
}

.example-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.65rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.example-row button,
.text-button,
.table-use {
  min-height: 2.75rem;
  padding: 0.35rem 0;
  color: var(--accent-dark);
  background: transparent;
  border: 0;
  font-weight: 740;
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

.result-panel {
  position: relative;
  margin-top: 1.75rem;
  padding-top: 1.35rem;
  border-top: 1px solid var(--line-strong);
}

.result-panel[aria-busy="true"] {
  opacity: 0.65;
}

.result-topline {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.match-status,
.result-interpretation {
  margin: 0;
  font-size: 0.82rem;
}

.match-status {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.15rem 0.65rem;
  color: var(--green);
  background: #e5eee8;
  border: 1px solid #9fb5a8;
  border-radius: 999px;
  font-weight: 800;
}

.match-status--nearest,
.match-status--conflict {
  color: #67420c;
  background: #f7ebcc;
  border-color: #d0ae68;
}

.match-status--error {
  color: var(--error);
  background: #fae6e3;
  border-color: #d79d96;
}

.result-interpretation {
  color: var(--muted);
  text-align: right;
}

.result-primary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 0 1rem;
  margin-bottom: 1.1rem;
}

.result-label {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 720;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#result-title {
  display: block;
  color: var(--accent);
  font-family: var(--serif);
  font-size: clamp(3rem, 8vw, 5.35rem);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.055em;
}

#result-inch {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.equivalent-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.equivalent-grid > div {
  min-width: 0;
  padding: 0.9rem 0.75rem 0.95rem 0;
}

.equivalent-grid > div + div {
  padding-left: 0.75rem;
  border-left: 1px solid var(--line);
}

.equivalent-grid dt {
  margin-bottom: 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.equivalent-grid dd {
  margin: 0;
}

.result-value,
.result-relation {
  display: block;
  overflow-wrap: anywhere;
}

.result-value {
  margin-bottom: 0.15rem;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
  font-weight: 790;
}

.result-relation {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.variation-note,
.yarn-note {
  margin: 1rem 0 0;
  font-size: 0.88rem;
}

.variation-note {
  padding-left: 0.8rem;
  color: var(--muted);
  border-left: 3px solid var(--gold);
}

.candidate-picker {
  padding: 1rem;
  margin-top: 1rem;
  background: #f7ebcc;
  border: 1px solid #d0ae68;
}

.candidate-picker p {
  margin-bottom: 0.65rem;
}

.candidate-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.result-actions,
.chart-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.button {
  min-height: 2.75rem;
  padding: 0.55rem 0.9rem;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--line-strong);
  border-radius: 0.35rem;
  font-size: 0.87rem;
  font-weight: 760;
}

.button:hover {
  background: var(--paper-deep);
}

.button--primary {
  color: var(--white);
  background: var(--accent);
  border-color: var(--accent);
}

.button--primary:hover {
  background: var(--accent-dark);
}

.button[aria-pressed="true"] {
  color: var(--white);
  background: var(--green);
  border-color: var(--green);
}

.noscript-note {
  padding: 1rem;
  background: #f7ebcc;
  border: 1px solid #d0ae68;
}

.diameter-figure {
  display: flex;
  min-width: 0;
  padding: clamp(1.4rem, 3.5vw, 2.75rem);
  margin: 0;
  flex-direction: column;
  justify-content: center;
  background:
    radial-gradient(circle at 82% 18%, rgb(183 123 35 / 12%), transparent 38%),
    var(--paper-deep);
}

.diameter-figure h2 {
  max-width: 12ch;
  font-size: clamp(2rem, 3.5vw, 3rem);
}

.diameter-figure figcaption > p:last-child {
  color: var(--muted);
}

#diameter-visual {
  display: block;
  width: 100%;
  height: auto;
  margin-block: 1rem;
}

.needle-row text,
.disc-figure text {
  fill: var(--ink);
  font-family: var(--sans);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.needle-row--muted {
  opacity: 0.72;
}

.figure-warning {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.section-rule {
  padding-block: clamp(4rem, 9vw, 7rem);
  border-top: 1px solid var(--line-strong);
}

.section-heading {
  max-width: 46rem;
  margin-bottom: 2rem;
}

.section-heading > p:last-child {
  color: var(--muted);
}

.section-heading--split {
  display: flex;
  max-width: none;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
}

.section-heading--split > div:first-child {
  max-width: 48rem;
}

.chart-actions {
  flex: 0 0 auto;
  justify-content: end;
  margin: 0;
}

.chart-toolbar {
  display: grid;
  grid-template-columns: minmax(15rem, 1.5fr) minmax(12rem, 0.8fr) auto auto;
  align-items: end;
  gap: 1rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: var(--paper-deep);
  border: 1px solid var(--line);
}

.chart-toolbar input,
.chart-toolbar select,
.compare-controls select,
.number-with-unit {
  width: 100%;
  min-height: 2.9rem;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--line-strong);
  border-radius: 0.25rem;
}

.chart-toolbar input,
.chart-toolbar select,
.compare-controls select {
  padding: 0.55rem 0.7rem;
}

.chart-count {
  align-self: center;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.scroll-hint {
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  border: 1px solid var(--line-strong);
  background: var(--white);
}

.table-scroll:focus-visible {
  outline-offset: 4px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

caption {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.needle-table {
  min-width: 52rem;
}

.needle-table th,
.needle-table td,
.yarn-table th,
.yarn-table td {
  padding: 0.8rem 1rem;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.needle-table thead th,
.yarn-table thead th {
  position: sticky;
  z-index: 3;
  top: 0;
  color: var(--white);
  background: var(--ink);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.needle-table th:first-child {
  position: sticky;
  z-index: 2;
  left: 0;
  min-width: 10rem;
  background: var(--paper);
}

.needle-table thead th:first-child {
  z-index: 4;
  background: var(--ink);
}

.needle-table tr:last-child > *,
.yarn-table tr:last-child > * {
  border-bottom: 0;
}

.needle-table tr > *:last-child,
.yarn-table tr > *:last-child {
  border-right: 0;
}

.needle-table tbody tr:nth-child(even) td {
  background: rgb(238 229 213 / 33%);
}

.needle-table tbody tr.is-selected > * {
  background: var(--accent-soft);
  box-shadow: inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent);
}

.needle-table tbody tr.is-candidate > * {
  background: #f7ebcc;
  box-shadow: inset 0 1px 0 var(--gold), inset 0 -1px 0 var(--gold);
}

.needle-table tbody tr[hidden] {
  display: none;
}

.table-use {
  min-width: 3.6rem;
  min-height: 2.75rem;
  text-align: left;
  white-space: nowrap;
}

.table-use:disabled {
  min-height: 0;
  color: var(--ink);
  cursor: default;
  text-decoration: none;
}

.mapping {
  display: inline-block;
  padding: 0.12rem 0.3rem;
  border-radius: 0.2rem;
  font-weight: 720;
}

.mapping--manufacturer {
  color: #2c4d44;
  background: #e5eee8;
}

.mapping--source-dependent {
  color: #67420c;
  background: #f7ebcc;
}

.mapping-separator,
.chart-note {
  color: var(--muted);
}

.chart-note {
  font-size: 0.8rem;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.chart-legend p {
  margin: 0;
}

.chart-legend p:last-child {
  flex-basis: 100%;
}

.saved-section {
  padding-block: 2.5rem;
}

.saved-section h2 {
  font-size: 2rem;
}

.saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.saved-item {
  display: flex;
  align-items: center;
  min-height: 3rem;
  gap: 0.25rem;
  padding: 0.25rem 0.35rem 0.25rem 0.8rem;
  background: var(--white);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
}

.saved-item button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 50%;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.compare-layout,
.gauge-layout,
.method-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(2rem, 6vw, 5rem);
  align-items: center;
}

.compare-controls {
  display: grid;
  gap: 1.2rem;
}

.compare-controls strong {
  display: block;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 3rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.compare-controls output {
  display: block;
  padding: 1rem;
  background: var(--white);
  border-left: 4px solid var(--accent);
  font-weight: 700;
}

.disc-figure {
  margin: 0;
  text-align: center;
}

.disc-figure svg {
  display: block;
  width: 100%;
  height: auto;
}

.disc-figure figcaption {
  color: var(--muted);
  font-size: 0.8rem;
}

.gauge-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.gauge-form > p,
.gauge-form > button {
  grid-column: 1 / -1;
}

.gauge-form > p {
  margin: 0;
}

.number-with-unit {
  display: grid;
  grid-template-columns: minmax(4.5rem, 0.7fr) minmax(8rem, 1.3fr);
  align-items: center;
  overflow: hidden;
}

.number-with-unit:focus-within {
  outline: 3px solid #1675a1;
  outline-offset: 2px;
}

.number-with-unit input {
  width: 100%;
  min-height: 3rem;
  padding: 0.45rem 0.65rem;
  border: 0;
  border-right: 1px solid var(--line);
  outline: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.number-with-unit span {
  padding-inline: 0.65rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.gauge-result {
  display: grid;
  gap: 0.6rem;
  padding: clamp(1.4rem, 4vw, 2.5rem);
  background: var(--ink);
  color: var(--white);
}

.gauge-result strong {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  line-height: 1.1;
}

.gauge-result > span:last-child {
  color: #d8ddd9;
  font-size: 0.88rem;
}

.gauge-direction {
  color: #f3c977;
  font-size: 0.78rem;
  font-weight: 820;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ambiguity-section {
  display: grid;
  grid-template-columns: minmax(0, 0.75fr) minmax(0, 1.25fr);
  gap: 3rem;
  align-items: end;
}

.ambiguity-copy p:last-child {
  color: var(--muted);
}

.ambiguity-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.ambiguity-options button {
  display: grid;
  min-height: 7.5rem;
  padding: 1rem;
  align-content: space-between;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--line-strong);
  text-align: left;
}

.ambiguity-options button:hover {
  border-color: var(--accent);
  box-shadow: inset 0 -4px 0 var(--accent);
}

.ambiguity-options strong {
  color: var(--accent);
  font-family: var(--serif);
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
}

.yarn-table {
  min-width: 42rem;
}

.yarn-table tbody th {
  background: var(--paper);
}

.yarn-number {
  display: inline-grid;
  width: 2rem;
  height: 2rem;
  margin-right: 0.45rem;
  place-items: center;
  color: var(--white);
  background: var(--accent);
  border-radius: 50%;
}

.yarn-alias {
  display: block;
  margin-left: 2.65rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.measure-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 0;
  margin: 0 0 1.5rem;
  list-style: none;
  counter-reset: none;
  border-top: 1px solid var(--line-strong);
}

.measure-steps li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1rem;
  padding: 1.5rem 1.25rem 1.5rem 0;
}

.measure-steps li + li {
  padding-left: 1.25rem;
  border-left: 1px solid var(--line);
}

.measure-steps li > span {
  color: var(--accent);
  font-family: var(--serif);
  font-size: 2rem;
  line-height: 1;
}

.measure-steps p {
  margin: 0;
  color: var(--muted);
}

.definition-list {
  margin: 0;
}

.definition-list > div {
  display: grid;
  grid-template-columns: minmax(9rem, 0.65fr) minmax(0, 1.35fr);
  gap: 1rem;
  padding-block: 0.85rem;
  border-top: 1px solid var(--line);
}

.definition-list dt {
  font-weight: 780;
}

.definition-list dd {
  color: var(--muted);
}

.source-list {
  padding-left: 1.2rem;
}

.source-list li {
  margin-block: 0.55rem;
}

.site-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2rem;
  padding-block: 3rem 2rem;
  border-top: 1px solid var(--line-strong);
}

.site-footer > div p,
.footer-note {
  color: var(--muted);
  font-size: 0.82rem;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 0.5rem 1.2rem;
}

.site-footer nav a {
  min-height: 2.75rem;
  padding-block: 0.6rem;
}

.footer-note {
  grid-column: 1 / -1;
  padding-top: 1rem;
  margin: 0;
  border-top: 1px solid var(--line);
}

.legal-dialog {
  width: min(56rem, calc(100% - 2rem));
  max-width: none;
  max-height: min(52rem, calc(100dvh - 2rem));
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  box-shadow: 0 22px 80px rgb(0 0 0 / 35%);
}

.legal-dialog::backdrop {
  background: rgb(19 25 23 / 70%);
  backdrop-filter: blur(2px);
}

.dialog-bar,
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4rem;
  gap: 1rem;
  padding: 0.65rem 1.2rem;
  background: var(--white);
}

.dialog-bar {
  border-bottom: 1px solid var(--line);
}

.dialog-footer {
  border-top: 1px solid var(--line);
}

.dialog-footer a {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
}

.dialog-bar p {
  margin: 0;
  font-weight: 800;
}

.dialog-close {
  min-height: 2.75rem;
  padding: 0.4rem 0.7rem;
  color: var(--accent-dark);
  background: transparent;
  border: 1px solid var(--line-strong);
}

.legal-dialog-content {
  max-height: calc(100dvh - 10rem);
  padding: clamp(1.25rem, 4vw, 3rem);
  overflow-y: auto;
}

.legal-dialog-content article,
.legal-main article {
  max-width: 46rem;
  margin-inline: auto;
}

.legal-dialog-content h1,
.legal-main h1 {
  max-width: 20ch;
  font-size: clamp(2.2rem, 5vw, 4rem);
}

.legal-dialog-content h2,
.legal-main h2 {
  margin-top: 2rem;
  font-size: 1.55rem;
}

.legal-dialog-content li,
.legal-main li {
  margin-block: 0.45rem;
}

.legal-page {
  background: var(--paper);
}

.legal-header,
.legal-footer {
  display: flex;
  width: min(calc(100% - 2rem), 50rem);
  min-height: 4.8rem;
  margin-inline: auto;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
}

.legal-footer a {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
}

.legal-footer {
  min-height: 5rem;
  justify-content: flex-start;
  gap: 1.5rem;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.legal-warning {
  padding: 1rem;
  color: #67420c;
  background: #f7ebcc;
  border: 1px solid #d0ae68;
}

.simple-main {
  width: min(calc(100% - 2rem), 46rem);
  min-height: 100dvh;
  padding-block: clamp(4rem, 12vw, 9rem);
  margin-inline: auto;
}

.simple-main h1 {
  max-width: 14ch;
}

.legal-main {
  width: min(calc(100% - 2rem), 50rem);
  min-height: calc(100vh - 12rem);
  padding-block: clamp(3rem, 8vw, 6rem);
  margin-inline: auto;
}

.prelaunch-notice {
  padding: 1rem;
  margin-bottom: 2rem;
  color: #67420c;
  background: #f7ebcc;
  border: 1px solid #d0ae68;
}

.toast {
  position: fixed;
  z-index: 100;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  max-width: min(22rem, calc(100% - 2rem));
  padding: 0.8rem 1rem;
  color: var(--white);
  background: var(--ink);
  border: 1px solid #aeb8b3;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
}

@media (max-width: 58rem) {
  .primary-nav a:nth-child(2),
  .primary-nav a:nth-child(3) {
    display: none;
  }

  .hero-heading,
  .workbench,
  .ambiguity-section {
    grid-template-columns: 1fr;
  }

  .hero-heading .eyebrow,
  .hero-heading h1,
  .hero-deck {
    grid-column: 1;
    grid-row: auto;
  }

  .hero-deck {
    max-width: 46rem;
  }

  .converter-column {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chart-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .compare-layout,
  .gauge-layout,
  .method-grid {
    gap: 2.5rem;
  }
}

@media (max-width: 42rem) {
  html {
    scroll-padding-top: 1rem;
  }

  .site-header {
    min-height: 4rem;
  }

  .brand-name {
    display: none;
  }

  .primary-nav a:nth-child(3),
  .primary-nav .nav-action:not(:last-child) {
    display: none;
  }

  .hero {
    padding-top: 1.5rem;
  }

  h1 {
    font-size: clamp(2.1rem, 10vw, 2.75rem);
  }

  .hero-deck {
    font-size: 1rem;
  }

  .hero-heading {
    margin-bottom: 1.15rem;
  }

  .workbench {
    width: calc(100% + 1rem);
    margin-left: -0.5rem;
  }

  .converter-form {
    display: block;
  }

  .converter-form fieldset {
    margin-bottom: 1rem;
  }

  .system-switch span {
    min-height: 3.5rem;
    padding-inline: 0.18rem;
    font-size: 0.7rem;
    line-height: 1.2;
  }

  .input-group {
    margin-top: 0;
  }

  .example-row {
    display: none;
  }

  .result-topline,
  .section-heading--split {
    align-items: flex-start;
    flex-direction: column;
  }

  .result-topline {
    display: flex;
  }

  .result-interpretation {
    text-align: left;
  }

  .equivalent-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .equivalent-grid > div:nth-child(3) {
    padding-left: 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .equivalent-grid > div:nth-child(4) {
    border-top: 1px solid var(--line);
  }

  .chart-toolbar,
  .compare-layout,
  .gauge-layout,
  .method-grid,
  .gauge-form,
  .site-footer {
    grid-template-columns: 1fr;
  }

  .chart-count {
    align-self: end;
  }

  .chart-toolbar .text-button {
    justify-self: start;
  }

  .chart-actions {
    justify-content: flex-start;
  }

  .gauge-form > p,
  .gauge-form > button {
    grid-column: 1;
  }

  .ambiguity-options,
  .measure-steps {
    grid-template-columns: 1fr;
  }

  .ambiguity-options button {
    min-height: 5.5rem;
  }

  .measure-steps li,
  .measure-steps li + li {
    padding-inline: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .site-footer nav {
    justify-content: flex-start;
  }

  .footer-note {
    grid-column: 1;
  }

  .legal-dialog {
    width: 100%;
    max-height: 92dvh;
    margin: auto 0 0;
    border-width: 1px 0 0;
  }

  .legal-dialog-content {
    max-height: calc(92dvh - 8rem);
  }
}

@media (max-width: 23rem) {
  .site-header,
  main > section,
  .site-footer {
    width: min(calc(100% - 1.25rem), var(--content));
  }

  .primary-nav a:first-child {
    display: none;
  }

  .converter-column,
  .diameter-figure {
    padding-inline: 1rem;
  }

  .result-actions .button {
    flex: 1 1 7rem;
  }

  .definition-list > div {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .brand-mark,
  .match-status,
  .mapping,
  .yarn-number {
    border: 1px solid CanvasText;
  }

  .needle-table tbody tr.is-selected > * {
    outline: 3px solid Highlight;
    outline-offset: -3px;
  }

  .system-switch input:checked + span {
    color: HighlightText;
    background: Highlight;
  }
}

@page {
  size: auto;
  margin: 12mm;
}

@page chart {
  size: landscape;
}

.print-only {
  display: none;
}

@media print {
  :root {
    --paper: #fff;
    --white: #fff;
    --ink: #000;
    --muted: #222;
    --line: #999;
    --line-strong: #444;
  }

  body {
    background: #fff;
    font-size: 8.5pt;
  }

  body[data-print-mode="chart"] {
    page: chart;
  }

  .print-only {
    display: block !important;
  }

  .site-header,
  .site-footer,
  .converter-form,
  .result-actions,
  .diameter-figure,
  .chart-toolbar,
  .chart-actions,
  .scroll-hint,
  .saved-section,
  .decision-lab,
  .gauge-section,
  .ambiguity-section,
  .measure-section,
  .toast,
  .legal-dialog:not([open]) {
    display: none !important;
  }

  main > section {
    width: 100%;
  }

  .hero,
  .chart-section,
  .yarn-section,
  .method-section {
    padding-block: 0 1rem;
    border: 0;
  }

  .hero-heading {
    display: block;
    margin-bottom: 1rem;
  }

  h1 {
    font-size: 24pt;
  }

  h2 {
    font-size: 18pt;
  }

  .workbench {
    display: block;
    border: 0;
    box-shadow: none;
  }

  .converter-column {
    padding: 0;
    border: 0;
  }

  .result-panel {
    break-inside: avoid;
  }

  .table-scroll {
    overflow: visible;
    border-color: #444;
  }

  .needle-table,
  .yarn-table {
    min-width: 0;
  }

  .needle-table thead th,
  .yarn-table thead th,
  .needle-table th:first-child {
    position: static;
    color: #fff;
    background: #000 !important;
  }

  .needle-table tbody tr,
  .yarn-table tbody tr {
    break-inside: avoid;
  }

  .needle-table th,
  .needle-table td,
  .yarn-table th,
  .yarn-table td {
    padding: 3pt 5pt;
    color: #000;
    background: #fff !important;
  }

  .mapping,
  .match-status {
    color: #000;
    background: #fff;
    border: 1px solid #555;
  }

  body[data-print-mode="result"] main > section:not(.hero),
  body[data-print-mode="result"] .hero-heading {
    display: none !important;
  }

  body[data-print-mode="result"] .result-panel {
    margin-top: 0;
  }

  body[data-print-mode="chart"] .hero,
  body[data-print-mode="chart"] .yarn-section,
  body[data-print-mode="chart"] .method-section {
    display: none !important;
  }

  body[data-print-mode="chart"] .needle-table tbody tr[hidden] {
    display: table-row !important;
  }

  .legal-dialog[open] {
    position: static;
    display: block;
    width: 100%;
    max-height: none;
    border: 0;
    box-shadow: none;
  }

  body.legal-open main,
  body.legal-open > .site-header,
  body.legal-open > .site-footer {
    display: none !important;
  }

  .legal-dialog[open] .dialog-bar,
  .legal-dialog[open] .dialog-footer {
    display: none;
  }

  .legal-dialog[open] .legal-dialog-content {
    max-height: none;
    padding: 0;
    overflow: visible;
  }
}
