:root {
  --bg: #f6efe6;
  --bg-2: #efe5d8;
  --card: #fffaf4;
  --ink: #3b2f2a;
  --ink-soft: #7a6a60;
  --line: #e6d9c9;
  --accent: #c46f55;
  --accent-ink: #fffaf4;
  --accent-soft: #f3dcd2;
  --sage: #8fa58a;
  --sage-soft: #e3eadf;
  --danger: #b4534a;
  --shadow: 0 1px 2px rgba(74, 52, 40, .06), 0 8px 24px rgba(74, 52, 40, .08);
  --radius: 22px;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221c19;
    --bg-2: #2b2420;
    --card: #2f2723;
    --ink: #f1e6da;
    --ink-soft: #b5a597;
    --line: #42372f;
    --accent: #db8a70;
    --accent-ink: #221c19;
    --accent-soft: #4a3229;
    --sage: #a3b99e;
    --sage-soft: #33392f;
    --danger: #e0857b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  /* ganz zarte Strickmaschen im Hintergrund */
  background-image: radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--ink) 6%, transparent) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: clamp(1.9rem, 6vw, 2.4rem); line-height: 1.15; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.08rem; }
p { margin: 0; }
.muted { color: var(--ink-soft); }
.small { font-size: .88rem; }

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 28px) 16px calc(env(safe-area-inset-bottom) + 110px);
}
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.head .muted { margin-top: 4px; }
.stack > * + * { margin-top: 16px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 30px 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; padding: 13px 22px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 800; cursor: pointer;
  transition: transform .15s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: scale(.97); }
.btn:focus-visible, .chip:focus-visible, .icon-btn:focus-visible, .proj:focus-visible, .tab:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.btn.soft { background: var(--accent-soft); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.block { width: 100%; }
.btn.big { padding: 17px 26px; font-size: 1.08rem; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--ink-soft);
  width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 1.1rem;
}
.icon-btn:hover { background: var(--bg-2); color: var(--ink); }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 380px; text-align: center; padding: 34px 26px; }
.login img { width: 84px; height: 84px; margin-bottom: 14px; animation: wobble 6s ease-in-out infinite; }
.login form { margin-top: 22px; display: grid; gap: 12px; }
.login .err { color: var(--danger); min-height: 1.4em; font-size: .92rem; }

/* ---------- Formulare ---------- */
label.field { display: grid; gap: 6px; font-weight: 700; font-size: .92rem; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--bg);
  border-radius: 14px; padding: 12px 14px; font-weight: 600;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { resize: vertical; min-height: 90px; font-weight: 400; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 10px; }
.form { display: grid; gap: 16px; }
.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.picker button {
  width: 42px; height: 42px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  background: var(--bg-2); font-size: 1.25rem; display: grid; place-items: center;
}
.picker button[aria-pressed="true"] { border-color: var(--ink); }
.picker.colors button { background: var(--c); }

/* ---------- Timer ---------- */
.timer {
  position: relative; overflow: hidden; text-align: center; padding: 30px 22px 26px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--pc) 22%, var(--card)), var(--card) 70%);
}
.timer .yarn { font-size: 3.4rem; display: inline-block; animation: roll 3.2s ease-in-out infinite; }
.timer .clock { font-family: var(--serif); font-size: clamp(3rem, 15vw, 4.4rem); font-variant-numeric: tabular-nums; line-height: 1.1; margin: 10px 0 2px; }
.timer .pname { font-weight: 800; font-size: 1.1rem; }
.timer .actions { margin-top: 22px; display: grid; gap: 10px; }
.pulse { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--pc); margin-right: 6px; animation: pulse 1.8s ease-in-out infinite; vertical-align: middle; }

