/* Captain Store — Advanced Layout components (.cl-*).

   Builder descriptions in the HTML format (project.description_format = 'html') are sanitized on publish
   (helpers.sanitize_layout_html) and placed inside the material's `.prose` wrapper. Authors wrap them in
   <div class="cl">…</div>; every rule here is scoped under `.cl` (two classes) so it wins over the
   `.prose p / ul / li / a` rules of store.css. Only the shared tokens are used (--background, --card,
   --muted, --border, --accent, --radius …), so light and dark themes work in the store and in the
   dashboard preview (which links this file inside a shadow root). Mobile first: one column below 40rem. */

/* A description with a layout uses the full content width (plain text keeps the 46rem reading measure). */
.prose:has(> .cl) { max-width: none; }
.overview:has(.prose > .cl) { max-width: none; }
.inline-overview:has(.prose > .cl) { max-width: calc(var(--content, 68rem) + 2rem); }
/* Breadcrumbs above a wide layout description start at the same left edge as the description. */
.inline-below:has(.inline-overview .prose > .cl) .inline-crumbs { max-width: calc(var(--content, 68rem) + 2rem); }

.cl { --cl-gap: 1rem; display: flow-root; color: var(--foreground); overflow-wrap: anywhere; }
.cl > :first-child, .cl .cl-section > :first-child { margin-top: 0; }
.cl img { max-width: 100%; height: auto; }
.cl svg:not([width]) { width: 1.25rem; height: 1.25rem; }

/* ---------- typography inside a layout ---------- */
.cl h2 { margin: 0 0 0.75rem; font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.55rem); }
.cl h3 { margin: 1.25rem 0 0.5rem; font-size: 1.05rem; font-weight: 800; }
.cl h4 { margin: 1rem 0 0.35rem; font-size: 0.95rem; font-weight: 800; }
.cl > p, .cl .cl-section > p, .cl .cl-section > ul:not([class]), .cl .cl-section > ol:not([class]) { max-width: 46rem; }
.cl code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85em; background: var(--muted); padding: 0.1rem 0.3rem; border-radius: 0.3rem; }
.cl pre { margin: 0 0 1rem; padding: 0.9rem 1rem; background: var(--muted); border-radius: calc(var(--radius) - 2px); overflow-x: auto; font-size: 0.85rem; }
.cl pre code { background: none; padding: 0; }
.cl blockquote { margin: 0 0 1rem; padding: 0.25rem 0 0.25rem 1rem; border-left: 3px solid var(--border); color: var(--muted-foreground); }
.cl hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }
.cl mark { background: color-mix(in srgb, var(--accent) 16%, transparent); color: inherit; padding: 0 0.15em; border-radius: 0.2em; }
.cl table:not(.cl-table) { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.cl dl { margin: 0 0 1rem; }
.cl dt { font-weight: 700; }
.cl dd { margin: 0 0 0.6rem; color: var(--muted-foreground); }

/* ---------- sections ---------- */
.cl .cl-section { margin: 0 0 clamp(2rem, 1.5rem + 2vw, 3rem); }
.cl .cl-section:last-child { margin-bottom: 0; }
.cl .cl-eyebrow { display: block; margin: 0 0 0.4rem; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted-foreground); }
.cl .cl-lead { margin: 0 0 1.25rem; max-width: 46rem; font-size: 1.125rem; line-height: 1.6; color: var(--muted-foreground); }

