.gallery-page {
  padding-top: 32px;
}

.gallery-page [hidden] {
  display: none !important;
}

.gallery-page h1 {
  margin: 0;
  font-size: clamp(2.5rem, 3.6vw, 3.375rem);
  line-height: 1.12;
  letter-spacing: -0.01em;
}

.gallery-intro {
  margin: 12px 0 26px;
  color: var(--ink-muted);
  font-size: 1.25rem;
  line-height: 1.26;
}

.gallery-layout {
  display: grid;
  grid-template: "filters search" max-content "filters cards" min-content "archive cards" 1fr / 230px minmax(0, 1fr);
  column-gap: 24px;
  align-items: start;
  align-content: start;
}

.sketch-search {
  grid-area: search;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.sketch-search input {
  width: min(100%, 510px);
  height: 44px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-md);
  padding: 0 13px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.sketch-search input::placeholder {
  color: var(--ink-muted);
  opacity: 1;
}

.sketch-count,
.sketch-tags,
.sketch-caption {
  font: 0.75rem/1.45 var(--mono);
  color: var(--accent);
}

.sketch-count {
  flex: 0 0 auto;
  color: var(--ink-muted);
}

.sketch-filters {
  grid-area: filters;
}

.sketch-filters h2,
.gallery-archive h2 {
  margin: 0 0 9px;
  font-size: 1.19rem;
  line-height: 1.24;
}

.sketch-filter-list {
  display: grid;
  justify-items: start;
  gap: 8px;
}

.sketch-filter,
.gallery-primary,
.gallery-secondary,
.gallery-quiet {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 47px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--ink);
  background: transparent;
  font: 0.925rem var(--sans);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.sketch-filter:hover,
.gallery-quiet:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--accent);
}

.sketch-filter[aria-pressed="true"],
.gallery-secondary {
  border-color: var(--accent);
  color: var(--accent);
}

.gallery-primary {
  border-color: var(--accent);
  color: var(--brand-ink);
  background: var(--brand);
}

