/* Brand, welcome page and crawlable landing content. Loaded after styles.css. */
.brand { gap: 10px; font-size: 15px; }
.brand-mark { width: 28px; height: 28px; flex-shrink: 0; color: var(--brand); }
.brand span { font-family: var(--display); font-size: 17px; font-weight: 600; letter-spacing: -.3px; }
.brand b { font-weight: 600; color: var(--brand); }

/* Welcome page: the pitch beside the upload card, then how it works, all in the first screen. */
.upload-screen { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 440px); align-items: center; gap: clamp(32px, 5vw, 72px); max-width: 1120px; margin: clamp(20px, 6vh, 72px) auto clamp(28px, 5vh, 56px); text-align: left; }
.upload-screen h1 { max-width: 600px; margin: 0 0 18px; font-family: var(--display); font-size: clamp(40px, 4.6vw, 66px); line-height: 1.02; font-weight: 650; letter-spacing: -.035em; text-wrap: balance; }
.intro-copy { max-width: 500px; margin: 0; font-size: 18px; line-height: 1.55; text-wrap: pretty; }
.hero-action { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.upload-card { width: 100%; max-width: 440px; padding: 30px 26px 18px; border: 1.5px dashed var(--field-border); border-radius: 22px; background: var(--elevated); box-shadow: 0 18px 50px -28px var(--shadow); text-align: center; transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease; }
.upload-card .primary { padding: 15px 30px; font-size: 16px; font-weight: 600; box-shadow: 0 8px 22px -10px var(--brand); }
.drop-hint { margin: 12px 0 0; color: var(--muted); font-size: 14px; }
.file-types { margin: 20px 0 4px; padding: 14px 0 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; text-align: center; }
.upload-card #demo { font-size: 13px; }
.upload-progress { top: calc(100% + 14px); font-size: 13px; }
body.drop-target .upload-card { border-color: var(--brand); background: var(--brand-soft); transform: scale(1.015); }

.landing { max-width: 1120px; margin: 0 auto; padding: 0 0 24px; }
.landing h2 { font-family: var(--display); font-size: clamp(22px, 2.4vw, 28px); line-height: 1.15; font-weight: 650; letter-spacing: -.02em; margin-bottom: 14px; }
.landing .eyebrow { display: block; margin-bottom: 16px; font-family: inherit; font-size: 12px; font-weight: 600; letter-spacing: 1.6px; text-align: center; }
.showcase { padding: clamp(18px, 3vh, 32px) 0 clamp(28px, 5vh, 48px); border-top: 1px solid var(--border); }
.steps { --visual-height: clamp(140px, 17vh, 168px); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; margin: 0; padding: 0; list-style: none; }
.steps > li { position: relative; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 18px; background: var(--elevated); }
.steps > li:not(:last-child)::after { content: "→"; position: absolute; z-index: 1; right: -17px; top: calc(var(--visual-height) / 2); translate: 0 -50%; color: var(--muted); font-size: 18px; line-height: 1; }
.step-visual { display: grid; place-items: center; height: var(--visual-height); padding: 10px 18px; border-bottom: 1px solid var(--border); }
.motif-picture { width: auto; height: 78%; }
.motif-chart { width: auto; height: 86%; }
.motif-a { fill: #f3ede1; }
.motif-b { fill: #c8312b; }
.motif-grid line { stroke: #5a4a3a40; stroke-width: 1; }
.showcase-rows { width: 100%; margin: 0; padding: 0; list-style: none; font-size: 13px; line-height: 1.4; text-align: left; }
.showcase-rows li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.showcase-rows li:last-child { border-bottom: 0; }
.showcase-rows strong { display: block; color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .8px; text-transform: uppercase; }
.step-text { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px 18px; }
.steps h3 { margin: 3px 0 4px; font-size: 16px; }
.steps p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.step-number { display: inline-grid; flex-shrink: 0; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-size: 14px; font-weight: 700; }

/* Below the first screen: tips beside the questions. */
.landing-more { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: clamp(32px, 5vw, 64px); padding: 40px 0 8px; border-top: 1px solid var(--border); }
.landing-text { font-size: 16px; line-height: 1.65; }
.landing-text p { margin-bottom: 14px; }
.landing-text ul { margin: 0; padding-left: 20px; }
.landing-text li { margin-bottom: 10px; padding-left: 4px; }
.landing-text li::marker { color: var(--brand); }
.faq details { border-bottom: 1px solid var(--border); }
.faq details:first-of-type { border-top: 1px solid var(--border); }
.faq summary { position: relative; padding: 14px 32px 14px 0; list-style: none; font-size: 16px; font-weight: 600; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; position: absolute; right: 4px; top: 50%; translate: 0 -50%; color: var(--muted); font-size: 22px; font-weight: 400; transition: rotate 160ms ease; }
.faq details[open] > summary { margin-bottom: 0; }
.faq details[open] > summary::after { rotate: 45deg; }
.faq details p { margin: 0 0 16px; color: var(--muted); font-size: 15px; line-height: 1.65; }

.site-footer { display: flex; align-items: center; justify-content: space-between; gap: 24px; max-width: 1120px; margin: 24px auto 0; padding: 24px 0 8px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.footer-brand strong { color: var(--ink); font-size: 14px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.site-footer a { text-decoration: none; }
.site-footer a:hover { color: var(--ink); text-decoration: underline; }

.document-page main.document { max-width: 720px; margin: 40px auto 0; padding: 0 24px; font-size: 17px; line-height: 1.7; }
.document h1 { font-family: var(--display); font-size: 44px; font-weight: 650; letter-spacing: -.03em; }
.document h2 { margin-top: 32px; font-size: 20px; }
.document-page .site-footer { max-width: 720px; padding-right: 24px; padding-left: 24px; }

/* Short laptop screens keep how it works in view by trimming the space around the hero. */
@media (min-width: 901px) and (max-height: 820px) {
  .upload-screen { margin: 20px auto 26px; }
  .upload-screen h1 { font-size: clamp(40px, 4.2vw, 56px); }
  .showcase { padding-top: 16px; }
}

@media (max-width: 900px) {
  .upload-screen { grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 26px; max-width: 560px; margin: 32px auto; text-align: center; }
  .upload-screen h1 { margin-right: auto; margin-left: auto; }
  .intro-copy { margin: 0 auto; }
  .hero-action { width: 100%; max-width: 440px; }
  .steps { gap: 14px; }
  .steps > li:not(:last-child)::after { right: -12px; font-size: 15px; }
  .step-text { flex-direction: column; gap: 8px; padding: 14px; }
  .landing-more { grid-template-columns: minmax(0, 1fr); gap: 28px; }
}

@media (max-width: 600px) {
  .upload-screen { margin: 20px auto 28px; gap: 20px; }
  .upload-screen h1 { margin-bottom: 12px; font-size: 38px; }
  .intro-copy { font-size: 16px; }
  .upload-card { padding: 24px 18px 14px; border-radius: 18px; }
  .brand span { font-size: 16px; }
  .steps { --visual-height: 124px; grid-template-columns: minmax(0, 1fr); }
  .steps > li:not(:last-child)::after { content: none; }
  .step-text { flex-direction: row; gap: 12px; padding: 14px 16px 16px; }
  .step-visual { height: auto; min-height: var(--visual-height); padding: 12px 18px; }
  .motif-picture, .motif-chart { height: 96px; }
  /* With only the theme switch and Project, the welcome header fits on one line. */
  body:has(.workspace[data-flow-step="upload"]) .header-actions { width: auto; }
  .site-footer { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .upload-card, .faq summary::after { transition: none; }
  body.drop-target .upload-card { transform: none; }
}

/* The welcome page keeps the header quiet: no save state or settings before there is a chart. */
body:has(.workspace[data-flow-step="upload"]) :is(#save-status:not(.save-error), #open-settings) { display: none; }

/* Chart workspace refinements. */
.chart-grid-lines .major { stroke: #203a3488; stroke-width: 1.5; }
.flow-nav .export .secondary { padding: 10px 16px; }
.flow-nav .export button { font-size: 14px; font-weight: 600; }
.upload-screen .return-editor { margin-top: 14px; padding: 11px 20px; font-size: 14px; font-weight: 600; }

@media (max-width: 600px) {
  .chart-sizing .range-control { flex: 1 1 100%; max-width: none; }
  .chart-sizing label { white-space: nowrap; }
  .flow-nav .export button { padding: 9px 14px; font-size: 13px; }
}

/* Header controls share one shape: 34px ghost pills with a hover tint. */
.header-actions { gap: 6px; }
.theme-switch { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 999px; }
.theme-switch button { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border-radius: 50%; color: var(--muted); }
.theme-switch button:hover { color: var(--ink); background: var(--soft); }
.theme-switch button[aria-checked="true"] { color: var(--ink); background: var(--soft); box-shadow: inset 0 0 0 1px var(--border); }
.theme-switch svg, .header-button svg, .project-menu .chevron { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#save-status { margin: 0 6px; font-size: 12px; }
.project-menu > summary, .header-actions > .header-button { display: inline-flex; align-items: center; gap: 7px; height: 36px; margin: 0; padding: 0 14px; border-radius: 999px; background: transparent; color: var(--ink); font-size: 14px; font-weight: 500; }
.project-menu > summary:hover, .header-actions > .header-button:hover:not(:disabled), .project-menu[open] > summary { background: var(--soft); color: var(--ink); }
.project-menu[open] > summary { margin-bottom: 0; }
.project-menu .chevron { width: 12px; height: 12px; transition: rotate 160ms ease; }
.project-menu[open] .chevron { rotate: 180deg; }
.menu-content { top: calc(100% + 6px); padding: 6px; border-radius: 14px; }
.menu-content button { padding: 10px 12px; border-radius: 9px; font-size: 14px; }

@media (max-width: 600px) {
  .project-menu > summary, .header-actions > .header-button { height: 32px; padding: 0 10px; font-size: 13px; }
  .header-actions > .header-button svg { display: none; }
  /* In the editor the header wraps and Project sits at the left, so its menu opens rightward. */
  body:not(:has(.workspace[data-flow-step="upload"])) .menu-content { right: auto; left: 0; }
  .settings-card .field-grid { grid-template-columns: minmax(0, 1fr); }
  .theme-switch { padding: 0; border: 0; }
  .theme-switch button:not([aria-checked="true"]) { display: none; }
  .theme-switch button[aria-checked="true"] { width: 32px; height: 32px; background: transparent; box-shadow: none; color: var(--ink); }
  .theme-switch button[aria-checked="true"]:hover { background: var(--soft); }
}
@media (prefers-reduced-motion: reduce) { .project-menu .chevron { transition: none; } }

/* Settings: a side sheet of compact cards. */
.settings-dialog { width: 440px; padding: 22px 22px 32px; background: var(--surface); box-shadow: -24px 0 60px -30px var(--shadow); }
.settings-dialog .dialog-heading { position: sticky; top: -22px; z-index: 2; margin: -22px -22px 18px; padding: 18px 22px 14px; background: var(--surface); border-bottom: 1px solid var(--border); }
.settings-dialog .dialog-heading h2 { font-family: var(--display); font-size: 24px; font-weight: 650; letter-spacing: -.02em; }
.icon-button { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border-radius: 50%; background: var(--soft); color: var(--ink); }
.icon-button:hover { background: var(--secondary-hover); }
.icon-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.settings-dialog > .settings-card { margin: 0 0 14px; padding: 18px 18px 6px; border: 1px solid var(--border); border-radius: 16px; background: var(--elevated); }
.settings-dialog > .settings-card:not(:has(> :not([hidden]))) { display: none; }
.settings-card h3 { margin-bottom: 6px; font-size: 16px; }
.settings-card > .hint:first-of-type { margin-top: 0; }
.settings-card label { gap: 6px; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
.settings-card .field-grid { gap: 0 12px; }
.settings-card .settings-footnote { margin: 0 0 12px; font-size: 12px; }
.settings-card #detect { margin: 2px 0 14px; }
.settings-card .detection-summary { margin: 0 0 12px; font-size: 13px; }
.settings-optional details > summary { padding-bottom: 12px; font-size: 16px; font-weight: 600; }
.settings-optional details[open] > summary { margin-bottom: 0; }

/* Wide screens: tools | chart | written pattern. */
body.side-by-side .view-switch { display: none; }
body.side-by-side .linked-views { grid-template-columns: minmax(260px, 300px) minmax(0, 1fr) minmax(340px, 28%); }
body.side-by-side #knitting-pattern { padding-left: 22px; border-left: 1px solid var(--border); }
body.side-by-side .pattern-heading h2 { font-size: 20px; }
body.side-by-side .instruction-row { grid-template-columns: max-content minmax(0, 1fr); gap: 14px; padding: 12px 0; font-size: 14px; }
.instruction-row > strong { white-space: nowrap; }

/* Pattern rows follow the stitch under the pointer, and selected instructions stay marked. */
.instruction-row { transition: background-color 120ms ease; border-radius: 8px; }
.instruction-row.is-current { background: var(--soft); box-shadow: -8px 0 0 var(--soft), 8px 0 0 var(--soft); }
.instruction-row.is-current > strong { color: var(--brand); }

.pattern-hint { position: absolute; z-index: 9; display: flex; flex-direction: column; gap: 3px; max-width: min(340px, calc(100% - 16px)); padding: 9px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--elevated); color: var(--ink); box-shadow: 0 10px 30px -12px var(--shadow); font-size: 14px; line-height: 1.45; pointer-events: none; }
.pattern-hint strong { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; }
.token-span { position: absolute; z-index: 6; pointer-events: none; border-radius: 2px; box-shadow: 0 0 0 2px #fffef8, 0 0 0 4px #1d1d1b; }

.cell.highlight { background: repeating-linear-gradient(135deg, #fffef8cc 0 2px, transparent 2px 5px); box-shadow: inset 0 0 0 1px #1d1d1b; }
.highlight-box { position: absolute; z-index: 7; pointer-events: none; border-radius: 3px; box-shadow: 0 0 0 2px #fffef8, 0 0 0 4px #1d1d1b; outline: 3px solid var(--accent); outline-offset: 5px; animation: highlight-ring 900ms cubic-bezier(.22, 1, .36, 1) 2; }
@keyframes highlight-ring { from { outline-offset: 26px; outline-color: transparent; } 40% { outline-color: var(--accent); } to { outline-offset: 5px; } }

.viewer-toolbar .hint-toggle { margin-right: 4px; padding: 5px 11px; font-size: 12px; }
.viewer-toolbar .hint-toggle[aria-pressed="true"] { background: #f6f5ed; color: #22231f; }

@media (prefers-reduced-motion: reduce) {
  .highlight-box { animation: none; }
  .instruction-row { transition: none; }
}

/* Gallery depth without shared 3D space. When the tilting source sheet, its glow and the
   card row shared one preserve-3d context, the tilted sheet sliced through the flat glow
   and cards, leaving hard diagonal edges. Each part is now flattened into its own layer:
   the stage still gives the scene and cards perspective, and the scene gives the sheet its own. */
.gallery-stage { transform-style: flat; }
.scan-scene { transform-style: flat; perspective: 1100px; perspective-origin: 50% 42%; isolation: isolate; }

/* Instructions wear their yarn color; pink only outlines the one under the pointer or clicked. */
.instruction-text .token, .hint-token { padding: 1px 6px; margin: 2px 0; border-radius: 6px; line-height: 1.5; white-space: nowrap; }
.token.yarn, .hint-token.yarn { background: var(--yarn); color: var(--yarn-ink); box-shadow: inset 0 0 0 1px var(--swatch-border); }
.token.yarn-mixed, .hint-token.yarn-mixed { background: var(--yarn-stripes) left bottom / 100% 4px no-repeat, var(--soft); color: var(--ink); }
.instruction-text .token:hover, .instruction-text .token:focus-visible { outline: 1px solid var(--brand); outline-offset: 1px; }
.token.is-current, .hint-token.is-current { outline: 2px solid var(--brand); outline-offset: 1px; }
.token.is-active { outline: 2px solid var(--brand); outline-offset: 1px; box-shadow: inset 0 0 0 1px var(--swatch-border), 0 0 0 6px color-mix(in srgb, var(--brand) 28%, transparent); }

/* Settings dropdowns: a styled menu in front of each native select. */
.select-menu { position: relative; display: block; }
.select-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; }
.select-menu-button { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--field-border); border-radius: 9px; background: var(--field); color: var(--ink); font-size: 14px; font-weight: 400; text-align: left; transition: border-color 120ms ease; }
.select-menu-button::after { content: ""; flex-shrink: 0; width: 7px; height: 7px; margin: -3px 2px 0 0; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); rotate: 45deg; transition: rotate 160ms ease, margin 160ms ease; }
.select-menu-button[aria-expanded="true"] { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent); }
.select-menu-button:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent); }
.select-menu-button[aria-expanded="true"]::after { margin-top: 3px; rotate: 225deg; }
.select-menu-button:hover:not(:disabled) { border-color: var(--muted); }
.select-menu-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-menu-list { position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; min-width: 100%; max-height: 280px; margin: 0; padding: 6px; overflow: auto; list-style: none; border: 1px solid var(--border); border-radius: 14px; background: var(--elevated); box-shadow: 0 14px 40px -12px var(--shadow); color: var(--ink); font-size: 14px; }
.select-menu.opens-up .select-menu-list { top: auto; bottom: calc(100% + 6px); }
.select-menu-list [role="option"] { position: relative; padding: 9px 12px 9px 30px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.select-menu-list [role="option"].is-active { background: var(--soft); }
.select-menu-list [role="option"][aria-selected="true"] { font-weight: 600; }
.select-menu-list [role="option"][aria-selected="true"]::before { content: ""; position: absolute; left: 12px; top: 50%; width: 5px; height: 9px; margin-top: -6px; border-right: 2px solid var(--brand); border-bottom: 2px solid var(--brand); rotate: 45deg; }
.select-menu-list [role="option"][aria-disabled="true"] { opacity: .4; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) { .select-menu-button::after { transition: none; } }

/* Picture pan tool: grab cursor while dragging moves the zoomed picture. */
.viewer-shell.pan-tool .viewer-scroll, .viewer-shell.pan-tool canvas { cursor: grab; }
.viewer-shell.pan-tool .viewer-scroll.panning, .viewer-shell.pan-tool .viewer-scroll.panning canvas { cursor: grabbing; }
.viewer-toolbar .pan-tool svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* Polish pass: shared details for controls across the app. */

/* Scroll areas use thin, theme-colored scrollbars. */
* { scrollbar-width: thin; scrollbar-color: var(--field-border) transparent; }

/* Disclosures open with the same chevron everywhere. */
details:not(.project-menu):not(.faq details) > summary { display: flex; align-items: center; gap: 8px; list-style: none; }
details:not(.project-menu) > summary::-webkit-details-marker { display: none; }
details:not(.project-menu):not(.faq details) > summary::before { content: ""; flex-shrink: 0; width: 6px; height: 6px; margin: 0 2px 0 1px; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); rotate: -45deg; transition: rotate 160ms ease; }
details:not(.project-menu):not(.faq details)[open] > summary::before { rotate: 45deg; translate: 0 -2px; }
@media (prefers-reduced-motion: reduce) { details > summary::before { transition: none; } }

/* The tools column leaves room for focus rings and its scrollbar. */
.stitch-tools { margin: 0 -6px; padding: 3px 6px 6px; scrollbar-gutter: stable; }

/* Pattern rows: straight dividers, and a rounded highlight on the current row only. */
.instruction-row { border-radius: 0; }
.instruction-row.is-current { border-radius: 8px; border-bottom-color: transparent; }

/* Many yarns read as one continuous strip instead of overflowing the card. */
.variant-swatches { overflow: hidden; border-radius: 3px; }
.variant-swatches > i { min-width: 0; }
.variant-swatches:has(> i:nth-child(13)) { gap: 0; }
.variant-swatches:has(> i:nth-child(13)) > i { border: 0; border-radius: 0; }

/* Dialog close buttons match the Settings sheet. */
.dialog-heading .icon-button { flex-shrink: 0; }

@media (max-width: 600px) {
  /* The small picture keeps a one-line toolbar: zoom, fit and reset. */
  #source-pan, .original-view .zoom-entry { display: none; }
  .original-view .viewer-toolbar { flex-wrap: nowrap; border-radius: 999px; }
}
