/* Fine-Art-Planer – Stil angelehnt an formspace.art: schwarze Kopfzeile, Buttons in Grau und Rot, leichte Schrift, eckige Formen.
   Schriften: Raleway (Überschriften) und Roboto (Text), selbst gehostet in fonts/ –
   keine Verbindung zu Google (Datenschutz). Variable Schriften: eine Datei deckt alle Stärken ab. */
@font-face {
  font-family: Raleway; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url(../fonts/raleway-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: Raleway; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url(../fonts/raleway-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: Roboto; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url(../fonts/roboto-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: Roboto; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url(../fonts/roboto-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f9f9f9;
  --surface: #ffffff;
  --line: #e3e5df;
  --line-strong: #caced8;
  --text: #323335;
  --muted: #6f7074;
  --accent: #c8102e;        /* Rot (Fine-Art-Planer) */
  --accent-dark: #8f0b20;   /* dunkles Rot */
  --accent-ink: #ffffff;
  --accent-soft: #fbe7ea;
  --grey: #5f6368;          /* Grau für normale Buttons */
  --grey-dark: #3c4043;
  --grey-soft: #eceded;
  --top: #000000;
  --stage: #1c1c1c;
  --warn: #a5381c;
  --font: Roboto, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-head: Raleway, "Segoe UI Light", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
/* Kein Doppeltipp-Zoom des Browsers; Zwei-Finger-Zoom der Seite bleibt möglich */
html { touch-action: manipulation; }
body {
  font: 300 15px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
b, strong { font-weight: 500; }

/* Kopfzeile */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; background: var(--top); color: #fff;
  flex: none;
}
.brand {
  font: 300 20px/1 var(--font-head); letter-spacing: .02em;
  display: flex; align-items: center; gap: 10px; white-space: nowrap;
}
.logo { height: 34px; width: auto; display: block; }
.logo-link { display: block; flex: none; }
.brand-sub {
  font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: rgba(255,255,255,.7);
  padding-left: 12px; border-left: 1px solid rgba(255,255,255,.3); text-decoration: none;
}
a.brand-sub:hover { color: #fff; }
.card-links { margin: 8px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.card-links a { color: var(--accent); text-decoration: none; }
.card-links a:hover { text-decoration: underline; }

.shop-link { margin: 0 0 12px; }

/* Schritt 1: Kunstwerk wählen */
.start-card.pick-card { max-width: 920px; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-top: 4px; }
.pick-grid .swatch { font-size: 13px; padding: 3px; gap: 6px; }
.pick-grid .swatch img { aspect-ratio: 1 / 1; object-fit: contain; background: #f1f1f1; padding: 6px; }   /* Kunstwerke ganz zeigen, nicht beschneiden */
.pick-grid .swatch:hover img { filter: brightness(1.05); }
.picked { margin: 0; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.picked img { width: 36px; height: 54px; object-fit: cover; flex: none; }
.picked b { color: var(--text); font-weight: 500; }
.picked button { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
.picked button:hover { text-decoration: underline; }
@media (max-width: 560px) { .pick-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }

/* Kategorien (Seite 1 und Verwaltung) */
.cat-bar { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-tab {
  font: inherit; font-size: 13px; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
}
.cat-tab:hover { border-color: var(--accent); color: var(--accent); }
.cat-tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.cat-tab.over { outline: 2px dashed var(--accent); outline-offset: 2px; }

/* Verwaltung */
.start-card.admin-card { max-width: 1100px; }
.cat-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-tools .btn:disabled { opacity: .4; cursor: default; }
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center;
  min-height: 140px; padding: 20px; border: 2px dashed var(--line-strong); background: var(--bg); cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.busy { opacity: .6; pointer-events: none; }
.drop b { font-weight: 500; color: var(--accent-dark); font-size: 16px; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.admin-item { margin: 0; display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--line); padding: 6px; background: var(--surface); }
.admin-item img { width: 100%; aspect-ratio: 1 / 1; object-fit: contain; display: block; background: var(--bg); }
.admin-item figcaption { display: flex; flex-direction: column; font-size: 13px; min-width: 0; }
.admin-item figcaption small { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.admin-actions { display: flex; gap: 6px; }
.admin-actions select { min-height: 32px; font-size: 12px; flex: 1; min-width: 0; }

/* Infoseiten (Fine-Art-Planer, Impressum) */
.doc { overflow: auto; }
.doc .start-card { max-width: 720px; }
.doc h2 { font: 300 20px/1.3 var(--font-head); color: var(--accent-dark); margin: 18px 0 4px; }
.doc p, .doc li { margin: 4px 0; }
.doc ol, .doc ul { padding-left: 20px; margin: 4px 0; }
.doc .todo { background: #fff3cd; padding: 0 4px; }
@media (max-width: 560px) {
  .logo { height: 26px; }
  .brand-sub { display: none; }
}
.steps { display: flex; gap: 22px; font-size: 14px; color: rgba(255,255,255,.6); }
.steps .step {
  font: inherit; color: inherit; background: none; border: 0; border-bottom: 1px solid transparent;
  padding: 0 0 3px; cursor: pointer; white-space: nowrap;
}
.steps .step:hover:not(:disabled) { color: #fff; }
.steps .step:disabled { cursor: default; opacity: .45; }
.steps .step.on { color: #fff; border-bottom-color: #fff; opacity: 1; cursor: default; }
.steps .logout {
  color: rgba(255,255,255,.6); text-decoration: none; padding-left: 18px; margin-left: -4px;
  border-left: 1px solid rgba(255,255,255,.3);
}
.steps .logout:hover { color: #fff; }
.steps .ts, .ico-logout { display: none; }
.ico-logout { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; }
@media (max-width: 560px) {
  /* Handy: alles muss in eine Zeile passen, ☰ immer sichtbar */
  .topbar { padding: 10px 12px; gap: 10px; }
  .brand { min-width: 0; flex-shrink: 1; }
  .logo { height: 22px; }
  .steps { gap: 10px; font-size: 13px; min-width: 0; }
  .steps .t { display: none; }                    /* lange Namen aus */
  .steps .step.on .ts { display: inline; }        /* aktueller Schritt mit Kurzname */
  .steps .step { padding-left: 2px; padding-right: 2px; }
  .steps .logout { padding-left: 10px; margin-left: 0; display: inline-flex; }
  .ico-logout { display: block; }
  .menu-btn { width: 36px; height: 36px; margin-left: 0; }
}

.app { flex: 1; min-height: 0; display: flex; }
.screen { flex: 1; min-height: 0; min-width: 0; }

/* Startbildschirm */
.start {
  overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px;
  background: linear-gradient(160deg, var(--grey-dark) 0%, #9a9da1 100%);
}
.start-card {
  width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 12px; margin: auto 0;
  background: var(--surface); padding: 32px 28px;
}
.start h1 { font: 300 28px/1.25 var(--font-head); margin: 0; color: var(--accent-dark); }
.lead { margin: 0 0 8px; color: var(--muted); }
.tips { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.tips li { margin: 4px 0; }
.error { color: var(--warn); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 18px; border-radius: 0;
  border: 1px solid var(--grey); background: var(--grey); color: #fff;
  font: inherit; font-weight: 400; cursor: pointer; text-align: center;
  transition: background-color .15s, border-color .15s, color .15s;
}
/* Fine-Art-Planer: normale Buttons grau, Hauptaktionen rot, zurückhaltende Buttons hellgrau */
.btn:hover { background: var(--grey-dark); border-color: var(--grey-dark); color: #fff; }
a.btn { text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: var(--accent-ink); }
.btn.ghost { background: var(--grey-soft); border-color: var(--grey-soft); color: var(--grey-dark); }
.btn.ghost:hover { background: #dcdddd; border-color: #dcdddd; color: var(--grey-dark); }
.btn:disabled { opacity: .45; cursor: default; }
.seg-wrap { flex-wrap: wrap; }
.seg.seg-wrap button { flex: 1 1 30%; border-top: 1px solid var(--line-strong); margin-top: -1px; }
.color-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.color-row input[type=color] { width: 44px; height: 28px; padding: 0; border: 1px solid var(--line-strong); background: none; cursor: pointer; }
.btn.big { min-height: 54px; font-size: 17px; }
.btn.small { min-height: 34px; font-size: 13px; padding: 0 12px; }

/* Editor */
.editor { display: flex; }
.stage {
  flex: 1; min-width: 0; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  background: var(--stage); overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.view { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
#gl, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { overflow: visible; }
#loupe {
  position: absolute; width: 140px; height: 140px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 4px 16px rgba(0,0,0,.45); pointer-events: none;
}
.hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  background: rgba(0,0,0,.7); color: #fff; font-size: 12.5px; padding: 6px 14px; border-radius: 0;
  pointer-events: none; white-space: nowrap; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis;
}

/* Overlay-Elemente */
.grid { fill: none; stroke: rgba(255,255,255,.55); }
.quad { fill: rgba(200,16,46,.16); stroke: #ff5a6e; stroke-linejoin: round; }
.quad.bad { stroke: #ff4d4d; fill: rgba(255,77,77,.18); }
.handle { fill: #fff; stroke: var(--accent); }
.handle-num { fill: var(--accent); font-weight: 500; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.edge-label { fill: #fff; stroke: rgba(0,0,0,.65); paint-order: stroke; font-weight: 500; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.rug-frame { fill: none; stroke: rgba(255,255,255,.75); pointer-events: none; }
.handle.hot, .corner.hot .handle { fill: var(--accent); stroke: #fff; }
.handle-ico { fill: none; stroke: var(--accent); stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.corner.hot .handle-ico { stroke: #fff; }

/* Drehung in „Form & Größe“: Gradzahl als Knopf (Klick = gerade) */
.rot-row { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.rot-row > span { margin-right: auto; }
.rot-row .btn.small { min-height: 30px; padding: 0 10px; }
.deg {
  font: inherit; font-size: 14px; min-width: 64px; padding: 6px 12px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
}
.deg:hover { border-color: var(--accent); color: var(--accent); }.brush { fill: rgba(255,255,255,.12); stroke: #fff; }

/* Seitenleiste */
.panel {
  width: 340px; flex: none; overflow-y: auto; background: var(--surface);
  border-left: 1px solid var(--line); padding: 20px;
}
.panel h2 { margin: 0 0 10px; font: 300 22px/1.2 var(--font-head); color: var(--accent-dark); }
.muted { color: var(--muted); margin: 0 0 12px; }
.small { font-size: 12.5px; }
.panel .rug-name { margin: -6px 0 12px; overflow-wrap: anywhere; }
.rug-tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.rug-tools .btn { flex: 1 1 auto; }
.warn { color: var(--warn); font-weight: 500; margin: 8px 0; }

.group { border-top: 1px solid var(--line); padding: 0; }
.group .muted { margin: 0; }
.sec { display: flex; flex-direction: column; gap: 8px; padding: 0 0 14px; }

/* Klappleisten */
.group > summary {
  list-style: none; cursor: pointer; padding: 14px 0; user-select: none; -webkit-user-select: none;
  align-items: center; justify-content: flex-start;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before {
  content: ""; width: 7px; height: 7px; margin-right: 10px; flex: none;
  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 output { margin-left: auto; }
.group > summary:hover { color: var(--accent-dark); }
.group > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.label {
  font: 500 12px/1.4 var(--font-head); text-transform: uppercase; letter-spacing: .1em;
  color: var(--accent); display: flex; justify-content: space-between;
}
.label output { color: var(--text); text-transform: none; letter-spacing: 0; font-family: var(--font); font-weight: 400; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.unit { display: flex; align-items: center; gap: 6px; color: var(--text); }
input.text { min-height: 46px; font-size: 16px; }
input[type=number], input.text, select {
  width: 100%; min-height: 38px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 0;
  font: inherit; color: var(--text); background: var(--surface);
}
input[type=number]:focus, input.text:focus, select:focus { outline: none; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
.check.off { color: var(--muted); cursor: default; }
.check input:disabled { cursor: default; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.slider { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.group .chips { margin: 0; }
.chips button, .seg button {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 0;
  border: 1px solid var(--line-strong); background: var(--grey-soft); color: var(--grey-dark); cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.seg { display: flex; gap: 0; border: 1px solid var(--line-strong); }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 6px; }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 400; }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.swatch {
  border: 2px solid transparent; border-radius: 0; padding: 2px; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font: inherit; font-size: 11.5px; color: var(--muted);
}
.swatch img { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 0; display: block; background: var(--bg); }
.swatch:hover { border-color: var(--line-strong); }
.swatch.on { border-color: var(--accent); color: var(--text); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
#panelCalib .actions { border-top: 0; }
/* Buttons unten im Bedienfeld immer sichtbar */
#panelPlace .actions {
  position: sticky; bottom: -20px; background: var(--surface);
  margin: 0 -20px -20px; padding: 14px 20px 20px;
}

/* ☰-Menü */
.menu-btn {
  width: 40px; height: 40px; flex: none; margin-left: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff; cursor: pointer; padding: 0;
}
.menu-btn:hover { border-color: #fff; }
.menu-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: square; }
.menu-btn .ico-close { display: none; }
.menu-btn[aria-expanded="true"] .ico-close { display: block; }
.menu-btn[aria-expanded="true"] .ico-menu { display: none; }
.topbar { gap: 16px; }
.steps { margin-left: auto; }

body.panel-closed .panel { display: none; }
.fab-save { position: absolute; right: 12px; bottom: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.35); }
/* Platz für den Speichern-Knopf: Hinweis nach links rücken */
body.panel-closed .hint { left: 12px; transform: none; max-width: calc(100% - 170px); }
.actions .primary { margin-left: auto; }

/* Smartphone: Bild oben, Bedienung unten */
@media (max-width: 820px) {
  .editor { flex-direction: column; }
  .panel { width: auto; max-height: 46%; border-left: 0; border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  #panelPlace .actions {
    bottom: calc(-12px - env(safe-area-inset-bottom)); margin: 0 -16px calc(-12px - env(safe-area-inset-bottom));
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  }
}
