:root {
  --folder: #d3dcd2;      /* Aktenmappe: die Fläche, auf der die Seiten liegen */
  --folder-deep: #bcc9bd;
  --ink: #17282a;
  --ink-soft: #4b5e5c;
  --paper: #fff;
  --stamp: #1f3bc4;       /* Stempelblau: das Handeln */
  --stamp-deep: #162b92;
  --alert: #a3201a;
  --sans: "Avenir Next", Avenir, "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { background: var(--folder); }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--folder);
  color: var(--ink);
  font: 400 16px/1.4 var(--sans);
}

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }

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

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(16px, 4vw, 40px) 12px;
}

h1 { margin: 0; font-size: 1.375rem; font-weight: 700; letter-spacing: -.01em; }

.btn {
  min-height: 44px;
  padding: 8px 18px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--folder-deep); }
.btn.primary { background: var(--stamp); border-color: var(--stamp); color: #fff; }
.btn.primary:hover { background: var(--stamp-deep); border-color: var(--stamp-deep); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.quiet { border-color: transparent; color: var(--stamp); padding-inline: 10px; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px clamp(16px, 4vw, 40px) 32px;
}

.empty {
  flex: 1;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  border: 2px dashed var(--ink-soft);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
}
.empty:hover { background: var(--folder-deep); }
.empty-title { font-size: clamp(1.375rem, 4vw, 2rem); font-weight: 700; letter-spacing: -.01em; }
.empty-note { color: var(--ink-soft); }

/* Die Seitenfolge: Papier auf der Mappe, die Position ist die große Zahl darunter. */
.sequence {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(190px, calc(50% - 8px)), 1fr));
  gap: 24px 16px;
}

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.card.dragging { opacity: .25; }

.stage {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet {
  position: absolute;
  inset: 0;
  margin: auto;
  display: block;
  max-width: 100%;
  max-height: 100%;
  background: var(--paper);
  box-shadow: 0 1px 0 #7d8d83, 3px 4px 0 var(--folder-deep);
}

.sheet.pending { width: 70%; aspect-ratio: 1 / 1.41; }

.tools {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

.tool {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
}
.tool:hover { background: var(--folder-deep); }
.tool.remove { margin-left: auto; }
.tool.remove:hover { background: var(--alert); color: #fff; }
.tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.plate {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
}

.position {
  font-size: 2rem;
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  margin-right: auto;
}

.move {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
}
.move:hover:not(:disabled) { background: var(--folder-deep); }
.move:disabled { opacity: .25; cursor: default; }
.move svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.origin {
  margin: 2px 0 0;
  font-size: .8125rem;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drag-ghost {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  transform: rotate(-2deg) scale(1.03);
  filter: drop-shadow(6px 10px 0 rgb(23 40 42 / .22));
  opacity: 1;
  list-style: none;
}

.foot { padding: 0 clamp(16px, 4vw, 40px) 16px; font-size: .875rem; }
.foot a, .foot a:visited { color: var(--ink-soft); }

/* Lizenzseite */
.licenses main { display: block; max-width: 760px; width: 100%; margin: 0 auto; padding: 32px 16px 48px; }
.licenses h1 { margin-bottom: 8px; }
.licenses details { border-top: 1px solid var(--ink-soft); padding: 12px 0; }
.licenses summary { cursor: pointer; font-weight: 600; }
.lic-kind { font-weight: 400; color: var(--ink-soft); margin-left: 8px; }
.licenses details p { margin: 8px 0; }
.licenses pre { margin: 8px 0 0; padding: 12px; background: var(--paper); font-size: .8125rem; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Ausgabe-Leiste: bleibt immer sichtbar */
.output {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 40px) calc(12px + env(safe-area-inset-bottom));
  background: var(--ink);
  color: #fff;
}

.count { align-self: center; font-weight: 600; white-space: nowrap; margin-right: auto; }

.name { display: flex; flex-direction: column; gap: 2px; font-size: .8125rem; flex: 0 1 380px; min-width: 0; }

.name-field {
  display: flex;
  align-items: center;
  height: 44px;
  background: #fff;
  color: var(--ink);
  border-radius: 3px;
  font-size: 1rem;
}
.name-field:focus-within { outline: 3px solid #93a4ff; outline-offset: 1px; }
.name-field input { flex: 1; min-width: 0; height: 100%; padding: 0 2px 0 10px; border: 0; background: none; outline: 0; }
.name-field input::placeholder { color: #66777a; }
.suffix { padding-right: 10px; color: var(--ink-soft); }

.output .btn.primary { background: #fff; border-color: #fff; color: var(--stamp); }
.output .btn.primary:hover { background: #dfe4ff; border-color: #dfe4ff; }
.output :focus-visible { outline-color: #93a4ff; }

/* Hinweise */
.notices {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  min-height: 52px;
  background: var(--paper);
  border-left: 6px solid var(--ink);
  box-shadow: 3px 4px 0 rgb(23 40 42 / .25);
}
.notice.error { border-left-color: var(--alert); }
.notice p { margin: 0; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.notice .btn { min-height: 36px; padding: 4px 10px; }

/* Seitenauswahl */
.picker {
  width: min(1040px, calc(100% - 32px));
  height: min(800px, calc(100dvh - 32px));
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--folder);
  color: var(--ink);
}
.picker::backdrop { background: rgb(23 40 42 / .6); }

.picker-layout { height: 100%; display: flex; flex-direction: column; }

.picker-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 16px 20px 10px;
}
.picker-head > div:first-child { min-width: 0; flex: 1 1 260px; }
.picker h2 { margin: 0; font-size: 1.125rem; overflow-wrap: anywhere; }
.picker p { margin: 0; color: var(--ink-soft); }
.picker-bulk { display: flex; gap: 4px; }

.picker-pages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(150px, calc(50% - 6px)), 1fr));
  gap: 12px;
  align-content: start;
}

.pick {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 3px solid transparent;
  border-radius: 3px;
  cursor: pointer;
}
.pick:hover { background: var(--folder-deep); }
.pick:has(input:checked) { border-color: var(--stamp); background: #e7ebff; }
.pick:has(input:focus-visible) { outline: 3px solid var(--stamp); outline-offset: 2px; }
.pick input { width: 24px; height: 24px; margin: 0; accent-color: var(--stamp); }
.pick-row { display: flex; align-items: center; gap: 8px; }
.pick .stage { pointer-events: none; }
.pick-label { font-weight: 600; font-variant-numeric: tabular-nums; }

.picker-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 12px 20px;
  background: var(--folder-deep);
}

.drop-veil {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgb(31 59 196 / .88);
  color: #fff;
  font-size: 2rem;
  font-weight: 700;
  pointer-events: none;
}

@media (max-width: 640px) {
  .output { flex-wrap: wrap; gap: 8px 12px; }
  .count { order: 1; }
  .name { order: 3; flex: 1 1 100%; }
  #download { order: 2; }
  .notices { bottom: 150px; }
  .tool, .move { width: 34px; height: 34px; }
  .btn.quiet { padding-inline: 6px; }
  .picker-foot .btn { flex: 1 1 auto; }
  .picker-head, .picker-pages, .picker-foot { padding-inline: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .drag-ghost { transform: none; }
}
