:root {
  --cream: #FFF6E9;
  --yellow: #FFC93C;
  --sky: #4FB8E8;
  --pink: #FF6F91;
  --green: #58C97B;
  --ink: #2E2A4D;
  --white: #FFFFFF;
  --red: #E85757;
  --night: #0B0E2A;
  --night-2: #1C2260;
  --star-text: #F4F1FF;
  --muted: #A9A6D6;
  --panel: rgba(11, 15, 51, 0.82);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(120, 90, 255, 0.35), transparent 55%),
    radial-gradient(ellipse at 90% 30%, rgba(255, 111, 145, 0.18), transparent 50%),
    linear-gradient(180deg, var(--night-2) 0%, var(--night) 60%);
  background-attachment: fixed;
  color: var(--star-text);
  font-family: 'Quicksand', sans-serif;
  font-weight: 600;
  min-height: 100vh;
  padding-bottom: 3rem;
}

.back-link {
  display: inline-block;
  margin: 1rem 0 0 1.6rem;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  color: var(--sky);
  text-decoration: none;
  font-size: 1rem;
}
.back-link:hover { text-decoration: underline; }

.game-header {
  text-align: center;
  padding: .2rem 1rem 0;
}
.game-header h1 {
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(1.6rem, 4.5vw, 2.3rem);
  margin: 0;
  text-shadow: 3px 3px 0 var(--pink);
}
.game-header p { color: var(--muted); margin: 0; font-size: .95rem; }

/* ---------- HUD ---------- */
.hud {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin: .8rem auto .9rem;
  font-family: 'Baloo 2', sans-serif;
  max-width: 1000px;
  padding: 0 1rem;
}
.hud-item, .hud-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--star-text);
  padding: .4rem 1rem;
  border-radius: 999px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1rem;
}
.hud-btn { cursor: pointer; font-weight: 700; }
.hud-btn:hover { background: rgba(255, 255, 255, 0.2); }
#restart {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  border: none;
  padding: .45rem 1.2rem;
  border-radius: 999px;
  cursor: pointer;
  background: var(--pink);
  color: var(--white);
  box-shadow: 0 5px 0 #c94f6e;
  transition: transform .12s ease, box-shadow .12s ease;
}
#restart:hover { transform: translateY(2px); box-shadow: 0 3px 0 #c94f6e; }

/* ---------- Layout ---------- */
.game-layout {
  display: flex;
  gap: 1.4rem;
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 1rem;
  align-items: flex-start;
  justify-content: center;
}
.stage-col {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 1040px;
}

