:root {
  --gold: #d4af37;
  --gold-bright: #f5d76e;
  --wood: #3a2417;
  --wood-dark: #241209;
  --parchment: #f3e5c0;
  --ink: #1a0f2e;
  --danger: #e74c3c;
}

* { box-sizing: border-box; }

html, body, #root {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #0d0716;
  overflow: hidden;
  font-family: "Georgia", "Iowan Old Style", "Palatino Linotype", serif;
  color: var(--parchment);
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#game-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

#game-container canvas { display: block; }

#hud {
  position: absolute;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#hud > * { pointer-events: auto; }

/* ===== TOP BAR (Bloc Jauges) ===== */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto repeat(4, 1fr);
  gap: 8px;
  padding: 10px 12px 12px;
  background: linear-gradient(180deg, rgba(13, 7, 22, 0.95) 0%, rgba(13, 7, 22, 0.75) 70%, rgba(13, 7, 22, 0) 100%);
  border-bottom: 1px solid rgba(212, 175, 55, 0.25);
  pointer-events: auto;
}

.gauge {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(58, 36, 23, 0.55);
  border: 1px solid rgba(212, 175, 55, 0.28);
  box-shadow: inset 0 1px 0 rgba(245, 215, 110, 0.12);
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.gauge.critical {
  animation: gauge-pulse 0.9s ease-in-out infinite;
  border-color: rgba(231, 76, 60, 0.7);
}

@keyframes gauge-pulse {
  0%, 100% { box-shadow: 0 0 0 rgba(231, 76, 60, 0); }
  50% { box-shadow: 0 0 14px rgba(231, 76, 60, 0.65); }
}

.gauge-head {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  line-height: 1;
}

.gauge-icon { font-size: 14px; }
.gauge-label { flex: 1; letter-spacing: 0.02em; color: var(--parchment); }
.gauge-value { font-variant-numeric: tabular-nums; color: var(--gold-bright); font-weight: 700; font-size: 12px; }

.gauge-track {
  height: 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.5);
}

.gauge-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.18);
}

.gauge-alert {
  position: absolute;
  top: -6px;
  right: -4px;
  font-size: 13px;
  filter: drop-shadow(0 0 4px rgba(231, 76, 60, 0.9));
  animation: alert-blink 0.7s steps(2) infinite;
}

@keyframes alert-blink { 50% { opacity: 0.25; } }

