:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #1d1b20;
  --muted: #7a7580;
  --accent: #e0527a;
  --accent-soft: #fbe3ea;
  --line: #e7e2da;
  --warn: #d9822b;
  --bad: #d64545;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16151a;
    --card: #222027;
    --text: #f1eef4;
    --muted: #9a94a3;
    --accent-soft: #3a2230;
    --line: #34313b;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding: env(safe-area-inset-top) 16px calc(110px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }

h1 { margin: 0; font-size: 30px; letter-spacing: -0.5px; }
h2 { font-size: 20px; margin: 28px 0 10px; }
h3 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Kopfbereich */
.top { padding: 18px 0 6px; }
.title-row { display: flex; align-items: center; justify-content: space-between; }
.pill {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 15px;
  font-weight: 600;
}
.level { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.level-name { font-size: 14px; font-weight: 600; white-space: nowrap; }
.bar { flex: 1; height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
#xpBar { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.5s ease; }

.greeting { margin: 14px 0 12px; font-size: 16px; }

/* A-oder-B */
.duel-head h2 { margin: 0 0 2px; }
.duel-head p { margin: 0 0 12px; }
.duel { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.duel.single { grid-template-columns: 1fr; }
.option {
  position: relative;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 150px;
  padding: 36px 14px 14px;
  background: var(--card);
  border: 2px solid var(--line);
  border-top: 6px solid var(--c, var(--accent));
  border-radius: var(--radius);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.option:active { transform: scale(0.97); border-color: var(--c, var(--accent)); }
.option .letter {
  position: absolute; top: 10px; left: 12px;
  font-weight: 800; font-size: 14px;
  color: var(--c, var(--accent));
}
.option .text { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.or {
  text-align: center; margin: 12px 0 0;
}
.joker { margin-top: 10px; color: var(--accent); font-size: 15px; padding: 6px 0; }

.mission {
  background: var(--card);
  border: 2px solid var(--c, var(--accent));
  border-radius: 18px;
  padding: 18px;
  text-align: center;
}
.mission .label { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 0; }
.mission .text { font-size: 22px; font-weight: 700; margin: 8px 0; overflow-wrap: anywhere; }
.mission .big { font-size: 44px; margin: 0; }
.mission .meta { justify-content: center; }
.mission .actions { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 14px; }

.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 999px;
}
.secondary {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 999px;
}
.danger { color: var(--bad); padding: 10px 4px; }
.link { color: var(--accent); padding: 6px; font-size: 15px; }
.wide { width: 100%; margin-top: 16px; }

/* Listen */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--c, var(--line));
  border-radius: var(--radius);
  padding: 10px 12px;
}
.check {
  flex: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  display: grid; place-items: center;
  font-size: 14px;
}
.item.done .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.item.done .text { color: var(--muted); text-decoration: line-through; }
.item .idea-icon { flex: none; font-size: 20px; width: 28px; text-align: center; }
.item .body { flex: 1; min-width: 0; text-align: left; padding: 0; }
.item .text { overflow-wrap: anywhere; }

.meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 3px; font-size: 13px; color: var(--muted); }
.meta .today { color: var(--warn); font-weight: 600; }
.meta .overdue { color: var(--bad); font-weight: 600; }

.empty { color: var(--muted); padding: 6px 2px; margin: 0; }

/* Kategorien-Chips */
.chips { display: flex; gap: 8px; padding: 4px 0 12px; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; }
.chip {
  flex: none;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 15px;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Matrix */
.quad { margin-top: 18px; }
.quad-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.quad-head .small { flex: 1; }
.quad-head .count { font-size: 14px; color: var(--muted); font-weight: 600; }

details { margin-top: 26px; }
summary { color: var(--muted); padding: 6px 0; cursor: pointer; }
details .list { margin-top: 8px; }

.stats { margin-top: 20px; text-align: center; }

/* Neu-Button und Tabs */
#fab {
  position: fixed;
  right: max(16px, calc(50vw - 304px));
  bottom: calc(78px + env(safe-area-inset-bottom));
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 32px;
  line-height: 1;
  box-shadow: 0 6px 18px rgb(224 82 122 / 0.4);
  z-index: 5;
}
#tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 4;
}
#tabs button {
  flex: 1;
  max-width: 200px;
  display: flex; flex-direction: column; align-items: center;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
}
#tabs button span { font-size: 22px; filter: grayscale(1); opacity: 0.6; }
#tabs button.active { color: var(--text); font-weight: 600; }
#tabs button.active span { filter: none; opacity: 1; }

