:root {
  --bg:        #0f172a;
  --bg-card:   #1e293b;
  --bg-card-2: #273449;
  --line:      #334155;
  --text:      #e2e8f0;
  --muted:     #94a3b8;
  --primary:   #38bdf8;
  --primary-d: #0ea5e9;
  --danger:    #f87171;
  --ok:        #4ade80;
  --radius:    16px;
}

* { box-sizing: border-box; }

/* hidden muss IMMER ausblenden – sonst überschreiben Layout-Regeln (z. B. display:grid)
   das Attribut und Inhalte werden sichtbar, obwohl sie gesperrt sein sollten. */
[hidden] { display: none !important; }

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

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.2rem; margin: 0 0 1rem; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  border: none;
  border-radius: 12px;
  padding: 0.7rem 1.1rem;
  cursor: pointer;
  color: var(--text);
  background: var(--bg-card-2);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary-d); color: #04263a; font-weight: 700; }
.btn-ghost   { background: transparent; color: var(--muted); }
.btn-danger  { background: transparent; color: var(--danger); }
.btn-icon {
  width: 44px; height: 44px; padding: 0;
  font-size: 1.5rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}

.error { color: var(--danger); margin: 0.5rem 0 0; font-size: 0.9rem; }

/* ---------- PIN-Gate ---------- */
/* Vollbild-Overlay: deckt die App komplett ab, bis die PIN stimmt
   (kein Vorbeiscrollen möglich). */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow-y: auto;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.pin-card {
  width: 100%;
  max-width: 320px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
}
.pin-logo { font-size: 3rem; }
.pin-hint { color: var(--muted); margin: 0.25rem 0 1.25rem; }
.pin-input {
  width: 100%;
  font-size: 2rem;
  text-align: center;
  letter-spacing: 0.4em;
  padding: 0.6rem;
  margin-bottom: 1rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
}
.pin-card .btn-primary { width: 100%; }

/* ---------- App ---------- */
.app { max-width: 640px; margin: 0 auto; padding: 1rem 1rem 4rem; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 0;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar-actions { display: flex; gap: 0.4rem; align-items: center; }
.list-status { color: var(--muted); text-align: center; padding: 1rem; }

.machine-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.75rem; }

.machine {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.machine-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem;
}
.machine-name { font-weight: 600; font-size: 1.05rem; }
.machine-name button {
  all: unset; cursor: pointer; color: inherit; font: inherit; font-weight: 600;
}
.machine-sub { color: var(--muted); font-size: 0.85rem; }

.machine-controls {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-top: 0.75rem;
}
.stepper { display: flex; align-items: center; gap: 0.6rem; }
.step-btn {
  width: 52px; height: 52px; border-radius: 50%;
  font-size: 1.6rem; font-weight: 700;
  background: var(--bg-card-2); color: var(--text);
  border: 1px solid var(--line);
}
.step-btn.plus { color: var(--ok); }
.step-btn.minus { color: var(--danger); }
.total {
  min-width: 7.5rem; text-align: center;
}
.total-value { font-size: 1.9rem; font-weight: 800; line-height: 1; }
.total-unit { color: var(--muted); font-size: 0.9rem; }
.total-breakdown { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }

.machine.saving { opacity: 0.6; }
.machine .pending { color: var(--primary); }

/* Gesamtgewicht + getrennte Stepper (Grund / Zusatz) */
.machine-total { margin-top: 0.6rem; text-align: center; }
.machine-total .total-breakdown { display: block; margin-top: 0.1rem; }

.adjust { margin-top: 0.6rem; display: grid; gap: 0.5rem; }
.adjust-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.adjust-label { color: var(--muted); font-size: 0.92rem; }
.adjust-label small { display: block; font-size: 0.72rem; opacity: 0.8; }
.adjust-val {
  min-width: 3.5rem; text-align: center;
  font-size: 1.35rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Checkbox-Zeile im Dialog */
.check { display: flex; align-items: center; gap: 0.5rem; color: var(--text); margin-bottom: 0.9rem; }
.check input { width: auto; margin: 0; }

/* ---------- Muskeln / Körperkarte ---------- */
.machine-muscles {
  display: flex; align-items: center; gap: 0.85rem;
  margin-top: 0.85rem; padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.musclemap {
  all: unset; cursor: pointer; flex: none;
  display: inline-flex; border-radius: 10px;
}
.musclemap:active { transform: scale(0.97); }
.bodymap { height: 78px; width: auto; display: block; }
.muscle-big .bodymap { height: 220px; width: 100%; }

.muscle-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.muscle-chips.center { justify-content: center; margin-top: 0.75rem; }
.chip {
  background: var(--bg-card-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 999px;
  padding: 0.2rem 0.6rem; font-size: 0.78rem;
}
.muscle-none { color: var(--muted); font-size: 0.82rem; }
.muscle-body { text-align: center; }

/* Übungsbild (mit SVG-Diagramm als Fallback) */
.exercise-thumb {
  all: unset; cursor: pointer; flex: none;
  display: inline-flex; border-radius: 10px; overflow: hidden;
}
.exercise-thumb:active { transform: scale(0.97); }
.exercise-img {
  height: 80px; width: auto; max-width: 150px;
  object-fit: cover; border-radius: 8px; display: block; background: var(--bg);
}
.exercise-big { width: 100%; max-height: 52vh; object-fit: contain; border-radius: 10px; display: block; }
.image-credit { color: var(--muted); font-size: 0.75rem; text-align: center; margin-top: 0.6rem; }

.image-preview {
  display: flex; justify-content: center; align-items: center; min-height: 96px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.4rem; margin-bottom: 0.6rem;
}
.image-preview img { max-width: 100%; max-height: 180px; border-radius: 8px; display: block; }
.preview-fallback .bodymap { height: 92px; }
.image-actions { display: flex; gap: 0.5rem; align-items: center; }
.image-hint { color: var(--muted); font-size: 0.8rem; margin: 0.5rem 0 0; }

/* ---------- Muskel-Auswahl im Edit-Dialog ---------- */
.muscle-select { border: 1px solid var(--line); border-radius: 12px; padding: 0.6rem 0.75rem 0.85rem; margin: 0 0 0.9rem; }
.muscle-select legend { color: var(--muted); font-size: 0.85rem; padding: 0 0.35rem; }
.muscle-toggles { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.m-toggle {
  font: inherit; font-size: 0.8rem; cursor: pointer;
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 0.3rem 0.7rem;
}
.m-toggle.on { background: var(--primary-d); color: #04263a; border-color: var(--primary-d); font-weight: 600; }

/* ---------- Dialog ---------- */
.dialog {
  width: min(92vw, 420px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  padding: 1.5rem;
}
.dialog::backdrop { background: rgba(0,0,0,0.6); }
.dialog label { display: block; margin-bottom: 0.9rem; color: var(--muted); font-size: 0.9rem; }
.dialog input {
  display: block; width: 100%; margin-top: 0.3rem;
  font-size: 1.1rem; padding: 0.6rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
}
.dialog .row { display: flex; gap: 0.75rem; }
.dialog .row label { flex: 1; }
.dialog-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.dialog-actions .spacer { flex: 1; }

.history-body { max-height: 50vh; overflow: auto; }
.spark { width: 100%; height: 64px; display: block; margin-bottom: 0.75rem; }
.hist-row {
  display: flex; justify-content: space-between; gap: 0.5rem;
  padding: 0.5rem 0; border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.hist-row .date { color: var(--muted); font-size: 0.85rem; }
.hist-empty { color: var(--muted); padding: 1rem 0; }
