:root {
  --bg: #05060a;
  --bg-panel: #0a0c11;
  --bg-elevated: #12151c;
  --bg-elevated-2: #1a1e28;
  --bg-elevated-3: #212633;
  --border: #1e222c;
  --border-strong: #2b3140;
  --text: #f4f6fa;
  --text-dim: #9aa2b3;
  --text-faint: #5b6272;
  --blue: #4f8cff;
  --blue-strong: #3572e6;
  --blue-soft: rgba(79, 140, 255, 0.14);
  --turquoise: #2fe6cf;
  --turquoise-soft: rgba(47, 230, 207, 0.14);
  --radius-sm: 7px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.02) inset, 0 10px 30px rgba(0, 0, 0, 0.45);
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

svg[style*="display:none"] {
  position: absolute;
  width: 0;
  height: 0;
}

canvas {
  display: block;
}

/* ---------- Icons ---------- */
.icon {
  width: 17px;
  height: 17px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
}
.icon-fill { fill: currentColor; stroke: none; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 24px; height: 24px; }

/* ---------- App shell ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  background:
    radial-gradient(1200px 500px at 12% -10%, rgba(79, 140, 255, 0.08), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(47, 230, 207, 0.06), transparent 60%),
    var(--bg);
}

#topbar {
  height: 136px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  background: rgba(10, 12, 17, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  color: var(--blue);
}
.brand-name {
  position: relative;
  display: inline-block;
  font-family: var(--font-display);
  font-size: 68px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text);
  letter-spacing: 0.01em;
}

/* RGB-Glitch: zwei farbige Kopien der Wortmarke (Rot/Türkis), additiv per
   mix-blend-mode über den Basistext gelegt. In rascher, wiederkehrender
   Abfolge weichen sie kurz als Farbkanal-Versatz auseinander, analog zum
   "Glitch"-Effekt der App, und springen dazwischen zurück auf deckungsgleich. */
.brand-name::before,
.brand-name::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  mix-blend-mode: screen;
  pointer-events: none;
}
.brand-name::before {
  color: #ff3355;
  animation: glitchRed 1.1s steps(1, end) infinite;
}
.brand-name::after {
  color: var(--turquoise);
  animation: glitchCyan 1.1s steps(1, end) infinite;
}

@keyframes glitchRed {
  0%, 100% { opacity: 0; transform: translate(0, 0); }
  4% { opacity: 0.85; transform: translate(3px, -1px); }
  8% { opacity: 0; transform: translate(0, 0); }
  9% { opacity: 0.85; transform: translate(-4px, 1px); }
  13% { opacity: 0; transform: translate(0, 0); }
  40% { opacity: 0.85; transform: translate(4px, 0); }
  44% { opacity: 0; transform: translate(0, 0); }
  45% { opacity: 0.85; transform: translate(-2px, 1px); }
  49% { opacity: 0; transform: translate(0, 0); }
  70% { opacity: 0.85; transform: translate(3px, -1px); }
  74% { opacity: 0; transform: translate(0, 0); }
}
@keyframes glitchCyan {
  0%, 100% { opacity: 0; transform: translate(0, 0); }
  4% { opacity: 0.85; transform: translate(-3px, 1px); }
  8% { opacity: 0; transform: translate(0, 0); }
  9% { opacity: 0.85; transform: translate(4px, -1px); }
  13% { opacity: 0; transform: translate(0, 0); }
  40% { opacity: 0.85; transform: translate(-4px, 0); }
  44% { opacity: 0; transform: translate(0, 0); }
  45% { opacity: 0.85; transform: translate(2px, -1px); }
  49% { opacity: 0; transform: translate(0, 0); }
  70% { opacity: 0.85; transform: translate(-3px, 1px); }
  74% { opacity: 0; transform: translate(0, 0); }
}

#main {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

#leftMenu, #rightMenu {
  width: 288px;
  flex: none;
  padding: 16px;
  background: var(--bg-panel);
  overflow-y: auto;
  overflow-x: hidden;
}
#leftMenu { border-right: 1px solid var(--border); }
#rightMenu { border-left: 1px solid var(--border); }

/* ---------- Scrollbars ---------- */
#leftMenu::-webkit-scrollbar, #rightMenu::-webkit-scrollbar { width: 9px; }
#leftMenu::-webkit-scrollbar-track, #rightMenu::-webkit-scrollbar-track { background: transparent; }
#leftMenu::-webkit-scrollbar-thumb, #rightMenu::-webkit-scrollbar-thumb {
  background: var(--bg-elevated-3);
  border-radius: 999px;
  border: 2px solid var(--bg-panel);
}
#leftMenu::-webkit-scrollbar-thumb:hover, #rightMenu::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ---------- Canvas area ---------- */
#centerColumn {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#canvasWrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  min-width: 0;
  min-height: 0;
}

/* ---------- Export-Toolbar (unterhalb des Canvas) ---------- */
#exportBar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 18px;
  background: rgba(10, 12, 17, 0.9);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.export-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-right: 4px;
  flex: none;
}
.export-label .icon { color: var(--text-faint); }
#exportBar .btn {
  width: auto;
  flex: 0 0 auto;
  min-width: 100px;
  margin: 0;
}

#previewContainer {
  width: 86%;
  height: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg-panel);
  border: 1px solid var(--border);
}

#canvasHolder {
  background: #fff;
  border-radius: 4px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 0 6px var(--bg-elevated-2),
    0 20px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ---------- Panel cards ---------- */
