/* Spritz au poids — charte : DESIGN.md. Toutes les couleurs de thème passent par les variables du § 5. */

@font-face {
  font-family: "Sora";
  src: url("fonts/sora-latin-var.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

/* ---------- Variables ---------- */

:root {
  /* Couleurs communes à tous les thèmes (DESIGN.md § 6) */
  --prosecco: #f3e2a0;
  --water: #cfe8f5;
  --ice: #ffffff;
  --alert: #ffb020; /* fond de la pastille de dépassement, texte --ink */
  /* Valeurs par défaut, surchargées par thème */
  --on-acc: #ffffff; /* texte sur --acc (badges) */
  --acc-ui: var(--acc); /* − / + des tuiles actives et interrupteur, sur fond blanc : ≥ 3:1 */
  --fg-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  --so: 0.35;
  --bk: transparent;
  --bokeh-opacity: 0;
}

/* Thèmes (DESIGN.md § 5). Sélecteurs [data-theme] et non :root seul : les pastilles
   du sélecteur de thème portent elles aussi data-theme pour afficher leur dégradé. */

:root,
[data-theme="sunset"] {
  --g1: #ffb347; --g2: #ff7a2f; --g3: #e3451d; --g4: #8a1d12;
  --fg: #ffffff; --ink: #2a1208; --acc: #c8471f;
  --s1: #ffd98a; --s2: #ff9a2e;
  --shadow: rgba(90, 20, 0, 0.3);
}

[data-theme="lagon"] {
  --g1: #9ff3e4; --g2: #2fc9c2; --g3: #0e8da6; --g4: #0a3d6b;
  --fg: #ffffff; --ink: #0a2c3d; --acc: #0d7f95;
  --s1: #e8ffb0; --s2: #8fd14f;
  --shadow: rgba(5, 40, 70, 0.3);
}

[data-theme="riviera"] {
  --g1: #ffc6d0; --g2: #ff6f91; --g3: #c84a9a; --g4: #4b2378;
  --fg: #ffffff; --ink: #3a0f36; --acc: #d6336c;
  --s1: #ffe0e6; --s2: #ff8aa0;
  --shadow: rgba(80, 10, 60, 0.3);
}

[data-theme="hugo"] {
  --g1: #e9ee7a; --g2: #b9e34b; /* g1 assombri (maquette : #f6f7a3) pour le texte blanc */ --g3: #3fae6c; --g4: #115c47;
  --fg: #ffffff; --ink: #10382a; --acc: #278455;
  --s1: #fff9b0; --s2: #f2d43a;
  --shadow: rgba(10, 60, 40, 0.3);
}

[data-theme="guinguette"] {
  --g1: #5a3fb8; --g2: #3a2a8a; --g3: #231a5e; --g4: #120d33;
  --fg: #ffffff; --ink: #1b1540; --acc: #e0a62a; --on-acc: #1b1540; --acc-ui: #b18321;
  --s1: #ffe9a8; --s2: #f0b840;
  --shadow: rgba(0, 0, 30, 0.45);
  --bk: #ffd27a; --bokeh-opacity: 0.55;
}

[data-theme="pasteque"] {
  --g1: #ff9aa8; --g2: #ff4d6d; --g3: #d7286a; --g4: #6a0f3b;
  --fg: #ffffff; --ink: #3f0a24; --acc: #19a974; --on-acc: #3f0a24; --acc-ui: #179d6c;
  --s1: #d9f99d; --s2: #4ade80;
  --shadow: rgba(90, 10, 40, 0.3);
}

[data-theme="limoncello"] {
  --g1: #fff6a8; --g2: #ffe14d; --g3: #f2b705; --g4: #b86b00;
  --fg: #3b2600; --ink: #3b2600; --acc: #a36600;
  --s1: #fffbe0; --s2: #ffd43a;
  --shadow: rgba(120, 70, 0, 0.3);
  --fg-shadow: 0 1px 2px rgba(255, 255, 255, 0.35); /* texte sombre : halo clair */
}

[data-theme="nuit"] {
  --g1: #3a3542; --g2: #26222c; --g3: #17151c; --g4: #0a090d;
  --fg: #ffffff; --ink: #1a1720; --acc: #e0702e; --on-acc: #1a1720; --acc-ui: #d96d2d;
  --s1: #ffb57a; --s2: #c75a1e;
  --shadow: rgba(0, 0, 0, 0.6);
  --so: 0.22;
}

/* ---------- Base ---------- */

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

html {
  background: var(--g1);
  color: var(--fg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  font: 15px/1.3 "Sora", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

[hidden] { display: none !important; }

/* ---------- Décor du fond (DESIGN.md § 4) ---------- */

.decor {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: radial-gradient(120% 70% at 50% 0%, var(--g1) 0%, var(--g2) 38%, var(--g3) 70%, var(--g4) 100%);
}

.slice {
  position: absolute;
  right: -70px;
  top: 120px;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--s1) 0 26%, var(--s2) 27% 86%, #fff 87% 92%, var(--s2) 93%);
  opacity: var(--so);
  --quarters: conic-gradient(from 0deg, #000 0 12%, transparent 12% 13%, #000 13% 25%, transparent 25% 26%, #000 26% 37%, transparent 37% 38%, #000 38% 50%, transparent 50% 51%, #000 51% 62%, transparent 62% 63%, #000 63% 75%, transparent 75% 76%, #000 76% 87%, transparent 87% 88%, #000 88% 100%);
  -webkit-mask: var(--quarters);
  mask: var(--quarters);
}

.ice {
  position: absolute;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.12));
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.bubble {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.1) 60%, rgba(255, 255, 255, 0) 70%);
}

.bokeh {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: radial-gradient(circle, var(--bk) 0 40%, rgba(255, 255, 255, 0) 70%);
  opacity: var(--bokeh-opacity);
  filter: blur(1px);
}

@media (prefers-reduced-motion: no-preference) {
  .bubble {
    top: 100%;
    will-change: transform;
    animation: rise var(--dur) linear var(--delay) infinite;
  }
}

@keyframes rise {
  0% { transform: translateY(0); opacity: 0; }
  8% { opacity: 1; }
  92% { opacity: 1; }
  100% { transform: translateY(calc(-100vh - 40px)); opacity: 0; }
}

/* ---------- Mise en page (DESIGN.md § 3) ---------- */

.app {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 16px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 16px)
    calc(env(safe-area-inset-left) + 16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-shadow: var(--fg-shadow);
}

@media (min-width: 600px) {
  /* Tablette : colonne de 560 px, tailles +10 % */
  .app {
    zoom: 1.1;
    max-width: calc(560px / 1.1);
  }
}

.hd {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
}

.title {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.title small {
  display: block;
  font-size: 12px;
  font-weight: 600;
  opacity: 0.85;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.round {
  position: relative;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid color-mix(in srgb, currentColor 45%, transparent);
  display: grid;
  place-items: center;
  padding: 0;
}

.round::before {
  content: "";
  position: absolute;
  inset: -2px;
}

.glass {
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 22px;
  padding: 12px 14px;
}

/* ---------- Stepper − / + ---------- */

.step {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step button {
  position: relative;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, currentColor 70%, transparent);
  background: rgba(255, 255, 255, 0.14);
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  display: grid;
  place-items: center;
  text-shadow: inherit;
}

/* Zone tactile de 44 px */
.step button::before {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
}

.step button:disabled,
.step button[aria-disabled="true"] {
  opacity: 0.35;
  cursor: default;
}

.step output {
  font-size: 19px;
  font-weight: 800;
  min-width: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.cap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.cap .lb { font-size: 13px; opacity: 0.95; }
.cap .step output { min-width: 52px; font-size: 20px; }
.cap .step output small { font-size: 12px; font-weight: 600; opacity: 0.85; }

/* ---------- Compteur ---------- */

.count {
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  opacity: 0.9;
  padding: 0 4px;
}

.count b { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
.count .max { opacity: 0.8; }
.count.over { opacity: 1; }

.count.over .count-value {
  background: var(--alert);
  color: var(--ink);
  text-shadow: none;
  border-radius: 10px;
  padding: 2px 8px;
}

.count.over .max { opacity: 1; }

/* ---------- Tuiles 3 × 2 ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tile {
  border-radius: 16px;
  padding: 9px 4px 8px;
  min-width: 0;
  background: rgba(255, 255, 255, 0.14);
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  transition: background-color 0.2s, color 0.2s;
}

.tile.on {
  background: rgba(255, 255, 255, 0.92);
  border-color: #fff;
  color: var(--ink);
  text-shadow: none;
}

.tile .nm {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  margin-right: 5px;
  vertical-align: middle;
}

.tile .step { gap: 5px; }
.tile .step button { width: 26px; height: 26px; font-size: 14px; }
.tile .step button::before { inset: -9px; }
.tile .step output { font-size: 17px; min-width: 16px; }

.tile.on .step button {
  border-color: var(--acc-ui);
  color: var(--acc-ui);
  background: #fff;
}

/* ---------- Fiches de dosage ---------- */

.cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  /* Plus transparente que la maquette (80 %, flou 18 px) pour laisser voir les bulles */
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  color: var(--ink);
  text-shadow: none;
  border-radius: 22px;
  padding: 12px 14px;
  box-shadow: 0 14px 30px var(--shadow);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--on-acc);
  background: var(--acc);
  border-radius: 10px;
  padding: 3px 8px;
  font-variant-numeric: tabular-nums;
}

.ing {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 7px 10px;
  align-items: center;
  font-size: 14px;
}

.ing .dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.ing .dot-prosecco { --c: var(--prosecco); }
.ing .dot-water { --c: var(--water); }
.ing .dot-ice { --c: var(--ice); }

.ing .g {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* Remplissages successifs : à droite du poids (2 verres) ou sur leur propre ligne (3 verres et plus) */
.ing .g small,
.ing .fills {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}

.ing .g small { margin-left: 4px; }

.ing .fills {
  grid-column: 2 / -1;
  margin-top: -6px;
  text-align: right;
}

.cum {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px dashed color-mix(in srgb, var(--ink) 30%, transparent);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}

.cum > span:first-child { opacity: 0.85; }

.garnish {
  margin: 6px 0 0;
  font-size: 12px;
  opacity: 0.85;
}

.card .warn {
  margin: 0;
  font-size: 14px;
}

.empty {
  margin: 0;
  padding: 28px 16px;
  text-align: center;
  font-size: 14px;
  border-style: dashed;
}

.reset {
  align-self: center;
  min-height: 44px;
  padding: 0 16px;
  background: none;
  border: 0;
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  opacity: 0.9;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 14px 30px var(--shadow);
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .tile { transition: none; }
}

/* ---------- Bandeau de mise à jour ---------- */

.update {
  position: fixed;
  z-index: 11;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 12px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px 6px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 14px 30px var(--shadow);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Paramètres (DESIGN.md § 7) ---------- */

.title:focus { outline: none; }

.section-title {
  margin: 8px 4px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.9;
}

.rows { padding: 2px 14px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.row + .row { border-top: 1px solid color-mix(in srgb, currentColor 22%, transparent); }

.row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14px;
  min-width: 0;
}

.row-text small { font-size: 11px; opacity: 0.9; }

/* Pilule de valeur ; police à 16 px dans les champs pour éviter le zoom automatique d'iOS */
.pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 64px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  text-shadow: none;
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.pill:focus-within { outline: 2px solid var(--acc-ui); outline-offset: 1px; }

.pill input,
.parts input {
  min-width: 0;
  border: 0;
  padding: 0;
  background: none;
  font: inherit;
  color: inherit;
  font-variant-numeric: tabular-nums;
}

.pill input { width: 3ch; text-align: right; }
.pill input:focus,
.parts input:focus { outline: none; }

.pill.readonly {
  background: transparent;
  border: 1.5px dashed color-mix(in srgb, currentColor 80%, transparent);
  color: inherit;
  text-shadow: inherit;
}

.switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.3);
  transition: background-color 0.2s;
}

.switch::before {
  content: "";
  position: absolute;
  inset: -8px;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}

.switch[aria-checked="true"] { background: #fff; }
.switch[aria-checked="true"]::after { transform: translateX(18px); background: var(--acc-ui); }

.parts {
  display: grid;
  /* Colonne des noms élargie (1.75fr au lieu de 1.3fr) pour que « Limoncello » tienne en 360 px */
  grid-template-columns: minmax(0, 1.75fr) repeat(4, minmax(0, 1fr));
  gap: 6px 5px;
  align-items: center;
}

.parts .head {
  align-self: end;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-transform: uppercase;
  text-align: center;
  opacity: 0.9;
}

.parts .name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.parts .name .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c);
  margin-right: 4px;
  vertical-align: middle;
}

.parts input {
  width: 100%;
  height: 44px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  text-shadow: none;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
}

.parts input:focus-visible { outline: 2px solid var(--acc-ui); outline-offset: 1px; }

.themes {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 6px 4px 8px;
  scrollbar-width: none;
}

.theme {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 48px;
  padding: 0;
  border: 0;
  background: none;
  font-size: 10px;
  font-weight: 600;
}

.swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--g1), var(--g3));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
  transition: box-shadow 0.2s;
}

/* L'anneau prend la couleur du texte de la page (currentColor), pas celle du thème de la pastille */
.theme[aria-pressed="true"] .swatch { box-shadow: 0 0 0 3px currentColor, 0 6px 14px var(--shadow); }
.theme:focus-visible { outline: none; }
.theme:focus-visible .swatch { outline: 2px solid currentColor; outline-offset: 6px; }

.settings-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 8px;
  text-align: center;
  font-size: 12px;
}

.settings-foot p { margin: 0; opacity: 0.9; }
.settings-foot .reset { align-self: center; }

.confirm {
  width: 100%;
  font-size: 14px;
}

.confirm p { margin: 0 0 10px; opacity: 1; }

.confirm-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1.5px solid color-mix(in srgb, currentColor 70%, transparent);
  background: rgba(255, 255, 255, 0.14);
  font-size: 14px;
  font-weight: 700;
  text-shadow: inherit;
}

.btn.primary {
  border-color: var(--acc);
  background: var(--acc);
  color: var(--on-acc);
  text-shadow: none;
}

@media (prefers-reduced-motion: reduce) {
  .switch,
  .switch::after,
  .swatch { transition: none; }
}
