/* =============================================================
   MOTAMORPHOSE — composants réutilisables
   ============================================================= */

/* ------------------------------ Boutons ----------------------------- */
.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: inline-block;
  vertical-align: middle;
}

.icon--sm {
  width: 0.95em;
  height: 0.95em;
}

.icon--lg {
  width: 1.45em;
  height: 1.45em;
}

.btn__icon .icon {
  width: 1.05em;
  height: 1.05em;
}

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 160ms var(--ease-spring), box-shadow 200ms var(--ease-out),
    background 200ms var(--ease-out), opacity 200ms;
  overflow: hidden;
  isolation: isolate;
  min-height: 48px;
}

.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 60%);
  opacity: 0.6;
  pointer-events: none;
  z-index: -1;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn:active {
  transform: scale(0.975);
  box-shadow: var(--shadow-sm);
}

.btn:focus-visible {
  outline: 2px solid var(--turquoise);
  outline-offset: 3px;
}

.btn[disabled] {
  opacity: 0.45;
  pointer-events: none;
  filter: saturate(0.6);
}

.btn__icon {
  font-size: 1.15rem;
  line-height: 1;
  display: inline-grid;
  place-items: center;
  width: 1.4em;
  height: 1.4em;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.16);
  flex: none;
}

.btn__label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  line-height: 1.15;
}

.btn__label small {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.72;
  letter-spacing: 0.01em;
}

.btn--primary {
  --btn-bg: var(--grad-primary);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 14px 34px rgba(64, 46, 220, 0.42);
}

.btn--primary .btn__icon {
  background: rgba(255, 255, 255, 0.22);
}

.btn--soft {
  --btn-bg: var(--surface-2);
  color: var(--text);
}

.btn--ghost {
  --btn-bg: transparent;
  border-color: var(--border);
  color: var(--text-dim);
  box-shadow: none;
}

.btn--ghost:hover {
  color: var(--text);
  background: var(--surface);
}

.btn--daily {
  --btn-bg: linear-gradient(135deg, rgba(255, 217, 61, 0.22), rgba(255, 138, 61, 0.22));
  border-color: rgba(255, 200, 80, 0.4);
  color: #ffe6a8;
}

.btn--multi {
  --btn-bg: linear-gradient(135deg, rgba(43, 108, 255, 0.26), rgba(20, 224, 200, 0.2));
  border-color: rgba(90, 160, 255, 0.4);
  color: #cfe4ff;
}

.btn--free {
  --btn-bg: linear-gradient(135deg, rgba(255, 77, 157, 0.24), rgba(138, 83, 255, 0.24));
  border-color: rgba(255, 120, 180, 0.38);
  color: #ffd5e7;
}

.btn--chrono {
  --btn-bg: linear-gradient(135deg, rgba(20, 224, 200, 0.22), rgba(43, 108, 255, 0.2));
  border-color: rgba(20, 224, 200, 0.36);
  color: #c6fff6;
}

.btn--xl {
  padding: 18px 22px;
  border-radius: var(--radius-lg);
  font-size: 1.1rem;
  min-height: 76px;
  width: 100%;
}

.btn--xl .btn__icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 1.2rem;
}

.btn--xl .btn__label {
  gap: 4px;
}

.btn--xl .btn__label small {
  font-size: 0.76rem;
}

.btn--sm {
  padding: 8px 14px;
  min-height: 40px;
  font-size: 0.84rem;
  border-radius: var(--radius-sm);
}

.btn--block {
  width: 100%;
}

.btn--flex {
  flex: 1;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 1.15rem;
  color: var(--text);
  transition: transform 160ms var(--ease-spring), background 180ms;
}

.icon-btn:hover {
  background: var(--surface-3);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* ------------------------------ Badges ------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--grad-primary);
  color: #fff;
  white-space: nowrap;
}

.badge--soft {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 700;
}

.badge--live {
  background: rgba(53, 208, 127, 0.18);
  border: 1px solid rgba(53, 208, 127, 0.4);
  color: #9dffc7;
}

