.ig-mask-refiner {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100%;
  height: 100dvh;
  background: var(--surface);
  color: var(--ink);
  font: 500 14px/1.4 Inter, system-ui, sans-serif;
}
.ig-mask-refiner-head {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.ig-mask-refiner-head > div:first-child { display: grid; gap: 2px; }
.ig-mask-refiner-head strong { font-size: 1rem; }
.ig-mask-refiner-head span { font-size: .78rem; color: var(--muted); }
.ig-mask-refiner-head-actions,
.ig-mask-refiner-history { display: flex; gap: 8px; flex-wrap: wrap; }
.ig-mask-refiner-head-actions { gap: 4px; }
.ig-mask-refiner button {
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--control);
  color: var(--ink-soft);
  font: 700 inherit;
  cursor: pointer;
}
.ig-mask-refiner button:hover:not(:disabled) { color: var(--brand); border-color: var(--brand); }
.ig-mask-refiner button.primary { color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); border-color: transparent; box-shadow: 0 6px 16px rgba(109,94,252,.28); }
.ig-mask-refiner-head-actions .ig-editor-header-button { width: 40px; min-width: 40px; height: 40px; min-height: 40px; padding: 0; }
.ig-mask-refiner-head-actions .ig-editor-header-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ig-mask-refiner-modes button.on { color: var(--brand); background: color-mix(in srgb, var(--brand) 13%, var(--surface)); border-color: color-mix(in srgb, var(--brand) 38%, var(--line)); }
.ig-mask-refiner button:disabled { opacity: .42; cursor: not-allowed; }
.ig-mask-refiner-body {
  min-height: 0;
  display: grid;
  grid-template-columns: 88px 280px 1fr;
}
.ig-mask-refiner-modes {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.ig-mask-refiner-modes button { padding: 7px 3px; font-size: .68rem; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.ig-mask-refiner-modes button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ig-mask-refiner-controls {
  padding: 18px;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  align-content: start;
  gap: 18px;
}
.ig-mask-refiner-controls label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  color: var(--ink-soft);
}
.ig-mask-refiner-controls input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: #8175ff;
}
.ig-mask-refiner-controls p { margin: 0; color: var(--muted); font-size: .78rem; }
.ig-mask-refiner-view {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
}
.ig-mask-refiner-view button { grid-column: 1 / -1; }
.ig-mask-refiner-history button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.ig-mask-refiner-history svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ig-mask-refiner-stage {
  grid-column: 3;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background-color: var(--dropzone);
  background-image:
    linear-gradient(45deg, rgba(128,128,145,.13) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(128,128,145,.13) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(128,128,145,.13) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(128,128,145,.13) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
.ig-mask-refiner canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 16px 50px #0008;
  border-radius: 10px;
  touch-action: none;
  cursor: none;
  transform-origin: center;
  will-change: transform;
}
.ig-mask-refiner canvas.is-pan-mode { cursor: grab; }
.ig-mask-refiner canvas.is-panning { cursor: grabbing; }
.ig-mask-brush-cursor {
  position: fixed;
  z-index: 4;
  display: block;
  border: 2px solid #fff;
  border-radius: 50%;
  background: rgba(109, 94, 252, .18);
  box-shadow: 0 0 0 1px rgba(15, 17, 24, .82), 0 1px 5px #0009;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.ig-mask-brush-cursor[hidden] { display: none; }
.ig-mask-refiner-history button:last-child { flex-basis: 100%; }

@media (max-width: 640px) {
  .ig-mask-refiner-head { min-height: 56px; padding: 8px 10px; }
  .ig-mask-refiner-head span { display: none; }
  .ig-mask-refiner-head-actions button { min-height: 40px; padding: 7px 10px; }
  .ig-mask-refiner-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) min(210px, 38dvh) auto;
  }
  .ig-mask-refiner-stage { grid-column: 1; grid-row: 1; padding: 10px; }
  .ig-mask-refiner-controls {
    grid-column: 1;
    grid-row: 2;
    border-right: 0;
    border-top: 1px solid var(--line);
    padding: 10px 12px;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    overflow: auto;
  }
  .ig-mask-refiner-modes {
    grid-column: 1;
    grid-row: 3;
    min-height: 58px;
    padding: 7px max(10px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    border: 0;
    border-top: 1px solid var(--line);
    flex-direction: row;
    justify-content: center;
  }
  .ig-mask-refiner-modes button { min-width: 96px; flex: 1 1 0; }
  .ig-mask-refiner-history,
  .ig-mask-refiner-controls p { grid-column: 1 / -1; }
  .ig-mask-refiner-history { justify-content: center; }
  .ig-mask-refiner-history button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
  }
  .ig-mask-refiner-history button:last-child { flex-basis: auto; }
  .ig-mask-refiner-history button span { display: none; }
  .ig-mask-refiner-view { grid-column: 1 / -1; grid-template-columns: auto auto 1fr; align-content: start; }
  .ig-mask-refiner-view button { grid-column: auto; justify-self: end; min-width: 76px; min-height: 34px; padding: 5px 10px; }
  .ig-mask-refiner-controls p { font-size: .72rem; }
}
