/**
 * @file
 * Yarn Palette Contrast Simulator.
 *
 * - Logical properties only (inline/block), so RTL (Hebrew) mirrors for free.
 * - Container queries: the block adapts to the region it is placed in, not to
 *   the viewport.
 * - Theme it by overriding the --ycs-* custom properties on .ycs.
 */

.ycs {
  /* Matched to the yarn.co.il theme: Noto Sans, neutral greys and the
     store's blue (#2ba9e0). The filled buttons use a deeper shade of that
     blue so white text keeps WCAG AA contrast. */
  --ycs-ink: #333;
  --ycs-muted: #666;
  --ycs-surface: #fff;
  --ycs-panel: #f8f9fa;
  --ycs-border: #eee;
  --ycs-border-strong: #d9d9d9;
  --ycs-focus: #146a95;
  --ycs-radius: 12px;
  --ycs-radius-sm: 8px;

  --ycs-brand: #2ba9e0;
  --ycs-accent: #1778a6;
  --ycs-accent-hover: #135f85;
  --ycs-accent-ink: #fff;

  --ycs-high-bg: #187a47;
  --ycs-high-ink: #fff;
  --ycs-mid-bg: #f0b429;
  --ycs-mid-ink: #3b2a00;
  --ycs-low-bg: #b3261e;
  --ycs-low-ink: #fff;

  font-family: 'Noto Sans', Arial, sans-serif;
  position: relative;
  box-sizing: border-box;
  container-type: inline-size;
  container-name: ycs;
  inline-size: 100%;
  color: var(--ycs-ink);
  font-size: 1rem;
  line-height: 1.45;
}

.ycs *,
.ycs *::before,
.ycs *::after {
  box-sizing: border-box;
}

.ycs button,
.ycs input {
  font: inherit;
  color: inherit;
}

.ycs :focus-visible {
  outline: 3px solid var(--ycs-focus);
  outline-offset: 2px;
}

/* Header ------------------------------------------------------------------ */

.ycs__header {
  margin-block-end: 1.25rem;
}

.ycs__title {
  margin: 0;
  font-size: clamp(1.6rem, 1.1rem + 2.4cqi, 2.4rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.ycs__intro {
  margin: 0.35rem 0 0;
  color: var(--ycs-ink);
  font-size: 1.05rem;
}

.ycs__noscript {
  padding: 0.75rem 1rem;
  border-radius: var(--ycs-radius-sm);
  background: var(--ycs-panel);
}

.ycs__section {
  margin-block-start: 1.75rem;
}

.ycs__section-title {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
  font-weight: 700;
}

/* "What is this tool for?" explainer ------------------------------------------ */

.ycs-about {
  margin-block-end: 1.25rem;
  border: 1px solid var(--ycs-border-strong);
  border-radius: var(--ycs-radius);
  background: var(--ycs-panel);
}

.ycs-about__summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--ycs-radius);
  list-style: none;
  cursor: pointer;
}

.ycs-about__summary::-webkit-details-marker {
  display: none;
}

.ycs-about__q {
  font-weight: 700;
}

.ycs-about__hint {
  color: var(--ycs-muted);
  font-size: 0.85rem;
}

/* Chevron, pushed to the far end of the row; flips when open. */
.ycs-about__summary::after {
  content: "";
  flex: none;
  margin-inline-start: auto;
  inline-size: 0.55rem;
  block-size: 0.55rem;
  border-inline-end: 2px solid currentcolor;
  border-block-end: 2px solid currentcolor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.2s ease;
}

.ycs-about[open] > .ycs-about__summary::after {
  transform: translateY(2px) rotate(-135deg);
}

.ycs-about__body {
  padding: 0 1rem 1rem;
  font-size: 0.92rem;
}

.ycs-about__body p {
  margin: 0 0 0.6rem;
}

.ycs-about__body ul {
  margin: 0 0 0.6rem;
  padding-inline-start: 1.2rem;
}

.ycs-about__body li {
  margin-block-end: 0.3rem;
}

.ycs-about__body > :last-child {
  margin-block-end: 0;
}

.ycs-about__title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.ycs-about__body h4 {
  margin: 1rem 0 0.4rem;
  font-size: 1rem;
  font-weight: 700;
}

.ycs-about__cols {
  display: grid;
  gap: 0.75rem;
  margin-block-end: 0.6rem;
}

@container ycs (min-width: 640px) {
  .ycs-about__cols {
    grid-template-columns: 1fr 1fr;
  }
}

.ycs-about__card {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--ycs-border);
  border-radius: var(--ycs-radius-sm);
  background: var(--ycs-surface);
}

