@font-face {
  font-family: "PressStart";
  src: url("../assets/fonts/PressStart2P-Regular.ttf") format("truetype");
  font-display: block;
}

:root {
  --bg: #1b1128;
  --panel: #2a1b3d;
  --ink: #fff6e0;
  --accent: #ffd23f;
  --hot: #ff4f6d;
  --cool: #3fd0ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "PressStart", ui-monospace, monospace;
  /* Pas de scroll, pas de zoom, pas de sélection pendant le jeu */
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; }

#game {
  position: absolute;
  inset: 0;
}

#game canvas { display: block; touch-action: none; }

.noscript { padding: 24px; text-align: center; }

/* ---------- Modale (classement / soumission) ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 4, 20, 0.78);
  z-index: 10;
  touch-action: auto;
}
.modal[hidden] { display: none; }

.modal-box {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100% - 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: var(--panel);
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 #000;
  padding: 20px 16px 16px;
  font-size: 11px;
  line-height: 1.7;
  -webkit-user-select: text;
  user-select: text;
}

.modal-box h2 {
  margin: 0 32px 14px 0;
  font-size: 14px;
  color: var(--accent);
  font-weight: normal;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: transparent;
  border: 2px solid var(--ink);
  cursor: pointer;
}

.lb-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.btn, .lb-tabs button {
  font: inherit;
  font-size: 10px;
  color: var(--ink);
  background: #000;
  border: 2px solid var(--ink);
  padding: 8px 10px;
  cursor: pointer;
  min-height: 36px;
}
.lb-tabs button[aria-pressed="true"] { background: var(--accent); color: #000; }
.btn.primary { background: var(--hot); }
.btn:disabled { opacity: 0.5; cursor: default; }

.badge {
  display: inline-block;
  padding: 3px 6px;
  margin-bottom: 10px;
  font-size: 9px;
  background: #000;
  border: 2px solid var(--cool);
  color: var(--cool);
}
.badge.warn { border-color: var(--accent); color: var(--accent); }

.lb-table { width: 100%; border-collapse: collapse; font-size: 10px; }
.lb-table th, .lb-table td { text-align: left; padding: 6px 4px; border-bottom: 1px dashed rgba(255, 246, 224, 0.25); }
.lb-table td.num, .lb-table th.num { text-align: right; white-space: nowrap; }
.lb-table td.nick { word-break: break-all; }
.lb-empty { opacity: 0.8; }

.form-row { display: flex; gap: 8px; margin: 12px 0 6px; flex-wrap: wrap; }
.form-row input {
  flex: 1 1 160px;
  min-width: 0;
  font: inherit;
  font-size: 12px;
  padding: 8px;
  color: #000;
  background: var(--ink);
  border: 2px solid #000;
  min-height: 40px;
}
.small { font-size: 9px; opacity: 0.8; }
.error { color: var(--hot); }
.success { color: #7dff7a; }

.share-text {
  width: 100%;
  min-height: 70px;
  font: inherit;
  font-size: 10px;
  padding: 8px;
  color: #000;
  background: var(--ink);
}

/* ---------- Toast & bannière de mise à jour ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  font-size: 10px;
  background: #000;
  border: 2px solid var(--accent);
  z-index: 20;
  pointer-events: none;
}

.update-banner {
  position: fixed;
  left: 50%;
  top: calc(10px + env(safe-area-inset-top));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  font-size: 9px;
  background: #000;
  border: 2px solid var(--cool);
  z-index: 20;
  white-space: nowrap;
}
.update-banner[hidden] { display: none; }
.update-banner button { font: inherit; font-size: 9px; padding: 6px 8px; background: var(--cool); border: 0; cursor: pointer; }

/* ---------- V1.1 : écran de fin, défis, partage ---------- */
.endscreen {
  position: fixed;
  inset: 0;
  z-index: 5;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: calc(14px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  background: rgba(14, 6, 24, 0.55);
}
.endscreen[hidden] { display: none; }

.end-card {
  width: min(560px, 100%);
  margin: auto 0;
  background: var(--panel);
  border: 4px solid var(--ink);
  box-shadow: 6px 6px 0 #000;
  padding: 16px 14px;
  font-size: 11px;
  line-height: 1.6;
}

.end-head { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.end-char { height: 120px; width: auto; flex: 0 0 auto; image-rendering: auto; filter: drop-shadow(3px 3px 0 #000); }
.end-info { min-width: 0; }
.end-info p { margin: 0 0 4px; }
.end-title { font-size: 13px; }
.end-title.win { color: #7dff7a; }
.end-title.lose { color: var(--hot); }
.end-time { font-size: 30px; line-height: 1.2; color: var(--ink); text-shadow: 3px 3px 0 #000; }
.end-record { color: var(--cool); font-size: 11px; }

.verdict { border: 3px solid var(--ink); padding: 10px; margin: 6px 0 12px; background: #000; }
.verdict p { margin: 0; }
.verdict-title { font-size: 16px; margin-bottom: 6px !important; }
.verdict.win { border-color: #7dff7a; } .verdict.win .verdict-title { color: #7dff7a; }
.verdict.lose { border-color: var(--hot); } .verdict.lose .verdict-title { color: var(--hot); }
.verdict.draw { border-color: var(--accent); } .verdict.draw .verdict-title { color: var(--accent); }

.end-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.end-actions .big { grid-column: 1 / -1; font-size: 14px; min-height: 54px; }
.end-actions.secondary { margin-top: 14px; }

.btn { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; text-align: center; text-decoration: none; box-shadow: 3px 3px 0 #000; line-height: 1.3; }
.btn.blue { background: #3f6bff; }
.btn.purple { background: #7b5ea7; }
.btn.dark { background: #1b1128; }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.btn:focus-visible, .modal-close:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.challenge-block { border: 3px dashed var(--accent); padding: 12px 10px; margin: 6px 0; }
.challenge-block h3 { margin: 0 0 6px; font-size: 12px; font-weight: normal; color: var(--accent); line-height: 1.5; }
.share-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; margin: 6px 0; }
.share-wa { background: #1f9d55; }
.share-x { background: #000; }

@media (max-width: 380px) {
  .end-char { height: 96px; }
  .end-time { font-size: 24px; }
  .end-actions { grid-template-columns: 1fr; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .end-card { width: min(760px, 100%); }
  .end-char { height: 84px; }
}
.end-actions .wide, .end-actions > .btn:last-child:nth-child(odd):not(.big) { grid-column: 1 / -1; }

/* ---------- V2 : options, trophées, pause, titres ---------- */
.btn.toggle { width: 100%; margin-bottom: 8px; justify-content: flex-start; text-align: left; }
.btn.toggle[aria-pressed="true"] { background: #2e9e55; }
.trophy-progress { color: var(--accent); margin: 0 0 10px; }
.trophy-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.trophy-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border: 2px solid rgba(255, 246, 224, 0.3); background: #1b1128; }
.trophy-list li.unlocked { border-color: var(--accent); }
.trophy-list li.locked { opacity: 0.75; }
.trophy-list p { margin: 2px 0 0; }
.trophy-icon { font-size: 22px; line-height: 1; font-family: system-ui, sans-serif; }
.pause-overlay { z-index: 8; background: rgba(14, 6, 24, 0.75); align-items: center; }
.pause-card { text-align: center; width: min(380px, 100%); }
.end-titlebox { border: 3px solid var(--accent); background: #000; padding: 10px; margin: 0 0 10px; }
.end-titlebox p { margin: 0; }
.end-rank { color: var(--accent); font-size: 13px; margin-bottom: 4px !important; }
.end-quote { font-size: 10px; }
.end-cause { margin-top: 6px !important; color: #c9bfdc; font-size: 9px; }
.end-line { font-size: 10px; color: var(--cool); margin: 0 0 10px; }
.end-trophies { border: 2px solid #7dff7a; padding: 8px; margin: 0 0 10px; font-size: 10px; }
.end-trophies p { margin: 0 0 4px; }
