:root {
  --bg: #EEF1F5;
  --surface: #FFFFFF;
  --ink: #1C2740;
  --ink-2: #5B6680;
  --line: #D8DEE8;
  --crust: #C98A1B;
  --idea: rgba(242, 194, 48, .26);
  --cut: rgba(201, 138, 27, .22);
  --done: rgba(46, 158, 91, .20);
  --danger: #C2412D;
  --link: #2457C5;
  --primary-bg: #1C2740;
  --primary-ink: #FFFFFF;
  --rounded: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;
  --text: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121826;
    --surface: #1B2333;
    --ink: #E7EBF3;
    --ink-2: #97A2B8;
    --line: #2A3448;
    --crust: #E3A43A;
    --idea: rgba(242, 194, 48, .20);
    --cut: rgba(227, 164, 58, .18);
    --done: rgba(70, 190, 120, .18);
    --danger: #F06A52;
    --link: #8DB4FF;
    --primary-bg: #E7EBF3;
    --primary-ink: #121826;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html, body { margin: 0; background: var(--bg); color: var(--ink); overscroll-behavior-y: none; }

/* ---------- Ziehen zum Aktualisieren */
.top, .list, .empty { transform: translateY(var(--pull, 0px)); }
.ptr-animate .top, .ptr-animate .list, .ptr-animate .empty, .ptr-animate .ptr { transition: transform .25s ease, opacity .25s ease; }
.ptr {
  position: fixed; z-index: 6; left: 50%; top: calc(env(safe-area-inset-top) + 6px);
  width: 40px; height: 40px; margin-left: -20px; border-radius: 50%;
  display: grid; place-items: center; opacity: 0; pointer-events: none;
  background: var(--surface); color: var(--ink-2); box-shadow: 0 0 0 1px var(--line);
  transform: translateY(calc(var(--pull, 0px) - 46px));
}
.ptr svg { transform: rotate(var(--turn, 0deg)); transition: transform .15s ease; }
.ptr.ready { color: var(--ink); }
.ptr.spinning svg { display: none; }
.ptr.spinning::after {
  content: ""; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
body {
  font: 16px/1.4 var(--text);
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--crust); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Kopf */
.top { padding: 14px 18px 8px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.top h1 { font: 700 30px/1.15 var(--rounded); margin: 6px 0 0; letter-spacing: -.01em; }
.sync-line { margin: 2px 0 10px; min-height: 18px; font-size: 13px; color: var(--ink-2); }
.sync-line.warn { color: var(--crust); }
.sync-line.err { color: var(--danger); }

.filters { display: flex; gap: 6px; }
.filters button {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 999px;
  font: 600 15px/1 var(--rounded); color: var(--ink-2);
}
.filters button span { font-weight: 500; opacity: .8; margin-left: 2px; }
.filters button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }

/* ---------- Liste */
.list { list-style: none; margin: 0; padding: 4px 0 120px; }
.row {
  display: grid; grid-template-columns: 52px 1fr; gap: 12px;
  padding: 12px 18px; align-items: start; border-bottom: 1px solid var(--line);
}
.row:active { background: color-mix(in srgb, var(--surface) 60%, transparent); }
.stamp {
  width: 48px; height: 48px; border-radius: 50%; border: 0; display: grid; place-items: center;
  font-size: 24px; line-height: 1; background: var(--idea);
}
.stamp.schnitt { background: var(--cut); }
.stamp.fertig { background: var(--done); }
.stamp.pop { animation: pop .28s ease-out; }
@keyframes pop { 40% { transform: scale(1.18); } }
.row-body { min-width: 0; padding-top: 2px; }
.row-title { font: 600 17px/1.3 var(--text); margin: 0; overflow-wrap: anywhere; }
.row-text {
  margin: 2px 0 0; color: var(--ink-2); font-size: 15px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.row.is-fertig .row-title { color: var(--ink-2); }
.row-meta { margin: 6px 0 0; font-size: 13px; color: var(--ink-2); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mini-thumbs { display: flex; gap: 4px; }
.mini-thumbs img, .mini-thumbs i {
  width: 34px; height: 34px; border-radius: 6px; object-fit: cover; display: grid; place-items: center;
  background: var(--line); font-style: normal; font-size: 15px;
}
.progress { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--crust); transition: width .3s; }
.empty { padding: 40px 28px; color: var(--ink-2); text-align: center; font-size: 16px; }

.fab {
  position: fixed; right: calc(20px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom));
  width: 64px; height: 64px; border-radius: 50%; border: 0;
  background: var(--primary-bg); color: var(--primary-ink); font: 400 38px/1 var(--rounded);
  box-shadow: 0 6px 18px rgba(20, 30, 60, .28);
}

/* ---------- Eingabe-Blatt */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: var(--bg);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet-inner { padding: 6px 18px 40px; max-width: 640px; margin: 0 auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 14px; }
.sheet-head h2 { font: 600 17px/1 var(--rounded); margin: 0; }
.btn-plain { border: 0; background: none; padding: 8px 2px; font-size: 17px; color: var(--ink-2); }
.btn-plain.strong { color: var(--ink); font-weight: 700; }

.status-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.status-pick.three { grid-template-columns: 1fr 1fr 1fr; }
.status-pick button {
  border: 2px solid transparent; background: var(--surface); border-radius: 16px;
  padding: 14px 10px; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 92px;
}
.status-pick b { font-size: 28px; line-height: 1; }
.status-pick span { font: 600 15px/1.25 var(--rounded); color: var(--ink-2); }
.status-pick button[aria-checked="true"] { border-color: var(--ink); }
.status-pick button[aria-checked="true"] span { color: var(--ink); }
.status-pick button[data-status="idee"][aria-checked="true"] { background: var(--idea); }
.status-pick button[data-status="schnitt"][aria-checked="true"] { background: var(--cut); }
.status-pick button[data-status="fertig"][aria-checked="true"] { background: var(--done); }

textarea {
  width: 100%; border: 0; border-radius: 16px; background: var(--surface); color: var(--ink);
  font: 17px/1.45 var(--text); padding: 14px 16px; resize: vertical; min-height: 150px;
}
textarea::placeholder { color: var(--ink-2); }

.inline-link { color: var(--link); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.row.is-fertig .inline-link { color: var(--ink-2); }

.links { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.link-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 48px; padding: 10px 14px; border-radius: 14px;
  background: var(--surface); color: var(--link); text-decoration: none;
  font: 600 15px/1.3 var(--text);
}
.link-chip span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-chip svg { flex: none; }
.link-chip:active { opacity: .7; }

.atts { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin: 14px 0 4px; }
.att { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface); }
.att img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; }
.att .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 5px; font-size: 11px; color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, .65)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.att .rm {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 16px; line-height: 1;
}
.att .bar { position: absolute; left: 0; right: 0; top: 0; height: 4px; background: rgba(0, 0, 0, .25); }
.att .bar > div { height: 100%; background: var(--crust); }