.ycs-about__card h5 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.ycs-about__card p {
  margin-block-end: 0.4rem;
}

.ycs-about__card ul {
  margin-block-end: 0;
}

/* Workspace: slots + toggle panel ---------------------------------------- */

.ycs__workspace {
  display: grid;
  gap: 1rem;
  align-items: start;
}

@container ycs (min-width: 780px) {
  .ycs__workspace {
    grid-template-columns: minmax(0, 1fr) 17rem;
  }
}

.ycs__slots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 12.5rem), 1fr));
  gap: 0.9rem;
}

/* Yarn slot card ----------------------------------------------------------- */

.ycs-slot {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "media actions"
    "name  name"
    "tag   tag"
    "search search";
  gap: 0.5rem 0.6rem;
  padding: 0.75rem;
  background: var(--ycs-surface);
  border: 1px solid var(--ycs-border);
  border-radius: var(--ycs-radius);
  box-shadow: 0 1px 2px rgb(0 0 0 / 6%);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.ycs-slot:focus-within {
  z-index: 30; /* Lets the suggestion list overlap the cards below. */
  border-color: var(--ycs-brand);
  box-shadow: 0 4px 14px rgb(0 0 0 / 10%);
}

.ycs-slot__media {
  grid-area: media;
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border-radius: var(--ycs-radius-sm);
  background: var(--ycs-panel);
  color: var(--ycs-muted);
}

.ycs-slot__media img {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
}

.ycs-slot--empty .ycs-slot__media {
  border: 2px dashed var(--ycs-border-strong);
  background: transparent;
  cursor: pointer;
}

.ycs-slot__actions {
  grid-area: actions;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ycs-slot__name {
  grid-area: name;
  margin: 0;
  min-block-size: 1.45em;
  font-size: 0.95rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.ycs-slot--empty .ycs-slot__name {
  color: var(--ycs-muted);
  font-weight: 500;
}

.ycs-slot__tag {
  grid-area: tag;
  justify-self: start;
  margin: 0;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  background: var(--ycs-low-bg);
  color: var(--ycs-low-ink);
  font-size: 0.78rem;
  font-weight: 600;
}

.ycs-slot__tag[hidden] {
  display: none;
}

.ycs-slot__search {
  grid-area: search;
  position: relative;
}

.ycs-slot__input {
  inline-size: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--ycs-border-strong);
  border-radius: var(--ycs-radius-sm);
  background: var(--ycs-surface);
  font-size: 0.92rem;
}

.ycs-slot__input::placeholder {
  color: var(--ycs-muted);
  opacity: 1;
}

.ycs-iconbtn {
  display: inline-grid;
  place-items: center;
  inline-size: 2.4rem;
  block-size: 2.4rem;
  padding: 0;
  border: 1px solid var(--ycs-border);
  border-radius: var(--ycs-radius-sm);
  background: var(--ycs-surface);
  color: var(--ycs-ink);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.ycs-iconbtn:hover:not(:disabled) {
  background: var(--ycs-panel);
  border-color: var(--ycs-border-strong);
}

.ycs-iconbtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ycs-icon {
  display: inline-block;
  flex: none;
  inline-size: 1.25rem;
  block-size: 1.25rem;
}

/* The "add another yarn" bar, slim and spanning the whole slot grid. */
.ycs-slot-add {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 0.75rem;
  border: 2px dashed var(--ycs-border-strong);
  border-radius: var(--ycs-radius);
  background: transparent;
  color: var(--ycs-muted);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.ycs-slot-add:hover {
  background: var(--ycs-panel);
  color: var(--ycs-ink);
}

.ycs-slot-add[hidden] {
  display: none;
}

/* Suggestions dropdown ----------------------------------------------------- */

.ycs-suggest {
  position: absolute;
  inset-inline: 0;
  inset-block-start: calc(100% + 4px);
  z-index: 40;
  min-inline-size: min(18rem, 85vw); /* Wider than a narrow slot card. */
  max-block-size: 18rem;
  margin: 0;
  padding: 0.25rem;
  overflow-y: auto;
  list-style: none;
  background: var(--ycs-surface);
  border: 1px solid var(--ycs-border-strong);
  border-radius: var(--ycs-radius-sm);
  box-shadow: 0 10px 28px rgb(0 0 0 / 16%);
}

.ycs-suggest[hidden] {
  display: none;
}

.ycs-suggest__item {
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr);
  gap: 0.6rem;
  align-items: center;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
}

.ycs-suggest__item[aria-selected="true"],
.ycs-suggest__item:hover {
  background: var(--ycs-panel);
}

.ycs-suggest__thumb {
  inline-size: 2.75rem;
  block-size: 2.75rem;
  border-radius: 8px;
  background: var(--ycs-panel);
  object-fit: cover;
}

.ycs-suggest__label {
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.ycs-suggest__sub {
  display: block;
  color: var(--ycs-muted);
  font-size: 0.78rem;
  font-weight: 400;
}

.ycs-suggest__empty {
  padding: 0.6rem 0.75rem;
  color: var(--ycs-muted);
  font-size: 0.9rem;
}

/* Toggle mode panel ---------------------------------------------------------- */

.ycs__mode {
  margin: 0;
  min-inline-size: 0;
  padding: 1rem;
  border: 1px solid var(--ycs-border);
  border-radius: var(--ycs-radius);
  background: var(--ycs-panel);
}

.ycs__mode-title {
  /* Floating takes the legend out of the fieldset border it sits on. */
  float: inline-start;
  inline-size: 100%;
  padding: 0;
  margin-block-end: 0.75rem;
  font-size: 1.15rem;
  font-weight: 700;
}

.ycs__mode-title + * {
  clear: both;
}

.ycs__mode-hint {
  margin: 0.75rem 0 0;
  color: var(--ycs-muted);
  font-size: 0.85rem;
}

.ycs-segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: #eef0f2;
}

.ycs-segmented__option {
  position: relative;
  display: block;
  cursor: pointer;
}

.ycs-segmented__option input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.ycs-segmented__option span {
  display: block;
  padding: 0.6rem 0.5rem;
  border-radius: 9px;
  color: var(--ycs-muted);
  font-size: 0.92rem;
  font-weight: 600;
  text-align: center;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.ycs-segmented__option input:checked + span {
  background: var(--ycs-accent);
  color: var(--ycs-accent-ink);
}

.ycs-segmented__option input:focus-visible + span {
  outline: 3px solid var(--ycs-focus);
  outline-offset: 2px;
}

/* Swatch preview ------------------------------------------------------------- */

.ycs-preview {
  display: flex;
  min-block-size: clamp(11rem, 36cqi, 20rem);
  overflow: hidden;
  border-radius: 18px;
  background: var(--ycs-panel);
}

.ycs-preview__empty {
  align-self: center;
  margin: 0 auto;
  padding: 1rem;
  color: var(--ycs-muted);
  text-align: center;
}

.ycs-stripe {
  position: relative;
  flex: 1 1 0;
  min-inline-size: 0;
  overflow: hidden;
}

.ycs-stripe__img,
.ycs-stripe__gray {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
}

.ycs-stripe__img {
  object-fit: cover;
  transition: filter 0.35s ease;
}

/* Precise canvas-rendered grayscale, cross-faded over the color image. */
.ycs-stripe__gray {
  background-position: center;
  background-size: cover;
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.ycs[data-ycs-mode="grayscale"] .ycs-stripe__gray {
  opacity: 1;
}

/* Fallback when the canvas could not read the image: plain CSS filter. */
.ycs[data-ycs-mode="grayscale"] .ycs-stripe:not(.ycs-stripe--has-gray) .ycs-stripe__img {
  filter: grayscale(100%);
}

.ycs-stripe__cap {
  position: absolute;
  inset-inline: 0.6rem;
  inset-block-end: 0.6rem;
  overflow: hidden;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgb(0 0 0 / 62%);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
  inline-size: fit-content;
  max-inline-size: calc(100% - 1.2rem);
  backdrop-filter: blur(4px);
}

/* Analysis cards ------------------------------------------------------------- */

.ycs-analysis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 16rem), 1fr));
  gap: 0.9rem;
}

.ycs-analysis__note {
  grid-column: 1 / -1;
  margin: 0;
  padding: 1rem;
  border: 1px dashed var(--ycs-border-strong);
  border-radius: var(--ycs-radius);
  color: var(--ycs-muted);
}

.ycs-pair {
  display: grid;
  gap: 0.55rem;
  align-content: start;
  padding: 0.9rem 1rem 1rem;
  background: var(--ycs-surface);
  border: 1px solid var(--ycs-border);
  border-radius: var(--ycs-radius);
}

.ycs-pair__head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.ycs-pair__title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.ycs-chips {
  display: inline-flex;
  flex: none;
}

.ycs-chip {
  inline-size: 1.25rem;
  block-size: 1.25rem;
  border: 2px solid var(--ycs-surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--ycs-border-strong);
  transition: background-color 0.3s ease;
}

.ycs-chip + .ycs-chip {
  margin-inline-start: -0.4rem;
}

.ycs-badge {
  justify-self: start;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.3;
}

.ycs-pair--high .ycs-badge {
  background: var(--ycs-high-bg);
  color: var(--ycs-high-ink);
}

.ycs-pair--medium .ycs-badge {
  background: var(--ycs-mid-bg);
  color: var(--ycs-mid-ink);
}

.ycs-pair--low .ycs-badge {
  background: var(--ycs-low-bg);
  color: var(--ycs-low-ink);
}

.ycs-pair__desc {
  margin: 0;
  color: var(--ycs-ink);
  font-size: 0.92rem;
}

.ycs-pair__meter {
  block-size: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--ycs-panel);
}

