/* MATONS — look caméra de surveillance VHS noir et blanc */
:root {
  --bg: #0d0d0d;
  --scr: #262626;
  --tile: #3a3a3a;
  --fg: #f2f2f2;
  --dim: #a6a6a6;
  --paper: #e9e9e9;
  --ink: #111111;
  --font: 'Share Tech Mono', ui-monospace, 'Courier New', monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); }
body { min-height: 100vh; min-height: 100dvh; }
button, input { font-family: var(--font); }
.hidden { display: none !important; }

#app { max-width: 760px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom)); }
.screen { display: flex; flex-direction: column; gap: 12px; }
h2 { margin: 6px 0 0; font-weight: normal; font-size: 26px; letter-spacing: 2px; text-transform: uppercase; }
.note { margin: 0; color: var(--dim); font-size: 15px; }
.sub { font-size: 0.72em; opacity: 0.85; }

/* ---------- Écrans CRT / VHS ---------- */
.crt {
  position: relative; overflow: hidden; background: var(--scr);
  border-radius: 10px; border: 2px solid #000;
  box-shadow: 0 0 0 5px #1c1c1c, 0 12px 30px rgba(0,0,0,0.6);
}
.crt::before { /* lignes + grain */
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.045) 0px, rgba(255,255,255,0.045) 1px, transparent 1px, transparent 3px),
    repeating-radial-gradient(circle at 17% 32%, rgba(255,255,255,0.05) 0px, rgba(0,0,0,0.07) 1px, transparent 2px, transparent 3px);
  animation: grain 0.35s steps(2) infinite;
}
.crt::after { /* vignettage */
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 52%, rgba(0,0,0,0.7) 100%);
}
@keyframes grain { 0% { transform: translate(0,0); } 50% { transform: translate(-1px,1px); } 100% { transform: translate(1px,0); } }
.fx.track {
  position: absolute; left: -5%; width: 110%; height: 14px; z-index: 2; pointer-events: none; opacity: 0.55;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,0.4) 0px, rgba(255,255,255,0.05) 3px, rgba(255,255,255,0.55) 5px, transparent 9px);
  animation: track 7s linear infinite;
}
@keyframes track { 0% { top: 105%; } 100% { top: -10%; } }

