:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b1f24;
  --muted: #6b7280;
  --accent: #2f6df6;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --ok: #1f7a4d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-2: #232830;
    --border: #333a45;
    --text: #e8eaed;
    --muted: #9aa3b0;
    --accent: #5b8dff;
    --accent-text: #0d1117;
    --danger: #ef6a5c;
    --ok: #4cc38a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 0 calc(130px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

main { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* ------------------------------------------------------------------ Kopf */

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 24px;
}

.brand {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 20px;
  flex: none;
}

.brand h1 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------- Ablagefeld */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  background: var(--surface);
  padding: 34px 20px;
  text-align: center;
  transition: border-color .15s, background .15s;
}

.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.dropzone.compact { padding: 18px; }

body.dragging .dropzone,
.dropzone.hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

.dropzone-title { margin: 0; font-size: 16px; font-weight: 600; }
.dropzone-sub { margin: 6px 0; color: var(--muted); font-size: 13px; }
.dropzone-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.dropzone-hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- Buttons */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 11px 20px; font-weight: 600; }
.btn-quiet { color: var(--muted); }

/* -------------------------------------------------------------- Meldungen */

.alerts { margin: 16px 0 0; display: grid; gap: 8px; }

.alert {
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.alert.ok { border-left-color: var(--ok); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }

/* -------------------------------------------------------------- Werkzeuge */

.workspace { margin-top: 22px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar-info { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hint { font-size: 12px; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }

/* ----------------------------------------------------------------- Karten */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: grab;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  transition: transform .12s, box-shadow .12s, opacity .12s;
}

.card:active { cursor: grabbing; }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Gedrückthalten auf dem Touchscreen: Karte senkt sich leicht, bevor sie greift. */
.card.pressing { transform: scale(.97); }

/* Platz, an dem die gezogene Karte landen würde. */
.card.placeholder {
  background: var(--surface-2);
  border-style: dashed;
  box-shadow: none;
}

.card.placeholder > * { visibility: hidden; }

/* Die Karte, die am Zeiger hängt. */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 80;
  pointer-events: none;
  opacity: .96;
  box-shadow: 0 14px 30px rgba(16, 24, 40, .24), 0 4px 10px rgba(16, 24, 40, .18);
  will-change: transform;
}

body.reordering {
  cursor: grabbing;
  -webkit-user-select: none;
  user-select: none;
}

body.reordering .card { transition: none; }

.card-thumb {
  aspect-ratio: 3 / 4;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.card-thumb img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  -webkit-user-drag: none;
  pointer-events: none;
}

.card-index {
  position: absolute;
  top: 8px; left: 8px;
  min-width: 24px; height: 24px;
  padding: 0 7px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.card-remove {
  position: absolute;
  top: 6px; right: 6px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity .12s;
}

.card:hover .card-remove, .card:focus-within .card-remove { opacity: 1; }
.card-remove:hover { color: var(--danger); border-color: var(--danger); }

.card-meta { padding: 9px 10px 11px; }

.card-name {
  font-size: 13px;
  font-weight: 500;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-sub { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------- Aktionsbar */

.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  box-shadow: 0 -2px 12px rgba(16, 24, 40, .06);
}

.field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

.field input,
.field select {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  min-width: 230px;
}

.field select { min-width: 0; cursor: pointer; }

.check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check.disabled { opacity: .45; cursor: not-allowed; }

/* ---------------------------------------------------------------- Overlay */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, .45);
  display: grid;
  place-items: center;
  z-index: 50;
}

.overlay-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px 34px;
  text-align: center;
  box-shadow: var(--shadow);
}

.overlay-card p { margin: 14px 0 0; font-size: 14px; }

.spinner {
  width: 30px; height: 30px;
  margin: 0 auto;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

[hidden] { display: none !important; }

@media (hover: none) {
  .card-remove { opacity: 1; width: 32px; height: 32px; font-size: 17px; }
  .card { cursor: default; }
}

@media (max-width: 560px) {
  body { padding: 0 0 calc(215px + env(safe-area-inset-bottom, 0px)); }

  main { padding: 0 14px; }

  .list { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 12px; }

  .toolbar { gap: 10px; }
  .toolbar-actions { width: 100%; }
  .toolbar-actions .btn { flex: 1 1 auto; }

  /* Gestapelt frisst die Leiste ein Drittel des Bildschirms — die beiden
     Felder passen nebeneinander, Haken und Knopf darunter über die Breite. */
  .actionbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: end;
    gap: 10px;
  }

  .actionbar .check,
  .actionbar .btn-lg { grid-column: 1 / -1; }

  .field { flex-direction: column; align-items: stretch; gap: 4px; }
  .field input, .field select { min-width: 0; width: 100%; font-size: 16px; }
  .btn-lg { width: 100%; }
}
