/* Bagare Démineur — feuille de style unique.
   Les couleurs de joueurs viennent de /palette.css (.pc-<id> → --pc / --pct). */

:root {
  --bg: #0b0d12;
  --bg-soft: #0f1219;
  --bg-elev: #12151d;
  --bg-elev-2: #171b25;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e8ecf5;
  --muted: #8b93a7;
  --faint: #5d6478;
  --blue: #5b8cff;
  --blue-ink: #ffffff;
  --accent: #ffcf4d;
  --accent-ink: #1a1400;
  --good: #3ddc84;
  --bad: #ff5c6c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, dl, dd, ol, ul {
  margin: 0;
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 12px;
}

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-weight: 650;
  font-size: 14px;
  line-height: 1.2;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, filter 0.15s ease, transform 0.06s ease;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--blue);
  color: var(--blue-ink);
  box-shadow: 0 8px 24px rgba(91, 140, 255, 0.24);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-primary[aria-pressed="true"] {
  background: var(--good);
  color: #04150a;
  box-shadow: 0 8px 24px rgba(61, 220, 132, 0.22);
}

.btn-accent {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 24px rgba(255, 207, 77, 0.2);
}

.btn-accent:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line-strong);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 8px 10px;
  font-weight: 500;
}

.btn-quiet:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.btn-wide {
  width: 100%;
}

.btn-small {
  padding: 8px 12px;
  font-size: 13px;
}

.btn-link {
  background: none;
  border: 0;
  padding: 4px 6px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
  border-radius: 6px;
}

.btn-link:hover {
  color: var(--text);
}

.btn-link.is-danger:hover {
  color: var(--bad);
}

/* --------------------------------------------------------------------- home */

.home {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 40px 20px;
  overflow: hidden;
}

.home-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    radial-gradient(900px 600px at 50% -10%, rgba(91, 140, 255, 0.16), transparent 70%),
    radial-gradient(700px 500px at 85% 110%, rgba(255, 207, 77, 0.08), transparent 70%);
  background-size: 44px 44px, 44px 44px, 100% 100%, 100% 100%;
  mask-image: radial-gradient(circle at 50% 30%, #000 30%, transparent 85%);
}

.home-inner {
  position: relative;
  width: min(540px, 100%);
}

.home-head {
  margin-bottom: 26px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6);
  animation: pulse 2.2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(61, 220, 132, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); }
}

.home h1 {
  font-size: clamp(2.7rem, 8.5vw, 4.2rem);
  line-height: 0.94;
  letter-spacing: -0.045em;
  font-weight: 800;
}

.home h1 .accent {
  color: var(--accent);
}

.lede {
  margin-top: 16px;
  max-width: 44ch;
  color: var(--muted);
  font-size: 15.5px;
}

