:root {
  --bg: #f7f5f2; --fg: #24201d; --muted: #6b635c; --card: #ffffff; --line: #e4ddd5;
  --accent: #c2410c; --on-accent: #ffffff; --danger: #b3261e; --ok: #2e7d4f;
  --chip: #fff1e6; --rumble: #dbe4f0; --on-rumble: #1e2b3c;
  --l1: #f3d77a; --l2: #f0b45a; --l3: #e8853e; --l4: #d8552e; --l5: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151210; --fg: #ece6e1; --muted: #a59b93; --card: #1f1a17; --line: #352d28;
          --accent: #fb923c; --on-accent: #24120a; --danger: #f2867d; --ok: #8fc79b;
          --chip: #2e221a; --rumble: #2a3442; --on-rumble: #dbe4f0; }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
/* The home-screen app draws under the status bar and iOS reports the safe area as ~0 there:
   keep the header clear of the clock (html.standalone is set in app.js). */
html.standalone body { padding-top: max(40px, calc(env(safe-area-inset-top, 0px) + 24px)); }
main { max-width: 32rem; margin: 0 auto; padding: 16px 0 32px; }
header { display: flex; justify-content: space-between; align-items: baseline; }
h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .9rem; color: var(--muted); font-weight: 600; margin: 12px 0 4px; }
section { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
section.when { padding: 12px 16px; }
button, label.secondary { font: inherit; cursor: pointer; }
button:disabled { opacity: .6; }
button.primary { width: 100%; padding: 14px; border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent); font-weight: 600; }
header nav { display: flex; gap: 16px; align-items: baseline; }
header nav a { text-decoration: none; font-weight: 600; }
.wide { display: block; width: 100%; }
a.secondary { text-decoration: none; }
button.secondary, label.secondary, a.secondary { padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); font-weight: 600; white-space: nowrap; text-align: center; margin: 0; }
button.danger { width: 100%; padding: 12px; border: 1px solid var(--danger); border-radius: 10px; background: none; color: var(--danger); font-weight: 600; }
button.link { background: none; border: 0; color: var(--muted); padding: 0; }
input { width: 100%; font: inherit; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); margin-bottom: 12px; min-width: 0; }
label { display: block; margin-bottom: 4px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: flex-start; }
.row input { flex: 1; }
/* iOS draws date fields with its own height and centred text: drop the native look and give
   the field and the "Jetzt" button the same height so they line up. */
input[type="datetime-local"] { -webkit-appearance: none; appearance: none; min-height: 44px; line-height: 22px; text-align: left; }
input[type="datetime-local"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
.when .row { align-items: stretch; }
.when input, .when button { height: 44px; margin: 0; }
.when button { padding-top: 0; padding-bottom: 0; }
/* Quick pick and portion: compact chips sized to their text. */
.quick, .portion { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.chip { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--chip); color: var(--fg); font-size: .95rem; max-width: 100%; overflow-wrap: anywhere; text-align: left; }
.chip.chosen { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.portion .chip { padding: 5px 12px; font-size: .9rem; background: var(--bg); }
.portion .chip.chosen { background: var(--accent); }
.portion .hint { margin-right: 2px; }
.quickhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chip.toggle { padding: 4px 12px; font-size: .85rem; background: var(--bg); }
.chip.toggle.chosen { background: var(--accent); color: var(--on-accent); }
.multi-submit { margin-bottom: 12px; }
.multi-submit[hidden] { display: none; }
.rumble { width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--rumble); color: var(--on-rumble); font-weight: 600; margin-bottom: 12px; }
.rumble small { color: inherit; opacity: .75; font-weight: 400; margin-left: 4px; }
.rumble-tag { background: var(--rumble); color: var(--on-rumble); }
.scale { margin: 0 0 6px; }
.amount { margin-left: 2px; }
.pain { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.level { display: flex; flex-direction: column; align-items: center; padding: 10px 2px; border-radius: 10px; border: 2px solid transparent; color: #1d241e; }
.level b { font-size: 1.2rem; }
.level small { font-size: .68rem; color: inherit; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.level.chosen { border-color: var(--fg); }
.level-1 { background: var(--l1); } .level-2 { background: var(--l2); } .level-3 { background: var(--l3); }
.level-4 { background: var(--l4); color: #fff; } .level-5 { background: var(--l5); color: #fff; }
.entries { list-style: none; margin: 0; padding: 0; }
.entries a { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--fg); text-decoration: none; }
.entries time { color: var(--muted); font-variant-numeric: tabular-nums; }
.entries .note { flex-basis: 100%; padding-left: 3.2em; }
.tag { border-radius: 6px; padding: 1px 6px; font-size: .85rem; white-space: nowrap; }
a { color: var(--accent); }
.hint, small { color: var(--muted); font-size: .8rem; }
/* Messages float at the bottom of the screen, so they (and "Rückgängig") are seen after a reload. */
.message { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); z-index: 5;
           max-width: 32rem; margin: 0 auto; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line);
           background: var(--card); color: var(--danger); box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.message:empty { display: none; }
.message.ok { color: var(--ok); }
main { padding-bottom: 96px; }

.scanner { position: fixed; inset: 0; background: #000; z-index: 10; display: flex; flex-direction: column; }
.scanner[hidden] { display: none; }
.scanner video { flex: 1; width: 100%; min-height: 0; object-fit: cover; }
.scanner-frame { position: absolute; left: 8%; right: 8%; top: 35%; height: 18%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 12px; pointer-events: none; }
.scanner-state { color: #fff; text-align: center; margin: 12px 16px 0; }
.scanner-actions { display: flex; gap: 8px; justify-content: center; padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px); }

/* Evening check-in, undo, reminder */
.checkin { border: 2px solid var(--accent); }
.checkin p { margin: 0 0 12px; }
.checkin .hint { margin: 10px 0 0; }
.done-tag { background: #d7eedc; color: #1f4d2b; }
.undo { color: var(--accent); font-weight: 600; text-decoration: underline; margin-left: 4px; }
#push .link { display: block; margin: 12px auto 0; }

/* Week view: one 24 h timeline per day */
.weeknav { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 12px; }
.weeknav a { text-decoration: none; font-weight: 600; }
.weeknav span { color: var(--muted); font-size: .9rem; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .mark { position: static; transform: none; }
.day { border-bottom: 1px solid var(--line); }
.day summary { list-style: none; cursor: pointer; padding: 10px 0 8px; }
.day summary::-webkit-details-marker { display: none; }
.dayhead { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.timeline { position: relative; display: block; height: 22px; border-radius: 6px; background: var(--bg); }
.tick { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.mark { position: absolute; top: 50%; transform: translate(-50%, -50%); display: inline-block; border-radius: 50%; }
.m-meal { width: 9px; height: 9px; background: var(--fg); opacity: .7; }
.m-rumble { width: 11px; height: 11px; background: #8aa4c8; }
.m-pain { width: 14px; height: 14px; box-shadow: 0 0 0 2px var(--card); }
.legend .m-pain { width: 12px; height: 12px; }
.day .entries { margin-bottom: 8px; }
.axis { position: relative; height: 1.2em; margin: 6px 0 0; }
.axis span { position: absolute; transform: translateX(-50%); }
.axis span:first-child { transform: none; }
.axis span:last-child { transform: translateX(-100%); }
@media (prefers-color-scheme: dark) {
  .done-tag { background: #23402b; color: #bfe6c8; }
}
