:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1b1f26;
  --surface-3: #242a33;
  --line: #262c35;
  --text: #eef1f5;
  --muted: #8b94a3;
  --faint: #5b6473;
  --accent: #c8f53c;
  --accent-ink: #11160a;
  --accent-soft: rgba(200, 245, 60, 0.12);
  --easy: #3ddc97;
  --mid: #f5b83c;
  --hard: #ff5d5d;
  --danger: #ff5d5d;
  --radius: 16px;
  --radius-sm: 11px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
/* verhindert Doppeltipp-Zoom (z. B. bei schnellem +/-), Pinch-Zoom bleibt möglich */
html, body, button, input, textarea, label { touch-action: manipulation; }
button { -webkit-user-select: none; user-select: none; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }
svg { display: block; }
.muted { color: var(--muted); }
h2 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }

/* Icons */
[data-icon] { display: inline-flex; width: 20px; height: 20px; flex: none; }
[data-icon] svg { width: 100%; height: 100%; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-t)) 18px 12px;
  background: rgba(11, 13, 16, 0.85);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-mark {
  width: 30px; height: 30px; padding: 6px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
}
.topbar-date { color: var(--muted); font-size: 13px; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Scan hero */
.scan-hero {
  width: 100%;
  display: flex; align-items: center; gap: 14px;
  padding: 18px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-ink);
  text-align: left;
  box-shadow: 0 10px 30px -12px rgba(200, 245, 60, 0.45);
  transition: transform 0.12s ease;
}
.scan-hero:active { transform: scale(0.98); }
.scan-hero-icon { width: 48px; height: 48px; padding: 11px; border-radius: 14px; background: rgba(0, 0, 0, 0.1); }
.scan-hero-text { flex: 1; display: flex; flex-direction: column; }
.scan-hero-text strong { font-size: 18px; letter-spacing: -0.01em; }
.scan-hero-text small { font-size: 13px; opacity: 0.7; }

