:root{
  --gap: 10px;
  --outer: 10px;
  --bg: #f6f1e6;
}

html, body {
  height: 100%;
  margin: 0;
  background: #ffffff;
  font-family: var(--font-ui);
}


.site-header-title {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.site-header-heading {
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -1.5px;
  margin: 0 0 10px;
  line-height: 1.1;
  background: linear-gradient(135deg, #110623 0%, #4a4a4a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.site-header-subtitle {
  font-size: 18px; color: #666; font-weight: 400; letter-spacing: .2px;
  margin: 0;
}

#wrap{
  height: 100vh;
  box-sizing: border-box;
}

#board{
  height: 100vh;
  box-sizing: border-box;
  padding: var(--outer);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  overflow: hidden; /* no scrolling */
}

.row{
  display: flex;
  gap: var(--gap);
  width: 100%;
  align-items: stretch;
  justify-content: center;
}

.item{
  overflow: hidden;
  border-radius: 10px;
  background: transparent;
  flex: 0 0 auto;
  cursor: grab;
  transition: opacity .15s ease, transform .15s ease, box-shadow .15s ease;
}

.item.dragging{
  opacity: .35;
  transform: scale(.97);
  cursor: grabbing;
}

.item.drag-over{
  box-shadow: 0 0 0 3px #6c47ff, 0 4px 24px rgba(108,71,255,.25);
  transform: scale(1.03);
}

.item img{
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

/* ====== Center Button ====== */
#pickerOverlay{
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
}

#btnPick{
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(0,0,0,0.18);
  background: #fff;
  padding: 14px 18px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.10);
}

#btnPick:active{ transform: translateY(1px); }

.pickerBox{
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

#privacyNote{
  position: fixed;
  bottom: 20px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  line-height: 1.35;
  color: rgba(0,0,0,0.45);
  z-index: 60;
  margin: 0;
}

#usageHint{
  pointer-events: none;
  max-width: min(560px, calc(100vw - 40px));
  font-size: 15px;
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: .2px;
  color: #888888;
  padding-top: 20px;
  margin: 0;
}

.hidden{ display: none !important; }

/* ====== Lightbox (no close icon) ====== */
#lightbox{
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#lightbox.open{ display: flex; }

#lightboxInner{
  position: relative;
  max-width: min(92vw, 1400px);
  max-height: 90vh;
  border-radius: 14px;
  overflow: visible;
  box-shadow: none;
  background: transparent;
  transform: scale(0.98);
  opacity: 0;
  transition: transform .16s ease, opacity .16s ease;
}

#lightbox.open #lightboxInner{
  transform: scale(1);
  opacity: 1;
}

#lightboxContent{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  box-sizing: border-box;
}

#lightboxImg{
  display: block;
  width: 100%;
  height: 100%;
  max-width: min(92vw, 1400px);
  max-height: calc(90vh - 18px);
  object-fit: contain;
  background: transparent;
  border-radius: 4px;
}

#lightboxCaption{
  font-size: 11px;
  line-height: 1.2;
  color: rgb(255 255 255 / 44%);
  text-align: center;
  letter-spacing: 0.01em;
  user-select: none;
}


/* ============================================================
   RESPONSIVE — Tablet landscape  (≤ 1024px)
   ============================================================ */
@media (max-width: 1024px) {
  :root {
    --gap: 8px;
    --outer: 8px;
  }

  .site-header-heading {
    font-size: 38px;
    letter-spacing: -1px;
  }

  .site-header-subtitle {
    font-size: 16px;
  }
}


/* ============================================================
   RESPONSIVE — Tablet portrait  (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --gap: 6px;
    --outer: 12px;
  }


  .site-header-title {
    gap: 10px;
    flex-wrap: wrap;
  }

  .site-header-logo {
    height: 48px;
  }

  .site-header-heading {
    font-size: 32px;
    letter-spacing: -0.8px;
    margin: 0 0 8px;
  }

  .site-header-subtitle {
    font-size: 15px;
  }

  #btnPick {
    font-size: 15px;
    padding: 13px 20px;
    border-radius: 12px;
  }

  #usageHint {
    font-size: 13px;
    padding-top: 14px;
  }

  #privacyNote {
    font-size: 12px;
    bottom: 16px;
    padding: 0 16px;
  }

  .item {
    border-radius: 8px;
  }

  #lightbox {
    padding: 16px;
  }

  #lightboxImg {
    max-height: calc(90vh - 14px);
  }
}


/* ============================================================
   RESPONSIVE — Phone  (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
  :root {
    --gap: 5px;
    --outer: 10px;
  }


  .site-header-title {
    flex-direction: column;
    gap: 8px;
  }

  .site-header-logo {
    height: 40px;
  }

  .site-header-heading {
    font-size: 26px;
    letter-spacing: -0.5px;
    margin: 0 0 6px;
    text-align: center;
  }

  .site-header-subtitle {
    font-size: 14px;
    line-height: 1.4;
  }

  .pickerBox {
    gap: 8px;
    padding: 0 12px;
  }

  #btnPick {
    font-size: 15px;
    padding: 14px 24px;
    border-radius: 12px;
    width: 100%;
    max-width: 280px;
  }

  #usageHint {
    font-size: 13px;
    padding-top: 12px;
    line-height: 1.45;
  }

  #privacyNote {
    font-size: 11px;
    bottom: 14px;
    padding: 0 20px;
    line-height: 1.4;
  }

  .item {
    border-radius: 6px;
  }

  #lightbox {
    padding: 12px;
  }

  #lightboxImg {
    max-height: calc(88vh - 14px);
  }

  #lightboxCaption {
    font-size: 10px;
  }
}


/* ============================================================
   RESPONSIVE — Small phone  (≤ 360px)
   ============================================================ */
