/* =====================================================================
   Handtuch-Designer — Redesign "reinzeit frisch"
   Palette: Reinzeit-Grün verfeinert · Typo: Outfit · mobile-first Feinschliff
   Funktions-Kontrakt (IDs, .popover.open, .active, hidden/flex) unverändert.
   ===================================================================== */

:root {
  --ink: #1f2b16;
  --muted: #66755a;
  --brand-900: #1c3a0f;
  --brand-700: #2d5a1b;
  --brand-600: #3d7524;
  --brand-100: #e8f3d9;
  --brand-50: #f3f8ea;
  --lime: #8bc400;
  --lime-600: #7aad00;
  --lime-100: #eef7d6;
  --bg: #f3f6ec;
  --surface: #ffffff;
  --line: #e4e9d9;
  --line-strong: #cfdabd;
  --radius-btn: 0.65rem;
  --radius-pop: 1.1rem;
  --radius-modal: 1.35rem;
  --shadow-pop: 0 14px 44px rgba(28, 58, 15, 0.14), 0 2px 8px rgba(28, 58, 15, 0.05);
  --shadow-float: 0 10px 32px rgba(28, 58, 15, 0.16), 0 2px 6px rgba(28, 58, 15, 0.08);
}

/* ===== Grundgerüst / Viewport ===== */
html, body {
  height: 100vh;
  height: 100dvh;
}
.app-viewport {
  height: 100vh;
  height: 100dvh;
}
body {
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Outfit', 'Helvetica Neue', Arial, sans-serif;
}

button, .tool-btn, .tool-btn-icon, .ctx-btn, .ctx-btn-icon { touch-action: manipulation; }
.canvas-container, .canvas-container canvas { touch-action: none; }

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 1px;
}

a { color: var(--brand-700); }
a:hover { color: var(--brand-600); }

/* ===== Kopfzeile ===== */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  height: 3.25rem;
}
.app-logo { height: 1.9rem; object-fit: contain; }
.header-sep {
  width: 1px;
  height: 1.4rem;
  background: var(--line-strong);
}
.app-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.app-claim {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: auto;
}

/* ===== Werkzeugleiste ===== */
.toolbar {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(28, 58, 15, 0.04);
  scrollbar-width: thin;
  position: relative;
  z-index: 90;
}

