:root {
  --vert: #2D5A2D; --vert-fonce: #234723; --creme: #FBF7EF; --orange: #F2A93B;
  --orange-clair: #FFD98E; --tomate: #D9482B; --texte: #2B2B23; --muted: #7A766B;
  --chip: #E4F0DC; --chip-txt: #2E5E33; --card-r: 16px;
  --nav-h: 62px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--creme); color: var(--texte); }

/* ---- Loader ---- */
#loader { position: fixed; inset: 0; background: linear-gradient(160deg, var(--vert), var(--vert-fonce)); color: #fff; display: flex; align-items: center; justify-content: center; z-index: 100; transition: opacity .4s; }
#loader.done { opacity: 0; pointer-events: none; }
.loader-box { text-align: center; padding: 20px; }
.tomato-bounce { font-size: 60px; animation: bounce 1s infinite alternate ease-in-out; }
@keyframes bounce { to { transform: translateY(-12px); } }
.loader-box h1 { margin: 8px 0 4px; }
.loader-box p { opacity: .85; font-size: 14px; margin-bottom: 16px; }
.progress { width: 240px; height: 10px; background: rgba(255,255,255,.25); border-radius: 6px; overflow: hidden; margin: 0 auto; }
#loader-bar { height: 100%; width: 0; background: var(--orange); border-radius: 6px; transition: width .2s; }

/* ---- Topbar ---- */
#topbar { position: sticky; top: 0; z-index: 20; background: var(--vert); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
.brand { font-size: 17px; }
.icon-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: inherit; padding: 4px 8px; border-radius: 8px; }
.icon-btn.big { font-size: 24px; }
.icon-btn:active { background: rgba(0,0,0,.08); }

/* ---- Layout / nav ---- */
#layout { display: flex; min-height: calc(100dvh - 48px); }
#nav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid #E5DFD2; display: flex; z-index: 20; }
.nav-btn { flex: 1; background: none; border: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; color: var(--muted); font-size: 11px; }
.nav-btn span { font-size: 22px; }
.nav-btn.active { color: var(--vert); font-weight: 700; }
.nav-btn.active span { transform: scale(1.15); }
#main { flex: 1; padding: 18px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1080px; margin: 0 auto; width: 100%; }

