/* The fill picker: its sheet, tabs, rows, paints, pattern lists and search.

   Its layouts. Each media query in this file opens with the name of the layout it serves:
   - Phone sheet: the compact layout (compactLayout.ts), a bottom sheet in one column.
   - Two columns: the rows and tabs in a sidebar, the open tab beside them. Every window wider than
     a phone gets it at any height, and so does a phone on its side, which is also a phone sheet.
   - Tab menu: two columns with the height to stack the tabs down the sidebar.
   - Sideways phone: two columns on a phone on its side.
   - One column: a phone sheet that two columns don't take.
   - Laptop: the compact layout's opposite.
   - Sidebar paint tools: a laptop with the room to list the paint tools and brands in the sidebar.
   - Short window: the tabs, and the creator's bar (fill-creator.css), take less height.
   - Short phone: one column without the height to keep the rows while uploading or generating.
   The thresholds come in pairs, one on each side of a boundary (a phone's width, a short window's
   height); a change to one side of a pair goes with the other. */

/* Fill Picker Tabs */
.fill-picker-tabs {
  display: flex;
  border-bottom: 2px solid var(--line-1);
  gap: 4px;
}

.fill-picker-tab {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: 40px;
  padding: 8px 4px;
  white-space: nowrap;
  border: none;
  background: none;
  font-size: 0.9em;
  font-weight: 600;
  color: var(--ink-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

@media (hover: hover) {
  .fill-picker-tab:hover {
    color: var(--ink-6);
  }
}

.fill-picker-tab.active {
  color: var(--ui-accent);
  border-bottom-color: var(--ui-accent);
}

.fill-picker-tab-content {
  display: none;
}

/* In this design and My Palette: one row each, a label and then fills that scroll sideways. */
.fill-row.offers-nothing {
  display: none;
}

.fill-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fill-row-title {
  flex: 0 0 96px;
  font-size: 0.85em;
  font-weight: bold;
  text-align: left;
  white-space: nowrap;
}

.fill-row-no-matches {
  flex: 1 1 0;
  white-space: nowrap;
  color: var(--ink-3);
  font-size: 0.8em;
  text-align: left;
}

.fill-row [hidden] {
  display: none;
}

.fill-row.is-filtering .user-palette-empty {
  display: none;
}

/* A fill tile's side, the room the strips keep above and below it, and the gap between tiles. The
   tiles' tap areas reach into that room and half the gap. */
#colorModal {
  --fill-tile-size: 30px;
  --fill-strip-padding: 4px;
  --fill-tile-gap: 6px;
}

/* As tall as a row of fills, so saving the first one or filtering to none moves nothing. */
#colorModal .fill-row {
  min-height: calc(var(--fill-tile-size) + 2 * var(--fill-strip-padding));
}

/* The block padding is inside the strip because its overflow would clip the tiles' tap areas. */
.context-bar-fills,
.user-palette-grid {
  display: flex;
  flex: 1 1 0;
  gap: var(--fill-tile-gap);
  box-sizing: border-box;
  min-width: 0;
  padding-block: var(--fill-strip-padding);
  overflow: auto hidden;
  scrollbar-width: none;
  --focus-ring-offset: -2px;
}

/* Context bar: fills currently in use on the design */

/* A fill in the In this design or My Palette row. */
.fill-tile {
  flex: none;
  box-sizing: border-box;
  width: var(--fill-tile-size); height: var(--fill-tile-size); padding: 0;
  overflow: visible;
  border: 1px solid var(--line-4); border-radius: 4px;
  background: none;
  cursor: pointer; transition: border-color 0.15s;
}
@media (hover: hover) {
  .fill-tile:hover { border-color: var(--ink); }
}
.fill-tile svg { width: 100%; height: 100%; display: block; border-radius: 3px; }

/* User Palette */
.user-palette-grid:empty {
  display: none;
}
/* The row's name opens the palette's panel: quiet, with a chevron to say it goes somewhere. It is as
   tall as a tile, so like the tiles its focus ring fits in the row's strip padding: the patterns panel
   right under the row would paint over a ring that reached past it. */
.user-palette-open {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: var(--fill-tile-size);
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
}

.user-palette-open i {
  color: var(--ink-3);
  font-size: 0.7em;
}

/* A chevron after a label sits on the label's lowercase letters, not on the line's middle, which
   is above them in this font. */
.text-chevron {
  position: relative;
  top: 0.15em;
}

@media (hover: hover) {
  .user-palette-open:hover {
    text-decoration: underline;
  }
}

/* Wraps to a second line rather than losing words where the row is narrow. */
.user-palette-empty {
  flex: 1 1 0; min-width: 0;
  font-size: 0.8em; line-height: 1.15; color: var(--ink-3); text-align: left;
}