@media (max-width: 360px) {
  :root {
    --gap: 4px;
    --outer: 8px;
  }

  .site-header-logo {
    height: 34px;
  }

  .site-header-heading {
    font-size: 22px;
    letter-spacing: -0.3px;
  }

  .site-header-subtitle {
    font-size: 13px;
  }

  #btnPick {
    font-size: 14px;
    padding: 13px 20px;
    max-width: 260px;
  }

  #usageHint {
    font-size: 12px;
  }

  #privacyNote {
    font-size: 11px;
    bottom: 10px;
  }
}


/* ====== Extracted inline styles ====== */
.site-header-logo {
  height: 64px;
  max-height: 64px;
  width: auto;
  display: block;
  padding-bottom: 11px;
  flex-shrink: 0;
}

.usage-hint-icon {
  display: inline-block;
  vertical-align: -2px;
  margin-right: 5px;
  opacity: 0.75;
}


/* ============================================================
   PALETTE STUDIO
   ============================================================ */

/* Reset */
* {
  box-sizing: border-box;
}

/* Body additions for palette page */
body {
  width: 100%;
  color: #1a1a1a;
  line-height: 1.6;
  background: #ffffff;
  background-attachment: fixed;
}

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    html, body {
      width: 100%;
      height: 100%;
    }

    body {
      font-family: var(--font-ui);
      background: #ffffff;
      color: #1a1a1a;
      line-height: 1.6;
      background-attachment: fixed;
    }

    .wrap {
      /* Cap content at 1400px, but always keep a side gutter so it never sticks
         to the screen edges while narrowing (40px desktop, less on smaller
         screens — see CONTAINER GUTTERS). Vertical padding kept. */
      width: min(1400px, calc(100% - 80px));
      max-width: 1400px;
      margin: 0 auto;
      padding: 48px 0;
    }

    /* ============ HEADER ============ */
    .header {
      margin-bottom: 56px;
      text-align: center;
    }

    .header-title {
      font-size: 48px;
      font-weight: 800;
      letter-spacing: -1.5px;
      margin-bottom: 12px;
      background: linear-gradient(135deg, #110623 0%, #4a4a4a 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      display: inline-flex;
      align-items: center;
      gap: 12px;
      justify-content: center;
    }

    .header-subtitle {
      font-size: 16px;
      color: #666;
      font-weight: 400;
      letter-spacing: 0.2px;
    }

    /* ============ START SCREEN (empty state) ============ */
    .pfi-start {
      min-height: min(72vh, 780px);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      text-align: center;
      padding: 40px 0 60px;
    }

    .pfi-start-inner {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 10px;
      /* Reserve a consistent block height so the heading lines up with the
         /moodboard start screen no matter how many lines the hint wraps to. */
      min-height: 290px;
    }

    .pfi-start .moodboard-header {
      margin-bottom: 14px;
    }

    /* Heading and subtitle break into two even lines on wide screens and
       re-wrap by themselves on narrow ones (no hard <br> in the markup). */
    .palette-from-image-page .moodboard-header-heading {
      max-width: 560px;
      margin-left: auto;
      margin-right: auto;
      text-wrap: balance;
    }

    .palette-from-image-page .moodboard-header-subtitle {
      max-width: 620px;
      margin-left: auto;
      margin-right: auto;
      text-wrap: balance;
    }

    .pfi-start-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      appearance: none;
      -webkit-appearance: none;
      border: 1px solid rgba(0, 0, 0, 0.18);
      background: #ffffff;
      padding: 14px 18px;
      border-radius: 14px;
      cursor: pointer;
      font-family: inherit;
      font-weight: 700;
      font-size: 16px;
      line-height: 1;
      color: #1a1a1a;
      box-shadow: 0 14px 40px rgba(0, 0, 0, 0.10);
      transition: transform 0.15s ease;
    }

    .pfi-start-btn:active {
      transform: translateY(1px);
    }

    .pfi-start-btn__icon {
      width: 18px;
      height: 18px;
      flex-shrink: 0;
    }

    .pfi-start-hint {
      max-width: min(560px, calc(100vw - 40px));
      font-size: 15px;
      font-weight: 400;
      line-height: 1.35;
      letter-spacing: 0.2px;
      color: #888888;
      padding-top: 20px;
      margin: 0;
    }

    .pfi-start-note {
      text-align: center;
      font-size: 13px;
      line-height: 1.35;
      color: rgba(0, 0, 0, 0.45);
      margin: 36px 0 0;
    }

    /* ============ CONTROLS SECTION ============ */
    .controls-section {
      background: transparent;
      border: 0;
      border-radius: 0;
      padding: 0;
      box-shadow: none;
      margin-bottom: 40px;
    }

    .controls {
      display: flex;
      flex-wrap: wrap;
      gap: 20px;
      align-items: center;
    }

    /* Wide screens: Clean/Studio, Colors and RGB/CMYK share one width (like Colors) */
    /*
      Whenever the thumbnail sits beside its buttons, the settings mirror that
      block: the SAME two-column grid (repeat(2, minmax(0, 360px)), centred) as
      the .preview-card below, so the two settings columns line up exactly with
      the thumbnail and button columns above — and both collapse to a single
      column at the same breakpoint (see max-width: 560px).
    */
    @media (max-width: 1200px) {
      .controls {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 360px));
        justify-content: center;
        row-gap: 12px;
        column-gap: 20px;
        align-items: stretch;
      }

      .controls > .palette-topbar__colors,
      .controls > .palette-topbar__format {
        width: auto;
        max-width: none;
      }

      /* Clean / Studio and Colors share the same 200px inner width so the two
         pills read as an even, matching pair. */
      .controls > .palette-topbar__colors:has(.palette-mode-switch) .palette-mode-toggle {
        width: 100%;
        max-width: 200px;
        justify-content: space-between;
      }

      /* Colors: label on the left, then − 8 + spread across the right of the
         200px group so − lines up with the switch's left edge and + with the
         group's right edge — mirroring the Clean/Studio spacing. */
      .controls > .palette-topbar__colors:has(.palette-topbar__stepper) {
        justify-content: center;
        gap: 0;
      }
      .controls > .palette-topbar__colors:has(.palette-topbar__stepper) .palette-topbar__colors-label {
        margin-right: 27px;
      }
      .controls > .palette-topbar__colors:has(.palette-topbar__stepper) .palette-topbar__colors-value {
        margin: 0 23px;
      }

      /* Detail: label left, slider grows, value right */
      .controls > .palette-topbar__colors:has(.palette-topbar__detail-range) {
        justify-content: flex-start;
      }
      .controls > .palette-topbar__colors:has(.palette-topbar__detail-range) .palette-topbar__detail-range {
        width: auto;
        flex: 1 1 auto;
        min-width: 40px;
      }

      /* RGB / CMYK split their cell evenly */
      .controls > .palette-topbar__format .palette-topbar__format-button {
        flex: 1;
        min-width: 0;
      }
    }

    .controls .spacer {
      flex: 1;
      min-width: 12px;
    }

    /* ============ FILE INPUT ============ */
    input[type="file"] {
      display: none;
    }

    /* Choose image button — same look as the header Log in / Sign up button */
    .file-btn {
      width: 100%;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      min-height: 46px;
      height: 46px;
      padding: 0 26px;
      background: #020817;
      color: #ffffff;
      border: none;
      border-radius: 14px;
      font-family: inherit;
      font-size: 15px;
      font-weight: 700;
      line-height: 1;
      white-space: nowrap;
      cursor: pointer;
      box-shadow: 0 14px 30px rgba(2, 8, 23, 0.16);
    }

    .file-btn svg {
      width: 18px;
      height: 18px;
      opacity: 0.95;
      flex: 0 0 auto;
    }

    /* ============ SEGMENTED CONTROL (RGB / CMYK) ============ */
    .palette-topbar__format {
      height: 46px;
      min-height: 46px;
      padding: 4px;
      border-radius: 14px;
      border: 1px solid #e8e8e8;
      background: #fafafa;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 0;
    }

    .palette-topbar__format-button {
      height: 38px;
      min-width: 74px;
      padding: 0 18px;
      border: 0;
      border-radius: 10px;
      background: transparent;
      color: #666666;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-family: inherit;
      font-size: 13px;
      font-weight: 800;
      line-height: 1;
      white-space: nowrap;
      cursor: pointer;
      transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
    }

    .palette-topbar__format-button.active {
      background: #ffffff;
      color: #1a1a1a;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    }

    .palette-topbar__format-button:hover:not(.active) {
      background: rgba(0, 0, 0, 0.02);
      color: #1a1a1a;
    }

    /* ============ BORDERED PILL (Colors / Clean-Studio / Detail) ============ */
    .palette-topbar__colors {
      height: 46px;
      min-height: 46px;
      padding: 0 18px;
      border-radius: 14px;
      border: 1px solid #e8e8e8;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 13px;
      color: #1a1a1a;
      font-family: inherit;
      font-size: 15px;
      font-weight: 700;
      line-height: 1;
      white-space: nowrap;
    }

    .palette-topbar__colors-label {
      display: inline-flex;
      align-items: center;
      height: 100%;
    }

    .palette-topbar__colors-value {
      min-width: 18px;
      text-align: center;
      color: #020817;
      font-size: 15px;
      font-weight: 800;
      font-variant-numeric: tabular-nums;
      line-height: 1;
    }

    .palette-topbar__stepper {
      width: 30px;
      height: 30px;
      border-radius: 999px;
      border: 1px solid #dcdcdc;
      background: #ffffff;
      color: #1a1a1a;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      padding: 0;
      font-size: 20px;
      line-height: 1;
      font-weight: 500;
      cursor: pointer;
      transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
    }

    .palette-topbar__stepper:hover {
      background: #f7f7f7;
      border-color: #cfcfcf;
    }

    .palette-topbar__stepper:active {
      transform: translateY(1px);
    }

    .palette-topbar__range {
      position: absolute;
      width: 1px;
      height: 1px;
      margin: 0;
      padding: 0;
      opacity: 0;
      pointer-events: none;
    }

    /* Clean / Studio toggle (Auto-Pro style switch inside a pill) */
    .palette-mode-toggle {
      position: relative;
      display: inline-flex;
      align-items: center;
      gap: 9px;
      padding: 0;
      background: transparent;
      border: 0;
      color: #1a1a1a;
      font-size: 15px;
      line-height: 1;
      font-weight: 700;
      cursor: pointer;
      user-select: none;
    }

    .palette-mode-toggle__text {
      display: inline-flex;
      align-items: center;
      color: #1a1a1a;
    }

    .palette-mode-switch {
      display: inline-block;
      position: relative;
      width: 45px;
      height: 22px;
      flex: 0 0 auto;
    }

    .palette-mode-switch input {
      opacity: 0;
      width: 0;
      height: 0;
    }

    .palette-mode-switch__slider {
      position: absolute;
      inset: 0;
      cursor: pointer;
      background-color: #4bc05f;
      border-radius: 34px;
      transition: background-color 0.3s ease;
    }

    .palette-mode-switch__slider::before {
      position: absolute;
      content: "";
      height: 18px;
      width: 18px;
      left: 2px;
      bottom: 2px;
      background-color: #ffffff;
      border-radius: 50%;
      transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
      box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    .palette-mode-switch input:checked + .palette-mode-switch__slider {
      background-color: #ca70d4;
    }

    .palette-mode-switch input:checked + .palette-mode-switch__slider::before {
      transform: translateX(23px);
    }

    .palette-mode-switch__knob {
      position: absolute;
      top: 50%;
      left: 2px;
      transform: translateY(-50%);
      width: 18px;
      height: 18px;
      background-color: #ffffff;
      border-radius: 50%;
      transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
      pointer-events: none;
    }

    .palette-mode-switch input:checked ~ .palette-mode-switch__knob {
      transform: translateX(23px) translateY(-50%);
    }

    /* Detail slider (Hue-style range inside the pill) */
    .palette-topbar__detail-range {
      width: 150px;
      height: 6px;
      border-radius: 999px;
      outline: none;
      appearance: none;
      -webkit-appearance: none;
      background: #f1f1f1;
      cursor: pointer;
    }

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

    .palette-topbar__detail-range::-moz-range-thumb {
      width: 22px;
      height: 22px;
      border: 3px solid #ffffff;
      border-radius: 50%;
      background: #45c463;
      box-shadow: 0 2px 8px rgba(16, 24, 40, 0.18);
      cursor: pointer;
    }

    /* ============ BUILD PALETTE BUTTON (same as FIND) ============ */
    .btn-primary {
      width: auto;
      min-width: 200px;
      height: 46px;
      min-height: 46px;
      padding: 0 28px;
      border-radius: 14px;
      border: 1px solid #e8e8e8;
      background: #ffffff;
      color: #0f172a;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      font-family: inherit;
      font-size: 15px;
      font-weight: 700;
      cursor: pointer;
      box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
      transform: none;
      transition:
        transform 0.2s ease,
        box-shadow 0.2s ease,
        background-color 0.2s ease,
        border-color 0.2s ease;
    }

    .btn-primary:hover:not(:disabled) {
      color: #ffffff;
      border-color: transparent;
      background-image: linear-gradient(
        to right,
        #FF8C00,
        #FF8C00 16.65%,
        #FF5B2E 16.65%,
        #FF5B2E 33.3%,
        #FF2F86 33.3%,
        #FF2F86 49.95%,
        #9B42FF 49.95%,
        #9B42FF 66.6%,
        #2563EB 66.6%,
        #2563EB 83.25%,
        #16C7E8 83.25%,
        #16C7E8 100%
      );
      background-size: 260px 100%;
      animation: findPrimaryDance 2s linear infinite;
      transform: scale(1.04) translateY(-1px);
      box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    }

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

    .btn-primary:active:not(:disabled) {
      transform: scale(0.96);
      box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    }

    .btn-primary:disabled {
      opacity: 0.4;
      cursor: not-allowed;
    }

    .btn-primary .btn-icon {
      width: 17px;
      height: 17px;
      display: block;
      flex: 0 0 auto;
    }

    /* ============ SAVE PALETTE BUTTON (same as palette page) ============ */
    .palette-topbar__save {
      width: 165px;
      height: 46px;
      min-height: 46px;
      padding: 0 22px;
      border-radius: 14px;
      border: 1px solid #e8e8e8;
      background: #ffffff;
      color: #1a1a1a;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      font-family: inherit;
      font-size: 15px;
      font-weight: 700;
      line-height: 1;
      white-space: nowrap;
      cursor: pointer;
      transition: background 0.25s ease, border-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
    }

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

    .palette-topbar__save:active:not(:disabled) {
      transform: translateY(0);
      box-shadow: none;
    }

    .palette-topbar__save:disabled {
      opacity: 0.4;
      cursor: not-allowed;
    }

    .palette-topbar__save-icon {
      width: 18px;
      height: 18px;
      display: block;
      flex: 0 0 auto;
    }

    /* ============ MAIN CONTENT LAYOUT ============ */
    /*
      Match the original "Palette New" layout from the screenshot:
      small thumbnail column on the left, wide palette/tools column on the right.
    */
    .main-grid {
      display: grid;
      grid-template-columns: 360px 1fr;
      gap: 40px;
      align-items: start;
    }

    /*
      From the moment the palette would wrap under the thumbnail, reflow into:
        1. thumbnail + the three action buttons (side by side when they fit),
        2. the settings row (Clean/Studio, Colors, Detail, RGB/CMYK),
        3. the palette.
      Done without touching the HTML: .wrap becomes a flex column and .main-grid
      uses display:contents so its children can be reordered with `order`.
    */
    @media (max-width: 1200px) {
      .wrap {
        display: flex;
        flex-direction: column;
        gap: 28px;
      }

      /* Dissolve the grid so preview-card and palette-card become direct
         flex children of .wrap, alongside the settings row. */
      .main-grid {
        display: contents;
      }

      .preview-card     { order: 1; }
      .controls-section { order: 2; margin-bottom: 0; }
      .palette-card     { order: 3; }

      /* Thumbnail on the left, buttons in the second column on the right —
         the same two-column grid the settings use, so their columns align. */
      .preview-card {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 360px));
        justify-content: center;
        column-gap: 20px;
        row-gap: 20px;
        align-items: start;
        max-width: none;
      }

      .preview-actions {
        margin-top: 0;
      }
    }

    /* When the thumbnail and its buttons stack, the settings stack too — same
       breakpoint keeps the two blocks in lockstep. */
    @media (max-width: 560px) {
      .preview-card,
      .controls {
        grid-template-columns: minmax(0, 360px);
      }
    }

    /*
      Wide screens: the settings move OUT of the top bar and INTO the right
      column, sitting above the palette. Left column = thumbnail + its buttons,
      right column = settings, then palette. Achieved by turning .wrap into a
      grid (with .main-grid dissolved via display:contents so preview-card and
      palette-card become grid items alongside the settings block).
    */
    @media (min-width: 1201px) {
      .wrap {
        display: grid;
        grid-template-columns: 360px 1fr;
        grid-template-areas:
          "preview settings"
          "preview palette";
        column-gap: 40px;
        row-gap: 28px;
        align-items: start;
      }

      .main-grid { display: contents; }
      .pfi-start { grid-column: 1 / -1; }
      .preview-card     { grid-area: preview; }
      .controls-section { grid-area: settings; margin-bottom: 0; }
      .palette-card     { grid-area: palette; }

      /* Settings as a 2x2 grid (two columns of two buttons). The four buttons
         go into a single row only on the widest screens (see min-width:1400). */
      .controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        row-gap: 12px;
        column-gap: 20px;
        align-items: stretch;
      }

      .controls > .palette-topbar__colors,
      .controls > .palette-topbar__format {
        width: 100%;
      }

      /* Clean / Studio spread across a fixed 200px inner width */
      .controls > .palette-topbar__colors:has(.palette-mode-switch) .palette-mode-toggle {
        width: 100%;
        max-width: 200px;
        justify-content: space-between;
      }

      /* Colors: label + − 8 + spread across the same 200px band */
      .controls > .palette-topbar__colors:has(.palette-topbar__stepper) {
        justify-content: center;
        gap: 0;
      }
      .controls > .palette-topbar__colors:has(.palette-topbar__stepper) .palette-topbar__colors-label {
        margin-right: 27px;
      }
      .controls > .palette-topbar__colors:has(.palette-topbar__stepper) .palette-topbar__colors-value {
        margin: 0 23px;
      }

      /* Detail: label left, slider grows, value right */
      .controls > .palette-topbar__colors:has(.palette-topbar__detail-range) {
        justify-content: flex-start;
      }
      .controls > .palette-topbar__colors:has(.palette-topbar__detail-range) .palette-topbar__detail-range {
        width: auto;
        flex: 1 1 auto;
        min-width: 40px;
      }

      /* RGB / CMYK split their cell evenly */
      .controls > .palette-topbar__format .palette-topbar__format-button {
        flex: 1;
        min-width: 0;
      }
    }

    /* Widest screens: all four settings fit in a single row above the palette. */
    @media (min-width: 1400px) {
      .controls {
        grid-template-columns: repeat(4, 1fr);
      }
    }

    /* ============ PREVIEW CARD ============ */
    .preview-card {
      background: transparent;
      border: 0;
      border-radius: 0;
      padding: 0;
      box-shadow: none;
    }

    /* Photo surface — dashed border with white inset, like Template preview */
    .preview-photo-surface {
      position: relative;
      width: 100%;
      padding: 4px;
      box-sizing: border-box;
      border: 1px dashed #d8dee8;
      border-radius: 22px;
      background-color: #ffffff;
      overflow: hidden;
    }

    .preview-actions {
      display: flex;
      flex-direction: column;
      gap: 12px;
      margin-top: 14px;
    }

    .preview-actions .file-btn,
    .preview-actions .btn-primary,
    .preview-actions .palette-topbar__save {
      width: 100%;
    }

    .card-label {
      display: block;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1.2px;
      color: #999;
      margin-bottom: 20px;
    }

    canvas#photo {
      display: block;
      width: 100%;
      height: auto;
      border-radius: 18px;
    }

    /* ============ PALETTE CARD ============ */
    .palette-card {
      background: transparent;
      border: 0;
      border-radius: 0;
      padding: 0;
      box-shadow: none;
    }

    .palette-grid {
      display: grid;
      gap: 24px;
    }

    


    .extras-title {
      display: block;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1.2px;
      color: #999;
      margin: 0 0 14px 0;
    }

