/* Yksin Lapissa 3D – moninpelin HUD-lisät (G3.MPUI, js3d/mpui.js). Kaikki luokat alkavat .mp-.
 * Sijoittelun top/right/bottom-arvot laskee mpui.js HUD-elementtien mukaan; tämä tiedosto hoitaa koot ja ulkoasun.
 * Pelinäkymä on läpinäkyvä (pointer-events: none): vain 💬-painike, pelaajalistan otsikko ja chatin syöttökenttä ottavat kosketuksen.
 * Kosketuskohteet >= 44 px. Breakpointit vastaavat css/game3d.css:ää.
 */

.mp-root {
  --mp-bg: rgba(9, 16, 25, .66);
  --mp-bg-strong: rgba(11, 19, 30, .92);
  --mp-line: rgba(170, 200, 225, .18);
  --mp-line-2: rgba(170, 200, 225, .34);
  --mp-text: #e9f1f8;
  --mp-muted: #a3b8ca;
  --mp-dim: #6d8294;
  --mp-accent: #ffb14a;
  --mp-ice: #9fd8ff;
  --mp-good: #8fe3b0;
  --mp-warn: #ffd27a;
  --mp-bad: #ff9a9a;
  --mp-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mp-sa-l: env(safe-area-inset-left, 0px);
  --mp-sa-r: env(safe-area-inset-right, 0px);
  position: absolute; inset: 0; z-index: 3;
  pointer-events: none;
  font-family: var(--mp-sans);
  color: var(--mp-text);
  font-variant-numeric: tabular-nums;
  -webkit-user-select: none; user-select: none;
}
.mp-root *, .mp-root *::before, .mp-root *::after { box-sizing: border-box; }
.mp-root button, .mp-root input { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
.mp-root button { cursor: pointer; }
.mp-root :focus-visible { outline: 2px solid var(--mp-accent); outline-offset: 2px; }
.mp-root ul { list-style: none; margin: 0; padding: 0; }
.mp-root li { margin: 0; }

/* ---------- 💬-painike (HUD:n 🎒 🗺 ☰ -rivin alla) ---------- */
.mp-ibtn {
  pointer-events: auto;
  position: absolute; top: 56px; right: 10px;
  width: 44px; height: 44px; padding: 0;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--mp-line-2);
  background: var(--mp-bg-strong);
  font-size: 19px; line-height: 1;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  transition: background .15s, border-color .15s, transform .08s;
}
.mp-ibtn:hover { background: rgba(24, 40, 58, .95); border-color: rgba(200, 225, 245, .5); }
.mp-ibtn:active { transform: scale(.94); }
.mp-ibtn.on { border-color: var(--mp-accent); box-shadow: 0 0 0 1px var(--mp-accent) inset; }