.ycs-pair__meter > span {
  display: block;
  block-size: 100%;
  border-radius: inherit;
  transition: inline-size 0.4s ease;
}

.ycs-pair--high .ycs-pair__meter > span {
  background: var(--ycs-high-bg);
}

.ycs-pair--medium .ycs-pair__meter > span {
  background: var(--ycs-mid-bg);
}

.ycs-pair--low .ycs-pair__meter > span {
  background: var(--ycs-low-bg);
}

/* Status messages ------------------------------------------------------------ */

.ycs__status {
  margin-block-start: 1.25rem;
}

.ycs__status:empty {
  display: none;
}

.ycs-msg {
  padding: 0.8rem 1rem;
  border: 1px solid var(--ycs-border-strong);
  border-radius: var(--ycs-radius-sm);
  background: var(--ycs-panel);
}

.ycs-msg p {
  margin: 0;
}

.ycs-msg--success {
  border-color: var(--ycs-high-bg);
}

.ycs-msg--warning {
  border-color: var(--ycs-mid-bg);
}

.ycs-msg--error {
  border-color: var(--ycs-low-bg);
}

.ycs-msg ul {
  margin: 0.4rem 0 0;
  padding-inline-start: 1.2rem;
}

.ycs-msg a {
  font-weight: 700;
}