/* ===== CENTRAL CARD (Zone Centrale) ===== */
.card-stage {
  position: relative;
  margin-top: 128px;
  width: min(380px, 92vw);
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.card {
  width: 100%;
  height: min(520px, 58vh);
  touch-action: none;
  user-select: none;
  cursor: grab;
  transition: transform 0.18s ease-out;
  will-change: transform;
  pointer-events: auto;
}

.card:active { cursor: grabbing; }

.card-frame {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 18px;
  padding: 14px;
  background:
    linear-gradient(160deg, #4a2f1c 0%, #2c1a0e 55%, #1c0f08 100%);
  border: 3px solid var(--gold);
  box-shadow:
    0 0 0 2px var(--wood-dark),
    0 0 26px rgba(212, 175, 55, 0.28),
    0 18px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-frame::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 12px;
  pointer-events: none;
}

.portrait {
  position: relative;
  height: 42%;
  border-radius: 12px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 35%, #2b1d4a 0%, #14092a 70%, #0a0518 100%);
  border: 1px solid rgba(212, 175, 55, 0.35);
  flex: 0 0 auto;
}

.portrait-face {
  position: absolute;
  left: 50%;
  top: 52%;
  width: 92px;
  height: 112px;
  transform: translate(-50%, -50%);
  border-radius: 46% 46% 44% 44%;
  background: linear-gradient(165deg, #7a4a2b 0%, #5c3620 60%, #432413 100%);
  box-shadow: inset -6px -8px 14px rgba(0, 0, 0, 0.45), inset 4px 5px 10px rgba(255, 210, 150, 0.18);
}

.portrait-face::before,
.portrait-face::after {
  content: "";
  position: absolute;
  top: 44%;
  width: 13px;
  height: 6px;
  border-radius: 50%;
  background: #14090a;
}

.portrait-face::before { left: 22%; }
.portrait-face::after { right: 22%; }

.portrait-headdress {
  position: absolute;
  left: 50%;
  top: 12%;
  width: 130px;
  height: 46px;
  transform: translateX(-50%);
  border-radius: 50% 50% 18px 18px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold) 55%, #8a6a14 100%);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.portrait-headdress::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -12px;
  transform: translateX(-50%);
  width: 10px;
  height: 18px;
  border-radius: 50% 50% 0 0;
  background: #9b59b6;
  box-shadow: 0 0 8px rgba(155, 89, 182, 0.8);
}

.portrait-prêtre .portrait-headdress { background: linear-gradient(180deg, #e8e2d0, #b9ad8c 60%, #6e6448); }
.portrait-general .portrait-headdress { background: linear-gradient(180deg, #b0413e, #7c2a28 60%, #4a1513); }
.portrait-devin .portrait-headdress { background: linear-gradient(180deg, #9b59b6, #6c3483 60%, #4a235a); }
.portrait-emissaire .portrait-headdress { background: linear-gradient(180deg, #5dade2, #2e86c1 60%, #1b4f72); }
.portrait-intendante .portrait-headdress { background: linear-gradient(180deg, #58d68d, #27ae60 60%, #196f3d); }
.portrait-guerre .portrait-headdress { background: linear-gradient(180deg, #95a5a6, #5d6d7e 60%, #2c3e50); }
.portrait-sage .portrait-headdress { background: linear-gradient(180deg, #f7dc6f, #d4ac0d 60%, #9a7d0a); }
.portrait-marchand .portrait-headdress { background: linear-gradient(180deg, #eb984e, #ca6f1e 60%, #7e5109); }
.portrait-villageois .portrait-headdress { background: linear-gradient(180deg, #a8c686, #6b8e3d 60%, #3f5a20); }
.portrait-reine .portrait-headdress { background: linear-gradient(180deg, #f5d76e, #d4af37 45%, #b03a48 100%); }

.card-name {
  margin-top: 12px;
  font-size: 20px;
  font-weight: 700;
  color: var(--gold-bright);
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

.card-role {
  font-size: 13px;
  font-style: italic;
  text-align: center;
  color: rgba(243, 229, 192, 0.75);
  margin-top: 2px;
}

.card-text {
  margin-top: 12px;
  font-size: 15.5px;
  line-height: 1.5;
  text-align: center;
  color: var(--parchment);
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.card-hint {
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(212, 175, 55, 0.65);
  padding-bottom: 2px;
}

/* ===== SWIPE OVERLAYS (Indicateurs de Choix) ===== */
.swipe-overlay {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.12s linear;
}

.swipe-overlay.left { left: -14px; }
.swipe-overlay.right { right: -14px; }

.swipe-badge {
  padding: 12px 14px;
  border-radius: 12px;
  max-width: 150px;
  background: rgba(13, 7, 22, 0.82);
  border: 1px solid var(--gold);
  box-shadow: 0 0 18px rgba(212, 175, 55, 0.35);
  text-align: center;
}

.swipe-overlay.left .swipe-badge { border-color: #e67e22; box-shadow: 0 0 18px rgba(230, 126, 34, 0.4); }
.swipe-overlay.right .swipe-badge { border-color: #58d68d; box-shadow: 0 0 18px rgba(88, 214, 141, 0.4); }

.swipe-arrow { font-size: 22px; color: var(--gold-bright); }
.swipe-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: rgba(243, 229, 192, 0.7); margin-top: 2px; }
.swipe-action { font-size: 13px; font-weight: 700; margin-top: 6px; color: var(--parchment); }

/* ===== ACTION BADGES ===== */
.action-badges {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.badge {
  flex: 1;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(58, 36, 23, 0.85);
  border: 1px solid rgba(212, 175, 55, 0.5);
  color: var(--parchment);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.badge:hover, .badge:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.badge.left { justify-content: flex-start; }
.badge.right { justify-content: flex-end; }
.badge-arrow { font-size: 18px; color: var(--gold-bright); }
.badge-text { text-align: left; }
.badge.right .badge-text { text-align: right; }

/* ===== OVERLAYS (menu, pause, finished, leaderboard, boot) ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, rgba(26, 15, 46, 0.92), rgba(13, 7, 22, 0.97));
  pointer-events: auto;
}

.title {
  font-size: clamp(28px, 7vw, 44px);
  color: var(--gold-bright);
  text-shadow: 0 0 22px rgba(212, 175, 55, 0.45);
  margin: 0;
}

/* Écran de victoire : fond translucide pour laisser rayonner le Trône Impérial
   (or & bronze, rayons célestes) rendu par la scène Phaser derrière le HUD. */
.overlay.finished.victory {
  background: radial-gradient(circle at 50% 42%, rgba(212, 175, 55, 0.16), rgba(26, 15, 46, 0.5) 45%, rgba(13, 7, 22, 0.68));
  border: 1px solid rgba(212, 175, 55, 0.35);
  box-shadow: inset 0 0 80px rgba(212, 175, 55, 0.12);
}

/* Plan §2.3 : overlays semi-transparents — le trône reste visible derrière le menu
   et l'écran de fin (défaite), tout en gardant le texte lisible. */
.overlay.menu {
  background: radial-gradient(circle at 50% 40%, rgba(26, 15, 46, 0.55), rgba(13, 7, 22, 0.72));
}
.overlay.finished {
  background: radial-gradient(circle at 50% 40%, rgba(26, 15, 46, 0.62), rgba(13, 7, 22, 0.78));
}

/* Plan §2.2 : cinématique de transition de carte — sortie ~250ms, entrée ~180ms. */
.card.card-exit-left,
.card.card-exit-right {
  transition: transform 0.25s ease-in, opacity 0.25s ease-in;
  opacity: 0;
  pointer-events: none;
}
.card.card-exit-left { transform: translateX(-400px) rotate(-18deg) !important; }
.card.card-exit-right { transform: translateX(400px) rotate(18deg) !important; }
.card.card-enter {
  animation: card-enter 0.18s ease-out;
  pointer-events: none;
}
@keyframes card-enter {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.overlay.finished.victory h2 {
  text-shadow: 0 0 26px rgba(245, 215, 110, 0.8);
}

.subtitle { color: rgba(243, 229, 192, 0.8); margin: 0; }
.overlay h2 { color: var(--gold-bright); margin: 0 0 4px; }
.epilogue { max-width: 420px; line-height: 1.6; color: var(--parchment); }

.diff-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.diff {
  padding: 10px 14px;
  min-height: 48px;
  border-radius: 10px;
  background: rgba(58, 36, 23, 0.7);
  border: 1px solid rgba(212, 175, 55, 0.4);
  color: var(--parchment);
  font-family: inherit;
  cursor: pointer;
}

.diff.active { border-color: var(--gold-bright); box-shadow: 0 0 12px rgba(212, 175, 55, 0.4); }

.primary-btn {
  min-height: 56px;
  padding: 14px 28px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  color: #1a0f2e;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(212, 175, 55, 0.35);
}

.ghost-btn {
  min-height: 48px;
  padding: 10px 20px;
  border-radius: 12px;
  font-family: inherit;
  color: var(--parchment);
  background: transparent;
  border: 1px solid rgba(212, 175, 55, 0.5);
  cursor: pointer;
}

.name-input {
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(212, 175, 55, 0.5);
  color: var(--parchment);
  font-family: inherit;
  text-align: center;
}

.score-row { display: flex; gap: 22px; }
.score-item { display: flex; flex-direction: column; gap: 2px; }
.score-item span { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: rgba(243, 229, 192, 0.65); }
.score-item strong { font-size: 26px; color: var(--gold-bright); }

.board-list { list-style: none; padding: 0; margin: 0; width: min(360px, 88vw); display: flex; flex-direction: column; gap: 8px; }
.board-list li {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(58, 36, 23, 0.6);
  border: 1px solid rgba(212, 175, 55, 0.3);
}
.board-list .rank { color: var(--gold-bright); font-weight: 700; }
.board-list .bname { text-align: left; }
.board-list .bscore { font-variant-numeric: tabular-nums; }
.board-list .bdate { font-size: 12px; opacity: 0.6; }
.board-list .empty { grid-template-columns: 1fr; text-align: center; opacity: 0.7; }

.hud-buttons {
  position: fixed;
  top: 96px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 35;
  pointer-events: auto;
}

.hud-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 18px;
  background: rgba(58, 36, 23, 0.85);
  border: 1px solid rgba(212, 175, 55, 0.5);
  color: var(--parchment);
  cursor: pointer;
}

@media (max-width: 420px) {
  .top-bar { gap: 5px; padding: 8px; }
  .gauge-head { font-size: 10px; }
  .gauge-value { font-size: 10px; }
  .card-stage { margin-top: 116px; }
  .swipe-overlay.left { left: -6px; }
  .swipe-overlay.right { right: -6px; }
  .swipe-badge { max-width: 120px; padding: 9px 10px; }
}

/* ---------- Icône du projet : médaillon royal ---------- */
.project-icon {
  display: block;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.25), 0 4px 14px rgba(0, 0, 0, 0.55);
}

.project-icon-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  margin-bottom: 10px;
}

.project-icon-wrapper::before {
  content: "";
  position: absolute;
  inset: -18px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212, 175, 55, 0.4) 0%, rgba(212, 175, 55, 0.14) 45%, transparent 70%);
  animation: icon-halo 2.6s ease-in-out infinite;
  pointer-events: none;
}

.project-icon-wrapper::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px dashed rgba(212, 175, 55, 0.55);
  animation: icon-ring 14s linear infinite;
  pointer-events: none;
}

.project-icon-menu {
  width: 80px;
  height: 80px;
}

.project-icon-badge {
  width: 56px;
  height: 56px;
  margin-bottom: 10px;
  border-width: 2px;
}

.hud-seal {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

.project-icon-hud {
  width: 32px;
  height: 32px;
  border-width: 2px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.hud-seal:hover .project-icon-hud {
  transform: scale(1.12);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.4), 0 4px 14px rgba(0, 0, 0, 0.55);
}

@keyframes icon-halo {
  0%, 100% { opacity: 0.55; transform: scale(0.92); }
  50% { opacity: 1; transform: scale(1.08); }
}

@keyframes icon-ring {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .project-icon-wrapper::before,
  .project-icon-wrapper::after {
    animation: none;
  }
}

@media (min-width: 900px) {
  .card-stage { margin-top: 140px; }
}