* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: Arial, sans-serif;
  background: white;
  /* Seite selbst nicht zoombar (Pinch/Doppeltipp), aber Elemente bleiben bedienbar */
  touch-action: pan-y;
  -webkit-text-size-adjust: 100%;
}

button,
input {
  font: inherit;
  touch-action: manipulation;   /* verhindert Doppeltipp-Zoom auf Buttons */
}

button {
  border: 1px solid black;
  border-radius: 12px;
  padding: 12px 16px;
  background: white;
  color: black;
  box-shadow: none;
}

.screen {
  display: none;
  position: fixed;
  inset: 0;
  background: white;
}

.screen.active { display: block; }
.hidden { display: none !important; }

canvas,
video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  touch-action: none;
}

video { opacity: 0; }

.corner-square {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 40;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid black;
  border-radius: 0;
  background: white;
}

.camera-button {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 30;
  transform: translateX(-50%);
  border: 1px solid black;
  border-radius: 12px;
  padding: 12px 16px;
  background: white;
  color: black;
  box-shadow: none;
}

.photo-button {
  border: 1px solid black;
  border-radius: 12px;
  padding: 12px 16px;
  background: white;
  color: black;
  box-shadow: none;
}

.draw-hint {
  position: fixed;
  left: 50%;
  bottom: 124px;
  z-index: 30;
  margin: 0;
  transform: translateX(-50%);
  padding: 10px 14px;
  /* skaliert mit der Bildschirmbreite, wird nie abgeschnitten */
  font-size: clamp(13px, 5vw, 20px);
  white-space: nowrap;
  max-width: 100vw;
  text-align: center;
}

.tools {
  position: fixed;
  right: 12px;
  top: 72px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.tools input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  width: 48px;
  height: 48px;
  padding: 0;
  overflow: hidden;
  border: 1px solid black;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

.tools input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
  border: 0;
}

.tools input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 999px;
}

.tools input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 999px;
}

/* ── Vertical on/off slider (same look as freeze button) ── */
/* Width matches the 48px colour pickers, height is taller for the slide travel */
.tone-toggle {
  width: 48px;
  height: 88px;
  padding: 5px;
  border: 1px solid black;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  position: relative;
}

.tone-toggle .slider-knob {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: black;
  flex-shrink: 0;
  transition: transform 0.22s ease;
  transform: translateY(0);
}

/* ON: knob slides up (88 - 10 padding - 36 knob = 42px travel) */
.tone-toggle.on .slider-knob {
  transform: translateY(-42px);
}

.tone-toggle .slider-track {
  display: contents;
}

#drawCanvas { pointer-events: none; }
#drawCanvas.active { pointer-events: auto; }

.top-actions {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 40;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.size-picker {
  position: relative;
}

/* Einheitliche Buttons oben rechts: speichern + Formate – identische Optik */
.action-btn {
  height: 38px;
  min-width: 84px;
  padding: 0 14px;
  border: 1px solid black;
  border-radius: 12px;
  background: white;
  color: black;
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
  white-space: nowrap;
}

.size-menu {
  position: absolute;
  top: 46px;
  right: 0;
  display: grid;
  gap: 6px;
  min-width: 120px;
  padding: 8px;
  background: white;
  border: 1px solid black;
  border-radius: 12px;
  z-index: 50;
}

.size-menu button {
  height: 34px;
  padding: 0 10px;
  border: 1px solid black;
  border-radius: 8px;
  background: white;
  font-size: 12px;
  text-align: left;
  display: flex;
  align-items: center;
}

.size-menu button.active {
  background: black;
  color: white;
}

.collage-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border: 1px solid black;
}

#collageCanvas {
  background: white;
  object-fit: contain;
}

.library {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 70px;
  z-index: 30;
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.library img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: white;
  border: 1px solid black;
}

.collage-buttons {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 14px;
  z-index: 30;
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

/* Galerie-Button: oben links als Quadrat neben dem Square */
.galerie-open-button {
  position: fixed;
  top: 14px;
  left: 60px;            /* direkt rechts neben dem 38px-Square (14 + 38 + 8 Abstand) */
  z-index: 40;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid black;
  border-radius: 0;      /* quadratisch wie der Square */
  background: white;
  color: black;
  font-size: 8px;        /* klein genug, dass "galerie" ins Quadrat passt */
  line-height: 1;
  text-align: center;
  letter-spacing: 0.02em;
}

.object-controls {
  display: contents;
}

.fly-cutout {
  position: fixed;
  z-index: 100;
  object-fit: contain;
  pointer-events: none;
  transition: all 0.48s cubic-bezier(.2, .9, .1, 1);
}

@media (orientation: landscape) {
  .collage-stage { transform: translate(-50%, -50%); }

  .library {
    left: 12px;
    right: auto;
    top: 70px;
    bottom: 76px;
    width: 74px;
    flex-direction: column;
  }
}

@media (min-width: 900px) {
  button { padding: 10px 14px; }

  .collage-buttons {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}

/* ── Galerie ── */
.galerie-grid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  touch-action: pan-y;
  background: white;                 /* weißer Hintergrund */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 16px;
  padding: 16px;
  padding-top: 64px;                 /* Platz für den square oben links */
  padding-bottom: 70px;              /* Platz für Pagination */
  align-content: start;
}

.galerie-kachel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;                   /* anklickbar zum Download */
}

/* Bild behält die Proportionen des Collage-Canvas, schwarz umrandet wie die crops */
.galerie-kachel-bild {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
  background: white;
  border: 1px solid black;
}

.galerie-kachel-info {
  width: 100%;
  text-align: center;
}

.galerie-kachel-name {
  font-size: 11px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.galerie-kachel-datum {
  font-size: 10px;
  color: #888;
  margin-top: 1px;
}

.galerie-leer, .galerie-laden, .galerie-fehler {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  font-size: 13px;
  color: #aaa;
}

.galerie-fehler { color: #c00; }

.galerie-pagination {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: white;
  border-top: 1px solid black;
}

.galerie-pagination button {
  padding: 6px 14px;
  font-size: 12px;
  border-radius: 10px;
}

.galerie-pagination button:disabled { opacity: 0.3; }

.galerie-pagination span {
  font-size: 11px;
  color: #888;
}

/* ── Projekt-Namen-Dialog ── */
.name-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.name-dialog {
  background: white;
  border: 1px solid black;
  border-radius: 16px;
  padding: 28px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 280px;
  max-width: 88vw;
}

.name-label {
  font-size: 13px;
  color: black;
}

.name-input {
  border: 1px solid black;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  background: white;
  color: black;
  outline: none;
  width: 100%;
}

.name-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.name-btn { padding: 9px 18px; border-radius: 10px; font-size: 14px; }
.name-btn-primary { background: black; color: white; }

/* ── Toast (kurze Einblendung nach Export) ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%) translateY(20px);
  z-index: 300;
  background: black;
  color: white;
  font-size: 14px;
  padding: 12px 20px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
  max-width: 90vw;
}

.toast-sichtbar {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Download-Auswahl in der Galerie ── */
.wahl-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.wahl-dialog {
  background: white;
  border: 1px solid black;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 260px;
  max-width: 88vw;
}

.wahl-titel {
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wahl-btn {
  height: 44px;
  border: 1px solid black;
  border-radius: 10px;
  background: white;
  color: black;
  font-size: 14px;
}

.wahl-btn-primary { background: black; color: white; }
.wahl-btn-primary:disabled { background: #eee; color: #999; border-color: #ccc; }
.wahl-abbrechen { border: none; color: #888; height: 36px; }