/* ---------- pelaajalista (oikea yläkulma, pienennettävissä) ---------- */
.mp-plist {
  pointer-events: auto;
  position: absolute; top: 112px; right: 10px;
  width: 220px; max-height: 42%;
  display: flex; flex-direction: column;
  border-radius: 12px;
  background: var(--mp-bg);
  border: 1px solid var(--mp-line);
  -webkit-backdrop-filter: blur(8px) saturate(1.1); backdrop-filter: blur(8px) saturate(1.1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
  overflow: hidden;
  font-size: 12.5px;
}
.mp-ph {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 7px;
  width: 100%; min-height: 44px; padding: 0 10px 0 12px;
  border: 0; background: transparent; text-align: left;
}
.mp-ph:hover { background: rgba(160, 200, 235, .06); }
.mp-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--mp-good); box-shadow: 0 0 6px rgba(143, 227, 176, .6); }
.mp-dot.reconnecting { background: var(--mp-warn); box-shadow: 0 0 6px rgba(255, 210, 122, .6); animation: mp-pulse 1s ease-in-out infinite; }
.mp-dot.lost { background: var(--mp-bad); box-shadow: 0 0 6px rgba(255, 154, 154, .6); }
.mp-ttl { flex: 1 1 auto; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-plist[data-conn="reconnecting"] .mp-ttl { color: var(--mp-warn); }
.mp-plist[data-conn="lost"] .mp-ttl { color: var(--mp-bad); }
.mp-cnt {
  flex: 0 0 auto; min-width: 22px; height: 20px; padding: 0 6px;
  border-radius: 999px; line-height: 20px; text-align: center;
  font-size: 11.5px; font-weight: 650;
  background: rgba(160, 200, 235, .14); color: var(--mp-muted);
}
.mp-chev { flex: 0 0 auto; color: var(--mp-dim); font-size: 12px; }
.mp-rows {
  flex: 0 1 auto; min-height: 0;
  display: flex; flex-direction: column; gap: 1px;
  padding: 0 6px 7px;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.mp-plist.mp-collapsed .mp-rows { display: none; }
.mp-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px;
  min-height: 26px; padding: 2px 7px; border-radius: 7px;
}
.mp-row.self { background: rgba(255, 177, 74, .14); box-shadow: inset 0 0 0 1px rgba(255, 177, 74, .45); }
.mp-row.self .mp-nm { font-weight: 700; color: var(--mp-accent); }
.mp-row.empty { display: block; color: var(--mp-muted); }
.mp-nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-day { font-size: 11.5px; color: var(--mp-muted); white-space: nowrap; }

/* ---------- chat: viimeiset 5 riviä, syöttökenttä alla; tilarivien yläpuolella ---------- */
.mp-chat {
  position: absolute; bottom: 150px;
  left: calc(12px + var(--mp-sa-l));
  width: min(300px, 40vw);
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.mp-log {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end; gap: 4px;
  max-height: 40vh; overflow: hidden;
}
.mp-line {
  display: inline-block; max-width: 100%;
  padding: 3px 9px; border-radius: 9px;
  background: rgba(9, 16, 25, .6);
  font-size: 13px; line-height: 1.3;
  text-shadow: 0 1px 2px #000;
  overflow-wrap: anywhere;
  transition: opacity 1.2s ease;
  animation: mp-in .2s ease-out;
}
.mp-who { font-weight: 700; color: var(--mp-ice); }
.mp-line.self .mp-who { color: var(--mp-accent); }
.mp-line.sys { color: var(--mp-warn); font-style: italic; background: rgba(9, 16, 25, .5); }
.mp-log > li:nth-last-child(n+3) { opacity: .75; }
.mp-log > li:nth-last-child(n+4) { opacity: .5; }
.mp-line.mp-out { opacity: 0 !important; }
.mp-line.mp-clip { visibility: hidden; }

.mp-inp { display: none; align-items: stretch; gap: 6px; pointer-events: auto; }
.mp-chat.open .mp-inp { display: flex; }
.mp-chat.open .mp-log > li:not(.mp-out) { opacity: 1 !important; }
.mp-input {
  flex: 1 1 auto; min-width: 0; min-height: 44px;
  padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--mp-line-2);
  background: var(--mp-bg-strong);
  font-size: 16px;   /* 16 px estää iOS:n zoomauksen kentän aukeaessa */
  -webkit-user-select: text; user-select: text;
}
.mp-input::placeholder { color: var(--mp-dim); }
.mp-input:focus { outline: 2px solid var(--mp-accent); outline-offset: 1px; }
.mp-send, .mp-close {
  flex: 0 0 auto; min-width: 44px; min-height: 44px;
  border-radius: 12px; border: 1px solid var(--mp-line-2);
  background: var(--mp-bg-strong);
  font-size: 14px; font-weight: 650;
  transition: background .12s, transform .08s;
}
.mp-send { padding: 0 12px; background: linear-gradient(180deg, #ffc27a, #f59a3c); color: #2a1603; border-color: #ffd39a; }
.mp-send:hover { background: linear-gradient(180deg, #ffcb8e, #ffa64f); }
.mp-close { padding: 0; font-size: 18px; color: var(--mp-muted); background: transparent; border-color: transparent; }
.mp-close:hover { color: var(--mp-text); background: rgba(255, 255, 255, .05); }
.mp-send:active, .mp-close:active { transform: scale(.96); }

/* ---------- puhelin pystyssä (≤ 519 px) ---------- */
@media (max-width: 519px) {
  .mp-plist { width: 150px; }
  .mp-chat { left: calc(8px + var(--mp-sa-l)); width: min(300px, 66vw); }
}

/* ---------- vaakanäkymä puhelimella (matala ruutu) ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  /* matala korkeus: lista ei ulotu kosketusnappien (input.js) alueelle; rivit selattavissa */
  .mp-plist { width: 170px; max-height: 30%; font-size: 12px; }
  .mp-ph { min-height: 44px; }
  .mp-chat { left: calc(8px + var(--mp-sa-l)); width: 210px; bottom: 130px; }
  .mp-line { font-size: 12px; padding: 2px 7px; }
  /* HUD:n toastit kompaktimmiksi: useampi toasti mahtuu kellokortin alapuolelle */
  .g3-toasts { width: 210px; gap: 4px; }
  .g3-toast { padding: 5px 9px 5px 8px; font-size: 12px; line-height: 1.25; }
}

/* Chat auki (liike pois käytöstä): HUD:n toastit ja toimintakehote piiloon, jotta chat näkyy eikä mene päällekkäin */
.mp-typing .g3-toasts, .mp-typing .g3-prompt { visibility: hidden; }

@keyframes mp-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes mp-pulse { 50% { opacity: .35; } }

@media (prefers-reduced-motion: reduce) {
  .mp-root *, .mp-root *::before, .mp-root *::after { animation: none !important; transition: none !important; }
}
