.wpcp-wrap{
  --wpcp-bg: #ffffff;
  --wpcp-border: rgba(0,0,0,.10);
  --wpcp-shadow: 0 6px 18px rgba(0,0,0,.06);
  --wpcp-radius: 14px;
  --wpcp-gap: 10px;
  --wpcp-font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  max-width:100%;
  font-family: var(--wpcp-font);
}

.wpcp-wrap[data-maxw]:not([data-maxw="0"]) { max-width: var(--wpcp-maxw, 760px); margin-left:auto; margin-right:auto; }
.wpcp-wrap[data-maxw="0"]{ max-width:100%; }
.wpcp-wrap[data-maxw="0"]{ max-width:100%; }
.wpcp-wrap *{ box-sizing:border-box; }

.wpcp-toolbar{
  display:flex;
  flex-wrap:wrap;
  gap: var(--wpcp-gap);
  align-items:center;
  padding: 8px;
  border: 1px solid var(--wpcp-border);
  border-radius: var(--wpcp-radius);
  background: #fff;
  box-shadow: var(--wpcp-shadow);
}

.wpcp-section{
  display:inline-flex;
  align-items:center;
  gap:8px;
}

.wpcp-ibtn{
  appearance:none;
  border: 1px solid var(--wpcp-border);
  background: #fff;
  border-radius: 12px;
  padding: 8px 10px;
  display:inline-flex;
  align-items:center;
  gap:8px;
  cursor:pointer;
  font-weight: 700;
  line-height: 1;
  user-select:none;
  transition: transform .06s ease, background .12s ease, border-color .12s ease;
}
.wpcp-ibtn:hover{ background: rgba(0,0,0,.03); }
.wpcp-ibtn:active{ transform: translateY(1px); }
.wpcp-ibtn.is-active{
  background: rgba(10,132,255,.10);
  border-color: rgba(10,132,255,.35);
}
.wpcp-ibtn.wpcp-ghost{
  background: #fff;
}
.wpcp-ibtn.wpcp-primary{
  background: rgba(10,132,255,.95);
  border-color: rgba(10,132,255,.95);
  color:#fff;
}
.wpcp-ibtn.wpcp-primary:hover{ background: rgba(10,132,255,1); }
.wpcp-ico{ font-size: 16px; }
.wpcp-txt{ font-size: 13px; }

@media (max-width: 520px){
  .wpcp-txt{ display:none; }
  .wpcp-ibtn{ padding: 8px; }
}

.wpcp-controls{
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--wpcp-border);
  border-radius: var(--wpcp-radius);
  background:#fff;
  box-shadow: var(--wpcp-shadow);
}

.wpcp-row{ display:flex; flex-wrap:wrap; gap: 12px; align-items:center; }
.wpcp-row.wpcp-sliders{ display:grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items:center; }
.wpcp-row.wpcp-sliders > *{ width:100%; }
.wpcp-row + .wpcp-row{ margin-top: 10px; }

.wpcp-palette{
  display:flex;
  flex-wrap:wrap;
  gap: 8px;
  align-items:center;
}
.wpcp-swatch{
  width: 26px;
  height: 26px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,.12);
  cursor:pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
}
.wpcp-swatch:active{ transform: translateY(1px); }

.wpcp-colorpick{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  border: 1px solid var(--wpcp-border);
  border-radius: 12px;
  padding: 6px 10px;
  background:#fff;
}
.wpcp-colorpick input{ width: 34px; height: 28px; padding:0; border:0; background:transparent; }

.wpcp-slider, .wpcp-select{ width:100%;
  display:inline-flex;
  align-items:center;
  gap: 10px;
  border: 1px solid var(--wpcp-border);
  border-radius: 12px;
  padding: 6px 10px;
  background:#fff;
}
.wpcp-slider{ width:100%; }
.wpcp-slider input[type="range"]{ width: 100%; }
@media (max-width: 520px){
  .wpcp-slider input[type="range"]{ width: 140px; }
}
.wpcp-label{ font-weight: 800; font-size: 12px; opacity: .8; }

.wpcp-link{
  border:0;
  background: transparent;
  font-weight: 800;
  cursor: pointer;
  padding: 8px 6px;
  opacity: .85;
}
.wpcp-link:hover{ opacity: 1; text-decoration: underline; }

.wpcp-tolerance-wrap{ display:none; }

  50%{ transform: scale(1.08); opacity: 1; }
}

.wpcp-stage{
  width:100%;
  margin-top: 10px;
  border: 1px solid var(--wpcp-border);
  border-radius: var(--wpcp-radius);
  padding: 6px;
  background: #fafafa;
  overflow:hidden;
}

.wpcp-stack{
  position: relative;
  max-height: 75vh;
  width: 100%;
  max-width: 100%;
  aspect-ratio: var(--wpcp-aspect, 16 / 9);
  border-radius: 12px;
  overflow:hidden;
  background:#fff;
}

.wpcp-viewport{
  position:absolute;
  inset:0;
  transform-origin: 0 0;
  touch-action: none;
}
.wpcp-viewport.is-panning{ cursor: grab; }
.wpcp-canvas{ display:block; width:100% !important; height:100% !important; }
.wpcp-bg, .wpcp-layer{ position:absolute; inset:0; }
.wpcp-bg{ z-index:1; }
.wpcp-layer{ z-index:2; cursor: crosshair; }

.wpcp-modal{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 16px;
  z-index: 99999;
}
.wpcp-modal-card{
  width: min(420px, 92vw);
  background:#fff;
  border-radius: 18px;
  border: 1px solid rgba(0,0,0,.10);
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  padding: 16px;
}
.wpcp-modal-title{ font-weight: 900; font-size: 16px; margin-bottom: 6px; }
.wpcp-modal-desc{ opacity: .8; margin-bottom: 14px; }
.wpcp-modal-actions{ display:flex; gap: 10px; justify-content:flex-end; }

