/* === Screenshot editor (public/image-editor.js) ======================== */

#modal-image-editor { z-index: calc(var(--z-modal) + 3); }

/* Fixed height: the dialog never resizes while drawing or switching tools. */
#modal-image-editor .ie-card {
  max-width: min(1100px, 100%);
  height: min(88dvh, 860px);
  max-height: min(88dvh, 860px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ie-toolbar-wrap { position: relative; }
.ie-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  /* Sideways scrolling clips vertically too: the top padding keeps borders
     and focus rings of the buttons whole. */
  padding: 4px 2px 0.75rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.ie-toolbar::-webkit-scrollbar { display: none; }
.ie-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  padding-right: 0.5rem;
  border-right: 1px solid var(--border);
}
.ie-group:last-child { padding-right: 0; border-right: 0; }

.ie-btn {
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: var(--transition-ui);
}
.ie-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
html:not(.using-touch) .ie-btn:not(:disabled):hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.ie-btn:focus-visible,
.ie-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Touch-only bump to the app's 44px --touch-target: the toolbar is already
   built to scroll horizontally on mobile (see the arrow-button overflow
   handling), so growing the buttons there doesn't break the desktop row. */
@media (hover: none) and (pointer: coarse) {
  .ie-btn, .ie-swatch { min-width: var(--touch-target); min-height: var(--touch-target); }
}

.ie-swatch {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
}
.ie-swatch::before {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: var(--ie-swatch);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.28);
}
.ie-swatch[aria-pressed="true"] { border-color: var(--text); }

.ie-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  margin-bottom: 0.75rem;
  border-radius: var(--radius);
  background: repeating-conic-gradient(#1b1b1b 0% 25%, #222 0% 50%) 50% / 20px 20px;
  overflow: hidden;
}
.ie-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
.ie-stage[data-tool="crop"] canvas { cursor: move; }
.ie-stage[data-tool="text"] canvas { cursor: text; }

.ie-text-input {
  position: absolute;
  z-index: 1;
  min-width: 8ch;
  max-width: calc(100% - 1rem);
  padding: 0.1em 0.3em;
  transform: translateY(-50%);
  border: 1px dashed rgba(255,255,255,0.75);
  border-radius: 4px;
  background: rgba(0,0,0,0.45);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  outline: none;
}

.ie-hint {
  position: absolute;
  left: 50%;
  bottom: 0.6rem;
  max-width: calc(100% - 1.5rem);
  margin: 0;
  padding: 0.3rem 0.7rem;
  transform: translateX(-50%);
  border-radius: var(--radius-pill);
  background: rgba(0,0,0,0.62);
  color: #fff;
  font-size: var(--text-xs);
  text-align: center;
  pointer-events: none;
}

.ie-actions { flex-shrink: 0; }

/* Edge arrows while more tools are hidden to the left or right. */
.ie-scroll {
  position: absolute;
  top: 4px;
  bottom: 0.75rem;
  z-index: 1;
  width: 2.6rem;
  display: none;
  align-items: center;
  padding: 0;
  border: 0;
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.ie-scroll.is-left {
  left: 0;
  justify-content: flex-start;
  padding-left: 0.2rem;
  background: linear-gradient(to right, var(--surface) 45%, transparent);
}
.ie-scroll.is-right {
  right: 0;
  justify-content: flex-end;
  padding-right: 0.2rem;
  background: linear-gradient(to left, var(--surface) 45%, transparent);
}
.ie-toolbar-wrap.can-scroll-left .ie-scroll.is-left,
.ie-toolbar-wrap.can-scroll-right .ie-scroll.is-right { display: flex; }

/* R5-Tablet: Sheet-Höhe nur auf dem Handy; Tablet hochkant nimmt den festen
   Desktop-Rahmen oben (zentrierter Dialog, siehe Sheet-Block in styles.css). */
@media (max-width: 540px) {
  #modal-image-editor .ie-card {
    height: min(88dvh, calc(100dvh - max(3.75rem, calc(env(safe-area-inset-top, 0px) + 2.75rem)) - env(safe-area-inset-bottom, 0px) - 0.5rem));
    max-height: none;
  }
  .ie-stage { margin-inline: -0.5rem; }
}

/* D14: Die Tool-Labels wurden bis 820px ausgeblendet, obwohl der Kommentar
   "Icons only on phones" sagt — das betraf auch iPad Mini Portrait (768px),
   wo reichlich Platz ist. 600px ist die Phone-Grenze der App. */
@media (max-width: 600px) {
  /* Icons only on phones; the buttons keep their aria-label. */
  .ie-tool span { display: none; }
}

/* "Zurück" keeps its label on every width: it is the way back to the start. */
.ie-undo span { display: inline; }

/* Bin next to a selected mark */
.ie-delete {
  position: absolute;
  z-index: 2;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--danger) 88%, #000);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.45);
  cursor: pointer;
}
.ie-delete:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* R4 Modals/Touch: Werkzeuge, Farben, Pfeile und Papierkorb hatten keinerlei
   Druck-Rückmeldung — der Tipp war erst am Ergebnis zu erkennen. Einwärts wie
   die Chips der App; der Maus-Hover setzt kein transform, daher kein
   zweiter Maus-Tier nötig. */
.ie-swatch,
.ie-delete { transition: transform var(--transition-fast); }
.ie-btn:not(:disabled):active,
.ie-swatch:active,
.ie-delete:active {
  transform: scale(0.92);
  transition-duration: var(--motion-xs);
}
.ie-scroll:active { opacity: 0.6; }
/* Eigener Druck → keine zusätzliche generische Dimmung (--press-opacity, Agent „Global“). */
.ie-btn:active,
.ie-swatch:active,
.ie-delete:active,
.ie-scroll:active { --press-opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .ie-btn:not(:disabled):active,
  .ie-swatch:active,
  .ie-delete:active { transform: none; }
}
