/* ===== Wallpaper Studio (/wallpaper-studio) =====
   Только эта страница. palette-legacy.css сюда не подключается (план, раздел 2),
   поэтому кнопки, карточки и ползунки повторены здесь в том же виде, что на
   /gradient-creator: те же размеры, скругления и цвета. */

.ws-page {
  --ws-line: #e8e8e8;
  --ws-ink: #111827;
  --ws-muted: #667085;
  --ws-soft: #8b95a7;
  --ws-accent: #45c463;
  padding-bottom: 64px;
}

.ws-wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

.ws-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ----- Верхняя панель ----- */

.ws-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px 28px;
  flex-wrap: wrap;
  padding: 24px 0 18px;
}

.ws-topbar__group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.ws-topbar__group--end {
  margin-left: auto;
}

.ws-find {
  width: 200px;
  height: 46px;
  padding: 0 24px;
  border-radius: 14px;
  border: 1px solid var(--ws-line);
  background: #ffffff;
  color: #0f172a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  transition: transform 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.ws-find:hover {
  color: #ffffff;
  border-color: transparent;
  background-image: linear-gradient(to right,
    #FF8C00 0 16.65%, #FF5B2E 16.65% 33.3%, #FF2F86 33.3% 49.95%,
    #9B42FF 49.95% 66.6%, #2563EB 66.6% 83.25%, #16C7E8 83.25% 100%);
  background-size: 260px 100%;
  animation: wsFindDance 2s linear infinite;
  transform: scale(1.04) translateY(-1px);
}

.ws-find:hover .ws-find__icon {
  filter: brightness(0) invert(1);
}

.ws-find:active {
  transform: scale(0.96);
}

.ws-find__icon {
  width: 17px;
  height: 17px;
  display: block;
}

@keyframes wsFindDance {
  to { background-position: 260px 0; }
}

.ws-space-hint {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #777777;
  font-size: 13px;
  font-weight: 600;
}

.ws-space-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  height: 30px;
  padding: 0 14px;
  border-radius: 999px;
  background: #fafafa;
  border: 1px solid var(--ws-line);
  color: #666666;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.ws-size {
  position: relative;
  height: 46px;
  padding: 0 14px 0 16px;
  border-radius: 14px;
  border: 1px solid var(--ws-line);
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.ws-size__shape {
  flex: 0 0 auto;
  border: 2px solid #1a1a1a;
  border-radius: 3px;
  box-sizing: border-box;
}

.ws-size__select {
  height: 100%;
  border: 0;
  background: transparent;
  color: #1a1a1a;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  padding-right: 4px;
}

.ws-size__select:focus {
  outline: none;
}

.ws-size:focus-within {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.ws-btn {
  height: 46px;
  padding: 0 22px;
  border-radius: 14px;
  border: 1px solid var(--ws-line);
  background: #ffffff;
  color: #1a1a1a;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  min-width: 150px;
  transition: background 0.25s ease, transform 0.25s ease;
}

.ws-btn:hover:not(:disabled) {
  background: #fafafa;
  transform: translateY(-2px);
}

.ws-btn:disabled {
  cursor: progress;
  color: #98a2b3;
}

/* ----- Сцена -----
   Форма сцены = форма выбранного размера файла (--ws-ar ставит скрипт).
   Высота ограничена, ширина считается по пропорции и не шире страницы. */

.ws-stage-wrap {
  --ws-ar: 1.7778;
  --ws-max-h: min(64vh, 780px);
}

.ws-stage-wrap.is-portrait {
  --ws-max-h: min(78vh, 900px);
}

.ws-stage {
  position: relative;
  width: min(100%, calc(var(--ws-max-h) * var(--ws-ar)));
  aspect-ratio: var(--ws-ar);
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: #f4f4f4;
}

.ws-stage__canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.ws-stage__message {
  position: absolute;
  inset: auto 16px 16px 16px;
  margin: 0;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ws-ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

/* Ручка света — белое кольцо, как у точек меша на /gradient-creator.
   Видна только при наведении на сцену, чтобы ничего лишнего не лежало
   поверх картинки; на сенсорном экране видна всегда. */
.ws-light-handle {
  position: absolute;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 3px solid #ffffff;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.25), 0 4px 14px rgba(15, 23, 42, 0.3);
  transform: translate(-50%, -50%);
  cursor: grab;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.ws-light-handle::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: #ffffff;
}

.ws-stage:hover .ws-light-handle,
.ws-light-handle:focus-visible,
.ws-light-handle.is-dragging {
  opacity: 1;
}

.ws-light-handle.is-dragging {
  cursor: grabbing;
}

@media (hover: none) {
  .ws-light-handle { opacity: 1; }
}

/* ----- Карточки настроек ----- */

.ws-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 40px 44px;
  margin-top: 36px;
}

.ws-card {
  min-width: 0;
  display: grid;
  align-content: start;
  row-gap: 20px;
}

.ws-card__header {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.ws-card__title {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ws-ink);
}

.ws-card__hint {
  font-size: 12px;
  font-weight: 500;
  color: var(--ws-soft);
}

.ws-card__sub {
  display: grid;
  gap: 14px;
}

.ws-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ws-seg button {
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: #fafafa;
  color: #3f4654;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.ws-seg button:hover {
  background: #f4f5f7;
}

.ws-seg button.is-active {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px #e3e3e3;
  color: var(--ws-ink);
}

.ws-card__subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ws-card__header .ws-lock {
  margin-left: auto;
}

.ws-seg--small button {
  height: 36px;
  padding: 0 14px;
  font-size: 12px;
}

/* ----- Замок: что FIND не трогает ----- */

.ws-lock {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #e3e3e3;
  border-radius: 999px;
  background: #ffffff;
  color: #98a2b3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ws-lock svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.ws-lock:hover {
  background: #f8f8f8;
  color: #475467;
}

.ws-lock.is-locked {
  color: #111827;
  border-color: #cfd4dc;
}

.ws-lock--small {
  width: 28px;
  height: 28px;
  border-color: transparent;
}

.ws-lock--small svg {
  width: 14px;
  height: 14px;
}

/* ----- Палитра ----- */

.ws-palette-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.ws-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.ws-swatch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.ws-swatch__pick {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.ws-swatch__dot,
.ws-color-field__dot {
  position: relative;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.12);
}

/* Системный выбор цвета лежит прозрачным прямо на кружке: клик по кружку
   открывает его, а фокус с клавиатуры видно обводкой кружка. */
.ws-color-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.ws-swatch__dot:focus-within,
.ws-color-field__dot:focus-within {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.ws-swatch__hex,
.ws-color-field__hex {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: #344054;
}

.ws-stepper {
  height: 40px;
  padding: 0 6px;
  border: 1px solid var(--ws-line);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ws-stepper__btn {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: #fafafa;
  color: #1a1a1a;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.ws-stepper__btn:disabled {
  color: #c4c9d2;
  cursor: default;
}

.ws-stepper__value {
  min-width: 18px;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ----- Поля цвета (фон, свет, тени) ----- */

.ws-color-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
}

.ws-color-fields[hidden],
.ws-color-field[hidden] {
  display: none;
}

.ws-color-field {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.ws-color-field__text {
  display: grid;
  gap: 3px;
}

.ws-color-field__label {
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

/* ----- Свой размер ----- */

.ws-custom {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ws-custom[hidden] {
  display: none;
}

.ws-custom__input {
  width: 92px;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--ws-line);
  border-radius: 14px;
  color: #1a1a1a;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ws-custom__x {
  color: var(--ws-muted);
  font-weight: 700;
}

/* ----- Ползунки ----- */

.ws-sliders {
  display: grid;
  gap: 18px;
}

.ws-row {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) 52px;
  align-items: center;
  gap: 16px;
}

.ws-row__label {
  color: #344054;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.ws-row__value {
  color: var(--ws-muted);
  font-size: 15px;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ws-range {
  width: 100%;
  height: 6px;
  margin: 0;
  border-radius: 999px;
  appearance: none;
  -webkit-appearance: none;
  background: #f1f1f1;
  cursor: pointer;
}

.ws-range::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  border: 3px solid #ffffff;
  border-radius: 50%;
  background: var(--ws-accent);
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.18);
  -webkit-appearance: none;
  appearance: none;
}

.ws-range::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 3px solid #ffffff;
  border-radius: 50%;
  background: var(--ws-accent);
  box-shadow: 0 2px 8px rgba(16, 24, 40, 0.18);
}

/* ----- Описание страницы (для поиска и для тех, у кого нет WebGL) ----- */

.ws-about {
  max-width: 760px;
  margin: 64px 0 0;
  color: #475467;
  font-size: 15px;
  line-height: 1.65;
}

.ws-about__title {
  margin: 0 0 10px;
  color: var(--ws-ink);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.ws-about p {
  margin: 0;
}

/* ----- Узкие экраны ----- */

@media (max-width: 900px) {
  .ws-grid {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .ws-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 14px;
  }

  .ws-row > :first-child {
    grid-column: 1 / -1;
  }

  .ws-row__value {
    min-width: 44px;
  }
}

@media (max-width: 640px) {
  .ws-wrap {
    padding: 0 16px;
  }

  .ws-topbar {
    padding-top: 12px;
  }

  .ws-space-hint {
    display: none;
  }

  .ws-find {
    width: auto;
    flex: 1 1 auto;
    font-size: 18px;
  }

  .ws-topbar__group,
  .ws-topbar__group--end {
    width: 100%;
    margin-left: 0;
  }

  .ws-size {
    flex: 1 1 auto;
  }

  .ws-size__select {
    width: 100%;
  }

  .ws-custom {
    flex: 1 1 100%;
  }

  .ws-custom__field,
  .ws-custom__input {
    flex: 1 1 0;
    width: 100%;
  }

  .ws-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 12px;
  }

  .ws-stage-wrap,
  .ws-stage-wrap.is-portrait {
    --ws-max-h: 70vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ws-find:hover { animation: none; }
  .ws-find, .ws-btn, .ws-light-handle { transition: none; }
}

/* ===== Orbs ===== */

/* Карточки и подписи другого режима прячутся атрибутом hidden. У карточек
   свой display: grid, он перебил бы браузерное [hidden] — поэтому явно. */
.ws-page [hidden] {
  display: none !important;
}

.ws-modes button {
  height: 46px;
  padding: 0 20px;
  font-size: 15px;
}

.ws-stage:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 3px;
}

.ws-stage.is-orbs {
  cursor: pointer;
}

/* Рамка выбранного круга: пунктирный овал поверх картинки, ручки по углам
   описанного прямоугольника и точка угла градиента на самом краю. */
.ws-orb-box {
  position: absolute;
  border: 1.5px dashed rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.25);
  pointer-events: none;
  cursor: move;
}

.ws-orb-box__h,
.ws-orb-box__angle {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #ffffff;
  background: #111827;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.35);
  transform: translate(-50%, -50%);
  pointer-events: auto;
  touch-action: none;
}

.ws-orb-box__h {
  border-radius: 4px;
}

.ws-orb-box__h--nw { left: 0; top: 0; cursor: nwse-resize; }
.ws-orb-box__h--ne { left: 100%; top: 0; cursor: nesw-resize; }
.ws-orb-box__h--sw { left: 0; top: 100%; cursor: nesw-resize; }
.ws-orb-box__h--se { left: 100%; top: 100%; cursor: nwse-resize; }

.ws-orb-box__angle {
  border-radius: 50%;
  background: #ffffff;
  border-color: #111827;
  cursor: grab;
}

@media (hover: none) {
  .ws-orb-box__h,
  .ws-orb-box__angle {
    width: 22px;
    height: 22px;
  }
}

/* Панель кругов */

.ws-obj-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ws-chip {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--ws-line);
  border-radius: 10px;
  background: #ffffff;
  color: #1a1a1a;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.ws-chip:hover:not(:disabled) {
  background: #fafafa;
}

.ws-chip:disabled {
  color: #c4c9d2;
  cursor: default;
}

.ws-chip--danger:not(:disabled) {
  color: #b42318;
}

.ws-layers {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
  max-height: 260px;
  overflow: auto;
}

.ws-layer {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: #fafafa;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #344054;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.ws-layer:hover {
  background: #f4f5f7;
}

.ws-layer.is-selected {
  background: #ffffff;
  box-shadow: inset 0 0 0 1.5px #111827;
  color: var(--ws-ink);
}

.ws-layer__dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.12);
}