.tool-item { position: relative; }

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.48rem 0.75rem;
  border-radius: var(--radius-btn);
  font-size: 0.82rem;
  font-weight: 500;
  color: #3d4a33;
  white-space: nowrap;
  transition: background-color .15s, color .15s, box-shadow .15s;
}
.tool-btn:hover { background: var(--brand-50); color: var(--brand-700); }
.tool-btn:active { background: var(--brand-100); }
.tool-btn .caret { font-size: 0.55rem; color: #a8b39a; margin-left: -1px; }

.tool-btn-primary {
  background: var(--lime);
  color: #fff;
  font-weight: 600;
  border-radius: 999px;
  padding-inline: 1rem;
  box-shadow: 0 3px 10px rgba(139, 196, 0, 0.35);
}
.tool-btn-primary:hover { background: var(--lime-600); color: #fff; }
.tool-btn-primary .caret { color: rgba(255,255,255,.7); }

.tool-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: var(--radius-btn);
  color: #55654a;
  transition: background-color .15s, color .15s;
}
.tool-btn-icon:hover { background: var(--brand-50); color: var(--brand-700); }
.tool-btn-icon:disabled { color: #ccd5c1; cursor: not-allowed; background: transparent; }

.tool-divider {
  width: 1px;
  align-self: stretch;
  margin: 0.3rem 0.4rem;
  background: var(--line);
}

/* ===== Popover ===== */
.popover {
  position: absolute;
  top: calc(100% + 0.55rem);
  left: 0;
  z-index: 95;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pop);
  box-shadow: var(--shadow-pop);
  padding: 1.1rem;
  display: none;
}
.popover.open { display: block; animation: pop-in .16s ease; }
.tool-item:last-of-type .popover,
.popover.align-right { left: auto; right: 0; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.pop-title {
  font-weight: 600;
  color: var(--brand-700);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.55rem;
}
.pop-hint { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.75rem; }
.pop-footer { border-top: 1px solid var(--line); margin-top: 0.75rem; padding-top: 0.75rem; }
.opt-sub { font-size: 10px; font-weight: 500; color: #93a186; }

/* ===== Buttons ===== */
.btn-solid, .btn-solid-soft, .btn-solid-gray, .btn-lime, .btn-outline, .btn-glass {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: var(--radius-btn);
  font-size: 0.85rem;
  font-weight: 600;
  transition: background-color .15s, color .15s, box-shadow .15s, transform .1s;
  white-space: nowrap;
}
.btn-solid { background: var(--brand-700); color: #fff; }
.btn-solid:hover { background: var(--brand-600); }
.btn-solid-soft { background: var(--brand-600); color: #fff; }
.btn-solid-soft:hover { background: var(--brand-700); }
.btn-solid-gray { background: #9aa78e; color: #fff; }
.btn-solid-gray:hover { background: #85937a; }
.btn-lime { background: var(--lime); color: #fff; box-shadow: 0 3px 10px rgba(139,196,0,.3); }
.btn-lime:hover { background: var(--lime-600); }
.btn-outline {
  border: 1px solid var(--line-strong);
  color: #4a573f;
  background: var(--surface);
  font-weight: 500;
}
.btn-outline:hover { background: var(--brand-50); border-color: var(--lime); color: var(--brand-700); }
.btn-ghost-xs {
  font-size: 0.7rem;
  color: #8b987e;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  transition: background-color .15s, color .15s;
}
.btn-ghost-xs:hover { background: var(--brand-50); color: var(--brand-700); }
.btn-glass {
  padding: 0.5rem 1rem;
  background: rgba(255,255,255,.16);
  color: #fff;
  font-weight: 500;
  font-size: 0.85rem;
  backdrop-filter: blur(6px);
  border-radius: 999px;
}
.btn-glass:hover { background: rgba(255,255,255,.28); }

/* Swap-Modus (JS schaltet auf Orange um) */
#btn-swap.bg-orange-500 { background: #f97316 !important; }
#btn-swap.bg-orange-500:hover { background: #ea680c !important; }

/* ===== Formularelemente ===== */
.field {
  border: 1px solid var(--line-strong);
  border-radius: 0.6rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.field:focus {
  outline: none;
  border-color: var(--lime);
  box-shadow: 0 0 0 3px rgba(139, 196, 0, 0.18);
}
.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.font-preview {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  text-align: center;
  color: #4a573f;
  background: var(--brand-50);
  font-size: 1.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.color-well {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.55rem;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  padding: 2px;
  background: var(--surface);
}
.color-well-sm { width: 2.1rem; height: 2.1rem; }

.style-toggle {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 0.55rem;
  border: 1px solid var(--line-strong);
  font-size: 0.85rem;
  color: #66755a;
  transition: background-color .15s, color .15s, border-color .15s;
}
.style-toggle:hover { background: var(--brand-50); }

.swatch-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.swatch {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line-strong), 0 1px 3px rgba(28,58,15,.15);
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.15); }

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--line-strong);
  border-radius: 0.9rem;
  padding: 1.25rem;
  cursor: pointer;
  color: var(--muted);
  transition: border-color .15s, background-color .15s;
}
.upload-zone svg { color: var(--lime); }
.upload-zone:hover { border-color: var(--lime); background: var(--brand-50); }
.upload-zone-full {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 2px dashed var(--lime);
  border-radius: 0.9rem;
  padding: 0.8rem;
  cursor: pointer;
  color: var(--brand-700);
  transition: border-color .15s, background-color .15s;
}
.upload-zone-full svg { color: var(--lime); }
.upload-zone-full:hover { border-color: var(--brand-700); background: var(--brand-50); }

.counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--brand-50);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.5rem 0.75rem;
  color: var(--muted);
}
.counter-btn {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 0.5rem;
  background: #fff;
  border: 1px solid var(--line-strong);
  color: #4a573f;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background-color .15s;
}
.counter-btn:hover { background: var(--brand-100); }
.counter-btn-plus { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }
.counter-btn-plus:hover { background: var(--brand-600); }

.layer-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0;
  border-radius: 0.7rem;
  border: 1px solid var(--line);
  color: #66755a;
  transition: background-color .15s, border-color .15s, color .15s;
}
.layer-btn span { font-size: 10px; color: #93a186; }
.layer-btn:hover { background: var(--brand-50); border-color: var(--lime); color: var(--brand-700); }

.range-brand { accent-color: var(--lime); height: 0.4rem; }

/* Produkt- & Ausrichtungs-Buttons */
.product-btn, .orient-btn {
  border-color: var(--line-strong);
  background: var(--surface);
  color: #5a6950;
}
.product-btn:hover, .orient-btn:hover {
  border-color: var(--lime);
  background: var(--brand-50);
}
.product-btn.active, .orient-btn.active {
  border-color: var(--lime);
  background: var(--brand-100);
  color: var(--brand-700);
  box-shadow: 0 0 0 3px rgba(139, 196, 0, 0.14);
}

/* ===== Bühne / Canvas ===== */
main {
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(139, 196, 0, 0.07), transparent 60%),
    radial-gradient(rgba(45, 90, 27, 0.055) 1px, transparent 1.5px);
  background-size: auto, 22px 22px;
}
#canvas-wrapper {
  display: inline-block;
  box-shadow: 0 22px 55px rgba(28, 58, 15, 0.20), 0 3px 12px rgba(28, 58, 15, 0.08);
}
.canvas-container { border-radius: 0; overflow: hidden; }
.upper-canvas { border-radius: 0; }

/* Zoom-Gruppe */
.zoom-group {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(28, 58, 15, 0.07);
  overflow: hidden;
}
.zoom-btn {
  width: 2.1rem;
  height: 2.1rem;
  color: #4a573f;
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color .15s;
}
.zoom-btn:hover { background: var(--brand-50); }
.zoom-label {
  font-size: 0.8rem;
  color: var(--muted);
  width: 3rem;
  text-align: center;
}
.zoom-reset {
  padding: 0 0.85rem;
  height: 2.1rem;
  font-size: 0.72rem;
  color: var(--muted);
  border-left: 1px solid var(--line);
  transition: background-color .15s, color .15s;
}
.zoom-reset:hover { background: var(--brand-50); color: var(--brand-700); }
.safety-hint { color: #98a58b; }

/* Qualitäts-Ampel */
#quality-indicator.quality-good  { background: var(--brand-100); color: var(--brand-900); }
#quality-indicator.quality-medium { background: #fdf3d1; color: #7d5f0b; }
#quality-indicator.quality-bad   { background: #fde4e4; color: #a02222; }

/* ===== Schwebende Kontext-Leiste ===== */
#context-toolbar {
  position: absolute;
  z-index: 60;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  pointer-events: none;
}
#context-toolbar:not(.hidden) { display: flex; }
#context-toolbar.hidden { display: none; }

.ctx-row {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-float);
  padding: 0.3rem 0.4rem;
  pointer-events: auto;
}

.ctx-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  color: #3d4a33;
  white-space: nowrap;
  transition: background-color .15s, color .15s;
}
.ctx-btn:hover { background: var(--brand-50); color: var(--brand-700); }
.ctx-ai:hover, .ctx-colorize:hover { background: #f3e8ff; color: #7c3aed; }

.ctx-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  color: #55654a;
  transition: background-color .15s, color .15s;
}
.ctx-btn-icon:hover { background: var(--brand-50); color: var(--brand-700); }
.ctx-delete:hover { background: #fee2e2; color: #dc2626; }

.ctx-divider {
  width: 1px;
  height: 1.4rem;
  background: var(--line);
  margin: 0 0.15rem;
}

.ctx-flyout {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pop);
  box-shadow: var(--shadow-float);
  padding: 0.6rem 0.8rem;
  pointer-events: auto;
}
.ctx-flyout.hidden { display: none; }
.flyout-label { font-size: 0.72rem; color: var(--muted); }

