/* Visualizations (/visualizations and /visualizations/:slug). */
html:has(.canvas-gallery), body:has(.canvas-gallery) { background: #08090d; color-scheme: dark; }

.canvas-gallery {
  --cg-bg: #08090d;
  --cg-panel: #10121a;
  --cg-panel-2: #151824;
  --cg-line: #222636;
  --cg-line-strong: #343a52;
  --cg-text: #e9ebf3;
  --cg-muted: #9aa0b6;
  --cg-dim: #6c7290;
  --cg-accent: #8be9c9;
  --cg-accent-2: #ff8bd0;
  background: var(--cg-bg);
  color: var(--cg-text);
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.canvas-gallery * { box-sizing: border-box; }
.canvas-gallery a { color: inherit; }
.canvas-gallery :focus-visible { outline: 2px solid var(--cg-accent); outline-offset: 3px; }
.cg-wrap { max-width: 1400px; margin: 0 auto; padding: 22px 28px 48px; }
.cg-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Gallery */
.cg-topline { display: flex; gap: 8px; font-size: 12px; letter-spacing: .02em; color: var(--cg-dim); }
.cg-topline a { color: var(--cg-muted); text-decoration: none; }
.cg-topline a:hover { color: var(--cg-text); }
.cg-intro { margin: 40px 0 34px; max-width: 760px; }
.cg-intro h1 {
  margin: 0 0 14px; font-size: clamp(38px, 5.4vw, 64px); line-height: 1; letter-spacing: -.035em; font-weight: 700;
  background: linear-gradient(100deg, #ffffff 10%, #c9f7e6 45%, #ffc2e6 75%, #b9b4ff 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.cg-intro p { margin: 0; font-size: 17px; line-height: 1.6; color: var(--cg-muted); }
.cg-intro code, .cg-about code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .92em; color: var(--cg-accent); }

/* Toolbar: search, category chips, count and Surprise me. Sticks while browsing. */
.cg-toolbar {
  position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr) auto; gap: 12px 16px; align-items: center;
  margin: 0 -28px 22px; padding: 12px 28px; background: rgba(8, 9, 13, .86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--cg-line);
}
.cg-search { position: relative; display: block; }
.cg-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--cg-dim); pointer-events: none; }
.cg-search input {
  width: 100%; height: 38px; padding: 0 12px 0 36px; border-radius: 10px; border: 1px solid var(--cg-line); background: var(--cg-panel);
  color: var(--cg-text); font: inherit; font-size: 14px; outline: none;
}
.cg-search input::placeholder { color: var(--cg-dim); }
.cg-search input:focus { border-color: var(--cg-line-strong); box-shadow: 0 0 0 3px rgba(139, 233, 201, .14); }
.cg-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: -2px; mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); }
.cg-chips::-webkit-scrollbar { display: none; }
.cg-chip {
  flex-shrink: 0; height: 30px; padding: 0 11px; border-radius: 999px; border: 1px solid var(--cg-line); background: transparent;
  color: var(--cg-muted); font: inherit; font-size: 12.5px; font-weight: 500; white-space: nowrap; cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.cg-chip span { margin-left: 3px; color: var(--cg-dim); font-variant-numeric: tabular-nums; font-size: 11px; }
.cg-chip:hover { color: var(--cg-text); border-color: var(--cg-line-strong); }
.cg-chip[aria-pressed="true"] { background: var(--cg-text); border-color: var(--cg-text); color: #0b0c11; }
.cg-chip[aria-pressed="true"] span { color: #4a4f63; }
.cg-toolbar-end { display: flex; align-items: center; gap: 12px; }
.cg-count { margin: 0; font-size: 12.5px; color: var(--cg-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cg-surprise {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px; border-radius: 9px; border: 1px solid rgba(139, 233, 201, .35);
  background: rgba(139, 233, 201, .08); color: var(--cg-accent); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.cg-surprise:hover { background: rgba(139, 233, 201, .16); }
.cg-empty { padding: 60px 0; text-align: center; color: var(--cg-muted); }
.cg-empty p { margin: 0 0 14px; font-size: 15px; }
.cg-empty button { height: 34px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--cg-line-strong); background: var(--cg-panel); color: var(--cg-text); font: inherit; font-size: 13px; cursor: pointer; }
.cg-grid > li[hidden] { display: none; }

/* Favorites. Stars need JavaScript, so they only show once the controller runs; the
   card star sits beside the card's link (a button can't nest in a link) and rises with it. */
.cg-grid > li { position: relative; }
.cg-star { display: none; }
.cg-ready .cg-star {
  position: absolute; top: 9px; right: 9px; z-index: 2; display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0;
  border-radius: 50%; border: 1px solid rgba(255, 255, 255, .4); background: rgba(8, 9, 13, .5); color: #fff; cursor: pointer;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); opacity: 0; transition: opacity .15s ease, transform .18s ease, background .15s ease;
}
.cg-star::before { content: ""; width: 17px; height: 17px; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3.5l2.6 5.3 5.9.9-4.25 4.1 1 5.8L12 16.9l-5.25 2.7 1-5.8L3.5 9.7l5.9-.9z' fill='none' stroke='%23000' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3.5l2.6 5.3 5.9.9-4.25 4.1 1 5.8L12 16.9l-5.25 2.7 1-5.8L3.5 9.7l5.9-.9z' fill='none' stroke='%23000' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; }
.cg-grid > li:hover .cg-star, .cg-star:focus-visible, .cg-star[aria-pressed="true"] { opacity: 1; }
.cg-grid > li:hover .cg-star { transform: translateY(-3px); }
.cg-star:hover { background: rgba(8, 9, 13, .75); }
.cg-star[aria-pressed="true"] { color: #fbbf24; background: rgba(8, 9, 13, .68); border-color: rgba(251, 191, 36, .55); }
.cg-star[aria-pressed="true"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3.5l2.6 5.3 5.9.9-4.25 4.1 1 5.8L12 16.9l-5.25 2.7 1-5.8L3.5 9.7l5.9-.9z' stroke='%23000' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3.5l2.6 5.3 5.9.9-4.25 4.1 1 5.8L12 16.9l-5.25 2.7 1-5.8L3.5 9.7l5.9-.9z' stroke='%23000' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E"); }
@media (hover: none) { .cg-ready .cg-star { opacity: 1; } }

.cg-favorites-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--cg-line);
  background: transparent; color: var(--cg-muted); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.cg-favorites-toggle[hidden] { display: none; }
.cg-favorites-toggle svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.cg-favorites-toggle span { color: var(--cg-dim); font-variant-numeric: tabular-nums; }
.cg-favorites-toggle:hover { color: var(--cg-text); border-color: var(--cg-line-strong); }
.cg-favorites-toggle[aria-pressed="true"] { background: rgba(251, 191, 36, .12); border-color: rgba(251, 191, 36, .5); color: #fde68a; }
.cg-favorites-toggle[aria-pressed="true"] svg { fill: #fbbf24; stroke: #fbbf24; }
.cg-favorites-toggle[aria-pressed="true"] span { color: #fcd34d; }

.cg-page-star svg { fill: none; stroke: currentColor; }
.cg-page-star[hidden] { display: none; }
.cg-page-star[aria-pressed="true"] { color: #fbbf24; border-color: rgba(251, 191, 36, .5); }
.cg-page-star[aria-pressed="true"] svg { fill: #fbbf24; }

.cg-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.cg-card {
  display: flex; flex-direction: column; height: 100%; text-decoration: none; border-radius: 12px; overflow: hidden;
  background: var(--cg-panel); border: 1px solid var(--cg-line);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.cg-card:hover, .cg-card:focus-visible { transform: translateY(-3px); border-color: var(--cg-line-strong); box-shadow: 0 14px 34px -14px rgba(0, 0, 0, .8), 0 0 0 1px rgba(139, 233, 201, .08); }
.cg-media { position: relative; display: block; aspect-ratio: 16 / 10; background: #000; overflow: hidden; }
.cg-media img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .4s ease; }
.cg-card:hover .cg-media img { transform: scale(1.03); }
.cg-preview { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity .25s ease; pointer-events: none; }
.cg-preview.is-visible { opacity: 1; }
.cg-caption { display: flex; align-items: baseline; gap: 8px; padding: 12px 14px 0; min-width: 0; }
.cg-number { font: 500 11px/1 ui-monospace, "SF Mono", Menlo, monospace; color: var(--cg-dim); }
.cg-name { font-weight: 600; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-category { margin-left: auto; flex-shrink: 0; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--cg-dim); }
.cg-summary { display: block; padding: 6px 14px 14px; font-size: 13px; line-height: 1.45; color: var(--cg-muted); }

.cg-footer { margin-top: 44px; padding-top: 22px; border-top: 1px solid var(--cg-line); display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; font-size: 13px; line-height: 1.6; color: var(--cg-dim); }
.cg-footer p { margin: 0; max-width: 760px; }
.cg-footer a { color: var(--cg-muted); text-decoration: none; white-space: nowrap; }
.cg-footer a:hover { color: var(--cg-text); }

@media (max-width: 1180px) {
  .cg-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cg-category { display: none; }
  .cg-toolbar { grid-template-columns: minmax(0, 1fr) auto; }
  .cg-chips { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 900px) { .cg-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .cg-wrap { padding: 16px 16px 36px; }
  .cg-intro { margin: 26px 0 24px; }
  .cg-intro p { font-size: 15px; }
  .cg-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .cg-toolbar { margin: 0 -16px 16px; padding: 10px 16px; gap: 10px; }
  .cg-count { display: none; }
  .cg-ready .cg-star { width: 30px; height: 30px; top: 7px; right: 7px; }
  /* Phones: the toolbar buttons and the back link keep their icons (and the
     favorites count) so search and the pager have room; labels stay for screen readers. */
  .cg-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  .cg-favorites-toggle { padding: 0 10px; }
  .cg-surprise { padding: 0 10px; }
  .cg-back { padding: 8px 10px; }
  .cg-counter { white-space: nowrap; }
  .cg-caption { padding: 10px 10px 0; }
  .cg-name { font-size: 14px; }
  .cg-summary { padding: 4px 10px 12px; font-size: 12px; }
  .cg-footer { flex-direction: column; }
}

/* Demo page */
.cg-demo-bar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; }
.cg-back { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--cg-muted) !important; text-decoration: none; padding: 8px 12px 8px 10px; border-radius: 8px; border: 1px solid var(--cg-line); background: var(--cg-panel); }
.cg-back:hover { color: var(--cg-text) !important; border-color: var(--cg-line-strong); }
.cg-pager { display: flex; align-items: center; gap: 10px; }
.cg-counter { font: 500 12px/1 ui-monospace, "SF Mono", Menlo, monospace; color: var(--cg-dim); min-width: 62px; text-align: center; }
.cg-counter b { color: var(--cg-text); font-weight: 600; }
.cg-icon-button {
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; border-radius: 8px; cursor: pointer;
  color: var(--cg-muted); background: var(--cg-panel); border: 1px solid var(--cg-line); text-decoration: none;
}
.cg-icon-button:hover { color: var(--cg-text); border-color: var(--cg-line-strong); background: var(--cg-panel-2); }
.cg-icon-button[hidden] { display: none; }

.cg-stage {
  position: relative; height: min(68vh, 760px); min-height: 380px; border-radius: 14px; overflow: hidden;
  background: #000 center / cover no-repeat; border: 1px solid var(--cg-line);
}
.cg-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; opacity: 0; outline: none; cursor: crosshair; }
.cg-stage.is-running canvas { opacity: 1; }
.cg-stage canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--cg-accent); }
.cg-stage:fullscreen { height: 100vh; border: 0; border-radius: 0; }
.cg-stage-controls { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; opacity: .55; transition: opacity .2s ease; }
.cg-stage:hover .cg-stage-controls, .cg-stage-controls:focus-within, .cg-stage.is-paused .cg-stage-controls { opacity: 1; }
.cg-stage-controls .cg-icon-button { background: rgba(8, 9, 13, .72); border-color: rgba(255, 255, 255, .14); color: #e9ebf3; backdrop-filter: blur(6px); }
.cg-stage-controls .cg-icon-button:hover { background: rgba(20, 22, 32, .9); }
.cg-when-paused { display: none; }
.cg-stage.is-paused .cg-when-paused { display: block; }
.cg-stage.is-paused .cg-when-playing { display: none; }
.cg-stage-message { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); margin: 0; padding: 10px 14px; border-radius: 8px; background: rgba(8, 9, 13, .85); color: var(--cg-text); font-size: 13px; text-align: center; max-width: calc(100% - 32px); }
.cg-stage-message[hidden] { display: none; }

.cg-detail { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 40px; margin-top: 32px; align-items: start; }
.cg-eyebrow { margin: 0 0 10px; font: 500 11px/1 ui-monospace, "SF Mono", Menlo, monospace; text-transform: uppercase; letter-spacing: .12em; color: var(--cg-accent); }
.cg-about h1 { margin: 0 0 12px; font-size: clamp(32px, 4vw, 46px); line-height: 1.04; letter-spacing: -.03em; font-weight: 700; }
.cg-about p { margin: 0 0 14px; font-size: 15px; line-height: 1.7; color: var(--cg-muted); }
.cg-about .cg-lead { font-size: 18px; line-height: 1.5; color: var(--cg-text); }
.cg-try { padding: 12px 14px; border-radius: 10px; background: var(--cg-panel); border: 1px solid var(--cg-line); }
.cg-try strong { color: var(--cg-text); font-weight: 600; }
.cg-techniques { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 18px; padding: 0; }
.cg-techniques li { font-size: 12px; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--cg-line-strong); color: #cfd3e3; background: var(--cg-panel); }
.cg-source { font-size: 13px !important; }
.cg-source a { color: var(--cg-accent); text-decoration: none; }
.cg-source a:hover { text-decoration: underline; }
.cg-source span { color: var(--cg-dim); }

.cg-prompt { border-radius: 14px; background: var(--cg-panel); border: 1px solid var(--cg-line); overflow: hidden; }
.cg-prompt-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 18px 18px 14px; border-bottom: 1px solid var(--cg-line); }
.cg-prompt h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.cg-prompt-top p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--cg-muted); }
.cg-copy {
  flex-shrink: 0; cursor: pointer; padding: 9px 14px; border-radius: 8px; font: 600 13px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  color: #06110d; background: var(--cg-accent); border: 0; transition: background .15s ease, transform .1s ease;
}
.cg-copy:hover { background: #a6f2d8; }
.cg-copy:active { transform: translateY(1px); }
.cg-copy.is-copied { background: #ffffff; }
.cg-prompt pre {
  margin: 0; padding: 16px 18px 20px; max-height: 460px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  font: 12.5px/1.65 ui-monospace, "SF Mono", Menlo, monospace; color: #cfd3e3; background: #0c0e15;
}
.cg-prompt pre:focus-visible { outline-offset: -2px; }

.cg-neighbors { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 40px; }
.cg-neighbor { display: flex; align-items: center; gap: 14px; padding: 10px; border-radius: 12px; background: var(--cg-panel); border: 1px solid var(--cg-line); text-decoration: none; transition: border-color .18s ease; min-width: 0; }
.cg-neighbor:hover { border-color: var(--cg-line-strong); }
.cg-neighbor img { width: 132px; height: auto; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: #000; }
.cg-neighbor span { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cg-neighbor small { font: 500 10.5px/1 ui-monospace, "SF Mono", Menlo, monospace; text-transform: uppercase; letter-spacing: .1em; color: var(--cg-dim); }
.cg-neighbor b { font-size: 16px; font-weight: 600; }
.cg-neighbor em { font-style: normal; font-size: 13px; line-height: 1.4; color: var(--cg-muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cg-neighbor-next { flex-direction: row-reverse; text-align: right; }

/* Related visualizations: a 3x3 grid under previous and next. */
.cg-related { margin-top: 44px; }
.cg-related h2 { margin: 0 0 16px; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--cg-dim); }
.cg-related-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.cg-related-grid a {
  display: flex; flex-direction: column; height: 100%; text-decoration: none; border-radius: 12px; overflow: hidden;
  background: var(--cg-panel); border: 1px solid var(--cg-line); transition: transform .18s ease, border-color .18s ease;
}
.cg-related-grid a:hover { transform: translateY(-2px); border-color: var(--cg-line-strong); }
.cg-related-media { display: block; aspect-ratio: 16 / 10; background: #000; overflow: hidden; }
.cg-related-media img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cg-related-text { display: flex; align-items: baseline; gap: 8px; padding: 11px 13px 0; min-width: 0; }
.cg-related-text b { font-size: 15px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cg-related-text small { margin-left: auto; flex-shrink: 0; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--cg-dim); }
.cg-related-summary { display: block; padding: 5px 13px 13px; font-size: 13px; line-height: 1.45; color: var(--cg-muted); }

@media (max-width: 960px) {
  .cg-detail { grid-template-columns: minmax(0, 1fr); gap: 28px; }
}
@media (max-width: 640px) {
  .cg-stage { height: 62vh; min-height: 320px; border-radius: 10px; }
  .cg-stage-controls { opacity: 1; top: 8px; right: 8px; }
  .cg-detail { margin-top: 22px; }
  .cg-prompt-top { flex-direction: column; }
  .cg-neighbors { grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 28px; }
  .cg-neighbor img { width: 96px; }
  .cg-neighbor-next { flex-direction: row; text-align: left; }
  /* Phones: two columns of eight keeps the rows even. */
  .cg-related { margin-top: 32px; }
  .cg-related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .cg-related-grid li:nth-child(9) { display: none; }
  .cg-related-text { padding: 9px 10px 0; }
  .cg-related-text b { font-size: 13.5px; }
  .cg-related-text small { display: none; }
  .cg-related-summary { padding: 4px 10px 11px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .cg-card, .cg-media img, .cg-preview, .cg-stage-controls { transition: none; }
  .cg-card:hover, .cg-card:focus-visible { transform: none; }
}
