:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #f0eee6;
  --text: #22261f;
  --muted: #646d5f;
  --border: #e1ded3;
  --accent: #3f7d4e;
  --accent-ink: #ffffff;
  --ok: #4f9a5c;
  --over: #c0533a;
  --zero: #d4a12a;
  --danger: #b5432f;
  --alert-bg: #fdf1e6;
  --alert-border: #edc7a3;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 6px 20px rgba(0, 0, 0, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121611;
    --surface: #1b2119;
    --surface-2: #232b21;
    --text: #e7ece3;
    --muted: #9ba696;
    --border: #2d362a;
    --accent: #6fbd80;
    --accent-ink: #0d1a10;
    --ok: #6fbd80;
    --over: #ef8a6f;
    --zero: #f0c14e;
    --danger: #ef7d66;
    --alert-bg: #2d2219;
    --alert-border: #5b4330;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 2rem; letter-spacing: .02em; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .8em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); min-height: 1.5em; }

#app { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.screen { display: flex; flex-direction: column; gap: 14px; }

/* Boutons */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: 11px 16px; border-radius: 12px; cursor: pointer;
  min-height: 44px; transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.wide { width: 100%; }
.btn.round { width: 52px; height: 52px; border-radius: 50%; font-size: 1.6rem; padding: 0; }
.link-btn { background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; cursor: pointer; padding: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 700; cursor: pointer; display: inline-grid; place-items: center;
}
.icon-btn.small { width: 30px; height: 30px; font-size: .8rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, select {
  width: 100%; font: inherit; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); margin: 4px 0 12px; min-height: 44px;
}
label { font-weight: 600; font-size: .95rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card-head span:first-letter { text-transform: uppercase; }

/* Verrouillage */
.lock { align-items: center; text-align: center; padding-top: 12vh; }
.lock .unlock { width: 100%; max-width: 320px; text-align: left; }
.lock-msg { min-height: 1.5em; color: var(--muted); }
.lock-links { display: flex; gap: 8px; }
.logo { display: block; margin: 0 auto 8px; }

/* Accueil */
.onboard-card { display: flex; flex-direction: column; gap: 4px; }
.onboard-card h1 { text-align: center; }
.lead { text-align: center; font-size: 1.1rem; }
.rules { padding-left: 0; list-style: none; margin: 8px 0 12px; display: grid; gap: 8px; }
.choices { display: grid; gap: 8px; margin: 8px 0; }
.btn.choice { text-align: left; font-weight: 500; }
.btn.choice.selected { border-color: var(--accent); }
.score { font-size: 1.3rem; font-weight: 700; }
.alert { background: var(--alert-bg); border: 1px solid var(--alert-border); border-radius: 12px; padding: 12px 14px; }
.alert p:last-child { margin: 0; }
.dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 12px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.dots span.on { background: var(--accent); }

/* Principal */
.topbar { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.2rem; }
.topbar-actions { display: flex; gap: 8px; }

.garden-wrap { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); aspect-ratio: 5 / 3; background: #86c3ef; }
#garden { display: block; width: 100%; height: 100%; }
.garden-empty {
  position: absolute; left: 50%; bottom: 10%; transform: translateX(-50%); width: min(90%, 440px); margin: 0;
  background: rgba(255, 255, 255, .85); color: #2b3327; border-radius: 12px; padding: 10px 14px; text-align: center; font-size: .92rem;
}
.destroy-banner {
  position: absolute; left: 8px; right: 8px; top: 8px; margin: 0; padding: 10px 14px; border-radius: 12px;
  background: rgba(30, 36, 48, .85); color: #fff; font-weight: 600; text-align: center; font-size: .95rem;
}

.flower { cursor: pointer; }
.flower .sway { transform-box: fill-box; transform-origin: 50% 100%; animation: sway 6s ease-in-out infinite alternate; }
.flower .s1 { animation-duration: 7s; animation-delay: -2s; }
.flower .s2 { animation-duration: 5.5s; animation-delay: -4s; }
.flower .s3 { animation-duration: 8s; animation-delay: -1s; }
@keyframes sway { from { transform: rotate(-2.5deg); } to { transform: rotate(2.5deg); } }
.flower .glow { animation: glow 3s ease-in-out infinite alternate; }
@keyframes glow { from { opacity: .45; } to { opacity: 1; } }
.picking .flower .sway { animation: shiver 1.4s ease-in-out infinite alternate; }
@keyframes shiver { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
.picking .flower:hover .sway, .picking .flower:focus .sway { filter: drop-shadow(0 0 6px #fff) brightness(1.1); }
.picking .flower:focus { outline: none; }
.flower.wilting .sway { animation: wilt 1.1s ease-in forwards; }
@keyframes wilt {
  0% { transform: rotate(0); filter: none; opacity: 1; }
  45% { transform: rotate(18deg) translateY(4px); filter: grayscale(1) sepia(.6); opacity: 1; }
  100% { transform: rotate(70deg) translateY(30px) scale(.4); filter: grayscale(1) sepia(.8); opacity: 0; }
}
.night .star { animation: twinkle 4s ease-in-out infinite alternate; }
@keyframes twinkle { from { opacity: .35; } to { opacity: 1; } }
.veil, .rain { pointer-events: none; }
.drop { animation: fall 1s linear infinite; }
.drop.d1 { animation-duration: .8s; animation-delay: -.3s; }
.drop.d2 { animation-duration: 1.2s; animation-delay: -.6s; }
.drop.d3 { animation-duration: .9s; animation-delay: -.1s; }
@keyframes fall { from { transform: translate(0, 0); } to { transform: translate(-24px, 680px); } }

.count { font-size: 1.1rem; margin: 4px 0 8px; }
.count strong { font-size: 2.4rem; line-height: 1; }
.meter { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 99px; background: var(--ok); transition: width .3s ease; }
.meter-fill.over { background: var(--over); }
.verdict { margin: 8px 0 14px; font-weight: 600; }
.verdict.over { color: var(--over); }
.drink-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.drink {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center;
  text-align: left; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 12px; padding: 10px; font: inherit; cursor: pointer; min-height: 56px;
}
.drink:active { transform: scale(.98); }
.drink .icon { grid-row: span 2; font-size: 1.5rem; }
.drink span:nth-child(2) { font-weight: 600; font-size: .92rem; }
.drink small { color: var(--muted); }
.drink-list { list-style: none; padding: 0; margin: 14px 0 8px; display: grid; gap: 6px; }
.drink-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; background: var(--surface-2); border-radius: 10px; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week .day { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.week .bar-wrap { height: 80px; width: 100%; max-width: 34px; display: flex; align-items: flex-end; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.week .bar { width: 100%; border-radius: 8px; background: var(--ok); }
.week .bar.zero { background: var(--zero); }
.week .bar.over { background: var(--over); }
.week .bar.none { background: var(--border); }
.week .num { font-weight: 700; }
.week .lbl { color: var(--muted); font-size: .8rem; }
.week .today .lbl { color: var(--text); font-weight: 700; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; }
.tile strong { font-size: 1.5rem; }
.tile span { color: var(--muted); font-size: .88rem; }
.footer { text-align: center; }

/* Fenêtres */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(440px, calc(100% - 32px)); max-height: calc(100% - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(15, 20, 14, .55); }
.dlg { padding: 22px; display: flex; flex-direction: column; gap: 6px; }
.dlg h2:first-letter { text-transform: uppercase; }
.row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.row .btn { flex: 1 1 140px; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 10px 0; }
.big-count { font-size: 3rem; font-weight: 800; min-width: 2ch; text-align: center; }
.hint { text-align: center; min-height: 3em; }
.settings { display: flex; flex-direction: column; }
.menu-actions { display: grid; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.help-list { padding-left: 18px; display: grid; gap: 8px; }
.warn { font-size: .92rem; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  width: min(560px, calc(100% - 32px)); background: #222a20; color: #fff; padding: 12px 16px; border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3); transition: transform .3s ease, opacity .3s ease, visibility .3s; z-index: 10; text-align: center;
  opacity: 0; visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
