/* ---------------------------------------------------------
   Sticker Konfigurator — Styles
   --------------------------------------------------------- */

:root {
  --color-bg: #ffffff;
  --color-surface: #ffffff;
  --color-border: #e4e0d8;
  --color-border-strong: #d7d1c4;
  --color-text: #211d18;
  --color-text-muted: #7a7468;
  --color-accent: #211d18;
  --color-accent-soft: rgba(33, 29, 24, 0.06);

  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --header-height: 130px; /* doppelt so groß wie der ursprüngliche ~65px-Header */

  /* Konturstärke/-farbe der Sticker-Formen (siehe .sticker-shape) — wird auch für die
     Spaltentrennlinien wiederverwendet, damit beide optisch exakt zusammenpassen. */
  --contour-width: 2pt;
  --contour-color: #000;
  --column-divider: var(--contour-width) solid var(--contour-color);

  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Avenir Next", sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

button:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ---------- Layout ---------- */

.app {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header header"
    "sidebar list composition";
  min-height: 100vh;
}

.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: var(--header-height);
  padding: 0 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  overflow: hidden;
  position: relative;
}

/* Die Wortmarke ist selbst eine kleine, aus echten Sticker-Bausteinen (Form + Farbe + Kontur +
   Text) zusammengesetzte Komposition — siehe renderWordmark() in app.js. Kein separates Icon. */
.wordmark {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 0;
  flex: none;
  transform: scale(1.8);
  transform-origin: center center;
}

/* Jede Sticker-Form der Wortmarke wackelt für sich minimal — die negativen Delays versetzen die
   drei Formen in unterschiedliche Phasen desselben Zyklus, damit sie nicht synchron kippen. */
@keyframes wordmark-wobble {
  0%,
  100% {
    transform: rotate(-2.5deg);
  }
  50% {
    transform: rotate(2.5deg);
  }
}

.wordmark-part {
  transform-origin: center center;
  animation: wordmark-wobble 6s ease-in-out infinite;
}

.wordmark-part:nth-child(2) {
  animation-delay: -2s;
}

.wordmark-part:nth-child(3) {
  animation-delay: -4s;
}

@media (prefers-reduced-motion: reduce) {
  .wordmark-part {
    animation: none;
  }
}

.sidebar {
  grid-area: sidebar;
  background: var(--color-surface);
  border-right: var(--column-divider);
  padding: 24px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  overflow-y: auto;
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
}

.sticker-list {
  grid-area: list;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: var(--column-divider);
  overflow-y: auto;
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
}

.sticker-cards {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  /* Füllt die Spalte bis zum Tipp-Text — nötig, damit der leere Zustand unten (.empty-state)
     sich per margin:auto im übrigen Platz vertikal zentrieren kann, siehe dort. */
  flex: 1;
}

/* Zentriert sich im nach dem Bild-Sticker verbleibenden Platz der Spalte — analog zu
   .composition-empty, damit beide Leer-Hinweise auf gleicher Höhe/Größe erscheinen. */
.empty-state {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px;
  margin-top: auto;
  margin-bottom: auto;
}

.composition-panel {
  grid-area: composition;
  background: var(--color-surface);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
}

/* Gemeinsamer Header-Balken (Titel + optionaler Aktions-Button) für Style- und
   Komposition-Spalte. */
.column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.column-title {
  font-size: 1.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  color: var(--color-text);
  margin: 0;
}

/* ---------- Button-System ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  background: #000;
  color: #fff;
  transition: transform 0.12s ease, background 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #2a2a2a;
  transform: translateY(-1px);
}

.btn:disabled {
  cursor: not-allowed;
  pointer-events: none;
}

.btn-icon {
  display: inline-flex;
  flex: none;
  width: 16px;
  height: 16px;
}

.btn-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Kleinere, sekundäre Variante — für Aktions-Buttons neben einem Spaltentitel statt
   volle Breite/Größe wie z.B. der primäre Export-Button. */
.btn--secondary {
  padding: 8px 18px;
  font-size: 0.8rem;
}

.composition-canvas {
  position: relative;
  flex: 1;
  min-height: 280px;
  border-radius: var(--radius-lg);
  background: #fff;
  border: 1.5px solid var(--color-border);
  overflow: hidden;
}

.composition-group {
  position: absolute;
  left: 50%;
  top: 50%;
}

.composition-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px;
}

#export-btn {
  width: 100%;
  padding: 14px 20px;
  font-size: 0.95rem;
}

#export-btn .btn-icon {
  width: 18px;
  height: 18px;
}

/* ---------- Controls ---------- */

.hint {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin: -2px 0 4px;
}

.hint--tip {
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  line-height: 1.45;
}

/* Dockt den Tipp an den unteren Rand der (auf Desktop) auf Viewport-Höhe fixierten, sticky
   Spalte an — Sidebar und Sticker-Liste scrollen bei Überlänge intern statt die Seite zu
   strecken, siehe .sidebar/.sticker-list. */
