:root {
  --bg: #101010;
  --panel: #1a1a17;
  --panel-2: #2a2a26;
  --line: #3a3a35;
  --text: #ececec;
  --muted: #9a9a94;
  --tile: 100px;
  --gold: #c8aa6e;
  --gold-light: #f0e6d2;
  --danger: #ef5350;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, textarea { font: inherit; color: inherit; }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: rgba(16, 16, 16, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--gold-light); }
.brand img { border-radius: 50%; }
.presence { display: flex; flex: 1; min-width: 0; padding-left: 8px; }
.presence .who {
  width: 32px; height: 32px; margin-left: -6px;
  border-radius: 50%; border: 2px solid var(--bg);
  background: var(--panel-2) center/cover;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}
.top-actions { display: flex; gap: 8px; }

.btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--gold); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a1408; font-weight: 700; }
.btn.primary:hover { background: var(--gold-light); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 14px; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 20px 80px; }

.banner {
  margin-bottom: 16px; padding: 14px 16px;
  border: 1px solid var(--gold); border-radius: 10px;
  background: rgba(200, 170, 110, 0.1);
}
.banner a { color: var(--gold-light); font-weight: 700; }
.banner img { display: block; max-width: 100%; margin-top: 12px; border-radius: 8px; }

.title-input, .desc-input {
  display: block; width: 100%;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; padding: 6px 10px; margin-left: -10px;
}
.title-input { font-size: 30px; font-weight: 800; color: var(--gold-light); }
.desc-input { color: var(--muted); resize: vertical; margin-bottom: 14px; }
.title-input:hover, .desc-input:hover, .title-input:focus, .desc-input:focus {
  border-color: var(--line); background: var(--panel); outline: none;
}
.title-input:read-only, .desc-input:read-only { border-color: transparent; background: transparent; }

/* Style TierMaker : libellé coloré, vignettes carrées collées. */
.tiers { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; background: #000; border: 2px solid #000; }
.tier { display: flex; min-height: var(--tile); background: var(--panel); }
.tier-label {
  flex: 0 0 140px;
  display: grid; place-items: center;
  padding: 6px; border: 0; border-right: 2px solid #000;
  color: #333; font-size: 22px; font-weight: 400;
  text-align: center; overflow-wrap: anywhere; line-height: 1.15;
  cursor: pointer;
}
.tier-label.long { font-size: 16px; }
.tier-label:disabled { cursor: default; }
.tier-items { flex: 1; display: flex; flex-wrap: wrap; align-content: flex-start; min-width: 0; }

.pool-section { margin-top: 26px; }
.pool-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.pool-head h2 { margin: 0; font-size: 18px; }
.count { color: var(--muted); font-weight: 400; }
.pool-actions { display: flex; gap: 8px; }
.pool {
  display: flex; flex-wrap: wrap; align-content: flex-start;
  min-height: calc(var(--tile) + 4px);
  background: var(--panel); border: 2px dashed var(--line);
}
.pool:empty::before { content: "Ajoutez des membres du serveur ou d'autres éléments pour commencer."; color: var(--muted); padding: 38px 14px; }
.hint { color: var(--muted); font-size: 13px; }

.item {
  width: var(--tile); height: var(--tile);
  background: var(--panel-2) center/cover;
  cursor: grab; user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.item:hover { filter: brightness(1.15); }
.readonly .item { cursor: default; touch-action: auto; }
.readonly .item:hover { filter: none; }
.item.noimg {
  display: grid; place-items: center; padding: 6px;
  color: #fff; font-size: 14px; font-weight: 700; line-height: 1.15;
  text-align: center; overflow: hidden; overflow-wrap: anywhere;
}
.item.noimg span { pointer-events: none; max-height: 100%; overflow: hidden; }
.item.drag-source { opacity: 0.25; }
.item.ghost {
  position: fixed; z-index: 100; margin: 0;
  pointer-events: none; opacity: 0.95;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  transform: rotate(3deg);
}
.placeholder { width: var(--tile); height: var(--tile); border: 2px dashed var(--gold); }
.dropzone.over { background-color: #24241f; }

.message { max-width: 460px; margin: 18vh auto; padding: 0 20px; text-align: center; color: var(--muted); }
.message h1 { color: var(--gold-light); }
.message img { border-radius: 50%; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, 0.6);
}
.modal {
  width: min(520px, 100%); max-height: 86vh;
  display: flex; flex-direction: column; gap: 14px;
  padding: 20px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel);
}
.modal.wide { width: min(1100px, 100%); }
.modal h3 { margin: 0; font-size: 19px; color: var(--gold-light); }
.modal p { margin: 0; color: var(--muted); }
.modal .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.modal .end { justify-content: flex-end; }
.modal img.preview { max-width: 100%; border-radius: 8px; }
.modal .scroll { overflow: auto; min-height: 0; }
.field {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.field:focus { outline: none; border-color: var(--gold); }

.member-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.member {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); cursor: pointer; text-align: left;
}
.member .pic { flex: 0 0 34px; height: 34px; border-radius: 50%; background: var(--panel-2) center/cover; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.member .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member.selected { border-color: var(--gold); background: rgba(200, 170, 110, 0.14); }
.member:disabled { opacity: 0.4; cursor: default; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 32px; height: 32px; border-radius: 8px; border: 2px solid transparent; cursor: pointer; }
.swatch.selected { border-color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 200; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 8px;
  background: var(--danger); color: #fff; font-weight: 600;
  max-width: calc(100vw - 32px);
}

@media (max-width: 640px) {
  :root { --tile: 64px; }
  .top { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .brand span { display: none; }
  main { padding: 14px 12px 60px; }
  .title-input { font-size: 22px; }
  .tier-label { flex-basis: 84px; font-size: 16px; }
  .tier-label.long { font-size: 12px; }
  .item.noimg { font-size: 11px; padding: 3px; }
}