/* The tiles share out the row, so the grid ends where the buttons under it do. */
.materials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 4px;
  padding-block: 4px;
}

.materials-grid .color-box {
  width: auto;
  height: auto;
  aspect-ratio: 1;
  margin: 0;
}

/* My Patterns and Samples are each one row that scrolls sideways, like the fill rows above them, so
   the lists under them start in the first view however many patterns there are. Their tiles keep the
   grids' size. */
.materials-row {
  --row-tile-size: 52px;
  display: flex;
  overflow: auto hidden;
  scrollbar-width: none;
  --focus-ring-offset: -2px;
}

.materials-row .color-box {
  flex: 0 0 var(--row-tile-size);
}

/* A pattern's preview needs the cue's room for its row and its Save and Use; the cue comes back
   when it closes. */
#fillPickerTabMaterials[data-previewing] .more-cue {
  display: none;
}

.materials-section-header {
  padding-top: 10px;
  background: var(--surface);
  text-align: left;
  font-size: 0.85em;
  font-weight: bold;
  color: var(--ink-6);
}

/* A heading over a grid stays pinned while the grid scrolls under it. One over a single row isn't: the
   row scrolls past in a moment, and pinned, the heading would cover its top on the way. */
.materials-section-header--pinned {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* Under its heading, and lined up with it. */
.materials-lock-note p {
  margin: 4px 0 12px;
  text-align: left;
  color: var(--ink-6);
  font-size: 0.85em;
}

.materials-lock-note a {
  color: var(--brand);
  font-weight: 700;
  white-space: nowrap;
}

.materials-loading,
.materials-load-failed {
  font-size: 0.85em;
  color: var(--ink-3);
  text-align: center;
  padding: 12px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Etsy live-search (#530): placeholder tiles while the first page loads. */
.unified-etsy-skeleton {
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--line-2);
}

.materials-paging {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 6px;
}

.materials-show-more {
  padding: 4px 16px;
  font-size: 0.8em;
  background: var(--premium-tint);
  border: 1px solid var(--line-4);
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink-6);
}

@media (hover: hover) {
  .materials-show-more:hover {
    background: var(--premium-soft);
  }
}

/* Drawn inside the tile's edge, so the scrolling column a tile touches can't cut the ring. */
.materials-grid .color-box.is-previewed {
  outline: 3px solid var(--ui-accent);
  outline-offset: -3px;
}

/* The image's side is the height of the controls beside it, worked out from the same rows, so the
   two always line up. Anything else goes under both. */
#materialPreview {
  --preview-label-row: 44px;
  --preview-slider-row: 32px;
  --preview-actions-row: 44px;
  --preview-gap: 8px;
  --preview-size: calc(var(--preview-label-row) + var(--preview-slider-row) + var(--preview-gap) + var(--preview-actions-row));

  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: var(--preview-size) minmax(0, 1fr);
  grid-template-rows: calc(var(--preview-label-row) + var(--preview-slider-row)) var(--preview-actions-row) auto;
  grid-template-areas:
    "image zoom"
    "image actions"
    "info info";
  gap: var(--preview-gap) 12px;
  margin: 8px 0;
  text-align: left;
}

.material-preview-container {
  grid-area: image;
}

.material-preview-container svg {
  display: block;
  width: 100%;
  height: 100%;
}

.material-preview-info {
  grid-area: info;
}

.material-preview-bar {
  font-size: 0.85em;
  color: var(--ink-6);
}

.material-preview-zoom {
  display: grid;
  grid-area: zoom;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: var(--preview-label-row) var(--preview-slider-row);
  align-items: center;
}

.material-preview-zoom .fill-slider {
  grid-column: 1 / -1;
  width: 100%;
}

.material-preview-actions {
  display: flex;
  grid-area: actions;
  gap: 6px;
}

.material-preview-actions .fill-modal-button {
  min-width: 0;
  padding: 4px;
  white-space: nowrap;
}

/* Fixed, so its short messages don't move Use. */
#materialPreviewSave {
  flex: 0 0 min(40%, 88px);
}

#materialPreviewUse {
  flex: 1 1 0;
}

/* Phone sheet. */
@media (max-width: 768px), (max-height: 500px) {
  /* Fill tiles a finger can hit: a tile with its room and half the gap on each side makes a full tap
     target. */
  #colorModal {
    --fill-tile-size: 34px;
    --fill-strip-padding: calc((var(--tap-size) - var(--fill-tile-size)) / 2);
    --fill-tile-gap: calc(var(--tap-size) - var(--fill-tile-size));
  }

  /* A narrower edge than other sheets, so a phone's paint grid fits one more column. */
  #colorModal > .modal-content {
    --sheet-inline-padding: 12px;
    padding-bottom: 0;
  }

  /* A phone keeps the preview short: only the Buy link and the Etsy note go under it. */
  .material-preview-detail,
  .material-preview-info:not(.has-links) {
    display: none;
  }
}

