/* ─── Reset & Base ─────────────────────────────────────────────────────────── */

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

/* Override global container for full-game feel */
body:has(#swipe-game) .container {
  padding: 0;
  max-width: 100%;
}

/* ─── Game Root ────────────────────────────────────────────────────────────── */

#swipe-game {
  --gold:        #c9a84c;
  --gold-light:  #e8c96a;
  --gold-dim:    rgba(201, 168, 76, 0.25);
  --bg:          #0d0d1a;
  --card-bg:     #f8f4ec;
  --card-text:   #1e1e2e;
  --rail-bg:     rgba(255, 255, 255, 0.04);
  --rail-border: rgba(201, 168, 76, 0.2);

  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 100px);
  background: var(--bg);
  padding: 0 0 24px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ─── Progress Bar ─────────────────────────────────────────────────────────── */

#progress-bar {
  display: flex;
  gap: 10px;
  padding: 18px 16px 10px;
  justify-content: center;
  flex-shrink: 0;
}

.family-pip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.pip-circle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: transparent;
  transition: background 0.5s ease, box-shadow 0.5s ease;
  position: relative;
}

.pip-circle::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: transparent;
  transition: background 0.5s ease;
}

.family-pip.done .pip-circle {
  background: var(--gold-dim);
  box-shadow: 0 0 10px var(--gold);
}

.family-pip.done .pip-circle::after {
  background: var(--gold);
}

.pip-label {
  font-size: 9px;
  color: var(--gold);
  font-family: 'Georgia', serif;
  opacity: 0.6;
  letter-spacing: 0.5px;
}

.family-pip.done .pip-label {
  opacity: 1;
}

/* ─── Family Title ─────────────────────────────────────────────────────────── */

#family-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 20px;
  color: var(--gold);
  opacity: 0.7;
  transition: opacity 0.4s;
}

#family-numeral {
  font-family: 'Georgia', serif;
  font-size: 15px;
  font-weight: bold;
}

#family-phrase {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: 'Georgia', serif;
  max-width: 260px;
  text-align: center;
}

/* ─── Card Arena ───────────────────────────────────────────────────────────── */

#card-arena {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 420px;
  padding: 12px 20px;
  min-height: 320px;
}

/* ─── Directional Hints ────────────────────────────────────────────────────── */

.hint {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  font-family: 'Georgia', serif;
}

.hint-left  { left: 0;   top: 50%; transform: translateY(-50%); flex-direction: row; }
.hint-right { right: 0;  top: 50%; transform: translateY(-50%); flex-direction: row-reverse; }
.hint-up    { top: 4px;  left: 50%; transform: translateX(-50%); flex-direction: column; }
.hint-down  { bottom: 4px; left: 50%; transform: translateX(-50%); flex-direction: column-reverse; }

.hint-arrow { font-size: 16px; }

/* Hints selon la phase */
#swipe-game.phase-draw .hint-left,
#swipe-game.phase-draw .hint-right,
#swipe-game.phase-draw .hint-up,
#swipe-game.phase-draw .hint-down   { opacity: 0.3; }

#swipe-game.phase-revealed .hint-up,
#swipe-game.phase-revealed .hint-down  { opacity: 0.55; }
#swipe-game.phase-revealed .hint-left,
#swipe-game.phase-revealed .hint-right { opacity: 0.3; }

#swipe-game.phase-pair .hint-up,
#swipe-game.phase-pair .hint-down  { opacity: 0.55; }

/* Surlignage pendant le swipe actif */
#swipe-game.swiping-left  .hint-left  { opacity: 1; }
#swipe-game.swiping-right .hint-right { opacity: 1; }
#swipe-game.swiping-up    .hint-up    { opacity: 1; }
#swipe-game.swiping-down  .hint-down  { opacity: 1; }

/* ─── Main Card ────────────────────────────────────────────────────────────── */

#main-card-wrapper {
  perspective: 1200px;
  width: 240px;
  height: 340px;
  flex-shrink: 0;
}

#main-card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.3s ease;
  cursor: grab;
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6),
              0 0 0 1px rgba(201, 168, 76, 0.15);
}

#main-card:active { cursor: grabbing; }

#main-card.flipped {
  transform: rotateY(180deg);
}

/* Tilt during swipe */
#main-card.tilt-right { transform: rotate(5deg) translateX(8px); }
#main-card.tilt-left  { transform: rotate(-5deg) translateX(-8px); }
#main-card.tilt-up    { transform: translateY(-8px); }
#main-card.tilt-down  { transform: translateY(8px); }

/* Fly to rail animation */
@keyframes flyToRail {
  0%   { transform: rotateY(180deg) scale(1); opacity: 1; }
  40%  { transform: rotateY(180deg) scale(0.9) translateY(20px); opacity: 0.9; }
  100% { transform: rotateY(180deg) scale(0.38) translateY(120px); opacity: 0; }
}

#main-card.fly-to-rail {
  animation: flyToRail 0.5s cubic-bezier(0.4, 0, 1, 1) forwards;
}

/* Fade out when passing */
@keyframes exitUp {
  0%   { transform: rotateY(180deg) translateY(0)    scale(1);    opacity: 1; }
  100% { transform: rotateY(180deg) translateY(-60px) scale(0.85); opacity: 0; }
}

@keyframes exitDown {
  0%   { transform: rotateY(180deg) translateY(0)   scale(1);    opacity: 1; }
  100% { transform: rotateY(180deg) translateY(60px) scale(0.85); opacity: 0; }
}

