/* FitDuo – Farben nach validierter Referenzpalette (hell + dunkel) */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --good: #006300;
  --bad: #d03b3b;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.12);
  --s1: #2a78d6; --s2: #1baf7a; --s3: #eda100; --s4: #008300;
  --s5: #4a3aa7; --s6: #e34948; --s7: #e87ba4; --s8: #eb6834;

  /* Spacing-Rhythmus (4/8-px-System) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  /* Radius-Skala */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-pill: 999px;
  /* Elevation-Skala */
  --shadow-1: 0 1px 2px rgba(11, 11, 11, 0.05), 0 1px 3px rgba(11, 11, 11, 0.04);
  --shadow-2: 0 4px 14px rgba(11, 11, 11, 0.10);
  /* Motion-Tokens */
  --dur: 180ms;
  --ease: cubic-bezier(0.2, 0, 0.1, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --good: #0ca30c;
    --bad: #d03b3b;
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --s1: #3987e5; --s2: #199e70; --s3: #c98500; --s4: #008300;
    --s5: #9085e9; --s6: #e66767; --s7: #d55181; --s8: #d95926;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 6px 20px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html { overflow-x: hidden; -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}
.wrap { max-width: 980px; margin: 0 auto; padding: var(--sp-4); }
img, svg, table { max-width: 100%; }

header.top {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0 var(--sp-1);
}
header.top h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; flex: none; }
header.top .spacer { flex: 1; min-width: 0; }
.userchip { display: flex; align-items: center; gap: var(--sp-2); color: var(--ink-2); font-size: 14px; min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  margin: var(--sp-3) 0;
  box-shadow: var(--shadow-1);
}
.card h2 { font-size: 15px; margin: 0 0 var(--sp-3); color: var(--ink-2); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-3); margin: var(--sp-3) 0; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
@media (hover: hover) {
  .tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
}
.tile .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tile .value { font-size: 26px; font-weight: 650; margin-top: var(--sp-1); line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12.5px; color: var(--ink-2); margin-top: var(--sp-1); }
.delta-good { color: var(--good); font-weight: 600; }
.delta-bad { color: var(--bad); font-weight: 600; }
.progress { height: 8px; background: var(--grid); border-radius: var(--r-pill); overflow: hidden; margin-top: var(--sp-2); }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: var(--r-pill); transition: width 0.5s var(--ease); }
.progress > span.full { background: var(--good); }

form.inline { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: flex-end; }
label.field { display: flex; flex-direction: column; gap: var(--sp-1); font-size: 12px; color: var(--muted); }
input, select, button, textarea {
  font: inherit; font-size: 16px; /* >=16px verhindert Auto-Zoom beim Fokus auf iOS */
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--baseline); border-radius: var(--r-sm);
  padding: 7px 10px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
/* Native Date-Controls (v. a. iOS Safari) erzwingen sonst eine intrinsische Eigenbreite
   und ragen über den Container – Appearance aus, dann greifen width/max-width normal. */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  max-width: 100%;
  min-height: 38px; /* iOS kollabiert die Höhe ohne natives Appearance */
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
button {
  cursor: pointer; background: var(--accent); color: #fff; border: none; font-weight: 600;
  transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
button:hover { filter: brightness(1.08); }
button:active { transform: scale(0.97); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus-visible { outline-offset: 3px; }
button.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--baseline); font-weight: 500; }
button.ghost:hover { background: var(--surface-2); filter: none; }
button.small { padding: 4px 9px; font-size: 13px; border-radius: 7px; }
button.danger-ghost { background: transparent; color: var(--bad); border: none; padding: 2px 6px; }
button.danger-ghost:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); filter: none; }

.seg { display: inline-flex; border: 1px solid var(--baseline); border-radius: var(--r-sm); overflow: hidden; max-width: 100%; }
/* min-width:0 + Ellipse: ein langer Anzeigename darf die Gruppe nicht über den
   Kartenrand schieben, sondern kürzt sich auf dem Handy selbst. */