.btn-attach {
  display: block; text-align: center; padding: 14px; margin-top: 10px; border-radius: 14px;
  border: 1.5px dashed var(--line); color: var(--ink); font: 600 16px/1.2 var(--rounded); cursor: pointer;
}
.sheet-meta { color: var(--ink-2); font-size: 13px; margin: 18px 0 0; }
.btn-danger {
  margin-top: 26px; width: 100%; padding: 14px; border-radius: 14px; border: 0;
  background: transparent; color: var(--danger); font-weight: 600; box-shadow: inset 0 0 0 1.5px var(--line);
}

/* ---------- Einrichtung */
.setup { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.setup-box { width: 100%; max-width: 360px; }
.setup-icon { width: 72px; height: 72px; border-radius: 16px; }
.setup h1 { font: 700 30px/1.1 var(--rounded); margin: 14px 0 6px; }
.setup p { color: var(--ink-2); margin: 0 0 18px; }
.setup input {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 17px; margin-bottom: 10px;
}
.btn-primary {
  width: 100%; padding: 14px; border: 0; border-radius: 14px;
  background: var(--primary-bg); color: var(--primary-ink); font: 600 17px/1 var(--rounded);
}
.error { color: var(--danger) !important; margin-top: 12px !important; }

@media (prefers-reduced-motion: reduce) {
  .stamp.pop, .sheet { animation: none; }
  .ptr-animate .top, .ptr-animate .list, .ptr-animate .empty, .ptr-animate .ptr, .ptr svg { transition: none; }
}
