:root {
    --bg:        #0f172a;
    --surface:   #1e293b;
    --surface-2: #273449;
    --line:      #334155;
    --text:      #e2e8f0;
    --muted:     #94a3b8;
    --accent:    #38bdf8;
    --accent-2:  #34d399;
    --warn:      #fbbf24;
    --radius:    16px;
    --maxw:      560px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ---- Topbar ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding: env(safe-area-inset-top) 16px 0;
    height: calc(56px + env(safe-area-inset-top));
    display: flex;
    align-items: center;
}
.brand { color: var(--text); text-decoration: none; font-weight: 800; font-size: 1.2rem; letter-spacing: -0.02em; }
.brand-mark { color: var(--accent); }
.brand-accent { color: var(--accent-2); }

/* ---- Layout ---- */
.content {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 20px 16px calc(96px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.5rem; margin: 4px 0 2px; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; margin: 24px 0 10px; color: var(--text); }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 0.95rem; }

/* ---- Cards & Stats ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
}

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    text-align: center;
}
.stat .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 2.1rem; font-weight: 800; margin-top: 6px; letter-spacing: -0.02em; }
.stat .unit { font-size: 1rem; color: var(--muted); font-weight: 600; }
.stat.accent .value  { color: var(--accent); }
.stat.accent2 .value { color: var(--accent-2); }
.stat .delta { font-size: 0.82rem; margin-top: 4px; color: var(--muted); }
.delta.down { color: var(--accent-2); }
.delta.up   { color: var(--warn); }

/* ---- Goals ---- */
.goal-list { list-style: none; margin: 0; padding: 0; }
.goal {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 0; border-bottom: 1px solid var(--line);
}
.goal:last-child { border-bottom: none; }
.goal .txt { flex: 1; }
.goal .cat { font-size: 0.72rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }
.goal.done .txt { text-decoration: line-through; color: var(--muted); }
.goal input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent-2); }

/* ---- Wochen-Fortschritt (80/20) ---- */
.progress-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; font-size: 0.95rem; }
.progress-pct { font-size: 1.3rem; font-weight: 800; color: var(--accent); }
.progress-pct.ok { color: var(--accent-2); }
.progress-track {
    position: relative; height: 14px; border-radius: 999px;
    background: var(--surface-2); overflow: hidden;
}
.progress-fill {
    height: 100%; border-radius: 999px;
    background: var(--accent); transition: width 0.4s ease;
}
.progress-fill.ok { background: var(--accent-2); }
/* 80%-Marke */
.progress-marker {
    position: absolute; top: -3px; bottom: -3px; left: 80%;
    width: 2px; background: var(--text); opacity: 0.55;
}
.progress-note { margin: 10px 0 0; font-size: 0.85rem; color: var(--muted); }
.progress-note.ok { color: var(--accent-2); font-weight: 600; }

/* ---- Sterne (80/20-Belohnung) ---- */
.star { line-height: 1; font-size: 1.3rem; }
.star.gold   { color: #fbbf24; text-shadow: 0 0 8px rgba(251,191,36,0.55); }
.star.silver { color: #cbd5e1; text-shadow: 0 0 6px rgba(203,213,225,0.35); }
.star.none   { color: var(--line); }

.week-star { text-align: center; font-size: 3.4rem; line-height: 1; margin-bottom: 6px; color: var(--line); }
.week-star.gold   { color: #fbbf24; text-shadow: 0 0 18px rgba(251,191,36,0.6); }
.week-star.silver { color: #cbd5e1; text-shadow: 0 0 14px rgba(203,213,225,0.4); }

.goal-star { width: 1.6rem; text-align: center; font-size: 1.3rem; }
.goal-count { color: var(--muted); font-size: 0.9rem; font-weight: 600; white-space: nowrap; }
.goal-status { color: var(--muted); font-size: 0.8rem; }
.badge {
    display: inline-block; font-size: 0.68rem; font-weight: 700;
    color: var(--accent-2); background: rgba(52,211,153,0.12);
    border: 1px solid var(--accent-2); border-radius: 999px;
    padding: 1px 7px; vertical-align: middle;
}

/* Ziel-Zeile mit Zähler (Ziele-Seite) */
.goal-edit { list-style: none; padding: 14px 0; border-bottom: 1px solid var(--line); }
.goal-edit:last-child { border-bottom: none; }
.goal-edit-top { display: flex; align-items: center; gap: 12px; }
.goal-edit-top .txt { flex: 1; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 4px; }

.goal-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 10px 0 0; }
.goal-bar-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.35s ease; }
.goal-bar-fill.silver { background: #cbd5e1; }
.goal-bar-fill.gold   { background: #fbbf24; }

.counter { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.count-btn {
    width: 42px; height: 42px; border-radius: 50%;
    border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
    font-size: 1.5rem; font-weight: 700; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.count-btn:active { transform: translateY(1px); }
.count-val { font-size: 1.15rem; font-weight: 800; min-width: 64px; text-align: center; }
.count-val small { color: var(--muted); font-weight: 500; }
.count-pct { margin-left: auto; color: var(--accent); font-weight: 700; }

/* ---- Popup / Limit-Modal ---- */
.modal-overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(2, 6, 23, 0.7); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    animation: fadein 0.18s ease;
}
.modal {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 20px; padding: 22px; max-width: 360px; width: 100%;
    text-align: center;
    animation: pop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-img { max-width: 100%; height: auto; border-radius: 14px; margin-bottom: 14px; }
.modal-fallback { font-size: 4rem; margin-bottom: 8px; }
.modal h3 { margin: 6px 0 4px; font-size: 1.3rem; }
.modal p { color: var(--muted); margin: 0 0 8px; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---- Forms ---- */
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 14px 0 6px; }
input[type=text], input[type=number], input[type=password], select, textarea {
    width: 100%; padding: 13px 14px;
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--line); border-radius: 12px;
    font-size: 1rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

input[type=range] { width: 100%; accent-color: var(--accent); }
.range-row { display: flex; align-items: center; gap: 14px; }
.range-val { font-size: 1.8rem; font-weight: 800; min-width: 2ch; text-align: center; color: var(--accent); }

.btn {
    display: inline-block; width: 100%; margin-top: 18px;
    padding: 14px; border: none; border-radius: 12px;
    background: var(--accent); color: #042f3d;
    font-size: 1.05rem; font-weight: 800; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 0; }

.flash { background: rgba(52,211,153,0.12); border: 1px solid var(--accent-2); color: var(--accent-2); padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* ---- Verlauf-Tabelle ---- */
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { padding: 11px 8px; text-align: right; border-bottom: 1px solid var(--line); }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---- Tabbar ---- */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex;
    background: rgba(15,23,42,0.92);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
    flex: 1; text-align: center; text-decoration: none;
    color: var(--muted); font-size: 0.72rem; font-weight: 600;
    padding: 10px 0 8px;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabbar a .ico { font-size: 1.25rem; line-height: 1; filter: grayscale(0.4) opacity(0.85); }
.tabbar a.active { color: var(--accent); }
.tabbar a.active .ico { filter: none; }

@media (min-width: 600px) {
    .tabbar { max-width: var(--maxw); margin: 0 auto; border-radius: 18px 18px 0 0; }
}
