:root {
  --bg: #f7f5f2;
  --card: #ffffff;
  --card-2: #fbfaf8;
  --text: #26262e;
  --muted: #6f6f7a;
  --line: #ece8e2;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 20px;

  --accent: #b06a8f;         /* rose calme */
  --accent-soft: #f4e8ee;

  --calm-bg: #e9f1ee;  --calm-fg: #2f6b57;
  --prog-bg: #fbf0dd;  --prog-fg: #9a6b12;
  --close-bg: #fbe4d4; --close-fg: #b1541c;
  --go-bg:   #f7dadd;  --go-fg:   #b0243a;

  --ok: #2f8f6b;
  --off: #c9c4bd;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --card: #1d1f27;
    --card-2: #23252e;
    --text: #ecedf2;
    --muted: #9a9ba6;
    --line: #2c2e38;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);

    --accent: #d98cb2;
    --accent-soft: #34222c;

    --calm-bg: #1c3129; --calm-fg: #7fd6b4;
    --prog-bg: #352c19; --prog-fg: #e6b866;
    --close-bg: #3a251a; --close-fg: #f0a071;
    --go-bg:   #3a1f25;  --go-fg:   #f28b9c;

    --ok: #5fc79c;
    --off: #4a4c56;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    0
    max(16px, env(safe-area-inset-left));
}
.wrap { max-width: 520px; margin: 0 auto; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

header { text-align: center; margin: 8px 0 18px; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -.01em; }
.tagline { color: var(--muted); font-size: .92rem; margin-top: 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

/* Vues */
.view { display: none; }
.view.active { display: block; }

/* Statut */
.status { text-align: center; transition: background .3s ease; }
.status.calm  { background: var(--calm-bg); border-color: transparent; }
.status.prog  { background: var(--prog-bg); border-color: transparent; }
.status.close { background: var(--close-bg); border-color: transparent; }
.status.go    { background: var(--go-bg); border-color: transparent; animation: pulseGo 1.6s ease-in-out infinite; }
@keyframes pulseGo {
  0%,100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--go-fg) 25%, transparent), var(--shadow); }
}
.status-emoji { font-size: 2rem; line-height: 1; }
.status-title { font-size: 1.18rem; font-weight: 650; margin: 8px 0 4px; }
.status.calm  .status-title { color: var(--calm-fg); }
.status.prog  .status-title { color: var(--prog-fg); }
.status.close .status-title { color: var(--close-fg); }
.status.go    .status-title { color: var(--go-fg); }
.status-msg { font-size: .95rem; color: var(--text); opacity: .9; }