/* KI schärfen */
.sharpen-lvl-btn {
  padding: 0.32rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  color: #3d4a33;
  white-space: nowrap;
  transition: background-color .15s, color .15s, border-color .15s;
}
.sharpen-lvl-btn:hover { background: #f3e8ff; color: #7c3aed; }
.sharpen-lvl-btn.active {
  background: #f3e8ff;
  color: #7c3aed;
  border-color: #8b5cf6;
  font-weight: 600;
}
#sharpen-picker.busy .sharpen-lvl-btn { pointer-events: none; opacity: .5; }

.sharpen-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: #8b5cf6;
  border-radius: 50%;
  animation: sharpen-spin .7s linear infinite;
}
@keyframes sharpen-spin { to { transform: rotate(360deg); } }

.ki-pulse { animation: ki-pulse 2s ease-in-out infinite; }
@keyframes ki-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(139, 92, 246, .45); }
  70%  { box-shadow: 0 0 0 6px rgba(139, 92, 246, 0); }
  100% { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0); }
}

/* ===== Modals ===== */
.modal-backdrop { background: rgba(28, 43, 18, 0.45); backdrop-filter: blur(4px); }
.preview-backdrop { background: rgba(16, 26, 10, 0.93); backdrop-filter: blur(4px); }

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-modal);
  box-shadow: 0 24px 70px rgba(16, 26, 10, 0.35);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.modal-title { font-weight: 600; color: var(--ink); font-size: 1.02rem; }
