:root {
  --brand: #00497d; --ink: #10283a; --ink-soft: #55677a; --paper: #f3f5f7; --card: #ffffff; --line: #d6dde4;
  --accent: #00497d; --accent-ink: #ffffff; --ok: #2b8a3e; --bad: #c92a2a;
  --radius: 12px; --pad: 16px;
}
* { box-sizing: border-box; }
html { height: 100%; }
body { height: var(--vh, 100%); overflow: hidden; margin: 0; font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--paper);
  display: flex; flex-direction: column; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

#bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--brand); color: #fff; }
#bar .brand { background: none; border: 0; color: #fff; font-weight: 700; font-size: 17px; padding: 6px 4px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
#bar .brand .ver { font-weight: 500; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; border: 1px solid #ffffff88; border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.grow { flex: 1; }
.chip { border: 1px solid #ffffff55; background: transparent; color: #fff; border-radius: 999px; padding: 6px 12px; font-size: 14px; display: flex; align-items: center; gap: 6px; max-width: 34vw; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #8a93a6; flex: none; }
.chip.on::before { background: #51cf66; }
#langSel { background: transparent; color: #fff; border: 1px solid #ffffff55; border-radius: 8px; padding: 5px 6px; font-size: 14px; }
#langSel option { color: #000; }

#app { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.page { width: 100%; max-width: 720px; margin: 0 auto; padding: var(--pad); overflow: auto; }
.page h1 { font-size: 22px; margin: 8px 0 16px; }
.backlink { background: none; border: 0; color: var(--ink-soft); padding: 6px 0; font-size: 15px; }
.backlink::before { content: "‹ "; }

.choices { display: grid; gap: 12px; }
.choice { display: flex; align-items: center; gap: 14px; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; width: 100%; }
.choice:hover, .choice:focus-visible { border-color: var(--accent); outline: none; }
.choice b { display: block; font-size: 17px; }
.choice small { color: var(--ink-soft); font-size: 14px; }
.choice .ico { flex: none; width: 56px; height: 40px; display: grid; place-items: center; }
.choice .ico i { display: block; background: #fff; border: 2px solid var(--ink); border-radius: 3px; }
.group { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }

.form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 14px; }
.field { display: grid; gap: 4px; font-size: 14px; color: var(--ink-soft); }
.field input, .field select, .field textarea { color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-size: 16px; width: 100%; }
.field textarea { resize: vertical; min-height: 64px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--ink); }
.check input { width: 20px; height: 20px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 16px; font-size: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 7px 10px; font-size: 14px; }

/* Editor */
.editor { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ed-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.ed-head .title { flex: 1; min-width: 0; }
.ed-head .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-head .title small { color: var(--ink-soft); }
.tools { display: flex; gap: 6px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.tools .btn { white-space: nowrap; flex: 1 1 0; min-width: 0; }
.tools .sp { flex: 1; }
.stage { flex: 1 1 0; min-height: calc(var(--vh, 100vh) * .3); display: grid; place-items: center; padding: 12px; overflow: hidden;
  background: repeating-conic-gradient(#e9ebef 0 25%, #f4f5f7 0 50%) 0 0 / 16px 16px; }
.stage .canvas-container { box-shadow: 0 2px 10px #0003; background: #fff; }
.note { font-size: 13px; color: var(--bad); padding: 4px 12px; background: var(--card); }
/* Eigenschaften: feste, moderate Hoehe, damit die Zeichenflaeche sichtbar und ruhig bleibt */
.props { flex: none; height: calc(var(--vh, 100vh) * .34); background: var(--card); border-top: 1px solid var(--line); padding: 8px 12px 10px; overflow: auto; overscroll-behavior: contain; }
.props .hint { color: var(--ink-soft); font-size: 14px; margin: 4px 0; }
.props .quick { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; padding-bottom: 2px; }
.props .quick .btn { flex: none; white-space: nowrap; }
.props .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 10px; align-items: end; }
.props .grid .wide { grid-column: 1 / -1; }
.stepper { display: flex; gap: 6px; }
.stepper input { min-width: 0; text-align: center; }
.stepper .btn { flex: none; width: 42px; padding: 0; font-size: 20px; line-height: 1; }
/* Bildschirmtastatur offen: Zeichenflaeche behalten, Rest ausblenden */
body.kb .tools, body.kb .note, body.kb .props .tiles, body.kb .props .hint, body.kb .props .grid > :not(.keepkb) { display: none; }
body.kb .props { height: auto; max-height: calc(var(--vh, 100vh) * .5); }
body.kb .stage { min-height: calc(var(--vh, 100vh) * .4); }
@media (min-width: 900px), (orientation: landscape) and (max-height: 560px) and (min-width: 600px) {
  .editor { display: grid; grid-template-columns: 1fr 340px; grid-template-rows: auto auto auto minmax(0, 1fr); }
  .ed-head, .tools, .note { grid-column: 1 / -1; }
  .stage { grid-column: 1; grid-row: 4; min-height: 0; }
  .props { grid-column: 2; grid-row: 4; height: auto; border-top: 0; border-left: 1px solid var(--line); }
  body.kb .props { max-height: none; }
  body.kb .stage { min-height: 0; }
}
@media (max-width: 520px) {
  .ed-head .title small { display: none; }
  #bar { gap: 6px; padding-left: 10px; padding-right: 10px; }
  #bar .brand { font-size: 16px; gap: 6px; }
  #bar .brand .ver { font-size: 10px; padding: 0 6px; }
  .chip { max-width: none; font-size: 13px; padding: 5px 9px; }
}
@media (pointer: coarse) {
  .btn.small { min-height: 44px; padding: 8px 12px; }
  .field input, .field select, .field textarea { min-height: 44px; }
  .check input { width: 24px; height: 24px; }
  .check { min-height: 44px; }
}

/* Bibliothek */
.rec { display: flex; align-items: stretch; gap: 8px; }
.rec .choice { flex: 1; min-width: 0; }
.rec .choice b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec .choice .ico { width: 72px; height: 52px; }
.rec .choice .ico img { max-width: 72px; max-height: 52px; border: 1px solid var(--line); background: #fff; }
.rec .acts { display: grid; gap: 6px; align-content: center; }
.rec .bad { color: var(--bad); }
.toolrow { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.libnote { color: var(--ink-soft); font-size: 13px; margin-top: 14px; }

/* Dialoge */
#modal { position: fixed; inset: 0; background: #10283a99; display: grid; place-items: center; padding: 12px; z-index: 10; }
#modal[hidden] { display: none; }
.dialog { background: var(--card); border-radius: var(--radius); width: min(560px, 100%); max-height: 92vh; display: flex; flex-direction: column; }
.dialog header { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 18px; }
.dialog header .x { margin-left: auto; background: none; border: 0; font-size: 24px; line-height: 1; padding: 0 4px; }
.dialog .body { padding: 16px; overflow: auto; display: grid; gap: 14px; }
.dialog footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.preview { background: #e9ebef; border-radius: 8px; padding: 12px; display: grid; place-items: center; }
.preview canvas { max-width: 100%; max-height: 38vh; background: #fff; box-shadow: 0 1px 6px #0003; image-rendering: pixelated; }
.preview small { color: var(--ink-soft); margin-top: 8px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.msg { font-size: 15px; min-height: 22px; }
.msg.bad { color: var(--bad); } .msg.ok { color: var(--ok); }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.pgrid button { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; display: grid; gap: 4px; justify-items: center; font-size: 12px; color: var(--ink-soft); }
.pgrid button:hover { border-color: var(--accent); }
.pgrid img { width: 48px; height: 48px; object-fit: contain; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: 92vw; font-size: 15px; }
#toast[hidden] { display: none; }
.tsearch { width: 100%; box-sizing: border-box; font-size: 17px; padding: 12px 14px; margin: 0 0 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); }
.tsearch:focus { outline: none; border-color: var(--accent); }
.choice .ico .shp { display: block; fill: #fff; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.fchips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 4px; }
.fchip { position: relative; cursor: pointer; }
.fchip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.fchip span { display: block; padding: 9px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-size: 15px; min-height: 20px; }
.fchip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.fchip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.dialog .body:has(.ptabs) { display: flex; flex-direction: column; gap: 0; padding: 0; overflow: hidden; }
.psearch { flex: none; padding: 12px 16px 0; background: var(--card); }
.psearch input { width: 100%; box-sizing: border-box; min-height: 42px; padding: 8px 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.ptabs { flex: none; display: flex; flex-wrap: wrap; gap: 6px; max-height: 40%; overflow-y: auto; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--card); }
.ptabs button { flex: none; display: flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 36px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-size: 14px; line-height: 1.2; color: var(--ink); white-space: nowrap; }
.ptabs button small { font-size: 12px; color: var(--ink-soft); }
.ptabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.ptabs button.on small { color: #ffffffcc; }
#ppanel { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 16px; display: grid; gap: 14px; align-content: start; }
.dialog .body { min-height: 0; }
.fixedval { padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: #eef1f5; color: var(--ink); font-size: 16px; min-height: 22px; }

/* Kacheln fuer Objekt-Aktionen */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 62px; padding: 6px 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); font-size: 12.5px; line-height: 1.15; text-align: center; }
.tile:active { background: #e9eef4; }
.tile.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tile.danger { color: var(--bad); }
.edithead { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.edithead b { font-size: 16px; }
.pgrid.shapes { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.pgrid.shapes button { color: var(--ink); gap: 6px; padding: 12px 6px; font-size: 14px; }
.tools .btn { padding-left: 3px; padding-right: 3px; font-size: 13px; overflow: hidden; text-overflow: clip; }

.scanbox { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 4 / 3; }
.scanbox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanframe { position: absolute; inset: 18% 18%; border: 3px solid rgba(255,255,255,.85); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); pointer-events: none; }