.gallery-primary:hover {
  color: var(--brand-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sketch-filter:not([aria-pressed="true"]),
.gallery-quiet {
  padding-inline: 6px;
}

.sketch-filter-short,
.sketch-copy-short {
  display: none;
}

.gallery-archive {
  grid-area: archive;
  align-self: start;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.gallery-panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.gallery-panel p {
  margin: 8px 0 7px;
  color: var(--ink-muted);
  line-height: 1.28;
}

.gallery-page .examples-grid {
  grid-area: cards;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 17px 18px;
}

.sketch-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.sketch-card a {
  display: block;
  height: 100%;
  padding: 12px;
  border-radius: inherit;
  color: var(--ink);
  text-decoration: none;
}

.sketch-card a:hover h3 {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sketch-card img,
.sketch-stage {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
  background: var(--stage);
}

.sketch-card img {
  aspect-ratio: 306 / 134;
  height: auto;
  object-fit: contain;
}

.sketch-card h3 {
  margin: 9px 0;
  font-size: 1.32rem;
  line-height: 1.24;
  letter-spacing: -0.025em;
}

.sketch-card .sketch-description {
  margin: 8px 0 0;
  color: var(--ink-muted);
  line-height: 1.3;
}

.sketch-tags {
  margin: 0;
}

.sketch-origin {
  display: inline-block;
  margin-inline-start: 4px;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  color: var(--ink);
  background: var(--track);
  font: 700 0.8125rem/1.35 var(--sans);
  white-space: nowrap;
}

.gallery-page .sketch-card .sketch-description {
  display: none;
}

.gallery-empty {
  grid-area: cards;
}

.gallery-empty h2,
.sketch-viewer-layout h2 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.23;
}

.gallery-empty .gallery-secondary {
  margin-top: 5px;
}

.sketch-back {
  margin: -4px 0 26px;
}

.sketch-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 30px;
}

.sketch-heading .sketch-tags {
  font-size: 0.875rem;
  text-wrap: nowrap;
}

.sketch-viewer-layout {
  display: grid;
  grid-template: "stage edit" auto "stage learn" auto "stage original" auto / minmax(0, 2.06fr) minmax(0, 1fr);
  align-items: start;
  gap: 14px 24px;
}

.sketch-figure {
  grid-area: stage;
  min-width: 0;
  margin: 0;
}

.sketch-stage {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.sketch-stage > :is(img, canvas) {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sketch-stage:not([data-preview-state="playing"]) canvas {
  visibility: hidden;
  pointer-events: none;
}

.sketch-stage:not([data-presentation]) .sketch-presentation-actions {
  display: none;
}

.sketch-stage[data-presentation] {
  aspect-ratio: auto;
  border-radius: 0;
}

.sketch-stage[data-presentation] > canvas {
  /* The renderer sizes its drawing buffer independently of the stage. */
  width: 100% !important;
  height: 100% !important;
}

.sketch-presentation-actions button {
  background: var(--presentation-panel);
}

.sketch-presentation-actions button[aria-pressed="true"] {
  color: var(--brand-ink);
  background: var(--brand);
}

.sketch-source {
  position: absolute;
  inset: calc(var(--presentation-gap) * 2 + var(--presentation-controls-height)) auto var(--presentation-gap) var(--presentation-gap);
  z-index: 1;
  width: min(52rem, 63%);
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  font: 0.93rem/1.36 var(--mono);
  tab-size: 4;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.sketch-caption {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 7px;
}

.sketch-mandelbrot-controls {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.sketch-mandelbrot-controls label {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sketch-mandelbrot-controls input {
  flex: 1;
  min-width: 0;
  accent-color: var(--brand);
}

.mandelbrot-landmarks {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.sketch-copy-wide,
.sketch-caption [data-preview-action]:not([hidden]),
.sketch-caption [data-preview-action][hidden] + [data-enter-presentation] {
  margin-inline-start: auto;
}

.sketch-caption [data-enter-presentation] + .sketch-copy-wide {
  margin-inline-start: 0;
}

.sketch-copy-status {
  flex: 0 0 100%;
  text-align: right;
}

.sketch-copy-status:empty {
  display: none;
}

.sketch-cue-status:empty {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

.sketch-edit {
  grid-area: edit;
}

.sketch-edit-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 11px 0 12px;
}

.sketch-cue-status {
  flex: 0 0 100%;
}

.sketch-attribution {
  flex: 0 0 100%;
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.sketch-attribution p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.875rem;
  line-height: 1.5;
}

.sketch-edit .sketch-summary {
  margin-top: 13px;
  font-size: 1.11rem;
  line-height: 1.24;
}

.sketch-learn {
  grid-area: learn;
}

.sketch-original {
  grid-area: original;
}

.sketch-original-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.gallery-unavailable {
  min-height: 35vh;
}

.gallery-unavailable p {
  color: var(--ink-muted);
}

@media (max-width: 1050px) {
  .gallery-layout {
    grid-template-columns: 190px minmax(0, 1fr);
  }

  .gallery-page .examples-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .gallery-page {
    padding-top: 20px;
  }

  .gallery-intro {
    margin: 8px 0 18px;
    font-size: 1.04rem;
  }

  .gallery-layout {
    grid-template: "search" auto "filters" auto "cards" auto "archive" auto / minmax(0, 1fr);
    row-gap: 18px;
  }

  .sketch-search {
    position: relative;
    margin: 0;
  }

  .sketch-search input {
    width: 100%;
  }

  .sketch-count,
  .sketch-filters h2,
  .sketch-filter-wide,
  .sketch-copy-wide {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .sketch-copy-wide {
    display: none;
  }

  .sketch-filter-short,
  .sketch-copy-short {
    display: inline-flex;
  }

  .sketch-filter-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: thin;
    padding: 3px;
    margin: -3px;
  }

  .sketch-filter {
    flex: none;
  }

  .gallery-page .examples-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .sketch-card img {
    aspect-ratio: 326 / 167;
  }

  .gallery-page .sketch-card .sketch-description {
    display: block;
  }

  .gallery-archive {
    margin-top: 0;
  }

  .sketch-back {
    margin: -1px 0 20px;
  }

  .sketch-heading {
    display: block;
    margin-bottom: 15px;
  }

  .sketch-heading .sketch-tags {
    margin-top: 10px;
    font-size: 0.75rem;
  }

  .sketch-viewer-layout {
    display: grid;
    grid-template: "stage stage" auto "edit edit" auto "original original" auto / max-content minmax(0, 1fr);
    gap: 14px 5px;
  }

  .sketch-stage {
    aspect-ratio: 350 / 258;
  }

  .sketch-caption {
    margin-top: 0;
  }

  .sketch-source {
    inset: auto var(--presentation-gap) var(--presentation-gap);
    width: auto;
    height: min(57%, calc(100% - var(--presentation-controls-height) - var(--presentation-gap) * 2));
    font-size: 0.8rem;
  }

  .sketch-copy-status {
    text-align: left;
  }

  .sketch-edit,
  .sketch-learn {
    display: contents;
  }

  .sketch-edit h2,
  .sketch-learn :is(h2, p) {
    display: none;
  }

  .sketch-edit .sketch-summary,
  .sketch-edit-actions {
    grid-column: 1 / -1;
  }

  .sketch-edit .sketch-summary {
    margin: 0;
  }

  .sketch-edit-actions {
    margin: 0;
  }

  .sketch-edit > [data-source-link],
  .sketch-learn > a {
    align-self: start;
  }

  .sketch-original {
    grid-area: auto / 1 / auto / -1;
  }

  .sketch-original p {
    margin-block: 4px;
  }

  .sketch-original .sketch-original-actions a {
    min-height: 44px;
  }

  .sketch-edit [data-source-link],
  .sketch-learn > a {
    grid-row: 4;
  }

  .sketch-learn > a {
    grid-column: 2;
  }

  .has-component-guide .sketch-learn p {
    display: block;
    grid-column: 1 / -1;
    grid-row: 5;
    margin: 0;
  }
}

.sketch-editor-note {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
