/* Couleurs du thème Telegram (variables posées par telegram-web-app.js), avec repli sombre */
:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --bg2: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #8b9aa7);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --btn: var(--tg-theme-button-color, #5288c1);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --radius: 14px;
  --tabs-h: 58px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.muted { color: var(--hint); font-size: 13px; margin: 6px 12px; }
.center { text-align: center; margin: 32px 24px; }
[hidden] { display: none !important; }

/* --- Catalogue ------------------------------------------------------------ */
.toolbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 10px 12px 6px;
  display: grid; gap: 8px;
}
#search {
  width: 100%; padding: 10px 14px; border-radius: 12px; border: 0; outline: 0;
  background: var(--bg2); color: var(--text); font-size: 16px;
}
#search::placeholder { color: var(--hint); }
.segmented { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.segmented button, .chips button {
  flex: none; padding: 7px 12px; border-radius: 999px; background: var(--bg2);
  white-space: nowrap; font-size: 14px;
}
.segmented button.on { background: var(--btn); color: var(--btn-text); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips button { font-size: 13px; padding: 5px 10px; color: var(--hint); }
.chips button.on { color: var(--text); outline: 1.5px solid var(--btn); }

.grid {
  display: grid; gap: 8px; padding: 4px 12px 12px;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}
.tile {
  position: relative; aspect-ratio: 3 / 4; border-radius: var(--radius); overflow: hidden;
  background: var(--bg2); padding: 0; text-align: left;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.tile img.loaded { opacity: 1; }
.tile .label {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  color: #fff; font-weight: 600; font-size: 13px; line-height: 1.2;
}
.tile .label small { display: block; font-weight: 400; opacity: .8; font-size: 11px; }
.tile .heart { position: absolute; top: 6px; right: 6px; font-size: 14px; text-shadow: 0 1px 3px rgba(0,0,0,.5); }

/* RP sauvegardés à reprendre (comme /recent) */
.resume { padding: 2px 0 6px; }
.resume h2 { margin: 4px 12px 8px; font-size: 15px; }
.resume-list { display: flex; gap: 8px; overflow-x: auto; padding: 0 12px; scrollbar-width: none; }
.resume-list::-webkit-scrollbar { display: none; }
.resume-item {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 6px;
  border-radius: var(--radius); background: var(--bg2); text-align: left; max-width: 240px;
}
.resume-item img { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: none; background: var(--bg); }
.resume-item b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resume-item small { color: var(--hint); font-size: 12px; white-space: nowrap; }
.resume-item:disabled { opacity: .5; }
details.box summary { font-weight: 600; cursor: pointer; }
details.box p { white-space: pre-wrap; }

/* --- Fiche ------------------------------------------------------------------ */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; }
.close {
  position: fixed; top: 10px; left: 10px; z-index: 21; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(0,0,0,.5); color: #fff; font-size: 16px;
}
.photos { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; background: #000; }
.photos::-webkit-scrollbar { display: none; }
.photos img { flex: none; width: 100%; aspect-ratio: 4 / 5; object-fit: cover; scroll-snap-align: center; }
.dots { display: flex; justify-content: center; gap: 5px; padding: 8px 0 0; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--hint); opacity: .4; }
.dots i.on { opacity: 1; background: var(--btn); }
.card-body { padding: 8px 16px 24px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-head h1 { margin: 4px 0 0; font-size: 24px; }
.card-head .muted { margin: 4px 0 0; font-size: 15px; }
.fav { font-size: 28px; padding: 4px; }
.primary {
  display: block; width: 100%; margin-top: 20px; padding: 14px; border-radius: 12px;
  background: var(--btn); color: var(--btn-text); font-weight: 600; font-size: 16px;
}
.primary:disabled { opacity: .6; }
.secondary { display: block; width: 100%; margin-top: 10px; padding: 12px; border-radius: 12px; background: var(--bg2); color: var(--link); }

/* --- Réglages et compte ----------------------------------------------------- */
.panel { padding: 12px; display: grid; gap: 12px; }
.panel h2 { margin: 8px 4px 0; font-size: 20px; }
.box { background: var(--bg2); border-radius: var(--radius); padding: 14px; }
.box h3 { margin: 0 0 10px; font-size: 15px; }
.box p { margin: 6px 0 0; color: var(--hint); font-size: 13px; }
.choice { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.choice button { flex: 1; padding: 8px 4px; border-radius: 8px; font-size: 14px; }
.choice button.on { background: var(--btn); color: var(--btn-text); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; border-radius: 999px; background: var(--hint); transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.on { background: var(--btn); }
.switch.on::after { transform: translateX(20px); }
.profile { white-space: pre-wrap; color: var(--text) !important; }
.big { font-size: 28px; font-weight: 700; margin: 0; }
.link { word-break: break-all; color: var(--link) !important; font-size: 13px; }

/* --- Onglets et toast ------------------------------------------------------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--bg2);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; display: grid; place-items: center; gap: 0; font-size: 11px; color: var(--hint); padding-top: 6px; }
.tabs button span { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--accent); }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; background: rgba(0,0,0,.82); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 14px;
  max-width: 90vw; text-align: center;
}