/* ------------------------------ Panneaux ---------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.panel__title {
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ------------------------------ Champs ------------------------------ */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field--row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
}

.field__label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-dim);
}

.field__input {
  width: 100%;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  transition: border-color 180ms, box-shadow 180ms, background 180ms;
  min-height: 48px;
}

.field__input::placeholder {
  color: var(--text-faint);
  font-weight: 500;
}

.field__input:focus {
  outline: none;
  border-color: rgba(20, 224, 200, 0.6);
  box-shadow: 0 0 0 4px rgba(20, 224, 200, 0.14);
  background: var(--surface-3);
}

.field__input--code {
  text-align: center;
  letter-spacing: 0.35em;
  font-family: var(--font-mono);
  font-size: 1.25rem;
  text-transform: uppercase;
}

.field__input--select {
  width: auto;
  min-width: 140px;
  padding-right: 34px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23b6a9dd' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.form-error {
  color: #ffb3bd;
  font-size: 0.84rem;
  font-weight: 600;
  background: rgba(255, 92, 108, 0.12);
  border: 1px solid rgba(255, 92, 108, 0.3);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

/* Interrupteur */
.switch {
  appearance: none;
  width: 50px;
  height: 30px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  transition: background 200ms var(--ease-out);
  flex: none;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform 220ms var(--ease-spring);
}

.switch:checked {
  background: var(--grad-primary);
}

.switch:checked::after {
  transform: translateX(20px);
}

/* Curseur */
.range {
  appearance: none;
  width: 140px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  outline: none;
}

.range::-webkit-slider-thumb {
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--blue);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--blue);
  cursor: pointer;
}

/* ------------------------------ Toasts ------------------------------ */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 20px);
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: rgba(20, 12, 40, 0.92);
  border: 1px solid var(--border-strong);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  animation: toast-in 260ms var(--ease-out) both;
  display: flex;
  gap: 10px;
  align-items: center;
}

.toast--error {
  background: rgba(70, 12, 26, 0.94);
  border-color: rgba(255, 92, 108, 0.5);
}

.toast--success {
  background: rgba(8, 54, 38, 0.94);
  border-color: rgba(53, 208, 127, 0.5);
}

.toast--info {
  background: rgba(14, 22, 60, 0.94);
  border-color: rgba(43, 108, 255, 0.5);
}

.toast--leaving {
  animation: toast-out 220ms var(--ease-out) both;
}

/* ------------------------------ Modale ------------------------------ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 2, 18, 0.72);
  backdrop-filter: blur(6px);
  animation: fade-in 200ms both;
}

.modal__card {
  position: relative;
  width: min(440px, 100%);
  background: linear-gradient(180deg, var(--violet-700), var(--violet-800));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 22px;
  box-shadow: var(--shadow);
  animation: modal-in 280ms var(--ease-spring) both;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

[data-theme="light"] .modal__card {
  background: linear-gradient(180deg, #ffffff, #f1ecff);
}

.modal__title {
  font-size: 1.1rem;
  font-weight: 800;
}

.modal__body {
  font-size: 0.92rem;
  color: var(--text-dim);
  line-height: 1.55;
}

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

.modal__actions .btn {
  flex: 1;
}

/* ------------------------------ Divers ------------------------------ */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 13px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-dim);
  transition: transform 160ms var(--ease-spring), color 160ms, border-color 160ms;
}

.chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.chip--active {
  background: var(--grad-primary);
  color: #fff;
  border-color: transparent;
}

.stars {
  display: flex;
  gap: 8px;
  justify-content: center;
  font-size: 2rem;
  line-height: 1;
}

.stars__item {
  color: rgba(255, 255, 255, 0.16);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
  transform: scale(0.6);
  animation: star-pop 520ms var(--ease-spring) forwards;
}

.stars__item--on {
  color: var(--yellow);
  text-shadow: 0 0 22px rgba(255, 217, 61, 0.6);
}

