/*
 * upkreator — builder page. The scene is a bead board: flocked felt, a groove with the string and a ruler
 * counted from the centre, the way jewellers lay a necklace out before stringing it. Everything around it is quiet.
 * Colours from the shop (Mercury + custom.css); body font inherited (Roboto). Mobile first, desktop >= 992 px.
 */

.upk {
  --upk-ink: #4d403a;
  --upk-ink-2: #7a6c64;
  --upk-line: #e7dfd9;
  --upk-felt-1: #f2ece7;
  --upk-felt-2: #e3d9d1;
  --upk-groove: #d6cabf;
  --upk-thread: #a08f83;
  --upk-accent: #b26a4e;
  --upk-soft: #f7f3f0;
  color: var(--upk-ink);
  margin: 0 0 32px;
}

.upk *,
.upk *::before,
.upk *::after {
  box-sizing: border-box;
}

.upk button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.upk button:focus-visible,
.upk a:focus-visible {
  outline: 2px solid var(--upk-accent);
  outline-offset: 2px;
}

/* ---------- intro ---------- */

.upk-intro {
  margin: 4px 0 18px;
}

.upk-title {
  margin: 0 0 6px;
  font-size: clamp(26px, 3.4vw, 34px);
  font-weight: 300;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--upk-ink);
}

.upk-lead {
  max-width: 34em;
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--upk-ink-2);
}

/* ---------- layout ---------- */

.upk-grid {
  display: grid;
  gap: 18px;
}

@media (min-width: 992px) {
  .upk-grid {
    grid-template-columns: minmax(0, 7fr) minmax(320px, 5fr);
    gap: 36px;
    align-items: start;
  }

  .upk-stage {
    position: sticky;
    top: 16px;
  }
}

/* ---------- type and length ---------- */

.upk-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  margin-bottom: 12px;
}

.upk-seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--upk-soft);
  box-shadow: inset 0 0 0 1px var(--upk-line);
}

.upk-seg[hidden] {
  display: none;
}

.upk-seg__opt {
  min-height: 38px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
  cursor: pointer;
}

.upk-seg__opt[aria-pressed="true"] {
  background: var(--upk-ink);
  color: #fff;
}

.upk-lengths {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.upk-chip {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--upk-line);
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.upk-chip[aria-pressed="true"] {
  border-color: var(--upk-ink);
  box-shadow: inset 0 0 0 0.5px var(--upk-ink);
  font-weight: 500;
}

/* ---------- the bead board ---------- */

.upk-board {
  position: relative;
  border-radius: 20px;
  background: radial-gradient(120% 95% at 50% 30%, var(--upk-felt-1) 0%, var(--upk-felt-2) 100%);
  box-shadow: inset 0 1px 3px rgba(77, 64, 58, 0.1), inset 0 0 0 1px rgba(77, 64, 58, 0.06);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* flock of the felt */
.upk-board::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.45;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .48 0 0 0 0 .43 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

.upk-scene {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.upk-ruler path {
  fill: none;
  stroke: #b3a497;
  stroke-width: 0.8;
  stroke-linecap: round;
}

.upk-ruler text {
  fill: #9a8b80;
  font-size: 8.5px;
  font-variant-numeric: tabular-nums;
  text-anchor: middle;
  dominant-baseline: central;
}

.upk-groove {
  fill: none;
  stroke: var(--upk-groove);
  stroke-linecap: round;
  opacity: 0.55;
}

.upk-thread {
  fill: none;
  stroke: var(--upk-thread);
  stroke-width: 0.9;
}

.upk-noimg {
  fill: #fbf8f5;
  stroke: #b3a497;
  stroke-width: 0.6;
}

.upk-acc {
  cursor: grab;
  touch-action: none;
  outline: none;
  transform-box: fill-box;
  transform-origin: center;
}

.upk.is-dragging,
.upk.is-dragging .upk-acc {
  cursor: grabbing;
}

.upk-acc-hit {
  fill: transparent;
  stroke: transparent;
  stroke-width: 1.2;
}

.upk-acc:hover .upk-acc-hit,
.upk-acc:focus-visible .upk-acc-hit,
.upk-acc.is-active .upk-acc-hit {
  fill: rgba(178, 106, 78, 0.08);
  stroke: var(--upk-accent);
}

.upk-acc.is-active .upk-acc-hit {
  stroke-dasharray: 2.5 2;
}

.upk-acc.is-lifted {
  opacity: 0.25;
}

.upk-acc.is-new {
  animation: upk-place 0.22s ease-out;
}

@keyframes upk-place {
  from { transform: scale(1.6); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

.upk-target {
  fill: rgba(178, 106, 78, 0.1);
  stroke: var(--upk-accent);
  stroke-width: 1.2;
  stroke-dasharray: 3 2;
  pointer-events: none;
}

.upk-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 24px;
  text-align: center;
  font-size: 15px;
  color: var(--upk-ink-2);
}

.upk-status[hidden] {
  display: none;
}

.upk-menu {
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 6px 24px rgba(77, 64, 58, 0.18);
}

.upk-menu[hidden] {
  display: none;
}

.upk-menu__name {
  max-width: 220px;
  padding: 0 4px;
  font-size: 12px;
  color: var(--upk-ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upk-menu__row {
  display: flex;
  gap: 6px;
}

.upk-menu button {
  min-width: 44px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--upk-line);
  border-radius: 8px;
  background: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.upk-menu .upk-menu__remove {
  font-size: 14px;
  color: var(--upk-accent);
}

.upk-flash {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 2;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--upk-ink);
  color: #fff;
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  transform: translateX(-50%);
}

.upk-flash[hidden] {
  display: none;
}

.upk-note,
.upk-hint {
  margin: 8px 2px 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--upk-ink-2);
}

.upk-hint:empty {
  display: none;
}

.upk-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2000;
  width: 36px;
  height: 36px;
  pointer-events: none;
  filter: drop-shadow(0 3px 5px rgba(77, 64, 58, 0.35));
}

.upk-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---------- shelf ---------- */

.upk-tabs {
  display: flex;
  gap: 18px;
  border-bottom: 1px solid var(--upk-line);
  overflow-x: auto;
  scrollbar-width: none;
}

.upk-tabs::-webkit-scrollbar {
  display: none;
}

.upk-tabs [role="tab"] {
  flex: none;
  min-height: 42px;
  margin-bottom: -1px;
  padding: 0 1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  font-size: 14px;
  color: var(--upk-ink-2);
  cursor: pointer;
}

.upk-tabs [role="tab"][aria-selected="true"] {
  border-bottom-color: var(--upk-accent);
  color: var(--upk-ink);
  font-weight: 500;
}

.upk-tabs [role="tab"][hidden] {
  display: none;
}

.upk-help {
  min-height: 1.45em;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--upk-ink-2);
}

.upk-cards {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 112px;
  gap: 8px;
  margin: 0 -15px;
  padding: 2px 15px 6px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}

@media (min-width: 768px) {
  .upk-cards {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    margin: 0;
    padding: 2px 0 6px;
    overflow: visible;
  }
}

.upk-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 100%;
  padding: 10px 8px 9px;
  border: 1px solid var(--upk-line);
  border-radius: 14px;
  background: #fff;
  text-align: center;
  cursor: pointer;
  scroll-snap-align: start;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.upk-card:hover:not(:disabled) {
  border-color: #cfc3ba;
}

.upk-card.is-selected {
  border-color: var(--upk-ink);
  box-shadow: inset 0 0 0 0.5px var(--upk-ink);
}

.upk-card__img {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  margin-bottom: 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, var(--upk-felt-1), var(--upk-felt-2));
}

.upk-card__img img {
  max-width: 44px;
  max-height: 44px;
  object-fit: contain;
  pointer-events: none;
}

.upk-card--none .upk-card__img {
  background: none;
  border: 1px dashed #cfc3ba;
}

.upk-card__name {
  font-size: 13px;
  line-height: 1.3;
}

.upk-card__meta {
  font-size: 11.5px;
  color: var(--upk-ink-2);
  font-variant-numeric: tabular-nums;
}

.upk-card__count {
  position: absolute;
  top: 6px;
  right: 7px;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--upk-ink);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
}