/* Sticky footer -------------------------------------------------------------- */

.ycs__footer {
  position: sticky;
  inset-block-end: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-block-start: 1.5rem;
  padding: 0.75rem 0.9rem;
  border-block-start: 1px solid var(--ycs-border);
  border-radius: var(--ycs-radius);
  background: rgb(255 255 255 / 92%);
  backdrop-filter: blur(8px);
  box-shadow: 0 -6px 20px rgb(0 0 0 / 8%);
}

.ycs-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-block-size: 3rem;
  padding: 0.6rem 1.25rem;
  border: 0;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.ycs-btn--ghost {
  background: transparent;
  color: var(--ycs-ink);
}

.ycs-btn--ghost:hover {
  background: var(--ycs-panel);
}

.ycs .ycs-btn--primary,
.ycs .ycs-btn--primary:hover,
.ycs .ycs-btn--primary:focus,
.ycs .ycs-btn--primary:disabled {
  /* Beats ".ycs button { color: inherit }" and the theme's button colors. */
  color: var(--ycs-accent-ink);
}

.ycs-btn--primary {
  background: var(--ycs-accent);
  box-shadow: 0 4px 12px rgb(23 120 166 / 28%);
}

.ycs-btn--primary:hover:not(:disabled) {
  background: var(--ycs-accent-hover);
}

.ycs-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.ycs-btn[aria-busy="true"] {
  cursor: progress;
}

@container ycs (max-width: 520px) {
  /* Compact slot rows: small thumbnail on the left, name beside it. */
  .ycs-slot {
    grid-template-columns: 5.5rem minmax(0, 1fr) auto;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "media name actions"
      "media tag actions"
      "search search search";
  }

  .ycs-slot__media {
    aspect-ratio: 1;
  }

  /* One footer row: icon-only reset, the cart button takes the rest. */
  .ycs__footer {
    flex-wrap: nowrap;
    padding: 0.5rem;
  }

  .ycs-btn--primary {
    flex: 1;
    padding-inline: 0.75rem;
  }

  .ycs-btn--ghost {
    padding-inline: 0.75rem;
  }

  .ycs-btn--ghost span:not(.ycs-icon) {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .ycs-stripe__cap {
    inset-inline: 0.35rem;
    inset-block-end: 0.35rem;
    max-inline-size: calc(100% - 0.7rem);
    font-size: 0.7rem;
  }
}

/* Loading skeleton ------------------------------------------------------------ */

.ycs-skeleton {
  background: linear-gradient(90deg, #eceef0 25%, #f6f7f8 50%, #eceef0 75%);
  background-size: 200% 100%;
  animation: ycs-shimmer 1.2s linear infinite;
}

@keyframes ycs-shimmer {
  to {
    background-position-x: -200%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ycs *,
  .ycs *::before,
  .ycs *::after {
    animation: none !important;
    transition: none !important;
  }
}