:root {
  /* Palette claire (par défaut) */
  --sage: #5b7d63;
  --sage-dark: #3f5c46;
  --terracotta: #c1613f;
  --terracotta-dark: #9c4c30;
  --cream: #faf6ef;
  --paper: #ffffff;
  --ink: #23241f;
  --ink-soft: #52544a;
  --line: #d8d2c4;
  --danger-bg: #fbe9e4;
  --danger-ink: #7a2e15;
  --font-scale: 1.25;
  --radius: 14px;
}

/* Palette sombre : suit le système, sauf si l'utilisateur force le mode clair
   (data-theme="light") depuis les réglages. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* --sage et --terracotta servent de fond à du texte blanc (boutons,
       badges) : on les garde proches du clair pour ne pas perdre le
       contraste. --sage-dark / --terracotta-dark servent de texte sur fond
       sombre : on les éclaircit pour rester lisibles. */
    --sage: #4d6c55;
    --sage-dark: #8fb798;
    --terracotta: #c1613f;
    --terracotta-dark: #e6a37e;
    --cream: #1b1d18;
    --paper: #262922;
    --ink: #f3f1e9;
    --ink-soft: #c3c1b4;
    --line: #454838;
    --danger-bg: #3a231c;
    --danger-ink: #f2b8a4;
  }
}

/* Mode sombre forcé depuis les réglages, quel que soit le système. */
:root[data-theme="dark"] {
  --sage: #4d6c55;
  --sage-dark: #8fb798;
  --terracotta: #c1613f;
  --terracotta-dark: #e6a37e;
  --cream: #1b1d18;
  --paper: #262922;
  --ink: #f3f1e9;
  --ink-soft: #c3c1b4;
  --line: #454838;
  --danger-bg: #3a231c;
  --danger-ink: #f2b8a4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: calc(17px * var(--font-scale));
  line-height: 1.5;
}

body.high-contrast {
  --ink: #111111;
  --ink-soft: #2b2b2b;
  --line: #8a8a8a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body.high-contrast {
    --ink: #ffffff;
    --ink-soft: #e9e7db;
    --line: #7c7f6d;
  }
}
:root[data-theme="dark"] body.high-contrast {
  --ink: #ffffff;
  --ink-soft: #e9e7db;
  --line: #7c7f6d;
}

h1, h2, h3 { color: var(--sage-dark); line-height: 1.25; }
h1 { font-size: 1.5em; }
h2 { font-size: 1.3em; margin-top: 0; }
h3 { font-size: 1.1em; }

.hidden { display: none !important; }

.app { max-width: 640px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Landing ---------- */
.landing {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.landing-card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.08);
}
.landing-emblem { font-size: 3em; color: var(--sage); margin-bottom: 8px; }
.landing-text { color: var(--ink-soft); }
.landing-text--small { font-size: 0.85em; }
.landing-recover { margin-top: 20px; }
.recover-message { color: var(--sage-dark); font-weight: 600; }
.privacy-note { color: var(--ink-soft); font-size: 0.8em; margin-top: 6px; }

/* ---------- Boutons ---------- */
.btn {
  font-size: 1em;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  cursor: pointer;
  min-height: 44px;
}
.btn-primary { background: var(--sage); color: white; }
.btn-primary:hover { background: var(--sage-dark); }
.btn-secondary { background: var(--paper); color: var(--sage-dark); border: 2px solid var(--sage); }
.btn-secondary.selected { background: var(--sage); color: white; }
.btn-big { width: 100%; font-size: 1.15em; padding: 16px; margin-top: 8px; }
.btn-small { padding: 8px 12px; font-size: 0.9em; }
.link-button { background: none; border: none; color: var(--sage-dark); text-decoration: underline; cursor: pointer; font-size: 0.95em; }
#onboarding-name .settings-sheet { text-align: center; }
#onboarding-name .field { text-align: left; }
#onboarding-name .link-button { display: block; margin: 12px auto 0; }
.icon-button { background: none; border: none; font-size: 1.3em; cursor: pointer; padding: 6px 10px; color: var(--ink); min-width: 44px; min-height: 44px; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Topbar / nav ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--sage);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title { font-weight: 700; font-size: 1.05em; }
.topbar .icon-button { color: white; }

.safety-banner {
  background: var(--danger-bg);
  color: var(--danger-ink);
  padding: 14px 16px;
  border-bottom: 2px solid var(--terracotta);
}
.safety-banner p { margin: 0 0 10px; }

#screens { flex: 1; padding: 18px 16px 90px; }
.screen h2 { margin-bottom: 4px; }
.hint { color: var(--ink-soft); font-size: 0.9em; }
.daily-quote { color: var(--sage-dark); font-style: italic; font-size: 0.95em; margin: -4px 0 16px; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  background: var(--paper);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 2px 10px;
  font-size: 1.3em;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.nav-btn span { font-size: 0.32em; font-weight: 600; letter-spacing: 0.02em; }
.nav-btn.active { color: var(--sage-dark); }

/* ---------- Semaine / jours ---------- */
.week-picker { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 8px 0 16px; font-weight: 700; font-size: 1.1em; }
.days-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 10px; }
.day-cell {
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}
.day-cell.done { background: var(--sage); border-color: var(--sage-dark); color: white; }
.day-cell .day-label { display: block; font-weight: 700; margin-bottom: 6px; }
.day-cell .day-mark { font-size: 1.4em; }

/* ---------- Formulaires ---------- */
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; }
.field em { font-weight: 400; color: var(--ink-soft); font-style: normal; font-size: 0.85em; }
input[type=text], input[type=email], input[type=number], input[type=time], select, textarea {
  width: 100%;
  font-size: 1em;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
}
input[type=range] { width: 100%; accent-color: var(--sage); }
output { font-weight: 700; color: var(--sage-dark); margin-left: 8px; }
.field-label { font-weight: 600; margin: 16px 0 8px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-weight: 600; }
.checkbox-row input { width: 22px; height: 22px; }
.saved-message { color: var(--sage-dark); font-weight: 700; min-height: 1.4em; }

.entry-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.entry-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.entry-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.entry-item .entry-date { display: block; font-size: 0.8em; color: var(--ink-soft); margin-bottom: 4px; }
.entry-item .entry-delete { float: right; background: none; border: none; color: var(--terracotta-dark); cursor: pointer; font-size: 0.9em; }

/* ---------- Progression ---------- */
.paliers { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 24px; }
.palier {
  min-width: 64px;
  text-align: center;
  padding: 10px 6px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--paper);
  font-weight: 700;
}
.palier.done { background: var(--terracotta); border-color: var(--terracotta-dark); color: white; }
.weight-chart { background: var(--paper); border-radius: var(--radius); padding: 12px; }
.weight-chart svg { width: 100%; height: auto; display: block; }

/* ---------- Export ---------- */
.export-content { margin-top: 18px; }
.export-content table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.export-content th, .export-content td { border: 1px solid var(--line); padding: 6px 8px; font-size: 0.85em; text-align: left; }
.export-note { margin-bottom: 8px; }

@media print {
  .topbar, .bottom-nav, #btn-export, .safety-banner { display: none !important; }
  #screens { padding-bottom: 0; }
  body { background: white; }
  .screen.hidden { display: none !important; }
  #screen-export { display: block !important; }
}

/* ---------- Settings sheet ---------- */
.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 20;
  display: flex;
  align-items: flex-end;
}
.settings-sheet {
  background: var(--cream);
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px 20px 32px;
}
.settings-header { display: flex; justify-content: space-between; align-items: center; }
.settings-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.settings-section--first { margin-top: 18px; padding-top: 0; border-top: none; }
