/* =====================================================================
   GIAO DIỆN ĐIỆN THOẠI (dọc & ngang) – nạp cuối cùng để ghi đè
   ===================================================================== */

/* Chạm: bỏ nháy xanh khi bấm, chặn phóng to khi chạm đúp, chừa vùng tai thỏ */
html { -webkit-text-size-adjust: 100%; }
body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
.game-root { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
.toolbar { padding-bottom: max(9px, env(safe-area-inset-bottom)); }
#street-canvas { touch-action: pan-y; cursor: default; }

/* Màn đăng nhập / tạo nhân vật: căn giữa an toàn – khi nội dung cao hơn màn hình vẫn cuộn được tới đầu trang */
.login-overlay, .creator-overlay { align-items: flex-start; overscroll-behavior: contain; }
.login-overlay { padding-top: max(56px, calc(env(safe-area-inset-top) + 50px)); }
.creator-overlay { padding-top: max(34px, calc(env(safe-area-inset-top) + 28px)); }
.login-card, .creator-card { margin: auto; }

/* Thanh trượt ngang dùng chung: ẩn thanh cuộn, có bóng mờ gợi ý kéo */
@media (max-width: 760px), (max-height: 500px) {
  .dock-bar, .district-bar, .tab-bar, .ms-tabs {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .dock-bar::-webkit-scrollbar, .tab-bar::-webkit-scrollbar { display: none; }

  /* ---------- Hộp thoại: toàn màn hình, trượt lên từ dưới ---------- */
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal-card {
    max-width: none; width: 100%;
    max-height: none; height: 100%; height: 100dvh;
    border: none; border-radius: 0; box-shadow: none;
    animation: sheet-up .24s cubic-bezier(.2,1,.4,1);
  }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
  .modal-header { padding: calc(8px + env(safe-area-inset-top)) 10px 8px 12px; }
  .modal-header h2 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .modal-close { width: 38px; height: 38px; }
  .modal-body { padding: 10px 10px calc(16px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
  .tab-bar { flex-wrap: nowrap; overflow-x: auto; margin-bottom: 10px; gap: 6px; padding-bottom: 2px; }
  .tab-btn { flex-shrink: 0; white-space: nowrap; }
  .card-grid { grid-template-columns: 1fr; gap: 8px; }
  .info-banner { font-size: 12.5px; }
  .btn { min-height: 36px; }
  .btn-sm { min-height: 32px; }

  /* ---------- Thông báo nổi: giữa trên, không che nút ---------- */
  #toast-container { left: 8px; right: 8px; top: calc(6px + env(safe-area-inset-top)); max-width: none; align-items: center; }
  .toast { font-size: 12.5px; max-width: 100%; }
}

/* =====================================================================
   ĐIỆN THOẠI DỌC
   ===================================================================== */
@media (max-width: 760px) {
  /* HUD gọn lại */
  .hud { top: 6px; }
  .hud-left { left: 6px; transform: scale(.74); transform-origin: top left; }
  .hud-right { right: 6px; transform: scale(.8); transform-origin: top right; gap: 5px; }
  .stat-row span { display: none; }
  .curr-pill.rep { display: none; }

  /* Bảng nhiệm vụ nhỏ: thu gọn, nằm dưới hồ sơ */
  .mission-tracker { top: 76px; left: 6px; width: 196px; border-radius: 12px; }
  .mt-head { font-size: 11px; padding: 4px 6px; }
  .mt-row { font-size: 10.5px; padding: 2px 5px 4px; grid-template-columns: 16px 1fr auto; }
  .mt-num { font-size: 10px; }

  /* Tiện ích trên phố: chỉ biểu tượng tròn */
  .street-widgets { left: 8px; bottom: 58px; gap: 8px; }
  .sw-btn { min-width: 0; padding: 3px; border-radius: 50%; }
  .sw-icon { width: 38px; height: 38px; border-radius: 50%; font-size: 20px; }
  .sw-text { display: none; }
  .chat-widget { left: 8px; bottom: 8px; }
  .chat-fab { padding: 8px 10px; }
  .chat-fab-label { display: none; }
  .chat-panel { width: calc(100vw - 16px); height: min(460px, calc(100dvh - 240px)); }

  /* Thanh công cụ */
  .toolbar { padding: 12px 6px 6px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .toolbar::before { top: -8px; height: 12px; }
  .toolbar-top { flex-direction: column; align-items: stretch; gap: 6px; margin-bottom: 4px; }
  .district-bar { gap: 5px; }
  .dist-btn { font-size: 11px; padding: 4px 9px; }
  .dist-btn small { display: none; }
  .loa-ticker { min-height: 26px; padding: 1px 8px 1px 2px; }
  .loa-icon { width: 22px; height: 22px; font-size: 12px; }
  #loa-ticker-text { font-size: 11.5px; }

  /* Nút chức năng: 1 hàng trượt ngang */
  .dock-bar {
    display: flex; grid-template-columns: none;
    gap: 6px; overflow-x: auto; overflow-y: visible;
    padding: 15px 4px 4px; margin: 0 -6px;
    scroll-snap-type: x proximity;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 10px, #000 calc(100% - 22px), transparent);
            mask-image: linear-gradient(90deg, transparent 0, #000 10px, #000 calc(100% - 22px), transparent);
  }
  .dock-btn { flex: 0 0 66px; scroll-snap-align: start; padding: 17px 2px 5px; border-radius: 11px; }
  .dock-btn:first-child { margin-left: 6px; }
  .dock-btn:last-child { margin-right: 14px; }
  .dock-icon { width: 30px; height: 30px; top: -12px; font-size: 17px; }
  .dock-label { font-size: 10px; white-space: nowrap; letter-spacing: 0; }
  .dock-btn .badge-count { top: -10px; right: -2px; transform: scale(.85); }
  .dock-btn:hover { transform: none; }

  /* Màn đăng nhập / tạo nhân vật */
  .login-card { padding-left: 14px; padding-right: 14px; }
  .creator-card { padding: 30px 12px 14px; border-radius: 18px; }
}

/* Điện thoại rất nhỏ (≤ 360px) */
@media (max-width: 360px) {
  .hud-left { transform: scale(.66); }
  .hud-right { transform: scale(.72); }
  .mission-tracker { top: 68px; width: 176px; }
}

/* =====================================================================
   ĐIỆN THOẠI NGANG (chiều cao thấp)
   ===================================================================== */
@media (max-height: 500px) {
  .hud { top: 4px; }
  .hud-left { left: 6px; transform: scale(.68); transform-origin: top left; }
  .hud-right { right: 6px; transform: scale(.72); transform-origin: top right; gap: 4px; }
  .stat-row span { display: none; }
  .donate-strip .ds-sub { display: none; }

  .mission-tracker { top: 64px; left: 6px; width: 210px; }
  .mission-tracker .mt-row:nth-child(n+2) { display: none; }
  .mt-head { font-size: 11px; padding: 3px 6px; }
  .mt-row { font-size: 10.5px; padding: 2px 5px 3px; }

  .street-widgets { left: 8px; bottom: 54px; gap: 6px; }
  .sw-btn { min-width: 0; padding: 2px; border-radius: 50%; }
  .sw-icon { width: 34px; height: 34px; border-radius: 50%; font-size: 18px; }
  .sw-text { display: none; }
  .chat-fab { padding: 6px 9px; }
  .chat-fab-label { display: none; }
  .chat-panel { height: calc(100dvh - 130px); min-height: 0; width: min(380px, 60vw); }

  /* Thanh công cụ siêu gọn: 1 hàng khu phố + 1 hàng nút */
  .toolbar { padding: 9px 6px 4px; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .toolbar::before { top: -7px; height: 10px; }
  .toolbar-top { flex-direction: row; gap: 6px; margin-bottom: 2px; }
  .district-bar { flex: 0 1 auto; max-width: 58%; gap: 4px; }
  .dist-btn { font-size: 10.5px; padding: 3px 8px; border-width: 2px; }
  .dist-btn small { display: none; }
  .loa-ticker { min-height: 24px; padding: 0 8px 0 2px; border-width: 2px; }
  .loa-icon { width: 20px; height: 20px; font-size: 11px; }
  #loa-ticker-text { font-size: 11px; }

  .dock-bar {
    display: flex; grid-template-columns: none;
    gap: 5px; overflow-x: auto; overflow-y: visible;
    padding: 12px 2px 2px;
  }
  .dock-btn { flex: 1 0 58px; padding: 13px 2px 3px; border-radius: 10px; border-width: 2px; }
  .dock-icon { width: 26px; height: 26px; top: -11px; font-size: 15px; border-width: 2px; }
  .dock-label { font-size: 9.5px; white-space: nowrap; letter-spacing: 0; }
  .dock-btn .badge-count { top: -10px; right: -3px; transform: scale(.8); }
  .dock-btn:hover { transform: none; }

}

/* Gợi ý xoay ngang / kéo phố (chỉ hiện ở điện thoại dọc) */
.rotate-hint {
  position: absolute; left: 50%; top: 50%; z-index: 4;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  font-size: 12.5px; font-weight: 700; line-height: 1.35; color: #fff;
  background: rgba(20, 24, 40, .82); border: 2px solid rgba(255,255,255,.5); border-radius: 14px;
  width: max-content; max-width: 86%;
  pointer-events: none;
  animation: rh-fade 6s ease forwards;
}
.rotate-hint .rh-icon { font-size: 26px; animation: rh-rotate 1.6s ease-in-out infinite; }
@keyframes rh-rotate { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@keyframes rh-fade { 0%, 85% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
@media (min-width: 761px) { .rotate-hint { display: none; } }

/* Thanh map phụ (Về Phố) trên điện thoại */
@media (max-width: 760px) {
  .map-bar { top: 80px; left: 8px; right: 8px; transform: none; max-width: none; padding: 5px 10px 5px 5px; gap: 8px; border-width: 2.5px; border-radius: 14px; }
  .map-bar .btn { padding: 6px 10px; font-size: 12px; white-space: nowrap; }
  .map-info b { font-size: 13px; }
  .map-info span { font-size: 10.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
@media (max-height: 500px) {
  .map-bar { top: 6px; max-width: 38vw; padding: 3px 8px 3px 3px; gap: 6px; border-width: 2px; }
  .map-bar .btn { padding: 4px 8px; font-size: 11px; white-space: nowrap; }
  .map-info b { font-size: 12px; }
  .map-info span { display: none; }
}

/* Đấu Trường Oẳn Tù Tì & các bảng riêng: toàn màn hình trên điện thoại */
@media (max-width: 760px), (max-height: 500px) {
  .rps-overlay { padding: 0; align-items: stretch; }
  .rps-card { width: 100%; max-height: none; height: 100dvh; border: none; border-radius: 0; box-shadow: none; }
  .rps-head { padding: calc(6px + env(safe-area-inset-top)) 10px 6px; gap: 8px; }
  .rps-body { padding: 10px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) {
  .rps-head h2, .rps-title { font-size: 17px; }
  .rps-detail { padding: 10px; gap: 6px; }
  .rps-detail-char { width: 150px; height: 150px; }
  .rps-detail-name { font-size: 20px; }
  .rps-detail-hint, .rps-detail-rule { font-size: 13px; }
}
@media (max-height: 500px) {
  .rps-detail-char { width: 120px; height: 120px; }
  .rps-detail { grid-template-columns: 130px 1fr; }
  .rps-fighter canvas { width: 110px; height: 110px; }
}

@media (max-width: 760px) { body.in-map .donate-strip { display: none; } }