.panel-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 14px 14px 16px;
  margin-bottom: 14px;
}
.panel-card:last-child { margin-bottom: 0; }

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px 0;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}
.panel-title .icon { color: var(--blue); }

.info-line {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

/* ---------- Form fields ---------- */
.field { margin: 12px 0; }
.field:first-child { margin-top: 0; }
.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field-label .icon { color: var(--text-faint); margin-right: auto; }

label { display: block; margin: 10px 0; font-size: 14px; line-height: 1.4; font-weight: 500; color: var(--text); }

textarea, select, input[type="text"] {
  width: 100%;
  background: var(--bg-elevated-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; min-height: 64px; }
textarea:focus, select:focus, input[type="text"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa2b3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
  padding-right: 32px;
}

.color-row { display: flex; align-items: center; gap: 8px; }
input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 38px;
  height: 34px;
  flex: none;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated-2);
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
.color-row input[type="text"] { font-family: var(--font-mono); }

/* ---------- Sliders (value fill via --fill, set in sketch.js) ---------- */
.field-slider .field-label { justify-content: space-between; }
.sliderVal {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--turquoise);
  background: var(--turquoise-soft);
  border-radius: 999px;
  padding: 1px 8px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--blue) 0%, var(--blue) var(--fill, 0%), var(--bg-elevated-3) var(--fill, 0%), var(--bg-elevated-3) 100%);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--turquoise);
  border: 2px solid var(--bg-elevated);
  box-shadow: 0 0 0 1px var(--turquoise), 0 2px 6px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--bg-elevated-3);
}
input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--blue);
}
input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--turquoise);
  border: 2px solid var(--bg-elevated);
  cursor: pointer;
}

/* ---------- Buttons ---------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin: 8px 0;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.btn .icon { color: inherit; }
.btn:hover { border-color: var(--border-strong); background: var(--bg-elevated-3); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #06101f;
  box-shadow: 0 4px 16px rgba(79, 140, 255, 0.35);
}
.btn-primary:hover { background: var(--blue-strong); border-color: var(--blue-strong); }
.btn-accent {
  border-color: var(--turquoise);
  color: var(--turquoise);
  background: var(--turquoise-soft);
}
.btn-accent:hover { background: rgba(47, 230, 207, 0.22); }

button { display: block; }

/* ---------- Distortion cards (generated by distortions.js) ---------- */
.distortion-block {
  padding: 10px 0;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.distortion-block:last-child { border-bottom: none; margin-bottom: 0; }

.distortion-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.distortion-title .icon { color: var(--text-dim); flex: none; }
.distortion-title span { flex: 1 1 auto; }

/* Native Checkbox -> Toggle-Switch (Pill mit gleitendem Punkt) */
.distortion-title input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 21px;
  flex: none;
  border-radius: 999px;
  background: var(--bg-elevated-3);
  border: 1px solid var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.distortion-title input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform .15s ease, background .15s ease;
}
.distortion-title input[type="checkbox"]:checked {
  background: var(--blue-soft);
  border-color: var(--blue);
}
.distortion-title input[type="checkbox"]:checked::before {
  transform: translateX(15px);
  background: var(--blue);
}

.distortion-param {
  margin: 8px 0 8px 25px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}
.distortion-param .sliderVal { margin-left: 6px; }

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

/* Tablet-Breite: 3-Spalten-Layout bleibt erhalten, Seitenmenüs werden nur
   schmaler, damit der Canvas-Bereich in der Mitte genug Platz behält. */
@media (max-width: 1180px) {
  #leftMenu, #rightMenu { width: 240px; }
}

/* Ab hier wird gestapelt statt nebeneinander: die App verlässt das feste
   100vh-Shell-Layout (Menüs scrollen intern) zugunsten einer normal
   scrollenden Seite (Header -> Textmenü -> Canvas -> Export -> Verzerrung).
   canvasWrap bekommt dafür eine feste Höhe statt flex-grow, weil ohne die
   100vh-Begrenzung des Eltern-Containers sonst keine konkrete Höhe mehr für
   die Canvas-Skalierung (updateCanvasScale() in sketch.js) zur Verfügung
   stünde. */
@media (max-width: 960px) {
  html, body { height: auto; overflow: visible; }
  #app { height: auto; min-height: 100vh; }
  #main { flex-direction: column; }

  /* Canvas zuerst: direkt nach dem Header sieht man das Ergebnis, die
     Regler (Text-/Typografie- und Verzerrungsmenü) folgen zum Scrollen
     darunter statt davor. */
  #centerColumn { order: 1; }
  #leftMenu { order: 2; }
  #rightMenu { order: 3; }

  #leftMenu, #rightMenu {
    width: 100%;
    overflow: visible;
  }
  #leftMenu { border-right: none; border-bottom: 1px solid var(--border); }
  #rightMenu { border-left: none; border-top: 1px solid var(--border); }

  #canvasWrap { flex: none; height: 62vh; min-height: 320px; padding: 20px 0; }
  #previewContainer { width: 92%; height: 92%; }

  #topbar { height: auto; padding: 20px 18px; }
  .brand-name { font-size: 44px; }
}

@media (max-width: 560px) {
  #leftMenu, #rightMenu { padding: 12px; }
  #topbar { padding: 16px 12px; }
  .brand-name { font-size: 30px; }

  #canvasWrap { height: 48vh; min-height: 240px; padding: 14px 0; }

  #exportBar { flex-wrap: wrap; row-gap: 8px; padding: 10px 12px; }
  .export-label { flex: 1 1 100%; justify-content: center; margin: 0 0 2px; }
  #exportBar .btn { flex: 1 1 100px; min-width: 0; }
}