.stage {
  position: relative;
  height: clamp(380px, 72vh, 720px);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12), 0 18px 40px rgba(0, 0, 0, 0.45);
  background: #070920;
  user-select: none;
  -webkit-user-select: none;
}
#spaceCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- Ordre de mission (dans le jeu) ---------- */
.mission-panel {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 250px;
  max-height: calc(100% - 120px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  padding: .35rem .45rem .45rem;
  backdrop-filter: blur(3px);
}
.mission-panel.riddles { width: 300px; }
.mission-head {
  display: flex;
  align-items: center;
  gap: .35rem;
  width: 100%;
  background: none;
  border: none;
  color: var(--yellow);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: .95rem;
  padding: .1rem .2rem .25rem;
  cursor: pointer;
  text-align: left;
}
.mission-head::after {
  content: '▾';
  margin-left: auto;
  color: var(--muted);
}
.mission-panel.collapsed .mission-head::after { content: '▸'; }
.mission-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.m-item {
  display: flex;
  align-items: center;
  gap: .45rem;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: .2rem .45rem .2rem .2rem;
  font-size: .85rem;
  line-height: 1.2;
  transition: background .3s ease;
}
.m-item.done { background: rgba(88, 201, 123, 0.25); }
.m-thumb {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.m-thumb img { width: 100%; height: 100%; transform: scale(1.45); }
.m-q {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  color: var(--yellow);
  font-size: 1rem;
}
.m-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.m-text strong { font-family: 'Baloo 2', sans-serif; font-size: .95rem; }
.m-riddle { font-size: .74rem; color: #D8D5F5; font-weight: 600; }
.m-item.done .m-riddle { opacity: .6; }
.m-check {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: .85rem;
}
.m-item.done .m-check { background: var(--green); border-color: var(--green); color: var(--white); animation: pop .4s ease; }
@keyframes pop {
  0% { transform: scale(.3); }
  70% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
/* Panneau replié : on ne garde que les images */
.mission-panel.collapsed { width: auto; }
.mission-panel.collapsed .mission-head-text { display: none; }
.mission-panel.collapsed .m-text { display: none; }
.mission-panel.collapsed .m-item { padding: .15rem; position: relative; }
.mission-panel.collapsed .m-check {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 16px;
  height: 16px;
  font-size: .6rem;
  border-width: 1px;
}
.mission-panel.collapsed .m-item:not(.done) .m-check { display: none; }

/* ---------- Photo (carte postale qui apparaît après un clic) ---------- */
.photo-card {
  position: absolute;
  top: 10px;
  right: 10px;
  width: min(360px, 48%);
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  background: #FFFDF8;
  color: var(--ink);
  border-radius: 10px;
  padding: .55rem;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  transform: rotate(1.5deg);
  pointer-events: none;
  animation: cardIn .45s cubic-bezier(.2, 1.4, .4, 1);
}
.photo-card.on-mission { box-shadow: 0 0 0 4px var(--green), 0 10px 26px rgba(0, 0, 0, 0.45); }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(-20px) rotate(-8deg) scale(.7); }
  to   { opacity: 1; transform: rotate(1.5deg); }
}
.pc-pic {
  flex: 0 0 auto;
  width: 84px;
  height: 84px;
  background: #0B0F33;
  border-radius: 6px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.pc-pic img { width: 100%; height: 100%; transform: scale(1.4); }
.pc-body { flex: 1; min-width: 0; }
.pc-body p { margin: 0 0 .2rem; }
.pc-tag { display: flex; flex-wrap: wrap; gap: .25rem; }
.tag {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: .72rem;
  padding: 0 .5rem;
  border-radius: 999px;
}
.tag-ok { background: var(--green); color: var(--white); }
.tag-off { background: #ECE8F5; color: #6a6486; }
.tag-new { background: var(--yellow); color: var(--ink); }
.pc-name {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1.1;
  color: var(--pink);
}
.pc-name small { font-size: .75rem; color: #8a84a6; font-weight: 700; }
.pc-fact { font-size: .85rem; line-height: 1.3; }
.pc-wow {
  font-size: .8rem;
  line-height: 1.3;
  background: #FFF3C9;
  border-radius: 8px;
  padding: .25rem .4rem;
}

/* ---------- Bip, le copilote ---------- */
.copilot {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  align-items: flex-end;
  gap: .4rem;
  pointer-events: none;
  max-width: calc(100% - 190px);
}
.bip {
  flex: 0 0 auto;
  width: 70px;
  height: 74px;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
  animation: hover 2.6s ease-in-out infinite;
}
@keyframes hover {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-6px) rotate(3deg); }
}
.bip-eyes { transform-box: fill-box; transform-origin: center; animation: blink 4s infinite; }
@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}
.bip-antenna { animation: antenna 1.2s infinite; }
@keyframes antenna {
  0%, 100% { fill: #FF6F91; }
  50% { fill: #FFC93C; }
}
.bip-mouth { transform-box: fill-box; transform-origin: center; }
.copilot.talking .bip-mouth { animation: talk .18s infinite alternate; }
@keyframes talk {
  from { transform: scaleY(1); }
  to { transform: scaleY(2.6); }
}
.bubble {
  position: relative;
  background: var(--white);
  color: var(--ink);
  border-radius: 16px;
  padding: .45rem .8rem;
  font-size: .92rem;
  line-height: 1.3;
  margin-bottom: 34px;
  max-width: 340px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: scale(.6);
  transform-origin: bottom left;
  transition: opacity .2s ease, transform .2s ease;
}
.bubble::before {
  content: '';
  position: absolute;
  left: -8px;
  bottom: 10px;
  border: 8px solid transparent;
  border-right-color: var(--white);
  border-left: 0;
}
.bubble.show { opacity: 1; transform: scale(1); animation: bubbleIn .35s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes bubbleIn {
  from { transform: scale(.5); }
  to { transform: scale(1); }
}

/* ---------- Mini-carte ---------- */
.minimap {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  pointer-events: none;
}

/* ---------- Commandes tactiles (tablettes / téléphones) ---------- */
.touch-pad {
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  padding: 0 .5rem;
  user-select: none;
  -webkit-user-select: none;
}
@media (pointer: coarse) {
  .touch-pad { display: flex; }
}
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 4px;
}
.dpad button, .turbo-btn {
  border: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.14);
  color: var(--white);
  font-size: 1.3rem;
  touch-action: none;
}
.dpad button:active, .dpad button.pressed { background: rgba(79, 184, 232, 0.6); }
.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 3; }
.turbo-btn {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.2rem;
  padding: 1.2rem 1.6rem;
  background: var(--sky);
  border-radius: 999px;
  box-shadow: 0 5px 0 #2f8fb8;
}
.turbo-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #2f8fb8; }

/* ---------- Classement ---------- */
.leaderboard {
  flex: 0 0 240px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  padding: 1.2rem 1.1rem;
  position: sticky;
  top: 1.5rem;
}
.leaderboard h2 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.15rem;
  margin: 0 0 .5rem;
  text-align: center;
}
.lb-tabs {
  display: flex;
  gap: .3rem;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  padding: .2rem;
  margin-bottom: .5rem;
}
.lb-tabs button {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: .8rem;
  border-radius: 999px;
  padding: .3rem .2rem;
  cursor: pointer;
}
.lb-tabs button.active { background: var(--sky); color: var(--white); }
.leaderboard-sub {
  font-size: .75rem;
  color: var(--muted);
  text-align: center;
  margin: 0 0 .9rem;
}
.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  max-height: 420px;
  overflow-y: auto;
}
.leaderboard-list li {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: .4rem .6rem;
}
.leaderboard-list li .rank {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  color: var(--sky);
  width: 1.4rem;
  flex-shrink: 0;
}
.leaderboard-list li:nth-child(1) .rank { color: #FFD24A; }
.leaderboard-list li:nth-child(2) .rank { color: #C7CCD3; }
.leaderboard-list li:nth-child(3) .rank { color: #E0955A; }
.leaderboard-list li .lb-name {
  flex: 1;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaderboard-list li .lb-time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.leaderboard-list li.leaderboard-empty {
  display: block;
  background: none;
  text-align: center;
  color: var(--muted);
  padding: 1rem 0;
}
.leaderboard-note {
  margin: .9rem 0 0;
  padding-top: .8rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.15);
  font-size: .72rem;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
}

/* ---------- Ordre de mission (écran de départ) ---------- */
.start-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: rgba(7, 9, 32, 0.6);
  backdrop-filter: blur(2px);
  padding: 1rem;
  overflow-y: auto;
}
.order-card {
  position: relative;
  margin: auto 0;
  background:
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(79, 184, 232, 0.12) 27px 28px),
    #FFFCF3;
  color: var(--ink);
  border-radius: 18px;
  padding: 1.2rem 1.5rem 1rem;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.25);
  animation: orderIn .5s cubic-bezier(.2, 1.3, .4, 1);
}
@keyframes orderIn {
  from { opacity: 0; transform: translateY(30px) rotate(-3deg); }
  to { opacity: 1; transform: none; }
}
.order-head {
  position: relative;
  text-align: center;
  border-bottom: 3px double rgba(46, 42, 77, 0.35);
  padding-bottom: .5rem;
  margin-bottom: .6rem;
}
.order-agency {
  margin: 0;
  font-size: .75rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #8a84a6;
}
.order-title {
  margin: 0;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: .04em;
}
.order-title span { color: var(--pink); }
.stamp {
  position: absolute;
  right: -6px;
  top: -4px;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: .95rem;
  color: var(--red);
  border: 3px solid var(--red);
  border-radius: 8px;
  padding: 0 .5rem;
  transform: rotate(12deg);
  opacity: .8;
}
.order-story {
  margin: 0 0 .7rem;
  font-size: .98rem;
  line-height: 1.4;
  text-align: center;
}
.mode-switch {
  display: flex;
  gap: .5rem;
  margin-bottom: .7rem;
}
.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--ink);
  background: #F1EDF8;
  border: 3px solid transparent;
  border-radius: 14px;
  padding: .35rem .4rem;
  cursor: pointer;
}
.mode-btn small { font-family: 'Quicksand', sans-serif; font-weight: 600; font-size: .75rem; color: #6a6486; }
.mode-btn.active { border-color: var(--sky); background: #E4F5FD; }
.order-sub {
  margin: 0 0 .35rem;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
}
.order-list {
  list-style: none;
  margin: 0 0 .7rem;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .35rem;
}
.order-list .m-item { background: #F1EDF8; color: var(--ink); }
.order-list .m-thumb { background: #0B0F33; width: 42px; height: 42px; }
.order-list .m-riddle { color: #4a4568; font-size: .78rem; }
.order-list .m-check { display: none; }
.how-to {
  list-style: none;
  margin: 0 0 .8rem;
  padding: .5rem .7rem;
  background: rgba(79, 184, 232, 0.1);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .82rem;
}
.keys { white-space: nowrap; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: .05em .4em;
  margin: 0 .1em;
  border-radius: 6px;
  background: var(--cream);
  border: 1px solid #E4DCCB;
  box-shadow: 0 2px 0 #E4DCCB;
  font-family: 'Baloo 2', sans-serif;
  font-size: .8rem;
  text-align: center;
}
.order-actions {
  display: flex;
  gap: .6rem;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
#startBtn {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.25rem;
  background: var(--yellow);
  color: var(--ink);
  border: none;
  padding: .6rem 1.8rem;
  border-radius: 999px;
  box-shadow: 0 6px 0 #d9a21e;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
#startBtn:hover { transform: translateY(2px); box-shadow: 0 4px 0 #d9a21e; }
.order-sign {
  margin: .6rem 0 0;
  text-align: right;
  font-size: .8rem;
  color: #8a84a6;
}

/* ---------- Victoire ---------- */
.win-banner {
  position: fixed;
  inset: 0;
  background: rgba(7, 9, 32, 0.65);
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 30;
  padding: 1rem;
  overflow-y: auto;
}
.win-banner.show { display: flex; }
.win-card {
  margin: auto 0;
  background: var(--white);
  color: var(--ink);
  border-radius: 28px;
  padding: 1.6rem 1.8rem;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.25);
}
.win-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.5rem;
  margin: 0 0 .5rem;
  color: var(--pink);
}
.win-photos {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .4rem;
  margin-bottom: .8rem;
}
.win-photos figure {
  margin: 0;
  background: #FFFDF8;
  padding: .25rem .25rem .1rem;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
  transform: rotate(var(--tilt));
  width: 72px;
}
.win-photos figure img {
  display: block;
  width: 64px;
  height: 64px;
  background: #0B0F33;
}
.win-photos figcaption {
  font-family: 'Baloo 2', sans-serif;
  font-size: .62rem;
  line-height: 1.2;
  padding-top: .15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#winTime {
  font-family: 'Baloo 2', sans-serif;
  color: #6a6486;
  margin: 0 0 .6rem;
}
#winTime strong { color: var(--ink); font-size: 1.3rem; }
.win-carnet {
  margin: 0 0 1rem;
  font-size: .9rem;
  background: #FFF3C9;
  border-radius: 12px;
  padding: .4rem .6rem;
}
.score-label {
  display: block;
  font-size: .85rem;
  color: #6a6486;
  margin-bottom: .5rem;
}
#pseudoInput {
  width: 100%;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  padding: .6rem .8rem;
  border: 2px solid #EFEAF6;
  border-radius: 12px;
  margin-bottom: .8rem;
  text-align: center;
}
#pseudoInput:focus { outline: none; border-color: var(--sky); }
.score-actions {
  display: flex;
  gap: .6rem;
  justify-content: center;
  margin-bottom: .4rem;
}
#saveScore {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  background: var(--sky);
  color: var(--white);
  border: none;
  padding: .6rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 5px 0 #2f8fb8;
  cursor: pointer;
  font-size: .9rem;
}
.ghost-btn {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  background: transparent;
  color: #9089a8;
  border: none;
  padding: .6rem .8rem;
  cursor: pointer;
  font-size: .9rem;
}
.ghost-btn:hover { color: var(--ink); }
.score-saved {
  display: none;
  font-family: 'Baloo 2', sans-serif;
  color: var(--green);
  margin: .4rem 0 .8rem;
}
.win-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  margin-top: .6rem;
}
#playAgain {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  background: var(--green);
  color: var(--white);
  border: none;
  padding: .7rem 1.6rem;
  border-radius: 999px;
  box-shadow: 0 5px 0 #3a9c58;
  cursor: pointer;
}

