.converter-container:has(.ape-root) {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1280px;
  padding-top: 30px;
}

.converter-container:has(.ape-root) > .converter-header {
  order: -1;
  margin-bottom: 24px;
}

.converter-container:has(.ape-root) .converter-title {
  font-size: clamp(25px, 3.8vw, 38px);
}

.converter-container:has(.ape-root) .converter-description {
  max-width: 700px;
  font-size: 14px;
  line-height: 1.65;
}

.converter-container:has(.ape-root) .converter-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
}

.converter-container:has(.ape-root) .converter-stamp {
  margin-bottom: 10px;
}

.ape-root {
  width: 100%;
  min-width: 0;
  margin-bottom: 32px;
  overflow: hidden;
  border: 1px solid var(--border-ink);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  box-shadow: var(--float-3);
}

.ape-root *,
.ape-root *::before,
.ape-root *::after,
.ape-dialog *,
.ape-dialog *::before,
.ape-dialog *::after {
  box-sizing: border-box;
}

.ape-root [hidden],
.ape-dialog [hidden] {
  display: none !important;
}

.ape-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 20px;
  min-height: 76px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--paper);
}

.ape-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.3px;
}

.ape-brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: var(--primary);
  color: var(--on-action);
  font-size: 21px;
  font-weight: 750;
  line-height: 1;
}

.ape-brand small {
  display: block;
  margin-top: 1px;
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 450;
  letter-spacing: 0.15px;
}

.ape-brand h2 {
  margin: 0;
  font: inherit;
  font-weight: bolder;
  letter-spacing: inherit;
}

.ape-brand > div > span {
  display: block;
  margin-top: 1px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 450;
  letter-spacing: 0.1px;
}

.ape-topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 7px;
}

.ape-contentsbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-ink);
  background: var(--paper-3);
  color: var(--action-text);
}
.ape-contentsbar > span { flex: 1 1 240px; overflow-wrap: anywhere; }
.ape-contentsbar > div { display: flex; flex-wrap: wrap; gap: 7px; }

.ape-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 13px;
  border: 1px solid var(--border-ink);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, box-shadow 0.16s;
}

.ape-btn:hover:not(:disabled) {
  border-color: var(--primary-light);
  background: var(--paper-3);
}

.ape-btn-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-action);
}

.ape-btn-primary:hover:not(:disabled) {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
}

.ape-btn-icon {
  flex: 0 0 44px;
  width: 44px;
  padding: 10px;
}

.ape-sr-only,
.ape-btn-icon > span {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ape-btn svg,
.ape-tool svg,
.ape-layer-actions svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  stroke-width: 1.7;
}

.ape-root button:disabled,
.ape-dialog button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ape-root button:focus-visible,
.ape-root a:focus-visible,
.ape-dialog button:focus-visible {
  outline: 3px solid var(--primary-light);
  outline-offset: 3px;
}

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

.ape-workspace {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 280px;
  align-items: stretch;
  min-width: 0;
}

.ape-toolbar {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 8px;
  padding: 12px 6px;
  border-right: 1px solid var(--border-soft);
  background: var(--paper);
}

.ape-toolbar .ape-control {
  width: 50px;
  margin-top: 7px;
  gap: 5px;
  text-align: center;
}

.ape-toolbar .ape-control > span {
  justify-content: center;
  font-size: 10px;
}

.ape-toolbar .ape-control input[type="number"] {
  padding-inline: 4px;
  text-align: center;
}

.ape-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  width: 50px;
  min-width: 44px;
  min-height: 58px;
  padding: 8px 3px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 10px;
  font-weight: 550;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.16s, color 0.16s, border-color 0.16s;
}

.ape-tool:hover:not(:disabled) {
  background: var(--paper-2);
  color: var(--ink);
}

.ape-tool[aria-pressed="true"] {
  border-color: var(--border-ink);
  background: var(--paper-3);
  color: var(--action-text);
}

.ape-tool svg {
  width: 21px;
  height: 21px;
}