/* Search input */
/* Unified search bar */
.unified-search-container {
  padding: 0 0 8px;
}

#unifiedSearch {
  box-sizing: border-box;
  width: 100%;
  padding: 8px 12px;
  border: 2px solid var(--line-3);
  border-radius: 20px;
  font-size: 0.95em;
  outline: none;
  transition: border-color 0.2s;
}

#unifiedSearch:focus {
  border-color: var(--brand);
}

/* A pattern can't be one color of a pattern, so with a color row chosen search offers no Generate.
   The rows leave out their patterns through their filter (applyRowFilter). */
#colorModal[data-paints-lent] .search-generate {
  display: none;
}

/* On the shapes tab a pick from the rows or a search would leave the form behind, with its work,
   so they wait for a color's Paint Brands, where a pick sets that color. */
#colorModal[data-panel="fillPickerCreator"][data-creator-mode="pattern"]:not([data-creator-view="paints"]) :is(.fill-row, .unified-search-container) {
  display: none;
}

/* Unified search results */
.unified-results-section {
  margin-bottom: 16px;
}

.unified-results-header {
  font-size: 0.85em;
  font-weight: bold;
  color: var(--ink-6);
  margin-bottom: 6px;
  text-align: left;
  padding-left: 4px;
}

.unified-results-header.collapsible {
  cursor: pointer;
  user-select: none;
}

.unified-results-header .results-count {
  font-weight: normal;
  color: var(--ink-2);
}

.unified-results-header .collapse-icon {
  transition: transform 0.15s;
}

.unified-results-section.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

.unified-results-section.collapsed .unified-color-grid,
.unified-results-section.collapsed .materials-grid,
.unified-results-section.collapsed .unified-pattern-grid {
  display: none;
}

.unified-material-upsell {
  text-align: center;
  padding: 12px 0;
  color: var(--ink-3);
  font-size: 0.9em;
}

.unified-material-upsell a {
  color: var(--brand);
  font-weight: 600;
}

.unified-generate-cta {
  text-align: center;
  padding: 16px 0 4px;
  color: var(--ink-3);
}

.unified-generate-cta p {
  margin-bottom: 8px;
  font-size: 0.9em;
}

.unified-no-results {
  text-align: center;
  padding: 20px 0;
  color: var(--ink-3);
}

.unified-any-color-tools {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.unified-no-results p {
  margin-bottom: 12px;
}

.unified-no-results .unified-no-results-hint {
  font-size: 0.9em;
  margin-bottom: 8px;
}

@keyframes highlight-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 60%, transparent); }
  50%  { box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 30%, transparent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.highlight-pulse {
  animation: highlight-pulse 0.8s ease-out 2;
}

/* The fill picker keeps one height, so switching tabs doesn't move the sheet, and the tab fills
   what the header leaves. */
#colorModal > .modal-content {
  display: flex;
  flex-direction: column;
}

#colorModal > .modal-content > * {
  flex-shrink: 0;
}

/* The title and tabs stay put; each tab scrolls on its own, so switching can't move them. The
   minimum keeps a usable list on a short screen, where the sheet itself scrolls instead. */
#colorModal #browseContent {
  display: contents;
}

/* The tabs go first, so the search and the rows can make way on a view that has no use for them
   and no tab moves. Under the tabs' line, the room the search keeps above My Palette, where the
   screen has it. */
#colorModal .fill-picker-tabs {
  container: picker-tabs / inline-size;
  flex-shrink: 0;
  order: 1;
  margin-bottom: 8px;
}

#colorModal .unified-search-container {
  order: 2;
}

#colorModal .fill-row {
  order: 3;
}

#colorModal #etsyPreview,
#colorModal .fill-picker-tab-content {
  order: 4;
}

#colorModal .fill-picker-tab-content.active,
#colorModal.is-searching #browseContent .fill-picker-tab-content[data-paint-tools] {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 240px;
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  --focus-ring-offset: -2px;
}

#colorModal .fill-picker-tab-content.active > * {
  flex-shrink: 0;
}

/* Each tab's content carries the sheet's foot padding. Under the patterns, Make your own carries the
   safe area. */
#colorModal #fillPickerTabColors.active > #paintTools {
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

#colorModal #fillPickerCreator.active > #fillCreator {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#colorModal #fillPickerTabMaterials.active > .materials-panel {
  padding-bottom: 16px;
}

#fillPickerTabMaterials .materials-panel,
#fillPickerTabMaterials .section-content {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
}

