:root {
  --bg: #101012;
  --panel: #17181b;
  --panel-2: #1f2023;
  --border: #2b2c30;
  --text: #f2f2f2;
  --text-dim: #86878c;
  /* Courbes Material Design 3 (m3.material.io/styles/motion/easing-and-duration) */
  --ease-standard: cubic-bezier(.2, 0, 0, 1);
  --ease-emphasized-decelerate: cubic-bezier(.05, .7, .1, 1);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.btn {
  background: var(--text);
  color: var(--bg);
  border: 1px solid var(--text);
  padding: 6px 12px;
  border-radius: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  cursor: pointer;
}
.btn:hover { background: var(--bg); color: var(--text); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover { border-color: var(--text); color: var(--text); background: transparent; }

.lock-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-btn.unlocked { border-color: var(--text); color: var(--text); }

.np-status {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ---------- mise en page générale : colonne principale + colonne latérale ---------- */

.layout {
  flex: 1;
  min-height: 0;
  display: flex;
}

.main-col {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.side-col {
  width: clamp(260px, 22vw, 380px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--panel);
}

/* ---------- tierlist (partie haute) ---------- */

.board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
}

.tier-row {
  display: flex;
  flex: 1;
  min-height: 0;
}

.tier-label {
  width: 84px;
  min-width: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: var(--panel);
}

.tier-label input.tier-name {
  background: transparent;
  border: none;
  color: inherit;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
  width: 100%;
  outline: none;
  pointer-events: none;
}
body.unlocked .tier-label input.tier-name { pointer-events: auto; }
body.unlocked .tier-label { cursor: pointer; }

.tier-row-controls {
  display: none;
  gap: 2px;
  position: absolute;
  top: 3px;
  right: 3px;
}
body.unlocked .tier-row-controls { display: flex; }
.tier-row-controls button {
  background: rgba(0,0,0,.3);
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 10px;
  padding: 2px 5px;
  line-height: 1;
}
.tier-row-controls button:hover { background: rgba(0,0,0,.55); }

.tier-cards {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 6px;
  padding: 0 8px;
  background: var(--bg);
  overflow-x: auto;
  overflow-y: hidden;
  transition: background-color .15s ease;
}
.tier-cards.drag-over {
  outline: 2px solid var(--text);
  outline-offset: -2px;
  background: var(--panel-2);
}
.tier-cards::-webkit-scrollbar { height: 4px; }
.tier-cards::-webkit-scrollbar-thumb { background: var(--border); }
.tier-cards::-webkit-scrollbar-track { background: transparent; }

/* Les covers occupent toute la hauteur de leur ligne (largeur dérivée par aspect-ratio). */
.card {
  height: 100%;
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
  position: relative;
  background: var(--panel-2);
  transition: transform .2s var(--ease-standard), box-shadow .15s ease, opacity .2s var(--ease-standard);
}
.card:hover { transform: translateY(-3px); box-shadow: 0 6px 14px rgba(0,0,0,.5); z-index: 2; }
.card:active { cursor: grabbing; }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card.dragging { opacity: .3; transform: scale(.92) rotate(-2deg); }

@keyframes cardLand {
  0% { transform: scale(.6) rotate(-6deg); opacity: 0; }
  55% { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); }
}
.card.landed { animation: cardLand .4s var(--ease-emphasized-decelerate); }

.card.preview-slot { transform: scale(.6); opacity: .8; pointer-events: none; }
.card.settling {
  transition: transform .25s var(--ease-emphasized-decelerate), opacity .25s var(--ease-emphasized-decelerate);
}

.card .card-title {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 6px 6px 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,.9), rgba(0,0,0,0));
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.empty-hint { color: var(--text-dim); font-size: 12px; text-align: center; padding: 20px; }

/* ---------- lecteur (partie basse) ---------- */

.now-playing {
  flex-shrink: 0;
  height: 30vh;
  min-height: 180px;
  display: flex;
  align-items: stretch;
  gap: 2vw;
  padding: 1.2vh 2vw;
  border-top: 1px solid var(--border);
  background: var(--panel);
  overflow: hidden;
}

.np-cover {
  aspect-ratio: 1 / 1;
  height: 100%;
  flex-shrink: 0;
  background: var(--panel-2) center/cover no-repeat;
  cursor: grab;
  transition: box-shadow .15s ease;
}
.np-cover:hover { box-shadow: 0 10px 24px rgba(0,0,0,.55); }
.np-cover:active { cursor: grabbing; }

.np-body {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2.5vh;
}

/* Fondu + scale unique lors du passage d'un morceau à l'autre (piloté en JS) */
@keyframes npSwap {
  0% { opacity: 1; transform: scale(1); }
  45%, 55% { opacity: 0; transform: scale(.92); }
  100% { opacity: 1; transform: scale(1); }
}
.np-cover.np-swap-anim,
.np-body.np-swap-anim {
  animation: npSwap .5s ease;
}

.np-meta { min-width: 0; }
.np-title {
  font-size: clamp(24px, 3.4vw, 52px);
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.np-artist {
  margin-top: .8vh;
  font-size: clamp(13px, 1.3vw, 20px);
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.np-transport {
  display: flex;
  align-items: center;
  gap: 1.5vw;
  min-width: 0;
}
.np-play {
  width: clamp(40px, 5vh, 64px);
  height: clamp(40px, 5vh, 64px);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: clamp(16px, 2vh, 24px);
  flex-shrink: 0;
  transition: border-color .15s ease, transform .1s ease;
}
.np-play:hover { border-color: var(--text); }
.np-play:active { transform: scale(.92); }
.np-play:disabled { opacity: .35; cursor: not-allowed; }

.np-progress-wrap { flex: 1; min-width: 0; }
.np-progress {
  height: 5px;
  background: var(--border);
  cursor: pointer;
  position: relative;
}
.np-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--text);
  transition: width .2s linear;
}
.np-times {
  display: flex;
  justify-content: space-between;
  margin-top: 1vh;
  font-size: clamp(11px, .9vw, 13px);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.hidden { display: none !important; }

/* Emplacements réservés pour 3 caméras (composées plus tard, ex. via OBS), en
   bas de la colonne latérale (order:2 — le chat prend le haut, order:1).
   La largeur est fixée à 100% du conteneur ; aspect-ratio dérive la hauteur
   depuis cette largeur (seule la largeur est contrainte, sinon flex+stretch
   écrasent le 16:9). Le conteneur suit donc la hauteur ainsi obtenue. */
.cam-slots {
  --cam-gap: 6px;
  order: 2;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--cam-gap);
  padding: 10px;
  border-top: 1px solid var(--border);
}
.cam-slot {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 1px dashed var(--border);
  background: rgba(31, 32, 35, .6);
  position: relative;
}
.cam-slot span {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 9px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ---------- chatbox Twitch fusionnée (IRC anonyme en JS, badge par chaîne) ---------- */

.chat-log {
  order: 1;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-log::-webkit-scrollbar { width: 5px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--border); }
.chat-log::-webkit-scrollbar-track { background: transparent; }

.chat-row {
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}
.chat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-right: 5px;
  vertical-align: middle;
  flex-shrink: 0;
}
.chat-name { font-weight: 700; margin-right: 5px; }
.chat-text { color: var(--text); }

/* --- palette de couleurs custom, légère (pas d'input[type=color] natif) --- */
.color-popover {
  position: fixed;
  z-index: 999;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px;
}
.cp-swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}
.cp-swatch {
  width: 20px;
  height: 20px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,.15);
}
.cp-swatch:hover { outline: 1px solid var(--text); }

@media (max-width: 720px) {
  .tier-label { width: 60px; min-width: 60px; }
  .now-playing {
    height: auto;
    flex-direction: column;
    padding: 12px 16px;
    gap: 10px;
  }
  .np-cover { width: 100%; height: auto; aspect-ratio: 1 / 1; }
  .np-body { gap: 10px; }
  .np-title { font-size: 18px; }
  .side-col { display: none; }
}
