/* ==========================================================================
   Grafik — Oberfläche
   Grundriss C: Einstellungen links, Bühne mittig, Fotos rechts.
   Die Oberfläche hält sich farblich zurück; die Farbe kommt aus den Fotos.
   ========================================================================== */

/* Die eigenen Schriften laufen über denselben Spiegel wie die des Nutzers —
   kein Kontakt zwischen Browser und Google. */
@font-face { font-family: "UI"; font-weight: 500; font-display: swap;
             src: url("/api/font/Archivo/500.woff2") format("woff2"); }
@font-face { font-family: "UI"; font-weight: 600; font-display: swap;
             src: url("/api/font/Archivo/600.woff2") format("woff2"); }
@font-face { font-family: "UI"; font-weight: 700; font-display: swap;
             src: url("/api/font/Archivo/700.woff2") format("woff2"); }
@font-face { font-family: "Mono"; font-weight: 400; font-display: swap;
             src: url("/api/font/IBM%20Plex%20Mono/400.woff2") format("woff2"); }
@font-face { font-family: "Mono"; font-weight: 500; font-display: swap;
             src: url("/api/font/IBM%20Plex%20Mono/500.woff2") format("woff2"); }

:root {
  --paper:   #FAF9F6;
  --surface: #FFFFFF;
  --sunk:    #F2F0EB;
  --ink:     #16181C;
  --muted:   #6B7078;
  --rule:    #E2DFD8;
  --accent:  #0A7C8A;
  --accent-soft: #0A7C8A18;
  --mark:    #B23A55;
  --shadow:  0 1px 2px rgba(20,24,30,.07), 0 8px 22px rgba(20,24,30,.10);

  --ui:   "UI", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --r: 6px;
  --pad: 14px;
  --side: 272px;
  --lib: 208px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:   #131519;
    --surface: #1B1E24;
    --sunk:    #0E1014;
    --ink:     #EBECEE;
    --muted:   #969DA7;
    --rule:    #2C3038;
    --accent:  #45B8C8;
    --accent-soft: #45B8C822;
    --mark:    #DB7C90;
    --shadow:  0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.45);
  }
}
:root[data-theme="dark"] {
  --paper: #131519; --surface: #1B1E24; --sunk: #0E1014;
  --ink: #EBECEE; --muted: #969DA7; --rule: #2C3038;
  --accent: #45B8C8; --accent-soft: #45B8C822; --mark: #DB7C90;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

/* Muss nach allen display-Regeln greifen: .picker und .slotbar setzen selbst
   ein display, das sonst das hidden-Attribut aushebelt — das Overlay läge
   dann unsichtbar über der Seite und finge jeden Klick ab. */
[hidden] { display: none !important; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 500 13px/1.45 var(--ui);
  -webkit-font-smoothing: antialiased;
}

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

/* ------------------------------------------------------------ Kopfzeile */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  position: relative;
  z-index: 30;
}
.brand { font-weight: 700; letter-spacing: -.01em; font-size: 14px; }
.docname {
  font: 400 12.5px var(--mono);
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 6px;
  width: 15ch;
}
.docname:hover  { border-color: var(--rule); }
.docname:focus  { border-color: var(--accent); color: var(--ink); outline: none; }
.savestate { font: 400 11px var(--mono); color: var(--muted); min-width: 7ch; }
.spacer { flex: 1; }

/* --------------------------------------------------------------- Knöpfe */

.btn {
  font: 600 12.5px var(--ui);
  padding: 6px 11px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--sunk); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { filter: brightness(1.08); }