.upk-card.is-out {
  cursor: default;
}

.upk-card.is-out .upk-card__img img {
  filter: grayscale(1);
  opacity: 0.5;
}

.upk-card.is-out .upk-card__name,
.upk-card.is-out .upk-card__meta {
  opacity: 0.55;
}

.upk-card__out {
  font-size: 11.5px;
  color: var(--upk-accent);
}

/* ---------- summary and buying ---------- */

.upk-summary {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--upk-line);
}

.upk-summary__title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 500;
  text-transform: none;
  color: var(--upk-ink);
}

.upk-lines {
  margin: 0;
  padding: 0;
  list-style: none;
}

.upk-lines li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 14px;
}

.upk-lines__img {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--upk-soft);
}

.upk-lines__img img {
  max-width: 20px;
  max-height: 20px;
}

.upk-fee {
  display: flex;
  justify-content: space-between;
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px dashed var(--upk-line);
  font-size: 14px;
  color: var(--upk-ink-2);
}

.upk-msg {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fbf1ec;
  font-size: 13.5px;
  line-height: 1.45;
  color: #8a4a33;
}

.upk-msg[hidden] {
  display: none;
}

.upk-buy {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px -15px 0;
  padding: 10px 15px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--upk-line);
  background: rgba(255, 255, 255, 0.97);
}

@media (min-width: 992px) {
  .upk-buy {
    position: static;
    margin: 16px 0 0;
    padding: 14px 0 0;
    background: none;
  }
}

.upk-total {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 0 8px;
  margin: 0;
}

.upk-total__label {
  font-size: 13px;
  color: var(--upk-ink-2);
}

.upk-total strong {
  font-size: 19px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: opacity 0.15s;
}

.upk.is-pending .upk-total strong {
  opacity: 0.45;
}

.upk-total small {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--upk-ink-2);
}

.upk-add {
  flex: none;
  min-width: 150px;
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 8px;
  background: var(--upk-ink);
  color: #fff !important;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
}

/* no colour transition: a quote toggles :disabled on every change, the state must read at once */
.upk-add:hover:not(:disabled) {
  background: #6a5a51;
}

/* cannot be added (error, nothing priced yet): clearly inactive, text still readable (#6a5a51 on #ebe5e1 = 5.3:1) */
.upk-add:disabled {
  background: #ebe5e1;
  color: #6a5a51 !important;
  cursor: not-allowed;
}

/* only waiting for the price or for the cart: keeps the primary look, just quieter */
.upk.is-pending .upk-add:disabled,
.upk.is-adding .upk-add:disabled {
  background: var(--upk-ink);
  color: #fff !important;
  opacity: 0.6;
  cursor: progress;
}

/* editing is frozen while the design goes to the cart */
.upk.is-adding .upk-stage,
.upk.is-adding .upk-cards {
  opacity: 0.6;
  pointer-events: none;
}

.upk-added {
  margin: 10px 0 0;
  font-size: 14px;
}

.upk-added a {
  color: var(--upk-accent);
  text-decoration: underline;
}

.upk-added[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .upk-acc.is-new {
    animation: none;
  }

  .upk-card,
  .upk-total strong {
    transition: none;
  }
}