.card {
  background: linear-gradient(180deg, rgba(23, 27, 37, 0.92), rgba(18, 21, 29, 0.92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.muted {
  color: var(--faint);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

input[type="text"] {
  width: 100%;
  padding: 11px 13px;
  background: #0a0c11;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]::placeholder {
  color: #4d5468;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}

.sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 14px;
  color: var(--faint);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sep::before,
.sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.join-form {
  display: flex;
  gap: 8px;
}

.code-input {
  flex: 1;
  min-width: 0;
  padding: 10px 0.5em 10px 0.5em !important;
  font-family: var(--mono);
  font-size: 1.35rem !important;
  letter-spacing: 0.5em;
  text-align: center;
  color: var(--accent) !important;
}

.hint {
  margin-top: 8px;
  color: var(--faint);
  font-size: 12.5px;
}

.form-error {
  margin-top: 12px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 92, 108, 0.3);
  border-radius: 8px;
  background: rgba(255, 92, 108, 0.08);
  color: #ffb3ba;
  font-size: 13px;
}

.home-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  color: var(--faint);
  font-size: 12px;
}

/* --------------------------------------------------------------------- room */

.room {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 18, 0.82);
  backdrop-filter: blur(10px);
  flex: none;
}

.topbar > :first-child {
  justify-self: start;
}

.room-id {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: center;
}

.room-id-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.room-id-code {
  padding: 2px 9px;
  border: 1px solid rgba(255, 207, 77, 0.25);
  border-radius: 8px;
  background: rgba(255, 207, 77, 0.1);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 1.05rem;
  letter-spacing: 0.18em;
}

.me-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
  min-width: 0;
}

.me-name {
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 14px;
}

.rename-input {
  width: 14ch;
  padding: 4px 8px !important;
  font-size: 13px !important;
}

.conn {
  display: inline-flex;
  align-items: center;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

.conn.is-ok .conn-dot {
  background: var(--good);
}

.conn.is-down .conn-dot {
  background: var(--bad);
  animation: pulse-bad 1.4s infinite;
}

@keyframes pulse-bad {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.room-grid {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 350px;
  gap: 14px;
  padding: 14px;
  flex: 1;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(23, 27, 37, 0.7), rgba(15, 18, 25, 0.7));
}

.panel-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-rules {
  gap: 14px;
  overflow-y: auto;
}

.rules {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rule {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(10, 12, 17, 0.5);
}

.rule dt {
  color: var(--faint);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rule dd {
  margin-top: 2px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
}

.note {
  margin-top: auto;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.45;
}

.panel-stage {
  gap: 18px;
  overflow-y: auto;
}

.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.badge {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.seats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.seat {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 88px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-soft);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.seat.is-ready {
  border-color: color-mix(in srgb, var(--pc, var(--faint)) 40%, transparent);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--pc, var(--faint)) 10%, transparent), transparent 55%),
    var(--bg-soft);
  box-shadow: inset 3px 0 0 var(--pc, var(--faint));
}

.seat.is-empty {
  justify-content: center;
  border-style: dashed;
  border-color: var(--line-strong);
  background: transparent;
  color: var(--faint);
  font-size: 13.5px;
}

.seat-body {
  min-width: 0;
  flex: 1;
}

.seat-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 650;
  font-size: 15px;
  min-width: 0;
}

.seat-name .truncate,
.member-name .truncate {
  min-width: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12.5px;
}

.tag {
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tag.is-owner {
  background: rgba(255, 207, 77, 0.14);
  color: var(--accent);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.dot.is-on {
  background: var(--good);
}

.dot.is-off {
  background: var(--bad);
}

.dot.is-ready {
  background: var(--good);
  box-shadow: 0 0 8px rgba(61, 220, 132, 0.6);
}

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--pc, var(--faint));
  color: var(--pct, #fff);
  font-weight: 700;
  font-size: 18px;
  text-transform: uppercase;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.avatar-sm {
  width: 26px;
  height: 26px;
  font-size: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.color-block {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.block-title {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.swatch {
  position: relative;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--pc);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.swatch:hover:not(:disabled) {
  transform: translateY(-2px);
}

.swatch.is-selected {
  box-shadow:
    0 0 0 2px var(--bg-elev),
    0 0 0 4px var(--pc);
}

.swatch.is-selected::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 10px;
  height: 10px;
  margin: auto;
  border-radius: 50%;
  background: var(--pct);
}

.swatch:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.board-placeholder {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1;
  min-height: 160px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: center;
}

.board-placeholder p {
  position: relative;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(15, 18, 25, 0.82);
  color: var(--faint);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.stage-actions .btn {
  flex: 1;
  min-width: 150px;
}

/* ------------------------------------------------------------- chat / members */

.panel-side {
  padding: 0;
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--line);
  flex: none;
}

.tab {
  flex: 1;
  padding: 10px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  border-bottom-color: var(--accent);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}

.tab-count {
  display: inline-block;
  min-width: 18px;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-panel {
  padding: 12px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex: 1;
  padding: 2px 4px 10px;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
}

.msg-system {
  padding: 2px 6px;
  color: var(--faint);
  font-size: 12px;
  font-style: italic;
  text-align: center;
  line-height: 1.4;
}

.msg-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
}

.msg-name {
  color: var(--pc, var(--text));
  font-weight: 700;
}

.msg-time {
  margin-left: auto;
  color: #4d5468;
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.msg-text {
  margin-top: 1px;
  font-size: 13.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-form {
  display: flex;
  gap: 8px;
  flex: none;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px !important;
  font-size: 14px !important;
}

.members-panel {
  gap: 12px;
  padding: 12px;
  overflow-y: auto;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  list-style: none;
}

.member {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  flex-wrap: wrap;
}

.member-info {
  flex: 1;
  min-width: 0;
}

.member-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-sub {
  color: var(--faint);
  font-size: 11.5px;
}

.member-actions {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

.member-side {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ------------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(430px, calc(100% - 28px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--blue);
  border-radius: 10px;
  background: rgba(23, 27, 37, 0.97);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  font-size: 13.5px;
  animation: toast-in 0.18s ease-out;
}

.toast.is-error {
  border-left-color: var(--bad);
}

.toast.is-ok {
  border-left-color: var(--good);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1120px) {
  .room-grid {
    grid-template-columns: 215px minmax(0, 1fr) 310px;
  }
}

@media (max-width: 940px) {
  .room {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    grid-template-columns: auto 1fr auto;
  }

  .room-grid {
    grid-template-columns: minmax(0, 1fr);
    flex: none;
    padding: 12px;
  }

  .panel-stage {
    order: 1;
    overflow: visible;
  }

  .panel-side {
    order: 2;
    height: min(70vh, 560px);
  }

  .panel-rules {
    order: 3;
    overflow: visible;
  }
}

@media (max-width: 620px) {
  .home {
    padding: 28px 16px;
  }

  .seats {
    grid-template-columns: 1fr;
  }

  .seat {
    min-height: 74px;
  }

  .topbar {
    padding: 8px 8px;
    gap: 6px;
  }

  .room-id {
    gap: 6px;
  }

  .room-id-label {
    display: none;
  }

  .me-name {
    max-width: 9ch;
    font-size: 13px;
  }

  .panel-side {
    height: min(62vh, 460px);
  }
}

@media (min-width: 621px) {
  .narrow-only {
    display: none;
  }
}

@media (max-width: 620px) {
  .wide-only {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (prefers-color-scheme: light) {
  /* Le site reste sombre : c'est un choix de direction artistique. */
}
