* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  overflow: hidden;
  font-family: Arial, sans-serif;
  background-color: #000;
  overscroll-behavior: none;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

.pixel-text {
  font-family: 'BossPixel', 'Press Start 2P', monospace;
  letter-spacing: 1px;
}

#startOverlay {
  position: fixed;
  inset: 0;
  background: #02060d;
  display: grid;
  place-items: center;
  z-index: 9999;
  overflow: hidden;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100vw;
}

#startOverlay video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.9) brightness(0.9) contrast(1.05);
  opacity: 0.9;
  pointer-events: none;
}

@media (max-width: 900px) {
  #startOverlay video {
    transform: scale(1.08);
    transform-origin: center;
  }
}

#startOverlay.setup-mode {
  background: #02060d;
  background-image: url('../assets/backgrounds/background_front_level01.png');
  background-size: cover;
  background-position: center;
}
#startOverlay.setup-mode video {
  display: none;
}

.start-content {
  position: relative;
  z-index: 1;
  text-align: center;
  color: #d0f6ff;
  text-shadow: 2px 2px 0 #0a2233;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 100vw;
  padding: 16px 10px 24px;
  overflow: visible;
  width: 100%;
  box-sizing: border-box;
}

.start-title {
  font-size: 42px;
  letter-spacing: 4px;
}

.start-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: auto;
  align-items: center;
  margin: 0 auto;
}

.start-buttons button,
.start-panel,
.start-title {
  font-family: 'BossPixel', 'Press Start 2P', monospace;
}

.start-buttons button {
  font-size: 14px;
  padding: 10px 12px;
  border: none;
  background: rgba(6, 20, 28, 0.85);
  border: 2px solid #1ac9d9;
  box-shadow: 0 0 10px rgba(26, 201, 217, 0.5), inset 0 0 6px rgba(255, 255, 255, 0.08);
  color: #ffd9a6;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  width: 170px;
  text-align: center;
}

.btn-primary {
  font-size: 16px;
}

.btn-ghost {
  color: #0cf;
  background: rgba(6, 20, 28, 0.85);
  border: 2px solid #0cf;
  box-shadow: 0 0 8px rgba(12, 207, 255, 0.35), inset 0 0 4px rgba(255,255,255,0.08);
}

.btn-img.start-img,
.btn-img.controls-img,
.btn-img.about-img {
  background: rgba(6, 20, 28, 0.85);
  border: 2px solid #1ac9d9;
  box-shadow: 0 0 8px rgba(26, 201, 217, 0.4), inset 0 0 4px rgba(255,255,255,0.08);
  width: 120px;
  height: 40px;
  margin: 0 auto;
  color: #ffd9a6;
  text-transform: uppercase;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}


.start-buttons button:active {
  transform: translateY(2px);
  box-shadow: none;
}

.start-panel {
  display: none;
  background: rgba(3, 12, 20, 0.88);
  border: none;
  padding: 12px 14px;
  font-size: 12px;
  width: min(100%, 640px);
  max-width: 640px;
  margin: 0 auto;
  font-family: 'BossPixel', 'Press Start 2P', monospace;
}
#setupStep2 .canvas-wrap,
#setupStep2 .canvas-wrap canvas {
  margin-left: auto;
  margin-right: auto;
}
.setup-wrapper {
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 0 8px;
}
.setup-panel {
  margin-top: 8px;
  display: block;
  max-width: 95vw;
  width: min(96vw, 640px);
  margin-left: auto;
  margin-right: auto;
}
#setupStep1 .panel-section,
#setupStep2 .panel-section {
  text-align: center;
}
#setupStep1 .panel-subtitle,
#setupStep2 .panel-subtitle {
  text-align: center;
}
#setupStep1 .palette-row.writer-colors,
#setupStep2 .palette-row.writer-colors {
  justify-content: center;
}
#setupStep1 .start-buttons,
#setupStep2 .start-buttons {
  align-items: center;
}
#setupStep1 .canvas-wrap,
#setupStep2 .canvas-wrap {
  margin-left: auto;
  margin-right: auto;
}
.setup-wrapper > .start-panel {
  margin-left: auto;
  margin-right: auto;
}

