/* Shadow Boxing : affiche imprimée en deux encres (rouge, bleu) sur papier, traits noirs.
   Le jaune est réservé à l'impact et aux alertes. */

:root {
  --paper: #F3EDE0;
  --paper-deep: #E4DAC6;
  --face: #FFF9EC;
  --ink: #16130F;
  --red: #E5382B;
  --blue: #2456E6;
  --yellow: #FFC61A;

  /* échelle d'espaces unique */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  /* formes : angles vifs partout, seules les pastilles sont rondes */
  --line: 3px;
  --drop: 5px;

  --display: "Dela Gothic One", "Arial Black", Impact, sans-serif;
  --text: "Zen Kaku Gothic New", system-ui, -apple-system, "Segoe UI", sans-serif;

  --t-xs: 13px; --t-s: 15px; --t-m: 17px; --t-l: 24px; --t-xl: 40px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  font-size: var(--t-m);
  font-weight: 500;
  line-height: 1.4;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

h1, h2, p, ol { margin: 0; padding: 0; }

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ------------------------------------------------------------------ écrans */

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  padding: max(var(--s5), env(safe-area-inset-top)) var(--s5) max(var(--s5), env(safe-area-inset-bottom));
}

#menu {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  gap: var(--s5) var(--s7);
  align-items: center;
  max-width: 1180px;
  margin: 0 auto;
  background: transparent;
}

.screen--center,
.screen--end {
  display: grid;
  place-items: center;
}

.screen--center { background: rgba(243, 237, 224, 0.86); }

/* la fin de match laisse voir la scène : la carte se pose en bas */
.screen--end { align-items: end; padding-bottom: max(var(--s7), env(safe-area-inset-bottom)); }

/* ------------------------------------------------------------------ affiche */

.poster__kicker {
  display: inline-block;
  background: var(--ink);
  color: var(--paper);
  font-weight: 900;
  font-size: var(--t-s);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: var(--s1) var(--s3);
  margin-bottom: var(--s4);
}

.poster__title {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(52px, 7.2vw, 112px);
  line-height: 0.92;
  text-transform: uppercase;
  transform: rotate(-3deg);
  transform-origin: left center;
  margin-bottom: var(--s6);
}

.poster__title span { display: block; }

.poster__title span:first-child {
  color: var(--red);
  -webkit-text-stroke: var(--line) var(--ink);
  paint-order: stroke fill;
  text-shadow: var(--drop) var(--drop) 0 var(--ink);
}

.poster__title span:last-child {
  color: var(--paper);
  -webkit-text-stroke: var(--line) var(--ink);
  paint-order: stroke fill;
  text-shadow: var(--drop) var(--drop) 0 var(--blue);
  margin-left: 0.35em;
}

.rules {
  list-style: none;
  display: grid;
  gap: var(--s2);
  max-width: 34em;
}

.rules li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: var(--s3);
  align-items: baseline;
  font-weight: 700;
}

.rules b {
  font-family: var(--display);
  font-weight: 400;
  font-size: var(--t-l);
  line-height: 1;
}

/* ------------------------------------------------------------------ cartes */

.modes {
  display: grid;
  gap: var(--s5);
}

.card {
  background: var(--face);
  border: var(--line) solid var(--ink);
  box-shadow: var(--drop) var(--drop) 0 var(--ink);
  padding: var(--s5);
  display: grid;
  gap: var(--s4);
}

.card--wide {
  width: min(460px, 100%);
  text-align: center;
  justify-items: center;
}

.card h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: var(--t-l);
  line-height: 1.1;
  text-transform: uppercase;
}

.note {
  font-size: var(--t-s);
  min-height: 1.4em;
}

.foot {
  grid-column: 1 / -1;
  justify-self: start;
  background: var(--paper);
  padding: var(--s1) var(--s2);
  font-size: var(--t-xs);
  font-weight: 700;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
}

.row--tight { gap: var(--s2); }

.card--wide .row { justify-content: center; }

/* ------------------------------------------------------------------ boutons */

