:root {
  --red: #d9001a;
  --red-dark: #a80014;
  --ink: #1d1d1f;
  --muted: #5f6368;
  --line: #e2e2e6;
  --paper: #ffffff;
  --soft: #f4f4f6;
  --under: #e9e9ed;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column;
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--soft);
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--paper); border-radius: 8px;
  padding: 6px 11px; cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: #c9c9cf; background: #fafafa; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--red-dark); border-color: var(--red-dark); }
button.primary-outline { border-color: var(--red); color: var(--red); font-weight: 600; }
button.big { padding: 11px 22px; font-size: 16px; border-radius: 999px; }
button.small { padding: 2px 8px; font-size: 12px; }
button.wide { width: 100%; }
button.danger { color: var(--red); }
button.toggle.on { background: var(--red); border-color: var(--red); color: #fff; }
select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--paper); }

/* Kopfzeile */
.bar {
  display: flex; align-items: center; gap: 14px; padding: 8px 14px;
  background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.brand .tag { font-size: 11px; font-weight: 600; color: var(--red); border: 1px solid var(--red); border-radius: 999px; padding: 0 7px; }
.tools { display: flex; align-items: center; gap: 6px; flex: 1; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.zoom { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }

/* Hauptbereich */
.main { flex: 1; display: flex; min-height: 0; }
.viewer { flex: 1; overflow: auto; position: relative; background: var(--under); outline: none; }
.viewer.drop { box-shadow: inset 0 0 0 3px var(--red); }
.pages { padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
.page canvas { display: block; }
.layer { position: absolute; inset: 0; cursor: text; }

/* Leerzustand */
.empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: url("/assets/hintergrund.jpg") center / cover no-repeat;
}
.empty[hidden] { display: none; }
.empty::before { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.35); }
.empty .card {
  position: relative; text-align: center; background: #fff; border-radius: 20px; padding: 36px 44px;
  box-shadow: 0 10px 40px rgba(0,0,0,.12); border: 2px dashed rgba(217,0,26,.35); max-width: 440px;
}
.empty .logo { width: 84px; height: 84px; margin: 0 auto 10px; animation: float 3.6s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(-4px); } 50% { transform: translateY(4px); } }
.empty h1 { font-size: 22px; margin: 14px 0 6px; }
.empty p { color: var(--muted); margin: 0 0 18px; }
.demo { display: inline-flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; }
.demo .lines { display: grid; gap: 6px; }
.demo i { display: block; height: 7px; width: 140px; border-radius: 9px; background: #ececee; position: relative; overflow: hidden; }
.demo i:nth-child(3) { width: 100px; }
.demo i::after { content: ""; position: absolute; inset: 0; background: var(--red); transform-origin: left; transform: scaleX(0); animation: fill 4s infinite; }
.demo i:nth-child(2)::after { animation-name: fill2; }
.demo i:nth-child(3)::after { animation-name: fill3; }
.demo b { width: 22px; height: 22px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; font-size: 13px; animation: ok 4s infinite; }
@keyframes fill  { 0% { transform: scaleX(0); } 20%,100% { transform: scaleX(1); } }
@keyframes fill2 { 0%,22% { transform: scaleX(0); } 42%,100% { transform: scaleX(1); } }
@keyframes fill3 { 0%,45% { transform: scaleX(0); } 65%,100% { transform: scaleX(1); } }
@keyframes ok { 0%,66% { transform: scale(.3); opacity: 0; } 74%,100% { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } .demo i::after { transform: scaleX(1); } .demo b { opacity: 1; } }

/* Objekte auf der Seite */
.obj { position: absolute; white-space: pre; cursor: move; user-select: none; touch-action: none; }
.obj.text { padding-left: 0; overflow: visible; }
.obj.sel { outline: 1.5px dashed var(--red); outline-offset: 2px; }
.obj.image img { width: 100%; height: 100%; display: block; pointer-events: none; }
.obj-tools {
  position: absolute; z-index: 6; display: flex; gap: 6px; padding: 4px; border-radius: 10px;
  background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.2); touch-action: none;
}
.obj-tools button { width: 34px; height: 34px; padding: 0; font-size: 17px; line-height: 1; border-radius: 8px; }
.obj-tools .tool-move { cursor: move; color: var(--red); font-size: 20px; }
.obj-tools .tool-delete { color: var(--red); }
.obj .handle { touch-action: none; }
.obj .handle {
  position: absolute; right: -6px; bottom: -6px; width: 11px; height: 11px;
  background: #fff; border: 1.5px solid var(--red); cursor: nwse-resize;
}
.editor {
  position: absolute; border: 1.5px solid var(--red); border-radius: 3px; outline: none; padding: 0;
  background: rgba(217,0,26,.08); margin: 0; z-index: 5; min-width: 20px;
}
.move-handle {
  position: absolute; width: 18px; height: 18px; border-radius: 4px; background: var(--red); z-index: 6; cursor: move;
  touch-action: none;
}
.move-handle::before, .move-handle::after { content: ""; position: absolute; background: #fff; }
.move-handle::before { left: 8px; top: 3px; width: 2px; height: 12px; }
.move-handle::after { top: 8px; left: 3px; height: 2px; width: 12px; }
.guide { position: absolute; top: 0; bottom: 0; width: 9px; margin-left: -4px; cursor: ew-resize; z-index: 3; }
.guide::before { content: ""; position: absolute; left: 4px; top: 0; bottom: 0; border-left: 1px dashed var(--red); }
.guide .grip {
  position: absolute; top: 0; left: -4px; width: 16px; height: 22px; border-radius: 0 0 4px 4px;
  background: var(--red); cursor: grab;
}
.guide .grip::after { content: ""; position: absolute; left: 5px; right: 5px; top: 6px; bottom: 6px; border-left: 1.2px solid #fff; border-right: 1.2px solid #fff; }

/* Seitenleiste */
.inspector { width: 290px; overflow-y: auto; padding: 12px; background: var(--soft); border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.inspector > * { flex-shrink: 0; }
.preview { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow: hidden; }
.preview span { display: inline-block; max-width: 100%; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.preview .hint { margin-top: 6px; }
.saved-styles { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.saved-styles:empty { display: none; }
.saved-style { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.saved-style button { border: 0; border-radius: 0; padding: 4px 10px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
.saved-style .remove { padding: 4px 8px; color: var(--muted); border-left: 1px solid var(--line); }
.preview #saveStyle { margin-top: 8px; }
.preview small { display: block; text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 9px; }
.box h3 { margin: 0; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.row { display: flex; align-items: center; gap: 6px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row input[type=range] { flex: 1; }
.grow { flex: 1; }
.swatches { display: grid; grid-template-columns: repeat(6, 30px); gap: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); padding: 0; position: relative; }
.squares .swatch { border-radius: 5px; }
.swatch.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--red); }
.swatch.none { background: #fff; color: var(--muted); font-size: 16px; line-height: 1; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.check { display: flex; gap: 6px; align-items: center; }
.keys div { font-size: 12px; color: var(--muted); }
kbd { display: inline-block; min-width: 92px; font: 600 11px ui-monospace, Menlo, monospace; color: var(--ink); }
.legal { font-size: 12px; color: var(--muted); text-align: center; margin: 2px 0 10px; }
.legal a { color: var(--muted); }

/* Statuszeile */
.status { display: flex; justify-content: space-between; gap: 12px; padding: 6px 14px; font-size: 12px; color: var(--muted); background: #fff; border-top: 1px solid var(--line); }
.status .lock { color: var(--red); white-space: nowrap; }

/* Unterschrift */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.dialog { background: #fff; border-radius: 14px; padding: 22px; width: min(608px, 100%); display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dialog h2 { margin: 0; font-size: 20px; }
#signPad.pen-down { box-shadow: 0 0 0 2px var(--red); }
#signPad {
  width: 100%; aspect-ratio: 560 / 200; border: 1px solid var(--line); border-radius: 10px; touch-action: none; cursor: crosshair;
  background: linear-gradient(to top, transparent 22%, #c9c9cf 22%, #c9c9cf calc(22% + 1px), transparent calc(22% + 1px)) no-repeat;
  background-size: calc(100% - 48px) 100%; background-position: center;
}

.panel-toggle { display: none; }
.guide { touch-action: none; }
@media (max-width: 900px) {
  /* Seitenleiste als ausklappbares Feld, damit Stil und Ausrichten auch auf Tablets erreichbar bleiben. */
  .inspector {
    position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; width: min(320px, 88vw);
    transform: translateX(100%); transition: transform .2s ease; box-shadow: -8px 0 30px rgba(0,0,0,.2);
  }
  .inspector.open { transform: none; }
  .panel-toggle { display: inline-block; }
  .tools .sep { display: none; }
  .bar { flex-wrap: wrap; }
}

/* Finger statt Maus: größere Griffe */
@media (pointer: coarse) {
  .obj .handle { width: 28px; height: 28px; right: -14px; bottom: -14px; border-radius: 50%; border-width: 2px; }
  .obj-tools button { width: 44px; height: 44px; font-size: 20px; }
  .guide { width: 24px; margin-left: -12px; }
  .guide::before { left: 12px; }
  .guide .grip { left: 2px; width: 20px; height: 30px; }
}
