/* Yarn Calculator. Plain styles: system fonts, white page, one green accent. */

:root {
  --bg: #ffffff;
  --text: #1b1b1b;
  --muted: #555b57;
  --border: #c9cdca;
  --border-strong: #8d938f;
  --panel: #f5f7f5;
  --zebra: #f6f7f6;
  --field: #ffffff;
  --accent: #1a7f37;
  --accent-text: #ffffff;
  --error: #b42318;
  --map-ink: #1b1b1b;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #202124;
    --text: #e8eaed;
    --muted: #a6aba8;
    --border: #44474b;
    --border-strong: #6b7075;
    --panel: #26282b;
    --zebra: #26282b;
    --field: #2b2d31;
    --accent: #4cc46a;
    --accent-text: #0c1a10;
    --error: #ff8a80;
    --map-ink: #e8eaed;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #202124;
  --text: #e8eaed;
  --muted: #a6aba8;
  --border: #44474b;
  --border-strong: #6b7075;
  --panel: #26282b;
  --zebra: #26282b;
  --field: #2b2d31;
  --accent: #4cc46a;
  --accent-text: #0c1a10;
  --error: #ff8a80;
  --map-ink: #e8eaed;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 17px/1.55 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
img, svg { max-width: 100%; }
img { height: auto; display: block; }
a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 24px; } }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--bg); padding: 8px 12px; z-index: 10; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

h1 { font-size: 28px; line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 23px; line-height: 1.3; margin: 0 0 12px; }
h3 { font-size: 18px; line-height: 1.35; margin: 0 0 6px; }
p { margin: 0 0 1em; }
@media (min-width: 720px) { h1 { font-size: 31px; } }

/* Header */
.masthead { border-bottom: 1px solid var(--border); }
.masthead .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding-top: 12px; padding-bottom: 12px; }
.wordmark { font-weight: 700; font-size: 19px; color: var(--text); text-decoration: none; margin-right: auto; }
.nav { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.nav a[aria-current='page'] { color: var(--text); font-weight: 600; text-decoration: none; }
.theme-toggle { font: inherit; font-size: 15px; background: var(--field); color: var(--text); border: 1px solid var(--border-strong); border-radius: 4px; padding: 4px 10px; cursor: pointer; }
.theme-toggle .to-light { display: none; }
:root[data-theme='dark'] .theme-toggle .to-dark { display: none; }
:root[data-theme='dark'] .theme-toggle .to-light { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-toggle .to-dark { display: none; }
  :root:not([data-theme='light']) .theme-toggle .to-light { display: inline; }
}
@media (max-width: 560px) { .nav { order: 3; width: 100%; } }

.intro { padding: 24px 0 8px; }
.intro p { color: var(--muted); max-width: 70ch; }

/* Calculator */
.tool { display: grid; gap: 24px; padding: 8px 0 40px; }
@media (min-width: 880px) {
  .tool { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; }
  .result { position: sticky; top: 12px; }
}
fieldset { border: 0; margin: 0 0 18px; padding: 0; min-width: 0; }
legend { font-weight: 700; font-size: 18px; padding: 0; margin-bottom: 8px; }
.row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > label, .field > span:first-child { font-size: 15px; font-weight: 600; }
.hint { font-size: 15px; color: var(--muted); margin: 6px 0 0; }
.unit-wrap { position: relative; display: block; }
.unit-wrap input { padding-right: 2.4em; }
.unit { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 15px; color: var(--muted); pointer-events: none; }
input[type='number'], input[type='text'], select {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--field);
  border: 1px solid var(--border-strong); border-radius: 4px; padding: 7px 9px; min-height: 40px;
}
input[aria-invalid='true'] { border-color: var(--error); }
.error { color: var(--error); font-size: 15px; margin: 6px 0 0; }
.error:empty { display: none; }