.seg button {
  background: transparent; color: var(--ink-2); border: none; border-radius: 0;
  padding: 5px 11px; font-size: 13px; font-weight: 500;
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seg button:hover { background: var(--surface-2); filter: none; }
.seg button.active { background: var(--accent); color: #fff; font-weight: 600; }
.seg button.active:hover { background: var(--accent); }

.chartbox { position: relative; }
.chartbox svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  padding: 7px 10px; font-size: 12.5px; display: none; min-width: 110px; max-width: 60vw;
}
.tooltip .t-date { color: var(--muted); font-size: 11.5px; margin-bottom: 3px; }
.tooltip .t-row { display: flex; align-items: center; gap: var(--sp-1); }
.tooltip .t-val { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
/* Die Einzel-Sportarten hinter einer Oberkategorie – im Tooltip wie in der Tabelle */
.t-parts { color: var(--muted); font-size: 11.5px; line-height: 1.35; margin-top: 4px; }
.tooltip .t-parts { border-top: 1px solid var(--grid); padding-top: 4px; }

.legend { display: flex; gap: var(--sp-4); flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: var(--sp-2); }
.legend .item { display: flex; align-items: center; gap: 6px; }

/* Kopfzeile einer Karte: Titel links, Filter rechts – bricht auf schmalen Screens um */
.card-head { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.card-head h2 { margin: 0; flex: 1 1 auto; min-width: 120px; }

/* Workout-Wolke */
.cloudbox svg { touch-action: manipulation; }
.cloud-bubble { cursor: pointer; }
.cloud-bubble circle.body {
  transition: filter var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.cloud-bubble:hover circle.body,
.cloud-bubble:focus-visible circle.body { filter: brightness(1.12) saturate(1.1); }
.cloud-bubble:focus { outline: none; }
.cloud-bubble:focus-visible circle.hit { stroke: var(--accent); stroke-width: 2; }
.cloudbox.dim .cloud-bubble:not(.on) { opacity: 0.28; }
@media (prefers-reduced-motion: no-preference) {
  /* fill-box + center: sonst skaliert SVG um den Ursprung 0,0 statt um die Blasenmitte */
  .cloud-bubble { animation: bubble-in 320ms var(--ease) backwards; transform-box: fill-box; transform-origin: center; }
}
@keyframes bubble-in {
  from { opacity: 0; transform: scale(0.82); }
  to { opacity: 1; transform: scale(1); }
}

/* Beschriftung für schmale Screens: am Kranz wäre für Namen kein Platz, ohne sie
   auf Stummel zu kürzen – hier stehen sie vollständig unter der Wolke. */
.cloud-keys { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--sp-3); }
.cloud-keys:empty { display: none; }
.cloud-keys .key {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--border); border-radius: var(--r-pill);
  padding: 3px 10px 3px 7px; font-size: 12.5px; color: var(--ink-2); background: var(--surface-2);
}
.cloud-keys .key .dot { width: 7px; height: 7px; }
.cloud-keys .key b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Karte, die sich über ihre Überschrift auf-/zuklappt */
details.foldcard > summary {
  cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: var(--sp-2);
  border-radius: var(--r-sm);
}
details.foldcard > summary::-webkit-details-marker { display: none; }
details.foldcard > summary h2 { margin: 0; }
details.foldcard > summary::after {
  content: "⌄"; margin-left: auto; color: var(--muted); font-size: 15px;
  line-height: 1; align-self: flex-start; padding-top: 2px;
  display: inline-block; transition: transform var(--dur) var(--ease);
}
details.foldcard[open] > summary::after { transform: rotate(180deg); padding: 0 0 2px; }
details.foldcard[open] > summary { margin-bottom: var(--sp-3); }
@media (hover: hover) {
  details.foldcard > summary:hover h2 { color: var(--ink); }
}

/* Tabellen-Zwilling: jeder Wert bleibt ohne Hover erreichbar */
details.tableview { margin-top: var(--sp-3); }
details.tableview summary {
  cursor: pointer; font-size: 12.5px; color: var(--muted); font-weight: 600;
  list-style: none; display: inline-flex; align-items: center; gap: 6px; padding: 4px 0;
}
details.tableview summary::-webkit-details-marker { display: none; }
details.tableview summary::before { content: "▸"; font-size: 11px; transition: transform var(--dur) var(--ease); }
details.tableview[open] summary::before { transform: rotate(90deg); }
details.tableview .tablewrap { overflow-x: auto; margin-top: var(--sp-2); }

table.log { width: 100%; border-collapse: collapse; font-size: 14px; }
table.log td, table.log th { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--grid); }
table.log th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
table.log tr:last-child td { border-bottom: none; }
table.log .num { text-align: right; font-variant-numeric: tabular-nums; }

.badges { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--baseline); border-radius: var(--r-pill);
  padding: 5px 12px; font-size: 13px; color: var(--ink-2);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.badge.earned { border-color: var(--accent); color: var(--ink); background: var(--accent-soft); }
.badge .b-emoji { font-size: 15px; }

.duel { display: grid; grid-template-columns: 1fr auto 1fr; gap: var(--sp-3); align-items: center; text-align: center; }
.duel .side .name { font-weight: 650; font-size: 15px; }
.duel .side .score { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.duel .side .mins { font-size: 12.5px; color: var(--muted); }
.duel .vs { color: var(--muted); font-size: 13px; }
.duel .crown { font-size: 20px; line-height: 1; }

.auth-card { max-width: 380px; margin: 8vh auto; }
.auth-card form { display: flex; flex-direction: column; gap: var(--sp-3); }
.auth-card .tabs { display: flex; gap: 0; margin-bottom: var(--sp-4); border-bottom: 1px solid var(--grid); }
.auth-card .tabs button { background: none; color: var(--muted); border: none; border-radius: 0; padding: 8px 14px; font-weight: 600; border-bottom: 2px solid transparent; transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.auth-card .tabs button:hover { filter: none; color: var(--ink-2); }
.auth-card .tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.error { color: var(--bad); font-size: 13.5px; min-height: 18px; }

dialog {
  border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); color: var(--ink);
  max-width: 440px; width: calc(100vw - 40px); padding: var(--sp-5);
  box-shadow: var(--shadow-2);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 var(--sp-3); font-size: 17px; }
dialog form.settings { display: flex; flex-direction: column; gap: var(--sp-3); }
.tokenbox { display: flex; gap: 6px; align-items: center; }
.tokenbox code {
  flex: 1; font-size: 11.5px; background: var(--page); border: 1px solid var(--grid);
  border-radius: 6px; padding: 6px 8px; overflow-wrap: anywhere;
}
details.help { font-size: 13.5px; color: var(--ink-2); margin-top: 6px; }
details.help summary { cursor: pointer; font-weight: 600; }
details.help ol { padding-left: 18px; margin: 8px 0; }
.mut { color: var(--muted); font-size: 12.5px; }
.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--page); padding: 9px 16px; border-radius: var(--r-md);
  font-size: 14px; opacity: 0; transition: opacity 0.25s var(--ease), transform 0.25s var(--ease); pointer-events: none; z-index: 50;
  box-shadow: var(--shadow-2); max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  /* Kopfzeile: alles dezent in einer Zeile, läuft nie über den Rand */
  header.top { gap: var(--sp-2); }
  header.top h1 { font-size: 19px; white-space: nowrap; }
  .hide-sm { display: none; }
  .userchip { font-size: 13px; gap: 5px; min-width: 0; flex: 1 1 auto; }
  .userchip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  header.top .spacer { display: none; }
  header.top button.small { flex: none; padding: 6px 9px; font-size: 13px; border: none; background: transparent; color: var(--ink-2); }
  .wrap { padding: var(--sp-3); }
  .card { padding: var(--sp-3); }
  /* Formulare: Felder füllen die Breite, Button volle Zeile */
  form.inline label.field { flex: 1 1 40%; min-width: 0; }
  form.inline label.field input { width: 100% !important; }
  /* Gewicht-Formular: Datum kompakt (feste Breite → normale Höhe, kein iOS-Größenwuchs) */
  #form-weight label.field:has(input[type="date"]) { flex: 0 1 auto; }
  #form-weight input[type="date"] { width: 150px !important; }
  /* Sport-Formular: Datum über die gesamte Breite, aber nie über den Containerrand */
  #form-workout label.field:has(input[type="date"]) { flex: 1 1 100%; min-width: 0; }
  #form-workout input[type="date"] { width: 100% !important; max-width: 100%; min-width: 0; box-sizing: border-box; }
  form.inline > button { flex: 1 1 100%; padding: 11px; }
  /* Beschriftungs-Chips: auf schmalen Screens sind es viele – kompakter setzen,
     damit die Liste unter der Wolke nicht die halbe Karte einnimmt. */
  .cloud-keys { gap: 5px; margin-top: var(--sp-2); }
  .cloud-keys .key { font-size: 12px; padding: 2px 8px 2px 6px; }
  .card-head { gap: 6px; }
  .card-head h2 { flex: 1 1 100%; }
  .tiles { grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
  .tile { padding: var(--sp-3); }
  .tile .value { font-size: 22px; }
  .duel .side .score { font-size: 25px; }
  dialog { padding: var(--sp-4); }
  .tokenbox { flex-wrap: wrap; }
}

/* Touch-Geräte: größere Tippflächen */
@media (pointer: coarse) {
  button { padding: 10px 14px; }
  button.small { padding: 8px 12px; }
  table.log td { padding: 10px 8px; }
  .seg button { padding: 9px 13px; }
  button.danger-ghost { padding: 8px 12px; }
}

/* Bewegung reduzieren, wenn vom System gewünscht */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