.panel-title {
  font-size: 14px;
  color: #ffd9a6;
  margin-bottom: 10px;
  text-align: center;
}
.collapsible { cursor: pointer; }
.section-body { display: block; }

.panel-section {
  margin-bottom: 10px;
  line-height: 1.5;
  text-align: left;
}

.panel-subtitle {
  font-size: 12px;
  color: #f1b33c;
  margin-bottom: 4px;
}
.palette-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.palette-row.writer-colors {
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.palette-row.writer-colors .swatch {
  width: 90px;
  height: 110px;
}
.palette-row.palette-tight { gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 60px;
  height: 70px;
  border: 2px solid transparent;
  background: url('../assets/sprites/writer/spray_00000.png') no-repeat center/contain;
  background-color: rgba(0,0,0,0.2);
  cursor: pointer;
  filter: none;
  image-rendering: pixelated;
  animation: swatch-spray 0.8s steps(1) infinite;
}
.swatch[data-pal="cyan"]   { filter: hue-rotate(180deg) saturate(1.2); }
.swatch[data-pal="violet"] { filter: hue-rotate(250deg) saturate(1.2); }
.swatch.color-graff[data-color="#e2e1d7"] {
  background: url('../assets/other/white-spray.png') no-repeat center/contain;
  border-color: #e2e1d7;
}
.swatch.color-graff[data-color="#c40808"] {
  background: url('../assets/other/red-spray.png') no-repeat center/contain;
  border-color: #c40808;
}
.swatch.color-graff {
  animation: none;
}
.swatch.color-graff[data-pal] { filter: none; }

@keyframes swatch-spray {
  0%   { background-image: url('../assets/sprites/writer/spray_00000.png'); }
  25%  { background-image: url('../assets/sprites/writer/spray_00003.png'); }
  50%  { background-image: url('../assets/sprites/writer/spray_00006.png'); }
  75%  { background-image: url('../assets/sprites/writer/spray_00008.png'); }
  100% { background-image: url('../assets/sprites/writer/spray_00009.png'); }
}
.swatch.active { border: 3px solid #1ac9d9; box-shadow: 0 0 8px rgba(26, 201, 217, 0.6); }
.radio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  margin: 6px 0;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(6,20,28,0.9) 0%, rgba(2,10,16,0.85) 100%);
  border: 2px solid #1ac9d9;
  box-shadow: inset 0 0 6px rgba(0,0,0,0.7), 0 0 8px rgba(26,201,217,0.35);
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.radio-row:hover {
  box-shadow: inset 0 0 8px rgba(0,0,0,0.8), 0 0 10px rgba(26,201,217,0.5);
}
.radio-row input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: #f1b33c;
  flex-shrink: 0;
}
.radio-row:active {
  transform: translateY(1px);
}
.input-pixel {
  width: 160px;
  padding: 6px 8px;
  margin-top: 4px;
  background: rgba(0,0,0,0.4);
  border: 1px solid #2dd;
  color: #fff;
  font-family: 'BossPixel', 'Press Start 2P', monospace;
  font-size: 11px;
}
.small-select { width: 130px; }
.mp-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.tiny-note { font-size: 10px; opacity: 0.8; }
.canvas-wrap {
  margin: 10px auto;
  width: 100%;
  max-width: calc(100% - 0px);
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.6);
  border: 3px solid #2dd;
  outline: 2px solid rgba(0,0,0,0.5);
  box-shadow: 0 0 14px rgba(45,221,221,0.5), inset 0 0 12px rgba(0,0,0,0.85);
  padding: 10px;
  border-radius: 4px;
  position: relative;
}
.canvas-wrap::before {
  content: "";
  position: absolute;
  inset: -6px;
  border: 2px solid rgba(49,224,255,0.85);
  opacity: 1;
  pointer-events: none;
  border-radius: 6px;
  box-shadow: 0 0 12px rgba(49,224,255,0.5);
}
.canvas-wrap canvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  min-height: 180px;
  border: 3px solid #2dd;
  background: #2a2a2a; /* grigio scuro pieno per evidenziare l'area di disegno */
  box-shadow: inset 0 0 14px rgba(0,0,0,0.9), 0 0 12px rgba(45,221,221,0.4);
  display: block;
  margin: 6px auto 0;
  border-radius: 3px;
}
@media (max-width: 640px) {
  .setup-wrapper {
    padding: 0;
    overflow-x: hidden;
  }
  .start-content {
    padding: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .start-panel,
  .setup-panel {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    padding: 8px;
    margin: 0;
  }
}
@media (max-width: 900px) {
  .setup-panel {
    max-width: 100vw;
    width: 100vw;
    padding: 4px;
  }
  .start-content {
    padding: 8px 4px;
    max-width: 100vw;
    overflow-x: hidden;
  }
  #startOverlay {
    padding: 0;
    overflow-x: hidden;
  }
  .canvas-wrap canvas {
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  .start-content { padding: 6px 8px; max-height: 100vh; overflow-y: auto; box-sizing: border-box; }
  .setup-wrapper { padding: 0; box-sizing: border-box; }
  .setup-panel {
    box-sizing: border-box;
    max-width: 100%;
    width: 100%;
    padding: 6px 8px;
    margin: 0;
    max-height: 90vh;
    overflow-y: auto;
  }
  /* canvas wrap mobile: minimale, full width nel content-box */
  .canvas-wrap {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    padding: 4px;
    margin: 8px auto;
    border: 2px solid #2dd;
    outline: none;
    box-shadow: none;
    background: rgba(0,0,0,0.5);
    overflow: hidden;
  }
  .canvas-wrap::before { display: none; }
  .canvas-wrap canvas {
    max-width: 100%;
    width: 100%;
    height: auto;
    min-height: 72px;
    border: 2px solid #2dd;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.55), 0 0 5px rgba(45,221,221,0.2);
  }
  .btn-img.start-img,
  .btn-img.controls-img,
  .btn-img.about-img {
    width: 150px;
    height: 46px;
  }
  .start-buttons { gap: 8px; }
}
.canvas-tools {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.canvas-tools.inline-tools {
  margin-top: 0;
  gap: 6px;
}
.canvas-tools.right-align { margin-left: auto; }
.canvas-hint {
  font-size: 10px;
  opacity: 0.8;
  margin-top: 4px;
}
.canvas-hint.inline-hint { margin-top: 2px; }
.tiny { font-size: 10px; padding: 4px 6px; }
.group-box {
  background: rgba(0,0,0,0.25);
  border: 1px solid #2dd;
  padding: 8px;
  margin: 6px 0;
}
.preview-box {
  width: 220px;
  height: 80px;
  margin: 6px auto;
  border: 1px solid #2dd;
  background: rgba(0,0,0,0.4);
  background-repeat: no-repeat;
  background-position: center center;
  background-size: contain;
}

#startOverlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.08) 0px,
    rgba(255, 255, 255, 0.08) 1px,
    rgba(0, 0, 0, 0) 4px
  );
  mix-blend-mode: soft-light;
  opacity: 0.35;
  pointer-events: none;
}

