/*
 * Gemeinsames Design-System aller Seiten ("Blick durch den Spiegel").
 *
 * Wird NACH dem seiteneigenen <style> geladen: die Tokens hier gelten also
 * ueberall, auch fuer Regeln, die eine Seite selbst mitbringt. Die alten
 * Token-Namen (--orange, --green, ...) bleiben bewusst erhalten, damit die
 * vorhandenen Seiten-Styles ohne Umbau die neue Palette uebernehmen.
 *
 * Alle Textfarben erreichen auf ihrer Flaeche mindestens 4,5:1.
 */

/* ---------- Tokens: hell ---------- */
:root {
  --bg: #eceef2;
  --surface: #ffffff;
  --surface-alt: #f2f3f6;
  --surface-raised: #ffffff;
  --text: #0e1116;
  --text-muted: #5b6270;
  --border: rgba(14, 17, 22, .08);
  --hairline: rgba(14, 17, 22, .06);

  --sun: #a85f00;
  --air: #0874a8;
  --fil: #7e3ad1;
  --run: #0f7a53;
  --task: #2d55cf;
  --leaf: #4a7413;
  --danger: #c9332a;

  --tint: var(--task);
  --sheen: rgba(255, 255, 255, .9);
  --shadow-card: 0 1px 1px rgba(14, 17, 22, .04), 0 8px 28px -8px rgba(14, 17, 22, .12);
  --glass-fill: rgba(255, 255, 255, .72);
  --glass-edge: rgba(255, 255, 255, .9);

  --radius-s: 10px;
  --radius-m: 16px;
  --radius-l: 24px;

  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-num: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;

  --tabbar-h: 64px;
  --tabbar-space: calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));

  /* Himmelslicht "Tiefsee": Petrolblau und Cyan. */
  --sky-1: rgba(20, 120, 210, .25);
  --sky-2: rgba(0, 190, 210, .14);

  /* Alte Namen, auf die die Seiten-Styles zugreifen. */
  --accent: var(--tint);
  --accent-soft: color-mix(in srgb, var(--tint) 12%, transparent);
  --orange: var(--sun);
  --green: var(--run);
  --success: var(--run);
  --purple: var(--fil);
  --warning: var(--sun);
  --danger-soft: color-mix(in srgb, var(--danger) 12%, transparent);

  color-scheme: light dark;
}

/* ---------- Tokens: dunkel (der eigentliche Spiegel-Look) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #07080b;
    --surface: #111318;
    --surface-alt: #1a1d24;
    --surface-raised: #181b22;
    --text: #f3f4f7;
    --text-muted: #9aa1ad;
    --border: rgba(255, 255, 255, .07);
    --hairline: rgba(255, 255, 255, .06);

    --sun: #ffb547;
    --air: #5cc8ff;
    --fil: #c39bff;
    --run: #3ddc97;
    --task: #3f83ff; /* traegt weisse Schrift (3,6:1) und ist als Text lesbar (5,2:1) */
    --leaf: #9fd356;
    --danger: #ff6b61;

    --sheen: rgba(255, 255, 255, .045);
    --shadow-card: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 12px 32px -12px rgba(0, 0, 0, .6);
    --glass-fill: rgba(22, 24, 30, .62);
    --glass-edge: rgba(255, 255, 255, .1);

    --sky-1: rgba(20, 120, 210, .42);
    --sky-2: rgba(0, 190, 210, .24);
  }
}

@media (prefers-contrast: more) {
  :root {
    --border: rgba(14, 17, 22, .3);
    --text-muted: #3f4550;
  }
}

@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root {
    --border: rgba(255, 255, 255, .3);
    --text-muted: #c4c9d2;
  }
}

/* ---------- Grundlage ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding-bottom: var(--tabbar-space);
  /* Durchsichtig: die Grundfarbe traegt html. Haette body eine eigene
     Flaeche, laege sie ueber dem Himmelslicht (body::before, z-index -1). */
  background: transparent;
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Das Himmelslicht ("Tiefsee") hinter dem Spiegelglas: liegt fest hinter allem, die
   Karten sind blickdicht und lassen es nur in den Zwischenraeumen und oben
   durchscheinen - wie Licht hinter einem Spionspiegel. */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 90vh;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(85% 60% at 12% -8%, var(--sky-1), transparent 72%),
    radial-gradient(70% 55% at 98% 0%, var(--sky-2), transparent 72%);
}

.app {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: calc(22px + env(safe-area-inset-top)) 16px 24px;
}

@media (min-width: 720px) {
  .app { padding: calc(44px + env(safe-area-inset-top)) 24px 32px; }
}

h1 {
  margin: 0 0 22px;
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.035em;
}

@media (min-width: 720px) { h1 { font-size: 40px; } }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  background:
    linear-gradient(165deg, var(--sheen), transparent 38%),
    var(--surface);
  box-shadow: var(--shadow-card);
}

/* Bereichsfarbe der Seite (setzt app.js nach Pfad, Klima je nach Sensor). */
:root { --c: var(--tint); }
[data-area="sun"] { --c: var(--sun); }
[data-area="air"] { --c: var(--air); }
[data-area="fil"] { --c: var(--fil); }
[data-area="run"] { --c: var(--run); }
[data-area="task"] { --c: var(--task); }
[data-area="leaf"] { --c: var(--leaf); }

/* Hauptkarte einer Seite: leuchtet in der Bereichsfarbe wie die Kacheln der
   Startseite. isolation haelt das Licht zwischen Kartenflaeche und Inhalt. */