.seg { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.seg label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.seg input { margin: 0; accent-color: var(--accent); }

.colors { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.colors li, .colors-head { display: grid; grid-template-columns: 44px minmax(0, 1fr) 86px 36px; gap: 8px; align-items: center; }
.colors-head { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.colors-head span:first-child { grid-column: 2; }
.colors input[type='color'] { width: 44px; height: 40px; border: 1px solid var(--border-strong); border-radius: 4px; padding: 2px; background: var(--field); cursor: pointer; }
.colors .x { width: 36px; height: 40px; background: none; border: 1px solid transparent; border-radius: 4px; color: var(--muted); font-size: 22px; cursor: pointer; }
.colors .x:hover { border-color: var(--border); color: var(--error); }
.colors .x[disabled] { visibility: hidden; }
.link-btn { background: none; border: 0; padding: 6px 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }
.link-btn[disabled] { color: var(--muted); text-decoration: none; cursor: default; }

.result { border: 1px solid var(--border-strong); border-radius: 6px; padding: 16px 18px 18px; background: var(--bg); }
.result__label { margin: 0; color: var(--muted); }
.result__big { font-size: 30px; font-weight: 700; line-height: 1.2; margin: 0 0 6px; }
.result__sub { margin: 0; }
.result__colors { list-style: none; padding: 0; margin: 14px 0 0; border-top: 1px solid var(--border); }
.result__colors li { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.result__cname { overflow-wrap: anywhere; }
.result__cnum { font-weight: 600; }
.result__cyd { color: var(--muted); font-size: 15px; min-width: 5.5em; text-align: right; }
.chip { width: 16px; height: 16px; border-radius: 3px; border: 1px solid var(--border-strong); }
.result__note { font-size: 15px; color: var(--muted); margin: 10px 0 0; }
.result__parts { display: grid; grid-template-columns: auto 1fr; gap: 2px 16px; margin: 14px 0 0; padding: 10px 0 0; border-top: 1px solid var(--border); font-size: 15px; }
.result__parts div { display: contents; }
.result__parts dt { color: var(--muted); }
.result__parts dd { margin: 0; }
.result--error .result__body { opacity: 0.4; }
.result__msg { color: var(--error); font-weight: 600; margin: 0 0 10px; }
.result__msg:empty { display: none; }

.skein-map, .tally { margin: 16px 0 0; }
.skein-map__svg { display: block; width: 100%; height: auto; max-height: 340px; }
.skein-map__n { font: 600 13px -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; }
.skein-map__up { font: 12px -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; fill: var(--muted); }
.skein-map__join { stroke: var(--map-ink); stroke-width: 1; opacity: 0.45; }
.skein-map__edge { fill: none; stroke: var(--map-ink); stroke-width: 1.5; }
.skein-map figcaption, .tally figcaption { font-size: 15px; color: var(--muted); margin-top: 6px; }
.tally__svg { display: block; height: auto; }
.tally__ring { fill: none; stroke: var(--map-ink); stroke-width: 1.2; }

.actions { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.btn { font: inherit; font-size: 16px; font-weight: 600; background: var(--accent); color: var(--accent-text); border: 1px solid var(--accent); border-radius: 4px; padding: 8px 14px; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.status { font-size: 15px; color: var(--accent); }

/* Phone: the answer stays visible while you fill the form */
.answer-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: none; justify-content: space-between; align-items: center;
  gap: 12px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--border-strong); font-weight: 600;
}
.answer-bar.is-on { display: flex; }
@media (min-width: 880px) { .answer-bar.is-on { display: none; } }

/* Content below the tool */
.section { padding: 28px 0; border-top: 1px solid var(--border); }
.prose { max-width: 72ch; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin-bottom: 0.3em; }
.split > * + * { margin-top: 20px; }
.figure { margin: 0; max-width: 680px; }
.figure img { border: 1px solid var(--border); }
.figure figcaption { font-size: 15px; color: var(--muted); margin-top: 6px; }
.formula { font-weight: 600; background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 8px 12px; display: inline-block; }

.table-wrap { position: relative; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 16px; }
caption { text-align: left; font-size: 15px; color: var(--muted); padding-bottom: 8px; }
th, td { text-align: left; padding: 7px 10px; border: 1px solid var(--border); vertical-align: top; }
thead th { background: var(--panel); font-weight: 600; white-space: nowrap; }
tbody tr:nth-child(even) { background: var(--zebra); }
td.n, th.n { text-align: right; white-space: nowrap; }
tbody th { font-weight: 600; }
.small { font-size: 14px; color: var(--muted); font-weight: 400; }
table.wide { min-width: 600px; }
table.wide--xl { min-width: 760px; }

/* FAQ */
.ledger > div { padding: 12px 0; border-top: 1px solid var(--border); }
.ledger p { margin: 0 0 0.6em; max-width: 72ch; }
.ledger p:last-child { margin-bottom: 0; }

/* Grams page converter */
.convert { display: grid; gap: 24px; padding: 8px 0 40px; }
@media (min-width: 880px) { .convert { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; } }
.readout { font-size: 30px; font-weight: 700; line-height: 1.2; margin: 2px 0 6px; overflow-wrap: anywhere; }
.readout small { font-size: inherit; margin-left: 6px; }

/* Legal */
.legal { padding-bottom: 40px; }
.legal h2 { font-size: 20px; margin: 1.4em 0 0.4em; }
.legal .updated { color: var(--muted); }

/* Footer */
.foot { border-top: 1px solid var(--border); padding: 20px 0 72px; font-size: 15px; color: var(--muted); }
.foot .wrap { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.foot nav { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.foot p { margin: 0; margin-right: auto; }
@media (min-width: 880px) { .foot { padding-bottom: 24px; } }

@media print {
  .masthead, .foot, .answer-bar, .actions, form, .section { display: none !important; }
  .tool { display: block; }
}