/* Short window. */
@media (max-height: 700px) {
  #colorModal .fill-picker-tabs {
    margin-bottom: 4px;
  }
}

/* Narrow, the labels get smaller to keep one line; narrower still, each icon goes above its label. */
@container picker-tabs (max-width: 300px) {
  .fill-picker-tab {
    gap: 4px;
    font-size: 0.8em;
  }
}

@container picker-tabs (max-width: 280px) {
  .fill-picker-tab {
    flex-direction: column;
    gap: 2px;
  }
}

/* The paints' controls share one line, so the paints start high on the screen. */
.paint-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 4px 0 12px;
}

.paint-toolbar > * {
  flex: 1 1 auto;
}

/* Narrow, the buttons drop their icons so the row stays one line. */
#paintTools {
  container: paint-tools / inline-size;
}

@container paint-tools (max-width: 330px) {
  .paint-toolbar .fill-modal-button {
    padding-inline: 8px;
  }

  .paint-toolbar .fill-modal-icon {
    display: none;
  }
}

.paint-toolbar .fill-modal-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding-block: 0;
  white-space: nowrap;
}

/* The brands pick in a menu, so their checkboxes don't take two lines of the screen. */
.brand-menu {
  position: relative;
}

#brandMenuButton {
  width: 100%;
  box-sizing: border-box;
}

.brand-menu-chevron {
  font-size: 0.75em;
  transition: transform 0.15s;
}

.brand-menu[data-open] .brand-menu-chevron {
  transform: rotate(180deg);
}

.brand-menu-list {
  display: flex;
  position: absolute;
  z-index: 3;
  top: calc(100% + 4px);
  right: 0;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 0;
  margin: 0;
  padding: 4px 14px;
  border: 1px solid var(--line-3);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 14px var(--shadow);
  font-size: 0.9em;
}

.brand-menu:not([data-open]) .brand-menu-list,
.brand-menu-title {
  display: none;
}

.brand-filter-list {
  display: flex;
  flex-direction: column;
}

.brand-menu-actions {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-2);
}

.brand-menu-actions button,
#noPaintsShown button {
  position: relative;
  min-height: 36px;
  white-space: nowrap;
  padding: 0 10px;
  border: 1px solid var(--line-3);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

#noPaintsShown {
  margin: 12px 0;
  color: var(--ink-3);
  text-align: center;
}

.brand-menu .brand-filter {
  --tap-y: 0;
  --tap-x: -14px;
  gap: 8px;
  min-height: 44px;
}

/* The paints scroll down only: their tap areas reach past the last column, and that mustn't scroll
   sideways. The Colors tab and a pattern color's paints both scroll this way. */
.paint-scroller {
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  --focus-ring-offset: -2px;
}

/* A comfortable tap apart both ways, and a faint edge so the palest paints show on the cream. */
.paint-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 4px;
}

.paint-grid .color-box {
  box-sizing: border-box;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  margin: 0;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 12%);
}

/* A bar of main actions. */
.fill-picker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

/* At the foot of a tab, on show however long the tab runs, and above the sticky section headings,
   which scroll under it. */
.fill-picker-foot {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding: 8px 0;
  background: var(--surface);
  /* The tab's edge can land on a fraction of a pixel, which would leave a row of the list showing. */
  box-shadow: 0 2px 0 var(--surface);
}

.fill-picker-actions > button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding-inline: 4px;
  white-space: nowrap;
}

@container (max-width: 320px) {
  .fill-picker-actions > button > i {
    display: none;
  }
}

#fillLockHint {
  position: absolute;
  right: 0;
  left: 0;
  z-index: 4;
  display: flex;
  gap: 4px;
  align-items: center;
  box-sizing: border-box;
  padding: 10px 4px 10px 12px;
  border: 1px solid var(--line-3);
  border-radius: 10px;
  background: var(--surface-1);
  box-shadow: 0 2px 8px var(--shadow);
  color: var(--ink);
  font-size: 0.85em;
  line-height: 1.4;
  text-align: left;
}

#fillLockHint p {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
}

.lock-link {
  white-space: nowrap;
}

#fillLockHint a {
  display: inline-block;
  color: var(--brand);
  font-weight: 700;
  white-space: nowrap;
}

#fillLockHint button {
  position: relative;
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: none;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

/* Lent to the shapes tab, the toolbar brings only its brands menu. */
#colorModal[data-paints-lent] .paint-pick-tool {
  display: none;
}

/* Results replace the tabs. They live with the brand filters, in the paint tools, wherever those
   are; clearing the search leaves the tab that was open. */
