/* Tacheblette — mid-century modern : aplats géométriques, arêtes franches,
   navy + rouille sur papier. Aucun dégradé, aucune ombre portée : la lisibilité
   depuis l'autre bout de la cuisine vient du contraste plein/vide, pas de la
   profondeur.

   Les polices sont servies depuis ce dépôt et non depuis fonts.googleapis.com :
   la tablette du frigo doit démarrer même sans réseau. */

@font-face {
  font-family: 'Jost';
  font-style: normal;
  font-weight: 100 900;          /* fichier variable : un seul woff2 pour tous les gras */
  font-display: swap;
  src: url('../fonts/jost-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Jost';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/jost-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
                 U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
                 U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Bodoni Moda';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/bodoni-moda-700-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Bodoni Moda';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/bodoni-moda-700-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
                 U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
                 U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* --------------------------------------------------------------- palette */

:root {
  /* Teintes du set d'affiches : elles ne changent pas d'un fond à l'autre. */
  --ink: #1d2f5d;
  --rust: #b06425;
  --brick: #8f2d1e;
  --cream: #f2ead8;

  /* Rôles, redéfinis par html[data-bg]. */
  --page: #f2ead8;
  --surface: #fffdf6;
  --text: var(--ink);
  --line: var(--ink);
  --muted: #5d6b8d;
  --track: rgba(29, 47, 93, 0.16);
  --on-fill: #f7f2e6;

  --sans: 'Jost', Futura, 'Century Gothic', system-ui, -apple-system, sans-serif;
  --serif: 'Bodoni Moda', 'Didot', 'Times New Roman', serif;

  --bw: 2px;                     /* épaisseur de trait unique dans toute l'app */
  --gap: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

html[data-bg="white"] {
  --page: #ffffff;
  --surface: #f7f1e3;
}

html[data-bg="night"] {
  --page: #16233f;
  --surface: #1e2f52;
  --text: var(--cream);
  --line: #43598a;
  --muted: #9aabcc;
  --track: rgba(242, 234, 216, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--text);
  font: 400 16px/1.45 var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

/* Libellé secondaire mid-century : capitales, très espacées, jamais en gras. */
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 500;
}

/* ------------------------------------------------------------- appairage */

.pairing {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: calc(24px + var(--safe-t)) 20px calc(24px + var(--safe-b));
}

.pairing-box { width: min(460px, 100%); text-align: center; }
.pairing-mark { display: block; width: 128px; height: 79px; margin: 0 auto 20px; }
.pairing-box h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}
.lede { color: var(--muted); margin: 0 0 28px; }
.pairing-help { color: var(--muted); font-size: 0.95rem; text-align: left; margin: 0 0 20px; }
.pairing-sep {
  position: relative; margin: 26px 0; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.18em; font-size: 0.72rem;
}
.pairing-sep::before {
  content: ""; position: absolute; inset: 50% 0 auto; height: var(--bw); background: var(--line);
}
.pairing-sep span { position: relative; background: var(--page); padding: 0 14px; }
.pairing-join { display: grid; gap: 10px; text-align: left; }
.pairing-join label { color: var(--muted); font-size: 0.9rem; }
.pairing-join input {
  padding: 14px; border: var(--bw) solid var(--line);
  background: var(--surface); width: 100%;
}

/* ---------------------------------------------------------------- barre */

.app {
  min-height: 100dvh;
  padding: 0 calc(16px + var(--safe-r)) calc(104px + var(--safe-b)) calc(16px + var(--safe-l));
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: calc(14px + var(--safe-t)) 0 12px;
  margin-bottom: 18px;
  background: var(--page);
  border-bottom: 4px solid var(--line);
}

.brand {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  margin: 0;
  letter-spacing: -0.01em;
}
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.nav-btn {
  padding: 11px 15px;
  border: var(--bw) solid var(--line);
  background: transparent;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
}
.nav-btn.is-active { background: var(--ink); border-color: var(--ink); color: var(--cream); }
html[data-bg="night"] .nav-btn.is-active { background: var(--cream); border-color: var(--cream); color: var(--ink); }

.banner {
  margin: 0 0 14px; padding: 12px 14px;
  font-size: 0.88rem;
  background: var(--surface);
  border: var(--bw) solid var(--rust);
  border-left-width: 8px;
  color: var(--text);
}
.banner[data-kind="error"] { border-color: var(--brick); }

/* --------------------------------------------------------------- cartes */

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
  gap: var(--gap);
}

.board-empty { display: none; color: var(--muted); text-align: center; padding: 48px 16px; }
.board.is-empty + .board-empty { display: block; }

.card {
  position: relative;
  display: flex; flex-direction: column; gap: 8px;
  padding: 18px;
  min-height: 168px;
  background: var(--surface);
  border: var(--bw) solid var(--line);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.card:active { transform: translateY(2px); }

.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-shape { flex: none; color: var(--rust); }
.card-shape svg { display: block; width: 30px; height: 30px; fill: currentColor; }
.card-name {
  font-size: clamp(1.05rem, 1.7vw, 1.3rem);
  font-weight: 500; line-height: 1.2;
  letter-spacing: -0.005em;
}

.card-status {
  margin-top: auto; padding-top: 12px;
  font-size: clamp(1.5rem, 3vw, 2.1rem); font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
}
.card-freq {
  color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.13em;
  font-size: 0.7rem; font-weight: 500;
}

.card-bar { margin-top: 4px; height: 6px; background: var(--track); }
.card-bar i { display: block; height: 100%; background: currentColor; transition: width 400ms ease; }

/* Le décompte reste en pleine encre : la hiérarchie vient du remplissage de la
   carte, pas d'un gris qui affadirait le seul chiffre qu'on lit de loin. */
.card.is-cooling .card-status { color: var(--text); }

/* Aplat plein pour tout ce qui réclame une action : c'est le contraste de
   surface, pas la nuance de bordure, qui se lit à cinq mètres. */
.card.is-due,
.card.is-late {
  color: var(--on-fill);
  --muted: rgba(247, 242, 230, 0.72);
  --track: rgba(247, 242, 230, 0.28);
}
.card.is-due { background: var(--rust); border-color: var(--rust); }
.card.is-late { background: var(--brick); border-color: var(--brick); }
.card.is-due .card-shape,
.card.is-late .card-shape { color: inherit; }
.card.is-late .card-status { font-size: clamp(1.05rem, 2vw, 1.4rem); line-height: 1.15; }

/* Outils réservés au mode modification : au frigo, un appui accidentel ne doit
   jamais pouvoir renommer ou supprimer une tâche. */
.card-tools { display: none; gap: 6px; margin-top: 12px; }
.edit-mode .card-tools { display: flex; }
.edit-mode .card { border-style: dashed; }

.tool {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 0;
  border: var(--bw) solid currentColor;
  background: transparent;
  color: inherit;
  text-transform: uppercase; letter-spacing: 0.1em;
  font-size: 0.68rem; font-weight: 500;
  cursor: pointer;
}
.tool svg { display: block; width: 12px; height: 12px; fill: currentColor; }
.tool:disabled { opacity: 0.28; cursor: default; }
.tool-edit { flex: 1.6; }

.fab {
  position: fixed; z-index: 6;
  left: 50%; transform: translateX(-50%);
  bottom: calc(22px + var(--safe-b));
  padding: 17px 30px;
  border: var(--bw) solid var(--rust);
  background: var(--rust); color: var(--cream);
  text-transform: uppercase; letter-spacing: 0.14em;
  font-weight: 600; font-size: 0.82rem;
  cursor: pointer;
}

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed; z-index: 20;
  left: 50%; transform: translate(-50%, 16px);
  bottom: calc(22px + var(--safe-b));
  display: flex; align-items: center; gap: 16px;
  padding: 10px 10px 10px 18px;
  background: var(--ink); color: var(--cream);
  border: var(--bw) solid var(--ink);
  opacity: 0; transition: opacity 180ms ease, transform 180ms ease;
  max-width: calc(100vw - 32px);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-undo {
  border: var(--bw) solid var(--cream); background: transparent; color: var(--cream);
  padding: 9px 18px;
  text-transform: uppercase; letter-spacing: 0.12em;
  font-size: 0.72rem; font-weight: 600; cursor: pointer;
}

/* --------------------------------------------------------------- boutons */

.btn {
  padding: 13px 20px; cursor: pointer;
  border: var(--bw) solid var(--line);
  background: transparent; color: var(--text);
  text-transform: uppercase; letter-spacing: 0.12em;
  font-size: 0.76rem; font-weight: 500;
}
.btn-lg { padding: 17px 22px; font-size: 0.86rem; width: 100%; }
.btn-sm { padding: 9px 14px; font-size: 0.68rem; }
.btn-primary { background: var(--rust); border-color: var(--rust); color: var(--cream); font-weight: 600; }
.btn-danger { background: transparent; border-color: var(--brick); color: var(--brick); }
html[data-bg="night"] .btn-danger { color: #e2735c; border-color: #e2735c; }

.chip {
  padding: 9px 14px; cursor: pointer;
  border: var(--bw) solid var(--line);
  background: transparent; color: var(--text);
  text-transform: uppercase; letter-spacing: 0.1em;
  font-size: 0.7rem; font-weight: 500;
}
.chip.is-active { background: var(--ink); border-color: var(--ink); color: var(--cream); }
html[data-bg="night"] .chip.is-active { background: var(--cream); border-color: var(--cream); color: var(--ink); }

/* -------------------------------------------------------------- feuilles */

.sheet {
  border: none; padding: 0; background: transparent;
  width: min(560px, calc(100vw - 24px));
  max-height: 88dvh; color: var(--text);
}
.sheet::backdrop { background: rgba(29, 47, 93, 0.55); }

.sheet-form {
  display: grid; gap: 20px;
  padding: 24px;
  background: var(--page);
  border: 4px solid var(--line);
  max-height: 88dvh; overflow: auto;
}
.sheet-title {
  font-family: var(--serif); font-weight: 700;
  margin: 0; font-size: 1.6rem;
}

.field { display: grid; gap: 8px; border: none; padding: 0; margin: 0; }
.field > span, .field legend {
  color: var(--muted); padding: 0;
  text-transform: uppercase; letter-spacing: 0.13em;
  font-size: 0.7rem; font-weight: 500;
}
.field input, .field select, .duration input, .duration select {
  padding: 13px; border: var(--bw) solid var(--line);
  background: var(--surface); width: 100%;
}

.duration { display: flex; gap: 10px; align-items: center; }
.duration input { flex: 1; }
.duration select { flex: 1; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Sélecteur de forme : remplace l'ancien champ emoji. */
.shape-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.shape-btn {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: var(--bw) solid var(--line);
  background: transparent; color: var(--rust);
  cursor: pointer;
}
.shape-btn svg { display: block; width: 24px; height: 24px; fill: currentColor; }
.shape-btn.is-active { background: var(--ink); border-color: var(--ink); color: var(--cream); }
html[data-bg="night"] .shape-btn.is-active { background: var(--cream); border-color: var(--cream); color: var(--ink); }

.sheet-error {
  margin: 0; padding: 12px 14px;
  background: var(--surface);
  border: var(--bw) solid var(--brick); border-left-width: 8px;
  color: var(--text); font-size: 0.88rem;
}

.sheet-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.settings-block { display: grid; gap: 12px; padding-top: 16px; border-top: var(--bw) solid var(--line); }
.settings-block h3 {
  margin: 0; font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.16em; font-weight: 600;
}
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }
.code-row { display: flex; gap: 10px; align-items: center; }
.code-row code {
  flex: 1; padding: 12px 13px; background: var(--surface);
  border: var(--bw) solid var(--line); font-size: 0.82rem; overflow-wrap: anywhere;
}
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--rust); }
.night-range label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.9rem; }
.night-range input { width: 76px; }
.slider-row { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.9rem; }
.slider-row input { flex: 1; accent-color: var(--rust); }

