/* ==========================================================================
   MLBB Xona — vanilla CSS
   Sahifa umuman skroll qilinmaydi: butun ekran "stage", xona uning ichida
   transform bilan suriladi. Shu sabab hech qanday scrollbar yo'q.
   Stiker koordinatalari — foizda, ya'ni sahna istalgan ekranga moslashadi.
   ========================================================================== */

:root {
  --bg: #0d0b16;
  --ink: #efeaf7;
  --muted: #a79fc0;
  --accent: #ffc65c;
  --accent-2: #7c5cff;
  --panel: rgba(20, 17, 34, .92);
  --line: rgba(255, 255, 255, .12);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;              /* scrollbar yo'q */
  overscroll-behavior: none;     /* mobil "pull to refresh" o'chadi */
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 500 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ------------------------------ stage ----------------------------------- */

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;            /* surishni o'zimiz boshqaramiz */
  cursor: grab;
  background-color: var(--bg);
  background-repeat: repeat;     /* bitta pattern butun ekranga ko'payadi */
  background-position: 0 0;
  contain: strict;
}

.stage.grabbing { cursor: grabbing; }

/* Pattern rasmi hali qo'yilmagan bo'lsa — xona baribir ishlaydi */
.stage.is-missing {
  background-image:
    repeating-linear-gradient(135deg,
      rgba(255, 255, 255, .04) 0 14px,
      rgba(255, 255, 255, 0) 14px 28px);
  background-size: 56px 56px;
}

/* Chetlarga yumshoq qorayish — xona chegarasi bilinmasin */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 80% at 50% 40%, transparent 55%, rgba(6, 4, 14, .55) 100%);
  z-index: 30;
}

/* ------------------------------- xona ----------------------------------- */

.room {
  position: absolute;
  top: 0;
  left: 0;
  /* o'lchamlari va transformi app.js'da */
  will-change: transform;
  transform: translate3d(0, 0, 0);
}

.items { position: absolute; inset: 0; }

/* ------------------------------ stiker ---------------------------------- */

.item {
  position: absolute;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  transform-origin: 50% 50%;
  cursor: pointer;
  touch-action: none;
}

/* Minimal 44x44 bosish maydoni */
.item::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: max(100%, 44px);
  height: max(100%, 44px);
  transform: translate(-50%, -50%);
}

.item:focus-visible { outline: none; }
.item:focus-visible .art {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
  border-radius: 10px;
}

.art {
  display: block;
  animation: bob 3.6s ease-in-out infinite;
  animation-delay: var(--bob, 0s);
}

.item img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .45));
}

/* Rasm topilmasa — nomi yozilgan plitka (alt matni ko'rinadi) */
.item.is-missing img {
  aspect-ratio: 1;
  border-radius: 16px;
  background: linear-gradient(150deg, #3a2c66, #1d1733);
  border: 1px dashed rgba(255, 255, 255, .28);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  overflow: hidden;
}

.item.is-hidden { opacity: .16; }
.item.is-hidden:focus-visible { opacity: .6; }

.item.is-found img {
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .45))
          drop-shadow(0 0 8px rgba(255, 198, 92, .55));
}
.item.is-found.is-hidden { opacity: 1; }

.item.pop img { animation: pop 200ms cubic-bezier(.34, 1.56, .64, 1); }

@keyframes bob {
  0%, 100% { transform: translateY(-3px); }
  50%      { transform: translateY(3px); }
}

@keyframes pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ------------------------------ bulutcha --------------------------------
   Komiks uslubidagi "fikr buluti". Chetlaridagi do'ngchalar — takrorlanuvchi
   radial-gradient chiziqlari: matn uzunligi o'zgarsa ular o'zi cho'ziladi,
   ya'ni shakl har qanday yozuvga moslashadi.
   ------------------------------------------------------------------------ */

.bubble {
  --cloud: #fffdf7;
  --cloud-ink: #2a1c4a;
  --bump: 20px;              /* do'ngcha diametri */

  position: absolute;
  z-index: 500;
  /* Pastda quyruq doiralari uchun joy: pastki do'ngchalar 10px, quyruq
     41px pastga cho'ziladi — stikerga tegib ketmasin. */
  transform: translate(-50%, calc(-100% - 54px));
  opacity: 0;
  visibility: hidden;
  transition: opacity 140ms ease;
  pointer-events: none;
}

.bubble.show { opacity: 1; visibility: visible; }
.bubble.has-link { pointer-events: auto; }