.start-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left;
  border: 1px solid var(--line); background: var(--card); border-radius: 18px; padding: 16px;
  cursor: pointer; box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .15s ease, border-color .15s;
}
.chip::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--pc); }
.chip:hover { transform: translateY(-2px); border-color: var(--pc); }
.chip .em { font-size: 1.7rem; line-height: 1; }
.chip .nm { font-weight: 800; line-height: 1.25; }
.chip .play { font-size: .82rem; color: var(--ink-soft); font-weight: 700; }
.chip.add { align-items: center; justify-content: center; border-style: dashed; box-shadow: none; background: transparent; color: var(--ink-soft); min-height: 110px; }
.chip.add::before { display: none; }

.today { display: flex; align-items: center; gap: 16px; }
.today .num { font-family: var(--serif); font-size: 1.7rem; line-height: 1.1; }
.ring { width: 58px; height: 58px; flex: none; }

/* ---------- Listen ---------- */
.list { display: grid; gap: 10px; }
.entry {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 14px 14px 16px;
}
.entry .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--pc); margin-top: 7px; }
.entry .top { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.entry .dur { font-weight: 800; }
.entry .note { margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.entry .note:empty { display: none; }

.proj {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 14px; align-items: center; width: 100%;
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow); transition: transform .15s ease;
}
.proj:hover { transform: translateY(-2px); }
.proj .em { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 1.6rem; background: color-mix(in srgb, var(--pc) 22%, var(--card)); }
.proj .nm { font-weight: 800; }
.proj .tm { font-family: var(--serif); font-size: 1.1rem; text-align: right; white-space: nowrap; }
.proj.done { opacity: .72; box-shadow: none; }
.badge { display: inline-block; font-size: .74rem; font-weight: 800; padding: 2px 9px; border-radius: 999px; background: var(--sage-soft); color: var(--ink); margin-left: 6px; vertical-align: 2px; }

.detail-head { display: flex; gap: 16px; align-items: center; }
.detail-head .em { width: 68px; height: 68px; border-radius: 20px; display: grid; place-items: center; font-size: 2.1rem; background: color-mix(in srgb, var(--pc) 25%, var(--card)); flex: none; }
.notes { white-space: pre-wrap; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-soft); text-decoration: none; font-weight: 700; margin-bottom: 14px; }

/* ---------- Statistik ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); }
.kpi .v { font-family: var(--serif); font-size: 1.6rem; line-height: 1.2; margin-top: 2px; }
.kpi .l { color: var(--ink-soft); font-size: .86rem; font-weight: 700; }
.seg { display: inline-flex; background: var(--bg-2); border-radius: 999px; padding: 4px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 7px 14px; font-weight: 800; font-size: .88rem; color: var(--ink-soft); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--ink-soft); font: 700 11px var(--sans); }
.chart .grid { stroke: var(--line); stroke-dasharray: 3 4; }
.bars { display: grid; gap: 12px; }
.bar-row .lbl { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; margin-bottom: 5px; }
.bar-row .track { height: 12px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--pc); border-radius: 999px; transition: width .6s ease; }
.tip { position: fixed; pointer-events: none; background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 10px; font-size: .84rem; font-weight: 700; z-index: 60; opacity: 0; transition: opacity .12s; }

.empty { text-align: center; padding: 34px 20px; }
.empty .big-em { font-size: 3rem; display: block; margin-bottom: 8px; animation: wobble 6s ease-in-out infinite; }

/* ---------- Navigation ---------- */
.tabs {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  display: flex; gap: 4px; padding: 6px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); z-index: 20;
  width: min(420px, calc(100% - 32px));
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  text-decoration: none; color: var(--ink-soft); font-weight: 800; font-size: .76rem;
  padding: 7px 4px; border-radius: 999px; transition: background .15s, color .15s;
}
.tab span { font-size: 1.2rem; line-height: 1.2; }
.tab[aria-current="page"] { background: var(--accent-soft); color: var(--ink); }
.tab.live span { animation: roll 3.2s ease-in-out infinite; display: inline-block; }

