/* ZDASH — structure : HUD en haut, scène à gauche, panneau (flux/paliers/tchat) à droite. */

.app {
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "hud   hud"
    "stage aside";
  height: 100vh;
  gap: var(--gap);
  padding: var(--gap);
}
.app.no-aside { grid-template-columns: 1fr 0; }
.app.no-aside .aside { display: none; }

/* ---------------- HUD ---------------- */

.hud {
  grid-area: hud;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hud__brand { display: flex; flex-direction: column; line-height: 1.05; flex: none; }
.hud__logo {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .12em;
  color: var(--neon);
  text-shadow: 0 0 14px rgba(180, 255, 61, .5);
}
.hud__sub { font-size: 10px; color: var(--txt-3); letter-spacing: .18em; text-transform: uppercase; }

.hud__stats { display: flex; align-items: stretch; gap: 16px; flex: 1; min-width: 0; overflow: hidden; }

.stat { display: flex; flex-direction: column; justify-content: center; gap: 3px; min-width: 0; }
.stat__label {
  font-size: 9px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--txt-3);
  white-space: nowrap;
}
.stat__value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat--hero { flex: 1 1 240px; max-width: 340px; }
.stat--hero .stat__value { font-size: 26px; color: var(--neon); letter-spacing: -.02em; }
.stat--compare { flex: 0 1 150px; }
.stat--compare .stat__value { font-size: 13px; color: var(--gold); }

.hud__actions { display: flex; align-items: center; gap: 8px; flex: none; }