.cloud {
  position: relative;
  max-width: min(240px, 60vw);
  min-width: 78px;
  padding: 11px 18px;
  border-radius: 20px;
  background: var(--cloud);
  color: var(--cloud-ink);
  font-size: 14.5px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  letter-spacing: .1px;
  transform-origin: 50% 118%;
  /* Soya butun siluetni (do'ngchalar + quyruq bilan) kuzatadi */
  filter:
    drop-shadow(0 5px 0 rgba(78, 48, 150, .45))
    drop-shadow(0 12px 18px rgba(0, 0, 0, .45));
}

/* Do'ngchalar: yuqori/quyi — .cloud'da, chap/o'ng — .cloud-deco'da.
   Rang bir xil bo'lgani uchun asosiy quti bilan bir butun bo'lib qo'shiladi. */
.cloud::before,
.cloud::after,
.cloud-deco::before,
.cloud-deco::after {
  content: "";
  position: absolute;
}

.cloud::before,
.cloud::after {
  left: 9px;
  right: 9px;
  height: var(--bump);
  background:
    radial-gradient(circle at 9px 10px, var(--cloud) 9.5px, transparent 10px)
    0 0 / 18px var(--bump) repeat-x;
}
.cloud::before { top: calc(var(--bump) / -2); }
.cloud::after  { bottom: calc(var(--bump) / -2); }

.cloud-deco { position: absolute; inset: 0; }

.cloud-deco::before,
.cloud-deco::after {
  top: 9px;
  bottom: 9px;
  width: var(--bump);
  background:
    radial-gradient(circle at 10px 9px, var(--cloud) 9.5px, transparent 10px)
    0 0 / var(--bump) 18px repeat-y;
}
.cloud-deco::before { left: calc(var(--bump) / -2); }
.cloud-deco::after  { right: calc(var(--bump) / -2); }

/* Matn — do'ngchalar ustida */
.cloud-txt { position: relative; z-index: 1; display: block; }

/* Quyruq: pastga qarab kichrayadigan ikkita doira */
.cloud-tail { position: absolute; left: 50%; bottom: 0; }

.cloud-tail::before,
.cloud-tail::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: var(--cloud);
}
.cloud-tail::before { width: 15px; height: 15px; left: -14px; bottom: -18px; }
.cloud-tail::after  { width: 9px;  height: 9px;  left: -2px;  bottom: -32px; }

/* Havola (creator profili) — bulut ichidagi kichik tugmacha */
.cloud a {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #241a05;
  text-decoration: none;
  font-size: 12px;
}

/* --- fun animatsiya: sapchib chiqadi, keyin sekin suzadi --- */

.bubble.show .cloud {
  animation:
    cloudIn 420ms cubic-bezier(.34, 1.72, .55, 1) both,
    cloudFloat 2.6s ease-in-out 420ms infinite;
}
.bubble.show .cloud-tail::before { animation: tailPop 320ms cubic-bezier(.34, 1.72, .55, 1) 90ms both; }
.bubble.show .cloud-tail::after  { animation: tailPop 320ms cubic-bezier(.34, 1.72, .55, 1) 170ms both; }

@keyframes cloudIn {
  0%   { transform: scale(.2) rotate(-10deg); opacity: 0; }
  55%  { transform: scale(1.1) rotate(3deg);  opacity: 1; }
  75%  { transform: scale(.97) rotate(-1.5deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes cloudFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-5px) rotate(1.2deg); }
}

@keyframes tailPop {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ------------------------------ HUD ------------------------------------- */

.pill {
  position: fixed;
  z-index: 100;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .2px;
  backdrop-filter: blur(8px);
}

.pill-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}
.pill-btn:hover { color: var(--ink); }

.hint {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(46px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: opacity 400ms ease;
  pointer-events: none;
}
.hint-ico { font-size: 15px; animation: nudge 1.8s ease-in-out infinite; }
.hint.gone { opacity: 0; }

@keyframes nudge {
  0%, 100% { transform: translate(0, 0); }
  25%      { transform: translate(3px, 0); }
  50%      { transform: translate(0, 3px); }
  75%      { transform: translate(-3px, 0); }
}

.footer {
  position: fixed;
  z-index: 100;
  left: 0;
  right: 0;
  bottom: calc(8px + env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  opacity: .65;
  pointer-events: none;
}

.error {
  position: fixed;
  z-index: 400;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 32px));
  margin: 0;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid rgba(255, 120, 120, .4);
  background: rgba(40, 12, 20, .95);
  color: #ffc9c9;
  font-size: 14px;
  line-height: 1.6;
}
.error code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(0, 0, 0, .35);
  padding: 1px 6px;
  border-radius: 6px;
}