#gameContainer {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#arrestAnim {
  position: absolute;
  width: 210px;  /* scala al 70% (~-30%) */
  height: 280px;
  left: 50%;
  top: auto;
  bottom: 40px;
  transform: translateX(-50%);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  image-rendering: pixelated;
  z-index: 1001; /* sopra al box gameover */
  display: none;
  pointer-events: none;
  overflow: hidden;
}

.bg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 4128px; /* Larghezza dell'immagine di sfondo */
  height: 1024px; /* Altezza dell'immagine di sfondo */
  background-repeat: no-repeat;
  background-position: 0 0;
  will-change: transform;
  z-index: 0;
}
#backgroundBack {
  background-image: url('../assets/backgrounds/background_back_level01.png');
  background-size: cover;
  z-index: 0;
}
#backgroundFront {
  background-image: url('../assets/backgrounds/background_front_level01.png');
  background-size: cover;
  background-color: transparent;
  opacity: 1;
  z-index: 1;
}
#graffitiLayer {
  background: transparent;
  z-index: 2;
  pointer-events: none;
}
#foregroundLayer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5; /* sopra il personaggio */
}
.surface-debug {
  position: absolute;
  border: 1px dashed rgba(255,0,0,0.6);
  background: rgba(255,0,0,0.15);
  pointer-events: none;
  z-index: 2;
}