.sidebar .hint--tip,
.sticker-list .hint--tip {
  margin-top: auto;
}

#sticker-text {
  flex: 1;
  resize: vertical;
  min-height: 140px;
  padding: 12px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#sticker-text:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(33, 29, 24, 0.08);
}

/* ---------- Sticker card ---------- */

.sticker-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 100%;
}

.sticker-shape-wrapper {
  position: relative;
  /* Breite/Höhe werden inline gesetzt (js/stickerCard.js) — die Karte wächst mit dem Text. */
  transition: transform 0.15s ease;
}

.sticker-card:hover .sticker-shape-wrapper {
  transform: translateY(-2px);
}

.sticker-shape-wrapper svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

/* Überschreibt position:relative von .sticker-shape-wrapper für die Komposition — auf dem
   Canvas liegen die Sticker absolut positioniert nebeneinander. */
.composition-sticker {
  position: absolute;
  transform-origin: center center;
}

/* Bild-Sticker-Karte (Johanna-Spyri-Illustration) — an-/abwählbar statt textabhängig, daher
   eigener Rahmen um die Kontur, solange sie ausgewählt ist. */
.sticker-card-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-align: center;
}

.sticker-card--image .sticker-shape-wrapper {
  border-radius: 50%;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.sticker-card--image.is-selected .sticker-shape-wrapper {
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--color-accent);
}

.sticker-shape {
  stroke: var(--contour-color);
  stroke-width: var(--contour-width);
  /* Sticker-Formen werden nicht-uniform gestreckt (preserveAspectRatio="none"), damit die
     Karte in der Breite mit dem Text wachsen kann — ohne non-scaling-stroke würde diese
     Streckung auch die Kontur mitverzerren (unterschiedlich dick je nach Kante/Seitenverhältnis). */
  vector-effect: non-scaling-stroke;
  paint-order: stroke fill;
}

.sticker-text {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #000;
  font-weight: 600;
  line-height: 1.15;
  padding: 3px;
  overflow: hidden;
  white-space: nowrap;
  text-transform: uppercase;
  user-select: none;
}

.sticker-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sticker-controls .mini-btn {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, transform 0.1s ease, color 0.15s ease;
}

.sticker-controls .mini-btn:hover {
  transform: translateY(-1px);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.sticker-controls .mini-btn.is-active {
  border-color: var(--color-accent);
  color: var(--color-accent);
  box-shadow: 0 0 0 1.5px var(--color-accent-soft);
}

.sticker-controls .mini-btn svg {
  width: 100%;
  height: 100%;
}

.sticker-controls .mini-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.sticker-controls .mini-swatch:hover {
  transform: translateY(-1px);
}

.sticker-controls .mini-swatch.is-active {
  box-shadow: 0 0 0 2px #fff inset, 0 0 0 3.5px var(--color-accent);
}

.sticker-controls .mini-swatch svg {
  width: 55%;
  height: 55%;
  color: #000;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.sticker-controls .mini-swatch.is-active svg {
  opacity: 0.72;
}

.sticker-controls .divider {
  width: 1px;
  height: 18px;
  background: var(--color-border);
  margin: 0 2px;
}

/* ---------- Responsive ---------- */

/* Zwischenstufe: Sidebar bleibt eigene Zeile, Liste und Komposition teilen sich eine Reihe. */
@media (max-width: 1100px) {
  .app {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "header header"
      "sidebar sidebar"
      "list composition";
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: var(--column-divider);
  }

  .sticker-list {
    height: auto;
    min-height: 480px;
    position: static;
    overflow-y: visible;
  }

  .composition-panel {
    height: auto;
    min-height: 480px;
    position: static;
  }
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "sidebar"
      "list"
      "composition";
    --header-height: 100px;
  }

  .app-header {
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  /* Auf schmalen Screens ist die Wortmarke (3 volle Wörter als Sticker-Badges) breiter als der
     Viewport. Statt sie zu verkleinern (unleserlich), bleibt sie in natürlicher Größe und
     scrollt horizontal für sich. */
  .wordmark {
    flex: 1 1 auto;
    min-width: 0;
    gap: 0;
    transform: none;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 14px 16px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  }

  .wordmark-part {
    flex: none;
  }

  /* Text-Spalte bleibt auf allen Breiten immer sichtbar, genau wie Style und Komposition —
     kein Einklapp-Verhalten mehr, daher nur noch das Padding an die anderen Spalten angleichen. */
  .sidebar {
    padding: 20px;
  }

  .sticker-list {
    padding: 20px;
    gap: 18px;
    border-right: none;
    border-bottom: var(--column-divider);
    min-height: 0;
  }

  .composition-panel {
    min-height: 380px;
  }
}

@media (max-width: 420px) {
  .sticker-list {
    gap: 14px;
  }
}