/* Fullscreen layout: fit the whole image inside viewport (no cropping) */
.wpcp-wrap:fullscreen{
  background:#fff;
  padding: 10px;
}
.wpcp-wrap:fullscreen .wpcp-stage{
  /* JS sets --wpcp-fs-offset based on actual toolbar+controls height */
  height: calc(100dvh - var(--wpcp-fs-offset, 240px));
  display:flex;
  align-items:center;
  justify-content:center;
}
/* Fallback if dvh unsupported */
@supports not (height: 100dvh){
  .wpcp-wrap:fullscreen .wpcp-stage{ height: calc(100vh - var(--wpcp-fs-offset, 240px)); }
}
.wpcp-wrap:fullscreen .wpcp-stack{
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: var(--wpcp-aspect, 16 / 9);
}
.wpcp-wrap:fullscreen .wpcp-viewport,
.wpcp-wrap:fullscreen .wpcp-bg,
.wpcp-wrap:fullscreen .wpcp-layer{
  width:100% !important;
  height:100% !important;
}
@media (max-width: 520px){
  .wpcp-wrap:fullscreen .wpcp-stage{
    height: calc(100vh - var(--wpcp-fs-offset, 200px));
  }
}


/* Mobile toolbar compact mode */
@media (max-width: 520px){
  .wpcp-toolbar{
    gap: 6px;
    padding: 6px;
  }
  .wpcp-section{
    gap: 6px;
  }
  .wpcp-toolbar{
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .wpcp-toolbar::-webkit-scrollbar{ display:none; }
  .wpcp-ibtn{
    padding: 9px;
    min-width: 40px;
    justify-content:center;
  }
  .wpcp-ico{ font-size: 18px; }
}

/* Prevent page scroll when using fallback fullscreen */
html.wpcp-noscroll, body.wpcp-noscroll{
  overflow:hidden !important;
  height:100%;
}

/* Fallback fullscreen for browsers without Fullscreen API (e.g., iOS Safari) */
.wpcp-wrap.wpcp-fallbackfs{
  position: fixed !important;
  inset: 0 !important;
  z-index: 999999 !important;
  background:#fff;
  padding: 10px;
  max-width: 100% !important;
  margin: 0 !important;
}
.wpcp-wrap.wpcp-fallbackfs .wpcp-stage{
  height: calc(100dvh - var(--wpcp-fs-offset, 240px));
}
@supports not (height: 100dvh){
  .wpcp-wrap.wpcp-fallbackfs .wpcp-stage{ height: calc(100vh - var(--wpcp-fs-offset, 240px)); }
}


/* Fullscreen toolbar: keep single row to avoid eating vertical space */
.wpcp-wrap:fullscreen .wpcp-toolbar,
.wpcp-wrap.wpcp-fallbackfs .wpcp-toolbar{
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.wpcp-wrap:fullscreen .wpcp-toolbar::-webkit-scrollbar,
.wpcp-wrap.wpcp-fallbackfs .wpcp-toolbar::-webkit-scrollbar{ display:none; }


.wpcp-wrap:fullscreen .wpcp-controls,
.wpcp-wrap.wpcp-fallbackfs .wpcp-controls{
  padding: 6px;
}


/* Toolbar color button (label styled as button) */
.wpcp-colorbtn{
  position: relative;
  overflow: hidden;
  cursor: pointer;
}
.wpcp-colorbtn .wpcp-color{
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Mobile: move toolbar to the bottom (inside the plugin) to avoid theme headers hiding it */
@media (max-width: 520px){
  .wpcp-wrap{
    display:flex;
    flex-direction:column;
  }
  .wpcp-toolbar{ order: 3; }
  .wpcp-stage{ order: 2; }
  .wpcp-controls{ order: 1; }

  /* spacing when toolbar is at bottom */
  .wpcp-toolbar{ margin-top: 10px; }
}


/* Ensure toolbars remain visible in fullscreen (mobile + desktop) */
.wpcp-wrap:fullscreen,
.wpcp-wrap.wpcp-fallbackfs{
  display:flex;
  flex-direction:column;
  height: 100dvh;
}
@supports not (height: 100dvh){
  .wpcp-wrap:fullscreen,
  .wpcp-wrap.wpcp-fallbackfs{ height:100vh; }
}
.wpcp-wrap:fullscreen .wpcp-controls,
.wpcp-wrap.wpcp-fallbackfs .wpcp-controls,
.wpcp-wrap:fullscreen .wpcp-toolbar,
.wpcp-wrap.wpcp-fallbackfs .wpcp-toolbar{
  flex: 0 0 auto;
}
.wpcp-wrap:fullscreen .wpcp-stage,
.wpcp-wrap.wpcp-fallbackfs .wpcp-stage{
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 8px;
}
/* Keep toolbar accessible at bottom */
.wpcp-wrap:fullscreen .wpcp-toolbar,
.wpcp-wrap.wpcp-fallbackfs .wpcp-toolbar{
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: 10px;
  background: var(--wpcp-bg, #fff);
  border: 1px solid var(--wpcp-border);
}

/* Mobile (non-fullscreen): move toolbar to bottom and keep it visible */
@media (max-width: 520px){
  .wpcp-wrap{ display:flex; flex-direction:column; }
  .wpcp-stage{ flex: 1 1 auto; min-height: 0; }
  .wpcp-toolbar{
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--wpcp-bg, #fff);
  }
}


/* Pan tool cursor */
.wpcp-wrap.wpcp-is-pan .wpcp-stage{ cursor: grab; }
.wpcp-wrap.wpcp-is-pan .wpcp-stage:active{ cursor: grabbing; }
