:root {
  color-scheme: light;
  --bg: #fff;
  --surface: #fff;
  --on-text: #fff;
  --text: #111;
  --muted: #767676;
  --gray: #efefef;
  --gray-hover: #e2e2e2;
  --red: #e60023;
  --red-hover: #ad081b;
  --field: #cdcdcd;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212; --surface: #232323; --on-text: #111; --text: #f1f1f1; --muted: #a3a3a3;
  --gray: #2a2a2a; --gray-hover: #3a3a3a; --field: #4a4a4a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121212; --surface: #232323; --on-text: #111; --text: #f1f1f1; --muted: #a3a3a3;
    --gray: #2a2a2a; --gray-hover: #3a3a3a; --field: #4a4a4a;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 "Helvetica Neue", Helvetica, Arial, -apple-system, sans-serif;
}
button, input, select { font: inherit; color: inherit; }

/* Kopfzeile */
.top {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  background: var(--bg); position: sticky; top: 0; z-index: 10;
}
.top h1 { margin: 0 16px 0 0; font-size: 32px; font-weight: 900; -webkit-text-stroke: 1.5px var(--red); color: var(--red); letter-spacing: -.03em; line-height: 1; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: none; font-weight: 600; padding: 12px 16px; border-radius: 10px; cursor: pointer; }
.tab:hover { background: var(--gray); }
.tab.active { background: var(--text); color: var(--on-text); }
.badge { font-size: 12px; color: var(--muted); margin-left: 2px; }
.tab.active .badge { color: var(--on-text); opacity: .6; }

main { padding: 8px 20px 48px; max-width: 1600px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }
hr { border: 0; border-top: 1px solid var(--gray-hover); margin: 16px 0; }