.modal-sub { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.modal-close {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  color: #93a186;
  font-size: 1.25rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color .15s, color .15s;
}
.modal-close:hover { background: var(--brand-50); color: var(--brand-700); }
.modal-foot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--line);
}
.preview-chip {
  padding: 0.4rem 0.8rem;
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.75);
  border-radius: 999px;
  font-size: 0.8rem;
  backdrop-filter: blur(6px);
}

/* ===== Start-Auswahl ===== */
.start-backdrop {
  background:
    radial-gradient(ellipse 70% 55% at 50% 0%, rgba(139, 196, 0, 0.16), transparent 65%),
    linear-gradient(170deg, #f7faf1 0%, #e9f2da 60%, #dfecc9 100%);
}
.start-heading {
  font-size: clamp(1.35rem, 3.5vw, 1.9rem);
  font-weight: 700;
  color: var(--brand-900);
  margin-bottom: 0.35rem;
  letter-spacing: -0.01em;
}
.start-sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 2rem; }

.start-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 1.4rem;
  padding: 1.75rem;
  text-align: left;
  box-shadow: 0 10px 34px rgba(28, 58, 15, 0.10);
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.start-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 48px rgba(28, 58, 15, 0.16);
  border-color: var(--lime);
}
.start-card h3 { font-size: 1.05rem; font-weight: 700; color: var(--brand-700); margin-bottom: 0.3rem; }
.start-card p { font-size: 0.85rem; color: var(--muted); line-height: 1.45; }
.start-card-ai { border: 2px solid var(--lime); }
.start-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 1rem;
  margin-bottom: 0.9rem;
}
.start-icon-green { background: var(--brand-100); color: var(--brand-700); }
.start-icon-lime { background: var(--lime-100); color: var(--lime-600); }
.start-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--lime);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
}
.start-cta {
  display: inline-block;
  margin-top: 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--brand-600);
}
.start-card:hover .start-cta { color: var(--brand-900); }

/* ===== Varianten-Leiste ===== */
.variant-inner {
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 32px rgba(28, 58, 15, 0.12);
}
#variant-bar .variant-inner { border-radius: 1rem 1rem 0 0; }
.variant-title { font-size: 0.85rem; font-weight: 600; color: var(--brand-700); }
.variant-counter { font-size: 0.85rem; color: var(--muted); width: 4rem; text-align: center; }

/* ===== Remaps für JS-generierte Utility-Farben (script.js unangetastet) ===== */
/* Ebenenliste aktiv + B/I/U-Toggles (blau → grün) */
.bg-blue-50  { background-color: var(--brand-50) !important; }
.bg-blue-100 { background-color: var(--brand-100) !important; }
.text-blue-700 { color: var(--brand-700) !important; }
.border-blue-300 { border-color: var(--lime) !important; }
.border-blue-400 { border-color: var(--lime) !important; }

/* Collagen-Modal (indigo → grün) */
.bg-indigo-500 { background-color: var(--brand-600) !important; }
.hover\:bg-indigo-600:hover { background-color: var(--brand-700) !important; }
.bg-indigo-400 { background-color: #5c8f3c !important; }
.hover\:bg-indigo-500:hover { background-color: var(--brand-600) !important; }
.hover\:border-indigo-400:hover { border-color: var(--lime) !important; }

/* Clipart-Tabs (lila → grün) */
#clipart-tabs .bg-purple-100 { background-color: var(--brand-100) !important; }
#clipart-tabs .text-purple-700 { color: var(--brand-700) !important; }
#clipart-tabs .border-purple-300 { border-color: var(--lime) !important; }

/* Zuschneiden-Format-Chips (amber → grün) */
.crop-ratio-btn.bg-amber-100 { background-color: var(--brand-100) !important; }
.crop-ratio-btn.text-amber-700 { color: var(--brand-700) !important; }
.crop-ratio-btn.border-amber-300 { border-color: var(--lime) !important; }

/* ===== KI-Optimierung Animationen ===== */
@keyframes ai-spin { to { transform: rotate(360deg); } }
@keyframes ai-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.7; }
}
@keyframes ai-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.ai-spin { animation: ai-spin 1.2s linear infinite; }
.ai-pulse { animation: ai-pulse 1.8s ease-in-out infinite; }
#ai-progress { background-size: 200% 100%; animation: ai-shimmer 2s linear infinite; }

