:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #15171c;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --warn-bg: #fff7ed;
  --warn: #9a3412;
  --ok: #16a34a;
  --run: #059669;
  --run-soft: #ecfdf5;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 8px rgba(0,0,0,.04);
  --radius: 14px;
  --tap: 48px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #191c22;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --line: #2a2e36;
    --accent: #818cf8;
    --accent-text: #0f1115;
    --accent-soft: #23284a;
    --danger: #f87171;
    --warn-bg: #3a2614;
    --warn: #fdba74;
    --ok: #4ade80;
    --run: #34d399;
    --run-soft: #10261f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; }

#top, #status, #timerbar, main { max-width: 680px; margin: 0 auto; }
#top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  max-width: none;
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.sync { flex: 1; font-size: 13px; color: var(--muted); }
.gear { font-size: 22px; text-decoration: none; color: var(--muted); min-width: var(--tap); min-height: 40px; display: grid; place-items: center; }

main { padding: 4px 16px 24px; }
h1 { font-size: 28px; margin: 8px 0 12px; letter-spacing: -.02em; }
h1 small { display: block; font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 0 8px; font-weight: 600; }
h3 { font-size: 16px; margin: 20px 0 8px; }

/* Banner */
.banner { margin: 8px 16px 0; padding: 12px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); font-size: 15px; display: flex; gap: 10px; align-items: center; }
.banner button { margin-left: auto; }
.hint { padding: 12px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); font-size: 15px; margin: 0 0 12px; }

/* Timer-Leiste */
.timerbar {
  margin: 8px 16px 0; padding: 8px 8px 8px 14px; border-radius: var(--radius);
  background: var(--run-soft); color: var(--text); display: flex; align-items: center; gap: 10px;
  border: 1px solid color-mix(in srgb, var(--run) 35%, transparent);
}
.timerbar .clock { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--run); }
.timerbar .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: none; border: 0; text-align: left; padding: 8px 0; }

/* Erfassen */
.capture { display: flex; gap: 8px; margin: 0 0 12px; }
.capture input {
  flex: 1; min-width: 0; height: var(--tap); padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card); font-size: 16px; box-shadow: var(--shadow);
}
.capture input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Buttons */
.btn {
  min-height: var(--tap); padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.run { background: var(--run); color: #fff; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 15px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; }

/* Aufgabenliste */
ul.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
ul.list:empty { display: none; }
.task { display: flex; align-items: stretch; min-height: 56px; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.task.running { background: var(--run-soft); }
.task .check {
  flex: none; width: 52px; border: 0; background: none; display: grid; place-items: center; padding: 0;
}
.task .check::before {
  content: ""; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--muted); display: block;
}
.task.done .check::before { background: var(--ok); border-color: var(--ok); }
.task.done .check::after { content: "✓"; position: absolute; color: #fff; font-size: 14px; font-weight: 700; }
.task .check { position: relative; }
.task .body {
  flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 10px 4px; display: flex; flex-direction: column; justify-content: center; gap: 3px;
}
.task .title { overflow-wrap: anywhere; }
.task.done .title { color: var(--muted); text-decoration: line-through; }
.task .meta { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 13px; color: var(--muted); }
.task .meta .due { color: var(--danger); font-weight: 600; }
.chip { background: var(--accent-soft); color: var(--accent); padding: 1px 8px; border-radius: 99px; font-weight: 500; }
.task .icon {
  flex: none; width: 50px; border: 0; background: none; font-size: 18px; color: var(--muted); display: grid; place-items: center;
}
.task .icon.today-on { color: #f59e0b; }
.task .play { color: var(--run); }
.task .play.on { color: var(--danger); }

.empty { padding: 20px; text-align: center; color: var(--muted); background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Projekte */
.plist a {
  display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 16px; color: var(--text); text-decoration: none; border-top: 1px solid var(--line);
}
.plist li:first-child a { border-top: 0; }
.plist .n { margin-left: auto; color: var(--muted); font-size: 14px; white-space: nowrap; }
.plist .chev { color: var(--muted); }
details > summary { cursor: pointer; color: var(--muted); padding: 12px 0; }

/* Karten / Auswertung */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px; }
.card .head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.card .total { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { margin: 8px 0; }
.bar .lbl { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; gap: 8px; }
.bar .lbl span:last-child { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.bar .track { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.weeknav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.weeknav .lbl { flex: 1; text-align: center; font-weight: 600; }
.elist li { display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); min-height: 52px; }
.elist li:first-child { border-top: 0; }
.elist .tm { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; white-space: nowrap; }
.elist .what { flex: 1; min-width: 0; }
.elist .what small { display: block; color: var(--muted); }
.elist .d { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.elist button.what { border: 0; background: none; text-align: left; padding: 0; }

/* Tabs */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs a {
  flex: 1; max-width: 136px; min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; position: relative;
}
#tabs a .i { font-size: 21px; line-height: 1; }
#tabs a.on { color: var(--accent); }
#tabs .badge {
  position: absolute; top: 5px; left: calc(50% + 6px); background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px;
}
#tabs .badge.soft { background: var(--muted); }

/* Sheet */
#sheet { position: fixed; inset: 0; z-index: 20; }
#sheet .backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
#sheet .panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: calc(100% - env(safe-area-inset-top) - 24px); overflow: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  margin: 0 auto; max-width: 680px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
@media (min-width: 760px) {
  #sheet .panel { top: 5vh; bottom: auto; max-height: 90vh; border-radius: 18px; }
}
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 10px 0; background: var(--bg); }
.sheet-head b { font-size: 17px; }
.linkbtn { border: 0; background: none; color: var(--accent); font-weight: 600; min-height: 44px; padding: 0 4px; font-size: 17px; }
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field input, .field select, .field textarea, .title-input {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 16px;
}
.field textarea { resize: vertical; min-height: 96px; }
.title-input { font-size: 20px; font-weight: 600; resize: none; overflow: hidden; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two .field { margin: 0; }
.seg { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; background: var(--card); padding: 4px; border-radius: 12px; border: 1px solid var(--line); margin: 12px 0; }
.seg button { min-height: 40px; border: 0; background: none; border-radius: 9px; font-size: 14px; font-weight: 500; padding: 0 2px; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.timer-box { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); margin: 16px 0 4px; }
.timer-box .sum { flex: 1; }
.timer-box .sum b { font-size: 20px; font-variant-numeric: tabular-nums; }
.entry-edit { padding: 12px 16px; border-top: 1px solid var(--line); background: var(--accent-soft); }
.entry-edit .two { margin-bottom: 10px; }

textarea.import { width: 100%; min-height: 140px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font: 13px/1.4 ui-monospace, Menlo, monospace; }
label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
label.check input { width: 22px; height: 22px; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 15px; max-width: calc(100% - 32px);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