#colorModal.is-searching #browseContent .fill-picker-tab-content:not([data-paint-tools]),
#colorModal.is-searching .paint-pick-tool,
#colorModal.is-searching #browseContent:not(.shows-brand-filters) .paint-toolbar,
#colorModal.is-searching .paint-brands-section > .section-content,
#colorModal.is-searching #patternPaintsBack {
  display: none;
}

/* An Etsy search that came back empty leaves its grid with nothing to show. */
.materials-grid:empty {
  display: none;
}

.unified-pattern-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.unified-pattern-result {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 5px;
  border: 1px solid var(--line-4);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9em;
  cursor: pointer;
}

@media (hover: hover) {
  .unified-pattern-result:hover {
    border-color: var(--ink);
  }
}

.unified-pattern-result::before {
  content: "";
  width: 28px;
  height: 28px;
  border-radius: 4px;
}

.unified-pattern-result[data-pattern="checkered"]::before {
  background: repeating-conic-gradient(var(--ink) 0 25%, var(--line-1) 0 50%) 0 0 / 14px 14px;
}

.unified-pattern-result[data-pattern="stripes"]::before {
  background: repeating-linear-gradient(var(--ink) 0 4px, var(--line-1) 4px 8px);
}

.unified-pattern-result[data-pattern="diamonds"]::before {
  background: repeating-conic-gradient(from 45deg, var(--ink) 0 25%, var(--line-1) 0 50%) 0 0 / 14px 14px;
}

.unified-pattern-result[data-pattern="circles"]::before {
  background: radial-gradient(circle, var(--ink) 45%, var(--line-1) 50%) 0 0 / 9.33px 9.33px;
}

/* How far each tap area reaches past what it draws (the `tap-area` rule in tokens.css). */
.fill-tile { --tap-y: calc(-1 * var(--fill-strip-padding)); --tap-x: calc(var(--fill-tile-gap) / -2); }
.paint-grid .color-box { --tap-y: -4px; --tap-x: -4px; }
#moreColorsButton { --tap-y: -5px; }
.fill-picker-tab { --tap-bottom: -6px; }
.user-palette-open { --tap-y: -7px; }
/* Quiet 36px buttons, with the rest of a 44px tap around them. */
.brand-menu-actions button, #noPaintsShown button { --tap-y: -5px; --tap-x: 0px; }
#fillLockHint button { --tap-y: -8px; --tap-x: -8px; }

/* Select a Fill's title. A phone's sheet title has its own size and spacing (.sheet-title); a laptop's
   sits on the close button's line (the two-column block below sets where). */
.modal-title {
  font-weight: bold;
  color: var(--ui-accent);
  letter-spacing: 0.05em;
}

@media (min-width: 769px) and (min-height: 501px) {
  .modal-title {
    margin: var(--sheet-title-margin-top) 0 20px;
    font-size: 1.5em;
    line-height: var(--sheet-title-line-height);
    text-align: center;
  }

  .modal-title::after {
    content: "";
    display: block;
    height: 2px;
    background-color: var(--ui-accent);
    margin: 10px auto 0;
  }
}

/* Two columns. The rows and tabs take one column and the open tab the other, so the tab keeps the
   sheet's height and the sheet itself never scrolls. Every window wider than a phone gets it, at
   any height, as the left column fits beside the tab; a landscape phone or a short window gets it
   too, as it has no height for a tab under the rows. */
