/* StitchChartPDF — Editorial Craft Studio Design System (v1.0)
   Warm linen & precision needlework typography + unified Apple-grade state-transition motion tokens.
   Supports 360px+ mobile through 1440px+ desktop, dark mode, print, and prefers-reduced-motion. */

:root {
  color-scheme: light dark;
  --bg: #FAF7F2;
  --header-bg: rgba(250, 247, 242, 0.92);
  --surface: #FFFFFF;
  --surface-soft: #F3EEE5;
  --surface-tint: #EAE2D3;
  --ink: #1C1A17;
  --ink-2: #433F39;
  --muted: #6E685F;
  --line: #E2DACB;
  --line-strong: #C8BDA9;
  --accent: #A63A24;
  --accent-hover: #892D1A;
  --accent-soft: rgba(166, 58, 36, 0.10);
  --ink-btn: #1F332B;
  --ink-btn-hover: #14221D;
  --ok: #1D6846;
  --ok-soft: rgba(29, 104, 70, 0.12);
  --warn: #8F5410;
  --warn-soft: rgba(143, 84, 16, 0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-soft: 0 2px 12px rgba(28, 26, 23, 0.05);
  --shadow-card: 0 10px 28px rgba(28, 26, 23, 0.08);
  --max-w: 1180px;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Baskerville, Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Unified Motion Tokens */
  --dur-fast: 120ms;
  --dur-base: 220ms;
  --dur-slow: 420ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --header-bg: rgba(20, 19, 17, 0.92);
    --surface: #1D1C19;
    --surface-soft: #262420;
    --surface-tint: #312E28;
    --ink: #F4F0E8;
    --ink-2: #D5CFC3;
    --muted: #9E978B;
    --line: #32302A;
    --line-strong: #4A463E;
    --accent: #E25B3F;
    --accent-hover: #EE6E53;
    --accent-soft: rgba(226, 91, 63, 0.16);
    --ink-btn: #2B473C;
    --ink-btn-hover: #36594B;
    --ok: #4BC48B;
    --ok-soft: rgba(75, 196, 139, 0.16);
    --warn: #E8AC4E;
    --warn-soft: rgba(232, 172, 78, 0.16);
    --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.32);
    --shadow-card: 0 12px 32px rgba(0, 0, 0, 0.45);
  }
}

