/* =============================================================================
   GRAS Insta Studio – Oberfläche
   ========================================================================== */

:root {
  --green: #5BC500;
  --green-dark: #4aa800;
  --pink: #ED1E79;
  --ink: #16181a;
  --panel: #1e2124;
  --panel-2: #26292d;
  --line: #34383d;
  --text: #e9ecef;
  --muted: #9aa3ab;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #101214;
  color: var(--text);
  font: 14px/1.45 "Archivo Narrow", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ Kopf */

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: baseline; gap: 10px; margin-right: auto; }
.brand h1 {
  font-family: "Nörwäster", "Archivo Narrow", sans-serif;
  font-size: 22px;
  letter-spacing: 0.5px;
  margin: 0;
  text-transform: uppercase;
}
.brand span { color: var(--muted); font-size: 12px; }

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover { background: #33383d; border-color: #454b52; }
button.primary { background: var(--green); border-color: var(--green); color: #08210a; font-weight: 700; }
button.primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
button.ghost { background: transparent; }
button.icon { padding: 6px 8px; line-height: 1; }
button:disabled { opacity: .45; cursor: default; }

/* ----------------------------------------------------------------- Rumpf */

main {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: calc(100vh - 57px);
  min-height: 0;
}

aside {
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 12px 14px 60px;
}

details {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: var(--panel-2);
  overflow: hidden;
}
details[open] { background: #23262a; }
summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  font-size: 12px;
  color: #cfd6dc;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "▾"; float: right; color: var(--muted); }
details[open] summary::after { content: "▴"; }
.body { padding: 4px 12px 14px; display: grid; gap: 10px; }

.row { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; }
.row > label { color: var(--muted); font-size: 12px; }
.row.wide { grid-template-columns: 1fr; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  background: #15181a;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
}
textarea { resize: vertical; min-height: 56px; }
input[type="range"] { width: 100%; accent-color: var(--green); }
input[type="color"] {
  width: 34px; height: 30px; padding: 2px; background: #15181a;
  border: 1px solid var(--line); border-radius: 7px; cursor: pointer;
}
input[type="checkbox"] { accent-color: var(--green); width: 16px; height: 16px; }
.muted { color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.4; }

/* ------------------------------------------------------------------ Bühne */

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, #1b1f22 0%, #101214 70%);
}

.stage-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.stage-head .spacer { margin-left: auto; }

.canvas-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  padding: 16px;
}
#preview {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  cursor: grab;
  touch-action: none;
}
#preview.dragging { cursor: grabbing; }
#preview.dropping { outline: 3px dashed var(--green); }

/* ------------------------------------------------------------- Folienleiste */

.slides {
  display: flex;
  gap: 10px;
  padding: 10px 16px 14px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, .25);
}
.slide-card {
  position: relative;
  flex: 0 0 auto;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 4px;
  background: #1b1e21;
  cursor: pointer;
  text-align: center;
}
.slide-card.active { border-color: var(--green); }
.slide-card canvas { display: block; width: 84px; height: 105px; border-radius: 4px; }
.slide-card .name { font-size: 11px; color: var(--muted); margin-top: 4px; max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slide-card .del {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; padding: 0; border-radius: 50%;
  background: #3a3f45; border: 1px solid #4a5057; font-size: 12px; line-height: 1;
  display: none;
}
.slide-card:hover .del { display: block; }
.slide-add {
  flex: 0 0 auto; width: 92px; height: 133px;
  border: 2px dashed var(--line); border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 26px;
}

/* --------------------------------------------------------------- Blöcke */

.block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #1b1e21;
  display: grid;
  gap: 6px;
}
.block .head { display: flex; align-items: center; gap: 6px; }
.block .swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(255,255,255,.25); }
.block .head .grow { margin-left: auto; }
.chip {
  border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 9px; font-size: 11px; cursor: pointer; background: #202429;
}
.chip.on { background: var(--green); border-color: var(--green); color: #08210a; font-weight: 700; }
.chip .swatch {
  display: inline-block; width: 11px; height: 11px; border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, .35); margin-right: 6px; vertical-align: -1px;
}

.menu {
  position: fixed; z-index: 60; min-width: 200px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px; display: grid; gap: 4px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .6);
}
.menu button { text-align: left; }

/* Auswahl per Klick im Vorschaubild */
.block.ausgewaehlt {
  border-color: #0a84ff;
  box-shadow: 0 0 0 2px rgba(10, 132, 255, .22);
}
details.ausgewaehlt {
  border-color: #0a84ff;
  box-shadow: 0 0 0 2px rgba(10, 132, 255, .22);
}
.blitz { animation: grasBlitz .9s ease-out; }
@keyframes grasBlitz {
  0%   { background: rgba(10, 132, 255, .3); }
  100% { background: transparent; }
}

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #23272b; border: 1px solid var(--line); border-left: 4px solid var(--green);
  padding: 10px 16px; border-radius: 8px; box-shadow: 0 12px 30px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 40;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

