:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --ink: #1d1f23;
  --ink-2: #5d5f66;
  --ink-3: #8e9098;
  --line: #e2dccf;
  --accent: #1d1f23;
  --accent-ink: #fffdf8;
  --good: #16a37b;
  --warn: #c2862b;
  --bad: #d64545;

  --water: #2f80ed;
  --eat: #16a37b;
  --steps: #e07a1f;
  --plank: #8b5cf6;
  --sport: #e2553f;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 0 rgba(0,0,0,.04), 0 8px 24px -12px rgba(40,30,10,.18);
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --surface-2: #262a31;
    --ink: #f0ede6;
    --ink-2: #b4b4b8;
    --ink-3: #7d7f86;
    --line: #2e323a;
    --accent: #f0ede6;
    --accent-ink: #14161a;
    --water: #5b9df5;
    --eat: #2fc496;
    --steps: #f0913a;
    --plank: #a585fa;
    --sport: #f06a55;
    --shadow: 0 1px 0 rgba(255,255,255,.03), 0 8px 24px -12px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

#app { max-width: 640px; margin: 0 auto; min-height: 100dvh; }

/* ---------- Topbar & Tabbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px;
}
.brand { font-weight: 800; letter-spacing: -.02em; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: conic-gradient(var(--water) 0 20%, var(--eat) 0 40%, var(--steps) 0 60%, var(--plank) 0 80%, var(--sport) 0);
}
.me { font-size: 14px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.view { padding: 8px 16px calc(96px + env(safe-area-inset-bottom)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  max-width: 640px; margin: 0 auto;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-decoration: none; font-size: 12px; font-weight: 600; color: var(--ink-3);
  padding: 6px 0; border-radius: 12px;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--ink); }
.tabbar a.active svg { stroke-width: 2.6; }

/* ---------- Grundbausteine ---------- */
h1 { font-size: 28px; letter-spacing: -.03em; margin: 8px 0 4px; line-height: 1.1; }
h2 { font-size: 18px; letter-spacing: -.01em; margin: 28px 0 10px; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}

.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; padding: 12px 18px; border-radius: 14px; min-height: 46px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: transparent; color: var(--bad); box-shadow: inset 0 0 0 1.5px currentColor; }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn {
  appearance: none; border: 0; background: var(--surface); box-shadow: var(--shadow);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 20px; font-weight: 700;
  display: grid; place-items: center;
}
.icon-btn:disabled { opacity: .3; cursor: default; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); min-height: 46px; outline: none;
}
input:focus-visible, select:focus-visible { border-color: var(--ink-2); }
:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack > * + * { margin-top: 10px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- Login ---------- */
.login { min-height: 90dvh; display: grid; place-items: center; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.login h1 { margin-bottom: 4px; }
.login .brand-mark { width: 44px; height: 44px; border-radius: 14px; margin-bottom: 16px; }

/* ---------- Wochen-Navigation ---------- */
.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0 14px; }
.weeknav .title { text-align: center; }
.weeknav .kw { font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.weeknav .range { font-size: 13px; color: var(--ink-2); }

/* ---------- Tagesleiste ---------- */
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 14px; }
.day {
  appearance: none; border: 0; cursor: pointer; padding: 8px 0 7px; border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.day .wd { font-size: 11px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.day .dn { font-size: 18px; font-weight: 800; }
.day .bars { display: flex; gap: 2px; margin-top: 3px; }
.day .bars i { width: 5px; height: 5px; border-radius: 2px; background: var(--surface-2); }
.day.sel { background: var(--accent); color: var(--accent-ink); }
.day.sel .wd { color: inherit; opacity: .7; }
.day.today:not(.sel) { box-shadow: var(--shadow), inset 0 0 0 2px var(--ink); }
.day:disabled { opacity: .35; cursor: default; box-shadow: none; }
.day.locked .dn::after { content: ""; }

/* ---------- Wochen-Zusammenfassung ---------- */
.summary { display: flex; align-items: center; gap: 16px; }
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--ink) calc(var(--p) * 1%), var(--surface-2) 0);
  display: grid; place-items: center; }
