:root {
  color-scheme: light dark;
  --bg: #fff8f3;
  --surface: #ffffff;
  --surface-2: #fdeee6;
  --text: #2a1a24;
  --muted: #8a7480;
  --line: #f0dcd2;
  --accent: #ff4f7b;
  --accent-2: #a04bff;
  --warn: #c2620a;
  --danger: #d6304a;
  --grad: linear-gradient(45deg, #ffb347, #ff5e7e 50%, #a04bff);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171016;
    --surface: #221922;
    --surface-2: #2e222e;
    --text: #f6ecf1;
    --muted: #a8929f;
    --line: #3a2b39;
    --warn: #f0a04b;
    --danger: #ff6b81;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.muted { color: var(--muted); font-size: 13px; }

.logo {
  font-family: "Snell Roundhand", "Segoe Script", "Brush Script MT", cursive;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  padding: 0 4px;
}
.logo.big { font-size: 46px; }
.brand { display: flex; align-items: center; gap: 6px; min-width: 0; }
.brand .logo { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand img { flex: none; }
.login-logo { display: block; margin: 0 auto 6px; }

/* ---------- boutons et champs ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn.primary { border: 0; background: var(--grad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn:not(:disabled):hover { filter: brightness(1.06); }

input, textarea {
  font: inherit;
  font-size: 16px; /* en dessous, iOS zoome sur le champ */
  width: 100%;
  padding: 9px 12px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:focus-visible, textarea:focus-visible, .btn:focus-visible, .tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 10px 0 4px;
}

/* ---------- connexion ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 34px 26px;
}
.login-card input { text-align: center; margin-bottom: 12px; }
.login-card .btn { width: 100%; padding: 12px; }
.tagline { color: var(--muted); margin: 6px 0 22px; }
.form-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }

/* ---------- album ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }
@media (max-width: 520px) {
  .topbar { padding-inline: 10px; }
  .brand .logo { font-size: 21px; padding: 0; }
  .topbar .btn { padding: 7px 11px; font-size: 13px; }
}

.months {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 16px;
  scrollbar-width: none;
}
.months::-webkit-scrollbar { display: none; }
.months a {
  flex: none;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
}
.months a:hover { border-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 0 16px 60px; }

.month { scroll-margin-top: 70px; margin-bottom: 30px; }
.month h2 {
  font-size: 20px;
  margin: 14px 0 10px;
}
.month h2::first-letter, .viewer-panel h3::first-letter { text-transform: uppercase; }
.month h2 span { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 8px; text-transform: none; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 3px; }
  main { padding-inline: 3px; }
  .month h2 { padding-inline: 13px; }
}

.tile {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 12px;
}

.tabs { display: flex; gap: 6px; padding: 12px 16px 0; }
.tab {
  font: inherit;
  font-weight: 600;
  padding: 7px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

/* ---------- carte ---------- */

.map { width: 100%; background: var(--surface-2); z-index: 0; }
#map { height: calc(100dvh - 150px); min-height: 320px; margin-top: 12px; }
.map-note { text-align: center; padding: 8px 16px; margin: 0; }

.pin {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  background-color: var(--surface-2);
  background-size: cover;
  background-position: center;
}
.pin-count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: 600 12px/22px -apple-system, "Segoe UI", sans-serif;
  text-align: center;
}
.leaflet-popup-content { margin: 12px; font: 14px/1.4 -apple-system, "Segoe UI", sans-serif; }
.popup-place { font-weight: 600; margin-bottom: 8px; }
.popup-strip { display: flex; gap: 6px; overflow-x: auto; max-width: 260px; padding-bottom: 2px; }
.popup-strip button { flex: none; width: 72px; height: 72px; padding: 0; border: 0; border-radius: 8px; overflow: hidden; cursor: pointer; }
.popup-strip img { width: 100%; height: 100%; object-fit: cover; display: block; }

.picker[open] { width: min(760px, 100vw); }
#picker-map { flex: 1 1 auto; height: 46dvh; min-height: 220px; }
.picker-search { display: flex; gap: 8px; margin-top: 10px; }
.picker-results { display: flex; flex-direction: column; }
.picker-results button {
  font: inherit;
  font-size: 13px;
  text-align: left;
  padding: 8px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--text);
  cursor: pointer;
}
.picker-address { flex: none; margin: 0; padding: 10px 20px; font-size: 14px; }
.place-row { display: flex; gap: 8px; align-items: center; }
.place-row input { flex: 1; min-width: 0; }