@media (max-width: 980px) {
  main { grid-template-columns: 1fr; height: auto; }
  aside { border-right: none; border-bottom: 1px solid var(--line); }
  .stage { min-height: 70vh; }
}

/* =============================================================================
   Robustheit: Layout und Bedienung auf kleinen Fenstern und in älteren Browsern
   ========================================================================== */

/* Etwas engeres Panel, wenn der Bildschirm schmal ist */
@media (max-width: 1180px) and (min-width: 981px) {
  main { grid-template-columns: 320px minmax(0, 1fr); }
}

/* Kleines Fenster / hohe Windows-Skalierung: Panel scrollt für sich,
   die Vorschau bleibt sichtbar. */
@media (max-width: 980px) {
  main { grid-template-columns: 1fr; height: auto; }
  aside {
    border-right: none; border-bottom: 1px solid var(--line);
    max-height: 46vh; overflow-y: auto;
  }
  .stage { min-height: 58vh; }
  header { flex-wrap: wrap; padding: 8px 12px; }
  .brand h1 { font-size: 19px; }
}

/* Sehr flache Fenster: weniger Polster, damit die Vorschau Platz behält */
@media (max-height: 700px) {
  .canvas-wrap { padding: 8px; }
  .slides { padding: 6px 12px 8px; }
  .slide-card canvas { width: 64px; height: 80px; }
  .slide-add { width: 72px; height: 104px; }
}

/* Browser ohne CSS-Raster (altes Edge, Safari 10): gleiches Layout mit Flexbox */
@supports not (display: grid) {
  main { display: flex; align-items: stretch; }
  aside { flex: 0 0 360px; width: 360px; }
  .stage { flex: 1 1 auto; min-width: 0; }
  .canvas-wrap { display: flex; align-items: center; justify-content: center; }
  .body { display: block; }
  .body > * { margin-bottom: 10px; }
  .row { display: flex; align-items: center; gap: 8px; }
  .row > label { flex: 0 0 110px; }
  .row .inline { flex: 1 1 auto; }
  .two { display: flex; gap: 8px; }
  .two > * { flex: 1 1 0; }
  .inline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .block .head { display: flex; align-items: center; gap: 6px; }
  .slide-card .name { max-width: 88px; }
}


/* =============================================================================
   Handy und Tablet
   ========================================================================== */

html { -webkit-text-size-adjust: 100%; }

/* Kopfbereich und Leiste an Geräte mit Notch anpassen */
header { padding-top: max(10px, env(safe-area-inset-top)); padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(18px, env(safe-area-inset-right)); }
.slides { padding-bottom: max(14px, env(safe-area-inset-bottom)); }

/* Zoom-Tasten: auf Geräten ohne Mausrad */
.zoom-tasten { display: none; gap: 4px; }
.zoom-tasten .icon { font-size: 18px; line-height: 1; min-width: 40px; }

@media (hover: none), (max-width: 980px) {
  .zoom-tasten { display: inline-flex; }
}