/* ===== Zuschneiden ===== */
#crop-canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(28, 58, 15, 0.18);
}

/* ===== Cliparts ===== */
.clipart-item:active { transform: scale(0.95); }
.clipart-item svg { width: 100%; height: 100%; }

/* ===== Fotorahmen ===== */
.rahmen-card {
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.rahmen-card:active { cursor: grabbing; }

#frame-drag-ghost {
  position: fixed;
  z-index: 200;
  width: 90px;
  height: 64px;
  pointer-events: none;
  opacity: 0.85;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.3));
}

.frame-thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 40px;
  border: 2px solid transparent;
  border-radius: 0.5rem;
  overflow: hidden;
  transition: border-color .15s;
}
.frame-thumb:hover { border-color: var(--lime); }
.frame-thumb.active { border-color: var(--brand-700); }

.frame-remove-btn {
  flex: 0 0 auto;
  margin-left: 0.35rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  transition: background-color .15s, color .15s;
}
.frame-remove-btn:hover { background: #fee2e2; color: #dc2626; }

#frame-toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%) translateY(10px);
  z-index: 210;
  background: var(--brand-900);
  color: #fff;
  font-size: 0.8rem;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#frame-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Onboarding-Tutorial ===== */
#tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 205;
}
#tutorial-overlay.hidden { display: none; }

#tutorial-spotlight {
  position: absolute;
  top: 0; left: 0; width: 0; height: 0;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(16, 26, 10, 0.6);
  outline: 3px solid var(--lime);
  outline-offset: 2px;
  pointer-events: none;
  transition: top .25s ease, left .25s ease, width .25s ease, height .25s ease, opacity .2s;
}
#tutorial-spotlight.spot-hidden {
  top: 50%; left: 50%; width: 0; height: 0;
  outline-color: transparent;
}

#tutorial-tooltip {
  position: absolute;
  width: 300px;
  max-width: calc(100vw - 24px);
  background: var(--surface);
  border-radius: 1rem;
  box-shadow: 0 14px 40px rgba(16, 26, 10, 0.3);
  padding: 1.05rem 1.15rem 0.95rem;
  pointer-events: auto;
}
#tutorial-tooltip::before {
  content: "";
  position: absolute;
  top: -8px;
  left: var(--arrow-x, 24px);
  width: 16px; height: 16px;
  background: var(--surface);
  transform: rotate(45deg);
  box-shadow: -3px -3px 6px rgba(0, 0, 0, 0.05);
}
#tutorial-tooltip.centered {
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
}
#tutorial-tooltip.centered::before { display: none; }
#tutorial-tooltip.tut-above::before {
  top: auto;
  bottom: -8px;
  box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.05);
}

#tut-counter {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--lime-600);
  margin-bottom: 0.25rem;
}
#tut-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--brand-700);
  margin-bottom: 0.2rem;
}
#tut-text {
  font-size: 0.82rem;
  line-height: 1.4;
  color: #55654a;
  margin-bottom: 0.8rem;
}
.tut-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.tut-actions .tut-spacer { flex: 1; }
.tut-actions button {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.42rem 0.9rem;
  border-radius: 0.6rem;
  transition: background-color .15s, color .15s;
}
#tut-skip {
  color: #a0ac93;
  background: transparent;
  padding-left: 0;
}
#tut-skip:hover { color: #66755a; }
#tut-prev {
  border: 1px solid var(--line-strong);
  color: #4a573f;
  background: var(--surface);
}
#tut-prev:hover { background: var(--brand-50); }
#tut-next {
  background: var(--brand-700);
  color: #fff;
  font-weight: 600;
}
#tut-next:hover { background: var(--brand-600); }
#tut-prev.hidden { display: none; }

/* =====================================================================
   SCHMALER DESKTOP / TABLET (769–1140px): Icon-only, damit nichts überläuft
   ===================================================================== */
@media (min-width: 769px) and (max-width: 1140px) {
  .app-claim { display: none; }
  .tool-btn { padding: 0.48rem 0.55rem; }
  .tool-btn > span:not(.caret) { display: none; }
  .tool-btn svg { width: 1.15rem; height: 1.15rem; }
  .tool-btn-primary { padding-inline: 0.8rem; }
  .tool-btn-primary > span:not(.caret) { display: inline; font-size: 0.78rem; }
}

