/* =============================================================
   MOTAMORPHOSE — socle : jetons de design, thèmes, mise en page
   ============================================================= */

:root {
  /* Palette de marque */
  --violet-950: #0d0620;
  --violet-900: #150a2e;
  --violet-800: #1b1035;
  --violet-700: #281450;
  --violet-600: #3a1d75;
  --violet-500: #5b34c9;
  --blue: #2b6cff;
  --blue-soft: #6ea1ff;
  --turquoise: #14e0c8;
  --turquoise-soft: #6fffee;
  --rose: #ff4d9d;
  --orange: #ff8a3d;
  --yellow: #ffd93d;
  --green: #35d07f;
  --red: #ff5c6c;

  /* Surfaces (thème sombre par défaut) */
  --bg: var(--violet-900);
  --bg-deep: var(--violet-950);
  --surface: rgba(255, 255, 255, 0.055);
  --surface-2: rgba(255, 255, 255, 0.09);
  --surface-3: rgba(255, 255, 255, 0.14);
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.22);
  --text: #f6f3ff;
  --text-dim: #b6a9dd;
  --text-faint: #8b7fb5;

  /* Dégradés */
  --grad-brand: linear-gradient(135deg, #8a53ff 0%, #2b6cff 48%, #14e0c8 100%);
  --grad-primary: linear-gradient(135deg, #7f46ff 0%, #2b6cff 55%, #1fd8d0 100%);
  --grad-rose: linear-gradient(135deg, #ff4d9d 0%, #ff8a3d 100%);
  --grad-tile: linear-gradient(160deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04));
  --grad-target: linear-gradient(160deg, #ffd93d, #ff8a3d);

  /* Formes et ombres */
  --radius-xl: 30px;
  --radius-lg: 24px;
  --radius: 18px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --shadow-sm: 0 4px 14px rgba(4, 2, 16, 0.35);
  --shadow: 0 14px 40px rgba(4, 2, 16, 0.45);
  --shadow-glow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 18px 50px rgba(70, 40, 200, 0.35);

  /* Typographie */
  --font: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* Mouvement */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur: 240ms;

  /* Zones de sécurité iOS */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

[data-theme="light"] {
  --bg: #f4f1ff;
  --bg-deep: #eae4ff;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-2: rgba(255, 255, 255, 0.95);
  --surface-3: #ffffff;
  --border: rgba(58, 29, 117, 0.12);
  --border-strong: rgba(58, 29, 117, 0.22);
  --text: #221440;
  --text-dim: #5a4788;
  --text-faint: #7c6aa8;
  --grad-tile: linear-gradient(160deg, #ffffff, #f0ebff);
  --shadow-sm: 0 4px 14px rgba(58, 29, 117, 0.12);
  --shadow: 0 16px 44px rgba(58, 29, 117, 0.16);
  --shadow-glow: 0 0 0 1px rgba(58, 29, 117, 0.08), 0 18px 50px rgba(90, 60, 200, 0.18);
}

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

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

/* L'attribut hidden doit toujours l'emporter sur les display des composants. */
[hidden] {
  display: none !important;
}

/* Sprite SVG inline : jamais rendu, uniquement référencé par <use>. */
.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  transition: background var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}

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

ul, ol {
  padding: 0;
  list-style: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--surface-2);
}

::selection {
  background: var(--rose);
  color: #fff;
}

/* --------------------------- Arrière-plan --------------------------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% -10%, rgba(122, 70, 255, 0.35), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  /* Flou volontairement modéré : coût GPU maîtrisé sur mobile milieu de gamme. */
  filter: blur(54px);
  opacity: 0.5;
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.blob--violet {
  width: 52vmax;
  height: 52vmax;
  top: -26vmax;
  left: -18vmax;
  background: radial-gradient(circle, rgba(138, 83, 255, 0.85), rgba(138, 83, 255, 0) 70%);
  animation: blob-drift-1 26s var(--ease-out) infinite alternate;
}

.blob--turquoise {
  width: 40vmax;
  height: 40vmax;
  bottom: -20vmax;
  right: -14vmax;
  background: radial-gradient(circle, rgba(20, 224, 200, 0.55), rgba(20, 224, 200, 0) 70%);
  animation: blob-drift-2 32s var(--ease-out) infinite alternate;
}

.blob--rose {
  width: 30vmax;
  height: 30vmax;
  top: 32%;
  right: -18vmax;
  background: radial-gradient(circle, rgba(255, 77, 157, 0.45), rgba(255, 77, 157, 0) 70%);
  animation: blob-drift-3 29s var(--ease-out) infinite alternate;
}

.grain {
  position: absolute;
  inset: 0;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

[data-theme="light"] .blob {
  opacity: 0.4;
}

[data-theme="light"] .grain {
  opacity: 0.03;
}

/* ----------------------------- Structure ---------------------------- */
.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 14px) 16px calc(var(--safe-bottom) + 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: screen-in 320ms var(--ease-out) both;
}

.screen[hidden] {
  display: none !important;
}

.screen--game,
.screen--room {
  overflow: hidden;
}

.screen__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 0 4px;
}

.screen__head h2 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  flex: 1;
}

.muted {
  color: var(--text-dim);
}

.small {
  font-size: 0.82rem;
  line-height: 1.5;
}

/* Bandeau hors ligne */
.offline-banner {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: rgba(255, 92, 108, 0.16);
  border: 1px solid rgba(255, 92, 108, 0.45);
  color: #ffd9dd;
  font-size: 0.8rem;
  font-weight: 600;
  backdrop-filter: blur(12px);
  max-width: calc(100vw - 24px);
  text-align: center;
}

.offline-banner__icon {
  display: inline-flex;
  color: var(--red);
}

.offline-banner__icon .icon {
  width: 1.05em;
  height: 1.05em;
}

.offline-banner__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(255, 92, 108, 0.2);
  flex: none;
}

/* Écran de chargement */
.loading {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  transition: opacity 420ms var(--ease-out), visibility 420ms;
}

.loading--done {
  opacity: 0;
  visibility: hidden;
}

.loading__logo {
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  font-size: 2.4rem;
  font-weight: 900;
  border-radius: 26px;
  color: #fff;
  background: var(--grad-primary);
  box-shadow: 0 18px 50px rgba(90, 60, 220, 0.5);
  animation: logo-breathe 2.2s var(--ease-out) infinite;
}

.loading__text {
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* Mode allégé (piloté par ?lite=1 ou par le réglage « réduire les animations ») */
[data-lite="true"] .blob {
  display: none;
}

[data-lite="true"] .backdrop {
  background:
    radial-gradient(120% 80% at 20% 0%, rgba(122, 70, 255, 0.28), transparent 62%),
    radial-gradient(90% 70% at 90% 100%, rgba(20, 224, 200, 0.2), transparent 65%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
}

[data-lite="true"] .panel,
[data-lite="true"] .stat-chip,
[data-lite="true"] .game__hud,
[data-lite="true"] .toast,
[data-lite="true"] .result__card,
[data-lite="true"] .pause-overlay {
  backdrop-filter: none;
}

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

[data-reduced-motion="true"] .blob,
[data-reduced-motion="true"] .grain {
  animation: none !important;
}

[data-reduced-motion="true"] * {
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
}
