/* ───────────────────────────────────────────────
   Rastergenerator – Stylesheet
   Schlicht, hell, funktional. System-Sans-Serif.
   ─────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html, body, h1, h2, h3, h4, p, ul, ol, figure, fieldset { margin: 0; padding: 0; }
fieldset { border: 0; }
button { font: inherit; cursor: pointer; }

/* Globale Regel: hidden-Attribut darf NIE durch class-selectors mit display: ... überschrieben werden */
[hidden] { display: none !important; }

:root {
  --bg:           #0b0b0c;
  --surface:      #161618;
  --surface-2:    #1d1d20;
  --surface-3:    #25252a;
  --border:       #28282d;
  --border-2:     #3a3a40;
  --text:         #ededed;
  --text-muted:   #999ca3;
  --accent:       #5e9bff;
  --accent-hover: #7eb0ff;
  --danger:       #ef4444;
  --radius:       6px;
  --radius-sm:    4px;
  --header-h:     64px;
  --footer-h:     56px;
  --maxw:         1400px;
  --gap:          1rem;
  --pad:          1.25rem;
  color-scheme:   dark;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
               Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

/* Visuell versteckt, für Screenreader sichtbar */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* Skip-Link */
.skip-link {
  position: absolute;
  top: -100px; left: 0;
  background: var(--text); color: var(--bg);
  padding: 0.5rem 1rem;
  text-decoration: none;
  z-index: 100;
}
.skip-link:focus { top: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Header ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 1.125rem;
}
.brand:hover, .brand:focus-visible { text-decoration: none; color: var(--accent); }
.brand-mark { width: 28px; height: 28px; flex-shrink: 0; }
.brand-text { letter-spacing: -0.01em; }
.brand-tagline {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-left: auto;
}

/* ── Layout ── */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  gap: 0;
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  padding: 0;
  align-items: stretch;
}

/* Statische Seiten (Impressum/Datenschutz) */
.page {
  flex: 1;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
}
.prose { max-width: 65ch; }
.prose h1 { font-size: 1.75rem; margin-bottom: 1rem; letter-spacing: -0.01em; }
.prose h2 { font-size: 1.1rem; margin: 1.25rem 0 0.5rem; color: var(--text-muted); font-weight: 500; }
.prose p  { margin-bottom: 1rem; color: var(--text-muted); }
.prose address { font-style: normal; line-height: 1.7; color: var(--text); }
.prose a { color: var(--accent); }

/* ── Steuerung (links) ── */
.controls {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
  max-height: calc(100vh - var(--header-h));
  position: sticky;
  top: 0;
}

.panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.panel > summary {
  padding: 0.625rem 0.875rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::after {
  content: "+";
  color: var(--text-muted);
  font-weight: 400;
  font-size: 1.25rem;
  line-height: 1;
}
.panel[open] > summary::after { content: "−"; }
.panel > summary:hover { background: var(--bg); }
.panel-body {
  padding: 0.875rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Felder */
.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.field label, .field > legend {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
}
.field-row .field { min-width: 0; }

input[type="number"],
input[type="text"],
select {
  appearance: none;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.55rem;
  font: inherit;
  color: var(--text);
  width: 100%;
  min-width: 0;
}
input[type="number"]:focus-visible,
input[type="text"]:focus-visible,
select:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M3 5l3 3 3-3' fill='none' stroke='%23999ca3' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  padding-right: 1.75rem;
}

input[type="color"] {
  height: 32px;
  width: 100%;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  padding: 2px;
  cursor: pointer;
}

input[type="range"] { width: 100%; accent-color: var(--accent); }

output {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
}
.check input { accent-color: var(--accent); }

.segmented {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.segmented legend {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  width: 100%;
  margin-bottom: 0.25rem;
}
.segmented label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0;
}

.sep {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0.25rem 0;
}

.group { display: flex; flex-direction: column; gap: 0.625rem; }
.group[hidden] { display: none; }

/* Buttons */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.btn {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text);
  font-weight: 500;
  transition: background-color 0.12s, border-color 0.12s;
  text-align: center;
}
.btn:hover { background: var(--bg); border-color: var(--text-muted); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  grid-column: 1 / -1;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn.ghost:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border-2);
}

.reset-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

/* ── Vorschau (rechts) ── */
.preview {
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  min-width: 0;
  background: var(--bg);
}
.preview-meta {
  display: flex;
  gap: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}