/* Schmale Geräte: Vorschau oben, Bedienung darunter */
@media (max-width: 760px) {
  main { display: flex; flex-direction: column; height: auto; min-height: 0; }
  .stage { order: 1; min-height: 0; }
  aside {
    order: 2;
    max-height: none;
    overflow: visible;
    border-right: none;
    border-bottom: none;
    border-top: 1px solid var(--line);
    padding: 12px 12px 40px;
  }

  /* Vorschau so hoch, dass die Bedienung darunter gut erreichbar bleibt */
  .canvas-wrap { padding: 8px; }
  #preview { max-height: 46vh; }

  .stage-head { flex-wrap: wrap; padding: 8px 10px; gap: 6px; font-size: 13px; }
  .stage-head .muted { display: none; }              /* „6 Blöcke · 1080 × 1350" spart Platz */
  .slides { position: sticky; bottom: 0; z-index: 15; }

  /* Kopfbereich einzeilig und seitlich scrollbar – spart Höhe für die Vorschau */
  header {
    gap: 6px;
    padding: 8px 12px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  header::-webkit-scrollbar { display: none; }
  header button { white-space: nowrap; flex: 0 0 auto; min-height: 38px; padding: 8px 11px; }
  .brand { flex: 0 0 auto; margin-right: 6px; }
  .brand span { display: none; }
  .brand h1 { font-size: 18px; }

  /* Das Wichtigste steht vorn: exportieren und teilen */
  .brand { order: -3; }
  #btnPng { order: -2; }
  #btnTeilen { order: -1; }

  /* Fingerfreundliche Größen */
  button { min-height: 40px; padding: 9px 12px; }
  button.icon { min-width: 40px; }
  .chip { min-height: 34px; padding: 6px 11px; font-size: 12px; }
  input[type="text"], input[type="number"], select, textarea { min-height: 40px; }
  input[type="range"] { height: 30px; }
  input[type="color"] { width: 44px; height: 40px; }
  .row { grid-template-columns: 96px 1fr; }
  .row > label { font-size: 12px; }
  summary { padding: 12px; font-size: 13px; }
  .toast { left: 8px; right: 8px; transform: none; text-align: center; }
  .toast.show { transform: translateY(-4px); }
}

/* Sehr schmale Geräte: Zahlenfelder untereinander */
@media (max-width: 420px) {
  .row { grid-template-columns: 1fr; gap: 4px; }
  .row .inline { justify-content: flex-start; }
  .brand h1 { font-size: 17px; }
}

/* =============================================================================
   Anleitung (Overlay) – mit Katzen-Animationen
   ========================================================================== */

html.anl-offen, html.anl-offen body { overflow: hidden; }

.anl {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(8, 10, 12, .72);
  backdrop-filter: blur(3px);
}
.anl[hidden] { display: none; }

.anl-karte {
  width: min(900px, 100%);
  max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: #1e2124;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
  overflow: hidden;
}

.anl-kopf {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #23262a;
}
.anl-marke {
  font-family: "Nörwäster", "Archivo Narrow", sans-serif;
  font-size: 19px; letter-spacing: .5px; text-transform: uppercase;
  color: var(--green);
  margin-right: auto;
}
.anl-zu {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  width: 36px; height: 36px; border-radius: 8px; font-size: 20px; line-height: 1;
  cursor: pointer;
}
.anl-zu:hover { background: #33383d; }

.anl-inhalt {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 22px;
  padding: 20px;
  overflow-y: auto;
}
.anl-katze {
  margin: 0;
  align-self: start;
  border-radius: 12px;
  overflow: hidden;
  background: #15181a;
  border: 1px solid var(--line);
}
.anl-katze img { display: block; width: 100%; height: auto; }

.anl-text { min-width: 0; }
.anl-nr {
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 4px;
}
.anl-titel {
  margin: 0 0 10px;
  font-family: "Nörwäster", "Archivo Narrow", sans-serif;
  font-size: 30px; letter-spacing: .5px; text-transform: uppercase;
  color: var(--text);
}
.anl-absatz { margin: 0 0 14px; line-height: 1.6; color: #dfe4e8; }
.anl-absatz b { color: #fff; }

.anl-bild {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #15181a;
  max-width: 340px;
}
.anl-bild img {
  display: block; width: 100%; height: auto; max-height: 340px;
  object-fit: cover; object-position: top;   /* hohe Ausschnitte oben anschneiden */
}
.anl-bild figcaption {
  padding: 7px 10px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line);
}

.anl-tipp {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(91, 197, 0, .1);
  border: 1px solid rgba(91, 197, 0, .35);
  color: #d8f5c4; font-size: 13px; line-height: 1.5;
}

.anl-fuss {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #23262a;
}
.anl-fuss button {
  background: #2b3036; border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 14px; cursor: pointer;
}
.anl-fuss button:hover { background: #33383d; }
.anl-fuss button:disabled { opacity: .4; cursor: default; }
.anl-weiter { background: var(--green) !important; border-color: var(--green) !important; color: #08210a !important; font-weight: 700; }

.anl-punkte { display: flex; align-items: center; gap: 7px; margin: 0 auto; }
.anl-punkt {
  flex: 0 0 auto; width: 9px; height: 9px; padding: 0; border-radius: 50%;
  border: 1px solid #4a5057; background: #2b3036; cursor: pointer;
}
.anl-punkt.an { background: var(--green); border-color: var(--green); transform: scale(1.25); }

/* Handy: Katze oben, Text darunter */
@media (max-width: 760px) {
  .anl { padding: 0; }
  .anl-karte { max-height: 100vh; border-radius: 0; border: none; }
  .anl-inhalt { grid-template-columns: 1fr; gap: 14px; padding: 14px; }
  .anl-katze { max-width: 220px; }
  .anl-titel { font-size: 24px; }
  .anl-bild { max-width: none; }
  .anl-fuss { flex-wrap: wrap; }
  .anl-fuss > button { flex: 1 1 auto; }   /* nur die Blätterknöpfe, nicht die Punkte */
  .anl-punkte { order: 3; width: 100%; justify-content: center; align-self: flex-end; }
  /* die Punkte sind Knöpfe – hier die Finger-freundliche Mindesthöhe aufheben */
  .anl-punkt { min-height: 0; height: 9px; width: 9px; padding: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .anl { backdrop-filter: none; }
  .anl-punkt.an { transform: none; }
}