/* ========================================================================
   EDIT MODE (?edit=1) — hech qachon standart holat emas
   ======================================================================== */

body.edit .hint,
body.edit .pill { display: none; }

body.edit .art { animation: none; }
body.edit .item.is-hidden { opacity: .55; }
body.edit .item { cursor: grab; }

body.edit .item::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 1px dashed rgba(255, 255, 255, .22);
  border-radius: 8px;
  pointer-events: none;
}

body.edit .item.selected { z-index: 9999 !important; }
body.edit .item.selected::after {
  border: 2px solid var(--accent);
  border-radius: 6px;
}

/* Tutqichlar */
.handle {
  position: absolute;
  display: none;
  touch-action: none;
  z-index: 2;
}
body.edit .item.selected .handle { display: block; }

.handle-size {
  right: -9px;
  bottom: -9px;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--accent);
  border: 2px solid #1a1430;
  cursor: nwse-resize;
}

/* Aylantirish tutqichi — element tepasida, ip bilan ulangan */
.handle-rot {
  left: 50%;
  top: -34px;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  border-radius: 999px;
  background: var(--accent-2);
  border: 2px solid #1a1430;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: grab;
}
.handle-rot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 16px;
  margin-left: -1px;
  background: var(--accent-2);
}
body.edit .item.rotating .handle-rot { cursor: grabbing; }

/* Aylantirayotganda burchakni ko'rsatuvchi yorliq */
.angle-tag {
  position: fixed;
  z-index: 250;
  padding: 4px 9px;
  border-radius: 8px;
  background: var(--accent-2);
  color: #fff;
  font: 800 12px/1 system-ui, sans-serif;
  pointer-events: none;
  transform: translate(-50%, -160%);
  display: none;
}
.angle-tag.show { display: block; }

.editor {
  position: fixed;
  z-index: 200;
  left: 12px;
  bottom: 12px;
  width: 268px;
  max-height: min(78vh, 620px);
  overflow: auto;
  padding: 12px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  font-size: 13px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .55);
}

.editor h2 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.editor .row {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.editor label { color: var(--muted); font-weight: 700; }

.editor input[type="text"],
.editor input[type="number"],
.editor select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .35);
  color: var(--ink);
  font: inherit;
}

.editor input:focus,
.editor select:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }

.editor .grid4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }

.editor .bar { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }

.editor button {
  flex: 1 1 auto;
  padding: 7px 9px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: var(--ink);
  font: 700 12px/1 inherit;
  cursor: pointer;
}
.editor button:hover { background: rgba(255, 255, 255, .12); }
.editor button.primary { background: var(--accent); color: #241a05; border-color: transparent; }
.editor button.danger  { background: rgba(255, 90, 90, .18); border-color: rgba(255, 90, 90, .4); }

.editor .keys { margin-top: 8px; color: var(--muted); font-size: 11px; line-height: 1.7; }
.editor .empty { color: var(--muted); padding: 6px 0 2px; }

.toast {
  position: fixed;
  z-index: 300;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(8px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #241a05;
  font-weight: 800;
  font-size: 13px;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --------------------------- kichik ekranlar ---------------------------- */

@media (max-width: 560px) {
  .editor {
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 46vh;
  }
  .pill { font-size: 13px; padding: 7px 8px 7px 12px; }
  .footer { font-size: 10px; }
}

/* Landshaft rejimida past ekran — panel pastini yemasin */
@media (max-height: 480px) {
  .editor { max-height: 84vh; }
  .hint { bottom: calc(30px + env(safe-area-inset-bottom)); }
}

/* ------------------------- harakatni kamaytirish ------------------------ */

@media (prefers-reduced-motion: reduce) {
  .art,
  .hint-ico { animation: none !important; }
  .item.pop img { animation: none !important; }
  .bubble { transition: none; }
  /* Bulutcha animatsiyasiz, lekin to'liq ko'rinadigan holatda qoladi */
  .bubble.show .cloud,
  .bubble.show .cloud-tail::before,
  .bubble.show .cloud-tail::after { animation: none !important; }
}