.btn {
  appearance: none;
  font: inherit;
  font-weight: 900;
  font-size: var(--t-m);
  color: var(--ink);
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: 0;
  box-shadow: var(--s1) var(--s1) 0 var(--ink);
  padding: var(--s3) var(--s5);
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 60ms, box-shadow 60ms;
}

.btn:hover { background: var(--yellow); }

.btn:active {
  transform: translate(var(--s1), var(--s1));
  box-shadow: 0 0 0 var(--ink);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.levels button:focus-visible,
input:focus-visible {
  outline: var(--line) solid var(--blue);
  outline-offset: 3px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn--primary {
  background: var(--red);
  color: var(--face);
}

.btn--primary:hover { background: var(--ink); }

.btn--ghost {
  background: transparent;
  box-shadow: none;
}

.btn--small {
  font-size: var(--t-xs);
  padding: var(--s2) var(--s3);
  min-height: 36px;
  border-width: 2px;
  box-shadow: 3px 3px 0 var(--ink);
}

.icon-btn {
  appearance: none;
  font: inherit;
  font-size: var(--t-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--paper);
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 0;
  padding: var(--s2) var(--s3);
  min-height: 36px;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn[aria-pressed="false"] {
  background: var(--paper);
  color: var(--ink);
  text-decoration: line-through;
}

/* niveaux du bot : un seul choix actif */
.levels {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: var(--line) solid var(--ink);
}

.levels button {
  appearance: none;
  font: inherit;
  font-weight: 900;
  font-size: var(--t-s);
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-right: 2px solid var(--ink);
  border-radius: 0;
  padding: var(--s3) var(--s1);
  min-height: 48px;
  cursor: pointer;
}

.levels button:last-child { border-right: 0; }

.levels button[aria-checked="true"] {
  background: var(--ink);
  color: var(--paper);
}

/* ------------------------------------------------------------------ champs */

.join { display: grid; gap: var(--s2); }

.join label {
  font-size: var(--t-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.join__line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s3);
}

input[type="text"],
.join input {
  appearance: none;
  font: inherit;
  font-family: var(--display);
  font-size: var(--t-l);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: 0;
  padding: var(--s2) var(--s3);
  min-height: 48px;
  width: 100%;
}

.join input::placeholder { color: rgba(22, 19, 15, 0.28); }

/* ------------------------------------------------------------------ réglage caméra */

.screen--setup {
  background: var(--paper);
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: end;
  gap: var(--s5);
}

/* sans image caméra à montrer, le message se place au centre */
.screen--setup.is-nocam { grid-template-rows: 1fr; align-items: center; }
.screen--setup.is-nocam .setup__text { grid-row: 1; }

.setup__text {
  grid-row: 2;
  display: grid;
  gap: var(--s3);
  justify-items: center;
  text-align: center;
  max-width: 34em;
}

.setup__text h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: var(--t-xl);
  line-height: 1;
  text-transform: uppercase;
}

.setup__text p { font-weight: 700; min-height: 2.8em; }

.meter {
  width: min(320px, 80vw);
  height: var(--s4);
  border: var(--line) solid var(--ink);
  background: var(--face);
}

.meter i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--red);
  transform-origin: left center;
  transform: scaleX(0);
}

/* ------------------------------------------------------------------ vignette caméra */

.pip {
  position: fixed;
  z-index: 6;
  left: var(--s4);
  bottom: max(var(--s4), env(safe-area-inset-bottom));
  width: clamp(110px, 17vw, 210px);
  aspect-ratio: 4 / 3;
  border: var(--line) solid var(--ink);
  box-shadow: var(--s1) var(--s1) 0 var(--ink);
  background: var(--ink);
  overflow: hidden;
}

.pip video,
.pip canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pip video { transform: scaleX(-1); } /* vue miroir, comme dans une glace */

.pip__tag {
  position: absolute;
  left: 0;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 2px 6px;
}

/* masquée sans arrêter le flux : la vidéo doit continuer à produire des images */
.pip.is-off {
  opacity: 0;
  pointer-events: none;
  width: 2px;
  box-shadow: none;
}

.pip.is-setup {
  z-index: 12;
  left: 50%;
  bottom: auto;
  top: max(var(--s6), env(safe-area-inset-top));
  width: min(560px, 86vw, 58vh);
  transform: translateX(-50%);
  box-shadow: var(--drop) var(--drop) 0 var(--ink);
}