/* Groupes de choix des réglages d'apparence : des pastilles, pas des radios
   système — la cible doit rester atteignable au doigt sur la tablette. */
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 11px 15px; cursor: pointer;
  border: var(--bw) solid var(--line);
  text-transform: uppercase; letter-spacing: 0.1em;
  font-size: 0.7rem; font-weight: 500;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
/* `.is-active` est posée en JS : `:has()` seul exclurait les navigateurs
   antérieurs à 2022, et la tablette du frigo n'est pas forcément à jour. */
.choice.is-active,
.choice:has(input:checked) { background: var(--ink); border-color: var(--ink); color: var(--cream); }
html[data-bg="night"] .choice.is-active,
html[data-bg="night"] .choice:has(input:checked) { background: var(--cream); border-color: var(--cream); color: var(--ink); }
.choice-swatch { width: 16px; height: 16px; border: 1px solid var(--line); flex: none; }
.choice.is-active .choice-swatch,
.choice:has(input:checked) .choice-swatch { border-color: currentColor; }

/* ------------------------------------------------------------ historique */

.history-list { display: grid; gap: 0; }
.history-day {
  margin: 20px 0 6px; font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.16em; color: var(--rust); font-weight: 600;
}
.history-day:first-child { margin-top: 0; }
.history-row {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.history-when { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.empty { color: var(--muted); }

/* ------------------------------------------------------------ mode nuit */

.veil {
  position: fixed; inset: 0; z-index: 50;
  background: #000; opacity: 0; pointer-events: none;
  transition: opacity 900ms ease;
}

/* Téléphone : le réglage « 3 ou 4 par ligne » posé sur la tablette rendrait
   l'écran illisible ici, on le plafonne à deux colonnes. */
@media (max-width: 560px) {
  .board { grid-template-columns: repeat(var(--cols-narrow, 2), minmax(0, 1fr)); gap: 10px; }
  .card { padding: 13px; min-height: 132px; gap: 6px; }
  .card-shape svg { width: 22px; height: 22px; }
  .card-name { font-size: 0.98rem; }
  .card-status { font-size: 1.3rem; padding-top: 10px; }
  .card.is-late .card-status { font-size: 0.9rem; }
  .app { padding-left: calc(12px + var(--safe-l)); padding-right: calc(12px + var(--safe-r)); }
  .nav-btn { padding: 10px 11px; font-size: 0.66rem; letter-spacing: 0.08em; }
  /* La barre passe sur deux lignes : les boutons s'alignent alors sur le titre
     et sur la grille, pas sur le bord droit. */
  .topbar-actions { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; }
}
