:root {
  --bg: #f6f5f2;
  --surface: #fff;
  --text: #1c1b19;
  --muted: #6f6c66;
  --line: #e3e0da;
  --accent: #1c1b19;
  --accent-text: #fff;
  --danger: #c0392b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #222220;
    --text: #f0eee9;
    --muted: #a19e97;
    --line: #34332f;
    --accent: #f0eee9;
    --accent-text: #161615;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}
body.no-scroll { overflow: hidden; }
[hidden] { display: none !important; }
small { color: var(--muted); font-weight: normal; }

/* ---------- Boutons et liens */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: transform .1s, opacity .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { opacity: .88; border-color: var(--accent); }
.btn-lg { height: 52px; padding: 0 28px; font-size: 17px; }
.link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.hint { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Menu « Mes moodboards » */
ul.recent { margin: 16px 0 8px; padding: 0; list-style: none; border-top: 1px solid var(--line); max-height: 50vh; overflow: auto; }
.recent li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.recent li a { flex: 1; min-width: 0; color: inherit; font-weight: 500; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent li a:hover { text-decoration: underline; }
.recent li .link { color: var(--muted); font-size: 13px; }

.foot { padding: 24px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- Barre du moodboard */
.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo {
  padding: 6px 8px;
  margin-left: -8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.logo:hover { color: var(--text); background: var(--line); }
.logo span { font-size: 11px; }
.title-input, .title-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.title-input {
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-family: inherit;
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; border-color: var(--muted); background: var(--surface); }
.actions { display: flex; gap: 8px; }

body.mode-view .edit-only,
body.mode-edit .view-only,
body.loading .edit-only,
body.loading .view-only,
body.fatal .bar > :not(.logo) { display: none !important; }
body.fatal .title-text { display: none; }

main { flex: 1; width: 100%; padding: 20px; }
.status { color: var(--muted); text-align: center; margin: 0; }
body.fatal .status { margin: 20vh 0 20px; font-size: 18px; color: var(--text); }
body.fatal main { text-align: center; }
body.loading .status::before { content: "Chargement…"; }

/* ---------- Grille */
.grid { position: relative; width: 100%; }
.item {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  overflow: hidden;
  border-radius: 6px;
  background: var(--line);
  cursor: zoom-in;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .22s cubic-bezier(.2, .7, .3, 1), width .22s, height .22s, box-shadow .15s;
  will-change: transform;
}
.item.fresh { transition: none; }
body.mode-edit .item { cursor: grab; }
.item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.item.dragging {
  z-index: 10;
  cursor: grabbing;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .28);
  transition: width .22s, height .22s, box-shadow .15s;
  opacity: .95;
}
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }
.slot {
  position: absolute;
  top: 0;
  left: 0;
  border: 2px dashed var(--muted);
  border-radius: 6px;
  opacity: .5;
  transition: transform .22s cubic-bezier(.2, .7, .3, 1), width .22s, height .22s;
}
.item.uploading img { opacity: .45; filter: grayscale(.4); }
.item.uploading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 3px solid rgba(255, 255, 255, .5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 20px;
  line-height: 30px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.item:hover .del, .item:focus-within .del { opacity: 1; }
.del:hover { background: var(--danger); }
.item.uploading .del, .item.dragging .del { display: none; }
@media (hover: none) { .del { opacity: .8; width: 24px; height: 24px; line-height: 24px; font-size: 16px; top: 4px; right: 4px; } }

/* ---------- État vide et dépôt */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  border: 2px dashed var(--line);
  border-radius: 16px;
  text-align: center;
  padding: 24px;
}
.empty-title { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  border: 4px dashed var(--accent);
  pointer-events: none;
}
.drop-overlay p { font-size: 28px; font-weight: 600; }

/* ---------- Fenêtre de partage */
.modal {
  width: min(560px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}
.modal::backdrop { background: rgba(0, 0, 0, .45); }
.modal h2 { margin: 0 0 16px; font-size: 20px; }
.field { display: block; margin-bottom: 16px; font-weight: 500; }
.copy-row { display: flex; gap: 8px; margin-top: 6px; }
.copy-row input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 14px ui-monospace, Menlo, monospace;
}
.modal-actions { display: flex; justify-content: flex-end; margin-top: 8px; }

/* ---------- Agrandissement */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 10, .94);
}
.lightbox img { max-width: calc(100vw - 120px); max-height: calc(100vh - 48px); object-fit: contain; border-radius: 4px; }
.lightbox button {
  position: absolute;
  border: 0;
  background: none;
  color: #fff;
  font-size: 44px;
  line-height: 1;
  cursor: pointer;
  opacity: .7;
  padding: 12px 16px;
}
.lightbox button:hover { opacity: 1; }
.lb-close { top: 8px; right: 8px; }
.lb-prev { left: 4px; }
.lb-next { right: 4px; }
@media (max-width: 600px) {
  .lightbox img { max-width: 100vw; }
  .lb-prev, .lb-next { bottom: 16px; }
}

/* ---------- Message temporaire */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 70;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}

/* ---------- Mobile */
@media (max-width: 600px) {
  .bar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .title-input, .title-text { order: 3; flex-basis: 100%; font-size: 18px; }
  .actions { margin-left: auto; }
  .actions .btn { height: 34px; padding: 0 12px; font-size: 14px; }
  main { padding: 12px; }
}

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