.ws-layer__mat {
  margin-left: auto;
  color: var(--ws-soft);
  font-size: 12px;
  font-weight: 600;
}

.ws-obj-props {
  display: grid;
  gap: 18px;
}

.ws-obj-colors {
  display: grid;
  gap: 10px;
}

.ws-obj-colors__row {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
}

.ws-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ws-chip-color {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.12);
  cursor: pointer;
}

.ws-chip-color.is-active {
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #111827;
}

@media (max-width: 640px) {
  .ws-modes {
    width: 100%;
  }

  .ws-modes button {
    flex: 1 1 0;
  }

  .ws-obj-colors__row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

/* ===== Этап 4: история, направляющие, раскрывашки ===== */

.ws-history {
  display: inline-flex;
  gap: 8px;
}

.ws-icon-btn {
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--ws-line);
  border-radius: 14px;
  background: #ffffff;
  color: #1a1a1a;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ws-icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ws-icon-btn:hover:not(:disabled) {
  background: #fafafa;
}

.ws-icon-btn:disabled {
  color: #c4c9d2;
  cursor: default;
}

/* Строка под сценой — той же ширины, что и сама сцена. */
.ws-stage-bar {
  width: min(100%, calc(var(--ws-max-h) * var(--ws-ar)));
  margin: 10px auto 0;
  display: flex;
  justify-content: flex-end;
}

