/* style.css : interface du jeu. Mobile d'abord, portrait et paysage. */
:root {
  --bg: #2a1d1a;
  --panel: #3a2a25;
  --panel-2: #4a362f;
  --line: #6b4e42;
  --text: #fbeed7;
  --muted: #c9ab8c;
  --accent: #ffd23f;
  --good: #7be07b;
  --bad: #ff7a6a;
  --teal: #3fb6c9;
  --btn: 52px;                 /* taille minimale d'un bouton tactile */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none; touch-action: none;
}
#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }

/* ---------- Barre du haut ---------- */
#topbar {
  display: flex; align-items: center; gap: 6px; padding: 4px calc(8px + var(--safe-r)) 4px calc(8px + var(--safe-l));
  background: var(--panel); border-bottom: 2px solid var(--line); flex: none;
}
.stat { display: flex; flex-direction: column; min-width: 0; padding: 0 6px; line-height: 1.1; }
.stat span { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat b { font-size: 15px; white-space: nowrap; }
.stat-name { flex: 1; overflow: hidden; }
.stat-name b { overflow: hidden; text-overflow: ellipsis; }
#st-saved.ok { color: var(--good); }
#st-time.low { color: var(--bad); }

/* ---------- Zone de jeu ---------- */
#stage { position: relative; flex: 1; min-height: 0; background: #000; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; image-rendering: pixelated; cursor: default; }
#game.can-assign { cursor: crosshair; }
#toast {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); max-width: 90%;
  background: rgba(30,20,18,.88); border: 2px solid var(--accent); padding: 8px 12px; border-radius: 6px;
  font-size: 13px; text-align: center; opacity: 0; pointer-events: none; transition: opacity .25s;
}
#toast.show { opacity: 1; }
#pause-badge {
  position: absolute; right: 10px; top: 10px; background: rgba(30,20,18,.85); border: 2px solid var(--accent);
  color: var(--accent); padding: 4px 10px; font-weight: bold; letter-spacing: .1em; display: none; pointer-events: none;
}
#pause-badge.show { display: block; }

/* ---------- Barre du bas ---------- */
#bottombar {
  flex: none; background: var(--panel); border-top: 2px solid var(--line);
  padding: 6px calc(6px + var(--safe-r)) calc(6px + var(--safe-b)) calc(6px + var(--safe-l));
  display: flex; flex-wrap: wrap; gap: 6px;
}
#skillbar { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; flex: 1 1 100%; }
#armbar { display: grid; grid-template-columns: repeat(auto-fit, minmax(52px, 1fr)); gap: 4px; flex: 1 1 100%; }
#armbar[hidden], #skillbar[hidden] { display: none; }
#toolbar { display: flex; gap: 4px; flex: 1 1 100%; align-items: stretch; }
#toolbar .btn { flex: 1; }

.btn {
  font: inherit; color: var(--text); background: var(--panel-2); border: 2px solid var(--line); border-radius: 8px;
  min-height: var(--btn); cursor: pointer; padding: 0 6px; display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); background: #5a443b; }