.osd { position: absolute; z-index: 3; color: #fff; text-shadow: 2px 2px 0 #000; font-size: 18px; line-height: 1.25; pointer-events: none; text-transform: uppercase; }
.osd.tl { top: 10px; left: 14px; }
.osd.tr { top: 10px; right: 14px; }
.osd.bl { bottom: 10px; left: 14px; }
.osd.br { bottom: 10px; right: 14px; text-align: right; }
.blink { animation: blk 1.2s steps(1) infinite; }
@keyframes blk { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* Accueil */
.title-crt { aspect-ratio: 4 / 3; max-height: 46vh; width: 100%; }
.title-wrap { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-shadow: 3px 3px 0 #000; filter: blur(0.4px); }
.title-wrap h1 { margin: 0; font-weight: normal; font-size: clamp(54px, 15vw, 96px); letter-spacing: 8px; }
.tag { margin: 6px 0 0; font-size: 17px; color: #ddd; text-align: center; padding: 0 14px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--dim); text-transform: uppercase; }
input {
  width: 100%; padding: 14px; font-size: 20px; color: var(--fg); background: #1c1c1c;
  border: 2px solid #555; border-radius: 6px; outline: none;
}
input:focus { border-color: var(--fg); }
#code { text-transform: uppercase; letter-spacing: 6px; text-align: center; flex: 1; }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }

.btn {
  display: block; width: 100%; min-height: 50px; padding: 12px 14px; font-size: 18px; letter-spacing: 1px;
  text-transform: uppercase; color: var(--ink); background: var(--paper); border: 2px solid var(--paper);
  border-radius: 6px; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--fg); }
.btn.link { background: none; border: none; color: var(--dim); text-decoration: underline; min-height: 40px; font-size: 15px; }
.btn[disabled] { opacity: 0.4; cursor: default; }

/* Salle d'attente */
.lobby-crt { aspect-ratio: 16 / 9; width: 100%; }
.lobby-center { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-shadow: 2px 2px 0 #000; text-transform: uppercase; }
.code-big { font-size: clamp(56px, 16vw, 90px); letter-spacing: 14px; padding-left: 14px; }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #1c1c1c; border: 2px solid #333; border-radius: 6px; font-size: 18px; min-height: 54px; }
.plist li .cam { color: var(--dim); font-size: 14px; min-width: 58px; }
.plist li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist li input { padding: 8px 10px; font-size: 18px; flex: 1; }
.plist li .tagp { font-size: 12px; border: 1px solid #777; padding: 2px 6px; color: #ccc; }
.plist li .x { background: none; border: 2px solid #555; color: #ccc; width: 40px; height: 40px; border-radius: 6px; font-size: 18px; cursor: pointer; }

/* ---------- Partie ---------- */
#topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#deckInfo { color: var(--dim); font-size: 14px; text-transform: uppercase; text-align: center; }
.mini { background: none; color: var(--fg); border: 2px solid #555; border-radius: 6px; padding: 8px 12px; font-size: 14px; cursor: pointer; min-height: 40px; }

#thumbs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
#thumbs.n2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#thumbs.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.thumb {
  position: relative; display: flex; flex-direction: column; padding: 0; overflow: hidden; cursor: pointer;
  background: var(--scr); border: 2px solid #3a3a3a; border-radius: 6px; color: #fff; text-align: left;
}
.thumb .tsvg { height: 78px; width: 100%; overflow: hidden; padding-top: 16px; filter: blur(0.3px); }
.thumb .tsvg svg { width: 100%; height: 100%; display: block; }
.thumb .tname { font-size: 13px; padding: 3px 6px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 1px 1px 0 #000; }
.thumb .tinfo { font-size: 11px; padding: 0 6px 4px; color: #bbb; text-transform: uppercase; }
.thumb .tcam { position: absolute; top: 3px; left: 5px; font-size: 11px; text-shadow: 1px 1px 0 #000; }
.thumb.focused { border-color: #fff; }
.thumb.turn .tname::before { content: '▶ '; }
.thumb.target { border: 2px dashed #fff; animation: pulse 0.9s ease-in-out infinite; }
.thumb.chosen { outline: 3px solid #fff; outline-offset: 2px; }
.thumb.off { opacity: 0.55; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.0); } 50% { box-shadow: 0 0 0 4px rgba(255,255,255,0.35); } }

#main { aspect-ratio: 4 / 3; width: 100%; max-height: 48vh; }
#main.hit { animation: hit 0.6s steps(3) 2; }
@keyframes hit { 0% { transform: translateX(0); filter: none; } 33% { transform: translateX(-6px); filter: invert(1); } 66% { transform: translateX(5px); } 100% { transform: translateX(0); } }
.board { position: absolute; inset: 0; z-index: 1; padding: 46px 8px 48px; }
.board svg { width: 100%; height: 100%; display: block; filter: blur(0.4px) contrast(1.08); }
.board .cand { fill: rgba(255,255,255,0.10); stroke: #fff; stroke-width: 3; stroke-dasharray: 8 7; cursor: pointer; animation: candp 1s ease-in-out infinite; }
.board .cand.on { fill: rgba(255,255,255,0.0); }
@keyframes candp { 0%, 100% { fill-opacity: 0.6; } 50% { fill-opacity: 1.6; } }
.board .ghost { opacity: 0.75; }
.exit { animation: blk 1.2s steps(1) infinite; }

#status { min-height: 26px; font-size: 17px; text-align: center; color: #fff; text-transform: uppercase; }
#actions { display: flex; gap: 8px; flex-wrap: wrap; }
#actions:empty { display: none; }
#actions .btn { flex: 1 1 120px; min-height: 48px; font-size: 16px; }

#hand { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; min-height: 112px; }
#hand.many { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px;
  min-height: 112px; padding: 6px 4px; border-radius: 6px; cursor: pointer; text-align: center;
  background: #2a2a2a; color: #fff; border: 2px solid #555; font-size: 12px; text-transform: uppercase;
  transition: transform 0.12s;
}
.card svg { width: 100%; max-width: 64px; aspect-ratio: 1; display: block; }
.card .cn { line-height: 1.1; }
.card .cd { font-size: 13px; color: #ccc; }
.card.coup { background: var(--paper); color: var(--ink); border-color: var(--paper); justify-content: center; }
.card.coup .cn { font-size: 12px; font-weight: bold; hyphens: manual; overflow-wrap: anywhere; }
.card.coup .cd { color: #333; font-size: 10px; text-transform: none; line-height: 1.15; }
.card.coup .stamp { font-size: 10px; border: 1px solid var(--ink); padding: 1px 4px; }
.card.sel { border-color: #fff; transform: translateY(-8px); box-shadow: 0 8px 0 -4px #fff; }
.card.coup.sel { outline: 3px solid #fff; outline-offset: 2px; }
.card.dim { opacity: 0.45; }
.hand-hidden { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; border: 2px dashed #444; border-radius: 6px; color: var(--dim); font-size: 15px; text-transform: uppercase; }
#log { font-size: 13px; color: var(--dim); display: flex; flex-direction: column; gap: 2px; min-height: 40px; }

/* ---------- Superpositions ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0,0,0,0.85); }
.ov-box { width: 100%; max-width: 440px; background: #1c1c1c; border: 2px solid #ddd; border-radius: 8px; padding: 22px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.ov-box p { margin: 0; font-size: 18px; line-height: 1.35; }
.osd-big { font-size: 30px; letter-spacing: 2px; text-shadow: 3px 3px 0 #000; text-transform: uppercase; }
.rules { text-align: left; max-height: 90vh; overflow: auto; }
.rules .osd-big { text-align: center; }
.rules ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 9px; font-size: 16px; line-height: 1.35; }
#flash { background: rgba(0,0,0,0.55); pointer-events: none; }
#pass { background: #0d0d0d; }
.flash-box { background: var(--paper); color: var(--ink); padding: 22px 26px; max-width: 460px; text-align: center; border: 4px solid #000; box-shadow: 8px 8px 0 #000; transform: rotate(-2deg); }
.flash-box .osd-big { color: var(--ink); text-shadow: none; font-size: 42px; }
.flash-box p { margin: 8px 0 0; font-size: 20px; }
.jitter { animation: jit 0.18s steps(2) infinite; }
@keyframes jit { 0% { transform: translate(0,0); } 50% { transform: translate(2px,-1px); } 100% { transform: translate(-2px,1px); } }

#toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: var(--paper); color: var(--ink); padding: 12px 16px; border-radius: 6px; font-size: 16px; max-width: 90vw; text-align: center; box-shadow: 4px 4px 0 #000; }
#conn { position: fixed; top: 0; left: 0; right: 0; z-index: 70; background: #fff; color: #000; text-align: center; padding: 6px; font-size: 14px; }

@media (max-width: 420px) {
  .osd { font-size: 15px; }
  .card { min-height: 100px; font-size: 11px; }
  .card.coup .cn { font-size: 11px; }
  .card.coup .cd { display: none; }
  .thumb .tname { font-size: 12px; }
}

#thumbs.n2 .thumb .tsvg { height: 92px; }

/* ---------- Grand écran (ordinateur, tablette paysage) ---------- */
@media (min-width: 900px) {
  #app { max-width: 1140px; }
  #game {
    display: grid; grid-template-columns: minmax(0, 1fr) 260px; column-gap: 18px; row-gap: 10px; align-items: start;
    grid-template-areas: "top top" "main side" "status side" "actions side" "hand side" "log side";
    grid-template-rows: auto auto auto auto auto 1fr;
  }
  #topbar { grid-area: top; }
  #main { grid-area: main; max-height: 58vh; }
  #status { grid-area: status; }
  #actions { grid-area: actions; }
  #hand { grid-area: hand; }
  #log { grid-area: log; }
  #thumbs, #thumbs.n2, #thumbs.n3 { grid-area: side; grid-row: 2 / span 5; grid-template-columns: 1fr; align-content: start; }
  #thumbs .thumb .tsvg, #thumbs.n2 .thumb .tsvg { height: 92px; }
  .card { min-height: 130px; font-size: 13px; }
  .card svg { max-width: 72px; }
}