.card.glow {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.card.glow::before {
  content: "";
  position: absolute;
  inset: -45% -25% auto auto;
  z-index: -1;
  width: 85%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 24%, transparent), transparent);
  pointer-events: none;
  transition: background .4s ease;
}

/* Datumszeile ueber dem Seitentitel (fuegt app.js ein), wie auf der Startseite. */
.eyebrow {
  margin: 8px 0 4px;
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 500;
}

.eyebrow + h1, .eyebrow + div > h1 { margin-top: 0; }

/* Kopfzeile einer Karte: Symbol in Bereichsfarbe + Beschriftung, rechts
   optional eine Pille - wie die Kacheln der Startseite. */
.card-head {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.card-head svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: var(--c);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card-head .pill { margin-left: auto; }

/* Grosser Wert mit kleiner Einheit daneben. */
.big-value {
  font-family: var(--font-num);
  font-size: 48px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.035em;
  line-height: 1;
}

.big-value small {
  margin-left: 3px;
  color: var(--text-muted);
  font-size: .42em;
  font-weight: 600;
  letter-spacing: 0;
}

/* Status-Pille mit Punkt: ok / warn / bad. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--pc, var(--text)) 14%, transparent);
  color: var(--pc, var(--text));
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .01em;
  text-transform: none;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill.ok { --pc: var(--run); }
.pill.warn { --pc: var(--sun); }
.pill.bad { --pc: var(--danger); }

.section-label {
  margin: 30px 6px 10px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.hidden { display: none !important; }

/* Nur fuer Bildschirmleser sichtbar. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

:focus-visible {
  outline: 2px solid var(--tint);
  outline-offset: 2px;
}

::selection { background: color-mix(in srgb, var(--tint) 30%, transparent); }

/* ---------- Auftauchen beim Laden ----------
   Nur "backwards": nach der Animation bleibt keine Transformation stehen,
   sonst wuerden fest positionierte Elemente in den Karten mitwandern. */
@keyframes surface-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(.985);
  }
}

.rise {
  animation: surface-in .7s cubic-bezier(.2, .8, .2, 1) backwards;
  animation-delay: calc(var(--i, 0) * 55ms);
}

/* ---------- Schwebende Tab-Leiste (einzige Glasflaeche) ---------- */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  width: min(580px, calc(100% - 16px));
  height: var(--tabbar-h);
  padding: 6px;
  border: 1px solid var(--glass-edge);
  border-radius: 999px;
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  backdrop-filter: blur(24px) saturate(1.5);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .45);
  transform: translateX(-50%);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 40px;
  min-height: 44px;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .01em;
  text-decoration: none;
  transition: background .2s ease, color .2s ease;
}

.tab svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab[aria-current="page"] {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 10%, transparent);
}

.tab:active { transform: scale(.94); }

/* Unten fest positionierte Elemente der Seiten (Meldungen, Plus-Knopf)
   sitzen ueber der Tab-Leiste statt darunter. */
.toast { bottom: var(--tabbar-space) !important; z-index: 60 !important; }
.fab { bottom: var(--tabbar-space) !important; z-index: 45 !important; }

/* Ueberlauf-Verlauf, damit Inhalt unter der Leiste nicht hart anstoesst. */
body::after {
  content: "";
  position: fixed;
  inset: auto 0 0 0;
  height: calc(var(--tabbar-h) + 40px + env(safe-area-inset-bottom));
  z-index: 40;
  pointer-events: none;
  background: linear-gradient(to top, var(--bg) 35%, transparent);
}

@media (prefers-reduced-transparency: reduce) {
  .tabbar {
    background: var(--surface-raised);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .tabbar { background: var(--surface-raised); border-color: var(--text-muted); }
}

@media (prefers-reduced-motion: reduce) {
  .rise { animation: none; }
  .tab { transition: none; }
}

/* Gym-Training laeuft: Punkt am Reiter "Sport" */
.tab[data-live="1"] { position: relative; }
.tab[data-live="1"]::after {
  content: "";
  position: absolute;
  top: 6px;
  left: calc(50% + 6px);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--run);
  box-shadow: 0 0 0 2px var(--surface);
}

/* ---------- Maskottchen im Assistenten-Knopf ---------- */
.cm { overflow: visible; }
.cm-all { animation: cm-bob 3.2s ease-in-out infinite; }
.cm-eye { transform-box: fill-box; transform-origin: center; animation: cm-blink 4.6s infinite, cm-look 11s ease-in-out infinite; }
.cm-la, .cm-lb { transform-box: fill-box; transform-origin: top center; }
@keyframes cm-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
@keyframes cm-blink { 0%, 91%, 100% { transform: scaleY(1); } 94.5% { transform: scaleY(.08); } }
@keyframes cm-look { 0%, 62%, 100% { translate: 0 0; } 68%, 76% { translate: -13px 0; } 84%, 92% { translate: 13px 0; } }
@keyframes cm-stepa { 0%, 100% { transform: translateY(0) scaleY(1); } 50% { transform: translateY(-4px) scaleY(.45); } }
@keyframes cm-stepb { 0%, 100% { transform: translateY(-4px) scaleY(.45); } 50% { transform: translateY(0) scaleY(1); } }
.busy .cm-all { animation-duration: .5s; }
.busy .cm-la { animation: cm-stepa .32s linear infinite; }
.busy .cm-lb { animation: cm-stepb .32s linear infinite; }
.tc-fab:active .cm-all, .coach-fab:active .cm-all { animation-duration: .25s; }
@media (prefers-reduced-motion: reduce) { .cm-all, .cm-eye, .cm-la, .cm-lb { animation: none !important; } }
