:root {
  color-scheme: dark;
  --bg: #101018;
  --panel: #202032;
  --ink: #f4f1d8;
  --muted: #aab0c4;
  --blue: #69b8ff;
  --cyan: #70d7ff;
  --gold: #ffd15c;
  --yellow: #ffe45c;
  --danger: #ff6f7d;
  --green: #89d672;
  --shadow: #08080e;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html,
body {
  height: 100%;
  margin: 0;
  touch-action: none;
}

body {
  display: grid;
  place-items: center;
  min-height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(180deg, #111421 0%, #142234 58%, #18172b 100%);
  background-size: 24px 24px, 24px 24px, auto;
}

button,
a {
  font: inherit;
}

.machine {
  width: min(97vw, 1200px);
  padding: 14px;
  border: 4px solid #383852;
  background: #161622;
  box-shadow:
    0 0 0 4px #090910,
    0 24px 80px rgb(0 0 0 / 55%);
}

.legend {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  touch-action: pan-x;
}

.legend-items {
  min-width: 0;
  display: flex;
  flex: 1 1 auto;
  justify-content: flex-start;
  gap: 8px;
  overflow-x: auto;
  overflow-y: visible;
  overscroll-behavior-x: contain;
  padding: 3px;
  scrollbar-width: none;
  touch-action: pan-x;
}

.legend-items::-webkit-scrollbar {
  display: none;
}

.legend-item {
  position: relative;
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  background: #202032;
  border: 2px solid #08080e;
  box-shadow:
    inset 0 -3px 0 rgb(0 0 0 / 24%),
    2px 2px 0 #08080e;
}

.legend-item::after {
  position: fixed;
  left: 50vw;
  top: 54px;
  z-index: 40;
  width: max-content;
  max-width: min(260px, 72vw);
  padding: 7px 8px;
  color: #08080e;
  content: attr(data-tooltip);
  background: var(--gold);
  box-shadow: 3px 3px 0 #08080e;
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
  text-transform: none;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
}

.legend-item::before {
  position: fixed;
  left: 50vw;
  top: 44px;
  z-index: 41;
  border: 6px solid transparent;
  border-bottom-color: #08080e;
  content: "";
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
}

.legend-item:focus-visible::before,
.legend-item:focus-visible::after,
.legend-item:hover::before,
.legend-item:hover::after,
.legend-item.is-tooltip-visible::before,
.legend-item.is-tooltip-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.legend-icon {
  width: 24px;
  height: 24px;
  display: block;
  image-rendering: pixelated;
}

.legend-item.is-boosted {
  border-color: var(--gold);
  animation: boostLegendPulse 0.62s ease-in-out infinite alternate;
}

.legend-item.is-boosted .legend-text {
  color: var(--gold);
  text-shadow:
    2px 2px 0 #08080e,
    0 0 8px rgb(255 209 92 / 82%);
}

@keyframes boostLegendPulse {
  from {
    box-shadow:
      inset 0 -3px 0 rgb(0 0 0 / 24%),
      2px 2px 0 #08080e,
      0 0 0 rgb(255 209 92 / 0%);
    transform: translateY(0);
  }

  to {
    box-shadow:
      inset 0 -3px 0 rgb(0 0 0 / 24%),
      2px 2px 0 #08080e,
      0 0 12px rgb(255 209 92 / 76%);
    transform: translateY(-1px);
  }
}

.legend-control {
  flex: 0 0 auto;
  width: 34px;
  min-height: 30px;
  padding: 0;
  color: var(--gold);
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  border: 2px solid #08080e;
  background:
    linear-gradient(180deg, rgb(255 209 92 / 18%), transparent 58%),
    #202032;
  box-shadow:
    inset 0 -3px 0 rgb(0 0 0 / 24%),
    2px 2px 0 #08080e;
  cursor: pointer;
}

.arcade-back-button {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 30;
  width: auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 8px;
  color: var(--blue);
  text-decoration: none;
}

.arcade-back-icon {
  display: block;
  font-size: 34px;
  line-height: 0.72;
  transform: translateY(-1px);
  text-shadow: 2px 2px 0 #08080e;
}

.arcade-back-text {
  display: block;
  color: var(--gold);
  font-size: 12px;
  line-height: 1;
  text-shadow: 2px 2px 0 #08080e;
}

.settings-button {
  position: relative;
}

.settings-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  background: currentColor;
  transform: translate(-50%, -50%) scale(0.55);
  box-shadow:
    0 -10px 0 currentColor,
    0 10px 0 currentColor,
    -10px 0 0 currentColor,
    10px 0 0 currentColor,
    -7px -7px 0 currentColor,
    7px -7px 0 currentColor,
    -7px 7px 0 currentColor,
    7px 7px 0 currentColor,
    -4px -4px 0 2px currentColor,
    4px -4px 0 2px currentColor,
    -4px 4px 0 2px currentColor,
    4px 4px 0 2px currentColor;
}

.settings-icon::before {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  content: "";
  border: 2px solid #08080e;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.machine:fullscreen .arcade-back-button,
.machine:-webkit-full-screen .arcade-back-button {
  display: none;
}

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-inline: auto;
  overflow: hidden;
  border: 4px solid #08080e;
  background: #080812;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.game-meta {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  font-weight: 700;
  text-transform: uppercase;
  font-size: clamp(12px, 2vw, 16px);
}

.hud-box,
.target-counter {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-shadow: 2px 2px 0 #08080e;
}

.hud-box strong,
.target-counter strong {
  color: var(--gold);
}

.hud-box.is-bumped strong {
  animation: timer-bump 0.34s ease-out;
}

.target-counter {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  color: var(--ink);
  font-size: clamp(12px, 2vw, 15px);
  font-weight: 900;
  text-transform: uppercase;
  pointer-events: none;
}

.game-score {
  position: absolute;
  top: 8px;
  left: 50%;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 1px;
  transform: translateX(-50%);
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.game-score-label {
  color: #f4f1d8;
  font-size: clamp(10px, 2vw, 14px);
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #08080e;
}

.game-score-value {
  color: var(--gold);
  font-size: clamp(28px, 7vw, 52px);
  text-shadow:
    3px 0 0 #5d3155,
    0 3px 0 #5d3155,
    3px 3px 0 #08080e,
    0 0 12px rgb(255 209 92 / 45%);
}

.time-warning {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  display: grid;
  justify-items: center;
  color: #fff;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
  pointer-events: none;
  text-shadow:
    4px 0 0 #5d1320,
    0 4px 0 #5d1320,
    4px 4px 0 #08080e;
}

.time-warning[hidden] {
  display: none;
}

.time-warning-label {
  color: var(--danger);
  font-size: 22px;
  font-weight: 900;
}

.time-warning-value {
  color: #fff0a8;
  font-size: clamp(56px, 18vw, 118px);
  line-height: 0.88;
}

.effect-strip {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 2;
  display: flex;
  gap: 6px;
  align-items: flex-end;
  pointer-events: none;
}

.effect-pill {
  padding: 5px 7px;
  color: #08080e;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  background: var(--gold);
  box-shadow: 3px 3px 0 #08080e;
}

.overlay,
.settings-modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(8 8 18 / 78%);
}

.overlay[hidden],
.settings-modal[hidden] {
  display: none;
}

.settings-modal {
  position: fixed;
  z-index: 100;
  background: rgb(8 8 18 / 68%);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.settings-panel {
  max-height: calc(100dvh - 36px);
  overflow: auto;
}

.message,
.settings-panel {
  width: min(520px, 100%);
  padding: clamp(18px, 4vw, 30px);
  text-align: center;
  border: 4px solid var(--gold);
  background:
    linear-gradient(180deg, rgb(112 215 255 / 14%), transparent 58%),
    #202032;
  box-shadow:
    0 0 0 4px #08080e,
    8px 8px 0 #08080e;
}

.overlay-level {
  margin-bottom: 8px;
  color: var(--green);
  font-weight: 900;
  text-transform: uppercase;
}

.message h1 {
  margin: 0 0 10px;
  color: #fff;
  font-size: clamp(2rem, 8vw, 4.2rem);
  line-height: 0.92;
  text-transform: uppercase;
  text-shadow:
    4px 0 0 #2f9cff,
    -4px 0 0 #f5a623,
    0 5px 0 #08080e;
}

.message p {
  margin: 8px 0;
  font-weight: 700;
  line-height: 1.35;
}

.muted {
  color: var(--muted);
}

.start-button,
.settings-action,
.settings-close {
  min-height: 38px;
  padding: 9px 12px;
  color: #08080e;
  font-weight: 900;
  text-transform: uppercase;
  text-decoration: none;
  background: var(--gold);
  border: 0;
  box-shadow: 4px 4px 0 #08080e;
  cursor: pointer;
}

.start-button {
  min-width: 150px;
  margin-top: 12px;
}

.settings-panel {
  display: grid;
  gap: 12px;
  text-align: left;
}

.settings-header,
.settings-row,
.settings-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-header h2 {
  margin: 0;
  color: var(--gold);
  text-transform: uppercase;
}

.settings-pause-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 8px 10px;
  color: #08080e;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  background: var(--green);
  box-shadow: 4px 4px 0 #08080e;
}

.settings-pause-status strong {
  font-size: 11px;
}

.settings-close {
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 18px;
}

.settings-slider {
  width: 100%;
  accent-color: var(--gold);
}

.settings-action {
  min-height: 44px;
  display: grid;
  place-items: center;
  width: 100%;
  padding: 0 12px;
  font-size: 14px;
  line-height: 1.1;
  text-align: center;
}

.settings-home {
  background: var(--blue);
}

.settings-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-header h2 {
  margin: 0;
  color: var(--gold);
  text-transform: uppercase;
}

.settings-pause-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 8px 10px;
  color: #08080e;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  background: var(--green);
  box-shadow: 4px 4px 0 #08080e;
}