/* Buttons und Felder */
.btn {
  border: 0; background: var(--gray); font-weight: 600; padding: 12px 18px; border-radius: 10px; cursor: pointer;
  display: inline-block; text-align: center;
}
.btn:hover:not(:disabled) { background: var(--gray-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--red); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--red-hover); }
.btn.danger { color: var(--red); }
dialog.wide { width: min(920px, 94vw); max-height: 90vh; overflow: auto; }
dialog.wide h2 { margin: 0; }
.rotate { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.rotate .icon { width: 36px; height: 36px; flex: none; font-size: 18px; }
.rotate input[type=range] { flex: 1; accent-color: var(--text); }
.layer .rot {
  display: none; position: absolute; left: 50%; top: -32px; width: 18px; height: 18px; margin-left: -9px;
  background: #fff; border: 2px solid #0074e8; border-radius: 50%; cursor: grab;
}
.layer.selected .rot { display: block; }
.intro { max-width: 60ch; margin: 4px 0 16px; }
.combos { columns: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 24px 16px; align-items: start; }
.combo { margin: 0; }
.palette { display: flex; height: 150px; border-radius: 16px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.palette div { flex: 1; display: flex; align-items: flex-end; padding: 10px; font-size: 12px; font-weight: 600; }
.combo b { display: block; margin-top: 8px; font-size: 15px; }
.combo p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.top .backup { margin-left: auto; }
.top .menu { margin-left: auto; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; }
.pw-box { margin-bottom: 14px; }
.pw-msg { font-size: 14px; min-height: 20px; margin: 0 0 8px; }
.pw-msg.err { color: #c4202e; }
.set-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.set-head h2 { margin: 0; }
.set-head .icon { flex: none; }
.set-row {
  display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left;
  background: var(--gray); border: 0; border-radius: 10px; padding: 14px 16px; margin-bottom: 8px;
  font-weight: 600; cursor: pointer;
}
.set-row::after { content: "›"; font-size: 22px; line-height: 1; color: var(--muted); }
.set-row:hover { background: var(--gray-hover); }
.set-panel[hidden] { display: none; }
dialog h2 { margin: 0 0 8px; font-size: 22px; }
.dropbox { display: block; text-align: center; background: var(--gray); border: 2px dashed transparent; border-radius: 16px; padding: 28px 16px; margin: 8px 0 12px; cursor: pointer; font-weight: 600; }
.dropbox:hover { background: var(--gray-hover); }
.dropbox.over { border-color: var(--text); }
.batch { border-top: 1px solid var(--gray-hover); padding-top: 14px; margin-bottom: 14px; }
.batch[hidden] { display: none; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 10px; cursor: pointer; }
.btn.full { width: 100%; margin-bottom: 14px; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }

.field, .field-inline { display: flex; flex-direction: column; gap: 6px; font-size: 13px; margin-bottom: 14px; }
.field-inline { margin: 0; }
input[type=text], input[type=password], select {
  background: var(--surface); border: 2px solid var(--field); border-radius: 16px; padding: 11px 14px; width: 100%; font-size: 16px;
}
input[type=text]:focus, input[type=password]:focus, select:focus { outline: 0; border-color: #0074e8; }

/* Upload */
.upload {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--gray); border-radius: 24px; padding: 20px 24px; margin-bottom: 20px;
  border: 2px dashed transparent;
}
.upload p { margin: 2px 0 0; }
.upload.over { border-color: var(--text); }
.upload-actions { display: flex; gap: 12px; align-items: flex-end; }

/* Filter */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { border: 0; background: var(--gray); font-weight: 600; font-size: 14px; padding: 9px 14px; border-radius: 10px; cursor: pointer; }
.chip:hover { background: var(--gray-hover); }
.chip.active { background: var(--text); color: var(--on-text); }
.subchips { flex-basis: 100%; display: flex; gap: 8px; flex-wrap: wrap; }

/* Raster: alle Karten stehen in einer Reihe, gleich große Bildfelder */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 22px 16px; align-items: start; }
.card { margin: 0; display: block; width: 100%; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.card .img { --pad: 14px; position: relative; aspect-ratio: 4 / 5; background: var(--gray); border-radius: 16px; display: block; transition: background .15s; }
.card:hover .img { background: var(--gray-hover); }
.card .img img { position: absolute; inset: var(--pad); width: calc(100% - 2 * var(--pad)); height: calc(100% - 2 * var(--pad)); object-fit: contain; }
.card .meta { padding: 8px 4px 0; }
.card .meta b { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta span { font-size: 12px; color: var(--muted); }
.outfits { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.outfits .card { cursor: default; }
.outfits .card .img { --pad: 0px; aspect-ratio: 9 / 16; overflow: hidden; background: #fff; border: 1px solid var(--gray-hover); }
.card-actions { display: flex; gap: 6px; padding: 8px 0 0; }
.card-actions .btn { padding: 7px 12px; font-size: 13px; }

.empty { text-align: center; color: var(--muted); padding: 64px 0; display: none; }
.empty.show { display: block; }

/* Outfit bauen */
.builder { display: grid; grid-template-columns: 260px minmax(0, 1fr) 280px; gap: 24px; align-items: start; }
.picker { max-height: calc(100vh - 100px); overflow: auto; }
.panel { background: var(--gray); border-radius: 24px; padding: 20px; }
.picker .chips { margin-bottom: 12px; }
.picker-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.picker { min-width: 0; }
.pick { aspect-ratio: 1; border: 0; border-radius: 16px; background: var(--gray); padding: 8px; cursor: pointer; display: grid; place-items: center; }
.pick:hover { background: var(--gray-hover); }
.pick.active { box-shadow: inset 0 0 0 3px var(--text); }
.pick img { max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; }

.stage-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.layer-tools { display: flex; gap: 8px; }
.layer-tools[hidden] { display: none; }
.icon { width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--gray); cursor: pointer; display: grid; place-items: center; }
.icon:hover { background: var(--gray-hover); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--field); padding: 0; cursor: pointer; }
.swatch.active { box-shadow: 0 0 0 2px var(--gray), 0 0 0 4px var(--text); }
.swatch.custom { position: relative; overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.swatch.custom input { position: absolute; inset: -6px; width: 44px; height: 44px; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.panel .row { flex-wrap: nowrap; gap: 6px; }
.panel .row .btn { padding: 10px 12px; }
.panel .hint { margin: 16px 0 0; }
.stage {
  position: relative; width: 100%; max-width: 420px; aspect-ratio: 9/16; background: #fff;
  border: 1px solid var(--gray-hover); border-radius: 24px; overflow: hidden; touch-action: pan-y; user-select: none;
}
.stage-hint { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #aaa; padding: 24px; margin: 0; pointer-events: none; }
.layer { position: absolute; cursor: grab; touch-action: pan-y; }
.layer.selected { touch-action: none; } /* erst nach dem ersten Antippen ziehbar, sonst scrollt die Seite */
.layer img { display: block; width: 100%; height: auto; pointer-events: none; -webkit-user-drag: none; }
.layer.selected { outline: 2px solid #0074e8; outline-offset: 2px; }
.layer .handle {
  display: none; position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px;
  background: #fff; border: 2px solid #0074e8; border-radius: 50%; cursor: nwse-resize;
}
.layer.selected .handle { display: block; }

/* Dialoge */
dialog { border: 0; border-radius: 32px; background: var(--bg); color: var(--text); padding: 24px; width: min(400px, 92vw); box-shadow: 0 8px 40px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog img { display: block; width: 100%; max-height: 260px; object-fit: contain; background: var(--gray); border-radius: 16px; margin-bottom: 14px; padding: 8px; }
.up-preview {
  position: relative; height: 280px; display: block; overflow: auto; border-radius: 16px; margin-bottom: 12px; padding: 8px;
  background: repeating-conic-gradient(#ececec 0 25%, #fff 0 50%) 0 0 / 16px 16px; /* Schachbrett zeigt Transparenz */
}
.up-zoom { position: relative; --z: 1; width: calc(var(--z) * 100%); height: calc(var(--z) * 100%); display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; }
.up-zoom img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; background: none; padding: 0; margin: 0; border-radius: 0; }
.up-zoom.busy img { opacity: .4; }
.zoom-line { display: flex; align-items: flex-end; gap: 12px; }
.zoom-line label { flex: 1; font-size: 13px; }
.zoom-line input { margin-top: 6px; }
.zoom-line .btn { padding: 12px 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--on-text); padding: 12px 20px; border-radius: 12px; font-size: 14px; transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  main { padding: 8px 16px 48px; }
  .top { padding: 10px 16px; flex-wrap: wrap; }
}

/* ---------- iPad / Tablet ---------- */
@media (min-width: 701px) and (max-width: 1100px) and (orientation: portrait) {
  /* Bild links, Auswahl und Bedienfeld rechts: alles auf einen Blick */
  .builder { grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto 1fr; gap: 20px; }
  .stage-wrap { grid-column: 1; grid-row: 1 / span 2; }
  .picker { grid-column: 2; grid-row: 1; max-height: 46vh; }
  .panel { grid-column: 2; grid-row: 2; }
  .picker-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage { max-width: min(100%, calc(76vh * 9 / 16)); }
  .grid, .outfits { gap: 18px 14px; }
  .combos { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Handy ---------- */
dialog { max-height: 92vh; overflow: auto; }

@media (max-width: 700px) {
  /* Kopfzeile: Titel links, Sicherung rechts; Tabs wandern als Leiste nach unten */
  .top { padding: 10px 14px; flex-wrap: nowrap; }
  .top h1 { margin: 0; font-size: 26px; }
  .top .menu { width: 40px; height: 40px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; gap: 0;
    background: var(--bg); border-top: 1px solid var(--gray-hover);
    padding: 6px 8px calc(12px + env(safe-area-inset-bottom));
  }
  .tab { flex: 1; padding: 12px 4px; font-size: 14px; text-align: center; }
  main { padding: 4px 12px calc(96px + env(safe-area-inset-bottom)); }

  /* Raster: zwei Spalten */
  .grid, .outfits { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 10px; }
  .card .img { --pad: 8px; border-radius: 14px; }
  .card .meta b { font-size: 13px; }
  .card-actions { flex-wrap: wrap; }

  /* Upload kompakter, „ziehen“ gibt es auf dem Handy nicht */
  .upload { padding: 14px; border-radius: 18px; margin-bottom: 14px; }
  .upload > div:first-child p { display: none; }
  .upload-actions { width: 100%; }
  .upload-actions .field-inline { flex: 1; }
  .chips { margin-bottom: 12px; }

  /* Outfit bauen: Name und Speichern oben, darunter das Bild, dann Hintergrund und Auswahl.
     Das Panel löst sich auf (display: contents), seine Teile werden einzeln angeordnet. */
  .builder { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .panel { display: contents; }
  .panel > .field:first-child { order: 0; margin: 0; }
  .panel > .row { order: 1; margin: 0; }
  .stage-wrap { order: 2; }
  .panel > .field:nth-child(2) { order: 3; margin: 0; }
  .picker { order: 4; }
  .panel .hint { display: none; }
  .builder .panel .btn:not(.primary) { background: var(--gray); }
  .builder .panel .btn:not(.primary):hover:not(:disabled) { background: var(--gray-hover); }
  .stage { max-width: min(100%, calc(60vh * 9 / 16)); border-radius: 18px; }
  .picker-grid { display: flex; overflow-x: auto; gap: 8px; padding-bottom: 6px; overflow-y: hidden; scroll-snap-type: x proximity; }
  .pick { flex: none; width: 84px; height: 84px; aspect-ratio: auto; scroll-snap-align: start; overflow: hidden; }
  .pick img { max-width: 68px; max-height: 68px; }
  .layer-tools { flex-wrap: wrap; justify-content: center; }

  /* Dialoge nutzen die Breite */
  dialog { width: 94vw; padding: 18px; border-radius: 24px; }
  .combos { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 10px; }
  .palette { height: 110px; }
  .palette div { padding: 6px; font-size: 11px; }
  .up-preview { height: 220px; }
}

/* Fingerfreundlichere Griffe am ausgewählten Teil */
@media (pointer: coarse) {
  .layer .handle { width: 28px; height: 28px; right: -14px; bottom: -14px; }
  .layer .rot { width: 28px; height: 28px; top: -44px; margin-left: -14px; }
  .btn, .chip { min-height: 40px; }
}

/* Touchgeräte allgemein (iPad, Handy): kein Doppeltipp-Zoom, keine Lupe oder Menü beim langen Drücken auf Teilen */
button, .tab, .chip, .pick, .card, label.btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.layer, .layer img { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }

/* Auf dem grauen Panel brauchen Buttons einen hellen Untergrund, sonst sieht man sie nicht */
.panel .btn:not(.primary) { background: var(--surface); }
.panel .btn:not(.primary):hover:not(:disabled) { background: var(--gray-hover); }

/* Querformat mit wenig Höhe (iPad quer, kleine Laptops): ganzes Bild ohne Scrollen sichtbar */
@media (min-width: 901px) and (max-height: 900px) {
  .stage { max-width: min(100%, calc((100vh - 160px) * 9 / 16)); }
}

/* Notiz (z. B. Preis) unter der Kategorie; Platzhalter ist grau und verschwindet beim Tippen */
input::placeholder { color: #a8a8a8; opacity: 1; }
.card .meta .note { display: block; font-style: normal; font-size: 12px; color: var(--text); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta .note:empty { display: none; }

/* Kategorie-Auswahl: schlichtes Feld ohne System-Optik, eigener Pfeil */
select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  background-color: var(--gray);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23111' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center; background-size: 14px;
  border: 0; border-radius: 12px; padding: 13px 44px 13px 16px; font-weight: 600; min-width: 190px;
}
select:hover { background-color: var(--gray-hover); }
select:focus-visible { outline: 0; box-shadow: 0 0 0 2px #0074e8; }
.upload select { background-color: var(--surface); }
.upload select:hover { background-color: var(--gray-hover); }

/* Beschriftung „Kategorie“ im Upload-Bereich kräftiger */
.upload .field-inline { font-size: 14px; font-weight: 700; }

/* Wunschliste: Link zum Shop unter dem Teil */
.card .meta .shop {
  display: inline-block; max-width: 100%; margin-top: 6px; padding: 5px 10px; border-radius: 10px;
  background: var(--gray); color: var(--text); font-size: 12px; font-weight: 600; text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top;
}
.card .meta .shop:hover { background: var(--gray-hover); }
@media (max-width: 700px) { .tab { font-size: 13px; padding: 12px 2px; } }

/* Anmeldung */
.locked .top, .locked main { display: none; }
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
.auth[hidden] { display: none; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card h1 { margin: 0 0 4px; font-size: 40px; font-weight: 900; color: var(--red, #e60023); letter-spacing: -1px; }
.auth-card h2 { margin: 0 0 20px; font-size: 20px; }
.auth-card input { font-size: 16px; }
.auth-error { color: #c4202e; font-size: 14px; min-height: 20px; margin: 0 0 8px; }
.account { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--gray); border-radius: 16px; padding: 14px 16px; margin-bottom: 16px; }
.icon[hidden], .btn[hidden], .pw-box[hidden] { display: none; }

/* Bereich einzeichnen */
.up-draw-row .grow { flex: 1; white-space: nowrap; }
.up-draw-row .btn { padding: 12px 10px; }
.field[hidden] { display: none; }
.up-mode { margin-bottom: 12px; }
.up-draw-row[hidden], .up-draw-row .btn[hidden] { display: none; }
.up-draw { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; border-radius: 16px; }
.btn.on { background: var(--text); color: var(--on-text); }

/* Hochladen-Fenster am Computer breiter, mit größerer Vorschau */
@media (min-width: 701px) {
  #uploadDialog { width: min(620px, 92vw); }
  #uploadDialog .up-preview { height: 340px; }
}

/* Beim Bearbeiten bleibt das Foto oben stehen, während man die Werkzeuge darunter benutzt */
#itemDialog.editing .up-preview { position: sticky; top: 0; z-index: 3; box-shadow: 0 6px 0 var(--bg); }

/* Ausrufezeichen am Outfit, wenn ein Teil daraus gelöscht wurde */
.outfits .card .img { position: relative; }
.card .warn {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%; padding: 0;
  border: 0; background: #ffb020; color: #111; font-weight: 800; font-size: 15px; line-height: 24px; text-align: center; cursor: pointer;
}

dialog.tooling .up-preview { position: sticky; top: 0; z-index: 3; box-shadow: 0 6px 0 var(--bg); }