.link-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px; margin-top: 8px;
  color: var(--muted); font-weight: 500; font-size: 14px;
}
.link-btn [data-icon] { width: 17px; height: 17px; }
.link-btn.light { color: #fff; opacity: 0.85; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 2px 12px; }

/* Stats */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 10px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.stat b { font-size: 19px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat.accent b { color: var(--accent); }

/* Cards */
.stack { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.entry { display: flex; gap: 12px; align-items: flex-start; }
.entry-num {
  flex: none; width: 28px; height: 28px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--muted); font-size: 13px; font-weight: 600;
}
.entry-main { flex: 1; min-width: 0; }
.entry-title { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.entry-title strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-time { color: var(--faint); font-size: 12.5px; font-variant-numeric: tabular-nums; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip i { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.d-einfach { background: var(--easy); }
.d-moderat { background: var(--mid); }
.d-schwer { background: var(--hard); }

.icon-btn {
  flex: none; width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn [data-icon] { width: 18px; height: 18px; }
.icon-btn.danger:active { color: var(--danger); }
.icon-btn-dark { background: rgba(0, 0, 0, 0.45); color: #fff; width: 44px; height: 44px; border-radius: 50%; }

.empty {
  text-align: center; color: var(--muted);
  padding: 34px 16px; border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty [data-icon] { display: flex; width: 30px; height: 30px; margin: 0 auto 10px; color: var(--faint); }

/* Segmented */
.segmented {
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 4px; gap: 4px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--line);
}
.segmented button { padding: 9px 0; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.segmented button.active { background: var(--surface-3); color: var(--text); }

/* Day card */
.day-head { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; }
.day-head .grow { flex: 1; min-width: 0; }
.day-head strong { font-size: 16px; display: block; }
.day-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.day-head [data-icon="chevron"] { color: var(--faint); transition: transform 0.2s; }
.day.open .day-head [data-icon="chevron"] { transform: rotate(90deg); }
.day-body { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.day.open .day-body { display: flex; flex-direction: column; gap: 14px; }

/* Device list */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.search [data-icon] { width: 17px; height: 17px; }
.search input { flex: 1; background: none; border: 0; outline: 0; padding: 12px 0; color: var(--text); min-width: 0; font-size: 16px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; text-align: left;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-2); }
.row-icon {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.row-icon [data-icon] { width: 18px; height: 18px; }
.row-main { flex: 1; min-width: 0; }
.row-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main small { color: var(--muted); font-size: 13px; }
.row > [data-icon="chevron"] { color: var(--faint); width: 18px; height: 18px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border-radius: 13px;
  font-weight: 650; font-size: 15px;
  background: var(--surface-3); color: var(--text);
  transition: transform 0.1s ease, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: rgba(255, 93, 93, 0.12); color: var(--danger); }
.btn-block { width: 100%; padding: 16px; font-size: 16px; }
.btn-icon-text { padding: 0 16px; }
.btn [data-icon] { width: 18px; height: 18px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* FAB */
.fab {
  position: fixed; z-index: 30;
  right: 18px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 58px; height: 58px; border-radius: 18px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 12px 28px -8px rgba(200, 245, 60, 0.5), 0 4px 10px rgba(0, 0, 0, 0.4);
  transition: transform 0.12s ease;
}
.fab:active { transform: scale(0.93); }
.fab [data-icon] { width: 26px; height: 26px; }
body.on-heute .fab { display: none; }

/* Tabbar */
.tabbar {
  position: fixed; z-index: 25; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(14, 16, 20, 0.92);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--faint); font-size: 11.5px; font-weight: 600;
}
.tabbar button [data-icon] { width: 23px; height: 23px; }
.tabbar button.active { color: var(--accent); }

/* Scanner */
.scanner { position: fixed; inset: 0; z-index: 60; background: #000; overflow: hidden; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner-shade {
  position: absolute; left: 50%; top: 45%;
  width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 28px;
  box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.55);
}
.scanner-frame {
  position: absolute; left: 50%; top: 45%;
  width: min(70vw, 300px); aspect-ratio: 1; transform: translate(-50%, -50%);
}
.scanner-frame i { position: absolute; width: 44px; height: 44px; border: 4px solid var(--accent); }
.scanner-frame i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 28px; }
.scanner-frame i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 28px; }
.scanner-frame i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 28px; }
.scanner-frame i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 28px; }
.scanner-line {
  position: absolute; left: 12%; right: 12%; height: 2px; top: 50%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: sweep 1.6s ease-in-out infinite;
}
@keyframes sweep { 0%, 100% { top: 14%; } 50% { top: 86%; } }
.scanner.hit .scanner-frame i { border-color: #fff; }
.scanner-top { position: absolute; top: calc(14px + var(--safe-t)); right: 16px; }
.scanner-bottom {
  position: absolute; left: 0; right: 0; bottom: calc(24px + var(--safe-b));
  text-align: center; color: #fff; padding: 0 24px;
}
.scanner-bottom p { margin: 0 0 6px; font-weight: 600; font-size: 16px; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6); }

/* Sheet */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  animation: fade-in 0.2s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.sheet {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
  max-width: 640px; margin: 0 auto;
  max-height: calc(100vh - var(--safe-t) - 28px);
  max-height: calc(100dvh - var(--safe-t) - 28px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 24px 24px 0 0;
  animation: slide-up 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes slide-up { from { transform: translateY(100%); } }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 8px auto 0; flex: none; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 18px calc(18px + var(--safe-b)); overscroll-behavior: contain; }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.sheet-head .grow { flex: 1; min-width: 0; }
.sheet-head h3 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.sheet-head p { margin: 3px 0 0; color: var(--muted); font-size: 13.5px; }
.sheet-foot {
  position: sticky; bottom: calc(-18px - var(--safe-b));
  margin: 16px -18px calc(-18px - var(--safe-b));
  padding: 12px 18px calc(14px + var(--safe-b));
  background: linear-gradient(to bottom, rgba(20, 23, 28, 0), var(--surface) 30%);
}

/* Last-time box */
.last-box {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 16px;
}
.last-box-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.last-box-head b { color: var(--text); font-weight: 600; }
.last-box .chips { margin-top: 8px; }

/* Set editor */
.set {
  border: 1px solid var(--line); border-radius: 16px;
  padding: 12px; margin-bottom: 10px; background: var(--surface-2);
}
.set-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.set-top strong { font-size: 14px; color: var(--muted); font-weight: 600; }
.set-fields { display: grid; grid-template-columns: 1.15fr 1fr; gap: 10px; }
.field-label { display: block; font-size: 11.5px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 6px 2px; }
.stepper {
  display: flex; align-items: stretch;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.stepper button { width: 40px; flex: none; display: grid; place-items: center; color: var(--muted); }
.stepper button:active { background: var(--surface-3); color: var(--text); }
.stepper button [data-icon] { width: 16px; height: 16px; }
.stepper input {
  flex: 1; min-width: 0; width: 100%;
  background: none; border: 0; outline: 0;
  text-align: center; font-size: 19px; font-weight: 700; padding: 10px 0;
  font-variant-numeric: tabular-nums;
}
.stepper:focus-within { border-color: var(--accent); }
.diff { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.diff button {
  padding: 9px 0; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.diff button i { width: 8px; height: 8px; border-radius: 50%; }
.diff button.on.einfach { border-color: var(--easy); color: var(--easy); background: rgba(61, 220, 151, 0.1); }
.diff button.on.moderat { border-color: var(--mid); color: var(--mid); background: rgba(245, 184, 60, 0.1); }
.diff button.on.schwer { border-color: var(--hard); color: var(--hard); background: rgba(255, 93, 93, 0.1); }
.add-set {
  width: 100%; padding: 13px; border-radius: 14px;
  border: 1px dashed var(--line); color: var(--muted); font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.add-set [data-icon] { width: 17px; height: 17px; }

/* Forms */
.form-field { margin-bottom: 14px; }
.input, textarea.input {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line); outline: 0;
  font-size: 16px;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; min-height: 80px; }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn .input { flex: 1; min-width: 0; font-size: 14px; }
.input-with-btn .btn { padding: 0 14px; }

/* Device detail */
.kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.chart {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 12px 6px; margin-bottom: 16px;
}
.chart-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.chart svg { width: 100%; height: 160px; overflow: visible; }
.chart .axis { font-size: 10px; fill: var(--faint); }
.history { display: flex; flex-direction: column; }
.history-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.history-row:last-child { border-bottom: 0; }
.history-row .h-date { width: 74px; flex: none; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.history-row .h-max { width: 64px; flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.history-row .h-sets { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.subhead { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin: 18px 2px 8px; font-weight: 600; }
.qr-text { font-size: 12px; color: var(--faint); word-break: break-all; margin-top: 4px; }

/* Toast */
.toast {
  position: fixed; z-index: 90; left: 50%; top: calc(12px + var(--safe-t));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 12px 16px; border-radius: 14px;
  background: var(--surface-3); color: var(--text);
  font-weight: 600; font-size: 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; gap: 10px;
  animation: toast-in 0.22s ease;
}
.toast.ok { background: var(--accent); color: var(--accent-ink); }
.toast.err { background: #3a1616; color: #ffb3b3; border: 1px solid rgba(255, 93, 93, 0.4); }
.toast button { font-weight: 700; text-decoration: underline; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }

.skeleton { height: 64px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 380px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .kv { grid-template-columns: repeat(2, 1fr); }
}