/* ---------- Carnet de l'explorateur ---------- */
.carnet-overlay {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(7, 9, 32, 0.75);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}
.carnet-card {
  position: relative;
  margin: auto 0;
  background: #FFFCF3;
  color: var(--ink);
  border-radius: 22px;
  padding: 1.2rem 1.2rem 1.4rem;
  max-width: 780px;
  width: 100%;
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.25);
}
.carnet-card h2 {
  font-family: 'Baloo 2', sans-serif;
  margin: 0;
  text-align: center;
}
.carnet-sub { text-align: center; color: #6a6486; margin: 0 0 .8rem; font-size: .9rem; }
.carnet-close {
  position: absolute;
  top: .6rem;
  right: .7rem;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #F1EDF8;
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
}
.carnet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: .5rem;
}
.c-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  background: #0B0F33;
  color: var(--white);
  border: 3px solid #F1EDF8;
  border-radius: 14px;
  padding: .3rem .2rem .35rem;
  cursor: pointer;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: .78rem;
  line-height: 1.15;
  overflow: hidden;
}
.c-item:hover { border-color: var(--yellow); }
.c-item img { width: 76px; height: 76px; transform: scale(1.3); }
.c-item.locked img, .carnet-detail img.locked { filter: brightness(0) invert(1) opacity(.28); }
.c-item.locked span { color: var(--muted); }
.carnet-detail {
  display: flex;
  gap: .8rem;
  align-items: flex-start;
  background: #F1EDF8;
  border-radius: 16px;
  padding: .7rem;
  margin-bottom: .8rem;
  animation: cardIn .35s ease;
}
.carnet-detail > img {
  flex: 0 0 auto;
  width: 120px;
  height: 120px;
  background: #0B0F33;
  border-radius: 12px;
}
.carnet-detail p { margin: 0 0 .3rem; }
.carnet-detail ul { margin: 0 0 .4rem; padding-left: 1.1rem; font-size: .88rem; line-height: 1.35; }
.cd-name { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.2rem; color: var(--pink); }
.cd-name small { color: #8a84a6; font-size: .8rem; }
.cd-wow { font-size: .85rem; background: #FFF3C9; border-radius: 8px; padding: .3rem .5rem; }
.cd-count { font-size: .8rem; color: #6a6486; }
.cd-riddle { font-style: italic; }

/* ---------- Confettis ---------- */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  font-size: 1.4rem;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: .9; }
}

/* ---------- Écrans plus petits ---------- */
@media (max-width: 1100px) {
  .game-layout { flex-direction: column; align-items: stretch; }
  .stage-col { max-width: 1040px; width: 100%; margin: 0 auto; }
  .leaderboard { position: static; width: 100%; max-width: 560px; margin: 0 auto; flex: none; }
  .leaderboard-list { max-height: 240px; }
}
@media (max-width: 700px) {
  .game-header p { display: none; }
  .back-link { margin: .7rem 0 0 1rem; }
  .hud { gap: .35rem; margin: .5rem auto .6rem; padding: 0 .5rem; }
  .hud-item, .hud-btn, #restart { font-size: .85rem; padding: .3rem .7rem; }
  .game-layout { padding: 0 .5rem; }
  .stage { height: clamp(340px, 62vh, 560px); border-radius: 18px; }
  .mission-panel, .mission-panel.riddles { width: 210px; padding: .25rem .3rem .3rem; }
  .m-item { font-size: .78rem; }
  .m-riddle { font-size: .68rem; }
  .photo-card { width: min(300px, 70%); top: auto; bottom: 110px; right: 8px; padding: .4rem; gap: .4rem; }
  .pc-pic { width: 60px; height: 60px; }
  .pc-name { font-size: 1rem; }
  .pc-fact { font-size: .75rem; }
  .pc-wow { font-size: .7rem; }
  .copilot { max-width: calc(100% - 110px); left: 6px; bottom: 6px; }
  .bip { width: 48px; height: 52px; }
  .bubble { font-size: .78rem; padding: .35rem .6rem; margin-bottom: 22px; }
  .minimap { width: 96px; height: 96px; right: 6px; bottom: 6px; }
  .order-card { padding: 1rem 1rem .8rem; }
  .order-title { font-size: 1.2rem; }
  .order-list { grid-template-columns: 1fr; }
  .how-to { font-size: .75rem; }
  .mode-btn { font-size: .95rem; }
}

/* ---------- Téléphone : le jeu occupe tout l'écran ---------- */
.phone-only { display: none; }
#restart .phone-only { font-size: 1rem; }

body.phone {
  --top: max(6px, env(safe-area-inset-top));
  --hud-h: 34px;
  --under-hud: calc(var(--top) + var(--hud-h) + 6px);
  padding: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}
body.phone .phone-only { display: inline-block; }
body.phone .desktop-only { display: none; }
body.phone {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
body.phone button { touch-action: manipulation; }
body.phone .btn-label,
body.phone .back-link,
body.phone .game-header { display: none; }

/* HUD flottant en haut */
body.phone .hud {
  position: fixed;
  top: var(--top);
  left: 0;
  right: 0;
  z-index: 12;
  margin: 0;
  padding: 0 max(6px, env(safe-area-inset-left)) 0 max(6px, env(safe-area-inset-right));
  gap: .25rem;
  flex-wrap: nowrap;
  max-width: none;
  pointer-events: none;
}
body.phone .hud > * { pointer-events: auto; }
body.phone .hud-item,
body.phone .hud-btn,
body.phone #restart {
  height: var(--hud-h);
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  font-size: .82rem;
  padding: 0 .5rem;
  background: rgba(11, 15, 51, 0.72);
  box-shadow: none;
}
body.phone #restart { background: var(--pink); }
body.phone #quitBtn { margin-right: auto; }
@media (max-width: 400px) {
  body.phone .hud { gap: .15rem; }
  body.phone .hud-item, body.phone .hud-btn, body.phone #restart { font-size: .74rem; padding: 0 .35rem; }
}
@media (max-width: 340px) {
  body.phone .hud { gap: .1rem; }
  body.phone .hud-item, body.phone .hud-btn, body.phone #restart { font-size: .68rem; padding: 0 .25rem; }
}

/* Zone de jeu = tout l'écran */
body.phone .game-layout { display: block; padding: 0; max-width: none; }
body.phone .stage-col { max-width: none; }
body.phone .stage {
  position: fixed;
  inset: 0;
  height: auto;
  border-radius: 0;
  box-shadow: none;
}

/* Ordre de mission : petite bande d'images sous le HUD */
body.phone .mission-panel,
body.phone .mission-panel.riddles {
  top: var(--under-hud);
  left: max(6px, env(safe-area-inset-left));
  width: min(260px, 72vw);
  max-height: calc(100% - var(--under-hud) - 100px);
  padding: .2rem .3rem .3rem;
  border-radius: 12px;
}
body.phone .mission-head { font-size: .8rem; padding: 0 .15rem .15rem; }
body.phone .m-item { font-size: .75rem; padding: .1rem .35rem .1rem .1rem; gap: .35rem; }
body.phone .m-thumb { width: 26px; height: 26px; }
body.phone .m-text strong { font-size: .8rem; }
body.phone .m-riddle { font-size: .66rem; }
body.phone .m-check { width: 18px; height: 18px; font-size: .7rem; }
body.phone .m-q { font-size: .85rem; }
body.phone .mission-panel.collapsed {
  display: flex;
  align-items: center;
  gap: .15rem;
  width: auto;
  max-width: calc(100% - 110px);
  padding: .15rem .25rem;
}
body.phone .mission-panel.collapsed .mission-head { width: auto; padding: 0 .1rem; }
body.phone .mission-panel.collapsed .mission-list { flex-direction: row; flex-wrap: wrap; gap: .2rem; }
body.phone .mission-panel.collapsed .m-item { padding: .05rem; border-radius: 50%; }
body.phone .mission-panel.collapsed .m-check { width: 13px; height: 13px; font-size: .5rem; right: -2px; bottom: -2px; }

/* Mini-carte en haut à droite (le bas est pour les commandes) */
body.phone .minimap {
  top: var(--under-hud);
  bottom: auto;
  right: max(6px, env(safe-area-inset-right));
  width: 84px;
  height: 84px;
}

/* Photo : petite carte postale, sans le paragraphe « Incroyable mais vrai » (il reste dans le carnet) */
body.phone .photo-card {
  z-index: 2;
  top: var(--under-hud);
  bottom: auto;
  right: 6px;
  width: min(250px, 64vw);
  padding: .3rem;
  gap: .4rem;
  border-radius: 8px;
}
body.phone .pc-pic { width: 44px; height: 44px; border-radius: 4px; }
body.phone .pc-body p { margin-bottom: .1rem; }
body.phone .tag { font-size: .6rem; padding: 0 .35rem; }
body.phone .pc-name { font-size: .9rem; }
body.phone .pc-name small { font-size: .65rem; }
body.phone .pc-fact {
  font-size: .68rem;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
body.phone .pc-wow { display: none; }

/* Pas de croix directionnelle : on pilote avec le doigt. Il ne reste que le Turbo, en bas à droite */
body.phone .touch-pad {
  display: flex;
  justify-content: flex-end;
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 11;
  margin: 0;
  padding: 0;
}
body.phone .dpad { display: none; }
body.phone .turbo-btn { padding: .8rem 1.1rem; font-size: 1rem; opacity: .9; }

/* Bip en bas à gauche, à côté du Turbo */
body.phone .copilot {
  left: max(6px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  max-width: calc(100% - 150px);
}
body.phone .bip { width: 40px; height: 44px; }
body.phone .bubble { font-size: .76rem; padding: .3rem .55rem; margin-bottom: 18px; max-width: 260px; }

/* Classement : caché pendant le jeu, s'ouvre avec le bouton 🏆 */
body.phone .leaderboard { display: none; }
body.phone .leaderboard.open {
  display: block;
  position: fixed;
  z-index: 26;
  top: var(--under-hud);
  left: 50%;
  transform: translateX(-50%);
  width: min(340px, calc(100% - 20px));
  max-height: calc(100% - var(--under-hud) - 10px);
  overflow-y: auto;
  margin: 0;
  background: #141A4A;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.5);
}
body.phone .leaderboard .carnet-close { top: .5rem; right: .5rem; width: 32px; height: 32px; font-size: .95rem; }

/* Ordre de mission (écran de départ) plus compact */
body.phone .start-overlay { padding: .5rem; }
body.phone .order-card { padding: .7rem .8rem .6rem; border-radius: 14px; }
body.phone .order-agency,
body.phone .order-sign,
body.phone .how-to li:first-child { display: none; }
body.phone .order-head { padding-bottom: .3rem; margin-bottom: .4rem; }
body.phone .order-title { font-size: 1.1rem; }
body.phone .stamp { font-size: .75rem; border-width: 2px; }
body.phone .order-story { font-size: .85rem; line-height: 1.3; margin-bottom: .5rem; }
body.phone .mode-switch { margin-bottom: .5rem; }
body.phone .mode-btn { font-size: .9rem; padding: .2rem .3rem; }
body.phone .mode-btn small { font-size: .65rem; }
body.phone .order-sub { font-size: .9rem; margin-bottom: .25rem; }
body.phone .order-list { grid-template-columns: 1fr 1fr; gap: .25rem; margin-bottom: .5rem; }
body.phone .order-list .m-thumb { width: 30px; height: 30px; }
@media (orientation: portrait) {
  body.phone .order-list.riddles { grid-template-columns: 1fr; }
}
body.phone .order-list .m-riddle { font-size: .66rem; }
body.phone .how-to { font-size: .72rem; padding: .35rem .5rem; margin-bottom: .5rem; gap: .2rem; }
body.phone #startBtn { font-size: 1.1rem; padding: .45rem 1.4rem; }
@media (orientation: landscape) {
  body.phone .order-card { max-width: 680px; }
  body.phone .order-list { grid-template-columns: repeat(3, 1fr); }
}

/* Photos de la victoire plus petites */
body.phone .win-card { padding: 1rem 1rem; border-radius: 20px; }
body.phone .win-title { font-size: 1.2rem; }
body.phone .win-photos { gap: .25rem; margin-bottom: .5rem; }
body.phone .win-photos figure { width: 48px; padding: .15rem .15rem .05rem; }
body.phone .win-photos figure img { width: 42px; height: 42px; }
body.phone .win-photos figcaption { font-size: .5rem; }

/* ---------- Quitter le jeu ---------- */
.quit-link { text-decoration: none; display: inline-block; }
.quit-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(7, 9, 32, 0.7);
}
.quit-card {
  background: var(--white);
  color: var(--ink);
  border-radius: 22px;
  padding: 1.1rem 1.2rem .9rem;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.25);
  animation: orderIn .35s cubic-bezier(.2, 1.3, .4, 1);
}
.quit-title { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 1.3rem; margin: 0 0 .2rem; color: var(--pink); }
.quit-sub { font-size: .85rem; color: #6a6486; margin: 0 0 .8rem; }
.quit-actions { display: flex; flex-direction: column; align-items: center; gap: .3rem; }
#quitYes {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  background: var(--sky);
  color: var(--white);
  border: none;
  padding: .55rem 1.4rem;
  border-radius: 999px;
  box-shadow: 0 5px 0 #2f8fb8;
  cursor: pointer;
}