.hint-x {
  position: absolute;
  width: 18px;
  height: 18px;
  color: #ffd93c;
  font-family: 'BossPixel', 'Press Start 2P', monospace;
  font-size: 10px;
  line-height: 18px;
  text-align: center;
  pointer-events: none;
  z-index: 3;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
  opacity: 0.7;
  border: 2px solid rgba(255, 217, 60, 0.8);
  border-radius: 50%;
  box-sizing: border-box;
  animation: hintPulse 0.8s infinite ease-in-out;
  background: rgba(255, 217, 60, 0.2);
  transform: translate(-50%, -50%) scale(0.8);
}

@keyframes hintPulse {
  0% { transform: translate(-50%, -50%) scale(0.7); opacity: 0.5; }
  50% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.7); opacity: 0.5; }
}

/* Spray effect */
.spray-effect {
  position: absolute;
  background-image: url('../assets/sprites/graffiti/graffito01.png');
  background-size: contain;
  background-repeat: no-repeat;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.spray-effect.active {
  opacity: 1;
}

.spray-loading {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
  z-index: 4;
}

.spray-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: var(--progress, 0%);
  background: #00ff00;
  transition: width 0.1s linear;
}

.spray-loading.active::after {
  width: var(--progress, 100%);
}

#character {
  position: absolute;
  width: 100px; /* Regola secondo le tue esigenze */
  height: 150px; /* Regola secondo le tue esigenze */
  background-image: url('../assets/sprites/writer/walk_00000.png'); /* primo frame walk */
  background-repeat: no-repeat;
  background-size: contain;
  bottom: 48px; /* ancorato al marciapiede */
  left: 200px;
  z-index: 3;
  will-change: transform;
  transform-origin: center bottom;
}

#gameUI {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 4;
  color: white;
  font-size: 18px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
}

#score {
  margin-bottom: 10px;
  font-size: 20px;
  font-weight: bold;
  font-family: 'PressStart', monospace;
}

#policeWarning {
  margin-top: 8px;
  font-size: 12px;
  color: #ff5555;
  text-shadow: 0 0 6px rgba(255,0,0,0.8);
  font-family: 'PressStart', monospace;
}

#gameOverOverlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.8);
  z-index: 999;
  color: #fff;
  padding: 20px;
  box-sizing: border-box;
}

#mpResults {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.8);
  z-index: 998;
  color: #fff;
  box-sizing: border-box;
}
#mpResults .gameover-box {
  width: min(420px, 94vw);
}

.gameover-box {
  text-align: center;
  padding: 20px 22px;
  border: none; /* rimuovi cornice esterna */
  background: rgba(6, 20, 28, 0.9);
  box-shadow: none;
  width: min(400px, 94vw);
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  position: relative;
  margin-top: 0;
}

#restartBtn {
  font-family: 'BossPixel', 'Press Start 2P', monospace;
  font-size: 16px;
  padding: 10px 12px;
  background: rgba(6, 20, 28, 0.9);
  color: #ffd9a6;
  border: 2px solid #1ac9d9;
  cursor: pointer;
  width: 170px;
  box-shadow: 0 0 10px rgba(26, 201, 217, 0.45), inset 0 0 6px rgba(255,255,255,0.08);
}
#gameOverOverlay .gameover-title {
  font-family: 'BossPixel', 'Press Start 2P', monospace;
  font-size: 22px;
  color: #ffd9a6;
  text-shadow: 0 0 8px rgba(26, 201, 217, 0.45);
}
.arrest-felpa-layer {
  content: '';
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  mix-blend-mode: normal;
  filter: var(--felpa-filter, none);
  pointer-events: none;
}