/* Eingabe-Sheet */
#sheet, #debtSheet, #dataSheet {
  width: 100%;
  max-width: 640px;
  margin: auto auto 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  max-height: 92dvh;
  overflow-y: auto;
}
#sheet::backdrop, #debtSheet::backdrop, #dataSheet::backdrop { background: rgb(0 0 0 / 0.45); }
#sheet h2, #debtSheet h2, #dataSheet h2 { margin: 0 0 12px; }
.title-actions { display: flex; gap: 8px; align-items: center; }
#dataBtn { cursor: pointer; }
#lastBackup { margin: 12px 0 0; }
.backup-hint {
  display: block; width: 100%; margin-top: 12px;
  padding: 10px 14px; border-radius: var(--radius);
  border: 1px dashed var(--warn); color: var(--warn);
  font-size: 15px;
}
.backup-hint[hidden] { display: none; }
.field {
  width: 100%;
  font: inherit;
  font-size: 17px;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
}
textarea.field { resize: none; }
.field:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.lbl { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 16px 0 6px; }
.seg {
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 3px; margin-top: 12px;
}
.seg button { padding: 8px; border-radius: 9px; }
.seg button.active { background: var(--accent); color: #fff; font-weight: 600; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.toggle {
  padding: 12px;
  border-radius: 12px;
  background: var(--card);
  border: 2px solid var(--line);
  font-weight: 600;
}
.toggle[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
#quadHint { margin: 8px 2px 0; min-height: 1.4em; }
/* Zeit, Schritte, Timer */
.quick-hint { margin: -6px 0 10px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.step {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
}
.step .box {
  flex: none; width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid var(--muted); display: grid; place-items: center; font-size: 13px;
}
.step.done .box { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.done .step-text { color: var(--muted); text-decoration: line-through; }
.step .step-text { flex: 1; overflow-wrap: anywhere; }
.step .x { color: var(--muted); padding: 0 4px; }
.step-add { display: flex; gap: 8px; margin-top: 8px; }
.step-add .secondary { flex: none; font-size: 20px; padding: 6px 16px; }
.timer-start { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.mission .steps { margin: 12px 0 0; text-align: left; }
.mission .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

#timer {
  position: fixed; inset: 0; z-index: 15;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(20px + env(safe-area-inset-top)) 24px calc(20px + env(safe-area-inset-bottom));
  text-align: center;
}
#timer[hidden] { display: none; }
#timer p { margin: 0; }
.timer-task { font-size: 22px; font-weight: 700; margin: 6px 0 20px !important; max-width: 480px; overflow-wrap: anywhere; }
.ring-wrap { position: relative; width: min(72vw, 300px); aspect-ratio: 1; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg, .ring-fg { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--c, var(--accent)); stroke-linecap: round; stroke-dasharray: 326.73; transition: stroke-dashoffset 1s linear; }
.timer-time { position: absolute; inset: 0; display: grid; place-items: center; font-size: 52px; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer-msg { margin: 20px 0 !important; min-height: 1.4em; }
.timer-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* Weisheiten */
.wisdom {
  display: flex; flex-direction: column; gap: 2px;
  width: 100%; text-align: left;
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.wisdom .w-word { font-weight: 700; font-size: 15px; }
.wisdom .w-jp { font-weight: 400; color: var(--muted); }
.wisdom .w-text { font-size: 15px; }
#timer .wisdom { max-width: 420px; margin: 0 0 20px; text-align: center; }
#timerWisdom:empty { display: none; }

/* Geben & Nehmen */
.debt-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.debt-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--c);
  border-radius: var(--radius);
  padding: 12px;
}
.debt-box .sum { font-size: 22px; font-weight: 700; margin: 2px 0 0; }
.debt-box p { margin: 0; }

/* A-oder-B im Vollbild */
#duelPop {
  width: 100%; height: 100%;
  max-width: none; max-height: none;
  margin: 0; border: 0; border-radius: 0;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
}
#duelPop::backdrop { background: var(--bg); }
.decide {
  max-width: 480px; min-height: 100%;
  margin: 0 auto;
  display: flex; flex-direction: column; justify-content: center; align-items: stretch;
  gap: 12px;
  text-align: center;
}
.decide h2 { font-size: 30px; margin: 0; }
.decide > p { margin: 0; }
.decide .big { font-size: 48px; }
.decide .label { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.decide .option { min-height: 0; padding-top: 34px; }
.decide .option .text { font-size: 20px; }
.decide .or { margin: -2px 0; }
.decide .duel { gap: 8px; margin-top: 6px; }
.decide .joker { margin: 0; }
.decide-cta {
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--card);
  border: 2px dashed var(--accent);
  border-radius: 18px;
  padding: 22px 18px;
}
.decide-cta .big { font-size: 40px; }
.decide-cta .text { font-size: 20px; font-weight: 700; }

.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 22px; }
.spacer { flex: 1; }

/* Toast und Konfetti */
#toast {
  position: fixed;
  left: 50%;
  top: calc(12px + env(safe-area-inset-top));
  transform: translate(-50%, -150%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  transition: transform 0.3s ease;
  z-index: 20;
  max-width: calc(100vw - 32px);
  text-align: center;
}
#toast.show { transform: translate(-50%, 0); }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 19; }
#confetti span {
  position: absolute;
  left: 50%;
  top: 55%;
  font-size: 24px;
  animation: burst 1.3s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
@keyframes burst {
  to {
    transform: translate(var(--x), var(--y)) rotate(var(--r));
    opacity: 0;
  }
}