.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  counter-reset: rank;
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.88rem;
  font-weight: 600;
}

.leaderboard li::before {
  counter-increment: rank;
  content: counter(rank);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-faint);
  width: 18px;
}

.leaderboard li b {
  margin-left: auto;
  font-weight: 800;
  color: var(--turquoise);
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background 200ms, border-color 200ms;
}

.player--me {
  border-color: rgba(20, 224, 200, 0.45);
  background: rgba(20, 224, 200, 0.08);
}

.player--host .player__name::after {
  content: "hôte";
  margin-left: 8px;
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 217, 61, 0.2);
  color: var(--yellow);
}

.player__avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: #fff;
  flex: none;
  font-size: 0.95rem;
}

.player__name {
  font-weight: 700;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player__status {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 6px;
}

.player__status--ready {
  color: var(--green);
}

.player__status--playing {
  color: var(--turquoise);
}

.player__status--done {
  color: var(--yellow);
}

.player__status--offline {
  color: var(--red);
}

.player__progress {
  width: 60px;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
  flex: none;
}

.player__progress span {
  display: block;
  height: 100%;
  background: var(--grad-primary);
  border-radius: 3px;
  transition: width 420ms var(--ease-out);
}

/* ------------------- Variantes de boutons en thème clair ----------------- */
[data-theme="light"] .btn--daily {
  --btn-bg: linear-gradient(135deg, rgba(255, 205, 60, 0.45), rgba(255, 160, 80, 0.32));
  border-color: rgba(190, 130, 0, 0.32);
  color: #7a4a00;
}

[data-theme="light"] .btn--multi {
  --btn-bg: linear-gradient(135deg, rgba(43, 108, 255, 0.2), rgba(20, 200, 190, 0.18));
  border-color: rgba(30, 90, 210, 0.3);
  color: #133a86;
}

[data-theme="light"] .btn--free {
  --btn-bg: linear-gradient(135deg, rgba(255, 77, 157, 0.2), rgba(138, 83, 255, 0.18));
  border-color: rgba(180, 50, 120, 0.28);
  color: #7d1f52;
}

[data-theme="light"] .btn--chrono {
  --btn-bg: linear-gradient(135deg, rgba(20, 200, 190, 0.22), rgba(43, 108, 255, 0.16));
  border-color: rgba(10, 130, 125, 0.3);
  color: #0a5f59;
}

[data-theme="light"] .btn__icon {
  background: rgba(255, 255, 255, 0.55);
}

[data-theme="light"] .btn--primary .btn__icon,
[data-theme="light"] .btn--xl .btn__icon {
  background: rgba(255, 255, 255, 0.28);
}

[data-theme="light"] .link-install {
  color: #0a7a70;
}

[data-theme="light"] .tile {
  box-shadow: inset 0 1px 0 #fff, 0 4px 12px rgba(58, 29, 117, 0.12);
}

[data-theme="light"] .tile--changed {
  color: #073f3c;
  background: linear-gradient(160deg, rgba(20, 224, 200, 0.45), rgba(43, 108, 255, 0.28));
}

[data-theme="light"] .tile--target,
[data-theme="light"] .chain-row--ghost .tile {
  color: #6a3a00;
}

[data-theme="light"] .key {
  background: #ffffff;
  color: #2a1850;
  box-shadow: inset 0 -2px 0 rgba(58, 29, 117, 0.14), 0 2px 6px rgba(58, 29, 117, 0.08);
}

[data-theme="light"] .chain-row--ghost {
  opacity: 0.6;
}

[data-theme="light"] .offline-banner {
  background: rgba(255, 235, 238, 0.95);
  color: #8c1b28;
}

[data-theme="light"] .toast {
  background: rgba(255, 255, 255, 0.97);
  color: #221440;
  border-color: rgba(58, 29, 117, 0.14);
}

[data-theme="light"] .toast--error { color: #8c1b28; }
[data-theme="light"] .toast--success { color: #105c39; }
[data-theme="light"] .toast--info { color: #133a86; }
