/* ==========================================================================
   Recommandations : « les cartes postales »
   Chaque lieu est une carte postale posée sur un bureau sombre. On choisit
   une pile (Congo, Nancy), on ouvre une carte, elle se retourne : message
   manuscrit, timbre du pays, cachet de la poste avec la ville et ses
   coordonnées, adresse tapée à la machine.
   ========================================================================== */

@font-face { font-family: "Courier Prime"; font-style: normal; font-weight: 400; font-display: swap; src: url("../assets/fonts/courier-prime-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Courier Prime"; font-style: normal; font-weight: 700; font-display: swap; src: url("../assets/fonts/courier-prime-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Caveat"; font-style: normal; font-weight: 500; font-display: swap; src: url("../assets/fonts/caveat-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Hanken Grotesk"; font-style: normal; font-weight: 400; font-display: swap; src: url("../assets/fonts/hanken-grotesk-latin-400-normal.woff2") format("woff2"); }

:root {
  --desk: #15171A;
  --desk-2: #1C1F23;
  --paper: #F3EEE3;
  --paper-edge: #E6DFD0;
  --card-border: #F6F2EA;
  --ink: #EDE8DD;
  --ink-2: #A7A49B;
  --ink-3: #75736C;
  --pen: #213A7A;          /* encre de stylo bleu */
  --type: #2A2722;         /* encre de machine à écrire */
  --postmark: rgba(52, 44, 92, 0.72);
  --rule: rgba(237, 232, 221, 0.12);
  --typewriter: "Courier Prime", "Courier New", Courier, monospace;
  --hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --sans: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body.desk {
  margin: 0;
  min-height: 100vh;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  background-color: var(--desk);
  /* grain discret du bureau */
  background-image:
    radial-gradient(1200px 700px at 50% -10%, rgba(255, 240, 210, 0.05), transparent 70%),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
  overflow-x: clip;
}

body.desk .site-nav { background: rgba(21, 23, 26, 0.88); }
body.desk :focus-visible { outline: 2px solid #E8C67A; outline-offset: 4px; }

.desk-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 clamp(20px, 4vw, 56px) 140px;
}

/* ---------- En-tête ---------- */
.desk-head { padding: clamp(56px, 8vw, 104px) 0 28px; max-width: 760px; }

.desk-title {
  margin: 0 0 14px;
  font-family: var(--typewriter);
  font-weight: 700;
  font-size: clamp(40px, 6.4vw, 80px);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.desk-lede { margin: 0; font-size: 18px; color: var(--ink-2); max-width: 46ch; }
.desk-link { color: var(--ink); text-decoration: underline; text-decoration-color: rgba(237,232,221,.3); text-underline-offset: 4px; }
.desk-link:hover { text-decoration-color: #E8C67A; }

/* ---------- La ligne entre les deux villes ---------- */
.route { position: relative; margin: 28px 0 44px; }
.route-svg { display: block; width: 100%; height: 110px; overflow: visible; }
.route-path { fill: none; stroke: rgba(237, 232, 221, 0.28); stroke-width: 1.2; stroke-dasharray: 2 6; vector-effect: non-scaling-stroke; }
.route-path-lit { fill: none; stroke: #E8C67A; stroke-width: 1.6; stroke-dasharray: 1 1; stroke-dashoffset: 1; transition: stroke-dashoffset 1.6s cubic-bezier(.6,0,.2,1); }
.route.is-drawn .route-path-lit { stroke-dashoffset: 0; }
.route-labels { position: absolute; inset: 0; pointer-events: none; }
.route-city {
  position: absolute;
  transform: translate(-50%, 0);
  text-align: center;
  font-family: var(--typewriter);
  font-size: 13px;
  line-height: 1.25;
  color: var(--ink-2);
  white-space: nowrap;
  transition: color 0.25s ease;
}
.route-city::before {
  content: "";
  display: block;
  width: 9px;
  height: 9px;
  margin: 0 auto 8px;
  border-radius: 50%;
  background: var(--ink-3);
  box-shadow: 0 0 0 4px rgba(21, 23, 26, 1);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}
.route-city small { display: block; color: var(--ink-3); font-size: 11.5px; }
.route-city.is-lit { color: var(--ink); }
.route-city.is-lit::before { background: #E8C67A; box-shadow: 0 0 0 4px rgba(21,23,26,1), 0 0 16px 4px rgba(232, 198, 122, 0.45); }
.route-distance {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  font-family: var(--hand);
  font-size: 22px;
  color: var(--ink-2);
}

/* ---------- Les piles ---------- */
.piles { display: flex; flex-wrap: wrap; gap: 14px 22px; margin: 0 0 56px; }

.pile {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 6px 4px;
  border: 0;
  background: none;
  color: var(--ink-2);
  font: 700 15px/1 var(--typewriter);
  cursor: pointer;
}
.pile-stack { position: relative; width: 38px; height: 28px; }
.pile-stack i {
  position: absolute;
  inset: 0;
  border-radius: 2px;
  background: var(--paper-edge);
  border: 2px solid var(--card-border);
  box-shadow: 0 2px 4px rgba(0,0,0,.5);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.pile-stack i:nth-child(1) { transform: rotate(-7deg) translate(-2px, 2px); opacity: .55; }
.pile-stack i:nth-child(2) { transform: rotate(4deg) translate(2px, 0); opacity: .75; }
.pile-stack i:nth-child(3) { transform: rotate(-1deg); }
.pile:hover .pile-stack i:nth-child(1) { transform: rotate(-14deg) translate(-6px, 3px); }
.pile:hover .pile-stack i:nth-child(2) { transform: rotate(10deg) translate(6px, -1px); }
.pile[aria-pressed="true"] { color: var(--ink); }
.pile[aria-pressed="true"] .pile-stack i:nth-child(3) { background: #E8C67A; border-color: #F3DDA8; }
.pile-count { font-weight: 400; color: var(--ink-3); }

/* ---------- La table ---------- */
.table {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 64px 48px;
}

.postcard {
  --rot: 0deg;
  --dx: 0px;
  --dy: 0px;
  transform: translate(var(--dx), var(--dy)) rotate(var(--rot));
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.35s ease;
}
.postcard.is-away { opacity: 0; transform: translate(var(--dx), calc(var(--dy) + 30px)) rotate(calc(var(--rot) * 2)) scale(0.94); pointer-events: none; }
.postcard.is-gone { display: none; }
.postcard.is-open { opacity: 0; }

.postcard button {
  display: block;
  width: 100%;
  padding: 9px 9px 9px;
  border: 0;
  background: var(--card-border);
  border-radius: 2px;
  box-shadow: 0 2px 2px rgba(0,0,0,.35), 0 18px 30px -12px rgba(0,0,0,.75);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: box-shadow 0.35s ease;
}
.postcard:hover { transform: translate(var(--dx), calc(var(--dy) - 6px)) rotate(calc(var(--rot) * 0.3)); }
.postcard:hover button { box-shadow: 0 2px 2px rgba(0,0,0,.35), 0 30px 44px -14px rgba(0,0,0,.85); }

.postcard-photo { position: relative; aspect-ratio: 3 / 2; overflow: hidden; background: #2A2C30; }
.postcard-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.postcard-photo::after {
  /* léger vieillissement d'impression */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 55%, rgba(0,0,0,.45));
  mix-blend-mode: multiply;
}
.pc-caption,
.postcard-caption {
  position: absolute;
  left: 12px;
  bottom: 9px;
  z-index: 1;
  margin: 0;
  font-family: var(--typewriter);
  font-weight: 700;
  font-size: 13px;
  line-height: 1.25;
  color: #FFF8EC;
  text-shadow: 0 1px 2px rgba(0,0,0,.7);
}
.postcard-caption small,
.pc-caption small { display: block; font-weight: 400; font-size: 11.5px; opacity: .85; }

/* ==========================================================================
   La carte ouverte
   ========================================================================== */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 72px 20px 24px;
}
.viewer[hidden] { display: none; }

.viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 11, 13, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.35s ease;
}
.viewer.is-in .viewer-backdrop { opacity: 1; }

.viewer-card {
  position: relative;
  width: min(880px, 100%, calc((100svh - 190px) * 1.5));
  aspect-ratio: 3 / 2;
  perspective: 2200px;
}

.pc-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.85s cubic-bezier(0.45, 0.05, 0.2, 1);
}
.viewer.is-flipped .pc-inner { transform: rotateY(180deg); }

.pc-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 50px 90px -30px rgba(0,0,0,.95), 0 2px 3px rgba(0,0,0,.4);
}

.pc-front { background: var(--card-border); padding: 14px; }
.pc-front img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pc-front .pc-caption { left: 30px; bottom: 26px; font-size: 16px; }
.pc-front .pc-caption small { font-size: 13px; }

.pc-back {
  transform: rotateY(180deg);
  display: grid;
  grid-template-columns: 1.1fr 1px 1fr;
  gap: 0 clamp(16px, 3vw, 34px);
  padding: clamp(18px, 3.2vw, 34px);
  color: var(--type);
  background-color: var(--paper);
  background-image:
    radial-gradient(120% 90% at 0% 0%, rgba(255,255,255,.55), transparent 55%),
    radial-gradient(90% 80% at 100% 100%, rgba(170,140,90,.14), transparent 60%),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)' opacity='0.09'/%3E%3C/svg%3E");
}

.pc-message { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.pc-hand {
  margin: 0;
  font-family: var(--hand);
  font-weight: 500;
  font-size: clamp(19px, 2.3vw, 27px);
  line-height: 1.3;
  color: var(--pen);
  transform: rotate(-1.2deg);
  transform-origin: left top;
}
.pc-sign {
  margin: auto 0 0;
  padding-top: 10px;
  font-family: var(--hand);
  font-size: clamp(22px, 2.6vw, 30px);
  color: var(--pen);
  transform: rotate(-3deg);
}

.pc-divider { background: rgba(42, 39, 34, 0.35); }

.pc-right { display: flex; flex-direction: column; min-height: 0; }

.pc-postage { position: relative; height: clamp(86px, 13vw, 118px); margin-bottom: 10px; }
.pc-postage svg { position: absolute; overflow: visible; }

.pc-address { margin-top: auto; }
.pc-name {
  margin: 0 0 6px;
  font-family: var(--typewriter);
  font-weight: 700;
  font-size: clamp(16px, 1.8vw, 21px);
  line-height: 1.2;
  color: var(--type);
}
.pc-line {
  margin: 0;
  padding: 5px 0 3px;
  border-bottom: 1px solid rgba(42, 39, 34, 0.28);
  font-family: var(--typewriter);
  font-size: clamp(12.5px, 1.3vw, 14.5px);
  line-height: 1.35;
  color: var(--type);
}
.pc-stars { letter-spacing: 3px; color: #8A6A1F; }

.pc-go {
  align-self: flex-start;
  margin-top: 14px;
  font-family: var(--typewriter);
  font-weight: 700;
  font-size: 13.5px;
  color: var(--type);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.pc-go:hover { color: #6B3A10; }

.viewer-tools {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  opacity: 0;
  transition: opacity 0.3s ease 0.2s;
}
.viewer.is-in .viewer-tools { opacity: 1; }

.viewer-btn {
  padding: 9px 14px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: rgba(21, 23, 26, 0.8);
  color: var(--ink);
  font: 400 14px/1 var(--typewriter);
  cursor: pointer;
}
.viewer-btn:hover { border-color: rgba(232, 198, 122, 0.6); }

.pc-thumbs { display: flex; gap: 8px; }
.pc-thumbs button {
  width: 54px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--card-border);
  cursor: pointer;
  opacity: 0.6;
}
.pc-thumbs button[aria-pressed="true"] { opacity: 1; outline: 2px solid #E8C67A; outline-offset: 1px; }
.pc-thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Mobile : la carte se tient debout ---------- */
@media (max-width: 700px) {
  .route-city { font-size: 11px; }
  .route-city small { display: none; }
  .route-distance { font-size: 18px; }
  .table { gap: 44px; }

  .viewer { padding: 64px 14px 18px; gap: 16px; }
  .viewer-card { width: min(100%, calc((100svh - 170px) * 0.66)); aspect-ratio: 2 / 3; }
  .pc-back {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 1px auto;
    gap: 12px;
  }
  .pc-right { display: contents; }
  .pc-postage { order: -1; height: 92px; margin: 0; }
  .pc-message { order: 0; }
  .pc-divider { order: 1; }
  .pc-address { order: 2; margin: 0; }
  .pc-go { order: 3; margin-top: 0; }
  .pc-hand { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  .postcard, .pc-inner, .viewer-backdrop, .viewer-tools, .route-path-lit { transition: none; }
}

/* Timbre et cachet un peu plus présents sur grand écran */
@media (min-width: 701px) {
  .pc-postage { transform: scale(1.25); transform-origin: top right; margin-bottom: 30px; }
}
