:root { --bg:#150b2b; --panel:#2a1650; --ink:#fff6e0; --pink:#ff4d6d; --yellow:#ffd23f; --cyan:#4cc9f0; --green:#3ddc97; }
* { box-sizing: border-box; }
body { margin:0; min-height:100vh; color:var(--ink); display:flex; justify-content:center; padding:16px;
  font:700 14px/1.4 "Courier New", monospace; letter-spacing:1px;
  background-color:var(--bg);
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size:16px 16px; }
.pop { animation:pop .35s steps(6) both; }
@keyframes pop { from { transform:translateY(16px); opacity:0; } }

#game { width:min(960px,100%); display:flex; flex-direction:column; gap:14px; }
#game[hidden], #lobby[hidden] { display:none; }

.screen { position:relative; border:4px solid var(--ink); box-shadow:0 0 0 4px #000, 8px 8px 0 4px #000, 0 0 40px rgba(179,136,255,.35); background:#000; }
.screen::after { content:''; position:absolute; inset:0; pointer-events:none;
  background:repeating-linear-gradient(0deg, rgba(0,0,0,.14) 0 1px, transparent 1px 3px);
  box-shadow:inset 0 0 60px rgba(0,0,0,.55); }
canvas { display:block; width:100%; height:auto; image-rendering:pixelated; }

.panel { background:var(--panel); border:4px solid var(--ink); box-shadow:6px 6px 0 #000; padding:14px; position:relative; }
.panel.slim { padding:10px 14px; }
.panel::before { content:''; position:absolute; inset:0; pointer-events:none; border-top:4px solid rgba(255,255,255,.12); }

#lobby { align-self:center; width:min(400px,100%); display:flex; flex-direction:column; gap:14px; text-align:center; margin-top:6vh; }
#lobby h1 { margin:0; font-size:46px; line-height:1.05; letter-spacing:3px; }
#lobby h1 span { display:inline-block; text-shadow:4px 4px 0 #000; animation:hop 1.2s steps(2) infinite; }
#lobby h1 span:nth-child(5n+1) { color:var(--pink); } #lobby h1 span:nth-child(5n+2) { color:var(--yellow); }
#lobby h1 span:nth-child(5n+3) { color:var(--green); } #lobby h1 span:nth-child(5n+4) { color:var(--cyan); }
#lobby h1 span:nth-child(5n) { color:#b388ff; }
#lobby h1 span:nth-child(2n) { animation-delay:.3s; } #lobby h1 span:nth-child(3n) { animation-delay:.6s; }
@keyframes hop { 50% { transform:translateY(-6px); } }
#lobby p { margin:0; opacity:.85; }

label { display:flex; gap:8px; align-items:center; justify-content:space-between; }
#name, #room { background:#0a0618; color:var(--ink); border:3px solid var(--ink); padding:8px; font:inherit; width:160px; text-transform:uppercase; outline:none; }
#name { text-transform:none; }
#name:focus, #room:focus { border-color:var(--yellow); box-shadow:3px 3px 0 #000; }
#err { color:var(--pink); min-height:1em; }

.bar { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.grow { flex:1; }
.lbl { font-size:12px; color:var(--cyan); margin-right:4px; }

.btn { background:var(--yellow); color:#000; border:3px solid #000; box-shadow:4px 4px 0 #000, inset 0 -4px 0 rgba(0,0,0,.2), inset 0 3px 0 rgba(255,255,255,.4);
  padding:8px 14px; font:inherit; cursor:pointer; }
.btn:hover { filter:brightness(1.12); }
.btn:active { transform:translate(3px,3px); box-shadow:1px 1px 0 #000; }
.btn.big { font-size:18px; padding:12px; background:var(--pink); color:#fff; }
.btn.small { font-size:12px; padding:6px 10px; background:var(--cyan); }
.btn.alt { background:#b388ff; }
.btn.on { background:var(--pink); color:#fff; animation:blink 1s steps(2) infinite; }
@keyframes blink { 50% { filter:brightness(1.25); } }

.inst { background:#0a0618; color:var(--ink); border:3px solid var(--ink); box-shadow:3px 3px 0 #000; padding:8px 14px; font:inherit; cursor:pointer; }
.inst:hover { border-color:var(--yellow); }
.inst.sel { background:var(--c, var(--yellow)); color:#000; border-color:#000; transform:translateY(-2px); }

input[type=range] { accent-color:var(--pink); vertical-align:middle; }

#grid { display:grid; gap:4px; overflow-x:auto; }
.row { display:grid; grid-template-columns:60px repeat(16, minmax(22px,1fr)); gap:4px; align-items:center; }
.row span { font-size:11px; opacity:.8; }
.cell { aspect-ratio:1; min-height:22px; background:#0a0618; border:2px solid #3b2a66; cursor:pointer; padding:0; transition:transform .05s; }
.cell:nth-child(4n+2) { border-color:#6b4fa8; }
.cell:hover { border-color:var(--yellow); }
.cell.on { background:var(--c); border-color:#fff; box-shadow:inset 0 3px 0 rgba(255,255,255,.4), inset 0 -3px 0 rgba(0,0,0,.25); }
.cell.now { outline:3px solid var(--ink); transform:scale(1.08); position:relative; z-index:1; }

/* ---- Phase 2 ---- */
select { background:#0a0618; color:var(--ink); border:3px solid var(--ink); padding:6px 8px; font:inherit; font-size:12px; cursor:pointer; outline:none; }
select:focus { border-color:var(--yellow); }
.slot { width:32px; height:32px; background:#0a0618; color:var(--ink); border:3px solid #6b4fa8; font:inherit; cursor:pointer; opacity:.55; }
.slot.act { opacity:1; border-color:var(--ink); }
.slot.cur { background:var(--yellow); color:#000; transform:translateY(-3px); }
.chan { display:flex; align-items:center; gap:6px; background:#0a0618; border:3px solid #3b2a66; padding:4px 8px; }
.chan input { width:70px; }
.chan .dot { width:10px; height:10px; display:inline-block; }
.chan .cname { font-size:11px; min-width:40px; }
.tiny { width:24px; height:24px; background:#3b2a66; color:var(--ink); border:2px solid #000; font:inherit; font-size:11px; cursor:pointer; padding:0; }
.tiny.on { background:var(--pink); }
#insts .inst { font-size:12px; padding:6px 10px; }

/* ---- Phase 3 ---- */
.chat { display:flex; flex-direction:column; gap:8px; }
#chatlog { height:92px; overflow-y:auto; background:#0a0618; border:3px solid #3b2a66; padding:6px 8px; font-size:12px; display:flex; flex-direction:column; gap:2px; }
#chatlog .sys { opacity:.55; font-style:italic; }
#chatlog b { margin-right:6px; }
#chatform { flex-wrap:nowrap; }
#chatin { flex:1; min-width:0; background:#0a0618; color:var(--ink); border:3px solid var(--ink); padding:8px; font:inherit; outline:none; }
#chatin:focus { border-color:var(--yellow); }
.react { background:#0a0618; border:3px solid #3b2a66; box-shadow:3px 3px 0 #000; font-size:18px; padding:2px 8px; cursor:pointer; }
.react:hover { border-color:var(--yellow); transform:translateY(-2px); }
.react:active { transform:translateY(1px); }
.chan .tiny.view { background:var(--cyan); color:#000; }
.chan .tiny.kick { background:#7a1f2b; }
.chan .crown { font-size:12px; }
.btn:disabled, input:disabled { opacity:.45; cursor:not-allowed; filter:grayscale(.6); }
.cell.ghost { outline:3px dashed var(--c); outline-offset:1px; position:relative; z-index:2; }
.cell.ghost::after { content:attr(data-who); position:absolute; left:50%; top:-16px; transform:translateX(-50%); background:var(--c); color:#000; font-size:9px; padding:0 3px; white-space:nowrap; pointer-events:none; }
.viewing { color:var(--yellow); }
.cell.ro { cursor:default; }

/* ---- Phase 4 ---- */
.btn.rec { background:#7a1f2b; color:#fff; }
.btn.rec.live { background:var(--pink); animation:blink 1s steps(2) infinite; }
.listenonly { display:none; }
body.listen .listenonly { display:flex; }
body.listen .editor, body.listen .tiny.view { display:none !important; }
#lobby[data-mode="listen"] .roomonly { display:none; }
#toast { position:fixed; left:50%; bottom:24px; transform:translateX(-50%); background:var(--yellow); color:#000; border:3px solid #000; box-shadow:4px 4px 0 #000; padding:10px 16px; z-index:10; max-width:90vw; }
#toast[hidden] { display:none; }

/* ---- Phase 5 : connexion + tactile / mobile ---- */
#conn { position:fixed; top:0; left:0; right:0; z-index:20; background:var(--pink); color:#fff; text-align:center; padding:8px; border-bottom:4px solid #000; animation:blink 1s steps(2) infinite; }
#conn[hidden] { display:none; }
button, select, input[type=range] { touch-action:manipulation; }
#grid, .cell { touch-action:pan-y; user-select:none; -webkit-user-select:none; }
.cell { -webkit-tap-highlight-color:transparent; }
@media (max-width:640px) {
  body { padding:8px; }
  #game { gap:10px; }
  #lobby { margin-top:2vh; padding:12px; }
  #lobby h1 { font-size:36px; }
  .panel { padding:10px; }
  .btn { padding:10px 12px; }
  .btn.small { padding:9px 10px; }
  .inst { padding:9px 10px; }
  .tiny { width:34px; height:34px; font-size:13px; }
  .slot { width:38px; height:38px; }
  .react { font-size:22px; padding:4px 10px; }
  .chan { flex-wrap:wrap; }
  .chan input { width:64px; }
  #chatlog { height:80px; }
  input, select, #chatin, #name, #room { font-size:16px; } /* évite le zoom automatique d'iOS au focus */
  #name, #room { width:140px; }
  .row { gap:3px; }
  #grid { gap:3px; padding:8px; }
  .cell { min-height:30px; }
  input[type=range] { height:28px; }
}
@media (max-width:640px) { .chat { order:20; } } /* sur téléphone : transport et grille d'abord, chat en bas */

/* ---- Identité v2 : pixels plus fins (bordures 3 px → 2 px, ombres plus courtes, trame serrée) ---- */
body { background-size:8px 8px; background-image:
    linear-gradient(rgba(255,255,255,.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.028) 1px, transparent 1px); }
.screen { border-width:3px; box-shadow:0 0 0 3px #000, 6px 6px 0 3px #000, 0 0 36px rgba(179,136,255,.3); }
.screen::after { background:repeating-linear-gradient(0deg, rgba(0,0,0,.10) 0 1px, transparent 1px 2px); box-shadow:inset 0 0 50px rgba(0,0,0,.5); }
.panel { border-width:3px; box-shadow:4px 4px 0 #000; }
.panel::before { border-top-width:2px; }
.btn { border-width:2px; box-shadow:3px 3px 0 #000, inset 0 -3px 0 rgba(0,0,0,.2), inset 0 2px 0 rgba(255,255,255,.4); }
.btn:active { transform:translate(2px,2px); box-shadow:1px 1px 0 #000; }
.inst { border-width:2px; box-shadow:2px 2px 0 #000; }
.inst.sel { transform:translateY(-1px); }
.chan, #chatlog { border-width:2px; }
#name, #room, #chatin, select { border-width:2px; }
.react { border-width:2px; box-shadow:2px 2px 0 #000; }
.cell { border-width:1px; }
.cell.on { box-shadow:inset 0 2px 0 rgba(255,255,255,.4), inset 0 -2px 0 rgba(0,0,0,.25); }
.cell.now { outline-width:2px; transform:scale(1.05); }
.slot { border-width:2px; }
#lobby h1 span { text-shadow:3px 3px 0 #000; }
#toast, #conn { border-width:3px; }