/* ============ COLOR STRIP ============ */
    .color-strip {
      /* Same look as the /palette strip: white background, tight gaps */
      display: flex;
      align-items: stretch;
      gap: 3px;
      padding: 0;
      background: transparent;
      border: 0;
      border-radius: 0;
      width: 100%;
      height: auto;
    }

    .color-swatch {
      flex: 1 1 0;
      min-width: 28px;
      height: 96px;
      border-radius: 12px;
      border: 0;
      box-shadow: none;
      cursor: pointer;
      transition: filter 0.2s ease;
      position: relative;
      overflow: hidden;
    }

    .color-swatch::after {
      content: '';
      position: absolute;
      inset: 0;
      background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, transparent 100%);
      opacity: 0;
      transition: opacity 0.3s ease;
    }

    .color-swatch:hover {
      filter: brightness(1.04);
    }

    .color-swatch:hover::after {
      opacity: 1;
    }

    .color-swatch:active {
      filter: brightness(0.98);
    }

    /* ============ DOWNLOAD BUTTONS (same as /palette) ============ */
    .export-share-buttons {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
    }

    .export-share-btn {
      height: 46px;
      min-width: 102px;
      padding: 0 22px;
      border: 1px solid #e8e8e8;
      border-radius: 14px;
      background: #ffffff;
      color: #111827;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      font-family: inherit;
      font-size: 15px;
      line-height: 1;
      font-weight: 700;
      cursor: pointer;
      white-space: nowrap;
      box-shadow: none;
    }

    .export-share-btn:hover:not(:disabled) {
      background: #f4f5f7;
    }

    .export-share-btn:active:not(:disabled) {
      background: #ffffff;
      box-shadow: inset 0 0 0 1px #e3e3e3;
    }

    .export-share-btn:disabled {
      opacity: 0.4;
      cursor: not-allowed;
    }

    .export-share-btn__icon {
      width: 16px;
      height: 16px;
      display: block;
      flex: 0 0 auto;
    }

    @media (max-width: 640px) {
      .export-share-buttons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
      }

      .export-share-btn {
        width: 100%;
        min-width: 0;
        height: 44px;
        padding: 0 14px;
      }
    }

    /* ============ SHARE PALETTE LINK (same as /palette) ============ */
    .export-share-url {
      height: 46px;
      width: 100%;
      border: 1px solid #e8e8e8;
      border-radius: 14px;
      background: #ffffff;
      display: grid;
      grid-template-columns: auto minmax(0, 1fr) auto;
      align-items: center;
      overflow: hidden;
    }

    .export-share-url__icon {
      width: 18px;
      height: 18px;
      margin-left: 18px;
      display: block;
      flex: 0 0 auto;
    }

    .export-share-url__input {
      min-width: 0;
      width: 100%;
      height: 100%;
      padding: 0 16px;
      border: 0;
      outline: none;
      background: transparent;
      color: #3f4654;
      font-family: inherit;
      font-size: 15px;
      line-height: 1;
      font-weight: 600;
    }

    .export-share-copy {
      height: 100%;
      min-width: 92px;
      padding: 0 22px;
      border: 0;
      border-left: 1px solid #e8e8e8;
      background: #ffffff;
      color: #111827;
      font-family: inherit;
      font-size: 15px;
      line-height: 1;
      font-weight: 700;
      cursor: pointer;
    }

    .export-share-copy:hover {
      background: #f4f5f7;
    }

    .export-share-copy:active {
      background: #ffffff;
      box-shadow: inset 0 0 0 1px #e3e3e3;
    }

    .export-share-link-section {
      margin-top: 26px;
    }

    @media (max-width: 640px) {
      .export-share-link-section {
        margin-top: 20px;
      }

      .export-share-url__icon {
        margin-left: 14px;
      }

      .export-share-url__input {
        padding: 0 12px;
        font-size: 14px;
      }

      .export-share-copy {
        min-width: 0;
        padding: 0 16px;
      }
    }

    /* ============ DOMINANCE BAR ============ */
    .dominance-bar {
      display: flex;
      height: 48px;
      border-radius: 12px;
      overflow: hidden;
      border: 1px solid #e8e8e8;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    }

    .dominance-segment {
      flex: 0 0 auto;
      height: 100%;
      position: relative;
      transition: flex 0.3s ease;
      border-right: 1px solid rgba(255, 255, 255, 0.4);
    }

    .dominance-segment:last-child {
      border-right: none;
    }

    /* ============ EXPORT BUTTONS ============ */
    .export-section {
      margin-top: 24px;
    }

    .export-buttons {
      display: flex;
      gap: 12px;
      flex-wrap: wrap;
    }

    .btn-export {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      height: 44px;
      padding: 0 18px;
      background: white;
      border: 1.5px solid #e8e8e8;
      border-radius: 10px;
      font-size: 13px;
      font-weight: 600;
      color: #1a1a1a;
      cursor: pointer;
      transition: all 0.25s ease;
      white-space: nowrap;
    }

    .btn-export:hover:not(:disabled) {
      background: #f5f5f5;
      border-color: #d8d8d8;
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    .btn-export:active:not(:disabled) {
      transform: translateY(0);
    }

    .btn-export:disabled {
      opacity: 0.4;
      cursor: not-allowed;
    }

    .btn-export svg {
      width: 16px;
      height: 16px;
      opacity: 0.7;
    }

    
    /* ============ CODES HEADER ============ */
    .codes-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
      margin-bottom: 16px;
      width: 100%;
    }

    .codes-sort-links {
      display: flex;
      gap: 0;
      align-items: center;
      margin-left: auto;
    }

    .codes-sort-link {
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1.2px;
      color: #bbb;
      text-decoration: none;
      transition: color 0.2s ease;
    }

    .codes-sort-link:hover {
      color: #666;
    }

    .codes-sort-link.active {
      color: #1a1a1a;
      text-decoration: underline;
      text-underline-offset: 3px;
    }

    .codes-sort-sep {
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1.2px;
      color: #bbb;
      margin: 0 10px;
      user-select: none;
    }

    /* ============ COLOR CODES SECTION (Legacy buttons) ============ */
    .codes-section { margin-top: 28px; }

    /* match old grid behavior */
    .details{
      display:grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 12px;
    }
    @media (max-width: 640px){
      .details{ grid-template-columns: 1fr; }
    }

    .rowCard{
      background: #fff;
      border: 1px solid #e8e8e8;
      border-radius: 14px;
      overflow:hidden;
      cursor: pointer;
      display:grid;
      grid-template-columns: 56px 1fr;
      min-height: 92px;
      transition: all 0.25s ease;
    }
    .rowCard:hover{
      border-color:#d8d8d8;
      box-shadow: 0 10px 24px rgba(0,0,0,0.08);
      transform: translateY(-2px);
    }
    .rowCard:active{ transform: translateY(0); }

    .miniChip{
      border-right: 1px solid #e8e8e8;
      background: #eee;
    }

    .rowBody{
      padding: 12px 14px;
      display:grid;
      gap: 8px;
      align-content:start;
    }

    .rowTop{
      display:flex;
      justify-content: space-between;
      align-items: baseline;
      gap: 10px;
    }
    .idx{
      font-weight: 700;
      color:#7a7a7a;
      font-size: 12px;
    }
    .hint{
      font-size: 12px;
      color:#7a7a7a;
      text-transform: lowercase;
    }

    .codeLine{
      display:flex;
      flex-direction: column;
      gap: 10px;
      flex-wrap: nowrap;
      align-items:flex-start;
    }

    .codeTag{
      display:inline-flex;
      gap: 8px;
      align-items: baseline;
      border: 1px solid #dcdcdc;
      border-radius: 999px;
      padding: 7px 10px;
      background: rgba(0,0,0,.02);
      cursor: pointer;
      user-select:none;
      transition: all 0.2s ease;
      width: fit-content;
      max-width: 100%;
    }
    .codeTag:hover{ background: rgba(0,0,0,.04); border-color:#cfcfcf; }
    .codeTag:active{ transform: translateY(1px); }

    .label{
      font-size: 12px;
      font-weight: 800;
      color:#7a7a7a;
      letter-spacing: .02em;
    }
    .mono{
      font-family: var(--font-mono);
      font-size: 12px;
      font-weight: 700;
      color:#7a7a7a;
    }

    /* hide new cards if still present */
    .codes-grid, .color-card{ all: unset; }


    /* ============ MODAL/* ============ MODAL ============ */
    .modal {
      position: fixed;
      inset: 0;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 20px;
      background: rgba(0, 0, 0, 0.4);
      z-index: 9999;
      backdrop-filter: blur(4px);
    }

    .modal.show {
      display: flex;
    }

    .modal-content {
      background: white;
      border-radius: 24px;
      padding: 40px;
      width: 100%;
      max-width: 800px;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
      max-height: 90vh;
      overflow-y: auto;
    }

    .modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 32px;
      padding-bottom: 20px;
      border-bottom: 1px solid #e8e8e8;
    }

    .modal-title {
      font-size: 24px;
      font-weight: 800;
      color: #1a1a1a;
    }

    .modal-close {
      width: 40px;
      height: 40px;
      border: none;
      background: #f5f5f5;
      border-radius: 10px;
      font-size: 20px;
      cursor: pointer;
      transition: all 0.2s ease;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #1a1a1a;
    }

    .modal-close:hover {
      background: #e8e8e8;
    }

    .modal-body {
      display: grid;
      grid-template-columns: 280px 1fr;
      gap: 40px;
    }

    @media (max-width: 768px) {
      .modal-body {
        grid-template-columns: 1fr;
      }
    }

    /* ============ COLOR WHEEL ============ */
    .wheel-container {
      display: grid;
      gap: 20px;
      justify-items: start;
    }

    .wheel-frame {
      width: 240px;
      height: 240px;
      border-radius: 50%;
      border: 1px solid #e8e8e8;
      background: white;
      overflow: hidden;
      box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    }

    canvas#wheel {
      width: 240px;
      height: 240px;
      display: block;
      cursor: crosshair;
    }

    .value-slider {
      width: 240px;
      display: flex;
      flex-direction: column;
      align-items: stretch;
      gap: 10px;
      padding: 16px 18px;
      background: #f5f5f5;
      border-radius: 12px;
      border: 1px solid #e8e8e8;
      box-shadow: 0 6px 18px rgba(0,0,0,0.06);
    }

    .value-slider label {
      font-size: 13px;
      font-weight: 700;
      color: #1a1a1a;
      text-align: center;
      letter-spacing: 0.02em;
    }

    .value-row{
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 0;
    }

    .value-slider input[type="range"] {
      flex: 1 1 auto;
      height: 4px;
      border: none;
      border-radius: 2px;
      background: #ddd;
      outline: none;
      -webkit-appearance: none;
      appearance: none;
      cursor: pointer;
      min-width: 0;
    }

    .value-slider input[type="range"]::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background: white;
      cursor: pointer;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
      border: 2px solid #1a1a1a;
    }

    .value-slider input[type="range"]::-moz-range-thumb {
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background: white;
      cursor: pointer;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
      border: 2px solid #1a1a1a;
    }

    .value-display {
      font-variant-numeric: tabular-nums;
      font-weight: 800;
      font-size: 14px;
      min-width: 36px;
      text-align: right;
      color: #1a1a1a;
    }

    /* ============ INLINE COLOR PICKER ============ */
    .inline-picker {
      width: 260px;
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    .picker-sv {
      width: 260px;
      height: 260px;
      border-radius: 10px;
      overflow: hidden;
      cursor: crosshair;
      position: relative;
      flex-shrink: 0;
      box-shadow: 0 2px 8px rgba(0,0,0,0.10);
    }
    #pickerSV { display: block; width: 100%; height: 100%; }
    .picker-sv-cursor {
      position: absolute;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      border: 2px solid #fff;
      box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.3);
      transform: translate(-50%, -50%);
      pointer-events: none;
      top: 50%; left: 50%;
    }
    #pickerHue {
      -webkit-appearance: none;
      appearance: none;
      width: 100%;
      height: 16px;
      border-radius: 8px;
      border: none;
      outline: none;
      cursor: pointer;
      background: linear-gradient(to right,
        #ff0000,#ffff00,#00ff00,#00ffff,#0000ff,#ff00ff,#ff0000);
    }
    #pickerHue::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 20px; height: 20px;
      border-radius: 50%;
      background: white;
      border: 2px solid rgba(0,0,0,0.25);
      box-shadow: 0 1px 4px rgba(0,0,0,0.25);
      cursor: pointer;
    }
    #pickerHue::-moz-range-thumb {
      width: 20px; height: 20px;
      border-radius: 50%;
      background: white;
      border: 2px solid rgba(0,0,0,0.25);
      cursor: pointer;
    }
    .picker-rgb-row {
      display: flex;
      gap: 6px;
      align-items: flex-end;
    }
    .picker-rgb-field {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 4px;
    }
    .picker-rgb-input {
      width: 100%;
      height: 34px;
      border: 1.5px solid #e8e8e8;
      border-radius: 8px;
      background: #f9f9f9;
      text-align: center;
      font-size: 13px;
      font-weight: 700;
      font-family: var(--font-mono);
      color: #1a1a1a;
      outline: none;
      transition: border-color 0.2s;
    }
    .picker-rgb-input:focus { border-color: #aaa; background: white; }
    .picker-rgb-label {
      font-size: 11px;
      font-weight: 700;
      color: #999;
      letter-spacing: 0.5px;
    }

    .color-tiles-row {
      display: flex;
      gap: 12px;
    }

    .color-tile {
      flex: 1;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .color-tile-swatch {
      width: 100%;
      height: 64px;
      border-radius: 14px;
      border: 1px solid rgba(0, 0, 0, 0.06);
      background: #fff;
      box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
    }

    .codes-two-col {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 16px;
    }

    .codes-col {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .editor-field-value--static {
      color: #999;
    }

    /* ============ COLOR EDITOR ============ */
    .editor-controls {
      display: grid;
      gap: 20px;
    }

    .editor-field {
      display: grid;
      gap: 12px;
    }

    .editor-field-label {
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 1px;
      color: #999;
    }

    .current-color-swatch {
      width: 100%;
      height: 64px;
      padding: 0;
      border-radius: 14px;
      border: 1px solid rgba(0, 0, 0, 0.06);
      cursor: pointer;
      background: #fff;
      box-shadow: 0 10px 26px rgba(0, 0, 0, 0.08);
      outline: none;
    }

    .current-color-swatch:focus-visible {
      box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.10), 0 10px 26px rgba(0, 0, 0, 0.08);
    }

    .editor-field-value {
      font-size: 13px;
      font-family: var(--font-mono);
      font-weight: 600;
      color: #1a1a1a;
      padding: 10px 12px;
      background: #f5f5f5;
      border-radius: 8px;
      border: 1px solid #e8e8e8;
    }

    .editor-field-value{ cursor: pointer; }
    .editor-field-value:active{ transform: translateY(1px); }


    .editor-actions {
      display: flex;
      gap: 12px;
      margin-top: 20px;
    }

    .btn-modal {
      flex: 1;
      height: 44px;
      background: white;
      border: 1.5px solid #e8e8e8;
      border-radius: 10px;
      font-size: 13px;
      font-weight: 700;
      cursor: pointer;
      transition: all 0.2s ease;
      color: #1a1a1a;
    }

    .btn-modal:hover {
      background: #f5f5f5;
      border-color: #d8d8d8;
    }

    .btn-modal.primary {
      background: #1a1a1a;
      color: white;
      border-color: #1a1a1a;
    }

    .btn-modal.primary:hover {
      background: #333;
      border-color: #333;
    }

    /* ============ TOAST ============ */
    .toast {
      position: fixed;
      left: 50%;
      bottom: 24px;
      transform: translateX(-50%);
      background: #1a1a1a;
      color: white;
      padding: 14px 20px;
      border-radius: 10px;
      font-size: 13px;
      font-weight: 600;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.3s ease;
      z-index: 10000;
      box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    }

    .toast.show {
      opacity: 1;
    }

    /* ============ RESPONSIVE ============ */
    @media (max-width: 768px) {
      .wrap {
        padding: 32px 20px;
      }

      .header-title {
        font-size: 36px;
      }

      .controls {
        row-gap: 12px;
        column-gap: 20px;
      }

      .modal-content {
        padding: 28px;
      }

      .color-strip {
        padding: 0;
        gap: 3px;
      }

      .color-swatch {
        height: 72px;
        border-radius: 12px;
      }

      .codes-grid {
        grid-template-columns: 1fr;
      }
    }

    /* ============ FOOTNOTE ============ */
    .privacy-note{
      margin: 22px 0 0;
      text-align: center;
      font-size: 12px;
      color: #8a8a8a;
      letter-spacing: 0.2px;
      padding-bottom: 30px;
    }

    /* ============ COLOR EDITOR: color name (same as /palette) ============ */
    .color-tile-name {
      text-align: left;
      font-size: 16px;
      font-weight: 800;
      color: #1a1a1a;
      line-height: 1.2;
      min-height: 20px;
      overflow-wrap: anywhere;
    }

/* ============ HEADER LOGO (inline) ============ */
.header-logo {
  height: 1.35em;
  width: auto;
  display: inline-block;
  vertical-align: middle;
  position: relative;
}

/* ============ CARD LABEL MODIFIER ============ */
.card-label--no-mb {
  margin-bottom: 0;
}

/* ============ TOGGLE LABELS ============ */
.toggle-label {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a1a;
}


/* ============ CONTAINER GUTTERS ============ */
/* The base rule keeps a 40px side gutter (content capped at 1400px). The gutter
   shrinks on smaller screens so it stays proportionate. Content is never flush
   against the screen edges at any width. */
@media (max-width: 1024px) {
  .wrap { width: min(1400px, calc(100% - 48px)); }   /* 24px each side */
}
@media (max-width: 640px) {
  .wrap { width: calc(100% - 32px); }                /* 16px each side */
}
@media (max-width: 380px) {
  .wrap { width: calc(100% - 24px); }                /* 12px each side */
}


/* ============================================================
   START SCREEN — fit into a single viewport (footer stays visible)
   Applies only before an image is chosen. Once an image is loaded,
   JS adds body.pfi-has-image and the normal (scrollable) layout returns.
   ============================================================ */
body:not(.pfi-has-image) {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

body:not(.pfi-has-image) .palette-from-image-page {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body:not(.pfi-has-image) .wrap {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  padding: 16px 0;
}

body:not(.pfi-has-image) .pfi-start {
  flex: 1 0 auto;
  min-height: 0;            /* was min(72vh, 780px) — that forced the overflow */
  padding: 20px 0;
}

body:not(.pfi-has-image) .pfi-start-note {
  margin-top: 24px;         /* was 36px */
}

@media (max-width: 768px) {
  body:not(.pfi-has-image) .wrap { padding: 8px 0; }
  body:not(.pfi-has-image) .pfi-start { padding: 12px 0; }
  body:not(.pfi-has-image) .pfi-start-inner { gap: 8px; }
  body:not(.pfi-has-image) .pfi-start-hint { padding-top: 12px; }
  body:not(.pfi-has-image) .pfi-start-note { margin-top: 16px; }
}

/* ===== Мобильный Color Editor: помещается в экран и скроллится внутри ===== */
@media (max-width: 768px) {
  /* Высота по реальной видимой части экрана (без адресной строки браузера) */
  .modal {
    padding: 12px;
    height: 100dvh;
    align-items: center;
  }

  /* Прокрутка происходит внутри самого окна редактора */
  .modal-content {
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* В одну колонку квадрат выбора цвета и ползунок — во всю ширину */
  .wheel-container {
    justify-items: stretch;
  }

  .inline-picker {
    width: 100%;
    max-width: 100%;
  }

  .picker-sv {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    flex-shrink: 1;
  }

  /* Чтобы перетаскивание по квадрату не прокручивало окно */
  .picker-sv,
  #pickerSV {
    touch-action: none;
  }
}