#main-card.exit-up   { animation: exitUp   0.3s ease forwards; }
#main-card.exit-down { animation: exitDown 0.3s ease forwards; }

/* Fade in new card */
@keyframes cardEnter {
  0%   { opacity: 0; transform: scale(0.92) translateY(12px); }
  100% { opacity: 1; transform: scale(1)    translateY(0); }
}

#main-card.entering {
  animation: cardEnter 0.4s cubic-bezier(0.2, 0, 0.2, 1) forwards;
}

/* ─── Card Faces ───────────────────────────────────────────────────────────── */

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* FRONT = face cachée (visible par défaut) */
.card-face.front {
  background: linear-gradient(145deg, #151528 0%, #0d0d1a 100%);
  border: 1.5px solid rgba(201, 168, 76, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-back-design {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px;
}

.stoic-emblem svg {
  width: 80px;
  height: 80px;
  opacity: 0.85;
}

.card-back-title {
  color: var(--gold);
  font-family: 'Georgia', serif;
  font-size: 13px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.6;
  opacity: 0.75;
}

/* BACK = face révélée */
.card-face.back {
  background: var(--card-bg);
  border: 1.5px solid rgba(201, 168, 76, 0.2);
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.card-type-badge {
  padding: 10px 16px 8px;
  font-family: 'Georgia', serif;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: bold;
  color: #fff;
  background: #1e1e2e;
  border-radius: 0;
  flex-shrink: 0;
}

.card-family-id {
  position: absolute;
  top: 44px;
  right: 14px;
  font-family: 'Georgia', serif;
  font-size: 11px;
  color: rgba(30, 30, 46, 0.35);
  font-style: italic;
}

.card-content-text {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 22px;
  font-family: 'Georgia', serif;
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--card-text);
  text-align: center;
  white-space: pre-line;
}

/* Type-specific badge colors */
.badge-la-phrase  { background: #3d1a1a; }
.badge-these      { background: #1a2d4f; }
.badge-antithese  { background: #1a3d2d; }
.badge-synthese   { background: #2d1a4f; }
.badge-histoire   { background: #3d2a1a; }
.badge-citation   { background: #1a3040; }

/* ─── State Message ────────────────────────────────────────────────────────── */

#state-message {
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.4;
  font-family: 'Georgia', serif;
  height: 16px;
  text-align: center;
  transition: opacity 0.3s;
}

/* ─── Card Rail ────────────────────────────────────────────────────────────── */

#card-rail {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  width: 100%;
  max-width: 420px;
  justify-content: center;
  flex-shrink: 0;
}

.rail-slot {
  flex: 1;
  max-width: 160px;
  position: relative;
}

.rail-empty-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.2;
  font-family: 'Georgia', serif;
  border: 1.5px dashed rgba(201, 168, 76, 0.2);
  border-radius: 12px;
  height: 100px;
  pointer-events: none;
  transition: opacity 0.3s;
}

.rail-card {
  width: 100%;
  height: 100px;
  border-radius: 12px;
  background: var(--card-bg);
  border: 1.5px solid rgba(201, 168, 76, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.9) translateY(10px);
  transition: opacity 0.4s, transform 0.4s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.rail-card.visible {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.rail-card-type {
  padding: 5px 8px 4px;
  font-size: 7.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-family: 'Georgia', serif;
  font-weight: bold;
  color: #fff;
  background: #1e1e2e;
  flex-shrink: 0;
}

.rail-card-content {
  flex: 1;
  padding: 6px 8px;
  font-family: 'Georgia', serif;
  font-size: 9.5px;
  line-height: 1.5;
  color: var(--card-text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rail-divider {
  color: var(--gold);
  font-size: 14px;
  opacity: 0.3;
  flex-shrink: 0;
}

/* When rail slot is filled, hide empty label */
.rail-slot.filled .rail-empty-label { opacity: 0; }

/* Pulse animation on pair ready */
@keyframes railPulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(0,0,0,0.4), 0 0 0 0 rgba(201,168,76,0); }
  50%       { box-shadow: 0 4px 16px rgba(0,0,0,0.4), 0 0 0 6px rgba(201,168,76,0.2); }
}

#swipe-game.phase-pair .rail-card.visible {
  animation: railPulse 2s ease-in-out infinite;
}

/* ─── Victory Screen ───────────────────────────────────────────────────────── */

#victory-screen {
  position: fixed;
  inset: 0;
  background: rgba(13, 13, 26, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(8px);
}

#victory-screen[hidden] { display: none; }

.victory-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  padding: 40px 32px;
  animation: cardEnter 0.6s cubic-bezier(0.2, 0, 0.2, 1) forwards;
}

.victory-emblem {
  font-size: 48px;
  color: var(--gold);
  animation: none;
}

.victory-title {
  font-family: 'Georgia', serif;
  font-size: 28px;
  color: var(--gold);
  margin: 0;
  line-height: 1.3;
  letter-spacing: 0.04em;
}

.victory-sub {
  color: rgba(201, 168, 76, 0.6);
  font-family: 'Georgia', serif;
  font-size: 14px;
  line-height: 1.7;
  margin: 0;
  max-width: 280px;
}

.restart-btn {
  margin-top: 8px;
  padding: 12px 32px;
  background: transparent;
  border: 1.5px solid var(--gold);
  border-radius: 30px;
  color: var(--gold);
  font-family: 'Georgia', serif;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.restart-btn:hover {
  background: var(--gold);
  color: #0d0d1a;
}

/* ─── No cards left ────────────────────────────────────────────────────────── */

#main-card.invisible {
  opacity: 0;
  pointer-events: none;
}