.ws-text-btn {
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ws-muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.ws-text-btn:hover {
  background: #f4f5f7;
  color: var(--ws-ink);
}

/* Направляющие скрыты: ни ручки света, ни рамки выбора. */
.ws-stage.is-clean .ws-light-handle {
  display: none;
}

/* Кнопка-раскрывашка есть только на узком экране. */
.ws-card__toggle {
  display: none;
}

@media (max-width: 900px) {
  .ws-card__header {
    position: relative;
    padding-right: 40px;
  }

  .ws-card__toggle {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ws-muted);
    cursor: pointer;
  }

  .ws-card__toggle svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.2s ease;
  }

  .ws-card__toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
  }

  /* Замок лежит поверх кнопки-раскрывашки, иначе нажатие на него сворачивало бы карточку. */
  .ws-card__header .ws-lock {
    position: relative;
    z-index: 1;
  }

  .ws-card.is-collapsed > :not(.ws-card__header),
  .ws-card.is-collapsed .ws-card__hint {
    display: none !important;
  }

  .ws-card {
    padding-bottom: 12px;
    border-bottom: 1px solid var(--ws-line);
  }

  .ws-grid {
    gap: 12px;
  }
}

@media (max-width: 640px) {
  .ws-history {
    flex: 0 0 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ws-card__toggle svg { transition: none; }
}