@media (min-width: 900px) {
  #nav { position: sticky; top: 48px; bottom: auto; height: calc(100dvh - 48px); width: 210px; flex-direction: column; border-top: none; border-right: 1px solid #E5DFD2; background: var(--vert-fonce); padding: 18px 10px; gap: 4px; }
  .nav-btn { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 14px; border-radius: 12px; font-size: 15px; color: rgba(255,255,255,.85); }
  .nav-btn.active { background: var(--orange); color: #2B1D07; }
  .nav-btn.active span { transform: none; }
  #main { padding-bottom: 40px; }
}

/* ---- Composants ---- */
.panel { display: none; }
.panel.active { display: block; animation: fadein .25s; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }
h2 { font-size: clamp(19px, 5vw, 24px); margin-bottom: 14px; }
.searchrow { display: flex; gap: 8px; margin-bottom: 10px; }
.searchrow input, .searchrow select { flex: 1; min-width: 0; padding: 13px 16px; font-size: 16px; border: 2px solid #E5DFD2; border-radius: 14px; background: #fff; outline: none; }
.searchrow input:focus { border-color: var(--orange); }
.searchrow.small input { padding: 9px 12px; font-size: 14px; }
.searchrow select { flex: 0 0 76px; }
.btn-primary { background: var(--orange); color: #2B1D07; border: none; border-radius: 14px; padding: 12px 20px; font-size: 16px; font-weight: 700; cursor: pointer; }
.btn-primary:active { transform: scale(.97); }
.btn-ghost { background: #fff; color: var(--chip-txt); border: 1.5px solid #CFE0C6; border-radius: 14px; padding: 12px 18px; font-size: 15px; font-weight: 600; cursor: pointer; }
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); margin-bottom: 8px; }
.hint { font-size: 13.5px; color: var(--muted); margin: 8px 0; }
.hint.feedback { color: var(--orange-fonce, #D98F1F); font-weight: 600; }
.small-muted { font-size: 12px; color: var(--muted); }

/* Chips */
.chipline { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0; }
.chip { background: var(--chip); color: var(--chip-txt); border: none; border-radius: 16px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; }
.chip.suggestion { background: #F1EDE3; color: var(--muted); }
.chip.pantry { background: #F3EBDD; color: #7A6A4F; }
.chip.member { background: #fff; }
.chip.member.selected { background: var(--orange); color: #2B1D07; }
.chip .x { opacity: .55; font-size: 12px; }

/* Cartes recettes (grille) */
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (min-width: 600px) { .cards { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); } }
.rcard { background: #fff; border-radius: var(--card-r); box-shadow: 0 2px 8px rgba(0,0,0,.06); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.rcard:active { transform: scale(.98); }
.rcard .pic { height: 110px; background: #E9F2E2; display: flex; align-items: center; justify-content: center; font-size: 38px; }
.rcard .pic img { width: 100%; height: 100%; object-fit: cover; }
.rcard .body { padding: 10px 12px 12px; }
.rcard h4 { font-size: 14.5px; line-height: 1.3; margin-bottom: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rcard .meta { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Lignes (frigo, livres) */
.rows { display: flex; flex-direction: column; gap: 10px; }
.rrow { background: #fff; border-radius: var(--card-r); box-shadow: 0 2px 8px rgba(0,0,0,.06); padding: 13px 15px; cursor: pointer; display: flex; align-items: center; gap: 12px; }
.rrow .grow { flex: 1; min-width: 0; }
.rrow h4 { font-size: 15px; margin-bottom: 3px; }
.rrow .sub { font-size: 12.5px; color: var(--muted); }
.rrow .badge { background: var(--chip); color: var(--chip-txt); font-size: 12px; font-weight: 700; border-radius: 10px; padding: 6px 10px; white-space: nowrap; }

/* Onglets */
.tabrow { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tabrow.small .tab { padding: 7px 12px; font-size: 13px; }
.tab { background: #fff; border: 1.5px solid #E5DFD2; border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer; color: var(--texte); }
.tab.active { background: var(--orange); border-color: var(--orange); color: #2B1D07; }

/* Enfants */
.roulette-box { background: #FFF3DE; border-radius: var(--card-r); padding: 16px; margin-bottom: 14px; }
.familybar { background: #F0F7EC; border-radius: var(--card-r); padding: 14px; margin-bottom: 14px; }
.famtitle { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.kcard { background: #F0F7EC; border-radius: var(--card-r); padding: 15px; margin-bottom: 10px; }
.kcard.reward { background: #FFF3DE; }
.kcard .khead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kcard .emo { font-size: 26px; }
.kcard b { font-size: 15px; }
.kcard .pts { background: var(--orange); color: #2B1D07; font-size: 11.5px; font-weight: 700; border-radius: 10px; padding: 3px 9px; }
.kcard.reward .pts { background: var(--tomate); color: #fff; }
.kcard p { font-size: 13.5px; color: #55524B; margin: 6px 0 10px; }
.kcard .btn-primary { padding: 9px 16px; font-size: 14px; }

/* Aide */
.helpcard { background: #fff; border-radius: var(--card-r); padding: 16px; margin-bottom: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.helpcard b { display: block; margin-bottom: 5px; font-size: 15px; }
.helpcard p { font-size: 13.5px; color: #55524B; line-height: 1.55; }
.helpcard.don { background: #FFF3DE; }
.helpcard .tiers { font-size: 15px; font-weight: 700; color: var(--texte); margin-top: 8px; }

/* Bibliothèque lecteur */
#lib-reader h3 { margin: 12px 0; }
#reader-body { background: #fff; border-radius: var(--card-r); padding: 18px; font-family: Georgia, serif; font-size: 15.5px; line-height: 1.75; white-space: pre-wrap; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.chap-item { padding: 10px 14px; }

/* Fiche recette */
#detail { position: fixed; inset: 0; background: rgba(43,43,35,.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
#detail[hidden] { display: none; }
@media (min-width: 700px) { #detail { align-items: center; padding: 24px; } }
#detail-card { background: var(--creme); width: 100%; max-width: 860px; max-height: 92dvh; border-radius: 22px 22px 0 0; overflow-y: auto; padding: 18px; }
@media (min-width: 700px) { #detail-card { border-radius: 22px; } }
.detail-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
#detail-thumb { width: 74px; height: 74px; border-radius: 14px; object-fit: cover; }
.detail-emoji { width: 74px; height: 74px; border-radius: 14px; background: #E9F2E2; display: flex; align-items: center; justify-content: center; font-size: 34px; flex: 0 0 74px; }
.detail-titles { flex: 1; min-width: 0; }
.detail-titles h3 { font-size: 19px; line-height: 1.25; }
.hint.time { color: var(--chip-txt); font-weight: 600; }
.detail-body { display: grid; gap: 14px; }
@media (min-width: 700px) { .detail-body { grid-template-columns: 280px 1fr; align-items: start; } }
.detail-ing, .detail-instr { background: #fff; border-radius: var(--card-r); padding: 16px; }
.detail-ing ul { list-style: none; margin-top: 8px; }
.detail-ing li { font-size: 14px; padding: 5px 0; border-bottom: 1px dashed #EEE8DC; }
.detail-instr #detail-steps { margin-top: 8px; font-size: 14.5px; line-height: 1.7; white-space: pre-wrap; }
.hint.license { margin-top: 12px; font-size: 11.5px; word-break: break-all; }
.hint.license a { color: var(--chip-txt); }

/* Saisons */
.chip.fruit { background: #FFE9EF; color: #A63D5A; }
.season-scroll { overflow-x: auto; }
#season-table table { border-collapse: collapse; width: 100%; min-width: 560px; }
#season-table th { font-size: 10.5px; padding: 4px 2px; color: var(--muted); }
#season-table th.cur { color: var(--orange-fonce, #D98F1F); }
#season-table td { font-size: 12px; padding: 3px 4px; }
#season-table td:first-child { white-space: nowrap; }
#season-table td.in, #season-table td.out { border-radius: 4px; border: 2px solid #fff; min-width: 22px; height: 18px; }
#season-table td.in { background: #7FB46B; }
#season-table td.out { background: #F1EDE3; }
#season-table td.cur { outline: 2px solid var(--orange); outline-offset: -2px; }
#season-table tr.grp td { font-weight: 700; font-size: 13.5px; padding-top: 12px; }

details#pantry-box { background: #fff; border-radius: var(--card-r); padding: 12px 15px; margin: 10px 0; }
details#pantry-box summary { cursor: pointer; font-weight: 700; font-size: 14px; }
details#pantry-box summary small { color: var(--muted); font-weight: 400; }
