/* Material library (web/js/materials.js): the card's Material button and its picker popover. */

#viewer .sv-selected__actions button[hidden] {
  display: none;
}

.sv-mat__dot {
  width: 16px;
  height: 16px;
  border: 1px solid rgb(23 23 26 / 0.16);
  border-radius: 50%;
  background: conic-gradient(from 200deg, #d9dce0, #8e1218, #c49a62, #85868a, #dcecef, #eceae6, #d9dce0);
}

.has-material > .sv-mat__dot {
  background: var(--c);
}

/* The chosen preset's name can be long: up to two lines, like the other action labels. */
.sv-mat__label {
  display: -webkit-box;
  max-width: 100%;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* The picker: a popover in the top layer, placed by materials.js under the Material button, its
   height fitted above the toolbar. While more is below, a soft shade at the bottom edge: the
   `local` cover scrolls with the content and hides the fixed shade once the end is in view. */
.sv-materials {
  position: fixed;
  inset: auto;
  width: min(312px, calc(100vw - 16px));
  max-height: min(70vh, 520px);
  margin: 0;
  padding: 8px 10px 10px;
  overflow-y: auto;
  border: 1px solid var(--sv-border);
  border-radius: 12px;
  background:
    linear-gradient(rgb(255 255 255 / 0), var(--sv-surface) 50%) center bottom / 100% 32px no-repeat local,
    linear-gradient(rgb(23 23 26 / 0), rgb(23 23 26 / 0.1)) center bottom / 100% 16px no-repeat scroll,
    var(--sv-surface);
  box-shadow: var(--sv-shadow);
}

.sv-materials__section {
  margin: 10px 2px 4px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--sv-muted, rgb(23 23 26 / 0.6));
}

.sv-materials__row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

/* The sheet's head (materials.js): phones only, it stays at the top while the presets scroll. */
.sv-materials__head {
  display: none;
}

.sv-materials__title {
  margin: 0 2px;
  font-size: 14px;
  font-weight: 650;
}

/* A tile: swatch over its name; at least 44 px a side. */
#viewer .sv-mat,
#viewer .sv-mat:hover:not(:disabled) {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 44px;
  min-height: 56px;
  padding: 5px 2px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
}

#viewer .sv-mat:hover:not(:disabled) {
  background: var(--sv-accent-soft);
}

#viewer .sv-mat[aria-pressed="true"] {
  border-color: var(--sv-accent);
  color: var(--sv-accent);
  font-weight: 650;
}

.sv-mat__swatch {
  flex: none;
  width: 30px;
  height: 30px;
  border: 1px solid rgb(23 23 26 / 0.16);
  border-radius: 50%;
  background: var(--c);
}

/* Hints of the look: metals and paint shine, glass shows what's behind, textures have grain. */
.sv-mat[data-section="Metal"] .sv-mat__swatch,
.sv-mat[data-section="Paint"] .sv-mat__swatch {
  background: radial-gradient(circle at 35% 30%, rgb(255 255 255 / 0.75), transparent 45%), linear-gradient(160deg, var(--c), rgb(0 0 0 / 0.35)), var(--c);
}

.sv-mat[data-section="Glass"] .sv-mat__swatch {
  background: linear-gradient(135deg, rgb(255 255 255 / 0.8), transparent 60%), repeating-conic-gradient(rgb(23 23 26 / 0.12) 0 25%, transparent 0 50%) 0 0 / 10px 10px, var(--c);
}

.sv-mat.is-textured .sv-mat__swatch {
  background: repeating-linear-gradient(100deg, rgb(0 0 0 / 0.08) 0 2px, transparent 2px 5px), var(--c);
}

/* Original: the file's own materials. */
.sv-mat[data-material=""] .sv-mat__swatch {
  background: linear-gradient(135deg, transparent 46%, var(--sv-danger) 46% 54%, transparent 54%), var(--sv-surface);
}

.sv-mat__name {
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Phones (materials.js leaves it unplaced): a sheet over the bottom of the screen, the card and
   toolbar under it, at most 40% of the screen, so the part being changed stays in view above. */
@media (max-width: 760px), (max-width: 1023px) and (max-height: 520px) and (min-aspect-ratio: 301/200) {
  .sv-materials {
    inset: auto 0 0;
    width: auto;
    max-height: 40dvh;
    padding: 8px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    border-width: 1px 0 0;
    border-radius: 12px 12px 0 0;
  }

  .sv-materials__head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: -8px;
    padding: 0;
    background: var(--sv-surface);
  }
}

/* Short landscape screens: over the card's side sheet (panel.css), the model beside it. */
@media (max-width: 1023px) and (max-height: 520px) and (min-aspect-ratio: 301/200) {
  /* height: the popover's UA `fit-content` would beat the bottom inset; it scrolls instead */
  .sv-materials {
    inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) var(--sv-above-dock) auto;
    width: 45%;
    height: auto;
    max-height: none;
    padding: 8px 10px 10px;
    border-width: 1px;
    border-radius: 12px;
  }
}
