/* Wasserzeichen — eigene Palette: Foto-Dunkel + Cyan-Akzent */
:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #22d3ee;
  --accent-2: #0891b2;
  --accent-ink: #06222b;
  --danger: #f87171;
  --ok: #34d399;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --maxw: 1180px;
}

[data-theme="light"] {
  --bg: #eef2f7;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #cbd5e1;
  --text: #0f172a;
  --text-dim: #475569;
  --accent: #0891b2;
  --accent-2: #0e7490;
  --accent-ink: #ecfeff;
  --danger: #dc2626;
  --ok: #059669;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 14px;
  border-radius: 0 0 10px 0;
  z-index: 50;
}
.skip-link:focus { left: 0; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  max-width: var(--maxw);
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  flex: none;
}
.brand-text h1 { font-size: 1.2rem; margin: 0; letter-spacing: 0.2px; }
.brand-text p { margin: 0; font-size: 0.78rem; color: var(--text-dim); }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Buttons */
.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border: none;
  font-weight: 700;
}
.btn-primary:disabled,
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; display: block; margin-top: 8px; }
.btn-sm { padding: 6px 10px; font-size: 0.85rem; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-icon { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; font-size: 1.1rem; }

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

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 18px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px;
  align-items: start;
}
.panel { min-width: 0; }
.controls { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 0.95rem;
  margin: 0 0 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 22px 16px;
  text-align: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.is-over {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface-2);
}
.dropzone svg { color: var(--accent); margin-bottom: 6px; }
.dropzone p { margin: 4px 0 0; font-size: 0.9rem; }

/* Batch */
.batch { margin-top: 12px; }
.batch-info { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
#batchPos { font-weight: 700; font-size: 0.85rem; }
.batch-name { font-size: 0.8rem; color: var(--text-dim); }
.batch-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.batch-nav .btn-sm { min-width: 40px; }
.batch-nav .btn-danger { margin-left: auto; }

/* Segmented control */
.seg {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}
.seg-btn {
  flex: 1;
  font: inherit;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.seg-btn.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
}

/* Fields */
.opts { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; min-width: 0; }
.field > span, legend { color: var(--text-dim); font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.field output { color: var(--accent); font-variant-numeric: tabular-nums; }
fieldset.field { border: none; margin: 0; padding: 0; }
legend { padding: 0; margin-bottom: 8px; }

input[type="text"], select {
  font: inherit;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
input[type="text"]:focus, select:focus { border-color: var(--accent); outline: none; }

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

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-2);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-2);
  cursor: pointer;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.check, .tile-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: pointer;
}
.tile-check { margin-top: 12px; }
.check input[type="checkbox"] {
  width: 20px; height: 20px;
  accent-color: var(--accent);
  flex: none;
  cursor: pointer;
}

.div { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.hint { font-size: 0.78rem; color: var(--text-dim); margin: 8px 0 0; }

/* Position grid */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  aspect-ratio: 3 / 2;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
}
.pos-cell {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
}
.pos-cell::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: 0.4;
}
.pos-cell:hover { border-color: var(--accent); }
.pos-cell.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: var(--accent);
}
.pos-cell.is-active::after { background: var(--accent-ink); opacity: 1; }

/* Preview */
.preview { position: sticky; top: 18px; }
.preview-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.dim-info { font-size: 0.8rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.stage {
  background:
    linear-gradient(45deg, #1b2536 25%, transparent 25%) 0 0,
    linear-gradient(-45deg, #1b2536 25%, transparent 25%) 0 0,
    linear-gradient(45deg, transparent 75%, #1b2536 75%) 0 0,
    linear-gradient(-45deg, transparent 75%, #1b2536 75%) 0 0;
  background-size: 24px 24px;
  background-color: #0b1220;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 280px;
  display: grid;
  place-items: center;
  padding: 14px;
  overflow: hidden;
}
[data-theme="light"] .stage {
  background:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%) 0 0,
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%) 0 0,
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%) 0 0,
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%) 0 0;
  background-size: 24px 24px;
  background-color: #f8fafc;
}
#canvas {
  max-width: 100%;
  max-height: 72dvh;
  height: auto;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.empty { text-align: center; color: var(--text-dim); }
.empty svg { color: var(--border); margin-bottom: 10px; }
.empty p { margin: 0; font-size: 0.9rem; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
  font-size: 0.88rem;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.toast-err { border-color: var(--danger); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.62);
  display: grid;
  place-items: center;
  z-index: 70;
  padding: 20px;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-box h3 { margin: 0 0 8px; color: var(--accent); }
.modal-box p { margin: 0 0 18px; color: var(--text); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* Responsive */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .preview { position: static; order: -1; }
  #canvas { max-height: 56dvh; }
}
@media (max-width: 420px) {
  .app-header { padding: 12px; }
  .layout { padding: 12px; gap: 14px; }
  .field-row { grid-template-columns: 1fr; }
  .brand-text h1 { font-size: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