.ape-stage-area {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--paper-2);
}

.ape-stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  min-height: 54px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--paper-2);
  color: var(--ink-muted);
  font-size: 11px;
}

.ape-document-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ape-stage-header > div {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.ape-stage-actions {
  flex: 0 0 auto;
}

.ape-zoom-label {
  display: flex;
  align-items: center;
  width: 78px;
}

.ape-stage-header input,
.ape-stage-header select {
  max-width: 94px;
}

.ape-stage-scroll {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  height: min(68vh, 680px);
  min-height: 420px;
  padding: 26px;
  overflow: auto;
  overscroll-behavior: contain;
  background-color: var(--dark-paper-3, #f7f5f1);
  background-image: linear-gradient(45deg, var(--dark-paper-deep, #e6e3dd) 25%, transparent 25%),
    linear-gradient(-45deg, var(--dark-paper-deep, #e6e3dd) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--dark-paper-deep, #e6e3dd) 75%),
    linear-gradient(-45deg, transparent 75%, var(--dark-paper-deep, #e6e3dd) 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.ape-stage-scroll.is-dragging,
.ape-stage-scroll.is-dragover {
  outline: 3px solid var(--primary-light);
  outline-offset: -3px;
}

.ape-stage {
  position: relative;
  flex: 0 0 auto;
  margin: auto;
  line-height: 0;
  transform-origin: top left;
  box-shadow: 0 0 0 1px var(--line, #252331), 3px 3px 0 rgba(37, 35, 49, 0.25);
}

.ape-canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  touch-action: none;
  border-radius: 0;
}

.ape-canvas:focus-visible { border-radius: 0; }

.ape-guide-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ape-crop-box {
  position: absolute;
  z-index: 2;
  border: 1px solid #fff;
  outline: 1px solid var(--primary);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 9999px rgba(37, 35, 49, 0.4);
  pointer-events: none;
}

.ape-crop-box::before,
.ape-crop-box::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.ape-crop-box::before {
  inset: 0 33.333%;
  border-right: 1px solid rgba(255, 255, 255, 0.5);
  border-left: 1px solid rgba(255, 255, 255, 0.5);
}

.ape-crop-box::after {
  inset: 33.333% 0;
  border-top: 1px solid rgba(255, 255, 255, 0.5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
}

.ape-empty {
  position: absolute;
  inset: 24px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 15px;
  margin: auto;
  text-align: center;
}

.ape-empty > svg,
.ape-empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  padding: 17px;
  border: 1px solid var(--border-ink);
  border-radius: 18px;
  background: var(--paper);
  color: var(--primary-light);
  box-shadow: var(--float-1);
}

.ape-empty-icon svg {
  width: 28px;
  height: 28px;
}

.ape-empty h2,
.ape-empty h3 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(20px, 2.8vw, 27px);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.8px;
}

.ape-empty p {
  width: 100%;
  max-width: 350px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.7;
}

.ape-empty small {
  color: var(--ink-muted);
  font-size: 11px;
}

.ape-empty > div:not(.ape-empty-icon) {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
}

.ape-inspector {
  min-width: 0;
  border-left: 1px solid var(--border-soft);
  background: var(--paper);
}

.ape-tabs {
  display: flex;
  align-items: stretch;
  gap: 3px;
  min-height: 54px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--paper);
}

.ape-tab {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 8px 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
}

.ape-tab:hover {
  background: var(--paper-2);
  color: var(--ink);
}

.ape-tab[aria-selected="true"],
.ape-tab[aria-pressed="true"],
.ape-tab.is-active {
  border-color: var(--border-soft);
  background: var(--paper-3);
  color: var(--action-text);
}

.ape-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 16px;
}

.ape-panel > p {
  margin: 0;
  color: var(--ink-muted);
  font-size: 11px;
  line-height: 1.65;
}

.ape-panel h3 {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: -0.2px;
}

.ape-panel-hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 11px;
  line-height: 1.65;
}

.ape-panel [data-ape="layer-properties"],
.ape-dialog [data-ape="dialog-body"] {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.ape-panel > .ape-btn {
  width: 100%;
}

.ape-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  color: var(--ink);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: 0.4px;
}

.ape-section-title h3 {
  font-size: 12px;
  letter-spacing: 0;
}

.ape-panel section,
.ape-panel fieldset {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.ape-panel section + section {
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

.ape-control {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.ape-control > label,
.ape-control > span,
.ape-control > legend,
.ape-adjustment > label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 550;
  line-height: 1.4;
}

.ape-root input:not([type="range"]):not([type="checkbox"]):not(.ape-file-input),
.ape-root select,
.ape-root textarea,
.ape-dialog input:not([type="range"]):not([type="checkbox"]),
.ape-dialog select,
.ape-dialog textarea {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--border-ink);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  line-height: 1.4;
}

.ape-root textarea,
.ape-dialog textarea {
  min-height: 86px;
  resize: vertical;
}

.ape-root input[type="color"],
.ape-dialog input[type="color"] {
  height: 40px;
  padding: 4px !important;
  cursor: pointer;
}

.ape-root input[type="range"],
.ape-dialog input[type="range"] {
  width: 100%;
  min-width: 0;
  height: 24px;
  margin: 0;
  padding: 0;
  accent-color: var(--primary-light);
  cursor: pointer;
}

.ape-root input[type="checkbox"],
.ape-dialog input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary-light);
}

.ape-root input:focus-visible,
.ape-root select:focus-visible,
.ape-root textarea:focus-visible,
.ape-dialog input:focus-visible,
.ape-dialog select:focus-visible,
.ape-dialog textarea:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: 2px;
}

.ape-root input:disabled,
.ape-root select:disabled,
.ape-root textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ape-controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.ape-controls-grid .ape-btn {
  width: 100%;
  padding-inline: 8px;
  font-size: 11px;
}

.ape-checkbox {
  align-items: center;
  flex-direction: row;
  gap: 9px;
  min-height: 40px;
  cursor: pointer;
}

.ape-adjustment {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ape-adjustment output {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.ape-layers {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ape-layer-selection-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
}

.ape-layer-selection-bar strong {
  color: var(--primary-light);
  font-size: 11px;
}

.ape-layer-selection-bar > div {
  display: flex;
  gap: 5px;
}

.ape-layer-selection-bar .ape-btn {
  min-height: 34px;
  padding: 5px 9px;
  font-size: 10px;
}

.ape-layer-selection-help {
  margin: 8px 0 10px;
}

.ape-layer-merge-actions {
  margin: 12px 0;
}

.ape-layer-check {
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  min-height: 44px;
  cursor: pointer;
}

.ape-layer-check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary-light);
  cursor: pointer;
}

.ape-layer {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: 59px;
  padding: 4px;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.ape-layer-visibility {
  display: grid;
  place-items: center;
  flex: 0 0 36px;
  width: 36px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--primary-light);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.ape-layer-visibility:hover {
  background: var(--paper-deep);
}

.ape-layer-visibility[aria-pressed="false"] {
  color: var(--ink-muted);
}

.ape-layer-select {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 8px;
  min-width: 0;
  min-height: 48px;
  padding: 4px 3px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.ape-layer-select > span {
  min-width: 0;
}

.ape-layer-thumbnail {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  background: var(--paper);
}

.ape-layer:hover {
  border-color: var(--border-ink);
  background: var(--paper-2);
}

.ape-layer.is-selected,
.ape-layer[aria-selected="true"],
.ape-layer[aria-pressed="true"] {
  border-color: var(--primary-light);
  background: var(--paper-3);
}

.ape-layer.is-active {
  box-shadow: inset 3px 0 0 var(--primary-light);
}

.ape-layer > svg,
.ape-layer > canvas,
.ape-layer > img,
.ape-layer-thumb {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 5px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--paper);
  color: var(--primary-light);
  object-fit: contain;
}

.ape-layer > div:not(.ape-layer-actions) {
  min-width: 0;
}

.ape-layer-name {
  display: block;
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ape-layer-meta {
  display: block;
  margin-top: 2px;
  color: var(--ink-muted);
  font-size: 10px;
  line-height: 1.4;
}

.ape-layer-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.ape-layer-actions .ape-btn {
  flex: 1 1 94px;
  min-width: 0;
  padding: 9px 7px;
}

.ape-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 16px;
  min-height: 38px;
  padding: 9px 16px;
  border-top: 1px solid var(--border-soft);
  background: var(--paper-2);
  color: var(--ink-muted);
  font-size: 10px;
  line-height: 1.5;
}

.ape-statusbar svg {
  width: 13px;
  height: 13px;
  vertical-align: -2px;
}

.ape-error,
.ape-status {
  margin: 0;
  padding: 11px 16px;
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.ape-error {
  border-top: 1px solid var(--error);
  background: var(--error-soft);
  color: var(--error);
}

.ape-status {
  border-top: 1px solid var(--border-soft);
  background: var(--paper-3);
  color: var(--ink-soft);
}

.ape-status:empty,
.ape-error:empty {
  display: none;
}

.ape-dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  margin: auto;
  padding: 24px;
  overflow: auto;
  border: 1px solid var(--border-ink);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  box-shadow: var(--float-4);
}

.ape-dialog::backdrop {
  background: rgba(37, 35, 49, 0.4);
  backdrop-filter: blur(3px);
}

.ape-dialog form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 0;
}

.ape-dialog h2,
.ape-dialog h3 {
  margin: 0;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.5px;
}

.ape-dialog p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.65;
}

.ape-dialog [data-ape="dialog-body"] {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ape-effect-fields {
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
}
.ape-effect-fields legend { padding-inline: 5px; font-weight: 600; }
.ape-effect-fields legend label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.ape-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 5px;
}

@media (max-width: 1100px) {
  .ape-workspace {
    grid-template-columns: 64px minmax(0, 1fr) 258px;
  }

  .ape-topbar {
    padding-inline: 14px;
  }

  .ape-topbar-actions {
    gap: 6px;
  }

  .ape-topbar-actions .ape-btn {
    padding-inline: 10px;
    font-size: 11px;
  }

  .ape-stage-scroll {
    padding: 20px;
  }

  .ape-panel {
    padding-inline: 14px;
  }
}

@media (max-width: 820px) {
  .ape-workspace {
    grid-template-columns: 60px minmax(0, 1fr);
  }

  .ape-inspector {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border-soft);
    border-left: 0;
  }

  .ape-tabs {
    padding-inline: 14px;
  }

  .ape-tab {
    min-height: 44px;
    font-size: 12px;
  }

  .ape-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    padding: 18px;
    gap: 16px 22px;
  }

  .ape-panel > .ape-section-title,
  .ape-panel > p,
  .ape-panel > .ape-layers,
  .ape-panel > .ape-layer-actions {
    grid-column: 1 / -1;
  }

  .ape-panel section + section {
    padding-top: 0;
    border-top: 0;
  }

  .ape-stage-scroll {
    height: min(61vh, 570px);
    min-height: 350px;
  }

  .ape-layers {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .converter-container:has(.ape-root) {
    padding-inline: 12px;
    padding-top: 24px;
  }

  .ape-root {
    border-radius: 14px;
  }

  .ape-topbar {
    align-items: flex-start;
    gap: 12px;
    padding: 14px 12px 12px;
  }

  .ape-brand {
    font-size: 13px;
  }

  .ape-topbar-actions {
    justify-content: flex-start;
    width: 100%;
    gap: 6px;
  }

  .ape-topbar-actions .ape-btn {
    flex: 1 1 auto;
    padding-inline: 9px;
  }

  .ape-topbar-actions .ape-btn-icon {
    flex: 0 0 44px;
  }

  .ape-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .ape-toolbar {
    align-items: stretch;
    justify-content: space-between;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    padding: 7px 9px;
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
  }

  .ape-tool {
    flex: 1 1 44px;
    width: auto;
    min-height: 54px;
    max-width: none;
    font-size: 10px;
  }

  .ape-toolbar .ape-control {
    align-items: center;
    flex: 1 1 calc(50% - 4px);
    flex-direction: row;
    gap: 9px;
    width: auto;
    margin-top: 0;
    padding-inline: 5px;
  }

  .ape-toolbar .ape-control > span {
    flex: 0 0 auto;
  }

  .ape-toolbar .ape-control input {
    min-height: 36px !important;
    height: 36px;
  }

  .ape-stage-header {
    padding-inline: 12px;
    min-height: 51px;
  }

  .ape-stage-scroll {
    height: min(56vh, 450px);
    min-height: 310px;
    padding: 18px;
  }

  .ape-empty {
    inset: 18px;
    gap: 13px;
  }

  .ape-empty h2,
  .ape-empty h3 {
    font-size: 22px;
  }

  .ape-empty p {
    font-size: 12px;
  }

  .ape-inspector {
    grid-column: auto;
  }

  .ape-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 18px 14px;
  }

  .ape-panel > * {
    width: 100%;
  }

  .ape-panel section + section {
    padding-top: 16px;
    border-top: 1px solid var(--border-soft);
  }

  .ape-control input,
  .ape-control select {
    min-height: 44px !important;
  }

  .ape-root input:not([type="range"]):not([type="checkbox"]):not([type="color"]),
  .ape-root select,
  .ape-root textarea,
  .ape-dialog input:not([type="range"]):not([type="checkbox"]):not([type="color"]),
  .ape-dialog select {
    font-size: 16px;
  }

  .ape-layers {
    display: flex;
  }

  .ape-statusbar {
    justify-content: flex-start;
    padding-inline: 12px;
  }

  .ape-dialog {
    padding: 21px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ape-root *,
  .ape-root *::before,
  .ape-root *::after,
  .ape-dialog * {
    transition: none !important;
  }
}

.ape-menubar {
  display: flex;
  gap: 3px;
  padding: 5px 12px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--paper);
}
.ape-menu { position: relative; }
.ape-menu > summary {
  list-style: none;
  padding: 7px 13px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.ape-menu > summary::-webkit-details-marker { display: none; }
.ape-menu[open] > summary, .ape-menu > summary:hover { background: var(--paper-3); }
.ape-menu-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  width: 235px;
  max-height: min(65vh, 480px);
  overflow: auto;
  padding: 7px;
  border: 1px solid var(--border-ink);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--float-3);
}
.ape-menu-panel .ape-btn {
  display: flex;
  justify-content: flex-start;
  width: 100%;
  min-height: 36px;
  padding: 8px 11px;
  border-color: transparent;
  font-size: 12px;
}
.ape-optionsbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--paper-2);
  font-size: 11px;
}
.ape-tool-description { flex: 1 1 250px; color: var(--ink-soft); }
.ape-optionsbar > label { display: flex; align-items: center; gap: 7px; }
.ape-optionsbar select { width: auto; min-height: 32px; padding: 4px 7px; font-size: 11px; }
.ape-optionsbar input[type="number"] { width: 57px; min-height: 32px; padding: 4px 6px; font-size: 11px; }
.ape-optionsbar input[type="color"] { width: 38px; height: 32px; min-height: 32px; padding: 3px; }
.ape-workspace {
  grid-template-columns: 116px minmax(0, 1fr) 280px;
  height: min(76vh, 820px);
  min-height: 650px;
}
.ape-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  align-content: start;
  overflow: auto;
}
.ape-tool { width: 48px; min-height: 52px; padding-block: 5px; }
.ape-toolbar .ape-control { grid-column: 1 / -1; width: auto; flex-direction: row; align-items: center; }
.ape-toolbar .ape-control input { min-width: 0; }
.ape-stage-scroll { height: auto; min-height: 0; }
.ape-inspector { min-height: 0; overflow: auto; }
.ape-tabs { position: sticky; top: 0; z-index: 3; background: var(--paper); }
.ape-mask-controls { margin-block: 12px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.ape-layer[hidden] { display: none; }
.ape-warp-grid { width: 100%; height: auto; border: 1px solid var(--border-soft); border-radius: 12px; touch-action: none; margin-block: 12px; }
.ape-warp-point { min-width: 0; grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; border: 1px solid var(--border-soft); border-radius: 10px; padding: 10px; }
.ape-warp-point[hidden] { display: none; }
.ape-warp-point legend { font-size: 12px; color: var(--ink-muted); }
.ape-root:fullscreen .ape-workspace { height: calc(100dvh - 212px); min-height: 0; }
@media (max-width: 820px) {
  .ape-workspace { grid-template-columns: 116px minmax(0, 1fr); height: auto; min-height: 0; }
  .ape-stage-scroll { height: min(61vh, 570px); min-height: 350px; }
  .ape-inspector { overflow: visible; }
}
@media (max-width: 560px) {
  .ape-menubar { justify-content: space-between; padding-inline: 7px; }
  .ape-menu > summary { padding: 7px 9px; font-size: 12px; }
  .ape-menu:nth-last-child(-n+2) .ape-menu-panel { left: auto; right: 0; }
  .ape-optionsbar { gap: 8px; padding: 10px 12px; }
  .ape-tool-description { flex-basis: 100%; }
  .ape-optionsbar > label { flex: 1 1 calc(50% - 8px); min-width: 0; justify-content: space-between; }
  .ape-optionsbar input[type="number"], .ape-optionsbar select { font-size: 16px; min-height: 36px; }
  .ape-workspace { grid-template-columns: minmax(0, 1fr); }
  .ape-toolbar { display: flex; overflow: visible; }
  .ape-tool { flex: 1 1 50px; width: auto; }
  .ape-toolbar .ape-control { flex: 1 1 calc(50% - 5px); }
  .ape-stage-scroll { height: min(56vh, 450px); min-height: 310px; }
}

/* Paper, pastel panels, and ink outlines shared with the sprite workspace. */
.ape-root,
.ape-dialog {
  color-scheme: light;
  border: 2px solid var(--line, #252331);
  border-radius: 10px;
  background: var(--paper, #fffef9);
  box-shadow: 4px 4px 0 var(--shade, #252331);
}
.ape-topbar { background: var(--pastel-lavender, #d9caff); border-bottom: 2px solid var(--line, #252331); }
.ape-brand { font-weight: 800; letter-spacing: -0.035em; }
.ape-brand-mark { border: 1.5px solid var(--line, #252331); border-radius: 5px; box-shadow: 2px 2px 0 var(--shade, #252331); }
.ape-menubar { background: var(--paper, #fffef9); border-bottom: 1.5px solid var(--line, #252331); }
.ape-optionsbar { background: var(--yellow-tint, #fff6cd); border-bottom: 1.5px solid var(--line, #252331); }
.ape-contentsbar { background: var(--blue-wash, #edf9ff); color: var(--ink, #252331); border-bottom: 1.5px solid var(--line, #252331); }
.ape-toolbar { background: var(--paper, #fffef9); border-right-color: var(--line, #252331); }
.ape-stage-header { background: var(--pastel-blue, #8bd8ff); border-bottom: 1.5px solid var(--line, #252331); color: var(--ink, #252331); }
.ape-document-name { color: var(--ink, #252331); font-weight: 750; }
.ape-inspector { border-color: var(--line, #252331); }
.ape-tabs { background: var(--pastel-pink, #ffbbcb); border-bottom: 1.5px solid var(--line, #252331); }
.ape-tab { border-radius: 5px; color: var(--ink, #252331); }
.ape-tab[aria-selected="true"],
.ape-tab[aria-pressed="true"],
.ape-tab.is-active { border: 1.5px solid var(--line, #252331); background: var(--paper, #fffef9); color: var(--ink, #252331); box-shadow: 2px 2px 0 var(--shade, #252331); }
.ape-statusbar { background: var(--action-tint, #f0eaff); border-top: 1.5px solid var(--line, #252331); }
.ape-panel h3 { font-weight: 800; letter-spacing: -0.025em; }
.ape-btn {
  border: 1.5px solid var(--line, #252331);
  border-radius: 5px;
  font-weight: 700;
  box-shadow: 2px 2px 0 var(--shade, #252331);
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.ape-btn:hover:not(:disabled) { border-color: var(--line, #252331); background: var(--pastel-yellow, #ffe57e); transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--shade, #252331); }
.ape-btn-primary { background: var(--primary, #7046cf); color: #fff; }
.ape-btn-primary:hover:not(:disabled) { border-color: var(--line, #252331); background: var(--primary-dark, #5c32b6); color: #fff; }
.ape-btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.ape-btn:disabled { box-shadow: none; }
.ape-tool { border-radius: 5px; }
.ape-tool[aria-pressed="true"] { border: 1.5px solid var(--line, #252331); background: var(--pastel-yellow, #ffe57e); color: var(--ink, #252331); box-shadow: 2px 2px 0 var(--shade, #252331); }
.ape-tool:hover:not(:disabled) { background: var(--yellow-tint, #fff6cd); }
.ape-empty > svg,
.ape-empty-icon { border: 2px solid var(--line, #252331); border-radius: 8px; background: var(--pastel-green, #c6edab); color: var(--ink, #252331); box-shadow: 3px 3px 0 var(--shade, #252331); }
.ape-empty h2,
.ape-empty h3 { font-weight: 800; letter-spacing: -0.04em; }
.ape-root input:not([type="range"]):not([type="checkbox"]):not(.ape-file-input),
.ape-root select,
.ape-root textarea,
.ape-dialog input:not([type="range"]):not([type="checkbox"]),
.ape-dialog select,
.ape-dialog textarea { border: 1.5px solid var(--line, #252331); border-radius: 5px; }
.ape-layer { border: 1.5px solid var(--line, #252331); border-radius: 5px; }
.ape-layer.is-selected,
.ape-layer[aria-selected="true"],
.ape-layer[aria-pressed="true"] { border-color: var(--line, #252331); background: var(--action-tint, #f0eaff); }
.ape-layer.is-active { box-shadow: inset 3px 0 0 var(--primary, #7046cf); }
.ape-menu-panel { border: 2px solid var(--line, #252331); border-radius: 6px; box-shadow: 3px 3px 0 var(--shade, #252331); }
.ape-menu-panel .ape-btn { box-shadow: none; transform: none; }
.ape-effect-fields,
.ape-warp-point,
.ape-warp-grid { border-color: var(--line, #252331); border-radius: 6px; }
.ape-dialog h2,
.ape-dialog h3 { font-weight: 800; }
.ape-root:fullscreen { border-radius: 0; box-shadow: none; }

@media (max-width: 560px) {
  .ape-toolbar { border-bottom-color: var(--line, #252331); }
}

/* Space the page holds for this view until it mounts (see .tool-view-placeholder in _workspace.css).
   Each height is a little under the space the view takes at that width, measured as how far the
   content below moves when the view replaces the placeholder, so nothing below it moves. Re-measure
   after changing the view's layout: node scripts/measure-tool-views.js --apply advanced-photo-editor. */
.tool-view-placeholder[data-tool="advanced-photo-editor"] { min-height: 906px; }
@media (max-width: 1200px) { .tool-view-placeholder[data-tool="advanced-photo-editor"] { min-height: 946px; } }
@media (max-width: 820px) { .tool-view-placeholder[data-tool="advanced-photo-editor"] { min-height: 1400px; } }
@media (max-width: 620px) { .tool-view-placeholder[data-tool="advanced-photo-editor"] { min-height: 1564px; } }
@media (max-height: 639px) { .tool-view-placeholder[data-tool="advanced-photo-editor"] { min-height: 300px; } }
