:root {
  --night: #0e1124;
  --ink: #161a2e;
  --ink2: #232845;
  --dusk: #3a3556;
  --cream: #f6efe4;
  --paper: #efe4d2;
  --sand: #e2cfae;
  --gold: #e7b96a;
  --gold-deep: #c9973f;
  --r-light: #fff4dc;
  --r-main: #e7b96a;
  --r-deep: #c9973f;
  --r-darker: #7a5a22;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--night);
  color: var(--cream);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body { position: fixed; inset: 0; }

#bg { position: fixed; inset: 0; }

.stage-canvas { display: block; position: absolute; inset: 0; touch-action: none; }

/* ─── Écrans ─────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 22px calc(24px + var(--safe-bottom));
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.7s ease, visibility 0s linear 0.7s;
  overflow-y: auto;
}
.screen.active {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.7s ease, visibility 0s;
}
.screen-game, .screen-reveal { padding: 0; background: var(--night); overflow: hidden; }
#game-root, #reveal-root { position: absolute; inset: 0; }

.panel {
  width: min(100%, 440px);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.panel-wide { width: min(100%, 980px); }

.screen.active .panel > * { animation: rise 0.9s cubic-bezier(.2,.8,.2,1) both; }
.screen.active .panel > *:nth-child(2) { animation-delay: 0.08s; }
.screen.active .panel > *:nth-child(3) { animation-delay: 0.16s; }
.screen.active .panel > *:nth-child(4) { animation-delay: 0.24s; }
.screen.active .panel > *:nth-child(5) { animation-delay: 0.32s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}

.eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 500;
}
.title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.8rem, 12vw, 5rem);
  line-height: 0.98;
  letter-spacing: -0.02em;
}
.title em { font-style: italic; color: var(--gold); }
.title-sm { font-size: clamp(2rem, 8vw, 3.2rem); }
.lead { font-size: 1.05rem; line-height: 1.55; color: rgba(246, 239, 228, 0.78); }
.note { font-size: 0.85rem; color: rgba(246, 239, 228, 0.5); }

/* ─── Boutons ────────────────────────────────────────── */
.btn {
  font: inherit;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 16px 30px;
  font-weight: 500;
  font-size: 1.02rem;
  letter-spacing: 0.01em;
  transition: transform 0.2s ease, background 0.3s ease, box-shadow 0.3s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--gold);
  color: var(--ink);
  box-shadow: 0 10px 40px -10px rgba(231, 185, 106, 0.7), inset 0 1px 0 rgba(255,255,255,0.4);
  margin-top: 8px;
}
.btn-primary:hover { background: #efc47a; }
.btn-choice {
  flex: 1;
  background: rgba(246, 239, 228, 0.06);
  color: var(--cream);
  border: 1px solid rgba(246, 239, 228, 0.25);
  padding: 20px 18px;
  font-family: var(--serif);
  font-size: 1.3rem;
}
.btn-choice:hover { background: rgba(246, 239, 228, 0.12); border-color: var(--gold); }
.btn-link { background: none; color: rgba(246, 239, 228, 0.6); text-decoration: underline; text-underline-offset: 4px; padding: 8px; }
.btn-light { background: #fff; color: var(--r-darker); box-shadow: 0 10px 30px -10px rgba(0,0,0,0.35); }
.btn-ghost { background: rgba(255,255,255,0.16); color: #fff; border: 1px solid rgba(255,255,255,0.45); backdrop-filter: blur(6px); }
.choices { display: flex; gap: 12px; width: 100%; }

.icon-btn {
  position: fixed;
  z-index: 50;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(246, 239, 228, 0.25);
  background: rgba(14, 17, 36, 0.45);
  color: var(--cream);
  font-size: 1.15rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  touch-action: manipulation;
}
.sound-btn { top: calc(12px + var(--safe-top)); right: 12px; }
.sound-btn.off { opacity: 0.5; text-decoration: line-through; }
.back-btn { top: calc(12px + var(--safe-top)); left: 12px; z-index: 20; }

.rehearsal-badge {
  position: fixed;
  bottom: calc(10px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(231, 185, 106, 0.18);
  color: var(--gold);
  pointer-events: none;
}

/* ─── Cartes de jeu ──────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  margin-top: 10px;
}
.card {
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border: 1px solid rgba(246, 239, 228, 0.16);
  background: linear-gradient(160deg, rgba(246, 239, 228, 0.09), rgba(246, 239, 228, 0.02));
  border-radius: 22px;
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  transition: transform 0.25s ease, border-color 0.25s ease, background 0.25s ease;
  backdrop-filter: blur(6px);
  touch-action: manipulation;
}
.card:hover, .card:focus-visible { transform: translateY(-4px); border-color: var(--gold); outline: none; }
.card:active { transform: scale(0.98); }
.card svg { width: 72px; height: 54px; }
.card-title { font-family: var(--serif); font-size: 1.35rem; }
.card-desc { font-size: 0.92rem; line-height: 1.45; color: rgba(246, 239, 228, 0.7); }
.card-best { font-size: 0.75rem; letter-spacing: 0.08em; color: var(--cream); opacity: 0.75; }
.card-time { font-size: 0.75rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); }

@media (max-width: 760px) {
  .cards { grid-template-columns: 1fr; gap: 10px; }
  .card { grid-template-columns: 64px 1fr; grid-template-areas: 'icon title' 'icon desc' 'icon time'; padding: 14px 16px; column-gap: 14px; row-gap: 3px; }
  .card svg { grid-area: icon; width: 64px; height: 48px; align-self: center; }
  .card-title { grid-area: title; font-size: 1.15rem; }
  .card-desc { grid-area: desc; font-size: 0.85rem; }
  .card-time { grid-area: time; }
  .card-best { grid-column: 2; }
}

/* ─── Score en jeu ───────────────────────────────────── */
.score-hud {
  position: absolute;
  z-index: 20;
  top: calc(12px + var(--safe-top));
  left: 64px;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(14, 17, 36, 0.45);
  border: 1px solid rgba(246, 239, 228, 0.2);
  backdrop-filter: blur(8px);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.score-hud span { font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); }
.score-hud b { font-size: 1.05rem; font-weight: 700; }
.score-hud.bump b { animation: bump 0.35s ease; display: inline-block; }
@keyframes bump { 40% { transform: scale(1.25); color: var(--gold); } }
.card-score { font-size: 0.95rem; letter-spacing: 0.02em; }
.card-score b { font-size: 1.15rem; }
.card-score .record { display: inline-block; margin-left: 6px; padding: 2px 10px; border-radius: 999px; background: #fff; color: var(--r-darker); font-weight: 700; font-size: 0.8rem; animation: letterPop 0.8s cubic-bezier(.2, 1.6, .4, 1) both; }

/* ─── Intro de jeu ───────────────────────────────────── */
.game-intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 12, 26, 0.72);
  backdrop-filter: blur(6px);
  z-index: 10;
  transition: opacity 0.5s ease;
}
.game-intro.hide { opacity: 0; pointer-events: none; }

/* ─── Révélation ─────────────────────────────────────── */
.reveal-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  padding: calc(30px + var(--safe-top)) 20px calc(30px + var(--safe-bottom));
  z-index: 2;
}
.reveal-msg {
  position: absolute;
  bottom: calc(14% + var(--safe-bottom));
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.25rem, 5vw, 1.8rem);
  color: var(--cream);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s ease, transform 0.5s ease;
  padding: 0 24px;
}
.reveal-msg.show { opacity: 1; transform: none; }

.reveal-title {
  font-family: var(--serif);
  font-weight: 600;
  text-align: center;
  color: #fff;
  display: none;
  line-height: 0.95;
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.22), 0 1px 2px rgba(0, 0, 0, 0.12);
}
.reveal-title.show { display: block; }
.reveal-pre {
  display: block;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.6rem, 7vw, 3rem);
  opacity: 0;
  animation: fadeUp 0.8s ease 0.1s forwards;
  margin-bottom: 0.15em;
}
.reveal-word { display: block; font-size: clamp(3.6rem, 19vw, 10rem); letter-spacing: -0.02em; white-space: nowrap; }
.reveal-article {
  font-size: 0.45em;
  font-style: italic;
  font-weight: 400;
  vertical-align: 0.4em;
  opacity: 0;
  animation: fadeUp 0.8s ease 0.35s forwards;
}
.reveal-letter {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.6em) scale(0.4) rotate(-12deg);
  animation: letterPop 0.9s cubic-bezier(.2, 1.6, .4, 1) forwards;
}
@keyframes letterPop {
  60% { opacity: 1; }
  to { opacity: 1; transform: none; }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.reveal-card {
  pointer-events: auto;
  margin-top: 28px;
  max-width: 460px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.9s ease, transform 0.9s ease;
  color: #fff;
  padding: 20px 22px;
  border-radius: 26px;
  background: rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.18);
}
.reveal-card.show { opacity: 1; transform: none; }
.card-intuition { font-weight: 700; letter-spacing: 0.04em; font-size: 1.05rem; }
.card-message { font-family: var(--serif); font-style: italic; font-size: clamp(1.1rem, 4.4vw, 1.35rem); line-height: 1.45; }
.card-signature { font-size: 0.95rem; opacity: 0.85; }
.card-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }
.card-actions .btn { padding: 13px 22px; font-size: 0.95rem; }

@media (max-height: 640px) {
  .reveal-card { margin-top: 14px; gap: 8px; }
  .card-actions .btn { padding: 10px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .screen.active .panel > * { animation: none; }
}
