:root {
  --bg: #faf6f1;
  --card: #ffffff;
  --ink: #2c2226;
  --muted: #7d6f74;
  --line: #ebe2dc;
  --accent: #8c3b5c;
  --accent-soft: #f3dfe7;
  --ok: #3f7d58;
  --warn: #b5731d;
  --danger: #b23a3a;
  --note: #fff4cc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 30, 40, .06), 0 4px 14px rgba(60, 30, 40, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1618; --card: #261f22; --ink: #f1e9ec; --muted: #a8999f; --line: #3a3034;
    --accent: #e07aa1; --accent-soft: #43293a; --note: #4a3f1c; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; margin-top: 1.4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .6rem;
  padding: calc(.55rem + env(safe-area-inset-top, 0px)) 1rem .55rem;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--ink); margin-right: auto; white-space: nowrap; }
.view { max-width: 860px; margin: 0 auto; padding: 1rem 1rem calc(5.5rem + var(--safe-b)); }
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .45rem 0 .5rem; font-size: .72rem; color: var(--muted);
}
.bottomnav a span { font-size: 1.25rem; line-height: 1; }
.bottomnav a.active { color: var(--accent); font-weight: 600; }
body.fullscreen .topbar, body.fullscreen .bottomnav { display: none; }
body.fullscreen .view { max-width: none; padding: 0; }

