/*
 * Traverse qui peut ! — habillage. Les couleurs de base et le rem viennent de public/css/app.css.
 * La course est un canvas : ici, on ne règle que son cadre et ce qui se pose dessus (compteurs,
 * bouton d'objet, messages). Chaque joueur a sa couleur (--c).
 */

.tq {
  --tq-leaf: #e0ebcc;
  --tq-deep: #35664e;
  --tq-grass: #abc98b;
  --tq-candy: #ed7968;
}

.tq-host {
  max-width: 90rem;
  margin: 0 auto;
  padding: 0.5rem 0 1.5rem;
}

.tq-main {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
}

.tq-title {
  margin: 0;
  font-size: clamp(1.7rem, 3.4vw, 3.2rem);
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: -0.035em;
  text-align: center;
  overflow-wrap: anywhere;
}

.tq-hint {
  max-width: 42rem;
  margin: 0;
  color: var(--lp-mute);
  font-size: 1rem;
  line-height: 1.6;
  text-align: center;
}

.tq-eyebrow {
  margin: 0;
  color: var(--tq-deep);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.15em;
}

.tq-big {
  font-size: 5rem;
  line-height: 1.1;
}

.tq-big img {
  width: 8rem;
  height: 8rem;
}

/* Le portrait d'un animal : son modèle, en image. */
.tq-pic {
  display: block;
  max-width: none;
}

.tq-pic--none {
  display: grid;
  place-items: center;
  color: var(--lp-mute);
  font-weight: 900;
}

.tq-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
}