.flash-tip {
  margin-left: auto;
  color: var(--accent);
  transition: opacity 0.4s;
  opacity: 0;
}
.preview-stage {
  /* Schreibtisch-Optik: das Papier liegt auf einer Arbeitsfläche */
  background: #2a2a2e;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: inset 0 2px 16px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  flex: 1;
  position: relative;
}
#canvas {
  background: #fff;
  display: block;
  /* width/height + aspect-ratio werden per JS gesetzt, keine CSS-Begrenzung */
  box-shadow: 0 8px 30px rgba(0,0,0,0.7), 0 0 0 1px rgba(0,0,0,0.5);
}
.preview {
  /* Begrenze die Sektion über die Höhe → so wird die Stage und damit der Canvas
     niemals größer als der verfügbare Platz und das Aspect-Ratio bleibt erhalten. */
  max-height: calc(100vh - var(--header-h) - var(--footer-h));
  overflow: hidden;
}

/* ── Footer ── */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  margin-top: auto;
}
.footer-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}
.footer-copy { color: var(--text-muted); font-size: 0.85rem; }
.footer-nav { display: flex; align-items: center; gap: 1.25rem; }
.footer-nav a { color: var(--text-muted); font-size: 0.85rem; }
.footer-nav a:hover, .footer-nav a:focus-visible { color: var(--text); }
.footer-nav a.footer-more {
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.7rem;
  color: var(--text);
}
.footer-nav a.footer-more:hover {
  background: var(--surface-2);
  text-decoration: none;
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Mobile-Toggle (Schublade) — Default-Definition ── */
.mobile-toggle {
  display: none;
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 50;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .header-inner { padding: 0.75rem 1rem; }
  .brand-tagline { display: none; }
  .layout {
    grid-template-columns: 1fr;
    position: relative;
  }
  /* Steuerung als ausziehbare Schublade von unten */
  .controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    max-height: 75vh;
    z-index: 40;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    border-right: 0;
    border-top: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.6);
    overflow-y: auto;
  }
  body.controls-open .controls { transform: translateY(0); }
  .preview {
    padding: 0.75rem;
    min-height: calc(100vh - var(--header-h) - var(--footer-h));
  }
  .preview-stage { padding: 0.5rem; min-height: 50vh; }
  .preview-tip { display: none; }
  .footer-inner { padding: 0.75rem 1rem; }
  .mobile-toggle { display: inline-flex; align-items: center; gap: 0.4rem; }
  body.controls-open .mobile-toggle { background: var(--surface-3); }
}

@media (max-width: 480px) {
  .field-row { grid-template-columns: 1fr; }
  .actions { grid-template-columns: 1fr; }
  .btn.primary { grid-column: auto; }
}

/* ── Preset-Bar ── */
.preset-bar {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.preset-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.preset-bar select { flex: 1; }

/* ── Color-Picker mit Swatch-Vorschau ── */
.color-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.color-row input[type="color"] {
  flex: 1;
  background: #fff;
  height: 32px;
}
.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border-2);
  box-shadow: 0 0 0 2px var(--surface);
  flex-shrink: 0;
}

/* Color-Pickerfläche heller, damit der gewählte Wert sichtbar bleibt */
input[type="color"] {
  background: #ffffff;
}

/* ── Margins-Raster ── */
fieldset.margins .margin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

/* ── Snapshot-Liste ── */
.snap-list {
  list-style: none;
  margin: 0.5rem 0;
  padding: 0;
  font-size: 0.85rem;
}
.snap-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.snap-list li:last-child { border-bottom: 0; }
.snap-list li > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-tiny {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.45rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.btn-tiny:hover { background: var(--bg); color: var(--text); }

/* ── Tastaturkürzel-Hinweis ── */
kbd {
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.7rem;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  color: var(--text);
}

/* ── Loading-Overlay ── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 11, 12, 0.78);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.875rem;
  z-index: 10;
  backdrop-filter: blur(2px);
}
/* hidden ist global durch [hidden]{display:none!important} oben abgedeckt */
.loading-overlay p {
  color: var(--text);
  margin: 0;
  font-size: 0.95rem;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile-Toggle (Schublade) ──
   ACHTUNG: Block muss VOR den @media-Queries stehen.
   Sonst überschreibt das spätere display:none die Mobile-Regel. */

/* ── Druck ── */
@media print {
  .site-header, .site-footer, .controls, .preview-meta { display: none; }
  body, .layout, .preview, .preview-stage {
    background: #fff;
    border: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
  }
  .layout { grid-template-columns: 1fr; }
  #canvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: none;
  }
}
