/*
 * Asset Maker: the preview fills the stage above a strip of the things that
 * can be made, each drawn live in the current colors; the picked one's
 * settings, the palette, the background and the size are the side panel.
 */

/* ---------- Bar ---------- */

.am-aspects .qp-btn { gap: 6px; padding: 0 9px; font-variant-numeric: tabular-nums; }

/* A small outline of each shape, so portrait and landscape read at a glance. */
.am-aspects i {
  display: block;
  flex: none;
  width: var(--w);
  height: var(--h);
  border: 1.5px solid currentColor;
  border-radius: 2px;
  opacity: .7;
}

.qp-btn.am-roll {
  border-color: color-mix(in srgb, var(--ab-accent) 36%, var(--border));
  color: color-mix(in srgb, var(--ab-accent) 80%, var(--text));
  background: color-mix(in srgb, var(--ab-accent) 8%, var(--surface));
}

@media (hover: hover) {
  .qp-btn.am-roll:hover:not(:disabled) { border-color: var(--ab-accent); }
}

.am-roll.is-rolling svg { animation: am-roll .55s cubic-bezier(.25, .8, .3, 1); }

@keyframes am-roll {
  from { transform: rotate(-220deg) scale(.7); }
  to { transform: none; }
}

/* ---------- Stage ---------- */

.am-stage {
  --ratio: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  container-type: inline-size;
}

/* The preview is the largest box of the canvas's shape that fits. */
.am-view {
  display: grid;
  flex: 1 1 auto;
  min-height: 200px;
  place-items: center;
  container-type: size;
}

.am-canvas {
  --check-a: #fffdf8;
  --check-b: #ece7de;
  width: min(100cqw, 100cqh * var(--ratio));
  aspect-ratio: var(--ratio);
  overflow: hidden;
  border-radius: 3px;
  background: repeating-conic-gradient(var(--check-b) 0 25%, var(--check-a) 0 50%) 0 0 / 18px 18px;
  box-shadow: 0 0 0 1px rgba(25, 25, 24, .08), 0 24px 54px -22px rgba(48, 42, 31, .38);
}

.am-canvas svg { display: block; width: 100%; height: 100%; }

.am-stage[data-backdrop="dark"] .am-canvas {
  --check-a: #262523;
  --check-b: #1c1b1a;
  box-shadow: 0 0 0 1px rgba(25, 25, 24, .3), 0 24px 54px -22px rgba(25, 25, 24, .55);
}

.am-meta {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font: 500 .68rem/1 "DM Mono", ui-monospace, monospace;
  letter-spacing: .02em;
}

.am-backdrops { display: flex; gap: 6px; }

.am-backdrop {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: repeating-conic-gradient(#ece7de 0 25%, #fffdf8 0 50%) 0 0 / 8px 8px;
  cursor: pointer;
}

.am-backdrop.is-dark { background: repeating-conic-gradient(#1c1b1a 0 25%, #302f2c 0 50%) 0 0 / 8px 8px; }
.am-backdrop[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px color-mix(in srgb, var(--text) 30%, transparent); }

/* ---------- What to make ---------- */

.am-types {
  display: grid;
  flex: none;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
}

.am-type {
  display: grid;
  min-width: 0;
  gap: 5px;
  padding: 4px 4px 7px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  background: var(--surface);
  cursor: pointer;
  font: 650 .7rem/1.1 "Inter", system-ui, sans-serif;
  text-align: center;
}

.am-type img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  border-radius: 8px;
  background: var(--surface-subtle);
  box-shadow: inset 0 0 0 1px rgba(25, 25, 24, .05);
}

.am-type span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.am-type[aria-checked="true"] {
  border-color: color-mix(in srgb, var(--ab-accent) 62%, var(--border));
  color: var(--text);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ab-accent) 15%, transparent);
}

@media (hover: hover) {
  .am-type:hover { border-color: var(--border-hover); transform: translateY(-1px); }
  .am-type[aria-checked="true"]:hover { border-color: var(--ab-accent); }
}

/* A narrow stage keeps the kinds in one row that scrolls sideways, rather
   than folding them into rows that push the preview up. */
@container (max-width: 760px) {
  .am-types {
    grid-auto-columns: 100px;
    grid-auto-flow: column;
    grid-template-columns: none;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }

  .am-type { scroll-snap-align: start; }
}

/* ---------- Settings ---------- */

.am-field + .am-field { margin-top: 16px; }