.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: .75rem; }
.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ---------- Komponenten ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem; box-shadow: var(--shadow);
}
a.card { color: inherit; display: block; }
.card.accent { border-left: 5px solid var(--c, var(--accent)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: .55rem .9rem; font: inherit; font-weight: 500;
  cursor: pointer; min-height: 42px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: .3rem .65rem; font-size: .88rem; }
.btn:disabled { opacity: .45; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent;
  color: var(--ink); font-size: 1.2rem; cursor: pointer;
}
.fab {
  position: fixed; right: 1rem; bottom: calc(4.8rem + var(--safe-b)); z-index: 15;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 1.8rem; box-shadow: 0 4px 16px rgba(0,0,0,.2); cursor: pointer;
}

.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .3rem; margin-bottom: .8rem; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: .3rem .8rem; font: inherit; font-size: .9rem; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.badge { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.badge.done { background: #e1f0e6; color: var(--ok); }
.badge.paused { background: #f6ead7; color: var(--warn); }
.badge.planned { background: var(--line); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .badge.done { background: #23392b; } .badge.paused { background: #3d3020; }
}

.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: .4rem; }
.progress > i { display: block; height: 100%; background: var(--accent); }

.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); vertical-align: middle; flex: none; }
.swatch.lg { width: 38px; height: 38px; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .big { font-size: 2.6rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.kv .card { padding: .7rem .8rem; }
.kv b { display: block; font-size: 1.35rem; }

/* ---------- Zähler ---------- */
.counter {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; box-shadow: var(--shadow);
}
.counter-head { display: flex; align-items: center; gap: .4rem; }
.counter-head .name { font-weight: 600; flex: 1; }
.counter-body { display: flex; align-items: center; gap: .6rem; margin-top: .4rem; }
.counter-value { flex: 1; text-align: center; user-select: none; }
.counter-value .num { font-size: 3.4rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.counter-value .sub { font-size: .85rem; color: var(--muted); }
.cbtn {
  width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font-size: 2rem; cursor: pointer; flex: none;
  touch-action: manipulation; user-select: none;
}
.cbtn.plus { width: 84px; height: 84px; background: var(--accent); border-color: var(--accent); color: #fff; font-size: 2.6rem; }
.cbtn:active { transform: scale(.94); }
.row-note {
  margin-top: .6rem; padding: .5rem .7rem; border-radius: 10px; background: var(--note);
  font-size: .95rem;
}
.row-note.next { opacity: .7; background: transparent; border: 1px dashed var(--line); }
.counter-big .counter-value .num { font-size: 5.5rem; }
.counter-big .cbtn.plus { width: 120px; height: 120px; font-size: 3.4rem; }

/* ---------- Timer ---------- */
.timer-chip {
  font-size: .85rem; padding: .25rem .65rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; min-width: 0;
}
.timer-chip::before { content: "● "; animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.timer-box { display: flex; align-items: center; gap: .6rem; }
.timer-box .t { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Formulare ---------- */
label { display: block; font-size: .88rem; color: var(--muted); }
label + label, label + .row, .row + label { margin-top: .7rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem;
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; min-height: 42px;
}
input[type=color] { padding: 2px; height: 42px; }
input[type=checkbox] { display: inline; width: auto; min-height: 0; margin: 0 .4rem 0 0; }
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.form-grid label { margin-top: 0 !important; }
.form-grid .full { grid-column: 1 / -1; }
.check-list { max-height: 45vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; padding: .2rem .6rem; }
.check-list label { display: flex; align-items: center; gap: .5rem; color: var(--ink); padding: .45rem 0; margin: 0 !important; border-bottom: 1px solid var(--line); }
.check-list label:last-child { border-bottom: 0; }
.check-list input[type=number] { width: 80px; margin: 0 0 0 auto; min-height: 34px; padding: .2rem .4rem; }

dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, 94vw); max-height: 90vh;
  background: var(--card); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(30, 15, 20, .45); }
#modal-form { padding: 1.1rem 1.1rem 1rem; overflow-y: auto; max-height: 90vh; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.1rem; flex-wrap: wrap; }
.modal-actions .left { margin-right: auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(5.5rem + var(--safe-b)); transform: translateX(-50%); z-index: 100;
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 12px; font-size: .92rem;
  max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.note { background: #f6d55c; color: #3a2e00; font-weight: 600; }

/* ---------- PDF-Ansicht ---------- */
.pdf-wrap { position: fixed; inset: 0; display: flex; flex-direction: column; background: #555; z-index: 30; }
.pdf-bar {
  display: flex; align-items: center; gap: .3rem; padding: calc(.35rem + env(safe-area-inset-top, 0px)) .5rem .35rem;
  background: var(--card); border-bottom: 1px solid var(--line); color: var(--ink);
}
.pdf-bar .title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-bar .icon-btn { width: 36px; height: 36px; font-size: 1.05rem; }
.pdf-bar .icon-btn.on { background: var(--accent-soft); color: var(--accent); }
.pdf-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; position: relative; touch-action: pan-x pan-y; }
.pdf-pages { position: relative; margin: 0 auto; padding: 8px 0; }
.pdf-page { display: block; margin: 0 auto 8px; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.pdf-marker {
  position: absolute; left: 0; right: 0; z-index: 5;
  background: rgba(246, 213, 92, .28); border-top: 2px solid #e0b100; border-bottom: 2px solid #e0b100;
  pointer-events: none;
}
.pdf-marker .handle {
  pointer-events: auto; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border-radius: 50%; background: #e0b100; color: #3a2e00;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem; touch-action: none; cursor: ns-resize;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.pdf-marker .handle.size { right: 50px; width: 30px; height: 30px; font-size: .85rem; background: #f4dc7c; }
.pdf-counter {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .7rem calc(.5rem + var(--safe-b));
  background: var(--card); border-top: 1px solid var(--line); color: var(--ink);
}
.pdf-counter .cinfo { flex: 1; min-width: 0; text-align: center; }
.pdf-counter .cname { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-counter .num { font-size: 2rem; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.pdf-counter .cbtn { width: 52px; height: 52px; font-size: 1.6rem; }
.pdf-counter .cbtn.plus { width: 64px; height: 64px; font-size: 2rem; }
.pdf-note { padding: .4rem .8rem; background: var(--note); color: var(--ink); font-size: .92rem; border-top: 1px solid var(--line); }
.pdf-loading { color: #fff; text-align: center; padding: 3rem 1rem; }

/* ---------- Statistik ---------- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: .5rem; }
.bars .b { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .b.zero { background: var(--line); }
.bars-axis { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: .3rem; }
.hbar { display: grid; grid-template-columns: minmax(90px, 35%) 1fr auto; gap: .6rem; align-items: center; padding: .35rem 0; }
.hbar .track { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--c, var(--accent)); }
.hbar .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: min(360px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 1.6rem; box-shadow: var(--shadow); }
.login-card .logo { font-size: 2.6rem; text-align: center; }
.login-card h1 { text-align: center; margin-bottom: 1rem; }
.login-card .btn { width: 100%; margin-top: 1.1rem; }
.error { color: var(--danger); background: #fbe9e9; padding: .5rem .7rem; border-radius: 10px; }

@media (min-width: 900px) {
  .bottomnav { left: 50%; transform: translateX(-50%); max-width: 640px; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