.btn.on { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.icon { min-height: 40px; min-width: 40px; flex: none; }
.btn.tool { font-weight: bold; font-size: 16px; }

.skill { position: relative; flex-direction: column; gap: 2px; padding: 3px 2px; min-height: 62px; }
.skill canvas { width: 32px; height: 32px; image-rendering: pixelated; }
.skill .lbl { font-size: 9px; line-height: 1; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.skill .cnt { position: absolute; top: 1px; right: 3px; font-size: 13px; font-weight: bold; color: var(--accent); }
.skill .key { position: absolute; top: 1px; left: 4px; font-size: 10px; color: var(--muted); display: none; }
.skill.on { background: #5c4a2a; box-shadow: 0 0 0 2px var(--accent) inset; }
.skill.on .lbl { color: var(--accent); }
.skill:disabled .cnt { color: var(--muted); }

.rate { display: flex; align-items: stretch; gap: 4px; flex: 1.6 !important; }
.rate .btn { flex: 1; font-size: 22px; }
.rate-val { flex: 1.2; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.rate-val span { font-size: 9px; text-transform: uppercase; color: var(--muted); }
.rate-val b { font-size: 16px; }

/* Souris : un seul rang, les raccourcis sont affichés. */
@media (hover: hover) and (pointer: fine) {
  .skill .key { display: block; }
}
@media (min-width: 880px) {
  #skillbar { flex: 1 1 520px; }
  #toolbar { flex: 1 1 380px; }
  .skill { min-height: 66px; }
}
/* Paysage sur téléphone : tout sur une ligne, bandeau compact. */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --btn: 44px; }
  #topbar { padding-top: 2px; padding-bottom: 2px; }
  .stat span { font-size: 9px; } .stat b { font-size: 13px; }
  #bottombar { flex-wrap: nowrap; padding-top: 4px; padding-bottom: calc(4px + var(--safe-b)); }
  #skillbar { flex: 1 1 54%; }
  #toolbar { flex: 1 1 46%; }
  .skill { min-height: 52px; } .skill canvas { width: 26px; height: 26px; } .skill .lbl { display: none; }
  .btn.icon { min-height: 32px; }
}
@media (max-width: 420px) {
  .stat { padding: 0 3px; } .stat b { font-size: 13px; } .stat-name { display: none; }
  .btn.tool { font-size: 14px; }
  .skill .lbl { font-size: 8px; letter-spacing: -.02em; }
}

/* ---------- Écrans (titre, aide, résultat) ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(80,50,35,.92), rgba(20,12,10,.96)); padding: 14px; overflow: auto;
  touch-action: pan-y;
}
#overlay[hidden] { display: none; }
.card {
  width: min(560px, 100%); background: var(--panel); border: 3px solid var(--line); border-radius: 12px; padding: 18px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); max-height: 100%; overflow: auto;
}
.card h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: .04em; color: var(--accent); text-transform: uppercase; }
.card h2 { margin: 0 0 8px; font-size: 20px; color: var(--accent); }
.card p { margin: 6px 0 12px; line-height: 1.45; color: var(--text); font-size: 14px; }
.card .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.card .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.card .row .btn { flex: 1 1 140px; font-size: 15px; font-weight: bold; }
.btn.primary { background: #7a5a16; border-color: var(--accent); color: #fff6c8; }
.levels { display: grid; gap: 8px; margin: 10px 0; }
.level-card {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; min-height: 64px; padding: 8px 12px;
}
.level-card .num { font-size: 26px; color: var(--accent); width: 34px; text-align: center; }
.level-card .meta { flex: 1; min-width: 0; }
.level-card .meta b { display: block; font-size: 15px; }
.level-card .meta small { color: var(--muted); font-size: 12px; }
.level-card .best { color: var(--good); font-size: 13px; font-weight: bold; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 8px 0; }
.keys kbd { background: #1d1311; border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; color: var(--accent); justify-self: start; }
.result-big { font-size: 40px; font-weight: bold; margin: 4px 0; }
.result-big.win { color: var(--good); } .result-big.lose { color: var(--bad); }
.bar { height: 14px; background: #1d1311; border: 2px solid var(--line); border-radius: 7px; position: relative; overflow: hidden; margin: 8px 0; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--teal); }
.bar u { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); }
.logo { width: 64px; height: 80px; image-rendering: pixelated; float: right; margin-left: 10px; }

/* ---------- Univers : variables de couleur par thème ---------- */
body[data-theme=ruins] { --panel: #3a3032; --panel-2: #4d4044; --line: #77605f; --accent: #ffb347; }
body[data-theme=arctic] { --panel: #24384a; --panel-2: #324b61; --line: #5d83a3; --accent: #8ee3f2; --bg: #172635; }
body[data-theme=orbital] { --panel: #161a33; --panel-2: #232a52; --line: #4a56a0; --accent: #6df0ff; --bg: #0a0c1c; }
body[data-theme] { background: var(--bg); }

/* ---------- Arsenal ---------- */
.arm { position: relative; flex-direction: column; gap: 2px; padding: 3px 2px; min-height: 62px; overflow: hidden; }
.arm canvas { width: 28px; height: 28px; image-rendering: pixelated; position: relative; z-index: 1; }
.arm .lbl { font-size: 8px; line-height: 1; text-transform: uppercase; color: var(--muted); white-space: nowrap; position: relative; z-index: 1; }
.arm .cnt { position: absolute; top: 1px; right: 3px; font-size: 13px; font-weight: bold; color: var(--accent); z-index: 1; }
.arm .cost { position: absolute; top: 2px; left: 4px; font-size: 10px; color: #9fe39f; z-index: 1; }
.arm .key { position: absolute; bottom: 1px; right: 4px; font-size: 9px; color: var(--muted); display: none; z-index: 1; }
.arm .cd { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(0,0,0,.55); z-index: 0; pointer-events: none; }
.arm.on { background: #3a4f58; box-shadow: 0 0 0 2px var(--accent) inset; }
.arm.poor .cost { color: var(--bad); }
.arm.cooling .lbl { color: var(--bad); }
@media (hover: hover) and (pointer: fine) { .arm .key { display: block; } }
@media (max-height: 520px) and (orientation: landscape) { .arm { min-height: 52px; } .arm .lbl { display: none; } .arm canvas { width: 24px; height: 24px; } }
.stat-pts b { color: #9fe39f; }
#btn-tab { flex: 1.3 !important; font-size: 12px; }

/* ---------- Panneau du canon, détonateur, bandeau de reconnaissance ---------- */
#aimpanel {
  position: absolute; left: 8px; right: 8px; bottom: 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: rgba(24,16,14,.9); border: 2px solid var(--accent); border-radius: 10px; padding: 8px 10px; font-size: 12px; z-index: 3;
}
#aimpanel[hidden], #btn-boom[hidden], #reveal-badge[hidden] { display: none; }
#aimpanel label { display: flex; align-items: center; gap: 6px; flex: 1 1 160px; }
#aimpanel input[type=range] { flex: 1; min-width: 80px; accent-color: var(--accent); height: 28px; }
#aimpanel b { min-width: 34px; text-align: right; color: var(--accent); }
#btn-fire { flex: 0 0 auto; min-height: 44px; padding: 0 18px; font-weight: bold; }
#btn-boom { position: absolute; right: 8px; bottom: 8px; z-index: 3; min-height: 48px; padding: 0 14px; background: #7a2a24; border-color: #ff7a6a; font-weight: bold; }
#reveal-badge { position: absolute; left: 10px; top: 10px; background: rgba(10,40,48,.85); border: 2px solid #6df0ff; color: #6df0ff; padding: 4px 10px; font-size: 12px; pointer-events: none; }

/* ---------- Menus : campagne, versus, statistiques ---------- */
.menu-grid { display: grid; gap: 8px; margin: 10px 0; }
.menu-grid .btn { min-height: 64px; font-size: 16px; font-weight: bold; flex-direction: column; gap: 2px; }
.menu-grid .btn small { font-weight: normal; color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; margin: 6px 0 10px; }
.tabs .btn { flex: 1; min-height: 44px; font-size: 12px; padding: 0 2px; }
.tabs .btn.on { background: #5c4a2a; }
.world-title { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.lvl-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.lvl { flex-direction: column; min-height: 62px; gap: 2px; font-weight: bold; font-size: 18px; position: relative; }
.lvl .st { font-size: 11px; letter-spacing: .1em; color: var(--accent); min-height: 13px; }
.lvl.lock { opacity: .45; }
.lvl .new { position: absolute; top: 1px; right: 3px; font-size: 9px; color: #9fe39f; }
.stars-total { color: var(--accent); font-size: 13px; float: right; }
.diff { text-align: left; align-items: flex-start !important; padding: 10px 14px; }
.diff b { font-size: 16px; } .diff small { text-align: left; }
.stats { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.stats td, .stats th { padding: 3px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.stats td:first-child, .stats th:first-child { text-align: left; color: var(--muted); }
.stats th { color: var(--accent); }
.stars-big { font-size: 34px; letter-spacing: .15em; color: var(--accent); text-align: center; margin: 2px 0; }
.stars-big i { opacity: .25; font-style: normal; } .stars-big i.on { opacity: 1; }
.unlock { background: #1f3a25; border: 2px solid #7be07b; border-radius: 8px; padding: 6px 10px; font-size: 13px; margin: 8px 0; }
@media (max-width: 420px) { .lvl-grid { grid-template-columns: repeat(5, 1fr); gap: 4px; } .tabs .btn { font-size: 10px; } #skillbar { gap: 2px; } .stat-alive { display: none; } }

/* ---------- En ligne : salon, chat, bandeaux ---------- */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin: 8px 0; }
.field input, .field select, .ed-opts input, .ed-opts select, .wide-input, input.code {
  font: inherit; color: var(--text); background: #1d1311; border: 2px solid var(--line); border-radius: 8px; padding: 10px; min-height: 44px; user-select: text; -webkit-user-select: text;
}
input.code { flex: 1; text-transform: uppercase; letter-spacing: .4em; text-align: center; font-size: 22px; font-weight: bold; }
.wide-input { flex: 1; min-width: 0; }
.netstate { min-height: 18px; font-size: 12px; color: var(--accent); margin: 4px 0; }
.roomcode { font-size: 54px; font-weight: bold; letter-spacing: .3em; text-align: center; color: var(--accent); margin: 4px 0; user-select: text; -webkit-user-select: text; }
.sub { color: var(--muted); font-size: 12px; text-align: center; margin: 4px 0 10px; } .sub a { color: var(--accent); }
.prows { display: grid; gap: 6px; margin: 8px 0; }
.prow { display: flex; align-items: center; gap: 8px; background: #2c1f1b; border: 2px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.prow.me { border-color: var(--accent); } .prow.empty { opacity: .6; font-style: italic; }
.prow span:first-child { flex: 1; } .prow .role { color: var(--muted); font-size: 12px; }
.st { font-size: 12px; color: var(--muted); min-width: 64px; text-align: right; } .st.ok { color: var(--good); } .st.off { color: var(--bad); }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 10px; }
.opts select:disabled { opacity: .6; }
.count { text-align: center; min-height: 24px; color: var(--accent); font-weight: bold; }
.emojis { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; margin: 8px 0; }
.btn.emo { min-height: 44px; min-width: 44px; font-size: 22px; padding: 0 6px; }
#chatbar { position: absolute; right: 8px; top: 8px; z-index: 5; background: rgba(24,16,14,.92); border: 2px solid var(--accent); border-radius: 10px; padding: 6px; max-width: 220px; }
#chatbar .emojis { margin: 0; }
#chatlog { position: absolute; left: 8px; bottom: 74px; z-index: 20; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
.chatline { background: rgba(24,16,14,.85); border: 2px solid var(--line); border-radius: 14px; padding: 3px 10px; font-size: 18px; animation: pop .25s; } .chatline.mine { border-color: var(--accent); } .chatline b { font-size: 11px; color: var(--muted); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
#netbadge { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); z-index: 6; background: rgba(120,30,24,.92); border: 2px solid var(--bad); border-radius: 8px; padding: 6px 12px; font-size: 13px; pointer-events: none; text-align: center; }
#netinfo { position: absolute; left: 8px; bottom: 6px; z-index: 3; font-size: 10px; color: rgba(255,255,255,.7); text-shadow: 0 1px 2px #000; pointer-events: none; }
#jam-badge { position: absolute; left: 10px; top: 44px; background: rgba(120,20,60,.9); border: 2px solid #ff5a7a; color: #ffb0c0; padding: 4px 10px; font-size: 12px; pointer-events: none; z-index: 4; }
#jam-badge[hidden] { display: none; }
.btn.partner, .skill.partner, .arm.partner { opacity: .35; background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(255,255,255,.07) 6px 12px); }
body.net #btn-pause, body.net #btn-x2, body.net #btn-x4 { display: none; }
.card.wide { width: min(940px, 100%); }
/* ---------- Éditeur ---------- */
.ed-tools { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; } .ed-tools .btn { flex: 1 1 70px; min-height: 44px; font-size: 13px; } .ed-tools .btn.on { background: #5c4a2a; border-color: var(--accent); }
#ed-canvas { width: 100%; image-rendering: pixelated; border: 2px solid var(--line); border-radius: 6px; touch-action: none; cursor: crosshair; background: #96cdeb; }
.ed-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px 10px; margin: 8px 0; font-size: 12px; color: var(--muted); }
.ed-opts label { display: flex; flex-direction: column; gap: 3px; } .ed-opts input[type=range] { accent-color: var(--accent); min-height: 30px; padding: 0; }

.row.small .btn { min-height: 40px; font-size: 13px; flex: 1 1 120px; }
body.offline .menu-grid [data-action=online] { opacity: .5; }