@media (min-width: 560px) and (max-height: 700px), (min-width: 769px) {
  #colorModal > .modal-content {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    /* The same split with the tab's column a whole number of pixels wide: at a fractional width the
       scrolling column cuts the last tile in a row, and its ring, by a fraction of a pixel. */
    grid-template-columns: minmax(0, 1fr) round(down, calc((100% - var(--column-gap)) * 6 / 11), 1px);
    /* The rows and tabs, the room the column's last part takes (the paint tools, Make your own), and
       the open tab's foot, which holds Make your own where the sidebar has no room for it. */
    grid-template-rows: repeat(5, auto) minmax(0, 1fr) auto;
    --column-gap: 28px;
    column-gap: var(--column-gap);
    /* How far the sidebar's panel reaches past its column into the gap. */
    --sidebar-overhang: 8px;
    overflow: hidden;
    isolation: isolate;
  }

  #colorModal > .modal-content > *,
  #colorModal .fill-picker-tabs {
    grid-column: 1;
  }

  /* The left column is a sidebar: tinted to the sheet's edges, so it reads as one panel however
     little it holds. */
  #colorModal > .modal-content::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 0 calc(-1 * var(--sidebar-overhang)) 0 calc(-1 * var(--sheet-inline-padding));
    grid-column: 1 / 2;
    grid-row: 1 / -1;
    border-right: 1px solid var(--line-2);
    background: var(--surface-1);
  }

  #colorModal #closeModal.close,
  #colorModal .modal-title {
    grid-row: 1;
  }

  /* The close button keeps the dialogs' inset from the sheet's top and the sidebar panel's edge, and
     the title shares its line, so the two share a middle at any top padding. The sheet doesn't scroll
     here, so they needn't stick. Read by the title's rules (.sheet-title, .modal-title). */
  #colorModal > .modal-content {
    --sheet-title-margin-top: calc(var(--dialog-close-inset) - var(--sheet-padding-top, var(--sheet-inline-padding)));
    --sheet-title-padding-top: 0px;
    --sheet-title-line-height: var(--dialog-close-size);
  }

  /* Above the title, which spans the row's cell under it and stacks at 2 in a phone's sheet; a grid
     item stacks without positioning. */
  #colorModal #closeModal.close {
    position: static;
    z-index: 3;
    align-self: start;
    justify-self: end;
    margin: calc(var(--dialog-close-inset) - var(--sheet-padding-top, var(--sheet-inline-padding))) calc(var(--dialog-close-inset) - var(--sidebar-overhang)) 0 0;
  }

  #colorModal .fill-picker-tab-content,
  #colorModal #etsyPreview {
    grid-column: 2;
    grid-row: 1 / -2;
    margin-top: 8px;
  }

  #colorModal .fill-picker-tab-content.active,
  #colorModal.is-searching #browseContent .fill-picker-tab-content[data-paint-tools],
  #colorModal #etsyPreview {
    min-height: 0;
  }

  #colorModal #etsyPreview {
    overflow-y: auto;
  }
}

/* Tab menu. With the height for them, the tabs stack as the sidebar's menu. A phone on its side
   keeps them in a row: its sidebar needs the height for the rows, and the tab needs it for Make
   your own. */
@media (min-width: 560px) and (min-height: 501px) and (max-height: 700px), (min-width: 769px) and (min-height: 501px) {
  #colorModal .fill-picker-tabs {
    flex-direction: column;
    gap: 2px;
    border-bottom: none;
  }

  #colorModal .fill-picker-tab {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 6px;
    margin: 0;
    padding-inline: 12px;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    text-align: left;
  }

  #colorModal .fill-picker-tab.active {
    background: var(--line-1);
  }
}

#paintToolsSidebar {
  display: none;
}

/* Sidebar paint tools. A laptop's sidebar has the room for the paint tools under the rows, with
   the brands listed open two by two, so the paints have their column to themselves. It needs the
   width for the brands' heading, count and buttons on one line, and the height for all of it under
   both rows. */
@media (min-width: 800px) and (min-height: 650px) {
  #colorModal #paintToolsSidebar {
    display: block;
    grid-column: 1;
    grid-row: -3 / -2;
    order: 3;
    align-self: start;
    margin-top: 16px;
  }

  #paintToolsSidebar .paint-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 0;
  }

  /* Only the Colors tab and a pattern color's paints use the tools; a search has rules of its own. */
  #colorModal:not(.is-searching):not([data-panel="fillPickerTabColors"]):not([data-panel="fillPickerCreator"][data-creator-view="paints"]) #paintToolsSidebar .paint-toolbar {
    display: none;
  }

  #paintToolsSidebar .brand-menu {
    grid-column: 1 / -1;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line-2);
  }

  /* With the brands alone, as for a pattern color, nothing above needs dividing off. */
  #colorModal[data-paints-lent] #paintToolsSidebar .brand-menu {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
  }

  #paintToolsSidebar #brandMenuButton {
    display: none;
  }

  #paintToolsSidebar .brand-menu-list {
    position: static;
    display: block;
    padding: 0;
    border: none;
    background: none;
    box-shadow: none;
    font-size: 0.9em;
  }

  #paintToolsSidebar .brand-menu-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  #paintToolsSidebar .brand-menu-title {
    display: block;
    margin: 0;
    font-size: 1em;
    white-space: nowrap;
  }

  #paintToolsSidebar .brand-menu-actions {
    border-bottom: none;
  }

  #paintToolsSidebar .brand-filter-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 8px;
  }
}

/* Make your own: Generate's form and results, and Upload, on show while the Patterns tab is open.
   In one column it is the tab's foot, under the lists: Upload beside Describe it and Generate, and
   the results over them once there are some. A laptop puts it in the sidebar (below). */
#patternMaking {
  display: none;
}

#colorModal[data-tab="fillPickerTabMaterials"]:not(.is-searching) #patternMaking {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  order: 5;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-2);
}

#patternMaking > * {
  flex: 0 0 100%;
  min-width: 0;
}

#patternMaking > .materials-section-header {
  display: none;
}

#generateBalance:empty {
  display: none;
}

#generateBalance {
  order: 1;
  text-align: right;
}