.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--txt-3); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--txt-3); }
.conn.is-ok i { background: var(--neon); box-shadow: 0 0 8px var(--neon); }
.conn.is-off i { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.conn.is-stale i { background: var(--gold); box-shadow: 0 0 8px var(--gold); }

/* ---------------- Scène ---------------- */

.stage {
  grid-area: stage;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
  min-height: 0;
}

/* Le nombre de colonnes suit le nombre de players réellement montés (--cols,
   posé par main.js) : sélectionner 2 chaînes en disposition 4 ne doit pas laisser
   deux cases vides et deux players riquiqui. */
.grid {
  display: grid;
  gap: var(--gap);
  flex: 1;
  min-height: 0;
  grid-template-columns: repeat(var(--cols, 2), 1fr);
  grid-auto-rows: 1fr;
}
.grid:empty { display: none; }

/* Un player = une iframe créée une seule fois puis déplacée en CSS.
   La recréer rechargerait le flux à chaque changement de disposition. */
.player {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
  display: flex;
}
.player.is-focus { border-color: var(--neon); box-shadow: 0 0 0 1px var(--neon), var(--glow); }
.player.with-chat .player__video { width: 68%; }
.player__video { position: relative; flex: 1; min-width: 0; }
.player__video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player__chat { width: 32%; border-left: 1px solid var(--line); background: #0a0a12; }
.player__chat iframe { width: 100%; height: 100%; border: 0; display: block; }

.player__bar {
  position: absolute;
  left: 0; right: 0; top: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: linear-gradient(180deg, rgba(6, 6, 14, .92), rgba(6, 6, 14, 0));
  z-index: 3;
  opacity: 0;
  transition: opacity .18s;
  pointer-events: none;
}
.player:hover .player__bar, .player.is-focus .player__bar { opacity: 1; pointer-events: auto; }
.player__name { font-weight: 700; font-size: 13px; }
.player__meta { font-size: 11px; color: var(--txt-2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player__spacer { flex: 1; }
.player__btn {
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(10, 10, 20, .7);
  border-radius: 6px;
  padding: 3px 7px;
  cursor: pointer;
  font-size: 11px;
  color: var(--txt);
}
.player__btn:hover { border-color: var(--neon); color: var(--neon); }
.player__btn.is-on { border-color: var(--neon); color: var(--neon); }

/* Bandeau de célébration quand un palier tombe sur ce streamer. */
.player__pop {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 4;
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(8, 8, 16, .86);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  animation: pop .6s cubic-bezier(.22, 1, .36, 1);
}

/* ---------------- Écran vide ---------------- */

.empty { flex: 1; display: grid; place-items: center; }
.empty__card {
  max-width: 520px;
  text-align: center;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.empty__card h1 { font-size: 24px; margin-bottom: 10px; color: var(--neon); }
.empty__card p { color: var(--txt-2); line-height: 1.6; margin: 0 0 20px; }
.empty__hint { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }

/* ---------------- Cartes streamers ---------------- */

.cards {
  display: flex;
  gap: var(--gap);
  overflow-x: auto;
  padding-bottom: 2px;
  flex: none;
}
.cards:empty { display: none; }

.card {
  flex: 0 0 236px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  cursor: pointer;
  transition: border-color .15s;
}
.card:hover { border-color: #3d3d63; }
.card.is-focus { border-color: var(--neon); }
.card__top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card__name { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card__sub { font-size: 10px; color: var(--txt-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card__raised { margin-left: auto; font-weight: 800; font-size: 13px; color: var(--neon); font-variant-numeric: tabular-nums; }
.card__goal { font-size: 11px; color: var(--txt-2); line-height: 1.35; min-height: 30px; }
.card__goal b { color: var(--gold); }
.card__foot { display: flex; justify-content: space-between; font-size: 10px; color: var(--txt-3); }

/* ---------------- Panneau latéral ---------------- */

.aside {
  grid-area: aside;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 0;
}

.tabs { display: flex; gap: 4px; flex: none; }
.tabs__btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--txt-2);
  border-radius: var(--radius-sm);
  padding: 7px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
}
.tabs__btn.is-on { color: var(--neon); border-color: #33335a; background: var(--panel-2); }

.pane {
  flex: 1 1 45%;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.pane__head {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--txt-2); cursor: pointer; }
.switch input { accent-color: var(--neon); }

/* ---------------- Flux ---------------- */

.feed { flex: 1; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 5px; }
.ev {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 7px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--line);
  border-radius: var(--radius-sm);
  animation: slidein .3s ease-out;
}
.ev--donation { border-left-color: var(--neon-2); }
.ev--goal_reached { border-left-color: var(--gold); background: rgba(255, 204, 51, .07); }
.ev--global_milestone { border-left-color: var(--gold); background: rgba(255, 204, 51, .12); }
.ev--goal_close { border-left-color: var(--gold); }
.ev--online { border-left-color: var(--neon-3); }
.ev--duel, .ev--pace, .ev--spotlight { border-left-color: #3a3a5e; }
.ev.is-mine { box-shadow: inset 2px 0 0 var(--neon); }
.ev__body { min-width: 0; flex: 1; }
.ev__line { font-size: 12px; line-height: 1.4; }
.ev__line b { font-weight: 700; }
.ev__gain { color: var(--neon-2); font-weight: 800; font-variant-numeric: tabular-nums; }
.ev__amount { color: var(--gold); font-weight: 800; font-variant-numeric: tabular-nums; }
.ev__meta { font-size: 10px; color: var(--txt-3); margin-top: 2px; display: flex; gap: 6px; }
.ev__act { color: var(--txt-2); font-size: 11px; margin-top: 3px; line-height: 1.35; }

/* ---------------- Paliers ---------------- */

.goals { flex: 1; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.goal {
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}
.goal__top { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.goal__who { font-size: 12px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goal__amount { margin-left: auto; font-size: 12px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.goal__action { font-size: 11px; color: var(--txt-2); line-height: 1.4; margin-bottom: 6px; }
.goal__foot { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--txt-3); margin-top: 5px; }
.goal__link { color: var(--neon-3); text-decoration: none; }
.goal__link:hover { text-decoration: underline; }
.empty-note { padding: 18px 12px; text-align: center; color: var(--txt-3); font-size: 12px; line-height: 1.5; }

/* ---------------- Tchat ---------------- */

.chat {
  flex: 1 1 55%;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line-soft);
  flex: none;
}
.chat__title { font-weight: 700; font-size: 12px; }
.chat__presence {
  margin-left: auto;
  font-size: 10px;
  color: var(--neon);
  background: rgba(180, 255, 61, .1);
  border-radius: 20px;
  padding: 2px 8px;
  font-variant-numeric: tabular-nums;
}
.chat__mod { background: none; border: 0; cursor: pointer; opacity: .5; font-size: 13px; }
.chat__mod:hover { opacity: 1; }
.chat__mods { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line-soft); }
.chat__mods input {
  flex: 1;
  min-width: 120px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
}
.chat__mods-actions { display: flex; gap: 6px; width: 100%; }

.chat__list { flex: 1; overflow-y: auto; padding: 6px 8px; display: flex; flex-direction: column; gap: 3px; }
.msg { font-size: 12.5px; line-height: 1.45; word-wrap: break-word; }
.msg__nick { font-weight: 700; }
.msg__time { color: var(--txt-3); font-size: 10px; margin-right: 4px; font-variant-numeric: tabular-nums; }
.msg__del {
  border: 0;
  background: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 10px;
  opacity: 0;
  padding: 0 3px;
}
.msg:hover .msg__del { opacity: .8; }
.msg--sys { color: var(--txt-3); font-style: italic; font-size: 11px; }

.chat__form { display: flex; gap: 5px; padding: 7px; border-top: 1px solid var(--line-soft); flex: none; }
.chat__nick { width: 84px; flex: none; }
.chat__input { flex: 1; min-width: 0; }
.chat__form input {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
}
.chat__form input:focus { outline: none; border-color: #3d3d63; }
.chat__notice { font-size: 11px; color: var(--gold); padding: 0 9px 7px; min-height: 0; }
.chat__notice:empty { display: none; }

/* ---------------- Modale de sélection ---------------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 10, .78);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 24px;
}
.modal__box {
  width: min(920px, 100%);
  max-height: min(760px, 90vh);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal__head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.modal__head h2 { font-size: 15px; flex: none; }
.modal__search {
  flex: 1;
  min-width: 160px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.modal__search:focus { outline: none; border-color: var(--neon); }
.modal__close { background: none; border: 0; color: var(--txt-2); font-size: 16px; cursor: pointer; }
.modal__close:hover { color: var(--txt); }

.modal__selection { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); min-height: 46px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 11px;
  cursor: grab;
}
.chip.is-drag { opacity: .4; }
.chip button { border: 0; background: none; color: var(--txt-3); cursor: pointer; font-size: 12px; padding: 0; }
.chip button:hover { color: var(--danger); }
.chip__hint { color: var(--txt-3); font-size: 11px; align-self: center; }

.picker { flex: 1; overflow-y: auto; padding: 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 6px; align-content: start; }
.pick {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  min-width: 0;
}
.pick:hover { border-color: #3d3d63; }
.pick.is-on { border-color: var(--neon); background: rgba(180, 255, 61, .07); }
.pick__body { min-width: 0; flex: 1; }
.pick__name { font-size: 12.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick__meta { font-size: 10px; color: var(--txt-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick__raised { font-size: 11px; font-weight: 700; color: var(--neon); font-variant-numeric: tabular-nums; flex: none; }
.pick__dot { width: 7px; height: 7px; border-radius: 50%; background: #33334f; flex: none; }
.pick__dot.is-live { background: var(--neon-2); box-shadow: 0 0 7px var(--neon-2); }

.modal__foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line-soft); font-size: 11px; color: var(--txt-3); }

/* ---------------- Toasts & flash ---------------- */

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 7px; z-index: 200; pointer-events: none; }
.toast {
  padding: 9px 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--neon);
  border-radius: var(--radius-sm);
  font-size: 12px;
  box-shadow: var(--shadow);
  animation: slidein .3s ease-out;
  max-width: 320px;
}
.toast--gold { border-left-color: var(--gold); color: var(--gold); }

.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 150;
  opacity: 0;
  background: radial-gradient(circle at 50% 45%, rgba(255, 204, 51, .28), transparent 62%);
  transition: opacity .5s;
}
.flash.is-on { opacity: 1; transition: opacity .12s; }

.confetto {
  position: fixed;
  width: 8px;
  height: 12px;
  z-index: 160;
  pointer-events: none;
  animation: fall 1.5s cubic-bezier(.2, .6, .4, 1) forwards;
}
@keyframes fall {
  to { transform: translate(var(--dx), 100vh) rotate(var(--rot)); opacity: 0; }
}

/* ---------------- Responsive ---------------- */

@media (max-width: 1180px) {
  .app { grid-template-columns: 1fr 300px; }
  .stat--compare { display: none; }
}
@media (max-width: 900px) {
  html, body { overflow: auto; }
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "hud" "stage" "aside";
    height: auto;
  }
  .hud { flex-wrap: wrap; }
  .grid { grid-template-columns: 1fr !important; }
  .aside { height: 70vh; }
}