.btn.quiet { color: var(--muted); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.danger { color: var(--mark); }

/* Menüs */
.menu { position: relative; }
.pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 5px;
  z-index: 40;
}
.pop.right { left: auto; right: 0; }
.pop button {
  display: block;
  width: 100%;
  text-align: left;
  font: 600 12.5px var(--ui);
  padding: 7px 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.pop button:hover { background: var(--sunk); }
.pop button small {
  display: block;
  font: 400 11px var(--ui);
  color: var(--muted);
  margin-top: 1px;
}
.pop hr { border: 0; border-top: 1px solid var(--rule); margin: 5px 2px; }

/* ---------------------------------------------------------------- Aufbau */

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

.settings, .library {
  flex: none;
  background: var(--surface);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.settings { width: var(--side); border-right: 1px solid var(--rule); }
.library  { width: var(--lib);  border-left:  1px solid var(--rule);
            display: flex; flex-direction: column; overflow: hidden; }

/* ------------------------------------------------------ Einstellungen */

.ai {
  padding: var(--pad);
  border-bottom: 1px solid var(--rule);
  background: var(--accent-soft);
}
.ai textarea {
  width: 100%;
  margin: 5px 0 8px;
  padding: 8px;
  font: 500 12.5px/1.45 var(--ui);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  resize: vertical;
  min-height: 58px;
}
.ai textarea:focus { border-color: var(--accent); outline: none; }
.note { font: 400 11.5px/1.45 var(--ui); color: var(--muted); margin: 8px 0 0; }
.note.warn { color: var(--mark); }

.group { border-bottom: 1px solid var(--rule); }
.group > summary {
  padding: 11px var(--pad);
  font: 600 11px var(--ui);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 7px;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before {
  content: "";
  width: 5px; height: 5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .15s;
}
.group[open] > summary::before { transform: rotate(45deg); }
.group > summary:hover { color: var(--ink); }
.group .body { padding: 2px var(--pad) var(--pad); }

/* Bedienelemente */

.ctl { display: block; margin-bottom: 11px; }
.ctl:last-child { margin-bottom: 0; }
.ctl-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font: 500 11.5px var(--ui);
  color: var(--muted);
  margin-bottom: 4px;
}
.ctl-head output { font: 400 11.5px var(--mono); color: var(--ink); font-variant-numeric: tabular-nums; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input[type=text], input[type=search], select, textarea, .fontbtn {
  width: 100%;
  padding: 6px 8px;
  font: 500 12.5px var(--ui);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r);
}
input[type=text]:focus, input[type=search]:focus, select:focus { border-color: var(--accent); outline: none; }
.fontbtn { text-align: left; cursor: pointer; }
.fontbtn:hover { background: var(--sunk); }

input[type=range] {
  width: 100%;
  accent-color: var(--accent);
  height: 18px;
}
input[type=color] {
  width: 100%; height: 28px; padding: 2px;
  border: 1px solid var(--rule); border-radius: var(--r);
  background: var(--surface); cursor: pointer;
}

/* Umschaltgruppe */
.seg { display: flex; gap: 3px; margin-bottom: 11px; background: var(--sunk); padding: 3px; border-radius: var(--r); }
.seg button {
  flex: 1;
  font: 600 11.5px var(--ui);
  padding: 5px 2px;
  border: 0; border-radius: 4px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(20,24,30,.10); }

/* Farbfelder */
.colors { display: flex; gap: 6px; align-items: center; }
.colors input[type=color] { width: 42px; }
.colors .btn { padding: 5px 8px; font-size: 15px; line-height: 1; }

/* Grundformen als Vorschau-Kacheln */
.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.presets button {
  aspect-ratio: 1;
  display: grid; place-items: center;
  padding: 5px;
  border: 1px solid var(--rule); border-radius: var(--r);
  background: var(--surface); cursor: pointer;
}
.presets button:hover { border-color: var(--accent); }
.presets button.on { border-color: var(--accent); background: var(--accent-soft); }
.presets svg { width: 100%; height: 100%; display: block; }
.presets svg path, .presets svg circle, .presets svg polygon { fill: var(--muted); }
.presets button.on svg path, .presets button.on svg circle, .presets button.on svg polygon { fill: var(--accent); }

.checkline { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkline input { accent-color: var(--accent); width: 15px; height: 15px; }
.checkline span { color: var(--muted); font-size: 12.5px; }

.palettes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.palettes button {
  height: 26px; padding: 0;
  border: 1px solid var(--rule); border-radius: 4px;
  cursor: pointer; overflow: hidden; display: flex;
}
.palettes button span { flex: 1; }
.palettes button:hover { border-color: var(--accent); }

/* Beschriftungszeilen */
.textitem { border: 1px solid var(--rule); border-radius: var(--r); padding: 10px; margin-bottom: 10px; }
.textitem .top { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.textitem .top input { flex: 1; }
.textitem .del {
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; padding: 4px 6px; border-radius: 4px; font-size: 13px;
}
.textitem .del:hover { color: var(--mark); background: var(--sunk); }

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

.stage {
  flex: 1;
  min-width: 0;
  background: var(--sunk);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px;
  gap: 12px;
  position: relative;
}
.sheet-wrap {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#sheet {
  box-shadow: var(--shadow);
  border-radius: 1px;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}
#sheet.grab { cursor: grab; }
#sheet.grabbing { cursor: grabbing; }
#sheet.drop-target { outline: 2px solid var(--accent); outline-offset: 3px; }

.legend { flex: none; margin: 0; font-size: 11.5px; color: var(--muted); text-align: center; }
.legend b { color: var(--ink); font-weight: 600; }

.slotbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.slotbar-title { font: 400 11px var(--mono); color: var(--muted); }
.slotbar button {
  font: 600 12px var(--ui);
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  padding: 5px 9px;
  cursor: pointer;
}
.slotbar button:hover { background: var(--sunk); }
.slotbar .zoom { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); }
.slotbar .zoom input { width: 96px; }

/* --------------------------------------------------------------- Fotos */

.lib-head {
  flex: none;
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px var(--pad);
  font: 600 11px var(--ui);
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--rule);
}
.lib-head .count { font: 400 11px var(--mono); letter-spacing: 0; text-transform: none; }

.lib-grid {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 10px;
  align-content: start;
}
.lib-grid .empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
  padding: 28px 6px;
  line-height: 1.6;
}
.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 4px;
  overflow: hidden;
  cursor: grab;
  background: var(--sunk);
  border: 1.5px solid transparent;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.thumb.unplaced { border-color: var(--mark); }
.thumb.active   { border-color: var(--accent); }
.thumb:hover::after {
  content: "";
  position: absolute; inset: 0;
  box-shadow: inset 0 0 0 2px var(--accent);
  border-radius: 3px;
}
.thumb .badge {
  position: absolute; right: 2px; bottom: 2px;
  font: 500 9px var(--mono);
  background: rgba(0,0,0,.62); color: #fff;
  padding: 1px 3px; border-radius: 2px;
}

.lib-foot { flex: none; padding: 10px; border-top: 1px solid var(--rule); display: grid; gap: 6px; }
.lib-hint {
  display: flex; flex-direction: column; gap: 5px;
  font: 500 11.5px var(--ui); color: var(--mark);
  padding: 7px 8px;
  border: 1px solid var(--mark); border-radius: var(--r);
  background: color-mix(in srgb, var(--mark) 8%, transparent);
}
.lib-hint button {
  font: 600 11.5px var(--ui);
  border: 1px solid var(--mark); border-radius: 4px;
  background: transparent; color: var(--mark);
  padding: 4px 8px; cursor: pointer;
}
.lib-hint button:hover { background: color-mix(in srgb, var(--mark) 14%, transparent); }
.lib-foot .row { display: flex; gap: 6px; }
.lib-foot .row .btn { flex: 1; }

/* ------------------------------------------------------- Schriftauswahl */

.picker {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20,24,30,.34);
  display: grid; place-items: center;
  padding: 24px;
}
.picker-box {
  width: min(560px, 100%);
  max-height: min(620px, 88vh);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.picker-box > header { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--rule); }
