:root {
  --bg: #14110f;
  --card: #1f1a17;
  --card-2: #2a231f;
  --line: #3a302a;
  --text: #f6efe9;
  --muted: #a8998e;
  --fire: #ff7a1a;
  --fire-2: #ffb547;
  --gold: #ffd36b;
  --ok: #5fd08a;
  --ice: #7cc8ff;
  --danger: #ff6b5b;
  --radius: 18px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
.app { max-width: 480px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }

/* Start-Animation */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; transition: opacity .35s; }
.splash.out { opacity: 0; pointer-events: none; }
.splash svg { width: 72px; height: 88px; animation: flicker 1.6s ease-in-out infinite; }

/* Kopf */
header.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
header.top h1 { font-size: 15px; font-weight: 600; color: var(--muted); margin: 0; }
.chips { display: flex; gap: 8px; }
.chip { display: flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.chip.ice { color: var(--ice); }
.daytabs { display: flex; background: var(--card); border-radius: 999px; padding: 3px; margin: 4px 0 8px; }
.daytabs button { flex: 1; border: 0; background: none; padding: 6px; border-radius: 999px; color: var(--muted); cursor: pointer; }
.daytabs button.act { background: var(--card-2); color: var(--text); font-weight: 600; }

/* Flamme */
.hero { text-align: center; padding: 8px 0 18px; }
.flame { width: 132px; height: 160px; margin: 0 auto; transition: filter .4s; }
.flame svg { width: 100%; height: 100%; overflow: visible; }
.flame.off { filter: grayscale(1) brightness(.55); }
.flame.on { animation: flicker 2.4s ease-in-out infinite; }
.flame.gold { --flame-fill: url(#gGold); }
.flame.pop { animation: pop .6s ease-out; }
@keyframes flicker { 0%,100% { transform: scale(1) rotate(0); } 30% { transform: scale(1.03,.98) rotate(-1deg); } 60% { transform: scale(.98,1.03) rotate(1deg); } }
@keyframes pop { 0% { transform: scale(.8); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.streak { font-size: 48px; font-weight: 800; line-height: 1; margin-top: -6px; font-variant-numeric: tabular-nums; }
.streak-label { color: var(--muted); margin-top: 4px; }
.status { margin-top: 10px; display: inline-block; padding: 6px 12px; border-radius: 999px; font-size: 13px;
  background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.status.lit { color: var(--fire-2); border-color: #5a3a1e; }
.status.perfect { color: var(--gold); border-color: #6a5420; }

/* Woche */
.week { display: flex; justify-content: space-between; background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; background: var(--card-2); }
.dot.lit { background: #4a2a12; }
.dot.perfect { background: #4d3d12; }
.dot.frozen { background: #18344a; }
.dot.missed { background: #2a1a1a; color: #6a4a4a; }
.day.today .dot { outline: 2px solid var(--fire); outline-offset: 2px; }

/* Level */
.card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.level-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.level-top b { color: var(--text); }
.bar { height: 10px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--fire), var(--fire-2)); border-radius: inherit; transition: width .5s cubic-bezier(.2,.8,.2,1); }

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px 4px; }
section { margin-bottom: 22px; }

/* Gewohnheiten */
.habit { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid transparent;
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; cursor: pointer; user-select: none;
  transition: border-color .2s, background .2s, transform .1s; }
.habit:active { transform: scale(.985); }
.habit .ico { width: 42px; height: 42px; border-radius: 12px; background: var(--card-2); display: grid; place-items: center; font-size: 22px; flex: none; }
.habit .txt { flex: 1; min-width: 0; }
.habit .name { font-weight: 600; }
.habit .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.habit .mini { font-size: 13px; color: var(--muted); white-space: nowrap; }
.habit .more { border: 0; background: var(--card-2); width: 32px; height: 32px; border-radius: 10px; color: var(--muted); cursor: pointer; flex: none; font-size: 18px; line-height: 1; }
.check { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex: none; transition: background .2s, border-color .2s; }
.check svg { width: 16px; height: 16px; opacity: 0; transition: opacity .2s; }
.habit.done { border-color: #4a3020; background: #251c16; }
.habit.done .check { background: var(--fire); border-color: var(--fire); }
.habit.done .check svg { opacity: 1; }
.habit.auto-done .check { background: var(--card-2); border-color: var(--fire); }
.habit.auto-done .check svg { opacity: .7; }
.habit.over .check { border-color: var(--danger); }
.habit.managed { cursor: default; }
.habit.managed:active { transform: none; }
.minutes { width: 70px; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; text-align: right; }

/* Hausübungen */
.hw { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer; user-select: none; }
.hw .txt { flex: 1; min-width: 0; }
.hw .title { font-weight: 600; }
.hw .meta { font-size: 13px; color: var(--muted); }
.hw .check { width: 26px; height: 26px; }
.hw.done { opacity: .55; }
.hw.done .title { text-decoration: line-through; }
.hw.done .check { background: var(--ok); border-color: var(--ok); }
.hw.done .check svg { opacity: 1; }
.hw.busy { opacity: .6; pointer-events: none; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.early { background: #1e3a2a; color: var(--ok); }
.badge.soon { background: #4a2414; color: #ff9b6b; }
.badge.late { background: #4a1414; color: var(--danger); }
.source { font-size: 12px; color: var(--muted); margin: 2px 0 0 4px; }
.empty { color: var(--muted); font-size: 14px; background: var(--card); border-radius: 14px; padding: 14px; text-align: center; }
.warn { color: #ffb08a; background: #2e1a12; border-radius: 14px; padding: 10px 14px; font-size: 14px; }

/* Buch */
.book { display: flex; align-items: center; gap: 12px; }
.book .txt { flex: 1; min-width: 0; }
.book .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book .s { font-size: 13px; color: var(--muted); }

/* Buttons & Formulare */
.btn { border: 0; border-radius: 12px; padding: 10px 14px; background: var(--card-2); cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--fire); color: #1a0d03; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
label.f { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.f input, label.f select { display: block; width: 100%; margin-top: 4px; background: var(--card-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; color: var(--text); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 10px; }
.ok { color: var(--ok); }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 6px 0; }
code.big { display: inline-block; font-size: 22px; font-weight: 800; letter-spacing: .12em; background: var(--card-2); padding: 6px 12px; border-radius: 10px; color: var(--fire-2); }

/* Anmeldung */
.auth { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.auth .flame { width: 90px; height: 110px; }
.auth h1 { margin: 6px 0 4px; font-size: 26px; }
.auth form { text-align: left; margin-top: 18px; }
.auth .btn { width: 100%; padding: 12px; margin-top: 6px; }

/* Heatmap */
.grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, auto); grid-auto-columns: 1fr; gap: 3px; }
.grid i { aspect-ratio: 1; border-radius: 3px; background: var(--card-2); }
.grid i[data-l="1"] { background: #4a2a12; } .grid i[data-l="2"] { background: #8a4416; }
.grid i[data-l="3"] { background: #d4661a; } .grid i[data-l="4"] { background: var(--fire-2); }
.grid i[data-l="p"] { background: var(--gold); } .grid i[data-l="f"] { background: #2a5a80; }
.grid i.future { background: transparent; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; background: var(--c); }

/* Tabellen / Balken */
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: right; color: var(--muted); font-weight: 500; font-size: 12px; padding: 4px; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t td { text-align: right; padding: 8px 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; position: relative; padding-top: 6px; }
.bars .b { flex: 1; background: var(--fire); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .b.over { background: var(--danger); }
.bars .b.none { background: var(--card-2); }
.bars .limit { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--ok); opacity: .7; }
.bars-x { display: flex; gap: 4px; font-size: 10px; color: var(--muted); margin-top: 4px; }
.bars-x span { flex: 1; text-align: center; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.kpi { background: var(--card); border-radius: 14px; padding: 12px; }
.kpi b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--muted); }

/* Erfolge */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ach { background: var(--card); border-radius: 14px; padding: 12px 6px; text-align: center; font-size: 12px; color: var(--muted); }
.ach b { display: block; font-size: 28px; margin-bottom: 4px; }
.ach .n { color: var(--text); font-weight: 600; font-size: 13px; }
.ach.locked b { filter: grayscale(1) opacity(.3); }
.ach.locked .n { color: var(--muted); }

/* Einstellungen */
.set-habit { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.set-habit:first-child { border-top: 0; }
.set-habit input { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; color: var(--text); min-width: 0; }
.set-habit .icon-in { width: 48px; text-align: center; }
.set-habit .name-in { flex: 1; }
.set-habit .lim-in { width: 64px; text-align: right; }
.set-habit.archived { opacity: .5; }

/* Dialog */
dialog { border: 0; border-radius: 22px 22px 0 0; background: var(--card); color: var(--text); padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  width: 100%; max-width: 480px; margin: auto auto 0; }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h3 { margin: 0 0 12px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--fire); color: #1a0d03; font-weight: 800; padding: 8px 16px; border-radius: 999px; transition: .3s; z-index: 40; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* Navigation */
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: rgba(20,17,15,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 30; }
nav.tabs .in { display: flex; max-width: 480px; width: 100%; }
nav.tabs button { flex: 1; border: 0; background: none; padding: 10px 0 12px; color: var(--muted); font-size: 11px; cursor: pointer; }
nav.tabs button span { display: block; font-size: 20px; }
nav.tabs button.act { color: var(--fire-2); }

@media (prefers-reduced-motion: reduce) { .flame.on, .flame.pop, .splash svg { animation: none; } }