@view-transition { navigation: auto; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
main[id], .workbench { scroll-margin-top: 76px; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

img, svg, canvas { max-width: 100%; display: block; }
a {
  color: var(--ink);
  text-underline-offset: 3px;
  transition: color var(--dur-fast) var(--ease-out);
}
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip-link {
  position: absolute; left: -9999px; top: 8px;
  background: var(--ink); color: var(--bg); padding: 10px 14px;
  border-radius: var(--radius-sm); z-index: 999; text-decoration: none;
}
.skip-link:focus { left: 12px; }

.container { width: 100%; max-width: var(--max-w); margin: 0 auto; padding: 0 20px; }
@media (max-width: 420px) { .container { padding: 0 14px; } }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 90;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 62px;
}
.brand {
  display: inline-flex; align-items: baseline; gap: 8px;
  text-decoration: none; font-family: var(--font-serif);
  font-size: 20px; font-weight: 700; letter-spacing: -0.01em;
}
.brand-badge {
  font-family: var(--font-sans); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.nav-desktop { display: flex; align-items: center; gap: 6px; }
.nav-desktop a {
  text-decoration: none; font-size: 14px; font-weight: 600;
  padding: 8px 12px; border-radius: var(--radius-sm); color: var(--ink-2);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.nav-desktop a:hover, .nav-desktop a[aria-current="page"] {
  background: var(--surface-soft); color: var(--ink);
}
.menu-toggle {
  display: none; min-height: 42px; padding: 8px 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer;
}
.nav-mobile {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-base) var(--ease-out);
  overflow: hidden; border-top: 1px solid transparent;
}
.nav-mobile.open { grid-template-rows: 1fr; border-top-color: var(--line); }
.nav-mobile-inner { min-height: 0; display: flex; flex-direction: column; padding: 0 20px; }
.nav-mobile.open .nav-mobile-inner { padding: 10px 20px 16px; gap: 4px; }
.nav-mobile a {
  min-height: 44px; display: flex; align-items: center;
  text-decoration: none; font-weight: 600; font-size: 15px;
  padding: 8px 10px; border-radius: var(--radius-sm);
}
.nav-mobile a[aria-current="page"] { background: var(--surface-soft); color: var(--accent); }

@media (max-width: 820px) {
  .nav-desktop { display: none; }
  .menu-toggle { display: inline-flex; align-items: center; }
}

/* Hero & Quick Verdict */
.hero { padding: 28px 0 22px; }
.hero-grid {
  display: grid; grid-template-columns: 1.25fr 0.75fr; gap: 24px; align-items: center;
}
@media (max-width: 880px) { .hero-grid { grid-template-columns: 1fr; } }

.kicker {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--accent); margin: 0 0 8px;
}
h1 {
  font-family: var(--font-serif); font-size: clamp(28px, 4vw, 42px);
  line-height: 1.14; margin: 0 0 12px; letter-spacing: -0.015em;
}
h1 em { font-style: italic; color: var(--accent); font-weight: 600; }
.lead { font-size: 16.5px; color: var(--ink-2); margin: 0 0 14px; max-width: 65ch; }

.verdict-box {
  background: var(--surface); border: 1px solid var(--line-strong);
  border-left: 4px solid var(--accent); border-radius: var(--radius-sm);
  padding: 13px 16px; box-shadow: var(--shadow-soft);
}
.verdict-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); margin-bottom: 4px;
}
.verdict-box p { margin: 0; font-size: 14px; color: var(--ink-2); }

.hero-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-soft); margin: 0;
}
.hero-card img { width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; }
.hero-card figcaption { padding: 9px 12px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); }

/* Studio Workbench */
.workbench {
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-card);
  padding: 20px; margin: 8px 0 32px;
}
@media (max-width: 520px) { .workbench { padding: 14px; } }