/* Pastilles critères */
.criteria { display: flex; gap: 8px; margin-top: 14px; }
.crit {
  flex: 1; background: var(--card-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 6px; text-align: center;
}
.crit .dot {
  width: 22px; height: 22px; border-radius: 50%; margin: 0 auto 6px;
  display: grid; place-items: center; color: #fff; font-size: .8rem; font-weight: 700;
  background: var(--off); transition: background .3s ease;
}
.crit.on .dot { background: var(--ok); }
.crit .k { font-size: .95rem; font-weight: 650; }
.crit .lbl { font-size: .72rem; color: var(--muted); margin-top: 2px; }

/* Chrono */
.live { text-align: center; }
.live .live-lbl { color: var(--muted); font-size: .9rem; }
.live .live-val {
  font-variant-numeric: tabular-nums; font-weight: 700; letter-spacing: -.02em;
  font-size: 3.4rem; line-height: 1.05; margin-top: 2px;
}
.live.active .live-val { color: var(--go-fg); }
.live.active .live-lbl { color: var(--go-fg); font-weight: 600; }
.live.active { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 0%,100% { opacity: 1; } 50% { opacity: .72; } }

/* Bouton principal */
.btn {
  display: block; width: 100%; border: none; cursor: pointer;
  font-size: 1.2rem; font-weight: 700; color: #fff;
  padding: 20px; border-radius: 18px; margin-top: 14px;
  background: var(--accent); transition: transform .06s ease, filter .2s ease;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn:active { transform: scale(.98); }
.btn.stop { background: var(--go-fg); box-shadow: 0 6px 18px color-mix(in srgb, var(--go-fg) 35%, transparent); }

/* Stats */
.stats { display: flex; gap: 8px; }
.stat { flex: 1; text-align: center; }
.stat .v { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .74rem; color: var(--muted); margin-top: 2px; }
.stat + .stat { border-left: 1px solid var(--line); }

/* Historique */
.hist-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.hist-head h2 { font-size: 1rem; margin: 0; }
.hist-head .count { color: var(--muted); font-size: .85rem; }
.row {
  display: grid; grid-template-columns: auto 1fr 1fr auto; align-items: center;
  gap: 10px; padding: 11px 4px; border-top: 1px solid var(--line);
}
.row:first-child { border-top: none; }
.row .n { color: var(--muted); font-size: .8rem; width: 26px; }
.row .col .big { font-weight: 650; font-variant-numeric: tabular-nums; }
.row .col .small { font-size: .72rem; color: var(--muted); }
.row .del {
  background: none; border: none; color: var(--muted); font-size: 1.1rem;
  padding: 6px 8px; cursor: pointer; border-radius: 8px;
}
.row .del:active { background: var(--card-2); }
.empty { color: var(--muted); text-align: center; padding: 18px 0; font-size: .92rem; }

.actions { display: flex; gap: 10px; margin-top: 4px; }
.link-btn {
  flex: 1; background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px; font-size: .9rem; cursor: pointer; font-weight: 550;
}
.link-btn:active { transform: scale(.99); }
.link-btn.danger { color: var(--go-fg); }

/* Avertissement + info */
.warn {
  background: var(--go-bg); border: 1px solid transparent; border-radius: 16px;
  padding: 14px 16px; font-size: .9rem; color: var(--text);
}
.warn b { color: var(--go-fg); }
details.info { margin-top: 12px; }
details.info summary {
  cursor: pointer; color: var(--muted); font-size: .86rem; list-style: none;
  padding: 6px 2px; text-align: center;
}
details.info summary::-webkit-details-marker { display: none; }
details.info .body { font-size: .84rem; color: var(--muted); padding: 6px 4px 0; }
details.info .body p { margin: 8px 0; }

/* Courbes */
.range { display: flex; gap: 8px; margin-bottom: 14px; }
.range button {
  flex: 1; background: var(--card-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 10px; padding: 9px; font-size: .85rem; cursor: pointer; font-weight: 550;
}
.range button.active { background: var(--accent); color: #fff; border-color: transparent; }
.chart-title { font-size: .98rem; font-weight: 650; margin: 0 0 2px; }
.chart-sub { font-size: .78rem; color: var(--muted); margin: 0 0 10px; }
svg.chart { width: 100%; height: auto; display: block; }
svg text { fill: var(--muted); }
.grid-line { stroke: var(--line); stroke-width: 1; }
.target-line { stroke: var(--go-fg); stroke-width: 1.5; stroke-dasharray: 4 3; opacity: .75; }
.series-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.series-dot { fill: var(--accent); }
.bar { fill: var(--accent); }

/* Réglages */
.section-h { font-size: .98rem; font-weight: 650; margin: 0 0 8px; }
.hint { font-size: .82rem; color: var(--muted); margin: 0 0 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-2 {
  flex: 1 1 30%; min-width: 92px; padding: 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  font-weight: 600; font-size: .92rem; cursor: pointer;
}
.btn-2:active { transform: scale(.99); }
.btn-2.primary { background: var(--accent); color: #fff; border-color: transparent; }
textarea {
  width: 100%; min-height: 92px; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; font-family: inherit; font-size: .85rem; background: var(--card-2);
  color: var(--text); resize: vertical;
}
input[type=file] { font-size: .85rem; color: var(--muted); max-width: 100%; }

/* Barre d'onglets */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex;
  background: color-mix(in srgb, var(--card) 90%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 9px 4px 7px; font-size: .7rem; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabbar button .ic { font-size: 1.3rem; line-height: 1; }
.tabbar button.active { color: var(--accent); }

/* Toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(92px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px;
  font-size: .9rem; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .25s ease; z-index: 100; max-width: 88%; text-align: center;
}
#toast.show { opacity: .96; }