.tq-count {
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.tq-face {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 0.2rem solid var(--c);
  border-radius: 0.8rem;
  background: #fff;
  font-size: 1.1rem;
  line-height: 1;
}

.tq-face img {
  width: 2rem;
  height: 2rem;
}

.tq-clock {
  padding: 0.2rem 1.4rem;
  border: 2px solid var(--lp-ink);
  border-radius: 1.2rem;
  background: var(--tq-leaf);
  box-shadow: 4px 5px 0 var(--lp-ink);
  font-size: 3.6rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.tq-clock--small {
  padding: 0.1rem 0.7rem;
  border-width: 1.5px;
  border-radius: 0.7rem;
  box-shadow: none;
  font-size: 1.2rem;
}

/* ---------- choix des animaux ---------- */

.tq-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1rem;
  width: 100%;
  max-width: 62rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tq-grid li {
  display: grid;
  justify-items: center;
  gap: 0.15rem;
  padding: 1rem 0.8rem;
  border: 1px solid #cbd7c6;
  border-radius: 1.3rem;
  background: linear-gradient(155deg, #fffdf6, #edf1e3);
  box-shadow: 0 4px 0 var(--c), 0 9px 20px #304c3810;
  text-align: center;
}

.tq-grid li.is-waiting {
  border-style: dashed;
  box-shadow: none;
  color: var(--lp-mute);
}

.tq-grid__face {
  display: grid;
  place-items: center;
  min-height: 6rem;
  font-size: 3rem;
  line-height: 1.15;
}

.tq-grid__face img {
  width: 6rem;
  height: 6rem;
}

.tq-grid b {
  font-size: 1.1rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.tq-grid li > span:last-child {
  color: var(--lp-mute);
  font-size: 0.85rem;
}

.tq-animals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  width: 100%;
}

.tq-animal {
  display: grid;
  justify-items: center;
  gap: 0.1rem;
  min-width: 0;
  padding: 0.65rem 0.3rem;
  border: 1.5px solid #c5d2bc;
  border-radius: 1.1rem;
  background: linear-gradient(150deg, #fffdf5, #edf1e2);
  box-shadow: 0 3px 0 #becbb4, 0 6px 14px #304c380a;
  font-size: 0.8rem;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.tq-animal__face img {
  width: 4.1rem;
  height: 4.1rem;
}

.tq-animal b {
  max-width: 100%;
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tq-animal[aria-pressed="true"] {
  border-color: #4e8265;
  background: linear-gradient(145deg, #eef5dc, #d3e4bc);
  box-shadow: 0 3px 0 #527957, 0 0 0 2px #4e826530;
  transform: translateY(-2px);
}

@media (hover: hover) {
  .tq-animal:not(:disabled):hover {
    border-color: #719472;
    transform: translateY(-3px);
    box-shadow: 0 5px 0 #becbb4, 0 9px 16px #304c3814;
  }
}

.tq-animal:disabled {
  border-style: dashed;
  box-shadow: none;
  color: var(--lp-mute);
}

.tq-animal:disabled .tq-animal__face {
  opacity: 0.35;
  filter: grayscale(0.6);
}

.tq-animal:focus-visible,
.tq-item:focus-visible {
  outline: 0.2em solid var(--lp-purple);
  outline-offset: 0.15em;
}

/* ---------- la course : ce qui est commun ---------- */

.tq-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.tq-center {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: 86%;
  padding: 0.5rem 1.1rem;
  border: 2px solid var(--lp-ink);
  border-radius: 1rem;
  background: rgba(255, 253, 248, 0.95);
  box-shadow: 3px 4px 0 var(--lp-ink);
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1.3;
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.tq-center.is-count {
  padding: 0.5rem 2rem;
  font-size: 7rem;
  line-height: 1.1;
}

.tq-center[hidden],
.tq-item[hidden],
.tq-done[hidden],
.tq-chip[hidden],
.tq-lane[hidden] {
  display: none;
}

.tq-chip,
.tq-fx,
.tq-hud__rank,
.tq-hud__time,
.tq-feed li {
  padding: 0.2rem 0.75rem;
  border: 1.5px solid var(--lp-ink);
  border-radius: 2rem;
  background: #fffdf8;
  font-size: 0.9rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tq-chip--alert {
  background: #fbd9dd;
  color: var(--lp-coral-deep);
}

/* ---------- grand écran ---------- */

.tq-host .tq-race {
  display: grid;
  gap: 0.9rem;
}

.tq-arena {
  position: relative;
  height: clamp(17rem, 51dvh, 35rem);
  overflow: hidden;
  border: 2px solid #5a7867;
  border-radius: 1.2rem;
  background: var(--tq-grass);
  box-shadow: 0 5px 0 #c7d5ba, 0 12px 30px #344e3917;
}

.tq-arena::after,
.tq-phone .tq-race::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 #ffffe666, inset 0 -12px 30px #2744490d;
  pointer-events: none;
}

.tq-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  min-height: 2rem;
}

.tq-chips,
.tq-feed {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tq-chips {
  flex: none;
}

.tq-feed {
  justify-content: flex-end;
}

.tq-feed li {
  animation: tq-pop 0.25s ease-out;
}

.tq-feed li.is-malus {
  background: #fbe6e9;
}

.tq-board__head {
  display: flex;
  justify-content: space-between;
  padding: 0 1rem 0 0.5rem;
  color: var(--tq-deep);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tq-board {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tq-lane {
  display: grid;
  grid-template-columns: 2rem auto minmax(6rem, 11rem) minmax(0, 1fr) 1.8rem 6.5rem;
  align-items: center;
  gap: 0.7rem;
  padding: 0.25rem 1rem 0.25rem 0.4rem;
  border: 1px solid var(--lp-line);
  border-radius: 0.9rem;
  background: #fff;
}

.tq-lane.is-done {
  border-color: var(--lp-ink);
  background: #fff7db;
}

.tq-lane__rank {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1.5px solid var(--lp-ink);
  border-radius: 0.6rem;
  background: var(--c);
  font-weight: 900;
}

.tq-lane__name {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.tq-lane__name b {
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tq-lane__fx {
  flex: none;
  font-size: 0.95rem;
  white-space: nowrap;
}

.tq-lane__track {
  position: relative;
  height: 0.8rem;
  margin: 0 1.9rem 0 1.2rem;
  border-radius: 1rem;
  background: #ece7f1;
}

/* Le bout de la piste : la ligne d'arrivée. */
.tq-lane__track::after {
  content: "🏁";
  position: absolute;
  top: 50%;
  right: -1.7rem;
  font-size: 1.1rem;
  line-height: 1;
  transform: translateY(-50%);
}

.tq-lane__fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: inherit;
  background: var(--c);
  transition: width 1s linear;
}

.tq-lane__mark {
  position: absolute;
  top: 50%;
  line-height: 1;
  transform: translate(-50%, -62%);
  transition: left 1s linear;
}

.tq-lane__mark img {
  width: 2.5rem;
  height: 2.5rem;
}

.tq-lane__item {
  font-size: 1.3rem;
  line-height: 1;
  text-align: center;
}

/* Ce qu'il reste à parcourir, en gros : c'est le chiffre que toute la salle regarde. */
.tq-lane__state {
  display: grid;
  justify-items: end;
  line-height: 1.1;
  white-space: nowrap;
}

.tq-lane__left {
  font-size: 1.45rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.tq-lane__note {
  color: var(--lp-mute);
  font-size: 0.68rem;
  font-weight: 800;
}

.tq-lane__note:empty {
  display: none;
}

/* ---------- téléphone ---------- */

.tq-phone {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 0.5rem;
}

.tq-phone .tq-main {
  gap: 0.8rem;
}

.tq-phone .tq-title {
  font-size: 1.5rem;
}

.tq-phone .tq-hint {
  font-size: 0.9rem;
}

.tq-phone .tq-race {
  position: relative;
  flex: 1;
  min-height: 24rem;
  margin: 0 -0.5rem;
  overflow: hidden;
  border: 2px solid #5a7867;
  border-radius: 1.1rem;
  background: var(--tq-grass);
  /* Le doigt fait bondir l'animal : il ne doit ni faire défiler la page, ni rien sélectionner. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.tq-phone .tq-canvas {
  touch-action: none;
}

.tq-hud {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  gap: 0.4rem;
  padding: 0.5rem 0.5rem 1.4rem;
  /* Un voile sombre : les compteurs restent lisibles quel que soit le décor qui défile dessous. */
  background: linear-gradient(rgba(36, 63, 65, 0.46), rgba(36, 63, 65, 0));
  pointer-events: none;
}

.tq-hud__top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tq-track {
  position: relative;
  flex: 1;
  height: 0.5rem;
  margin: 0 0.8rem;
  border-radius: 1rem;
  background: rgba(255, 253, 248, 0.75);
}

.tq-track__dot {
  position: absolute;
  top: 50%;
  left: 0;
  line-height: 1;
  opacity: 0.9;
  transform: translate(-50%, -62%);
  transition: left 0.5s linear;
}

.tq-track__dot img {
  width: 1.5rem;
  height: 1.5rem;
}

.tq-track__dot.is-me {
  z-index: 1;
  opacity: 1;
}

.tq-track__dot.is-me img {
  width: 2.25rem;
  height: 2.25rem;
}

.tq-fxs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tq-fxs:empty {
  display: none;
}

/* Les messages se posent en haut, loin devant l'animal : ils ne cachent pas les voitures qui arrivent. */
.tq-phone .tq-center {
  top: 5.6rem;
  width: max-content;
  padding: 0.35rem 0.9rem;
  font-size: 0.95rem;
  transform: translate(-50%, 0);
}

.tq-phone .tq-center.is-count {
  top: 36%;
  padding: 0.5rem 2rem;
  font-size: 4.5rem;
  transform: translate(-50%, -50%);
}

.tq-item {
  position: absolute;
  left: max(0.8rem, env(safe-area-inset-left));
  bottom: max(0.8rem, env(safe-area-inset-bottom));
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  width: 6.2rem;
  height: 6.2rem;
  padding: 0;
  border: 2.5px solid var(--lp-ink);
  border-radius: 50%;
  background: var(--lp-amber);
  box-shadow: 3px 4px 0 var(--lp-ink);
  color: var(--lp-ink);
  touch-action: manipulation;
}

.tq-item:active {
  box-shadow: inset 0 3px 5px #263d4126, 0 1px 0 var(--lp-ink);
  filter: brightness(0.97);
}

.tq-item.is-malus {
  background: #f6a9b8;
}

.tq-item:disabled {
  opacity: 0.75;
}

.tq-item.is-empty {
  border-color: #698176;
  background: #eff2e3e8;
  box-shadow: 0 3px 0 #698176;
  color: #3e5e50;
  opacity: 0.85;
}

.tq-item__face {
  font-size: 2.5rem;
  line-height: 1.1;
}

.tq-item b {
  max-width: 5.2rem;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1.1;
}

.tq-item.is-rolling .tq-item__face {
  animation: tq-roll 0.5s linear infinite;
}

.tq-done {
  position: absolute;
  top: 22%;
  right: 8%;
  left: 8%;
  display: grid;
  justify-items: center;
  gap: 0.3rem;
  padding: 1.1rem;
  border: 2px solid var(--lp-ink);
  border-radius: 1.2rem;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 4px 5px 0 var(--lp-ink);
  text-align: center;
  pointer-events: none;
}

.tq-done .tq-big {
  font-size: 3rem;
}

.tq-done strong {
  font-size: 1.7rem;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.tq-done p {
  margin: 0.3rem 0 0;
  color: var(--lp-mute);
  font-size: 0.85rem;
}

/* ---------- résultats ---------- */

.tq-results {
  display: grid;
  gap: 0.55rem;
  width: 100%;
  max-width: 44rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tq-results li {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 1rem 0.5rem 0.7rem;
  border: 1px solid var(--lp-line);
  border-radius: 0.9rem;
  background: #fff;
}

.tq-results li.is-first {
  border-color: var(--lp-ink);
  background: #fff7db;
  box-shadow: 2px 3px 0 var(--lp-amber-deep);
}

.tq-results li.is-me {
  outline: 0.18rem solid var(--lp-purple);
  outline-offset: 0.1rem;
}

.tq-results__rank {
  flex: none;
  width: 2.3rem;
  font-weight: 900;
}

.tq-results__name {
  flex: 1;
  min-width: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.tq-results__detail {
  color: var(--lp-mute);
  font-size: 0.85rem;
  white-space: nowrap;
}

.tq-results__gain {
  padding: 0.1rem 0.55rem;
  border-radius: 1rem;
  background: var(--tq-leaf);
  color: var(--tq-deep);
  font-size: 0.85rem;
  font-weight: 900;
}

.tq-results b {
  min-width: 3.4rem;
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
}

.tq-award {
  margin: 0;
  padding: 0.6rem 1rem;
  border-radius: 0.8rem;
  background: #f8e9c4;
  color: #765617;
  font-weight: 800;
  text-align: center;
}

.tq-phone .tq-results__detail {
  font-size: 0.75rem;
}

@keyframes tq-roll {
  from { transform: rotate(0); }
  to { transform: rotate(360deg); }
}

@keyframes tq-pop {
  from { opacity: 0; transform: translateY(-0.4rem); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 860px), (orientation: portrait) {
  .tq-arena {
    height: clamp(13rem, 38dvh, 24rem);
  }

  .tq-lane {
    grid-template-columns: 2rem auto minmax(0, 1fr) 1.8rem auto;
    row-gap: 0.9rem;
    padding-bottom: 0.5rem;
  }

  .tq-lane__track {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tq-item.is-rolling .tq-item__face,
  .tq-feed li {
    animation: none;
  }
  .tq-animal,
  .tq-lane__fill,
  .tq-lane__mark,
  .tq-track__dot {
    transition: none;
  }
}

/* ---------- mode solo (screen.php + solo.js) : une page à part, sans salle ---------- */

.tqs {
  display: flex;
  flex-direction: column;
  width: min(34rem, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 1rem calc(0.8rem + env(safe-area-inset-bottom));
}

.tqs-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0;
}

.tqs-brand {
  color: var(--lp-purple);
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: -0.07em;
  text-decoration: none;
}

.tqs-back {
  color: var(--lp-mute);
  font-size: 0.85rem;
  font-weight: 800;
  text-decoration: none;
}

.tqs-back:hover {
  color: var(--lp-ink);
}

.tqs-game {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.tqs-menu .tq-main {
  gap: 0.9rem;
  padding: 0.5rem 0 1.5rem;
}

.tqs-menu .tq-title {
  font-size: clamp(1.7rem, 7vw, 2.4rem);
}

.tqs-record {
  margin: 0;
  padding: 0.3rem 1rem;
  border: 1.5px solid var(--lp-ink);
  border-radius: 2rem;
  background: var(--tq-leaf);
  font-size: 0.95rem;
}

.tqs-record b {
  font-weight: 900;
}

.tqs-rules {
  display: grid;
  gap: 0.45rem;
  width: 100%;
  margin: 0.4rem 0 0;
  padding: 1rem 1rem 1rem 2rem;
  border: 1px solid var(--lp-line);
  border-radius: 1rem;
  background: #fff;
  color: var(--lp-mute);
  font-size: 0.85rem;
  line-height: 1.5;
}

.tqs-top {
  justify-content: space-between;
}

.tqs-distance {
  font-size: 1.25rem;
}

.tqs-lives {
  letter-spacing: 0.1em;
}

.tq-center.tqs-word.is-count {
  font-size: 2.6rem;
  white-space: nowrap;
}

/* À combien est la coulée de caramel. */
.tqs-gap {
  position: absolute;
  bottom: calc(4.2rem + env(safe-area-inset-bottom));
  right: max(0.8rem, env(safe-area-inset-right));
  padding: 0.25rem 0.8rem;
  border: 1.5px solid var(--lp-ink);
  border-radius: 2rem;
  background: #fbe3bd;
  font-size: 0.9rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.tqs-gap.is-close {
  background: #fbd9dd;
  color: var(--lp-coral-deep);
  animation: tqs-pulse 0.6s ease-in-out infinite alternate;
}

.tqs-over {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(28rem, calc(100% - 2rem));
  transform: translate(-50%, -50%);
  z-index: 4;
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  padding: 1.2rem;
  border: 2px solid var(--lp-ink);
  border-radius: 1.2rem;
  background: rgba(255, 253, 248, 0.97);
  box-shadow: 4px 5px 0 var(--lp-ink);
  text-align: center;
}

.tqs-over__face img {
  width: 5.5rem;
  height: 5.5rem;
}

.tqs-over strong {
  font-size: 3.4rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
}

.tqs-over__note {
  margin: 0 0 0.3rem;
  color: var(--lp-mute);
  font-weight: 800;
}

.tqs-over__hub {
  color: var(--lp-mute);
  font-size: 0.85rem;
  font-weight: 800;
}

@keyframes tqs-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  .tqs-gap.is-close {
    animation: none;
  }
}

/* Pendant la course, la page devient le terrain. Les menus retrouvent leur
 * défilement normal dès que la course est quittée (sans état global à nettoyer). */
.lp-html:has(.tqs-run, .lp-stage .tq--race),
.lp-body:has(.tqs-run, .lp-stage .tq--race) {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

.tqs:has(.tqs-run),
.lp-phone:has(.tq--race),
.lp-host:has(.tq--race) {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  padding: 0;
}

.tqs:has(.tqs-run) .tqs-nav,
.lp-host:has(.tq--race) .lp-endbar,
.lp-host:has(.tq--race) .lp-top > :not(.lp-top__tools),
.lp-phone:has(.tq--race) .lp-me > :not(.lp-iconbtn) {
  display: none;
}

.lp-phone:has(.tq--race) .lp-stage,
.lp-host:has(.tq--race) .lp-stage,
.lp-body .tq--race,
.tqs-run {
  width: 100%;
  max-width: none;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
}

.lp-body .tq--race > .tq-race,
.tqs-run > .tq-race,
.lp-body .tq--race .tq-arena {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.lp-body .tq--race .tq-arena::after,
.lp-body .tq-phone .tq-race::after { display: none; }

.lp-body .tq-phone .tq-hud {
  padding: calc(0.7rem + env(safe-area-inset-top)) max(0.7rem, env(safe-area-inset-right)) 1.4rem max(0.7rem, env(safe-area-inset-left));
}

.lp-phone:has(.tq--race) .lp-me,
.lp-host:has(.tq--race) .lp-top {
  position: absolute;
  right: max(0.7rem, env(safe-area-inset-right));
  z-index: 6;
  gap: 0.5rem;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}

.lp-phone:has(.tq--race) .lp-me { bottom: max(0.8rem, env(safe-area-inset-bottom)); }
.lp-host:has(.tq--race) .lp-top { top: calc(0.7rem + env(safe-area-inset-top)); }

.tqs-menu-button,
.tq-standings > summary {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 0.5rem 0.85rem;
  border: 1.5px solid var(--lp-ink);
  border-radius: 0.85rem;
  background: #fffdf8ee;
  color: var(--lp-ink);
  font: 900 0.85rem 'LP Nunito', sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}

.tqs-menu-button {
  position: absolute;
  right: max(0.8rem, env(safe-area-inset-right));
  bottom: max(0.8rem, env(safe-area-inset-bottom));
  z-index: 3;
}

.tq-standings { position: relative; }
.tq-standings > summary { width: max-content; }
.tq-standings__panel { padding-top: 0.8rem; }
.tq-standings__panel .tq-board__head { margin-bottom: 0.7rem; }

.lp-body .tq-host.tq--race .tq-bar {
  position: absolute;
  top: calc(0.7rem + env(safe-area-inset-top));
  left: max(0.7rem, env(safe-area-inset-left));
  right: calc(10rem + env(safe-area-inset-right));
  z-index: 2;
  flex-wrap: wrap;
  pointer-events: none;
}

.lp-body .tq-host.tq--race .tq-chips { flex-shrink: 1; }
.lp-body .tq-host.tq--race .tq-standings {
  position: absolute;
  left: max(0.8rem, env(safe-area-inset-left));
  bottom: max(0.8rem, env(safe-area-inset-bottom));
  z-index: 5;
}

.lp-body .tq-host.tq--race .tq-standings__panel {
  position: absolute;
  bottom: 3.5rem;
  left: 0;
  width: min(52rem, calc(100vw - 1.6rem - env(safe-area-inset-left) - env(safe-area-inset-right)));
  max-height: calc(100dvh - 9rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: 0.8rem;
  overflow-y: auto;
  border: 1.5px solid var(--lp-ink);
  border-radius: 1rem;
  background: #fffdf8f5;
}

.lp-body .tq-host.tq--race .tq-actions {
  position: absolute;
  right: max(0.8rem, env(safe-area-inset-right));
  bottom: max(0.8rem, env(safe-area-inset-bottom));
  z-index: 2;
  margin: 0;
}

/* Les écrans bas (téléphone en paysage) gardent aussi les commandes de fin. */
@media (max-height: 540px) {
  .tqs-over { gap: 0.3rem; padding: 0.7rem 1rem; }
  .tqs-over__face { display: none; }
  .tqs-over strong { font-size: 2.3rem; }
  .tqs-over .lp-btn { min-height: 44px; padding: 0.45rem 1rem; font-size: 0.95rem; }
  .tqs-over__note { margin: 0; }
  .tq-phone .tq-item { width: 4.8rem; height: 4.8rem; }
  .tq-phone .tq-item__face { font-size: 1.9rem; }
  .tq-phone .tq-center:not(.is-count) { top: calc(3.5rem + env(safe-area-inset-top)); }
}

@media (max-width: 360px) {
  .tqs-top { gap: 0.3rem; }
  .tqs-top > * { padding-inline: 0.5rem; font-size: 0.85rem; }
}