/* ---------- profils ---------- */

.profiles { display: flex; gap: 14px; justify-content: center; margin-bottom: 22px; }
.profile {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 8px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: 18px;
  cursor: pointer;
}
.profile:hover, .profile.current { border-color: var(--accent); }
.avatar {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  background: linear-gradient(45deg, #ffb347, #ff5e7e);
}
.avatar-2 { background: linear-gradient(45deg, #ff5e7e, #a04bff); }
.link-btn { font: inherit; font-size: 13px; color: var(--muted); background: none; border: 0; text-decoration: underline; cursor: pointer; }
a.btn { text-decoration: none; display: inline-block; }

.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty .big { font-size: 54px; }
.empty h2 { color: var(--text); margin: 10px 0 6px; }

/* ---------- import ---------- */

dialog { color: var(--text); border: 0; padding: 0; }
dialog::backdrop { background: rgba(20, 10, 18, 0.7); }

.sheet {
  width: min(680px, 100vw);
  max-width: 100vw;
  max-height: min(92vh, 100dvh);
  border-radius: 20px;
  background: var(--surface);
}
.sheet[open] { display: flex; flex-direction: column; }
.sheet-head { padding: 18px 20px 8px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.sheet-head p { margin: 2px 0 0; }
/* « auto » et non 0 comme base : sur Safari, une zone défilante de base 0 dans
   un parent sans hauteur fixe s'écrase à zéro — la liste disparaissait. */
.sheet-body { overflow-y: auto; padding: 8px 20px; flex: 1 1 auto; min-height: 0; -webkit-overflow-scrolling: touch; }
.sheet-head, .sheet-foot { flex: none; }
@media (max-width: 600px) {
  /* Sur téléphone, la fenêtre prend tout l'écran : la place ne manque jamais. */
  .sheet { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .sheet-head { padding-top: calc(18px + env(safe-area-inset-top, 0px)); }
}
.sheet-foot {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
}
.sheet-foot .btn:first-child { margin-right: auto; }

.draft {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.draft:last-child { border-bottom: 0; }
.draft > img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface-2);
}
.draft-name { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.draft label:first-of-type { margin-top: 4px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.hint.warn { color: var(--warn); }
.coords { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.draft-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
details summary { cursor: pointer; font-size: 12px; color: var(--muted); margin-top: 8px; }
.notice {
  padding: 10px 12px;
  margin: 8px 0;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 13px;
}
.notice.error { color: var(--danger); }

/* ---------- visionneuse ---------- */

.viewer {
  width: 100vw;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100dvh;
  background: var(--bg);
}
.viewer[open] { display: grid; grid-template-columns: 1fr 360px; }
.viewer-stage {
  position: relative;
  background: #0d080c;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.nav-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.nav-btn.close { top: calc(12px + env(safe-area-inset-top, 0px)); left: 12px; font-size: 26px; }
.nav-btn.prev { left: 12px; top: 50%; transform: translateY(-50%); }
.nav-btn.next { right: 12px; top: 50%; transform: translateY(-50%); }
.nav-btn:disabled { opacity: 0.25; cursor: default; }

.viewer-panel { overflow-y: auto; padding: 20px; border-left: 1px solid var(--line); }
.viewer-panel h3 { margin: 0; font-size: 17px; }
.viewer-panel .place a { color: var(--accent); text-decoration: none; }
.caption { margin: 12px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.panel-actions a.btn { text-decoration: none; }

.comments { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.comments h4 { margin: 0 0 8px; font-size: 14px; }
.comment { padding: 8px 0; }
.comment-head { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; }
.comment-head strong { color: var(--text); font-size: 13px; }
.comment-head button {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}
.comment-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.comment-form textarea { resize: none; min-height: 42px; }

@media (max-width: 820px) {
  .viewer[open] { grid-template-columns: 1fr; grid-template-rows: minmax(0, 55dvh) 1fr; }
  .viewer-panel { border-left: 0; padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: #2a1a24;
  color: #fff;
  font-size: 14px;
}
[hidden] { display: none !important; }
