:root {
  --bg: #14111c;
  --panel: #221d2e;
  --panel-2: #2c2540;
  --border: #4a3f66;
  --text: #f1e9d6;
  --muted: #a89cbc;
  --gold: #f2c14e;
  --danger: #e04545;
  --black-cube: #26222e;
  --radius: 6px;
  --cube: 22px;
  --font-display: 'Press Start 2P', ui-monospace, monospace;
  font-family: 'VT323', ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background-color: var(--bg);
  background-image: linear-gradient(rgba(20, 17, 28, .82), rgba(20, 17, 28, .94)), url(img/wall.png);
  background-size: auto, 96px;
  font-size: 21px;
}

img { image-rendering: pixelated; }
.flip { transform: scaleX(-1); }

#app, .home {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; font-weight: 400; font-family: var(--font-display); line-height: 1.4; }
h1 { font-size: 1rem; }
h2, h3 { font-size: .75rem; }
.muted { color: var(--muted); }
.loading { text-align: center; padding: 40px; }

.panel {
  background: var(--panel);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 0 #0007;
  padding: 12px;
}

/* ---------- Boutons ---------- */
.btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 #000a;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  text-align: center;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #000a; }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-primary { background: #7a5a12; border-color: var(--gold); }
.btn-big { font-size: 1.4rem; padding: 14px; }
.btn-ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn-pad { width: 52px; height: 52px; padding: 0; font-family: var(--font-display); font-size: 1.1rem; }
.btn-pad.hit { background: #5c1d1d; border-color: var(--danger); }
.btn-pad.noise { background: #5a4310; border-color: var(--gold); }
.btn-rage { flex: 1; min-height: 52px; background: #5a2a10; border-color: #e8823a; font-size: 1.3rem; }
.btn-attack {
  width: 100%;
  min-height: 72px;
  background: #7d1d1d;
  border-color: var(--danger);
  font-family: var(--font-display);
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-attack img { width: 44px; height: 44px; }

/* ---------- Cubes ---------- */
.cube {
  display: inline-block;
  width: var(--cube); height: var(--cube);
  background: var(--c, #888);
  border-radius: 3px;
  box-shadow: inset -3px -3px 0 #0006, inset 3px 3px 0 #fff5, 0 2px 0 #0008;
  flex: none;
}
.cube.black { --c: var(--black-cube); box-shadow: inset -3px -3px 0 #000, inset 3px 3px 0 #ffffff26, 0 2px 0 #0008; }
.cube.lg { --cube: 34px; }
.cube.white { --c: #f4f8ff; }

/* ---------- Accueil ---------- */
.home { display: grid; gap: 16px; padding-top: 24px; }
.title { display: flex; align-items: center; gap: 12px; justify-content: center; margin: 4px 0; }
.title img { width: 72px; height: 72px; }
.title h1 { color: var(--gold); text-shadow: 0 3px 0 #000; }
.title small { display: block; margin-top: 8px; color: var(--muted); font-family: 'VT323', monospace; font-size: 1.2rem; }
.choice { display: flex; gap: 14px; align-items: center; color: var(--text); text-decoration: none; }
.choice img { width: 96px; height: 96px; flex: none; }
.choice strong { display: block; font-family: var(--font-display); font-weight: 400; font-size: .8rem; color: var(--gold); margin-bottom: 6px; }
.choice:active { transform: translateY(2px); }

/* ---------- Nouvelle partie ---------- */
.setup { display: grid; gap: 14px; }
.field-label { display: block; margin-bottom: 8px; color: var(--muted); }
.count-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.count-picker .btn[aria-pressed="true"] { border-color: var(--gold); background: #4a3a10; }
.setup-player { display: grid; gap: 10px; border-color: var(--pc); }
.setup-player input {
  font: inherit; color: var(--text);
  background: #0005; border: 2px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; width: 100%;
}
.heroes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.hero-pick {
  aspect-ratio: 1; padding: 2px; cursor: pointer;
  background: color-mix(in srgb, var(--c) 35%, #0008);
  border: 3px solid transparent; border-radius: var(--radius);
}
.hero-pick img { width: 100%; height: 100%; object-fit: contain; }
.hero-pick[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 60%, #0006); box-shadow: 0 0 0 2px #fff; }
.hero-pick:disabled { opacity: .2; cursor: not-allowed; }

/* ---------- Télécommande ---------- */
.status {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 12px;
  margin: -12px -12px 12px; padding: 10px 12px;
  background: #14111cf2; border-bottom: 3px solid var(--border);
}
.status .stat { display: flex; align-items: center; gap: 4px; font-family: var(--font-display); font-size: .8rem; }
.status .stat img { width: 28px; height: 28px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none; }
.dot.on { background: #3aa655; }
.pips { display: flex; gap: 3px; margin-right: auto; }
.pips i { width: 10px; height: 16px; background: #0006; border: 1px solid #e8823a55; }
.pips i.lit { background: linear-gradient(#ffd34d, #e8582a); border-color: #ffb347; box-shadow: 0 0 6px #e8582a; }

.remote-players { display: grid; gap: 10px; }
.player-picker { display: grid; grid-template-columns: repeat(var(--players), minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.player-tab { min-width: 0; display: grid; justify-items: center; gap: 3px; font: inherit; color: var(--text); background: #211c2c; border: 2px solid color-mix(in srgb, var(--pc) 45%, #30283b); border-radius: 6px; padding: 6px 3px; cursor: pointer; touch-action: manipulation; }
.player-tab[aria-pressed="true"] { border-color: var(--pc); background: color-mix(in srgb, var(--pc) 20%, #211c2c); box-shadow: 0 0 0 1px var(--pc); }
.player-tab img { width: 52px; height: 52px; object-fit: contain; }
.player-tab span { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 18px; }
.player-tab small { font-size: 16px; color: var(--muted); }
.rplayer {
  border-color: var(--pc);
  display: grid; gap: 6px 10px;
  grid-template-columns: 1fr 1fr;
  padding: 8px 10px;
}
.rplayer.ko { filter: grayscale(.8); }
.selected-player { grid-template-columns: minmax(0, 1fr); gap: 12px; }
.selected-player .rplayer-id img { width: 72px; height: 72px; }
.selected-player .selected-avatar { position: relative; flex: none; width: 72px; height: 72px; }
.selected-player .selected-avatar .avatar-artifact { position: absolute; left: var(--artifact-x); top: calc(var(--artifact-y) + 6%); width: 44%; height: 44%; object-fit: contain; transform: translate(-50%, -50%); }
.player-inventory { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 12px; font-size: 18px; }
.artifact-badge { display: flex; align-items: center; gap: 6px; color: var(--gold); }
.artifact-badge img { width: 52px; height: 52px; object-fit: contain; }
.player-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.player-actions .btn { min-width: 0; min-height: 68px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 8px 4px; font-size: 18px; line-height: 1.1; }
.player-actions img { width: 30px; height: 30px; object-fit: contain; }
.player-actions .hit { background: #5c1d1d; border-color: var(--danger); }
.player-actions .noise { background: #5a4310; border-color: var(--gold); }
.player-actions .btn-artifact { background: #574216; border-color: #ffc95b; color: #ffdfa1; }
.player-corrections { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.player-corrections .btn { font-size: 17px; padding: 5px 8px; }
.extra-draws { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 8px; align-items: center; }
.extra-draws small { font-size: 16px; }
.extra-draws strong { font-family: var(--font-display); font-size: .8rem; min-width: 2ch; text-align: center; }
.dragon-ctl > small { text-align: center; font-size: 17px; }
@media (max-width: 480px) { .player-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.player-end-controls { grid-column: 1 / -1; display: grid; gap: 8px; }
.player-end-controls small { text-align: center; }
.btn-exit { font-size: 18px; border-color: #3a8765; }
.btn-ended-attack { background: #5c1d1d; border-color: var(--danger); }
.game-finished { padding: 12px; text-align: center; background: #223f32; border-radius: var(--radius); }
.rplayer-id { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
.rplayer-id img { width: 40px; height: 40px; flex: none; }
.rplayer-id > div { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; }
.rplayer-id .hp { margin-left: auto; white-space: nowrap; }
.rplayer-id h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rplayer-id .hp { color: #ff7a7a; }
.rctl { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 2px 6px; background: #0003; border-radius: var(--radius); padding: 4px 6px 6px; }
.rctl .label { grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: .9rem; line-height: 1; }
.rctl .val { font-family: var(--font-display); font-size: 1rem; text-align: center; }
.rctl .btn-pad { width: 48px; height: 48px; }

.dragon-ctl { display: grid; gap: 10px; margin-top: 12px; border-color: #7d1d1d; }
.ghost-ctl { display: grid; gap: 10px; margin-top: 12px; border-color: #a4b9d1; }
.ghost-title { display: flex; align-items: center; gap: 8px; }
.ghost-title img { width: 60px; height: 60px; object-fit: contain; }
.ghost-title h3 { color: #dcecff; }
.ghost-title .muted { font-size: 18px; }
.ghost-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ghost-count { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.ghost-summary { color: #dcecff; }
.rage-row { display: flex; gap: 8px; }
.remote-footer { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; }
.remote-footer .btn { flex: 1; }

/* ---------- Dialogues ---------- */
dialog {
  color: var(--text);
  background: var(--panel);
  border: 3px solid var(--danger);
  border-radius: var(--radius);
  max-width: min(480px, calc(100vw - 24px));
  width: 100%;
  text-align: center;
  padding: 18px;
}
dialog::backdrop { background: #000c; }
.draws { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0; }
.summary { list-style: none; padding: 0; margin: 0 0 14px; display: grid; gap: 4px; }
.sheet { border-color: var(--border); text-align: left; max-height: 85vh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet h3 { margin: 16px 0 8px; color: var(--gold); }
.menu-actions { display: grid; gap: 8px; }
.bag-lines { display: grid; gap: 4px; }
.bag-line { display: flex; align-items: center; gap: 8px; }
.bag-line .n { font-family: var(--font-display); font-size: .7rem; min-width: 3ch; text-align: right; }
.log { max-height: 240px; overflow: auto; margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; font-size: .95rem; }
.log li { padding: 3px 0; border-bottom: 1px solid #ffffff12; }
.log time { color: var(--muted); margin-right: 8px; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: #7d1d1d; border: 3px solid var(--danger); border-radius: var(--radius);
  padding: 10px 16px; opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: calc(100vw - 32px); z-index: 10;
}
#toast.show { opacity: 1; }

/* Télécommande compacte : commandes tactiles et indicateurs essentiels. */
.remote #app { max-width: 440px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.remote .status { gap: 8px; margin: -8px -8px 8px; padding: 8px; }
.remote .status .stat { font-size: .65rem; }
.remote .status .stat img { width: 24px; height: 24px; }
.remote .player-picker { gap: 6px; margin-bottom: 8px; }
.remote .player-tab { gap: 0; padding: 4px 2px; }
.remote .player-tab img { width: 36px; height: 36px; }
.remote .player-tab span { font-size: 17px; }
.remote .panel { padding: 8px; border-width: 2px; }
.remote .selected-player { gap: 6px; }
.remote .player-inventory { font-size: 16px; }
.remote .artifact-badge img { width: 24px; height: 24px; }
.remote .player-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.remote .player-actions .btn { min-height: 62px; padding: 4px 2px; font-size: 17px; }
.remote .player-actions img { width: 26px; height: 26px; }
.remote .player-corrections { gap: 6px; }
.remote .player-corrections .btn { min-height: 44px; padding: 4px 8px; }
.remote .ghost-ctl, .remote .dragon-ctl { gap: 6px; margin-top: 8px; }
.remote .ghost-controls .btn { width: 44px; height: 44px; padding: 0; }
.remote .ghost-count img { width: 32px; height: 32px; object-fit: contain; }
.remote .btn-pad { width: 44px; height: 44px; font-size: .9rem; }
.remote .btn-rage { min-height: 44px; font-size: 21px; }
.remote .btn-attack { min-height: 52px; font-size: .7rem; }
.remote .btn-attack img { width: 30px; height: 30px; }
.remote .remote-footer { gap: 8px; margin-top: 8px; }
.remote .remote-footer .btn { min-height: 44px; padding: 4px 8px; }
.remote .game-finished { margin: 0 0 8px; padding: 8px; }