#patternMaking > #generatedResults {
  order: 2;
}

#patternMaking > #materialUploadButton {
  flex: none;
  order: 3;
  width: 44px;
  min-height: 44px;
  padding: 0;
}

#patternMaking > #materialUploadButton .upload-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The prompt keeps room to read what is typed beside Generate and its cost; what doesn't fit beside
   it wraps below. */
#patternMaking > #materialPromptRow {
  flex: 1 1 0;
  order: 4;
  min-width: 13rem;
}

#patternMaking > .acorn-inline-topup {
  order: 5;
}

.generate-prompt-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

#materialPrompt {
  flex: 1 1 0;
  box-sizing: border-box;
  min-width: 0;
  min-height: 44px;
  padding: 8px;
}

#generateMaterialButton {
  flex: none;
  min-height: 44px;
  margin: 0;
  white-space: nowrap;
}

/* Generated-result option cards (vector + image variants). Click one to load it
   into the preview, then the Use button. One row, however many come back, so the
   block keeps its height from placeholders to results. */
.generated-results {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* They share the row's width at one height, so any number of them keeps the layout still. */
.generated-result-card {
  flex: 1 1 0;
  box-sizing: border-box;
  min-width: 0;
  height: 64px;
  padding: 0;
  border: 2px solid var(--line-3);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

@media (hover: hover) {
  .generated-result-card:hover {
    border-color: var(--ink-1);
  }
}

.generated-result-card.selected {
  border-color: var(--premium);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--premium) 35%, transparent);
}

.generated-result-card img,
.generated-result-card svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

/* Placeholders that hold the results' place while generating. */
.generated-result-card.skeleton {
  cursor: default;
  border-color: var(--line-1);
  background: var(--surface-3);
}

/* Sideways phone. The sidebar has no room left for Make your own, so it is the sheet's foot, across
   both columns, on one line with the balance at its end; the rows give it their height while the
   Patterns tab is open, and the last results wait for Generate's view. Generate and Upload take the
   rows' height for their views, as on a short phone. */
@media (min-width: 560px) and (max-height: 500px) {
  #colorModal[data-panel="fillPickerTabMaterials"]:not(.is-searching) .fill-row,
  #colorModal:not([data-panel="fillPickerCreator"][data-creator-mode="generate"]) #patternMaking > #generatedResults {
    display: none;
  }

  #colorModal[data-tab="fillPickerTabMaterials"]:not(.is-searching) #patternMaking {
    grid-column: 1 / -1;
    grid-row: -2 / -1;
    padding-bottom: 8px;
  }

  #generateBalance {
    flex: none;
    order: 5;
  }

  #colorModal[data-panel="fillPickerCreator"]:is([data-creator-mode="generate"], [data-creator-mode="upload"]):not(.is-searching) :is(.fill-row, .unified-search-container) {
    display: none;
  }
}

/* Phone sheet. Beside the lists and over Upload the last results are a slim strip, so the foot keeps
   Describe it on screen; Generate's view, where they are picked, shows them full size. Cropping an upload needs the
   foot's height for the cropper; Back brings the foot back with the lists. */
@media (max-width: 768px), (max-height: 500px) {
  #colorModal #fillPickerTabMaterials.active {
    min-height: 0;
  }

  #colorModal:not([data-panel="fillPickerCreator"][data-creator-mode="generate"]) #patternMaking .generated-result-card {
    height: 40px;
  }

  #colorModal[data-tab="fillPickerTabMaterials"][data-panel="fillPickerCreator"][data-creator-cropping] #patternMaking {
    display: none;
  }
}

#useFillSlot {
  display: none;
}

/* One column. A pattern's preview reads down to Use: the preview and Size, then Make your own, then
   the results, then Use at the bottom, kept apart from Generate (fillPicker.ts moves it here). */
@media (max-width: 559px), (max-width: 768px) and (min-height: 701px) {
  #colorModal[data-tab="fillPickerTabMaterials"] #fillPickerCreator.active {
    min-height: 0;
  }

  #colorModal[data-tab="fillPickerTabMaterials"][data-panel="fillPickerCreator"] #useFillSlot {
    display: flex;
    order: 6;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  #colorModal[data-panel="fillPickerCreator"][data-creator-mode="generate"] #patternMaking > #generatedResults {
    order: 6;
  }

  #colorModal[data-tab="fillPickerTabMaterials"][data-panel="fillPickerCreator"] #patternMaking {
    padding-bottom: 0;
  }

  /* No result to use yet, or a search over the preview: Use waits with it. The slot itself stays, so
     the button keeps its place for when the preview comes back. */
  #colorModal:is(.is-searching, :not([data-creator-preview])) #useFillSlot > * {
    display: none;
  }

  #colorModal.is-searching #useFillSlot {
    padding: 0;
  }
}