.am-seg { grid-template-columns: repeat(var(--n, 3), minmax(0, 1fr)); }
.am-seg button { font-size: .67rem; }

.am-check { font-size: .74rem; font-weight: 600; }

.am-links { display: inline-flex; gap: 12px; }

.am-swatches { display: flex; flex-wrap: wrap; gap: 10px 8px; }

.am-swatch { position: relative; width: 46px; }

.am-swatch-face,
.am-chip {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(25, 25, 24, .14);
  cursor: pointer;
}

.am-swatch-face { width: 46px; height: 46px; }

.am-swatch-face input,
.am-chip input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.am-hex {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font: 500 .58rem "DM Mono", ui-monospace, monospace;
  letter-spacing: .02em;
  text-align: center;
}

.am-swatch-x {
  position: absolute;
  top: -7px;
  right: -7px;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(25, 25, 24, .12);
  cursor: pointer;
  font-size: .82rem;
  line-height: 1;
  opacity: 0;
}

.am-swatch:hover .am-swatch-x,
.am-swatch:focus-within .am-swatch-x { opacity: 1; }

/* No hover on a finger: the remove button is simply there. */
@media (hover: none) {
  .am-swatch-x { opacity: 1; }
}

.am-add {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  padding: 0;
  border: 1.5px dashed var(--line2);
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.am-add svg { width: 18px; height: 18px; }

@media (hover: hover) {
  .am-add:hover { border-color: var(--ab-accent); color: var(--ab-accent); }
}

.am-presets {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
}

.am-preset {
  position: relative;
  display: flex;
  height: 24px;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.am-preset span { flex: 1; }

/* The hairline is drawn over the colour strips, not under them. */
.am-preset::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(25, 25, 24, .12);
  content: "";
}

.am-preset[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 2px; }

@media (hover: hover) {
  .am-preset:hover { transform: translateY(-1px); }
}

.am-bg {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 43px;
  gap: 8px;
  align-items: center;
}

.am-chip { width: 43px; height: 43px; border-radius: 11px; }
.am-chip.is-off { opacity: .4; }

#bgNote { margin-top: 10px; }

.am-size {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.am-size label { position: relative; display: block; }

.am-size label span {
  position: absolute;
  top: 50%;
  left: 12px;
  color: var(--muted);
  font: 600 .64rem "DM Mono", ui-monospace, monospace;
  pointer-events: none;
  transform: translateY(-50%);
}

.am-size input { padding-left: 30px; font-variant-numeric: tabular-nums; }
.am-x { color: var(--muted); font-size: .8rem; }

/* ---------- Export ---------- */

.am-export { width: min(310px, calc(100vw - 24px)); }
.am-export h3:first-child { margin-top: 0; }

.am-export-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.am-export-grid .btn {
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-height: 50px;
  padding: 8px 12px;
  text-align: left;
}

.am-export-grid .btn strong { font-size: .78rem; }
.am-export-grid .btn span { color: var(--muted); font: 500 .6rem "DM Mono", ui-monospace, monospace; }

.am-scale { margin-top: 12px; }
.am-scale .control-label { margin-bottom: 7px; }

.am-export .control-help { margin-top: 12px; }

.am-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 70;
  padding: 10px 15px;
  border-radius: 11px;
  color: #fffdf8;
  background: #191918;
  box-shadow: 0 12px 30px rgba(25, 25, 24, .25);
  font: 600 .76rem "Inter", system-ui, sans-serif;
  transform: translateX(-50%);
}

/* ---------- Phones and narrow windows ---------- */

@media (max-width: 840px) {
  /* The stage scrolls with the page here, so the preview gets a height of
     its own: as wide as the screen, but never taller than most of it. */
  .am-view {
    height: min(58vh, calc((100vw - 2 * var(--qp-pad)) / var(--ratio)));
    height: min(58svh, calc((100vw - 2 * var(--qp-pad)) / var(--ratio)));
    min-height: 0;
  }

  .am-stage .am-types {
    margin: 0 calc(-1 * var(--qp-pad));
    padding: 2px var(--qp-pad) 6px;
    scroll-padding: 0 var(--qp-pad);
    scrollbar-width: none;
  }

  .am-stage .am-types::-webkit-scrollbar { display: none; }
}

@media (max-width: 640px) {
  .am-aspects .qp-btn { padding: 0 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .am-roll.is-rolling svg { animation: none; }
}