/* ---------- Sheet (Dialog) ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(40, 28, 22, .38); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease;
}
.sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto;
  border-radius: 26px 26px 0 0; padding: 22px 20px calc(env(safe-area-inset-bottom) + 22px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .15); animation: up .28s cubic-bezier(.2, .8, .2, 1);
}
.sheet .grab { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: -8px auto 16px; }
.sheet h2 { margin-bottom: 16px; }
@media (min-width: 640px) {
  .overlay { align-items: center; padding: 20px; }
  .sheet { border-radius: 26px; padding-bottom: 24px; }
  .sheet .grab { display: none; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 70; white-space: nowrap; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes roll { 0%, 100% { transform: rotate(-10deg); } 50% { transform: rotate(14deg) translateY(-3px); } }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-6deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

@media (max-width: 380px) {
  .row3 { grid-template-columns: 1fr 1fr; }
  .row3 > :first-child { grid-column: 1 / -1; }
}

/* ---------- Handy-Feinschliff ---------- */
/* iOS gibt Datums-/Zeitfeldern sonst eine Mindestbreite und lässt sie aus dem Raster laufen. */
.field, .row > *, .row3 > * { min-width: 0; }
.input { min-width: 0; max-width: 100%; font-size: 16px; min-height: 50px; }
input[type="date"].input, input[type="time"].input {
  -webkit-appearance: none; appearance: none; display: block; width: 100%;
  text-align: left; line-height: 1.3;
}
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
input[type="date"]::-webkit-calendar-picker-indicator, input[type="time"]::-webkit-calendar-picker-indicator { opacity: .55; }
@media (prefers-color-scheme: dark) {
  input[type="date"]::-webkit-calendar-picker-indicator, input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(1); }
}
select.input {
  -webkit-appearance: none; appearance: none; padding-right: 42px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 22px) 52%, calc(100% - 16px) 52%;
  background-size: 6px 6px; background-repeat: no-repeat;
}

.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.quick button {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px;
  padding: 9px 14px; min-height: 40px; font-weight: 800; font-size: .9rem; cursor: pointer;
}
.quick button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.quick.days { margin-bottom: 2px; }
.dur-hint { color: var(--ink-soft); font-weight: 700; margin-top: -6px; }
.dur-hint.bad { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.forgot { border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; background: var(--bg); }
.forgot summary { font-weight: 800; cursor: pointer; color: var(--ink-soft); list-style: none; }
.forgot summary::-webkit-details-marker { display: none; }
.forgot summary::before { content: '🕰️ '; }
.forgot[open] summary { color: var(--ink); }

/* Sheet: Hintergrund steht still, Sheet scrollt für sich, Tastatur schiebt nichts kaputt */
body.sheet-open { overflow: hidden; }
.sheet { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.overlay { height: 100dvh; }

/* Bessere Touch-Ziele und kein Text-Markieren beim Tippen */
.chip, .proj, .tab, .btn, .quick button, .picker button { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
.entry .icon-btn { width: 44px; height: 44px; margin: -6px -6px -6px 0; }
.bar-row .lbl { flex-wrap: wrap; }
.bar-row .lbl > span:first-child { min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 520px) {
  .wrap { padding-top: calc(env(safe-area-inset-top) + 20px); }
  .card { padding: 18px 16px; }
  .head { margin-bottom: 18px; }
  .sheet { padding-left: 16px; padding-right: 16px; }
  .sheet h2 { font-size: 1.5rem; }
  .start-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .chip { padding: 14px; min-height: 118px; }
  .timer .actions .btn { min-height: 56px; }
  .kpi { padding: 14px; }
  .kpi .v { font-size: 1.4rem; }
  .btn-row .btn { flex: 1 1 100%; }
  .section-title { flex-wrap: wrap; gap: 8px; }
  .picker { gap: 6px; }
  .picker button { width: 44px; height: 44px; }
  #toast { bottom: calc(env(safe-area-inset-bottom) + 100px); }
}