.ring::before { content: ""; grid-area: 1/1; width: 50px; height: 50px; border-radius: 50%; background: var(--surface); }
.ring b { grid-area: 1/1; z-index: 1; font-size: 17px; }
.summary .big { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.sportdots { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.sportdots i { width: 12px; height: 12px; border-radius: 50%; background: var(--surface-2); }
.sportdots i.on { background: var(--sport); }
.sportdots i.extra { background: color-mix(in srgb, var(--sport) 45%, transparent); }

/* ---------- Ziel-Karten ---------- */
.goal { border-left: 5px solid var(--c); }
.goal .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.goal .name { font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.goal .hint { font-size: 12.5px; color: var(--ink-3); margin-top: 8px; }
.pts {
  font-size: 13px; font-weight: 800; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.pts.p1 { background: color-mix(in srgb, var(--c) 22%, transparent); color: var(--ink); }
.pts.p2 { background: var(--c); color: #fff; }

.stepper { display: flex; align-items: stretch; gap: 8px; }
.stepper button {
  appearance: none; border: 0; width: 52px; border-radius: 12px; cursor: pointer;
  background: var(--surface-2); font-size: 22px; font-weight: 700;
}
.stepper input { text-align: center; font-size: 20px; font-weight: 800; flex: 1; }
.quick { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.quick button {
  appearance: none; border: 0; cursor: pointer; padding: 6px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: 13px; font-weight: 600;
}

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button {
  appearance: none; border: 0; cursor: pointer; padding: 12px 6px; border-radius: 12px;
  background: var(--surface-2); font-weight: 700; font-size: 15px; min-height: 48px;
}
.seg button.on { background: var(--c); color: #fff; }
.seg button.on.partial { background: color-mix(in srgb, var(--c) 30%, var(--surface)); color: var(--ink); }
.seg button.on.zero { background: var(--ink-2); color: var(--surface); }
fieldset:disabled .seg button, fieldset:disabled .stepper button, fieldset:disabled .quick button { cursor: default; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled .goal { opacity: .75; }

.savestate { font-size: 13px; color: var(--ink-3); text-align: center; min-height: 20px; margin-top: 4px; }
.notice {
  font-size: 14px; padding: 10px 14px; border-radius: 12px; margin-bottom: 12px;
  background: var(--surface-2); color: var(--ink-2);
}

/* ---------- Rangliste ---------- */
.status-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.status-chip.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.player .top { display: flex; align-items: center; gap: 12px; }
.rank {
  width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 900; font-size: 16px; background: var(--surface-2); flex: none;
}
.rank.r1 { background: #f2c94c; color: #3a2c00; }
.rank.r2 { background: #cfd4dc; color: #2a2e35; }
.rank.r3 { background: #e0a173; color: #3b1d06; }
.player .who { flex: 1; min-width: 0; }
.player .who b { display: flex; align-items: center; gap: 7px; font-size: 16px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; }
.player .score { text-align: right; }
.player .score .big { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.pay { font-size: 12.5px; font-weight: 700; color: var(--bad); }
.pay.ok { color: var(--good); }

.matrix { display: grid; grid-template-columns: 62px repeat(7, 1fr) 48px; gap: 3px; margin-top: 14px; font-size: 11.5px; align-items: center; }
.matrix .lbl { color: var(--ink-2); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.matrix .hd { text-align: center; color: var(--ink-3); font-weight: 700; }
.matrix .sum { text-align: right; font-weight: 700; color: var(--ink-2); }
.cell { height: 20px; border-radius: 5px; background: var(--surface-2); }
.cell.p1 { background: color-mix(in srgb, var(--c) 35%, var(--surface-2)); }
.cell.p2 { background: var(--c); }
.cell.sp { display: grid; place-items: center; font-weight: 800; font-size: 11px; color: #fff; }
.cell.future { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-3); margin: 6px 0 14px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); display: inline-block; }

details.more summary { cursor: pointer; font-size: 13px; color: var(--ink-3); margin-top: 10px; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }

/* ---------- Tabellen ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 700; padding: 0 6px 8px; }
.table td { padding: 9px 6px; border-top: 1px solid var(--line); }
.table .r { text-align: right; }
.table td.name { font-weight: 700; }
.weekrow { display: grid; grid-template-columns: 28px 1fr auto auto; gap: 8px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.weekrow:first-of-type { border-top: 0; }
.weekrow .p { color: var(--ink-3); font-weight: 800; }
.paidbox { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.paidbox input { width: 18px; height: 18px; accent-color: var(--good); }

.userrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.userrow:first-of-type { border-top: 0; }
.userrow .info { flex: 1; min-width: 0; }
.tag { font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); margin-left: 6px; }
.payrow { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 8px; align-items: center; margin-bottom: 8px; }

.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  z-index: 50; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}
.toast.err { background: var(--bad); color: #fff; }

@media (max-width: 360px) {
  .day .dn { font-size: 16px; }
  .matrix { grid-template-columns: 52px repeat(7, 1fr) 40px; }
}
@media (prefers-reduced-motion: no-preference) {
  .day, .seg button, .btn { transition: background-color .15s, color .15s, transform .1s; }
  .seg button:active, .btn:active, .day:active { transform: scale(.97); }
}