/* ------------------------------------------------------------------ barre de jeu */

.game-bar {
  position: fixed;
  z-index: 7;
  right: var(--s4);
  bottom: max(var(--s4), env(safe-area-inset-bottom));
  display: flex;
  gap: var(--s2);
}

/* ------------------------------------------------------------------ fin de match */

.result {
  font-size: var(--t-xl) !important;
}

.score {
  font-family: var(--display);
  font-size: var(--t-xl);
  line-height: 1;
}

/* ------------------------------------------------------------------ salle */

.code {
  font-family: var(--display);
  font-size: clamp(40px, 12vw, 72px);
  letter-spacing: 0.14em;
  line-height: 1;
  color: var(--blue);
  user-select: all;
}

/* ------------------------------------------------------------------ message bref */

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  top: max(var(--s4), env(safe-area-inset-top));
  transform: translateX(-50%);
  max-width: min(92vw, 560px);
  background: var(--yellow);
  border: var(--line) solid var(--ink);
  box-shadow: var(--s1) var(--s1) 0 var(--ink);
  padding: var(--s3) var(--s4);
  font-weight: 900;
  text-align: center;
}

/* ------------------------------------------------------------------ panneau développeur */

.debug {
  position: fixed;
  z-index: 30;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 92vw);
  background: var(--ink);
  color: var(--paper);
  display: grid;
  grid-template-rows: auto 1fr;
  font-size: var(--t-xs);
}

.debug__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s2) var(--s3);
  border-bottom: 2px solid var(--paper);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.debug__head .icon-btn { border-color: var(--paper); }

.debug__body {
  overflow-y: auto;
  padding: var(--s3);
  display: grid;
  gap: var(--s3);
  align-content: start;
  scrollbar-width: thin;
  scrollbar-color: var(--paper) var(--ink);
}

.debug__body::-webkit-scrollbar { width: 8px; }
.debug__body::-webkit-scrollbar-thumb { background: var(--paper); }
.debug__body::-webkit-scrollbar-track { background: var(--ink); }

.debug pre {
  margin: 0;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

#dbg-stick {
  width: 180px;
  height: 180px;
  background: var(--paper);
  justify-self: center;
}

.debug .btn--small {
  background: var(--paper);
  box-shadow: none;
}

.sliders { display: grid; gap: var(--s3); }

.slider { display: grid; gap: var(--s1); }

.slider span {
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
}

.slider output { font-family: ui-monospace, Consolas, monospace; }

input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: var(--paper); }
input[type="range"]::-moz-range-track { height: 4px; background: var(--paper); }

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 20px;
  margin-top: -8px;
  background: var(--yellow);
  border: 2px solid var(--ink);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 20px;
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: 0;
}

.check {
  display: flex;
  align-items: center;
  gap: var(--s2);
  cursor: pointer;
}

.check input {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  background: var(--ink);
  border: 2px solid var(--paper);
  border-radius: 0;
}

.check input:checked { background: var(--yellow); }

/* ------------------------------------------------------------------ portrait et petits écrans */

@media (max-width: 820px), (orientation: portrait) {
  #menu {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    align-items: start;
    gap: var(--s5);
  }

  .poster__title { font-size: clamp(40px, 13.5vw, 96px); margin-bottom: var(--s5); }
  .poster__title span:last-child { margin-left: 0.15em; }

  .levels button { font-size: var(--t-xs); }
}

@media (orientation: portrait) {
  /* en vertical : caméra en bas à droite, commandes en haut à droite */
  .pip { left: auto; right: var(--s3); width: clamp(96px, 27vw, 150px); aspect-ratio: 3 / 4; }
  .pip.is-setup { right: auto; }
  .game-bar { bottom: auto; top: max(var(--s3), env(safe-area-inset-top)); right: var(--s3); }
}

@media (max-height: 520px) and (orientation: landscape) {
  .poster__title { font-size: clamp(40px, 13vh, 72px); margin-bottom: var(--s4); }
  .rules { font-size: var(--t-s); }
  .card { padding: var(--s4); gap: var(--s3); }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}