/* =====================================================================
   MOBILE (<= 768px)
   ===================================================================== */
@media (max-width: 768px) {

  /* Kopfzeile kompakt */
  .app-header { height: 2.6rem; padding-inline: 0.9rem; gap: 0.6rem; }
  .app-logo { height: 1.35rem; }
  .app-title { font-size: 0.82rem; }
  .header-sep { height: 1rem; }

  /* Werkzeugleiste: horizontal scrollbar, App-Gefühl mit Icon über Label.
     backdrop-filter muss hier weg: es macht die Toolbar zum Containing Block
     für position:fixed – die Bottom-Sheet-Popovers würden sonst an der
     Toolbar statt am Viewport ankern (und vom overflow abgeschnitten). */
  .toolbar {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    gap: 0.1rem;
    padding: 0.35rem 0.5rem;
    backdrop-filter: none;
    background: rgba(255, 255, 255, 0.985);
  }
  .toolbar::-webkit-scrollbar { display: none; }

  .tool-btn {
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.4rem 0.55rem;
    min-height: 54px;
    min-width: 58px;
    font-size: 0.66rem;
    font-weight: 500;
    justify-content: center;
  }
  .tool-btn svg { width: 1.25rem; height: 1.25rem; }
  .tool-btn .caret { display: none; }
  .tool-divider { display: none; }

  .tool-btn-icon { width: 2.6rem; height: 2.6rem; min-height: 54px; border-radius: var(--radius-btn); }

  /* PDF-Export bleibt am rechten Rand sichtbar */
  .tool-btn-primary {
    position: sticky;
    right: 0;
    background: var(--lime);
    border-radius: var(--radius-btn);
    box-shadow: -8px 0 12px -6px rgba(28, 58, 15, 0.18), 0 3px 10px rgba(139, 196, 0, 0.35);
  }

  /* Popover als Bottom-Sheet */
  .popover.open {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: auto !important;
    max-height: 72dvh;
    overflow-y: auto;
    border-radius: 1.25rem 1.25rem 0 0;
    border: none;
    z-index: 95;
    box-shadow: 0 -14px 44px rgba(16, 26, 10, 0.3);
    padding: 1.75rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom));
    animation: sheet-up .22s ease;
  }
  .popover.open::before {
    content: "";
    position: absolute;
    top: 0.55rem;
    left: 50%;
    transform: translateX(-50%);
    width: 2.4rem;
    height: 0.28rem;
    border-radius: 999px;
    background: var(--line-strong);
  }

  @keyframes sheet-up {
    from { transform: translateY(14px); opacity: 0.6; }
    to   { transform: translateY(0); opacity: 1; }
  }

  /* Kontext-Leiste am unteren Rand verankern (--ctx-bottom setzt das JS) */
  #context-toolbar {
    position: fixed !important;
    left: 0 !important;
    right: 0;
    bottom: var(--ctx-bottom, 0) !important;
    top: auto !important;
    transform: none !important;
    z-index: 85;
    padding: 0.45rem 0.5rem calc(0.45rem + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(28, 58, 15, 0.12);
    flex-direction: column-reverse;
  }
  #context-toolbar .ctx-row {
    overflow-x: auto;
    box-shadow: none;
    border: none;
    padding: 0;
    border-radius: 0;
    background: transparent;
  }
  #context-toolbar .ctx-row::-webkit-scrollbar { display: none; }
  #context-toolbar .ctx-flyout { flex-wrap: wrap; max-width: none; }
  #frame-picker-row { max-width: none !important; }

  .ctx-btn { padding: 0.5rem 0.6rem; min-height: 44px; }
  .ctx-btn-icon { width: 2.75rem; height: 2.75rem; }

  /* Zoom-Leiste: größere Touch-Ziele */
  .zoom-btn { width: 2.75rem; height: 2.75rem; }
  .zoom-reset { height: 2.75rem; }

  /* Start-Karten kompakter */
  .start-card { padding: 1.25rem; }
  .start-heading { margin-top: 0.25rem; }

  /* Varianten-Leiste kompakter */
  #variant-bar .variant-inner { gap: 0.4rem; padding: 0.5rem 0.6rem; border-radius: 0; }
  #variant-bar button { padding: 0.5rem 0.7rem; font-size: 0.78rem; }

  /* Modal-Köpfe kompakter */
  .modal-head { padding: 0.9rem 1rem; }
  .modal-foot { padding: 0.85rem 1rem; }
}