/* Laptop. */
@media (min-width: 769px) and (min-height: 501px) {
  /* macOS hides scrollbars until you scroll, so this one stays on show. It sits in the sheet's
     padding, which keeps the tab's content as wide as the tabs. */
  #colorModal {
    --scrollbar-width: 12px;
  }

  #colorModal .fill-picker-tab-content::-webkit-scrollbar,
  #patternPaintSlot::-webkit-scrollbar {
    width: var(--scrollbar-width);
  }

  #colorModal .fill-picker-tab-content.active,
  #patternPaintSlot {
    margin-right: calc(-1 * var(--scrollbar-width));
  }

  /* The shapes tab fits without scrolling, and only its paints reach the sheet's padding. */
  #colorModal #fillPickerCreator.active {
    margin-right: 0;
    overflow: visible;
    scrollbar-gutter: auto;
  }

  #colorModal .fill-picker-tab-content::-webkit-scrollbar-thumb,
  #patternPaintSlot::-webkit-scrollbar-thumb {
    border: 3px solid var(--surface);
    border-radius: 6px;
    background: var(--line-5);
  }

  /* A mouse has no sideways swipe, so the fill strips keep a scrollbar. It takes their bottom
     padding, and the fixed height stops it moving the tabs when it appears. */
  #colorModal {
    --fill-strip-padding: 6px;
  }

  .context-bar-fills,
  .user-palette-grid {
    align-items: flex-start;
    height: calc(var(--fill-tile-size) + 2 * var(--fill-strip-padding));
    scrollbar-width: auto;
  }

  .context-bar-fills::-webkit-scrollbar,
  .user-palette-grid::-webkit-scrollbar {
    height: 6px;
  }

  .context-bar-fills::-webkit-scrollbar-thumb,
  .user-palette-grid::-webkit-scrollbar-thumb {
    border-radius: 3px;
    background: var(--line-5);
  }

  /* A tall window caps the sheet, so it never stands as a tall empty panel; the paints scroll in it. */
  #colorModal > .modal-content {
    width: min(960px, calc(100vw - 32px));
    height: min(92vh, 900px);
    padding-bottom: 0;
  }

  /* The sidebar's tint reaches the sheet's edges past its padding. */
  #colorModal > .modal-content::before {
    top: calc(-1 * var(--sheet-inline-padding));
  }

  /* In the sidebar: the column's last row, which takes the height the rows above leave (the paint
     tools' row, on the tabs that have them). It fills the row, so it stays on the sidebar's panel
     and scrolls there if short. Its title shares a line with the balance; the rest stack, Upload
     last and full width. */
  #colorModal[data-tab="fillPickerTabMaterials"]:not(.is-searching) #patternMaking {
    grid-column: 1;
    grid-row: -3 / -2;
    align-content: start;
    align-self: stretch;
    min-height: 0;
    box-sizing: border-box;
    /* Room at the sides for the focus rings, which the scrolling would clip; the rule above keeps to
       the column. */
    margin: 16px -4px 0;
    padding: 13px 4px var(--sheet-inline-padding);
    overflow-y: auto;
    border-top: none;
    background: linear-gradient(var(--line-2), var(--line-2)) 4px 0 / calc(100% - 8px) 1px no-repeat;
  }

  #patternMaking > .materials-section-header {
    display: block;
    flex: 1 1 0;
    order: 0;
    padding-top: 0;
    background: none;
  }

  #generateBalance {
    flex: none;
  }

  #patternMaking > #materialPromptRow {
    flex: 0 0 100%;
    order: 2;
  }

  #patternMaking > #generatedResults {
    order: 3;
  }

  #patternMaking > .acorn-inline-topup {
    order: 3;
  }

  #patternMaking > #materialUploadButton {
    flex: 0 0 100%;
    order: 4;
    width: auto;
  }

  #patternMaking > #materialUploadButton .upload-label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
  }
}

/* Short phone. Uploading spends too much height on these rows, and nothing is picked from them on
   the way; the Patterns tab's lists need it beside the tab's foot. */
@media (max-width: 559px) and (max-height: 600px) {
  #colorModal:is([data-panel="fillPickerCreator"][data-creator-mode="upload"], [data-panel="fillPickerTabMaterials"]):not(.is-searching) .fill-row {
    display: none;
  }
}

/* Short phone. Generate needs the height of most phones for its tools and preview all at once. */
@media (max-width: 559px) and (max-height: 750px) {
  #colorModal[data-panel="fillPickerCreator"][data-creator-mode="generate"]:not(.is-searching) :is(.fill-row, .unified-search-container) {
    display: none;
  }
}