.settings-pause-status strong {
  font-size: 11px;
}

.settings-close {
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 18px;
}

.settings-slider {
  width: 100%;
  accent-color: var(--gold);
}

.settings-action {
  min-height: 44px;
  display: grid;
  place-items: center;
  width: 100%;
  padding: 0 12px;
  font-size: 14px;
  line-height: 1.1;
  text-align: center;
}

.settings-home {
  background: var(--blue);
}

.settings-subpanel {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 3px solid #08080e;
  background: rgb(8 8 14 / 34%);
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 20%);
}

.settings-subpanel[hidden] {
  display: none;
}

.settings-subpanel-header h3 {
  margin: 0;
  color: var(--cyan);
  font-size: 15px;
  text-transform: uppercase;
}

.settings-toggle {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}

.settings-toggle[aria-pressed="true"] {
  background: var(--blue);
}

.settings-toggle strong {
  flex: 0 0 auto;
}

.settings-meta {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.controls {
  display: none;
}

.mobile-joystick,
.jump-button {
  -webkit-tap-highlight-color: transparent;
}

@keyframes timer-bump {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.42);
  }
  100% {
    transform: scale(1);
  }
}


/* Les composants de borne ci-dessus reprennent Banana Dash. */
.machine { width: min(97vw, 1200px, calc((100dvh - 116px) * 4 / 3)); }
.stage-wrap { isolation: isolate; min-width: 0; }
#game { cursor: crosshair; touch-action: none; }
.game-meta { padding: 0 4px; }
.hud-box { flex-direction: column; gap: 0; padding: 4px 8px; background: rgb(8 15 17 / 72%); border-radius: 4px; }
.game-score { top: 10px; padding: 0 14px 5px; background: rgb(8 15 17 / 72%); border-radius: 4px; }
.game-score-value { font-size: clamp(26px, 5vw, 46px); }
.target-counter { padding: 4px 8px; background: rgb(8 15 17 / 78%); border-radius: 4px; }
.arena-progress { position: absolute; right: 12px; bottom: 10px; width: min(46%, 230px); display: grid; gap: 3px; color: var(--ink); font-size: clamp(10px, 1.5vw, 13px); text-shadow: 1px 1px #08080e; pointer-events: none; padding: 6px 8px; background: rgb(8 15 17 / 80%); border-radius: 4px; }
.arena-progress span:first-child { color: var(--gold); font-weight: 900; text-transform: uppercase; }
.arena-progress progress { width: 100%; height: 5px; border: 0; accent-color: var(--gold); }
.arena-progress progress::-webkit-progress-bar { background: #3d4140; }
.arena-progress progress::-webkit-progress-value { background: var(--gold); }
.effect-strip { right: auto; left: 8px; top: 24%; }
.effect-strip[hidden], #effectStrip[hidden], .results[hidden], .level-announcement[hidden] { display: none; }
.effect-pill { border-radius: 4px; }
.level-announcement { position: absolute; top: 35%; left: 50%; transform: translateX(-50%); padding: 12px 20px; background: rgb(10 17 22 / 90%); border: 2px solid var(--gold); color: var(--gold); text-align: center; font-size: clamp(13px, 3vw, 28px); font-weight: 900; white-space: nowrap; pointer-events: none; z-index: 4; }
.title-emblem { display: block; margin: 0 auto 14px; }
.overlay { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.message { min-width: 0; min-height: 0; max-height: 100%; overflow: auto; }
.message h1 { font-size: clamp(2rem, 6vw, 3.7rem); text-shadow: 3px 0 #836036, -3px 0 #305740, 0 5px #08080e; }
.overlay-level { font-size: 12px; }
.message p { font-size: clamp(12px, 1.5vw, 16px); }
.results { display: grid; gap: 8px; padding: 14px 0; }
.results div { display: flex; justify-content: space-between; gap: 15px; font-size: 14px; }
.results strong { color: var(--gold); }
button:focus-visible, a:focus-visible, input:focus-visible, .legend-item:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
.start-button:hover, .settings-action:hover, .settings-close:hover { background: #ff9b38; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.settings-hint { margin: -5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
#aimSensitivityValue { flex: 0 0 auto; color: var(--gold); }
/* Le plein écran utilise toute la fenêtre et réserve une vraie ligne à la scène. */
.machine:fullscreen,
.machine:-webkit-full-screen,
.machine.is-fullscreen {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  align-items: stretch;
  justify-items: stretch;
  padding: 10px;
  border: 0;
  box-shadow: none;
}
.machine:fullscreen .legend,
.machine:-webkit-full-screen .legend,
.machine.is-fullscreen .legend { width: 100%; min-width: 0; margin-bottom: 8px; }
.machine:fullscreen .stage-wrap,
.machine:-webkit-full-screen .stage-wrap,
.machine.is-fullscreen .stage-wrap {
  align-self: center;
  justify-self: center;
  width: min(100%, calc((100dvh - 80px) * 4 / 3));
  height: auto;
  min-height: 0;
  aspect-ratio: 4 / 3;
}
.machine.is-fullscreen .arcade-back-button { display: none; }
#timeBox.is-penalized strong { color: var(--danger); }
@media (max-width: 560px), (orientation: portrait) {
  :root { --mobile-controls-reserve: calc(126px + env(safe-area-inset-bottom)); }
  body { min-height: 100dvh; align-items: start; }
  .machine, .machine:fullscreen, .machine:-webkit-full-screen, .machine.is-fullscreen { width: 100vw; height: 100dvh; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); padding: max(8px, env(safe-area-inset-top)) 0 var(--mobile-controls-reserve); border: 0; box-shadow: none; }
  .legend { width: 100%; min-width: 0; margin: 0 0 6px; padding: 0 8px; gap: 6px; }
  .legend-control { width: 44px; min-height: 42px; }
  .arcade-back-button { position: static; padding: 0; justify-content: center; }
  .arcade-back-text { display: none; }
  .legend-items { gap: 4px; }
  .legend-item { padding: 3px; font-size: 11px; gap: 3px; }
  .legend-icon { width: 20px; height: 20px; }
  .stage-wrap, .machine:fullscreen .stage-wrap, .machine:-webkit-full-screen .stage-wrap, .machine.is-fullscreen .stage-wrap { width: 100%; height: 100%; min-height: 0; aspect-ratio: auto; border-inline: 0; }
  .game-meta { top: 8px; font-size: 12px; }
  .hud-box { min-height: 38px; }
  .game-score { top: 8px; }
  .game-score-value { font-size: 32px; }
  .target-counter { font-size: 12px; bottom: 8px; }
  .arena-progress { right: 8px; bottom: 8px; width: 50%; font-size: 11px; }
  .overlay { padding: 14px; }
  .message { padding: 18px 14px; }
  .message h1 { font-size: clamp(28px, 9vw, 42px); }
  .message p { font-size: 13px; }
  .title-emblem { width: 46px; height: 46px; margin-bottom: 10px; }
  .controls.mobile-control-reserve .jump-button span { font-size: 54px; line-height: 1; color: var(--gold); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.legend-item[hidden] { display: none; }

.training-exit { width: auto; padding: 6px; font-size: 12px; }
.training-exit[hidden], .hud-box[hidden], #levelProgress[hidden] { display: none; }