.wb-top-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.preset-strip { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill-btn {
  min-height: 42px; padding: 8px 13px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface-soft); color: var(--ink);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.pill-btn:hover { border-color: var(--ink-2); }
.pill-btn:active { transform: scale(0.98); }
.pill-btn[aria-pressed="true"], .pill-btn.active {
  background: var(--ink-btn); color: #fff; border-color: var(--ink-btn);
}

.ai-compare-toggle {
  display: inline-flex; flex-wrap: wrap; gap: 6px; padding: 4px;
  background: var(--surface-soft); border: 1px solid var(--line); border-radius: 999px;
}
.ai-compare-btn {
  min-height: 38px; padding: 6px 12px; border: 0; border-radius: 999px;
  background: transparent; color: var(--ink-2); font-size: 13px; font-weight: 700; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.ai-compare-btn[aria-pressed="true"] {
  background: var(--accent); color: #fff;
}

.wb-grid {
  display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start;
}
@media (max-width: 940px) { .wb-grid { grid-template-columns: 1fr; } }

.wb-controls {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--surface-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 14px;
}
.ctrl-group { display: flex; flex-direction: column; gap: 6px; }
.ctrl-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; font-weight: 700; color: var(--ink);
}
.ctrl-val { font-family: var(--font-mono); font-size: 12.5px; color: var(--accent); font-weight: 700; }

.select-ctrl, .range-ctrl, .file-drop {
  width: 100%; min-height: 42px;
}
.select-ctrl {
  padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600;
}
.range-ctrl { accent-color: var(--accent); cursor: pointer; }

.upload-label {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 14px;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-size: 13.5px; font-weight: 700;
  cursor: pointer; text-align: center;
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.upload-label:hover { border-color: var(--accent); background: var(--accent-soft); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Canvas Stage */
.wb-stage-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stage-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between;
}
.metrics-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 8px;
}
.metric-pill {
  background: var(--surface-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px;
}
.metric-k { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.metric-v { font-size: 14.5px; font-weight: 700; color: var(--ink); }

.canvas-viewport {
  position: relative; width: 100%; overflow: auto;
  background: var(--surface-tint); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 14px;
  display: flex; justify-content: center; align-items: center; min-height: 340px;
}
#chartCanvas {
  background: #fff; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  cursor: crosshair; touch-action: manipulation;
}

.canvas-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--surface-soft);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.tool-seg {
  display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
.tool-btn {
  min-height: 38px; padding: 6px 11px; border: 0; border-radius: 4px;
  background: transparent; color: var(--ink-2); font-size: 12.5px; font-weight: 700; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.tool-btn[aria-pressed="true"] { background: var(--ink-btn); color: #fff; }
.hover-readout {
  font-family: var(--font-mono); font-size: 12px; color: var(--ink-2);
  padding: 4px 8px; border-radius: 4px; background: var(--surface); border: 1px solid var(--line);
}
.progress-track {
  height: 8px; width: 100%; background: var(--surface-tint);
  border-radius: 999px; overflow: hidden; margin: 6px 0 10px;
}
.progress-fill {
  height: 100%; background: var(--ok); width: 0%;
  transition: width var(--dur-base) var(--ease-out);
}
.row-item.done { opacity: 0.68; }
.row-check {
  width: 20px; height: 20px; border-radius: 4px; border: 1.5px solid var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0;
}
.row-item.done .row-check { background: var(--ok); border-color: var(--ok); color: #fff; }

/* Palette Swatches for Click-to-Paint */
.palette-bar {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 10px 12px; background: var(--surface-soft);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.swatch-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 5px 10px;
  border: 2px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.swatch-btn[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.swatch-dot { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.25); flex-shrink: 0; }
.swatch-sym { font-family: var(--font-mono); font-weight: 700; }

/* Action & Inline Conversion Bar */
.result-cta-bar {
  background: var(--surface-soft); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700; text-decoration: none; cursor: pointer; border: 1px solid transparent;
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-ink { background: var(--ink-btn); color: #fff; }
.btn-ink:hover { background: var(--ink-btn-hover); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--ink); }

.status-msg { font-size: 13px; font-weight: 600; color: var(--ok); min-height: 18px; }
.error-banner {
  background: rgba(180, 35, 24, 0.1); border: 1px solid #d92d20; color: #b42318;
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
}

/* Shopping Table & Crochet Written Row Tracker */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--surface-soft); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

.row-tracker-list {
  max-height: 300px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface);
}
.row-item {
  width: 100%; text-align: left; min-height: 44px; padding: 10px 14px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink);
  font-size: 13.5px; cursor: pointer; display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline;
  transition: background var(--dur-fast) var(--ease-out);
}
.row-item:hover { background: var(--surface-soft); }
.row-item[aria-current="true"] {
  background: var(--ok-soft); border-left: 4px solid var(--ok); font-weight: 700;
}
.row-dir { font-family: var(--font-mono); font-size: 12px; padding: 2px 6px; border-radius: 4px; background: var(--surface-tint); }

/* Content Sections & Related Cluster */
.section { padding: 28px 0; border-top: 1px solid var(--line); }
.section h2 { font-family: var(--font-serif); font-size: clamp(22px, 3vw, 30px); margin: 0 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 18px; box-shadow: var(--shadow-soft);
}
.card h3 { margin: 6px 0 8px; font-size: 17px; }
.tag {
  display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-soft); color: var(--accent);
}

.faq-item {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 10px;
}
.faq-item summary { font-weight: 700; cursor: pointer; min-height: 28px; }
.faq-item p { margin: 10px 0 2px; color: var(--ink-2); font-size: 14.5px; }

.site-footer {
  border-top: 1px solid var(--line); background: var(--surface-soft);
  padding: 32px 0 24px; margin-top: 24px; font-size: 14px;
}
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 20px; }
.footer-grid h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.footer-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.footer-bottom {
  padding-top: 16px; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px;
  font-size: 12.5px; color: var(--muted);
}

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