@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:ital,wght@0,500;0,600;1,500&display=swap');

:root {
  color-scheme: light;
  --paper: #f9f6ef;
  --white: #fffdf8;
  --ink: #262c21;
  --muted: #565b4c;
  --line: #e3dccd;
  --moss: #344b36;
  --moss-dark: #263b28;
  --sage: #edf0e5;
  --rust: #884a36;
  --serif: 'Playfair Display', Georgia, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 1rem/1.55 var(--sans); }
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
:focus-visible { outline: 3px solid #86703d; outline-offset: 4px; }
[hidden] { display: none !important; }

.shell { width: min(100% - 72px, 1180px); margin-inline: auto; }
.skip { position: absolute; inset: 8px auto auto 8px; z-index: 1; transform: translateY(-180%); background: white; padding: 8px 14px; }
.skip:focus { transform: none; }
.site-header { border-bottom: 1px solid var(--line); }
.header-inner { min-height: 73px; display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.brand { display: inline-flex; align-items: center; flex-shrink: 0; border-radius: 5px; }
.brand img { display: block; width: 116px; height: auto; }
nav { display: flex; align-items: center; gap: clamp(13px, 3vw, 32px); font-size: .87rem; }
nav a { text-decoration: none; color: var(--muted); }
nav a:hover, .nav-active { color: var(--moss); text-decoration: underline; text-underline-offset: 6px; }
.language-picker { display: flex; flex-shrink: 0; padding: 2px; gap: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--white); }
.language-picker a { display: grid; place-items: center; min-width: 32px; min-height: 32px; padding: 3px 5px; border-radius: 6px; color: var(--moss-dark); font-size: .75rem; font-weight: 700; text-decoration: none; }
.language-picker a[aria-current='page'] { background: var(--moss); color: white; }

.hero { display: grid; grid-template-columns: .97fr 1.03fr; min-height: 330px; margin: 32px 0 42px; overflow: hidden; border: 1px solid #e9e0cf; border-radius: 20px; background: #efe7d7; }
.hero-copy { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; padding: clamp(29px, 4vw, 58px); }
.hero-media { min-width: 0; background: #d8c9af url('knitting.jpg') center 52% / cover no-repeat; }
.eyebrow { color: var(--rust); font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin-block: 9px 13px; max-width: 9em; font: 600 clamp(2.8rem, 5.55vw, 5.25rem)/1.02 var(--serif); letter-spacing: -.068em; }
h1 em { color: var(--moss); font-weight: 500; }
.hero-copy > p:not(.eyebrow) { max-width: 33ch; color: #4b5143; }
.button { display: inline-flex; justify-content: space-between; align-items: center; gap: 26px; border: 1px solid var(--moss); border-radius: 8px; padding: 10px 17px; background: var(--moss); color: white; font-size: .9rem; font-weight: 700; text-decoration: none; }
.button:hover { background: var(--moss-dark); }
.button span { font-size: 1.16rem; line-height: 1; }
.hero-button { margin-top: 23px; }

#generator, .help { scroll-margin-top: 20px; }
h2 { font: 600 clamp(1.48rem, 2.7vw, 2rem)/1.15 var(--serif); letter-spacing: -.035em; }
.projects { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-block: 15px 24px; }
.project { min-height: 82px; position: relative; display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--white); cursor: pointer; }
.project:hover { border-color: #899580; }
.project:has(input:checked) { border-color: #70856e; background: var(--sage); }
.project:has(input:focus-visible) { outline: 3px solid #86703d; outline-offset: 3px; }
.project input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.project-caption { display: grid; line-height: 1.26; gap: 3px; }
.project-caption strong { font-size: 1rem; }
.project-caption small { color: var(--muted); font-size: .76rem; }
.project-thumbnail { flex: 0 0 auto; width: 58px; height: 52px; object-fit: cover; border-radius: 8px; background: #ede7db; }
.size-panel { width: min(100%, 660px); margin: 0 auto 28px; padding: clamp(14px, 3vw, 24px); border: 1px solid #dce3d1; border-radius: 16px; background: var(--sage); text-align: center; }
.size-panel .size-choice { margin: 0; }
.size-choice legend { margin-inline: auto; margin-bottom: 12px; color: var(--moss-dark); font: 600 clamp(1.14rem, 2.45vw, 1.42rem)/1.2 var(--serif); }
.size-options { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 8px; }
.size-options label { position: relative; cursor: pointer; }
.size-options input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.size-options span { display: grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0 8px; border: 1px solid #aab6a2; border-radius: 9px; background: var(--white); color: var(--moss-dark); font-size: .87rem; font-weight: 700; }
.size-options .custom-size span { padding-inline: 14px; }
.size-options label:hover span { border-color: var(--moss); }
.size-options input:checked + span { background: var(--moss); border-color: var(--moss); color: white; }
.size-options input:focus-visible + span { outline: 3px solid #86703d; outline-offset: 3px; }
#size-note { margin-top: 10px; color: var(--muted); font-size: .8rem; }

.workbench { display: grid; grid-template-columns: minmax(0, .91fr) minmax(0, 1.09fr); gap: 18px; align-items: start; }
.card { padding: clamp(16px, 2.5vw, 29px); border: 1px solid var(--line); border-radius: 15px; background: var(--white); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 22px; }
.card-header h2 { font-size: clamp(1.38rem, 2.15vw, 1.72rem); }
.text-button { border: 0; border-radius: 4px; padding: 5px 0; background: transparent; color: var(--moss); font-size: .79rem; font-weight: 700; white-space: nowrap; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover:enabled { color: var(--rust); }
fieldset { min-width: 0; padding: 0; margin: 0 0 20px; border: 0; }
legend { padding: 0; margin-bottom: 8px; font-size: .96rem; font-weight: 700; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field-heading { display: flex; align-items: center; gap: 4px; min-height: 26px; margin-bottom: 2px; }
.field label { color: var(--muted); font-size: .81rem; font-weight: 600; }
.field-help { display: inline-flex; vertical-align: middle; flex-shrink: 0; }
legend .field-help { margin-left: 4px; }
.info-button { position: relative; display: grid; place-items: center; width: 28px; height: 28px; border: 0; padding: 0; background: transparent; color: var(--moss); font: 700 12px/1 var(--sans); }
.info-button::before { position: absolute; inset: 6px; border: 1px solid currentColor; border-radius: 50%; content: ''; pointer-events: none; }
.info-button:hover { color: var(--rust); }
.info-popup { position: fixed; inset: var(--info-top) auto auto clamp(12px, var(--info-left), calc(100vw - min(280px, 100vw - 24px) - 12px)); width: min(280px, 100vw - 24px); max-height: min(150px, 45vh); margin: 0; overflow: auto; padding: 9px 11px; border: 1px solid var(--moss); border-radius: 8px; background: var(--moss-dark); color: white; box-shadow: 0 4px 18px #242d2233; font: 400 .82rem/1.45 var(--sans); white-space: normal; }
.info-popup.above { top: auto; bottom: var(--info-bottom); }
.field-input { position: relative; }
.field-input input { width: 100%; border: 1px solid #d6d0c2; border-radius: 7px; padding: 8px 44px 8px 11px; background: #fffefb; color: var(--ink); }
.field-input input[aria-invalid='true'] { border-color: #a34b3b; }
.field-input input.no-unit { padding-right: 11px; }
.field-input span { position: absolute; top: 50%; right: 11px; transform: translateY(-50%); color: var(--muted); font-size: .8rem; pointer-events: none; }
.field-error { margin-top: 4px; color: #8e3528; font-size: .77rem; }
.field-note { margin: -4px 0 10px; color: var(--muted); font-size: .81rem; }
.mode-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: .81rem; font-weight: 600; }
#gauge-mode, #pattern-style, #needle-size, #sample-shape, #consumption-method, #stock-yarn { width: 100%; margin-bottom: 12px; border: 1px solid #d6d0c2; border-radius: 7px; padding: 8px 11px; background: #fffefb; color: var(--ink); }
#stock-yarn { max-width: 420px; }
.needle-picker { margin-top: 14px; }
#rib-gauge { margin-top: 14px; grid-template-columns: 1fr; }
.needle-picker .field-heading label { color: var(--muted); font-size: .81rem; font-weight: 600; }
.needle-picker small { font-weight: 400; }
#needle-custom { margin: -5px 0 10px; }
#needle-note { margin-bottom: 0; }
#yarn-consumption { scroll-margin-top: 20px; }
#stock-result .text-button { margin-top: 6px; }
.yarn-fields { margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--line); }
.yarn-fields summary { margin-bottom: 10px; font-size: .96rem; font-weight: 700; cursor: pointer; }
#yarn-details { margin-bottom: 16px; }
.yarn-entry { margin: 14px 0 8px; padding: 0 10px 10px; border: 1px solid var(--line); border-radius: 8px; }
.yarn-entry legend { padding-inline: 5px; font-size: .86rem; }
.yarn-entry .text-button { margin-top: 6px; }
.yarn-fields small { margin-left: 5px; color: var(--muted); font-size: .75rem; font-weight: 400; }
.generate-button { width: 100%; }

.result { background: #fbfcf6; border-color: #dce3d1; }
.result .card-header { flex-wrap: wrap; }
.export-actions { display: flex; gap: 6px; }
.export-button { padding: 5px 8px; border: 1px solid #a3b09a; border-radius: 6px; color: var(--moss); background: #f7f9f0; font-size: .76rem; font-weight: 700; white-space: nowrap; }
.export-button:hover:enabled { background: var(--sage); }
.yarn-result { margin-top: 14px; padding-top: 10px; border-top: 1px solid #dce3d1; }
.yarn-result h4 { margin-bottom: 7px; font-size: .91rem; }
.yarn-material + .yarn-material { margin-top: 12px; }
.yarn-material h5 { margin: 8px 0 4px; font-size: .88rem; overflow-wrap: anywhere; }
.yarn-details { display: grid; gap: 3px; margin: 0 0 9px; font-size: .83rem; }
.yarn-details > div { display: flex; flex-wrap: wrap; gap: 3px 8px; }
.yarn-details dt { color: var(--muted); }
.yarn-details dd { min-width: 0; margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.result-status { color: var(--muted); font-size: .85rem; }
.result-status:not(:empty) { margin-bottom: 10px; }
.result-overview { margin-bottom: 14px; }
.result-overview h3 { font: 600 1.6rem/1.15 var(--serif); }
.result-overview p, .result-note { color: var(--muted); font-size: .83rem; }
.result-overview p { margin-top: 3px; }
.pattern-figure { margin: 0 0 15px; }
.pattern-figure img { display: block; width: 100%; height: 230px; object-fit: contain; background: #e9e0d3; border-radius: 9px; }
.pattern-figure figcaption { margin-top: 6px; color: var(--muted); font-size: .77rem; }
.pattern-section-title { margin: 16px 0 7px; }
.pattern-guide { margin: 0; font-size: .85rem; }
.pattern-guide > div + div { margin-top: 6px; }
.pattern-guide dt { font-weight: 700; }
.pattern-guide dd { margin: 2px 0 0; color: var(--muted); }
.steps li p + p, .pattern-checkpoint { margin-top: 6px; }
.pattern-checkpoint { font-weight: 600; color: var(--moss); }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 0 8px; border: 1px solid #dce3d1; border-radius: 9px; background: var(--sage); }
.metrics > div { display: flex; flex-direction: column; justify-content: space-between; padding: 9px; }
.metrics > div + div { border-left: 1px solid #dce3d1; }
.metrics dt { color: var(--muted); font-size: .73rem; line-height: 1.2; }
.metrics dd { margin: 5px 0 0; color: var(--moss-dark); font-size: clamp(.78rem, 1.55vw, 1.1rem); font-weight: 700; }
.steps { display: grid; gap: 10px; margin: 16px 0 0; padding-left: 1.4rem; }
.steps li { padding-left: 4px; }
.steps li::marker { color: var(--moss); font-weight: 700; }
.steps h4 { font-size: .91rem; }
.steps p { font-size: .86rem; }
.crown-table { width: 100%; margin-top: 9px; border-collapse: collapse; text-align: left; font-size: .78rem; }
.crown-table caption { padding: 3px 0; text-align: left; font-weight: 700; }
.crown-table th, .crown-table td { padding: 4px 5px; border-bottom: 1px solid #dce3d1; vertical-align: top; }
.crown-table th:first-child, .crown-table th:last-child, .crown-table td:first-child, .crown-table td:last-child { text-align: center; }
.crown-table thead { background: var(--sage); }

.help { margin: 24px 0 34px; padding: 13px 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); }
.stock { margin-top: 24px; }
.stock .card-header { flex-wrap: wrap; margin-bottom: 12px; }
.stock .fields { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 12px; }
#stock-result:not(:empty) { margin-top: 14px; }
#stock-result h3 { margin-bottom: 6px; font-size: .96rem; overflow-wrap: anywhere; }
.stock-metrics { grid-template-columns: repeat(auto-fit, minmax(min(100%, 110px), 1fr)); max-width: 650px; }
.help summary { color: var(--moss); cursor: pointer; font-weight: 700; }
.help ol { margin-bottom: 4px; padding-left: 22px; color: var(--muted); }
.help li + li { margin-top: 5px; }
.site-footer { border-top: 1px solid var(--line); padding: 18px 0; color: var(--muted); font-size: .79rem; }
.site-footer span { margin-inline: 4px; }
.support { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 24px; padding: 22px; margin: 0 0 34px; border: 1px solid #dce3d1; border-radius: 12px; background: var(--sage); scroll-margin-top: 20px; }
.support h2 { font-size: 1.5rem; }
.support p { max-width: 66ch; margin-top: 5px; color: var(--muted); font-size: .87rem; }
.support .support-status { margin-top: 6px; font-size: .8rem; }
.support-actions { display: flex; width: 100%; flex-wrap: wrap; align-items: center; gap: 12px 18px; }
.support-actions iframe { display: block; border: 0; max-width: 100%; }
.suppi-widget { width: 355px; height: 78px; }
.coffee-widget { width: 255px; height: 68px; }

@media (max-width: 800px) {
  .shell { width: min(100% - 32px, 640px); }
  .hero { margin-block: 22px 28px; min-height: 260px; }
  .hero-copy { padding: 22px; }
  .hero-copy > p:not(.eyebrow) { font-size: .9rem; }
  h1 { font-size: clamp(2.4rem, 7.2vw, 3.8rem); }
  .projects { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stock .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workbench { grid-template-columns: 1fr; }
  .metrics dd { font-size: 1rem; }
}

@media (max-width: 490px) {
  .header-inner { display: grid; grid-template-columns: 1fr auto; min-height: 62px; padding-block: 8px; gap: 6px 12px; }
  .header-inner nav { grid-row: 2; grid-column: 1 / -1; justify-content: flex-start; }
  .language-picker { justify-self: end; }
  .brand img { width: 92px; }
  .size-options { display: grid; grid-template-columns: repeat(5, minmax(0, 44px)); gap: 5px; }
  .size-options .custom-size { grid-column: 1 / -1; justify-self: center; }
  .size-options span { min-width: 0; }
  nav { font-size: .75rem; }
  .hero { grid-template-columns: 1fr; }
  .hero-copy { padding: 24px; }
  .hero-media { min-height: 175px; }
  .project { gap: 8px; padding: 8px; }
  .project-thumbnail { width: 43px; height: 42px; }
  .pattern-figure img { height: 190px; }
  .projects { gap: 8px; }
  .metrics > div { padding: 6px; }
  .metrics dd { font-size: .87rem; }
}

@media (max-width: 370px) {
  nav { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
}

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

@media print {
  @page { margin: 15mm; }
  body, .result { background: white; color: black; }
  .site-header, .skip, .hero, .size-panel, .generator-heading, .projects, .settings, .stock, .help, .support, .site-footer, .export-actions, .result-status { display: none; }
  .shell { width: auto; }
  .workbench { display: block; }
  .result { padding: 0; border: 0; }
  .result h2 { font-size: 1.15rem; }
  .result h3 { font-size: 1.7rem; }
  .metrics, .steps h4 { break-after: avoid; }
  .metrics, .crown-table tr { break-inside: avoid; }
  .crown-table thead { display: table-header-group; }
}