/* ---------- icons ---------- */
.cl .cl-icon { display: inline-block; width: 1.25rem; height: 1.25rem; flex: none; vertical-align: -0.22em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- grid + cards ---------- */
.cl .cl-grid { display: grid; gap: var(--cl-gap); grid-template-columns: minmax(0, 1fr); margin: 0 0 1.25rem; padding: 0; list-style: none; }
.cl .cl-grid > li { margin: 0; }
@media (min-width: 40rem) {
  .cl .cl-grid-2, .cl .cl-grid-3, .cl .cl-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 60rem) {
  .cl .cl-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 64rem) {
  .cl .cl-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.cl .cl-card { position: relative; min-width: 0; margin: 0; padding: 1.25rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.cl .cl-card > :last-child { margin-bottom: 0; }
.cl .cl-card h3, .cl .cl-card h4 { margin: 0 0 0.4rem; font-size: 1.02rem; }
.cl .cl-card p { margin: 0 0 0.75rem; color: var(--muted-foreground); }
.cl .cl-card ul, .cl .cl-card ol { margin: 0 0 0.75rem; }
.cl .cl-card-icon { display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; margin: 0 0 0.85rem; border-radius: calc(var(--radius) - 2px); background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); }
.cl .cl-card-icon svg { width: 1.375rem; height: 1.375rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- numbered steps (<ol class="cl-steps"><li><h3/><p/></li>…) ---------- */
.cl .cl-steps { counter-reset: cl-step; display: grid; gap: var(--cl-gap); grid-template-columns: minmax(0, 1fr); margin: 0 0 1.25rem; padding: 0; list-style: none; }
@media (min-width: 40rem) {
  .cl .cl-steps { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
  /* 5 or 6 steps: at most 3 columns (3 + 2 / 3 + 3) instead of 4 + 1 / 4 + 2. */
  .cl .cl-steps:has(> li:nth-child(5)):not(:has(> li:nth-child(7))) { grid-template-columns: repeat(auto-fit, minmax(max(13rem, calc((100% - 2 * var(--cl-gap)) / 3)), 1fr)); }
  /* 4 steps: 2 + 2 on tablets (not 3 + 1), one row from 64rem. */
  .cl .cl-steps:has(> li:nth-child(4):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 64rem) {
  .cl .cl-steps:has(> li:nth-child(4):last-child) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.cl .cl-steps > li { counter-increment: cl-step; min-width: 0; margin: 0; padding: 1.25rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.cl .cl-steps > li::before { content: counter(cl-step); display: inline-grid; place-items: center; width: 2rem; height: 2rem; margin: 0 0 0.75rem; border-radius: 999px; background: var(--primary); color: var(--primary-foreground); font-weight: 800; font-size: 0.9rem; line-height: 1; }
.cl .cl-steps h3 { margin: 0 0 0.35rem; font-size: 1.02rem; }
.cl .cl-steps p { margin: 0; color: var(--muted-foreground); }

/* ---------- colour swatches (style="--c:#C67B5C") ---------- */
.cl .cl-swatches { --cl-sw-max: 99; display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fill, minmax(max(5.5rem, calc((100% - (var(--cl-sw-max) - 1) * 0.5rem) / var(--cl-sw-max))), 1fr)); margin: 0 0 1.25rem; padding: 0; list-style: none; }
/* Long palettes: cap the columns at a divisor of the count so rows come out even (12 = 6 + 6, 16 = 8 + 8, 18 = 9 + 9). */
.cl .cl-swatches:has(> :nth-child(10)) { --cl-sw-max: 6; }
.cl .cl-swatches:has(> :nth-child(16):last-child) { --cl-sw-max: 8; }
.cl .cl-swatches:has(> :nth-child(18):last-child) { --cl-sw-max: 9; }
/* Tablets fit only ~7 columns: use the next divisor down (16 = 4 × 4, 18 = 6 × 3). */
@media (max-width: 63.99rem) {
  .cl .cl-swatches:has(> :nth-child(16):last-child) { --cl-sw-max: 4; }
  .cl .cl-swatches:has(> :nth-child(18):last-child) { --cl-sw-max: 6; }
}
.cl .cl-swatch { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; margin: 0; padding: 0.4rem 0.4rem 0.5rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.cl .cl-swatch-chip { display: block; aspect-ratio: 2 / 1; margin: 0 0 0.3rem; border-radius: calc(var(--radius) - 4px); background: var(--c, var(--muted)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--foreground) 12%, transparent); }
.cl .cl-swatch-name { font-weight: 700; font-size: 0.82rem; line-height: 1.3; }
.cl .cl-swatch code { align-self: flex-start; padding: 0; background: none; font-size: 0.72rem; color: var(--muted-foreground); }

/* ---------- comparison table ---------- */
.cl .cl-table-wrap { max-width: 100%; margin: 0 0 1.25rem; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius);
  /* Scroll shadows: a soft edge appears on the side that still has hidden columns (covers scroll with the content). */
  background:
    linear-gradient(to right, var(--card) 40%, transparent) left center / 2.5rem 100% no-repeat local,
    linear-gradient(to left, var(--card) 40%, transparent) right center / 2.5rem 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, color-mix(in srgb, var(--foreground) 22%, transparent), transparent) left center / 0.85rem 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, color-mix(in srgb, var(--foreground) 22%, transparent), transparent) right center / 0.85rem 100% no-repeat scroll,
    var(--card); }
.cl .cl-table { width: 100%; margin: 0 0 1.25rem; border-collapse: collapse; font-size: 0.92rem; overflow-wrap: normal; }
.cl .cl-table-wrap > .cl-table { min-width: 32rem; margin: 0; }
.cl .cl-table caption { padding: 0.75rem 0.9rem 0; text-align: left; font-size: 0.85rem; color: var(--muted-foreground); caption-side: top; }
.cl .cl-table th, .cl .cl-table td { min-width: 6rem; padding: 0.7rem 0.9rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
/* min-width: CJK text breaks after any character, so without it a squeezed column turns into one glyph per line. */
.cl .cl-table thead th { background: var(--muted); color: var(--muted-foreground); font-size: 0.82rem; font-weight: 700; }
.cl .cl-table tbody th { font-weight: 600; }
.cl .cl-table tbody tr:last-child > * { border-bottom: 0; }
.cl .cl-yes, .cl .cl-no { font-weight: 700; white-space: nowrap; }
.cl .cl-yes { color: var(--success); }
.cl .cl-no { color: var(--muted-foreground); }
/* Drawn markers (no icon fonts, no emoji): a check for yes, a dash for no. */
.cl .cl-yes::before { content: ""; display: inline-block; width: 0.35em; height: 0.7em; margin: 0 0.55em 0 0.1em; vertical-align: 0.05em; border: solid currentColor; border-width: 0 0.15em 0.15em 0; transform: rotate(45deg); }
.cl .cl-no::before { content: ""; display: inline-block; width: 0.7em; height: 0.15em; margin: 0 0.45em 0 0; vertical-align: 0.3em; background: currentColor; border-radius: 1px; }

/* ---------- FAQ (<details><summary>…</summary><p>…</p></details>) ---------- */
.cl .cl-faq { margin: 0 0 1.25rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cl .cl-faq > details { margin: 0; }
.cl .cl-faq > details + details { border-top: 1px solid var(--border); }
.cl .cl-faq summary { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3rem; padding: 0.75rem 1rem; font-weight: 700; line-height: 1.35; cursor: pointer; list-style: none; }
.cl .cl-faq summary::-webkit-details-marker { display: none; }
.cl .cl-faq summary::after { content: ""; flex: none; width: 0.5rem; height: 0.5rem; margin-right: 0.2rem; border: solid var(--muted-foreground); border-width: 0 2px 2px 0; transform: translateY(-0.15rem) rotate(45deg); transition: transform 0.15s; }
.cl .cl-faq details[open] > summary::after { transform: translateY(0.1rem) rotate(-135deg); }
.cl .cl-faq summary:hover { background: var(--muted); }
.cl .cl-faq summary:focus-visible { outline-offset: -2px; }
.cl .cl-faq details > :not(summary) { margin: 0; padding: 0 1rem 1rem; color: var(--muted-foreground); }

/* ---------- callout ---------- */
.cl .cl-callout { margin: 0 0 1.25rem; padding: 1rem 1.1rem; background: color-mix(in srgb, var(--accent) 6%, var(--card)); border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border)); border-left: 3px solid var(--accent); border-radius: var(--radius); }
.cl .cl-callout > :last-child { margin-bottom: 0; }
.cl .cl-callout h3, .cl .cl-callout h4 { margin: 0 0 0.35rem; }
.cl .cl-callout p { margin: 0 0 0.6rem; }
.cl .cl-callout-warn { --cl-warn: var(--warning, #b45309); background: color-mix(in srgb, var(--cl-warn) 8%, var(--card)); border-color: color-mix(in srgb, var(--cl-warn) 35%, var(--border)); border-left-color: var(--cl-warn); }

/* ---------- buttons + closing call to action ---------- */
.cl .cl-btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; max-width: 100%; min-height: 2.75rem; padding: 0.55rem 1.4rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--foreground); font-weight: 700; font-size: 0.95rem; line-height: 1.25; text-align: center; text-decoration: none; cursor: pointer; }
.cl .cl-btn:hover { background: var(--muted); color: var(--foreground); }
.cl .cl-btn-primary, .cl .cl-btn-primary:hover { color: #fff; border-color: transparent; background: linear-gradient(0deg, var(--accent) 0%, var(--accent-2, var(--accent)) 100%); }
.cl .cl-btn-primary:hover { filter: brightness(1.12); }
.cl .cl-btn svg { width: 1.125rem; height: 1.125rem; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cl .cl-cta { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.75rem; margin: 0 0 1.25rem; padding: clamp(1.25rem, 1rem + 2vw, 2.25rem) clamp(1rem, 0.75rem + 2vw, 2rem); text-align: center; background: var(--muted); border: 1px solid var(--border); border-radius: var(--radius); }
.cl .cl-cta > :not(.cl-btn) { flex: 1 1 100%; margin: 0; }
.cl .cl-cta h2, .cl .cl-cta h3 { margin: 0; }
.cl .cl-cta p { color: var(--muted-foreground); }
.cl .cl-cta > :not(.cl-btn) + .cl-btn { margin-top: 0.5rem; }

/* ---------- pills ---------- */
.cl .cl-pills { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1.25rem; padding: 0; list-style: none; }
.cl .cl-pill { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0; padding: 0.3rem 0.75rem; background: var(--card); border: 1px solid var(--border); border-radius: 999px; font-size: 0.85rem; font-weight: 600; line-height: 1.4; }
.cl .cl-pill svg { width: 0.95rem; height: 0.95rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- text + figure ---------- */
.cl .cl-split { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1fr); align-items: center; margin: 0 0 1.25rem; }
.cl .cl-split > * { min-width: 0; }
.cl .cl-split > div > :last-child { margin-bottom: 0; }
@media (min-width: 48rem) {
  .cl .cl-split { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2.5rem; }
}
.cl .cl-figure { margin: 0 0 1.25rem; }
.cl .cl-split > .cl-figure { margin: 0; }
.cl .cl-figure img { display: block; width: 100%; height: auto; background: var(--muted); border: 1px solid var(--border); border-radius: var(--radius); }
.cl .cl-figure figcaption { margin-top: 0.5rem; font-size: 0.85rem; color: var(--muted-foreground); }

/* ---------- stats ---------- */
.cl .cl-stats { display: grid; gap: var(--cl-gap); grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0 0 1.25rem; padding: 0; list-style: none; }
@media (min-width: 48rem) {
  .cl .cl-stats { grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); }
}
.cl .cl-stat { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; margin: 0; padding: 1rem 1.1rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.cl .cl-stat strong { font-size: clamp(1.4rem, 1.15rem + 1vw, 2rem); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.cl .cl-stat span { font-size: 0.85rem; color: var(--muted-foreground); }