.picker-box > footer {
  padding: 8px 12px; border-top: 1px solid var(--rule);
  font: 400 11px var(--mono); color: var(--muted);
}
.chips { display: flex; gap: 5px; flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid var(--rule); }
.chips button {
  font: 600 11.5px var(--ui);
  padding: 4px 10px;
  border: 1px solid var(--rule); border-radius: 20px;
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.chips button.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.picker-list { flex: 1; overflow-y: auto; padding: 6px; }
.fontrow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%;
  padding: 9px 11px;
  border: 0; border-radius: var(--r);
  background: transparent; cursor: pointer;
  text-align: left;
}
.fontrow:hover { background: var(--sunk); }
.fontrow.on { background: var(--accent-soft); }
.fontrow .sample {
  font-size: 21px; line-height: 1.25; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fontrow .meta { font: 400 10.5px var(--mono); color: var(--muted); flex: none; }

/* ------------------------------------------------------------- Sonstiges */

.dropzone {
  position: fixed; inset: 0; z-index: 50;
  display: none; place-items: center;
  background: var(--accent-soft);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.dropzone.on { display: grid; }
.dropzone span {
  background: var(--surface);
  border: 2px dashed var(--accent);
  color: var(--accent);
  font-weight: 700; font-size: 15px;
  padding: 20px 32px; border-radius: 10px;
}

.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  z-index: 70;
  background: var(--ink); color: var(--paper);
  font: 600 12.5px var(--ui);
  padding: 9px 16px; border-radius: 20px;
  box-shadow: var(--shadow);
  max-width: min(520px, 90vw);
}
.toast.err { background: var(--mark); color: #fff; }

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

@media (max-width: 1120px) {
  .library { width: 168px; }
  .lib-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  main { flex-direction: column; }
  .settings, .library { width: 100%; max-height: 34vh; border: 0; border-bottom: 1px solid var(--rule); }
  .library { order: 3; border-bottom: 0; border-top: 1px solid var(--rule); }
  .lib-grid { grid-template-columns: repeat(6, 1fr); }
  .stage { order: 2; }
}