@media (max-width: 900px) {
  #gameUI {
    font-size: 16px;
    top: 12px;
    left: 12px;
  }
  #score { font-size: 20px; }
  #instructions { font-size: 12px; }
  #character { transform-origin: center bottom; }
}

/* Animazione per il personaggio */
@keyframes walk {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-5px); }
  100% { transform: translateY(0px); }
}

.character-walking {
  animation: none;
}

.character-jumping {
  transform: translateY(0); /* fissato al marciapiede */
}

.character-climbing {
  background-image: url('../assets/sprites/writer/writer_climb_01.png');
  animation: none;
}

/* Spray system */
/* spray frame gestito da JS */

.spray-zone {
  position: absolute;
  border: 2px dashed red;
  background: rgba(255, 0, 0, 0.1);
  z-index: 1;
  display: block; /* visibile per debug */
}

.spray-zone.spray-active {
  background: rgba(0, 255, 0, 0.3);
  border-color: lime;
}

/* marker-zone placeholder disattivato */

#foregroundLayer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5; /* sopra il personaggio */
}

.pole {
  position: absolute;
  background-image: url('../assets/backgrounds/pole.png');
  background-repeat: no-repeat;
  background-size: contain;
  pointer-events: none;
}

.pole-02 {
  position: absolute;
  background-image: url('../assets/backgrounds/pole_02.png');
  background-repeat: no-repeat;
  background-size: contain;
  pointer-events: none;
}

.pole-light {
  position: absolute;
  /* cono di luce in CSS: gradiente morbido e clip triangolare */
  background: radial-gradient(ellipse at 50% 8%,
    rgba(255,255,255,0.36) 0%,
    rgba(210,225,255,0.24) 40%,
    rgba(180,200,230,0.0) 82%);
  clip-path: polygon(42% 0%, 58% 0%, 96% 100%, 4% 100%);
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0.28;
  filter: blur(2px);
}

.police-cone {
  position: absolute;
  pointer-events: none;
  mix-blend-mode: screen;
  background: radial-gradient(ellipse at 50% 20%,
    rgba(255,0,0,0.75) 0%,
    rgba(255,0,0,0.55) 30%,
    rgba(0,0,255,0.35) 55%,
    rgba(0,0,255,0.15) 75%,
    rgba(0,0,255,0) 100%);
  opacity: 0.85;
  z-index: 2; /* sotto al writer */
  mask-image:
    linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0.85) 70%, rgba(0,0,0,0) 100%),
    linear-gradient(to right, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 20%, rgba(0,0,0,1) 80%, rgba(0,0,0,0) 100%);
  -webkit-mask-image:
    linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0.85) 70%, rgba(0,0,0,0) 100%),
    linear-gradient(to right, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 20%, rgba(0,0,0,1) 80%, rgba(0,0,0,0) 100%);
  -webkit-mask-composite: destination-in;
  mask-composite: intersect;
}
.police-cone.foot-cone {
  opacity: 0.9;
  background: radial-gradient(ellipse at 50% 20%,
    rgba(255,0,0,0.8) 0%,
    rgba(255,0,0,0.6) 30%,
    rgba(0,0,255,0.4) 55%,
    rgba(0,0,255,0.2) 75%,
    rgba(0,0,255,0) 100%);
}

.bin {
  position: absolute;
  background-image: url('../assets/backgrounds/bidone-02.png');
  background-repeat: no-repeat;
  background-size: contain;
  pointer-events: none;
  z-index: 5;
}

.walk-debug {
  position: absolute;
  background: rgba(0, 255, 0, 0.25);
  border: 1px dashed rgba(0, 255, 0, 0.6);
  pointer-events: none;
  z-index: 2;
}
